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

RtcManager.h

説明を見る。
00001 // -*- C++ -*-
00019 /*
00020  * $Log: RtcManager.h,v $
00021  * Revision 1.2  2005/05/16 06:19:56  n-ando
00022  * - RtcManager class was DLL exported for Windows port.
00023  * - Some bugs were fixed.
00024  *
00025  * Revision 1.1.1.1  2005/05/12 09:06:18  n-ando
00026  * Public release.
00027  *
00028  *
00029  */
00030 
00031 #ifndef RtcManager_h
00032 #define RtcManager_h
00033 
00034 
00035 // CORBA includes
00036 //#include <RTC.h>
00037 
00038 // STL includes
00039 #include <list>
00040 #include <map>
00041 #include <memory>
00042 #include <string>
00043 #include <vector>
00044 #include <fstream>
00045 
00046 // ACE includes
00047 #include <ace/DLL.h>
00048 #include <ace/Signal.h>
00049 
00050 // Boost includes
00051 #include <boost/function.hpp>
00052 #include <boost/bind.hpp>
00053 
00054 // CORBA stub include
00055 #include "rtm/idl/RTCManagerSkel.h"
00056 #include "rtm/idl/RTCManagerStub.h"
00057 #include "rtm/RtcModuleProfile.h"
00058 #include "rtm/RtcBase.h"
00059 #include "rtm/RtcFactory.h"
00060 #include "rtm/RtcSystemLogger.h"
00061 
00062 // RTM includes
00063 
00064 namespace RTM
00065 {
00066   
00067   // Use std:: namespace
00068   using namespace std;
00069   
00070   // Pre-declaration of classes
00071   
00072   class RtcManager;
00073   class RtcNaming;
00074   class RtcConfig;
00075   
00076 #define RtcMgrCmd boost::function2<bool, vector<string>&, vector<string>& > 
00077   
00078   typedef void (*RtcModuleInitProc)(RtcManager* manager);  
00079   
00102   class EXPORTS RtcManager :
00103     public virtual POA_RTM::RTCManager, 
00104                                                         public virtual PortableServer::RefCountServantBase,
00105                                                                                                                    public ACE_Task<ACE_MT_SYNCH>
00106   {
00107         
00108   public:
00123     RtcManager(int argc, char** argv);
00124         void shutdown();
00132     virtual ~RtcManager();
00133         
00141         int open(void *args);
00142         
00150         int svc(void);
00151 
00152         int close(unsigned long flags);
00153         
00154     //============================================================
00155     //
00156     // <<< CORBA interfaces >>>
00157     //
00158     //============================================================
00159         
00160         
00181     virtual RtmRes load(const char* pathname, const char* initfunc);
00182         
00200     virtual RtmRes unload(const char* pathname);
00201         
00221     virtual RTCBase_ptr create_component(const char* module_name,
00222                                                                                  const char* category_name,
00223                                                                                  CORBA::String_out instance_name);
00224         
00244     virtual RtmRes delete_component(const char* instance_name,
00245                                                                         const char* category_name);
00246         
00260     virtual RTCFactoryList* factory_list();
00261         
00275     virtual RTCBaseList* component_list();
00276         
00290     virtual RtmRes command(const char* cmd, CORBA::String_out ret);
00291         
00292     // end of CORBA interface definition
00293     //============================================================
00294         
00295         
00296         
00297     //============================================================
00298     //
00299     // <<< Local interfaces >>>
00300     //
00301     //============================================================
00311     void initManager();
00312         
00322     void runManager();
00323         
00333     void runManagerNoBlocking();
00334         
00344     bool activateManager();
00345         
00355         void initModuleProc(RtcModuleInitProc proc);
00356         
00366     bool createCommand(string cmd,
00367                                            boost::function2<bool,
00368                                            vector<string>&, vector<string>&>  func);
00369         
00379     bool registerComponent(RtcModuleProfile& profile,
00380                                                    RtcNewFunc new_func,
00381                                                    RtcDeleteFunc delete_func);
00382         
00392         bool registerComponent(RtcFactoryBase* factory);
00393         
00394         
00404     RtcBase* createComponent(const string& module_name,
00405                                                          const string& category_name,
00406                                                          string& comp_name);
00407         
00417     RtcBase* createComponent(const string& module_name,
00418                                                          const string& category_name);
00419 
00420         
00430     void cleanupComponent(const string& instance_name,
00431                                                   const string& category_name);
00432         
00433         
00443     std::vector<RTCBase_ptr> findComponents(const string& comp_name);
00444         
00454     std::string bindInOut(RTCBase_ptr comp_in,
00455                                                   const std::string& inp_name,
00456                                                   RTCBase_ptr comp_out,
00457                                                   const std::string& outp_name,
00458                                                   RTM::SubscriptionType sub_type = RTM::OPS_NEW);
00468     std::string bindInOutByName(const std::string& comp_name_in,
00469                                                                 const std::string& inp_name,
00470                                                                 const std::string& comp_name_out,
00471                                                                 const std::string& outp_name,
00472                                                                 RTM::SubscriptionType sub_type = RTM::OPS_NEW);
00473         
00483     CORBA::ORB_var getORB();
00484         
00494     PortableServer::POA_var getPOA();
00495 
00496         RtcLogbuf& getLogbuf() {return m_Logbuf;}
00497         RtcConfig& getConfig() {return (*m_apConfig);}
00498 
00499 
00500         
00501     //============================================================
00502     // Commands
00503         
00504     bool loadCmd(const vector<string>& cmd, vector<string>& retval);
00505     bool unloadCmd(const vector<string>& cmd, vector<string>& retval);
00506     bool createComponentCmd(const vector<string>& cmd, vector<string>& retval);
00507     bool listComponent(const vector<string>& cmd, vector<string>& retval);
00508     bool listModule(const vector<string>& cmd, vector<string>& retval);
00509     bool commandListCmd(const vector<string>& cmd, vector<string>& retval);
00510 
00511   private:
00515     bool initORB();
00516         
00520     bool initPOA();
00521 
00522         bool initLogger();
00523         bool initMasterLogger();
00524         void loadMasterLogger();
00525 
00526         
00530     bool findPath(string path, string &full_path);
00531         
00535     bool libnameToInitFunc(const char* libname,
00536                                                    const char* initfunc,
00537                                                    string &initfunc_name);
00538         
00539         void shutdownAllComponents();
00540         
00541   private:
00549     auto_ptr<RtcConfig> m_apConfig;
00550         
00558     auto_ptr<RtcNaming> m_apNaming;
00559         
00567     CORBA::ORB_var m_pORB;
00568         
00576     PortableServer::POA_var m_pPOA;
00577         
00585     PortableServer::POAManager_var m_pPOAManager;
00586         
00594     map<string, boost::function2<bool, vector<string>&, vector<string>&> > m_CmdMap;
00595         
00603     list<string> m_LibraryLoadPath;
00604         
00606         /*    struct Factory {
00607                   
00608         RtcModuleProfile _profile;
00609         RtcNewFunc _new;
00610         RtcDeleteFunc _delete;
00611         int _num;
00612     };
00613         */
00614         
00622         struct FactoryMap {
00624       ACE_Thread_Mutex _mutex;
00626           std::map<std::string, std::map<std::string, RtcFactoryBase*> > _map;
00627         };
00628         
00636         FactoryMap m_FactoryMap;
00637         
00645     struct DLL {
00646       int _refCount;
00647       ACE_DLL _dll;
00648     };
00649         
00657     map<string, DLL> m_Lib; // Library name <=> DLL manager
00658 
00659         ACE_Sig_Action* m_SigAction;
00660         ACE_Sig_Action* m_SigHupAction;
00661         ACE_Sig_Action* m_SigIntAction;
00662         ACE_Sig_Action* m_SigKillAction;
00663         ACE_Sig_Action* m_SigSegvAction;
00664         ACE_Sig_Action* m_SigBusAction;
00665 
00666   public:
00674     struct ComponentMap {
00676       ACE_Thread_Mutex _mutex;
00677       std::map<string, std::map<string, RtcBase*> > _map;
00678     };
00689     ComponentMap m_Components;
00690         
00698     typedef bool (*RtcComponentInit)(RtcManager* manager);
00699         
00707     string m_ManagerName;
00708 
00716         RtcLogbuf m_Logbuf;
00724         RtcMedLogbuf m_MedLogbuf;
00732         RtcLogStream rtcout;
00733 
00734         TimedString m_LoggerOut;
00735         typedef OutPortAny<TimedString> LogOutPort;
00736         LogOutPort* m_pLoggerOutPort;
00737 
00738         class LogEmitter
00739           : public RtcSyncCallback
00740         {
00741         public:
00742           LogEmitter(OutPortAny<TimedString>& port, TimedString& var)
00743                 : m_OutPort(port), m_Var(var)
00744           {
00745           }
00746           virtual int operator()(const char* s)
00747           {
00748                 m_Var.data = CORBA::string_dup(s);
00749                 m_OutPort.write();
00750                 return true;
00751           }
00752         protected:
00753           OutPortAny<TimedString>& m_OutPort;
00754           TimedString& m_Var;
00755         };
00756         
00757         LogEmitter* m_pLogEmitter;
00758         RTCBase_var m_pMasterLogger;    
00759   };
00760 
00761 
00762 }; // end of namespace RTM
00763 
00764 #endif // RtcManager_h

OpenRTMに対してFri Sep 9 14:43:40 2005に生成されました。 doxygen 1.3.6