00001
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef Manager_h
00041 #define Manager_h
00042
00043 #include <iostream>
00044 #include <string>
00045 #include <vector>
00046
00047 #include <ace/Synch.h>
00048 #include <ace/Task.h>
00049
00050 #include <rtm/Factory.h>
00051 #include <rtm/ObjectManager.h>
00052 #include <rtm/RTObject.h>
00053 #include <rtm/SystemLogger.h>
00054
00055 class Properties;
00056
00057 namespace RTC
00058 {
00059 class CorbaNaming;
00060 class ModuleManager;
00061 class NamingManager;
00062 class CorbaObjectManager;
00063 class Manager;
00064
00065 typedef void (*ModuleInitProc)(Manager* manager);
00066
00067 class Manager
00068 {
00069 protected:
00070 Manager();
00071 Manager(const Manager& manager);
00072
00073
00074 public:
00075
00076
00109 static Manager* init(int argc, char** argv);
00110
00111
00134 static Manager& instance();
00135
00136
00137
00138
00139
00140
00165 void setModuleInitProc(ModuleInitProc proc);
00166
00167
00195 bool activateManager();
00196
00227 void runManager(bool no_block = false);
00228
00229
00230
00231
00232
00233
00234
00256 void load(const char* fname, const char* initfunc);
00257
00258
00279 void unload(const char* fname);
00280
00281
00297 void unloadAll();
00298
00299
00307 std::vector<std::string> Manager::getLoadedModules();
00308
00309
00317 std::vector<std::string> getLoadableModules();
00318
00319
00320
00321
00329 bool registerFactory(Properties profile,
00330 RtcNewFunc new_func,
00331 RtcDeleteFunc delete_func);
00332
00340 std::vector<std::string> getModulesFactories();
00341
00342
00343
00344
00352 RtcBase* createComponent(const char* module_name);
00353
00361 bool registerComponent(RtcBase* comp);
00362
00370 void deleteComponent(const char* instance_name);
00371
00379 RtcBase* getComponent(const char* instance_name);
00380
00388 std::vector<RtcBase*> getComponents();
00389
00390
00391
00392
00393
00401 CORBA::ORB_ptr getORB();
00402
00410 PortableServer::POA_ptr getPOA();
00411 PortableServer::POAManager_ptr getPOAManager();
00412
00413
00414 protected:
00422 void initManager(int argc, char** argv);
00423
00424
00432 bool initORB();
00433
00434
00442 bool initNaming();
00443
00444
00452 bool initLogger();
00453
00454
00455
00456 bool mergeProperty(Properties& prop, const char* file_name);
00457 std::string formatString(const char* naming_format,
00458 Properties& prop);
00459
00460
00461
00462
00470 static Manager* manager;
00471
00479 static ACE_Thread_Mutex mutex;
00480
00488 CORBA::ORB_var m_pORB;
00489
00497 PortableServer::POA_var m_pPOA;
00498
00506 PortableServer::POAManager_var m_pPOAManager;
00507
00508
00509 ModuleInitProc m_initProc;
00510
00518 Properties* m_config;
00519
00527 ModuleManager* m_module;
00528
00536 NamingManager* m_namingManager;
00537
00538 CorbaObjectManager* m_objManager;
00539
00540
00548 Logbuf m_Logbuf;
00549
00557 MedLogbuf m_MedLogbuf;
00558
00566 LogStream rtcout;
00567
00568
00569
00570
00571
00572
00573 struct InstanceName
00574 {
00575 InstanceName(RtcBase* comp) : m_name(comp->getInstanceName()) {};
00576 InstanceName(const char* name) : m_name(name) {};
00577 bool operator()(RtcBase* comp)
00578 {
00579 return m_name == comp->getInstanceName();
00580 }
00581 std::string m_name;
00582 };
00583
00584 typedef ObjectManager<std::string,
00585 RtcBase,
00586 InstanceName> ComponentManager;
00594 ComponentManager m_compManager;
00595
00596
00597
00598
00599
00600
00601 struct FactoryPredicate
00602 {
00603 FactoryPredicate(const char* name) : m_name(name){};
00604 FactoryPredicate(FactoryBase* factory)
00605 : m_name(factory->profile().getProperty("implementation_id")) {};
00606 bool operator()(FactoryBase* factory)
00607 {
00608 return m_name == factory->profile().getProperty("implementation_id");
00609 }
00610 std::string m_name;
00611 };
00619 typedef ObjectManager<const char*,
00620 FactoryBase,
00621 FactoryPredicate> FactoryManager;
00629 FactoryManager m_factory;
00630
00631
00632 struct ModuleFactories
00633 {
00634 void operator()(FactoryBase* f)
00635 {
00636 modlist.push_back(f->profile().getProperty("implementation_id"));
00637 }
00638 std::vector<std::string> modlist;
00639 };
00640
00641
00642 class OrbRunner
00643 : public ACE_Task<ACE_MT_SYNCH>
00644 {
00645 public:
00646 OrbRunner(CORBA::ORB_ptr orb) : m_pORB(orb)
00647 {
00648 open(0);
00649 };
00650 virtual int open(void *args)
00651 {
00652 activate();
00653 return 0;
00654 }
00655 virtual int svc(void)
00656 {
00657 m_pORB->run();
00658 return 0;
00659 }
00660 virtual int close(unsigned long flags)
00661 {
00662 return 0;
00663 }
00664 private:
00665 CORBA::ORB_ptr m_pORB;
00666
00667 };
00668 OrbRunner* m_runner;
00669
00670 };
00671 };
00672
00673 #endif // Manager_h