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

Manager.h

説明を見る。
00001 // -*- C++ -*-
00019 /*
00020  * $Log: Manager.h,v $
00021  * Revision 1.9  2007/04/26 15:36:54  n-ando
00022  * The header include order was modified to define _REENTRANT before
00023  * including ace/config-lite.h in Linux systems.
00024  * In ace 5.4.7 or later, _REENTRANT flag should be defined explicitly.
00025  *
00026  * Revision 1.8  2007/04/23 04:53:29  n-ando
00027  * Component instantiation processes were divided into some functions.
00028  *
00029  * Revision 1.7  2007/04/17 09:22:08  n-ando
00030  * Namespace of Timer class was changed from ::Timer to RTC::Timer.
00031  *
00032  * Revision 1.6  2007/04/13 18:02:14  n-ando
00033  * Some configuration properties handling processes were changed.
00034  *
00035  * Revision 1.5  2007/01/21 09:54:30  n-ando
00036  * A trivial bug fix.
00037  *
00038  * Revision 1.4  2007/01/14 19:42:37  n-ando
00039  * The activate() function now performs POA manager activation and
00040  * invoking ModuleInitProc.
00041  * Debugging messages are now output to system logger.
00042  *
00043  * Revision 1.3  2006/11/06 01:31:57  n-ando
00044  * Some Manager's functions has been implemented.
00045  * - Component creation process
00046  * - System logger initialization
00047  *
00048  * Revision 1.2  2006/10/25 17:28:05  n-ando
00049  * Component factory registration and relative functions are implemented.
00050  *
00051  * Revision 1.1  2006/10/17 10:21:24  n-ando
00052  * The first commitment.
00053  *
00054  *
00055  */
00056 
00057 #ifndef Manager_h
00058 #define Manager_h
00059 
00060 #include <rtm/RTC.h>
00061 
00062 #include <iostream>
00063 #include <string>
00064 #include <vector>
00065 
00066 #include <ace/Synch.h>
00067 #include <ace/Task.h>
00068 
00069 #include <rtm/Factory.h>
00070 #include <rtm/ECFactory.h>
00071 #include <rtm/ObjectManager.h>
00072 #include <rtm/RTObject.h>
00073 #include <rtm/SystemLogger.h>
00074 
00075 class Properties;
00076 
00077 namespace RTC
00078 {
00079   class CorbaNaming;
00080   class ModuleManager;
00081   class NamingManager;
00082   class CorbaObjectManager;
00083   class Manager;
00084   class Timer;
00085 
00086   typedef void (*ModuleInitProc)(Manager* manager);  
00087 
00088   class Manager
00089   {
00090   protected:
00098     Manager();
00099 
00100 
00108     Manager(const Manager& manager);
00109       //      Manager& operator=(const Manager& manager){return manager;};
00110     
00111   public:
00152     static Manager* init(int argc, char** argv);
00153 
00154 
00177     static Manager& instance();
00178 
00179     //============================================================
00180     // Manager
00181     //============================================================
00182 
00183 
00184 
00185     void terminate();
00186     void shutdown();
00187     void join();
00188     
00189     Logbuf& getLogbuf() {return m_Logbuf;}
00190     Properties& getConfig() { return m_config;}
00191     
00192     
00193     
00194     
00219     void setModuleInitProc(ModuleInitProc proc);
00220 
00221 
00249     bool activateManager();
00250 
00281     void runManager(bool no_block = false);
00282     
00283 
00284 
00285 
00286     //============================================================
00287     // Module management
00288     //============================================================
00310     void load(const char* fname, const char* initfunc);
00311 
00312 
00333     void unload(const char* fname);
00334 
00335 
00351     void unloadAll();
00352 
00353 
00361     std::vector<std::string> getLoadedModules();
00362     
00363 
00371     std::vector<std::string> getLoadableModules();
00372 
00373     //============================================================
00374     // Component Factory Management
00375     //============================================================
00383     bool registerFactory(Properties& profile,
00384                          RtcNewFunc new_func,
00385                          RtcDeleteFunc delete_func);
00386     
00387     bool registerECFactory(const char* name,
00388                            ECNewFunc new_func,
00389                            ECDeleteFunc delete_func);
00390     
00398     std::vector<std::string> getModulesFactories();
00399     
00400     //============================================================
00401     // Component management
00402     //============================================================
00410     RtcBase* createComponent(const char* module_name);
00411     void cleanupComponent(RtcBase* comp);
00419     bool registerComponent(RtcBase* comp);
00420     bool unregisterComponent(RtcBase* comp);
00421 
00422 
00423     bool bindExecutionContext(RtcBase* comp);
00424 
00432     void deleteComponent(const char* instance_name);
00433     
00441     RtcBase* getComponent(const char* instance_name);
00442     
00450     std::vector<RtcBase*> getComponents();
00451     
00452 
00453     //============================================================
00454     // CORBA 関連
00455     //============================================================
00463     CORBA::ORB_ptr getORB();
00464 
00472     PortableServer::POA_ptr getPOA();
00473     PortableServer::POAManager_ptr getPOAManager();
00474 
00475 
00476     //============================================================
00477     // Protected functions
00478     //============================================================
00479   protected:
00480     
00481     //============================================================
00482     // Manager initialize and finalization
00483     //============================================================
00491     void initManager(int argc, char** argv);
00492 
00493 
00501     void shutdownManager();
00502 
00503 
00504     //============================================================
00505     // Logger initialize and terminator
00506     //============================================================
00514     bool initLogger();
00515 
00516 
00524     void shutdownLogger();
00525 
00526 
00527     //============================================================
00528     // ORB initialization and finalization
00529     //============================================================
00537     bool initORB();
00538     
00539     
00547     std::string createORBOptions();
00548     
00549     
00557     void shutdownORB();
00558 
00559    
00560     //============================================================
00561     // NamingService initialization and finalization
00562     //============================================================
00570     bool initNaming();
00571     void shutdownNaming();
00572 
00573 
00574     //============================================================
00575     // Component management
00576     //============================================================
00577     void shutdownComponents();
00578 
00579 
00580     void configureComponent(RtcBase* comp);
00581 
00582 
00583     bool initExecContext();
00584 
00585     bool initTimer();
00586 
00587     bool mergeProperty(Properties& prop, const char* file_name);
00588     std::string formatString(const char* naming_format,
00589                              Properties& prop);
00590     
00591     //============================================================
00592     // protected 変数
00593     //============================================================
00594 
00595     //------------------------------------------------------------
00596     // static var
00597     //------------------------------------------------------------
00605     static Manager* manager;
00606 
00614     static ACE_Thread_Mutex mutex;
00615     
00616 
00617     //------------------------------------------------------------
00618     // CORBA var
00619     //------------------------------------------------------------
00627     CORBA::ORB_var m_pORB;
00628 
00636     PortableServer::POA_var m_pPOA;
00637 
00645     PortableServer::POAManager_var m_pPOAManager;
00646 
00647 
00648     //------------------------------------------------------------
00649     // Manager's variable
00650     //------------------------------------------------------------
00658     ModuleInitProc m_initProc;
00659 
00667     Properties m_config;
00668 
00676     ModuleManager* m_module;
00677     
00685     NamingManager* m_namingManager;
00686 
00687     CorbaObjectManager* m_objManager;
00688 
00696     Timer* m_timer;
00697 
00698 
00699     //------------------------------------------------------------
00700     // Logger
00701     //------------------------------------------------------------
00709     Logbuf m_Logbuf;
00710 
00718     MedLogbuf m_MedLogbuf;
00719 
00727     LogStream rtcout;
00728     
00729 
00730     //============================================================
00731     // コンポーネントマネージャ
00732     //============================================================
00733     // ObjectManager へ渡す述語クラス
00734     struct InstanceName
00735     {
00736       InstanceName(RtcBase* comp) : m_name(comp->getInstanceName()) {};
00737       InstanceName(const char* name) : m_name(name) {};
00738       bool operator()(RtcBase* comp)
00739       {
00740         return m_name == comp->getInstanceName();
00741       }
00742       std::string m_name;
00743     };
00744 
00745     typedef ObjectManager<const char*,
00746                           RtcBase,
00747                           InstanceName> ComponentManager;
00755     ComponentManager m_compManager;
00756 
00757 
00758     //============================================================
00759     // コンポーネントファクトリ
00760     //============================================================
00761     // コンポーネントファクトリへ渡す述語クラス
00762     struct FactoryPredicate
00763     {
00764       FactoryPredicate(const char* name) : m_name(name){};
00765       FactoryPredicate(FactoryBase* factory)
00766         : m_name(factory->profile()["implementation_id"]) {};
00767       bool operator()(FactoryBase* factory)
00768       {
00769         return m_name == factory->profile()["implementation_id"];
00770       }
00771       std::string m_name;
00772     };
00780     typedef ObjectManager<const char*,
00781                           FactoryBase,
00782                           FactoryPredicate> FactoryManager;
00790     FactoryManager m_factory;
00791 
00792     //============================================================
00793     // ExecutionContextファクトリ
00794     //============================================================
00795     // ECファクトリへ渡す述語クラス
00796     struct ECFactoryPredicate
00797     {
00798       ECFactoryPredicate(const char* name) : m_name(name){};
00799       ECFactoryPredicate(ECFactoryBase* factory)
00800         : m_name(factory->name()) {};
00801       bool operator()(ECFactoryBase* factory)
00802       {
00803         return m_name == factory->name();
00804       }
00805       std::string m_name;
00806     };
00807     typedef ObjectManager<const char*,
00808                           ECFactoryBase,
00809                           ECFactoryPredicate> ECFactoryManager;
00810     ECFactoryManager m_ecfactory;
00811     std::vector<ExecutionContextBase*> m_ecs;
00812 
00813 
00814     // ファクトリ名をリストアップするためのファンクタ
00815     struct ModuleFactories
00816     {
00817       void operator()(FactoryBase* f)
00818       {
00819         modlist.push_back(f->profile().getProperty("implementation_id"));
00820       }
00821       std::vector<std::string> modlist;
00822     };
00823 
00824 
00825     //------------------------------------------------------------
00826     // ORB runner
00827     //------------------------------------------------------------
00828     class OrbRunner
00829       : public ACE_Task<ACE_MT_SYNCH>
00830     {
00831     public:
00832       OrbRunner(CORBA::ORB_ptr orb) : m_pORB(orb)
00833       {
00834         open(0);
00835       };
00836       virtual int open(void *args)
00837       {
00838         activate();
00839         return 0;
00840       }
00841       virtual int svc(void)
00842       {
00843         m_pORB->run();
00844         Manager::instance().shutdown();
00845         return 0;
00846       }
00847       virtual int close(unsigned long flags)
00848       {
00849         return 0;
00850       }
00851     private:
00852       CORBA::ORB_ptr m_pORB;
00853       
00854     };
00855     OrbRunner* m_runner;
00856 
00857 
00858     //------------------------------------------------------------
00859     // Manager Terminator
00860     //------------------------------------------------------------
00861     class Terminator
00862       : public ACE_Task<ACE_MT_SYNCH>
00863     {
00864     public:
00865       Terminator(Manager* manager) : m_manager(manager) {};
00866       void terminate()
00867       {
00868         open(0);
00869       }
00870       virtual int open(void *args)
00871       {
00872         activate();
00873         return 0;
00874       }
00875       virtual int svc(void)
00876       {
00877         Manager::instance().shutdown();
00878         return 0;
00879       }
00880       Manager* m_manager;
00881     };
00882 
00883     Terminator* m_terminator;
00884 
00885     struct Term
00886     {
00887       int waiting;
00888       ACE_Thread_Mutex mutex;
00889     };
00890     Term m_terminate;
00891 
00892 
00893 
00894   }; // class Manager
00895 }; // namespace RTC
00896 
00897 #endif // Manager_h

OpenRTMに対してTue May 29 16:45:15 2007に生成されました。  doxygen 1.4.1