Manager.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef RTC_MANAGER_H
21 #define RTC_MANAGER_H
22 
23 #include <rtm/RTC.h>
24 
25 #include <iostream>
26 #include <string>
27 #include <vector>
28 
29 #include <coil/Mutex.h>
30 #include <coil/Guard.h>
31 #include <coil/Task.h>
32 
33 #include <rtm/Factory.h>
34 #include <rtm/ECFactory.h>
35 #include <rtm/ObjectManager.h>
36 #include <rtm/SystemLogger.h>
37 
38 namespace RTM
39 {
40  class ManagerServant;
41 }
42 
43 namespace coil
44 {
45  class Timer;
46 };
47 
48 namespace RTC
49 {
50 // class Properties;
51  class CorbaNaming;
52  class ModuleManager;
53  class NamingManager;
54  class Manager;
56  typedef RTObject_impl RtcBase;
57 
58  typedef void (*ModuleInitProc)(Manager* manager);
59 
80  class Manager
81  {
82  typedef coil::Mutex Mutex;
84  protected:
98  Manager();
99 
117  Manager(const Manager& manager);
118  // Manager& operator=(const Manager& manager){return manager;};
119 
120  public:
173  static Manager* init(int argc, char** argv);
174 
197  static Manager& instance();
198 
199  //============================================================
200  // Manager
201  //============================================================
202 
216  void terminate();
217 
233  void shutdown();
234 
248  void join();
249 
268 
286  std::string& getLogLevel() {return m_config["logger.log_level"];}
287 
305  coil::Properties& getConfig() { return m_config;}
306 
331  void setModuleInitProc(ModuleInitProc proc);
332 
365  bool activateManager();
366 
397  void runManager(bool no_block = false);
398 
399  //============================================================
400  // Module management
401  //============================================================
424  void load(const char* fname, const char* initfunc);
425 
445  void unload(const char* fname);
446 
462  void unloadAll();
463 
481  std::vector<coil::Properties> getLoadedModules();
482 
502  std::vector<coil::Properties> getLoadableModules();
503 
504  //============================================================
505  // Component Factory Management
506  //============================================================
533  bool registerFactory(coil::Properties& profile,
534  RtcNewFunc new_func,
535  RtcDeleteFunc delete_func);
536 
554  std::vector<coil::Properties> getFactoryProfiles();
555 
582  bool registerECFactory(const char* name,
583  ECNewFunc new_func,
584  ECDeleteFunc delete_func);
585 
603  std::vector<std::string> getModulesFactories();
604 
605  //============================================================
606  // Component management
607  //============================================================
666  RTObject_impl* createComponent(const char* comp_args);
680  ExecutionContextBase* createContext(const char* ec_args);
681 
700  void cleanupComponent(RTObject_impl* comp);
701 
715  void cleanupComponents();
716 
735  void notifyFinalized(RTObject_impl* comp);
736 
760  bool registerComponent(RTObject_impl* comp);
761 
783  bool unregisterComponent(RTObject_impl* comp);
784 
785 
807  void deleteComponent(RTObject_impl* comp);
808 
831  void deleteComponent(const char* instance_name);
832 
833 
857  RTObject_impl* getComponent(const char* instance_name);
858 
876  std::vector<RTObject_impl*> getComponents();
877 
878  //============================================================
879  // CORBA 関連
880  //============================================================
898  CORBA::ORB_ptr getORB();
899 
917  PortableServer::POA_ptr getPOA();
918 
936  PortableServer::POAManager_ptr getPOAManager();
937 
938  //============================================================
939  // Protected functions
940  //============================================================
941  protected:
942 
943  //============================================================
944  // Manager initialize and finalization
945  //============================================================
973  void initManager(int argc, char** argv);
974 
990  void shutdownManager();
991 
1008  void shutdownOnNoRtcs();
1009 
1010  //============================================================
1011  // Logger initialize and terminator
1012  //============================================================
1034  bool initLogger();
1035 
1053  void shutdownLogger();
1054 
1055  //============================================================
1056  // ORB initialization and finalization
1057  //============================================================
1075  bool initORB();
1076 
1096  std::string createORBOptions();
1097 
1115  void createORBEndpoints(coil::vstring& endpoints);
1116 
1130  void createORBEndpointOption(std::string& opt, coil::vstring& endpoint);
1131 
1150  void shutdownORB();
1151 
1152  //============================================================
1153  // NamingService initialization and finalization
1154  //============================================================
1186  bool initNaming();
1187 
1203  void shutdownNaming();
1204 
1205  //============================================================
1206  // Component management
1207  //============================================================
1223  void shutdownComponents();
1224 
1225 
1273  bool procComponentArgs(const char* comp_arg,
1274  coil::Properties& comp_id,
1275  coil::Properties& comp_conf);
1316  bool procContextArgs(const char* ec_args,
1317  std::string& ec_id,
1318  coil::Properties& ec_conf);
1319 
1342  void configureComponent(RTObject_impl* comp, const coil::Properties& prop);
1343 
1365  bool initExecContext();
1366 
1382  bool initComposite();
1383 
1405  bool initFactories();
1406 
1426  bool initTimer();
1427 
1441  bool initManagerServant();
1442 
1451 
1477  bool mergeProperty(coil::Properties& prop, const char* file_name);
1478 
1527  std::string formatString(const char* naming_format,
1528  coil::Properties& prop);
1529 
1530 
1531 
1532  //============================================================
1533  // protected 変数 //============================================================ //------------------------------------------------------------ // static var //------------------------------------------------------------ /*! * @if jp * @brief 唯一の Manager へのポインタ * @else * @brief The pointer to the Manager * @endif */ static Manager* manager; /*! * @if jp * @brief 唯一の Manager へのポインタに対する mutex * @else * @brief The mutex of the pointer to the Manager * @endif */ static Mutex mutex; //------------------------------------------------------------ // CORBA var //------------------------------------------------------------ /*! * @if jp * @brief ORB へのポインタ * @else * @brief The pointer to the ORB * @endif */ CORBA::ORB_var m_pORB; /*! * @if jp * @brief POA へのポインタ * @else * @brief The pointer to the POA * @endif */ PortableServer::POA_var m_pPOA; /*! * @if jp * @brief POAManager へのポインタ * @else * @brief The pointer to the POAManager * @endif */ PortableServer::POAManager_var m_pPOAManager; //------------------------------------------------------------ // Manager's variable //------------------------------------------------------------ /*! * @if jp * @brief ユーザ初期化関数へのポインタ * @else * @brief User's initialization function's pointer * @endif */ ModuleInitProc m_initProc; /*! * @if jp * @brief Manager の configuration を格納する Properties * @else * @brief Managaer's configuration Properties * @endif */ coil::Properties m_config; /*! * @if jp * @brief ModuleManager へのポインタ * @else * @brief The pointer to the ModuleManager * @endif */ ModuleManager* m_module; /*! * @if jp * @brief NamingManager へのポインタ * @else * @brief The pointer to the NamingManager * @endif */ NamingManager* m_namingManager; /*! * @if jp * @brief Timer Object * @else * @brief Timer Object * @endif */ coil::Timer* m_timer; //------------------------------------------------------------ // Logger //------------------------------------------------------------ /*! * @if jp * @brief ロガーバッファ * @else * @brief Logger buffer * @endif */ LogStreamBuf m_logStreamBuf; /*! * @if jp * @brief ロガーストリーム * @else * @brief Logger stream * @endif */ Logger rtclog; /*! * @if jp * @brief ログ出力ファイル * @else * @brief Files for log output * @endif */ std::vector<std::filebuf*> m_logfiles; //============================================================ // コンポーネントマネージャ //============================================================ // ObjectManager へ渡す述語クラス struct InstanceName { InstanceName(RTObject_impl* comp); InstanceName(const char* name); InstanceName(const std::string name); bool operator()(RTObject_impl* comp); std::string m_name; }; typedef ObjectManager<std::string, RTObject_impl, InstanceName> ComponentManager; /*! * @if jp * @brief コンポーネントマネージャ * @else * @brief ComponentManager * @endif */ ComponentManager m_compManager; //============================================================ // コンポーネントファクトリ //============================================================ // コンポーネントファクトリへ渡す述語クラス class FactoryPredicate { public: FactoryPredicate(const char* imple_id) : m_vendor(""), m_category(""), m_impleid(imple_id), m_version("") { } FactoryPredicate(const coil::Properties& prop) : m_vendor(prop["vendor"]), m_category(prop["category"]), m_impleid(prop["implementation_id"]), m_version(prop["version"]) { } FactoryPredicate(FactoryBase* factory) : m_vendor(factory->profile()["vendor"]), m_category(factory->profile()["category"]), m_impleid(factory->profile()["implementation_id"]), m_version(factory->profile()["version"]) { } bool operator()(FactoryBase* factory) { // implementation_id must not be empty if (m_impleid.empty()) return false; const coil::Properties& prop(factory->profile()); if (m_impleid != prop["implementation_id"]) return false; if (!m_vendor.empty() && m_vendor != prop["vendor"]) return false; if (!m_category.empty() && m_category != prop["category"]) return false; if (!m_version.empty() && m_version != prop["version"]) return false; return true; } private: std::string m_vendor; std::string m_category; std::string m_impleid; std::string m_version; }; class ModulePredicate { coil::Properties& m_prop; public: ModulePredicate(coil::Properties& prop) : m_prop(prop) { } bool operator()(coil::Properties& prop) { if (m_prop["implementation_id"] != prop["implementation_id"]) { return false; } if (!m_prop["vendor"].empty() && m_prop["vendor"] != prop["vendor"]) { return false; } if (!m_prop["category"].empty() && m_prop["category"] != prop["category"]) { return false; } if (!m_prop["version"].empty() && m_prop["version"] != prop["version"]) { return false; } return true; } }; /*! * @if jp * @brief コンポーネントファクトリ * @else * @brief ComponentFactory * @endif */ typedef ObjectManager<const coil::Properties, FactoryBase, FactoryPredicate> FactoryManager; /*! * @if jp * @brief ComponentManager * @else * @brief ComponentManager * @endif */ FactoryManager m_factory; //============================================================ // ExecutionContextファクトリ //============================================================ // ECファクトリへ渡す述語クラス struct ECFactoryPredicate { ECFactoryPredicate(const char* name) : m_name(name){}; ECFactoryPredicate(ECFactoryBase* factory) : m_name(factory->name()) {}; bool operator()(ECFactoryBase* factory) { return m_name == factory->name(); } std::string m_name; }; typedef ObjectManager<const char*, ECFactoryBase, ECFactoryPredicate> ECFactoryManager; /*! * @if jp * @brief ExecutionContext マネージャ * @else * @brief ExecutionContext Manager * @endif */ ECFactoryManager m_ecfactory; /*! * @if jp * @brief ExecutionContext リスト * @else * @brief ExecutionContext list * @endif */ std::vector<ExecutionContextBase*> m_ecs; // ファクトリ名をリストアップするためのファンクタ struct ModuleFactories { void operator()(FactoryBase* f) { modlist.push_back(f->profile().getProperty("implementation_id")); } std::vector<std::string> modlist; }; //------------------------------------------------------------ // ORB runner //------------------------------------------------------------ /*! * @if jp * @class OrbRunner * @brief OrbRunner クラス * * ORB 実行用ヘルパークラス。 * * @since 0.4.0 * * @else * @class OrbRunner * @brief OrbRunner class * * ORB exrcution helper class * * @since 0.4.0 * * @endif */ class OrbRunner : public coil::Task { public: /*! * @if jp * @brief コンストラクタ * * コンストラクタ * * @else * @brief Constructor * * Constructor * * @endif */ OrbRunner(CORBA::ORB_ptr orb) : m_pORB(orb) { open(0); }; /*! * @if jp * @brief ORB 活性化処理 * * ORB 活性化処理 * * @param args 活性化時引数 * * @return 活性化結果 * * @else * @brief ORB activation processing * * ORB activation processing. * * @param args ORB activation processing * * @return Activation result * * @endif */ virtual int open(void *args) { activate(); return 0; } /*! * @if jp * @brief ORB 開始処理 * * ORB 開始処理 * * @return 開始処理結果 * * @else * @brief ORB start processing * * ORB start processing * * @return Starting result * * @endif */ virtual int svc(void) { m_pORB->run(); // Manager::instance().shutdown(); return 0; } /*! * @if jp * @brief ORB 終了処理 * * ORB 終了処理 * * @param flags 終了処理フラグ * * @return 終了処理結果 * * @else * @brief ORB close processing * * ORB close processing. * * @param flags Flag of close processing * * @return Close result * * @endif */ virtual int close(unsigned long flags) { return 0; } private: CORBA::ORB_ptr m_pORB; }; /*! * @if jp * @brief ORB ヘルパークラスへのポインタ * @else * @brief The pointer to ORB helper class * @endif */ OrbRunner* m_runner; //------------------------------------------------------------ // Manager Terminator //------------------------------------------------------------ /*! * @if jp * @class Terminator * @brief Terminator クラス * * ORB 終了用ヘルパークラス。 * * @since 0.4.0 * * @else * @class Terminator * @brief Terminator class * * ORB termination helper class. * * @since 0.4.0 * * @endif */ class Terminator : public coil::Task { public: /*! * @if jp * @brief コンストラクタ * * コンストラクタ * * @param manager マネージャ・オブジェクト * * @else * @brief Constructor * * Constructor * * @param manager Manager object * * @endif */ Terminator(Manager* manager) : m_manager(manager) {}; /*! * @if jp * @brief 終了処理 * * ORB,マネージャ終了処理を開始する。 * * @else * @brief Termination processing * * Start ORB and manager's termination processing. * * @endif */ void terminate() { open(0); } /*! * @if jp * @brief 終了処理活性化処理 * * 終了処理活性化処理 * * @param args 活性化時引数 * * @return 活性化結果 * * @else * @brief Termination processing activation * * Termination processing activation. * * @param args Activation argument * * @return Activation result * * @endif */ virtual int open(void *args) { activate(); return 0; } /*! * @if jp * @brief ORB,マネージャ終了処理 * * ORB,マネージャ終了処理 * * @return 終了処理結果 * * @else * @brief ORB and manager's termination processing * * ORB and manager's termination processing. * * @return Termination result * * @endif */ virtual int svc(void) { Manager::instance().shutdown(); return 0; } Manager* m_manager; }; /*! * @if jp * @brief ORB 終了用ヘルパークラスへのポインタ * @else * @brief The pointer to ORB termination helper class. * @endif */ Terminator* m_terminator; struct Term { int waiting; Mutex mutex; }; /*! * @if jp * @brief マネージャ終了処理用同期フラグ * * マネージャ終了の待ち合せ処理で同期を取るためのフラグ。 * * @else * @brief Synchronous flag for manager termination * * Flag used to take synchronization by join(). * * @endif */ Term m_terminate; struct Finalized { Mutex mutex; std::vector<RTObject_impl*> comps; }; Finalized m_finalized; }; // class Manager }; // namespace RTC #endif // RTC_MANAGER_H
1534  //============================================================
1535 
1536  //------------------------------------------------------------
1537  // static var
1538  //------------------------------------------------------------
1546  static Manager* manager;
1547 
1555  static Mutex mutex;
1556 
1557  //------------------------------------------------------------
1558  // CORBA var
1559  //------------------------------------------------------------
1567  CORBA::ORB_var m_pORB;
1568 
1576  PortableServer::POA_var m_pPOA;
1577 
1585  PortableServer::POAManager_var m_pPOAManager;
1586 
1587  //------------------------------------------------------------
1588  // Manager's variable
1589  //------------------------------------------------------------
1598 
1607 
1616 
1625 
1634 
1635  //------------------------------------------------------------
1636  // Logger
1637  //------------------------------------------------------------
1646 
1655 
1663  std::vector<std::filebuf*> m_logfiles;
1664 
1665  //============================================================
1666  // コンポーネントマネージャ //============================================================ // ObjectManager へ渡す述語クラス struct InstanceName { InstanceName(RTObject_impl* comp); InstanceName(const char* name); InstanceName(const std::string name); bool operator()(RTObject_impl* comp); std::string m_name; }; typedef ObjectManager<std::string, RTObject_impl, InstanceName> ComponentManager; /*! * @if jp * @brief コンポーネントマネージャ * @else * @brief ComponentManager * @endif */ ComponentManager m_compManager; //============================================================ // コンポーネントファクトリ //============================================================ // コンポーネントファクトリへ渡す述語クラス class FactoryPredicate { public: FactoryPredicate(const char* imple_id) : m_vendor(""), m_category(""), m_impleid(imple_id), m_version("") { } FactoryPredicate(const coil::Properties& prop) : m_vendor(prop["vendor"]), m_category(prop["category"]), m_impleid(prop["implementation_id"]), m_version(prop["version"]) { } FactoryPredicate(FactoryBase* factory) : m_vendor(factory->profile()["vendor"]), m_category(factory->profile()["category"]), m_impleid(factory->profile()["implementation_id"]), m_version(factory->profile()["version"]) { } bool operator()(FactoryBase* factory) { // implementation_id must not be empty if (m_impleid.empty()) return false; const coil::Properties& prop(factory->profile()); if (m_impleid != prop["implementation_id"]) return false; if (!m_vendor.empty() && m_vendor != prop["vendor"]) return false; if (!m_category.empty() && m_category != prop["category"]) return false; if (!m_version.empty() && m_version != prop["version"]) return false; return true; } private: std::string m_vendor; std::string m_category; std::string m_impleid; std::string m_version; }; class ModulePredicate { coil::Properties& m_prop; public: ModulePredicate(coil::Properties& prop) : m_prop(prop) { } bool operator()(coil::Properties& prop) { if (m_prop["implementation_id"] != prop["implementation_id"]) { return false; } if (!m_prop["vendor"].empty() && m_prop["vendor"] != prop["vendor"]) { return false; } if (!m_prop["category"].empty() && m_prop["category"] != prop["category"]) { return false; } if (!m_prop["version"].empty() && m_prop["version"] != prop["version"]) { return false; } return true; } }; /*! * @if jp * @brief コンポーネントファクトリ * @else * @brief ComponentFactory * @endif */ typedef ObjectManager<const coil::Properties, FactoryBase, FactoryPredicate> FactoryManager; /*! * @if jp * @brief ComponentManager * @else * @brief ComponentManager * @endif */ FactoryManager m_factory; //============================================================ // ExecutionContextファクトリ //============================================================ // ECファクトリへ渡す述語クラス struct ECFactoryPredicate { ECFactoryPredicate(const char* name) : m_name(name){}; ECFactoryPredicate(ECFactoryBase* factory) : m_name(factory->name()) {}; bool operator()(ECFactoryBase* factory) { return m_name == factory->name(); } std::string m_name; }; typedef ObjectManager<const char*, ECFactoryBase, ECFactoryPredicate> ECFactoryManager; /*! * @if jp * @brief ExecutionContext マネージャ * @else * @brief ExecutionContext Manager * @endif */ ECFactoryManager m_ecfactory; /*! * @if jp * @brief ExecutionContext リスト * @else * @brief ExecutionContext list * @endif */ std::vector<ExecutionContextBase*> m_ecs; // ファクトリ名をリストアップするためのファンクタ struct ModuleFactories { void operator()(FactoryBase* f) { modlist.push_back(f->profile().getProperty("implementation_id")); } std::vector<std::string> modlist; }; //------------------------------------------------------------ // ORB runner //------------------------------------------------------------ /*! * @if jp * @class OrbRunner * @brief OrbRunner クラス * * ORB 実行用ヘルパークラス。 * * @since 0.4.0 * * @else * @class OrbRunner * @brief OrbRunner class * * ORB exrcution helper class * * @since 0.4.0 * * @endif */ class OrbRunner : public coil::Task { public: /*! * @if jp * @brief コンストラクタ * * コンストラクタ * * @else * @brief Constructor * * Constructor * * @endif */ OrbRunner(CORBA::ORB_ptr orb) : m_pORB(orb) { open(0); }; /*! * @if jp * @brief ORB 活性化処理 * * ORB 活性化処理 * * @param args 活性化時引数 * * @return 活性化結果 * * @else * @brief ORB activation processing * * ORB activation processing. * * @param args ORB activation processing * * @return Activation result * * @endif */ virtual int open(void *args) { activate(); return 0; } /*! * @if jp * @brief ORB 開始処理 * * ORB 開始処理 * * @return 開始処理結果 * * @else * @brief ORB start processing * * ORB start processing * * @return Starting result * * @endif */ virtual int svc(void) { m_pORB->run(); // Manager::instance().shutdown(); return 0; } /*! * @if jp * @brief ORB 終了処理 * * ORB 終了処理 * * @param flags 終了処理フラグ * * @return 終了処理結果 * * @else * @brief ORB close processing * * ORB close processing. * * @param flags Flag of close processing * * @return Close result * * @endif */ virtual int close(unsigned long flags) { return 0; } private: CORBA::ORB_ptr m_pORB; }; /*! * @if jp * @brief ORB ヘルパークラスへのポインタ * @else * @brief The pointer to ORB helper class * @endif */ OrbRunner* m_runner; //------------------------------------------------------------ // Manager Terminator //------------------------------------------------------------ /*! * @if jp * @class Terminator * @brief Terminator クラス * * ORB 終了用ヘルパークラス。 * * @since 0.4.0 * * @else * @class Terminator * @brief Terminator class * * ORB termination helper class. * * @since 0.4.0 * * @endif */ class Terminator : public coil::Task { public: /*! * @if jp * @brief コンストラクタ * * コンストラクタ * * @param manager マネージャ・オブジェクト * * @else * @brief Constructor * * Constructor * * @param manager Manager object * * @endif */ Terminator(Manager* manager) : m_manager(manager) {}; /*! * @if jp * @brief 終了処理 * * ORB,マネージャ終了処理を開始する。 * * @else * @brief Termination processing * * Start ORB and manager's termination processing. * * @endif */ void terminate() { open(0); } /*! * @if jp * @brief 終了処理活性化処理 * * 終了処理活性化処理 * * @param args 活性化時引数 * * @return 活性化結果 * * @else * @brief Termination processing activation * * Termination processing activation. * * @param args Activation argument * * @return Activation result * * @endif */ virtual int open(void *args) { activate(); return 0; } /*! * @if jp * @brief ORB,マネージャ終了処理 * * ORB,マネージャ終了処理 * * @return 終了処理結果 * * @else * @brief ORB and manager's termination processing * * ORB and manager's termination processing. * * @return Termination result * * @endif */ virtual int svc(void) { Manager::instance().shutdown(); return 0; } Manager* m_manager; }; /*! * @if jp * @brief ORB 終了用ヘルパークラスへのポインタ * @else * @brief The pointer to ORB termination helper class. * @endif */ Terminator* m_terminator; struct Term { int waiting; Mutex mutex; }; /*! * @if jp * @brief マネージャ終了処理用同期フラグ * * マネージャ終了の待ち合せ処理で同期を取るためのフラグ。 * * @else * @brief Synchronous flag for manager termination * * Flag used to take synchronization by join(). * * @endif */ Term m_terminate; struct Finalized { Mutex mutex; std::vector<RTObject_impl*> comps; }; Finalized m_finalized; }; // class Manager }; // namespace RTC #endif // RTC_MANAGER_H
1667  //============================================================
1668  // ObjectManager へ渡す述語クラス
1670  {
1671  InstanceName(RTObject_impl* comp);
1672  InstanceName(const char* name);
1673  InstanceName(const std::string name);
1674  bool operator()(RTObject_impl* comp);
1675  std::string m_name;
1676  };
1677 
1679 
1687  ComponentManager m_compManager;
1688 
1689  //============================================================
1690  // コンポーネントファクトリ //============================================================ // コンポーネントファクトリへ渡す述語クラス class FactoryPredicate { public: FactoryPredicate(const char* imple_id) : m_vendor(""), m_category(""), m_impleid(imple_id), m_version("") { } FactoryPredicate(const coil::Properties& prop) : m_vendor(prop["vendor"]), m_category(prop["category"]), m_impleid(prop["implementation_id"]), m_version(prop["version"]) { } FactoryPredicate(FactoryBase* factory) : m_vendor(factory->profile()["vendor"]), m_category(factory->profile()["category"]), m_impleid(factory->profile()["implementation_id"]), m_version(factory->profile()["version"]) { } bool operator()(FactoryBase* factory) { // implementation_id must not be empty if (m_impleid.empty()) return false; const coil::Properties& prop(factory->profile()); if (m_impleid != prop["implementation_id"]) return false; if (!m_vendor.empty() && m_vendor != prop["vendor"]) return false; if (!m_category.empty() && m_category != prop["category"]) return false; if (!m_version.empty() && m_version != prop["version"]) return false; return true; } private: std::string m_vendor; std::string m_category; std::string m_impleid; std::string m_version; }; class ModulePredicate { coil::Properties& m_prop; public: ModulePredicate(coil::Properties& prop) : m_prop(prop) { } bool operator()(coil::Properties& prop) { if (m_prop["implementation_id"] != prop["implementation_id"]) { return false; } if (!m_prop["vendor"].empty() && m_prop["vendor"] != prop["vendor"]) { return false; } if (!m_prop["category"].empty() && m_prop["category"] != prop["category"]) { return false; } if (!m_prop["version"].empty() && m_prop["version"] != prop["version"]) { return false; } return true; } }; /*! * @if jp * @brief コンポーネントファクトリ * @else * @brief ComponentFactory * @endif */ typedef ObjectManager<const coil::Properties, FactoryBase, FactoryPredicate> FactoryManager; /*! * @if jp * @brief ComponentManager * @else * @brief ComponentManager * @endif */ FactoryManager m_factory; //============================================================ // ExecutionContextファクトリ //============================================================ // ECファクトリへ渡す述語クラス struct ECFactoryPredicate { ECFactoryPredicate(const char* name) : m_name(name){}; ECFactoryPredicate(ECFactoryBase* factory) : m_name(factory->name()) {}; bool operator()(ECFactoryBase* factory) { return m_name == factory->name(); } std::string m_name; }; typedef ObjectManager<const char*, ECFactoryBase, ECFactoryPredicate> ECFactoryManager; /*! * @if jp * @brief ExecutionContext マネージャ * @else * @brief ExecutionContext Manager * @endif */ ECFactoryManager m_ecfactory; /*! * @if jp * @brief ExecutionContext リスト * @else * @brief ExecutionContext list * @endif */ std::vector<ExecutionContextBase*> m_ecs; // ファクトリ名をリストアップするためのファンクタ struct ModuleFactories { void operator()(FactoryBase* f) { modlist.push_back(f->profile().getProperty("implementation_id")); } std::vector<std::string> modlist; }; //------------------------------------------------------------ // ORB runner //------------------------------------------------------------ /*! * @if jp * @class OrbRunner * @brief OrbRunner クラス * * ORB 実行用ヘルパークラス。 * * @since 0.4.0 * * @else * @class OrbRunner * @brief OrbRunner class * * ORB exrcution helper class * * @since 0.4.0 * * @endif */ class OrbRunner : public coil::Task { public: /*! * @if jp * @brief コンストラクタ * * コンストラクタ * * @else * @brief Constructor * * Constructor * * @endif */ OrbRunner(CORBA::ORB_ptr orb) : m_pORB(orb) { open(0); }; /*! * @if jp * @brief ORB 活性化処理 * * ORB 活性化処理 * * @param args 活性化時引数 * * @return 活性化結果 * * @else * @brief ORB activation processing * * ORB activation processing. * * @param args ORB activation processing * * @return Activation result * * @endif */ virtual int open(void *args) { activate(); return 0; } /*! * @if jp * @brief ORB 開始処理 * * ORB 開始処理 * * @return 開始処理結果 * * @else * @brief ORB start processing * * ORB start processing * * @return Starting result * * @endif */ virtual int svc(void) { m_pORB->run(); // Manager::instance().shutdown(); return 0; } /*! * @if jp * @brief ORB 終了処理 * * ORB 終了処理 * * @param flags 終了処理フラグ * * @return 終了処理結果 * * @else * @brief ORB close processing * * ORB close processing. * * @param flags Flag of close processing * * @return Close result * * @endif */ virtual int close(unsigned long flags) { return 0; } private: CORBA::ORB_ptr m_pORB; }; /*! * @if jp * @brief ORB ヘルパークラスへのポインタ * @else * @brief The pointer to ORB helper class * @endif */ OrbRunner* m_runner; //------------------------------------------------------------ // Manager Terminator //------------------------------------------------------------ /*! * @if jp * @class Terminator * @brief Terminator クラス * * ORB 終了用ヘルパークラス。 * * @since 0.4.0 * * @else * @class Terminator * @brief Terminator class * * ORB termination helper class. * * @since 0.4.0 * * @endif */ class Terminator : public coil::Task { public: /*! * @if jp * @brief コンストラクタ * * コンストラクタ * * @param manager マネージャ・オブジェクト * * @else * @brief Constructor * * Constructor * * @param manager Manager object * * @endif */ Terminator(Manager* manager) : m_manager(manager) {}; /*! * @if jp * @brief 終了処理 * * ORB,マネージャ終了処理を開始する。 * * @else * @brief Termination processing * * Start ORB and manager's termination processing. * * @endif */ void terminate() { open(0); } /*! * @if jp * @brief 終了処理活性化処理 * * 終了処理活性化処理 * * @param args 活性化時引数 * * @return 活性化結果 * * @else * @brief Termination processing activation * * Termination processing activation. * * @param args Activation argument * * @return Activation result * * @endif */ virtual int open(void *args) { activate(); return 0; } /*! * @if jp * @brief ORB,マネージャ終了処理 * * ORB,マネージャ終了処理 * * @return 終了処理結果 * * @else * @brief ORB and manager's termination processing * * ORB and manager's termination processing. * * @return Termination result * * @endif */ virtual int svc(void) { Manager::instance().shutdown(); return 0; } Manager* m_manager; }; /*! * @if jp * @brief ORB 終了用ヘルパークラスへのポインタ * @else * @brief The pointer to ORB termination helper class. * @endif */ Terminator* m_terminator; struct Term { int waiting; Mutex mutex; }; /*! * @if jp * @brief マネージャ終了処理用同期フラグ * * マネージャ終了の待ち合せ処理で同期を取るためのフラグ。 * * @else * @brief Synchronous flag for manager termination * * Flag used to take synchronization by join(). * * @endif */ Term m_terminate; struct Finalized { Mutex mutex; std::vector<RTObject_impl*> comps; }; Finalized m_finalized; }; // class Manager }; // namespace RTC #endif // RTC_MANAGER_H
1691  //============================================================
1692  // コンポーネントファクトリへ渡す述語クラス
1694  {
1695  public:
1696  FactoryPredicate(const char* imple_id)
1697  : m_vendor(""), m_category(""), m_impleid(imple_id), m_version("")
1698  {
1699  }
1701  : m_vendor(prop["vendor"]),
1702  m_category(prop["category"]),
1703  m_impleid(prop["implementation_id"]),
1704  m_version(prop["version"])
1705  {
1706  }
1708  : m_vendor(factory->profile()["vendor"]),
1709  m_category(factory->profile()["category"]),
1710  m_impleid(factory->profile()["implementation_id"]),
1711  m_version(factory->profile()["version"])
1712  {
1713  }
1714  bool operator()(FactoryBase* factory)
1715  {
1716  // implementation_id must not be empty
1717  if (m_impleid.empty()) return false;
1718 
1719  const coil::Properties& prop(factory->profile());
1720 
1721  if (m_impleid != prop["implementation_id"])
1722  return false;
1723  if (!m_vendor.empty() && m_vendor != prop["vendor"])
1724  return false;
1725  if (!m_category.empty() && m_category != prop["category"])
1726  return false;
1727  if (!m_version.empty() && m_version != prop["version"])
1728  return false;
1729 
1730  return true;
1731  }
1732  private:
1733  std::string m_vendor;
1734  std::string m_category;
1735  std::string m_impleid;
1736  std::string m_version;
1737  };
1738 
1740  {
1742  public:
1744  : m_prop(prop)
1745  {
1746  }
1748  {
1749  if (m_prop["implementation_id"] != prop["implementation_id"])
1750  {
1751  return false;
1752  }
1753  if (!m_prop["vendor"].empty() &&
1754  m_prop["vendor"] != prop["vendor"]) { return false; }
1755  if (!m_prop["category"].empty() &&
1756  m_prop["category"] != prop["category"]) { return false; }
1757  if (!m_prop["version"].empty() &&
1758  m_prop["version"] != prop["version"]) { return false; }
1759  return true;
1760  }
1761  };
1762 
1772 
1780  FactoryManager m_factory;
1781 
1782  //============================================================
1783  // ExecutionContextファクトリ //============================================================ // ECファクトリへ渡す述語クラス struct ECFactoryPredicate { ECFactoryPredicate(const char* name) : m_name(name){}; ECFactoryPredicate(ECFactoryBase* factory) : m_name(factory->name()) {}; bool operator()(ECFactoryBase* factory) { return m_name == factory->name(); } std::string m_name; }; typedef ObjectManager<const char*, ECFactoryBase, ECFactoryPredicate> ECFactoryManager; /*! * @if jp * @brief ExecutionContext マネージャ * @else * @brief ExecutionContext Manager * @endif */ ECFactoryManager m_ecfactory; /*! * @if jp * @brief ExecutionContext リスト * @else * @brief ExecutionContext list * @endif */ std::vector<ExecutionContextBase*> m_ecs; // ファクトリ名をリストアップするためのファンクタ struct ModuleFactories { void operator()(FactoryBase* f) { modlist.push_back(f->profile().getProperty("implementation_id")); } std::vector<std::string> modlist; }; //------------------------------------------------------------ // ORB runner //------------------------------------------------------------ /*! * @if jp * @class OrbRunner * @brief OrbRunner クラス * * ORB 実行用ヘルパークラス。 * * @since 0.4.0 * * @else * @class OrbRunner * @brief OrbRunner class * * ORB exrcution helper class * * @since 0.4.0 * * @endif */ class OrbRunner : public coil::Task { public: /*! * @if jp * @brief コンストラクタ * * コンストラクタ * * @else * @brief Constructor * * Constructor * * @endif */ OrbRunner(CORBA::ORB_ptr orb) : m_pORB(orb) { open(0); }; /*! * @if jp * @brief ORB 活性化処理 * * ORB 活性化処理 * * @param args 活性化時引数 * * @return 活性化結果 * * @else * @brief ORB activation processing * * ORB activation processing. * * @param args ORB activation processing * * @return Activation result * * @endif */ virtual int open(void *args) { activate(); return 0; } /*! * @if jp * @brief ORB 開始処理 * * ORB 開始処理 * * @return 開始処理結果 * * @else * @brief ORB start processing * * ORB start processing * * @return Starting result * * @endif */ virtual int svc(void) { m_pORB->run(); // Manager::instance().shutdown(); return 0; } /*! * @if jp * @brief ORB 終了処理 * * ORB 終了処理 * * @param flags 終了処理フラグ * * @return 終了処理結果 * * @else * @brief ORB close processing * * ORB close processing. * * @param flags Flag of close processing * * @return Close result * * @endif */ virtual int close(unsigned long flags) { return 0; } private: CORBA::ORB_ptr m_pORB; }; /*! * @if jp * @brief ORB ヘルパークラスへのポインタ * @else * @brief The pointer to ORB helper class * @endif */ OrbRunner* m_runner; //------------------------------------------------------------ // Manager Terminator //------------------------------------------------------------ /*! * @if jp * @class Terminator * @brief Terminator クラス * * ORB 終了用ヘルパークラス。 * * @since 0.4.0 * * @else * @class Terminator * @brief Terminator class * * ORB termination helper class. * * @since 0.4.0 * * @endif */ class Terminator : public coil::Task { public: /*! * @if jp * @brief コンストラクタ * * コンストラクタ * * @param manager マネージャ・オブジェクト * * @else * @brief Constructor * * Constructor * * @param manager Manager object * * @endif */ Terminator(Manager* manager) : m_manager(manager) {}; /*! * @if jp * @brief 終了処理 * * ORB,マネージャ終了処理を開始する。 * * @else * @brief Termination processing * * Start ORB and manager's termination processing. * * @endif */ void terminate() { open(0); } /*! * @if jp * @brief 終了処理活性化処理 * * 終了処理活性化処理 * * @param args 活性化時引数 * * @return 活性化結果 * * @else * @brief Termination processing activation * * Termination processing activation. * * @param args Activation argument * * @return Activation result * * @endif */ virtual int open(void *args) { activate(); return 0; } /*! * @if jp * @brief ORB,マネージャ終了処理 * * ORB,マネージャ終了処理 * * @return 終了処理結果 * * @else * @brief ORB and manager's termination processing * * ORB and manager's termination processing. * * @return Termination result * * @endif */ virtual int svc(void) { Manager::instance().shutdown(); return 0; } Manager* m_manager; }; /*! * @if jp * @brief ORB 終了用ヘルパークラスへのポインタ * @else * @brief The pointer to ORB termination helper class. * @endif */ Terminator* m_terminator; struct Term { int waiting; Mutex mutex; }; /*! * @if jp * @brief マネージャ終了処理用同期フラグ * * マネージャ終了の待ち合せ処理で同期を取るためのフラグ。 * * @else * @brief Synchronous flag for manager termination * * Flag used to take synchronization by join(). * * @endif */ Term m_terminate; struct Finalized { Mutex mutex; std::vector<RTObject_impl*> comps; }; Finalized m_finalized; }; // class Manager }; // namespace RTC #endif // RTC_MANAGER_H
1784  //============================================================
1785  // ECファクトリへ渡す述語クラス
1787  {
1788  ECFactoryPredicate(const char* name) : m_name(name){};
1790  : m_name(factory->name()) {};
1791  bool operator()(ECFactoryBase* factory)
1792  {
1793  return m_name == factory->name();
1794  }
1795  std::string m_name;
1796  };
1797  typedef ObjectManager<const char*,
1798  ECFactoryBase,
1800 
1808  ECFactoryManager m_ecfactory;
1809 
1817  std::vector<ExecutionContextBase*> m_ecs;
1818 
1819  // ファクトリ名をリストアップするためのファンクタ
1821  {
1822  void operator()(FactoryBase* f)
1823  {
1824  modlist.push_back(f->profile().getProperty("implementation_id"));
1825  }
1826  std::vector<std::string> modlist;
1827  };
1828 
1829  //------------------------------------------------------------
1830  // ORB runner
1831  //------------------------------------------------------------
1852  : public coil::Task
1853  {
1854  public:
1868  OrbRunner(CORBA::ORB_ptr orb) : m_pORB(orb)
1869  {
1870  open(0);
1871  };
1872 
1894  virtual int open(void *args)
1895  {
1896  activate();
1897  return 0;
1898  }
1899 
1917  virtual int svc(void)
1918  {
1919  m_pORB->run();
1920 // Manager::instance().shutdown();
1921  return 0;
1922  }
1923 
1945  virtual int close(unsigned long flags)
1946  {
1947  return 0;
1948  }
1949  private:
1950  CORBA::ORB_ptr m_pORB;
1951  };
1960 
1961  //------------------------------------------------------------
1962  // Manager Terminator
1963  //------------------------------------------------------------
1984  : public coil::Task
1985  {
1986  public:
2004  Terminator(Manager* manager) : m_manager(manager) {};
2005 
2019  void terminate()
2020  {
2021  open(0);
2022  }
2023 
2045  virtual int open(void *args)
2046  {
2047  activate();
2048  return 0;
2049  }
2050 
2068  virtual int svc(void)
2069  {
2070  Manager::instance().shutdown();
2071  return 0;
2072  }
2074  };
2075 
2084 
2085  struct Term
2086  {
2087  int waiting;
2088  Mutex mutex;
2089  };
2104 
2105  struct Finalized
2106  {
2107  Mutex mutex;
2108  std::vector<RTObject_impl*> comps;
2109  };
2111 
2112 
2113  }; // class Manager
2114 }; // namespace RTC
2115 
2116 #endif // RTC_MANAGER_H
RTObject_impl *(* RtcNewFunc)(Manager *manager)
Definition: rtm/Factory.h:33
static Mutex mutex
The mutex of the pointer to the Manager.
Definition: Manager.h:1555
LogStreamBuf & getLogStreamBuf()
Get the log buffer.
Definition: Manager.h:267
void(* ModuleInitProc)(Manager *manager)
Definition: Manager.h:58
Logger rtclog
Logger stream.
Definition: Manager.h:1654
std::vector< std::string > modlist
Definition: Manager.h:1826
RT-Component.
LogStreamBuf m_logStreamBuf
virtual coil::Properties & profile()
Get the component profile.
Definition: Factory.cpp:55
virtual int open(void *args)
ORB activation processing.
Definition: Manager.h:1894
Term m_terminate
Synchronous flag for manager termination.
Definition: Manager.h:2103
log_streambuf template class
FactoryManager m_factory
ComponentManager.
Definition: Manager.h:1780
Mutex class.
RT component logger class.
void terminate()
Termination processing.
Definition: Manager.h:2019
RTM::ManagerServant * m_mgrservant
The pointer to the ManagerServant.
Definition: Manager.h:1450
Manager CORBA class.
FactoryPredicate(const char *imple_id)
Definition: Manager.h:1696
A base class for ExecutionContext.
std::string & getLogLevel()
Get the log level of the configuration.
Definition: Manager.h:286
RT-Component class.
Definition: RTObject.h:89
Manager class.
Definition: Manager.h:80
ECFactoryPredicate(const char *name)
Definition: Manager.h:1788
coil::Timer * m_timer
Timer Object.
Definition: Manager.h:1633
CORBA::ORB_ptr m_pORB
Definition: Manager.h:1950
NamingManager * m_namingManager
The pointer to the NamingManager.
Definition: Manager.h:1624
OrbRunner(CORBA::ORB_ptr orb)
Constructor.
Definition: Manager.h:1868
virtual int svc(void)
ORB start processing.
Definition: Manager.h:1917
std::vector< std::string > vstring
Definition: stringutil.h:37
coil::Properties & getConfig()
Get the manager configuration.
Definition: Manager.h:305
static Manager * manager
The pointer to the Manager.
Definition: Manager.h:1546
ECFactoryBase abstract class.
Definition: ECFactory.h:115
std::vector< std::filebuf * > m_logfiles
Files for log output.
Definition: Manager.h:1663
coil::Properties Properties
Definition: RTC.h:83
std::vector< ExecutionContextBase * > m_ecs
ExecutionContext list.
Definition: Manager.h:1817
LogStreamBuf m_logStreamBuf
Logger buffer.
Definition: Manager.h:1645
Finalized m_finalized
Definition: Manager.h:2110
ObjectManager< const coil::Properties, FactoryBase, FactoryPredicate > FactoryManager
ComponentFactory.
Definition: Manager.h:1771
OrbRunner class.
Definition: Manager.h:1851
coil::Properties m_config
Managaer&#39;s configuration Properties.
Definition: Manager.h:1606
CORBA::ORB_var m_pORB
The pointer to the ORB.
Definition: Manager.h:1567
ObjectManager< const char *, ECFactoryBase, ECFactoryPredicate > ECFactoryManager
Definition: Manager.h:1799
FactoryPredicate(const coil::Properties &prop)
Definition: Manager.h:1700
coil::Guard< Mutex > Guard
Definition: Manager.h:83
prop
Organization::get_organization_property ();.
ECFactoryPredicate(ECFactoryBase *factory)
Definition: Manager.h:1789
ModuleManager * m_module
The pointer to the ModuleManager.
Definition: Manager.h:1615
virtual int close(unsigned long flags)
ORB close processing.
Definition: Manager.h:1945
virtual int open(void *args)
Termination processing activation.
Definition: Manager.h:2045
Terminator * m_terminator
The pointer to ORB termination helper class.
Definition: Manager.h:2083
Timer class.
Definition: Timer.h:53
Class represents a set of properties.
Definition: Properties.h:101
ExecutionContext Factory class.
ExecutionContextBase *(* ECNewFunc)()
Definition: ECFactory.h:29
std::vector< RTObject_impl * > comps
Definition: Manager.h:2108
FactoryBase base class.
Definition: rtm/Factory.h:118
Task class.
coil::Properties & m_prop
Definition: Manager.h:1741
coil::Mutex Mutex
Definition: Manager.h:82
FactoryPredicate(FactoryBase *factory)
Definition: Manager.h:1707
ObjectManager< std::string, RTObject_impl, InstanceName > ComponentManager
Definition: Manager.h:1678
void(* RtcDeleteFunc)(RTObject_impl *rtc)
Definition: rtm/Factory.h:34
ComponentManager m_compManager
ComponentManager.
Definition: Manager.h:1687
RTComponent header.
bool operator()(FactoryBase *factory)
Definition: Manager.h:1714
bool operator()(coil::Properties &prop)
Definition: Manager.h:1747
PortableServer::POA_var m_pPOA
The pointer to the POA.
Definition: Manager.h:1576
Guard template class.
Definition: Guard.h:41
Terminator(Manager *manager)
Constructor.
Definition: Manager.h:2004
virtual const char * name()=0
Pure virtual function to get names of creation target ExecutionContext.
ECFactoryManager m_ecfactory
ExecutionContext Manager.
Definition: Manager.h:1808
void(* ECDeleteFunc)(ExecutionContextBase *ec)
Definition: ECFactory.h:30
OrbRunner * m_runner
The pointer to ORB helper class.
Definition: Manager.h:1959
bool operator()(ECFactoryBase *factory)
Definition: Manager.h:1791
RT-Middleware.
Definition: Manager.h:38
ModulePredicate(coil::Properties &prop)
Definition: Manager.h:1743
PortableServer::POAManager_var m_pPOAManager
The pointer to the POAManager.
Definition: Manager.h:1585
Terminator class.
Definition: Manager.h:1983
ModuleInitProc m_initProc
User&#39;s initialization function&#39;s pointer.
Definition: Manager.h:1597
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
Definition: Properties.cpp:156
void operator()(FactoryBase *f)
Definition: Manager.h:1822
virtual int svc(void)
ORB and manager&#39;s termination processing.
Definition: Manager.h:2068
RTObject_impl RtcBase
Definition: Manager.h:55
Common Object Interface Layer.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:58