メインページ | ネームスペース一覧 | クラス階層 | 構成 | Directories | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ

Manager.h

説明を見る。
00001 // -*- C++ -*-
00019 /*
00020  * $Log: Manager.h,v $
00021  * Revision 1.9.2.1  2007/07/20 15:56:14  n-ando
00022  * Functor InstanceName was modified for win32 porting.
00023  *
00024  * Revision 1.9  2007/04/26 15:36:54  n-ando
00025  * The header include order was modified to define _REENTRANT before
00026  * including ace/config-lite.h in Linux systems.
00027  * In ace 5.4.7 or later, _REENTRANT flag should be defined explicitly.
00028  *
00029  * Revision 1.8  2007/04/23 04:53:29  n-ando
00030  * Component instantiation processes were divided into some functions.
00031  *
00032  * Revision 1.7  2007/04/17 09:22:08  n-ando
00033  * Namespace of Timer class was changed from ::Timer to RTC::Timer.
00034  *
00035  * Revision 1.6  2007/04/13 18:02:14  n-ando
00036  * Some configuration properties handling processes were changed.
00037  *
00038  * Revision 1.5  2007/01/21 09:54:30  n-ando
00039  * A trivial bug fix.
00040  *
00041  * Revision 1.4  2007/01/14 19:42:37  n-ando
00042  * The activate() function now performs POA manager activation and
00043  * invoking ModuleInitProc.
00044  * Debugging messages are now output to system logger.
00045  *
00046  * Revision 1.3  2006/11/06 01:31:57  n-ando
00047  * Some Manager's functions has been implemented.
00048  * - Component creation process
00049  * - System logger initialization
00050  *
00051  * Revision 1.2  2006/10/25 17:28:05  n-ando
00052  * Component factory registration and relative functions are implemented.
00053  *
00054  * Revision 1.1  2006/10/17 10:21:24  n-ando
00055  * The first commitment.
00056  *
00057  *
00058  */
00059 
00060 #ifndef Manager_h
00061 #define Manager_h
00062 
00063 #include <rtm/RTC.h>
00064 
00065 #include <iostream>
00066 #include <string>
00067 #include <vector>
00068 
00069 #include <ace/Synch.h>
00070 #include <ace/Task.h>
00071 
00072 #include <rtm/Factory.h>
00073 #include <rtm/ECFactory.h>
00074 #include <rtm/ObjectManager.h>
00075 #include <rtm/RTObject.h>
00076 #include <rtm/SystemLogger.h>
00077 
00078 class Properties;
00079 
00080 
00081 namespace RTC
00082 {
00083   class CorbaNaming;
00084   class ModuleManager;
00085   class NamingManager;
00086   class CorbaObjectManager;
00087   class Manager;
00088   class Timer;
00089 
00090   typedef void (*ModuleInitProc)(Manager* manager);  
00091 
00092   class Manager
00093   {
00094   protected:
00102     Manager();
00103 
00104 
00112     Manager(const Manager& manager);
00113       //      Manager& operator=(const Manager& manager){return manager;};
00114     
00115   public:
00156     static Manager* init(int argc, char** argv);
00157 
00158 
00181     static Manager& instance();
00182 
00183     //============================================================
00184     // Manager
00185     //============================================================
00186 
00187 
00188 
00189     void terminate();
00190     void shutdown();
00191     void join();
00192     
00193     Logbuf& getLogbuf() {return m_Logbuf;}
00194     Properties& getConfig() { return m_config;}
00195     
00196     
00197     
00198     
00223     void setModuleInitProc(ModuleInitProc proc);
00224 
00225 
00253     bool activateManager();
00254 
00285     void runManager(bool no_block = false);
00286     
00287 
00288 
00289 
00290     //============================================================
00291     // Module management
00292     //============================================================
00314     void load(const char* fname, const char* initfunc);
00315 
00316 
00337     void unload(const char* fname);
00338 
00339 
00355     void unloadAll();
00356 
00357 
00365     std::vector<std::string> getLoadedModules();
00366     
00367 
00375     std::vector<std::string> getLoadableModules();
00376 
00377     //============================================================
00378     // Component Factory Management
00379     //============================================================
00387     bool registerFactory(Properties& profile,
00388                          RtcNewFunc new_func,
00389                          RtcDeleteFunc delete_func);
00390     
00391     bool registerECFactory(const char* name,
00392                            ECNewFunc new_func,
00393                            ECDeleteFunc delete_func);
00394     
00402     std::vector<std::string> getModulesFactories();
00403     
00404     //============================================================
00405     // Component management
00406     //============================================================
00414     RtcBase* createComponent(const char* module_name);
00415 
00416     void cleanupComponent(RtcBase* comp);
00417 
00425     bool registerComponent(RtcBase* comp);
00426 
00427     bool unregisterComponent(RtcBase* comp);
00428 
00429     bool bindExecutionContext(RtcBase* comp);
00430 
00438     void deleteComponent(const char* instance_name);
00439     
00447     RtcBase* getComponent(const char* instance_name);
00448     
00456     std::vector<RtcBase*> getComponents();
00457     
00458 
00459     //============================================================
00460     // CORBA 関連
00461     //============================================================
00469     CORBA::ORB_ptr getORB();
00470 
00478     PortableServer::POA_ptr getPOA();
00479     PortableServer::POAManager_ptr getPOAManager();
00480 
00481 
00482     //============================================================
00483     // Protected functions
00484     //============================================================
00485   protected:
00486     
00487     //============================================================
00488     // Manager initialize and finalization
00489     //============================================================
00497     void initManager(int argc, char** argv);
00498 
00499 
00507     void shutdownManager();
00508 
00509 
00510     //============================================================
00511     // Logger initialize and terminator
00512     //============================================================
00520     bool initLogger();
00521 
00522 
00530     void shutdownLogger();
00531 
00532 
00533     //============================================================
00534     // ORB initialization and finalization
00535     //============================================================
00543     bool initORB();
00544     
00545     
00553     std::string createORBOptions();
00554     
00555     
00563     void shutdownORB();
00564 
00565    
00566     //============================================================
00567     // NamingService initialization and finalization
00568     //============================================================
00576     bool initNaming();
00577     void shutdownNaming();
00578 
00579 
00580     //============================================================
00581     // Component management
00582     //============================================================
00583     void shutdownComponents();
00584 
00585 
00586     void configureComponent(RtcBase* comp);
00587 
00588 
00589     bool initExecContext();
00590 
00591     bool initTimer();
00592 
00593     bool mergeProperty(Properties& prop, const char* file_name);
00594     std::string formatString(const char* naming_format,
00595                              Properties& prop);
00596     
00597     //============================================================
00598     // protected 変数
00599     //============================================================
00600 
00601     //------------------------------------------------------------
00602     // static var
00603     //------------------------------------------------------------
00611     static Manager* manager;
00612 
00620     static ACE_Thread_Mutex mutex;
00621     
00622 
00623     //------------------------------------------------------------
00624     // CORBA var
00625     //------------------------------------------------------------
00633     CORBA::ORB_var m_pORB;
00634 
00642     PortableServer::POA_var m_pPOA;
00643 
00651     PortableServer::POAManager_var m_pPOAManager;
00652 
00653 
00654     //------------------------------------------------------------
00655     // Manager's variable
00656     //------------------------------------------------------------
00664     ModuleInitProc m_initProc;
00665 
00673     Properties m_config;
00674 
00682     ModuleManager* m_module;
00683     
00691     NamingManager* m_namingManager;
00692 
00693     CorbaObjectManager* m_objManager;
00694 
00702     Timer* m_timer;
00703 
00704 
00705     //------------------------------------------------------------
00706     // Logger
00707     //------------------------------------------------------------
00715     Logbuf m_Logbuf;
00716 
00724     MedLogbuf m_MedLogbuf;
00725 
00733     LogStream rtcout;
00734     
00735 
00736     //============================================================
00737     // コンポーネントマネージャ
00738     //============================================================
00739     // ObjectManager へ渡す述語クラス
00740     struct InstanceName
00741     {
00742       InstanceName(RtcBase* comp) : m_name(comp->getInstanceName()) {};
00743       InstanceName(const char* name) : m_name(name) {};
00744       InstanceName(const std::string name) : m_name(name) {};
00745       bool operator()(RtcBase* comp)
00746       {
00747         return m_name == comp->getInstanceName();
00748       }
00749       std::string m_name;
00750     };
00751 
00752     typedef ObjectManager<std::string,
00753                           RtcBase,
00754                           InstanceName> ComponentManager;
00762     ComponentManager m_compManager;
00763 
00764 
00765     //============================================================
00766     // コンポーネントファクトリ
00767     //============================================================
00768     // コンポーネントファクトリへ渡す述語クラス
00769     struct FactoryPredicate
00770     {
00771       FactoryPredicate(const char* name) : m_name(name){};
00772       FactoryPredicate(FactoryBase* factory)
00773         : m_name(factory->profile()["implementation_id"]) {};
00774       bool operator()(FactoryBase* factory)
00775       {
00776         return m_name == factory->profile()["implementation_id"];
00777       }
00778       std::string m_name;
00779     };
00787     typedef ObjectManager<const char*,
00788                           FactoryBase,
00789                           FactoryPredicate> FactoryManager;
00797     FactoryManager m_factory;
00798 
00799     //============================================================
00800     // ExecutionContextファクトリ
00801     //============================================================
00802     // ECファクトリへ渡す述語クラス
00803     struct ECFactoryPredicate
00804     {
00805       ECFactoryPredicate(const char* name) : m_name(name){};
00806       ECFactoryPredicate(ECFactoryBase* factory)
00807         : m_name(factory->name()) {};
00808       bool operator()(ECFactoryBase* factory)
00809       {
00810         return m_name == factory->name();
00811       }
00812       std::string m_name;
00813     };
00814     typedef ObjectManager<const char*,
00815                           ECFactoryBase,
00816                           ECFactoryPredicate> ECFactoryManager;
00817     ECFactoryManager m_ecfactory;
00818     std::vector<ExecutionContextBase*> m_ecs;
00819 
00820 
00821     // ファクトリ名をリストアップするためのファンクタ
00822     struct ModuleFactories
00823     {
00824       void operator()(FactoryBase* f)
00825       {
00826         modlist.push_back(f->profile().getProperty("implementation_id"));
00827       }
00828       std::vector<std::string> modlist;
00829     };
00830 
00831 
00832     //------------------------------------------------------------
00833     // ORB runner
00834     //------------------------------------------------------------
00835     class OrbRunner
00836       : public ACE_Task<ACE_MT_SYNCH>
00837     {
00838     public:
00839       OrbRunner(CORBA::ORB_ptr orb) : m_pORB(orb)
00840       {
00841         open(0);
00842       };
00843       virtual int open(void *args)
00844       {
00845         activate();
00846         return 0;
00847       }
00848       virtual int svc(void)
00849       {
00850         m_pORB->run();
00851         Manager::instance().shutdown();
00852         return 0;
00853       }
00854       virtual int close(unsigned long flags)
00855       {
00856         return 0;
00857       }
00858     private:
00859       CORBA::ORB_ptr m_pORB;
00860       
00861     };
00862     OrbRunner* m_runner;
00863 
00864 
00865     //------------------------------------------------------------
00866     // Manager Terminator
00867     //------------------------------------------------------------
00868     class Terminator
00869       : public ACE_Task<ACE_MT_SYNCH>
00870     {
00871     public:
00872       Terminator(Manager* manager) : m_manager(manager) {};
00873       void terminate()
00874       {
00875         open(0);
00876       }
00877       virtual int open(void *args)
00878       {
00879         activate();
00880         return 0;
00881       }
00882       virtual int svc(void)
00883       {
00884         Manager::instance().shutdown();
00885         return 0;
00886       }
00887       Manager* m_manager;
00888     };
00889 
00890     Terminator* m_terminator;
00891 
00892     struct Term
00893     {
00894       int waiting;
00895       ACE_Thread_Mutex mutex;
00896     };
00897     Term m_terminate;
00898 
00899 
00900 
00901   }; // class Manager
00902 }; // namespace RTC
00903 
00904 #endif // Manager_h

OpenRTMに対してFri Oct 5 05:14:57 2007に生成されました。  doxygen 1.4.1