00001
00020 #ifndef __RtcManager_h__
00021 #define __RtcManager_h__
00022
00023
00024
00025
00026
00027
00028 #include <list>
00029 #include <map>
00030 #include <memory>
00031 #include <string>
00032 #include <vector>
00033 #include <fstream>
00034
00035
00036 #include <ace/DLL.h>
00037
00038
00039 #include <boost/function.hpp>
00040 #include <boost/bind.hpp>
00041
00042
00043 #include "rtm/idl/RTCManagerSkel.h"
00044 #include "rtm/idl/RTCManagerStub.h"
00045 #include "rtm/RtcModuleProfile.h"
00046 #include "rtm/RtcBase.h"
00047 #include "rtm/RtcFactory.h"
00048
00049
00050
00051 namespace RTM
00052 {
00053
00054
00055 using namespace std;
00056
00057
00058
00059 class RtcManager;
00060 class RtcNaming;
00061 class RtcConfig;
00062
00063 #define RtcMgrCmd boost::function2<bool, vector<string>&, vector<string>& >
00064
00065 typedef void (*RtcModuleInitProc)(RtcManager* manager);
00066
00089 class RtcManager :
00090 public virtual POA_RTM::RTCManager,
00091 public virtual PortableServer::RefCountServantBase,
00092 public ACE_Task<ACE_MT_SYNCH>
00093 {
00094
00095 public:
00110 RtcManager(int argc, char** argv);
00111
00119 virtual ~RtcManager();
00120
00128
00129
00137 int svc(void);
00138
00139
00140
00141
00142
00143
00144
00145
00166 virtual RtmRes load(const char* pathname, const char* initfunc);
00167
00185 virtual RtmRes unload(const char* pathname);
00186
00206 virtual RTCBase_ptr create_component(const char* comp_name,
00207 CORBA::String_out instance_name);
00208
00226 virtual RtmRes delete_component(const char* instance_name);
00227
00241 virtual ComponentFactoryList* component_factory_list();
00242
00256 virtual RTCBaseList* component_list();
00257
00271 virtual RtmRes command(const char* cmd, CORBA::String_out ret);
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00292 void initManager();
00293
00303 void runManager();
00304
00314 void runManagerNoBlocking();
00315
00325 bool activateManager();
00326
00336 void initModuleProc(RtcModuleInitProc proc);
00337
00347 bool createCommand(string cmd,
00348 boost::function2<bool,
00349 vector<string>&, vector<string>&> func);
00350
00360 bool registerComponent(RtcModuleProfile& profile,
00361 RtcNewFunc new_func,
00362 RtcDeleteFunc delete_func);
00363
00373 bool registerComponent(RtcFactoryBase* factory);
00374
00375
00385 RtcBase* createComponent(const string& module_name, string& comp_name);
00386
00396 RtcBase* createComponent(const string& module_name);
00397
00398
00408 std::vector<RTCBase_ptr> findComponents(const string& comp_name);
00409
00419 std::string bindInOut(RTCBase_ptr comp_in,
00420 const std::string& inp_name,
00421 RTCBase_ptr comp_out,
00422 const std::string& outp_name,
00423 RTM::SubscriptionType sub_type = RTM::OPS_NEW);
00433 std::string bindInOutByName(const std::string& comp_name_in,
00434 const std::string& inp_name,
00435 const std::string& comp_name_out,
00436 const std::string& outp_name,
00437 RTM::SubscriptionType sub_type = RTM::OPS_NEW);
00438
00448 CORBA::ORB_var getORB();
00449
00459 PortableServer::POA_var getPOA();
00460
00461
00462
00463
00464 bool loadCmd(const vector<string>& cmd, vector<string>& retval);
00465 bool unloadCmd(const vector<string>& cmd, vector<string>& retval);
00466 bool createComponentCmd(const vector<string>& cmd, vector<string>& retval);
00467 bool listComponent(const vector<string>& cmd, vector<string>& retval);
00468 bool listModule(const vector<string>& cmd, vector<string>& retval);
00469 bool commandListCmd(const vector<string>& cmd, vector<string>& retval);
00470
00487 bool writeLog(int loglevel, std::string msg);
00488
00505 bool writeErrLog(int loglevel, std::string msg);
00506
00507 private:
00511 bool initORB();
00512
00516 bool initPOA();
00517
00518 bool initLogger();
00519
00520
00524 bool findPath(string path, string &full_path);
00525
00529 bool libnameToInitFunc(const char* libname,
00530 const char* initfunc,
00531 string &initfunc_name);
00532
00533
00534 private:
00542 auto_ptr<RtcConfig> m_apConfig;
00543
00551 auto_ptr<RtcNaming> m_apNaming;
00552
00560 CORBA::ORB_var m_pORB;
00561
00569 PortableServer::POA_var m_pPOA;
00570
00578 PortableServer::POAManager_var m_pPOAManager;
00579
00587 map<string, boost::function2<bool, vector<string>&, vector<string>&> > m_CmdMap;
00588
00596 list<string> m_LibraryLoadPath;
00597
00599
00600
00601
00602
00603
00604
00605
00606
00607
00615 struct FactoryMap {
00617 ACE_Thread_Mutex _mutex;
00619 map<string, RtcFactoryBase*> _map;
00620 };
00621
00629 FactoryMap m_FactoryMap;
00630
00638 struct DLL {
00639 int _refCount;
00640 ACE_DLL _dll;
00641 };
00642
00650 map<string, DLL> m_Lib;
00651 struct OstreamMtx
00652 {
00653 ACE_Thread_Mutex _mutex;
00654 std::ofstream _stream;
00655 };
00656 OstreamMtx m_Log;
00657 OstreamMtx m_ErrLog;
00658
00659
00660 public:
00668 struct ComponentDB {
00669 RtcBase& _component;
00670 RtcModuleProfile& _mod_profile;
00671 };
00679 map<string, RtcBase*> m_Components;
00680
00688 typedef bool (*RtcComponentInit)(RtcManager* manager);
00689
00697 string m_ManagerName;
00698
00699 };
00700
00701
00702 };
00703
00704 #endif //