OpenRTM-aist 2.1.0
Loading...
Searching...
No Matches
Manager.h
Go to the documentation of this file.
1
20#ifndef RTC_MANAGER_H
21#define RTC_MANAGER_H
22
23#include <rtm/RTC.h>
24
25#ifdef ORB_IS_TAO
26#include <tao/Strategies/advanced_resource.h>
27#include <tao/IORTable/IORTable.h>
28#endif
29
30#include <rtm/Factory.h>
31#include <rtm/ECFactory.h>
32#include <rtm/ObjectManager.h>
33#include <rtm/SystemLogger.h>
35
36#ifdef ORB_IS_ORBEXPRESS
37#include <RTPortableServer.h>
38#endif
39
40#include <coil/Timer.h>
41#include <coil/Signal.h>
42
43#include <atomic>
44#include <functional>
45#include <mutex>
46#include <list>
47#include <thread>
48#include <vector>
49
50namespace RTM
51{
52 class ManagerServant;
53} // namespace RTM
54
55namespace coil
56{
57} // namespace coil
58
59namespace RTC
60{
61 class CorbaNaming;
62 class ModuleManager;
63 class NamingManager;
64 class Manager;
65 class RTObject_impl;
67
68 using ModuleInitProc = void (*)(Manager*);
69
90 class Manager
91 {
92 protected:
107
108 Manager(const Manager&) = delete;
109 Manager& operator=(const Manager&) = delete;
110
111 public:
164 static Manager* init(int argc, char** argv);
165
188 static Manager& instance();
189
190 //============================================================
191 // Manager
192 //============================================================
193
207 static void terminate();
208
222 void join();
223
242
260 std::string& getLogLevel() {return m_config["logger.log_level"];}
261
279 coil::Properties& getConfig() { return m_config;}
280
306
340
372 void runManager(bool no_block = false);
373
374 using TaskId = coil::Timer<coil::PeriodicFunction>::TaskId;
375
404 TaskId addTask(std::function<void(void)> fn,
405 std::chrono::nanoseconds period);
406
426 static void removeTask(TaskId id) { id->stop(); }
427
451 void invoke(std::function<void(void)> fn,
452 std::chrono::nanoseconds delay
453 = std::chrono::seconds::zero());
454
455 //============================================================
456 // Module management
457 //============================================================
490 ReturnCode_t load(const std::string& fname, const std::string& initfunc);
491
528 ReturnCode_t load(coil::Properties &prop, const std::string& initfunc);
529
549 void unload(const char* fname);
550
566 void unloadAll();
567
585 std::vector<coil::Properties> getLoadedModules();
586
606 std::vector<coil::Properties> getLoadableModules();
607
608 //============================================================
609 // Component Factory Management
610 //============================================================
637 bool registerFactory(coil::Properties& profile,
638 RtcNewFunc new_func,
639 RtcDeleteFunc delete_func);
640
658 std::vector<coil::Properties> getFactoryProfiles();
659
686 bool registerECFactory(const char* name,
687 ECNewFunc new_func,
688 ECDeleteFunc delete_func);
689
707 std::vector<std::string> getModulesFactories();
708
709 //============================================================
710 // Component management
711 //============================================================
770 RTObject_impl* createComponent(const char* comp_args);
784 ExecutionContextBase* createContext(const char* ec_args);
785
805
820
840
865
888
889
912
935 void deleteComponent(const char* instance_name);
936
937
961 RTObject_impl* getComponent(const char* instance_name);
962
980 std::vector<RTObject_impl*> getComponents();
981
982
983 void
985 bool autoclean = true);
986 void
988
989 void
991 bool autoclean = true);
992 void
994
995 void
997 bool autoclean = true);
998 void
1000
1001 void
1003 bool autoclean = true);
1004 void
1006
1007 void
1009 bool autoclean = true);
1010 void
1012
1013
1014 //============================================================
1015 // CORBA 関連
1016 //============================================================
1043 CORBA::ORB_ptr theORB();
1044
1081 CORBA::ORB_ptr getORB();
1082
1110 PortableServer::POA_ptr thePOA();
1111#ifdef ORB_IS_OMNIORB
1112 PortableServer::POA_ptr theShortCutPOA();
1113#endif
1150 PortableServer::POA_ptr getPOA();
1151#ifdef ORB_IS_OMNIORB
1152 PortableServer::POA_ptr getShortCutPOA();
1153#endif
1154
1182 PortableServer::POAManager_ptr thePOAManager();
1222 PortableServer::POAManager_ptr getPOAManager();
1223
1235
1265
1266 //============================================================
1267 // Protected functions
1268 //============================================================
1269 protected:
1270 //============================================================
1271 // Manager initialize and finalization
1272 //============================================================
1300 void initManager(int argc, char** argv);
1301
1317 void shutdown();
1318
1326 // TAO will cause the build to fail, so don't use name "main".
1328
1329 //============================================================
1330 // Logger initialize and terminator
1331 //============================================================
1357
1376
1391
1392 //============================================================
1393 // ORB initialization and finalization
1394 //============================================================
1412 bool initORB();
1413
1433 std::string createORBOptions();
1434
1454 static bool isORBEndPoint(const std::string& endpoint);
1455
1473 void createORBEndpoints(coil::vstring& endpoints);
1474
1488 void createORBEndpointOption(std::string& opt, coil::vstring endpoints);
1489
1509
1510 //============================================================
1511 // NamingService initialization and finalization
1512 //============================================================
1545
1562
1574
1575 //============================================================
1576 // Component management
1577 //============================================================
1594
1595
1643 bool procComponentArgs(const char* comp_arg,
1644 coil::Properties& comp_id,
1645 coil::Properties& comp_conf);
1686 bool procContextArgs(const char* ec_args,
1687 std::string& ec_id,
1688 coil::Properties& ec_conf);
1689
1712 void configureComponent(RTObject_impl* comp, const coil::Properties& prop);
1713
1736
1753
1776
1880 PortServiceList* getPortsOnNameServers(const std::string& nsname, const std::string& kind);
1896 void connectDataPorts(PortService_ptr port, PortServiceList_var& target_ports);
1912 void connectServicePorts(PortService_ptr port, PortServiceList_var& target_ports);
1913
1928
1929
1930
1939
1965 bool mergeProperty(coil::Properties& prop, const char* file_name);
1966
2015 std::string formatString(const char* naming_format,
2016 coil::Properties& prop);
2017
2025 void setEndpointProperty(CORBA::Object_ptr objref);
2026
2034 void endpointPropertySwitch(const std::string& ipver,
2035 bool& ip, std::vector<int>& ip_list);
2036
2037 //============================================================
2038 // protected 変数
2039 //============================================================
2040
2041 //------------------------------------------------------------
2042 // static var
2043 //------------------------------------------------------------
2052
2060 static std::mutex mutex;
2061
2069 static std::atomic_flag m_isRunning;
2070
2071 //------------------------------------------------------------
2072 // CORBA var
2073 //------------------------------------------------------------
2081 CORBA::ORB_var m_pORB;
2082
2090 PortableServer::POA_var m_pPOA;
2091#ifdef ORB_IS_OMNIORB
2092 PortableServer::POA_var m_pShortCutPOA;
2093#endif
2094
2102 PortableServer::POAManager_var m_pPOAManager;
2103
2114 coil::Argv m_argv;
2115
2127
2128 //------------------------------------------------------------
2129 // Manager's variable
2130 //------------------------------------------------------------
2139
2147 coil::Properties m_config;
2148
2157
2166
2174 coil::Timer<coil::DelayedFunction> m_invoker;
2175
2183 coil::Timer<coil::PeriodicFunction> m_scheduler;
2184
2192 std::thread m_threadOrb;
2193
2201 std::thread m_threadMain;
2202
2210 std::list<coil::SignalAction> m_signals;
2211
2219 bool m_needsTimer{false};
2220
2221 //------------------------------------------------------------
2222 // Logger
2223 //------------------------------------------------------------
2232
2241
2249 std::vector<std::filebuf*> m_logfiles;
2250
2251 //============================================================
2252 // コンポーネントマネージャ
2253 //============================================================
2254 // ObjectManager へ渡す述語クラス
2256 {
2258 explicit InstanceName(const char* name);
2259 explicit InstanceName(std::string name);
2261 std::string m_name;
2262 };
2263
2265 InstanceName>;
2266
2275
2276 //============================================================
2277 // コンポーネントファクトリ
2278 //============================================================
2279 // コンポーネントファクトリへ渡す述語クラス
2281 {
2282 public:
2283 explicit FactoryPredicate(const char* imple_id)
2284 : m_vendor(""), m_category(""), m_impleid(imple_id), m_version(""), m_language("")
2285 {
2286 }
2287 explicit FactoryPredicate(const coil::Properties& prop)
2288 : m_vendor(prop["vendor"]),
2289 m_category(prop["category"]),
2290 m_impleid(prop["implementation_id"]),
2291 m_version(prop["version"]),
2292 m_language(prop["language"])
2293 {
2294 }
2296 : m_vendor(factory->profile()["vendor"]),
2297 m_category(factory->profile()["category"]),
2298 m_impleid(factory->profile()["implementation_id"]),
2299 m_version(factory->profile()["version"]),
2300 m_language(factory->profile()["language"])
2301 {
2302 }
2305 {
2306 // implementation_id must not be empty
2307 if (m_impleid.empty()) return false;
2308
2309 const coil::Properties& prop(factory->profile());
2310
2311 if (m_impleid != prop["implementation_id"])
2312 return false;
2313 if (!m_vendor.empty() && m_vendor != prop["vendor"])
2314 return false;
2315 if (!m_category.empty() && m_category != prop["category"])
2316 return false;
2317 if (!m_version.empty() && m_version != prop["version"])
2318 return false;
2319 if (!m_language.empty() && m_language != prop["language"])
2320 return false;
2321
2322
2323 return true;
2324 }
2325 private:
2326 std::string m_vendor;
2327 std::string m_category;
2328 std::string m_impleid;
2329 std::string m_version;
2330 std::string m_language;
2331 };
2332
2334 {
2335 coil::Properties& m_prop;
2336 public:
2337 explicit ModulePredicate(coil::Properties& prop)
2338 : m_prop(prop)
2339 {
2340 }
2341 bool operator()(coil::Properties& prop)
2342 {
2343 if (m_prop["implementation_id"] != prop["implementation_id"])
2344 {
2345 return false;
2346 }
2347 if (!m_prop["vendor"].empty() &&
2348 m_prop["vendor"] != prop["vendor"]) { return false; }
2349 if (!m_prop["category"].empty() &&
2350 m_prop["category"] != prop["category"]) { return false; }
2351 if (!m_prop["version"].empty() &&
2352 m_prop["version"] != prop["version"]) { return false; }
2353 return true;
2354 }
2355 };
2356
2364 using FactoryManager = ObjectManager<const coil::Properties,
2366
2375
2376 //============================================================
2377 // ExecutionContextファクトリ
2378 //============================================================
2379 // ECファクトリへ渡す述語クラス
2381 {
2382 explicit ECFactoryPredicate(const char* name) : m_name(name) {}
2384 : m_name(factory->name()) {}
2386 {
2387 return m_name == factory->name();
2388 }
2389 std::string m_name;
2390 };
2393
2402
2410 std::vector<ExecutionContextBase*> m_ecs;
2411
2412 // ファクトリ名をリストアップするためのファンクタ
2414 {
2416 {
2417 modlist.emplace_back(f->profile().getProperty("implementation_id"));
2418 }
2419 std::vector<std::string> modlist;
2420 };
2421
2423 {
2425 std::mutex mutex;
2426 std::vector<RTObject_impl*> comps;
2427 };
2429
2431 }; // class Manager
2432} // namespace RTC
2433
2434#endif // RTC_MANAGER_H
ExecutionContext Factory class.
RT-Component factory class.
component action listener class
Object management class.
RTComponent header.
RT component logger class.
ECFactoryBase abstract class.
Definition ECFactory.h:116
virtual const char * name()=0
Pure virtual function to get names of creation target ExecutionContext.
A base class for ExecutionContext.
Definition ExecutionContextBase.h:366
FactoryBase base class.
Definition Factory.h:138
virtual coil::Properties & profile()
Get the component profile.
Logger class.
Definition SystemLogger.h:101
Definition Manager.h:2281
FactoryPredicate(FactoryBase *factory)
Definition Manager.h:2295
FactoryPredicate(const char *imple_id)
Definition Manager.h:2283
bool operator()(FactoryBase *factory)
Definition Manager.h:2304
FactoryPredicate(const coil::Properties &prop)
Definition Manager.h:2287
Definition Manager.h:2334
bool operator()(coil::Properties &prop)
Definition Manager.h:2341
ModulePredicate(coil::Properties &prop)
Definition Manager.h:2337
Manager class.
Definition Manager.h:91
std::string formatString(const char *naming_format, coil::Properties &prop)
Construct registration information when registering to Naming server.
void setEndpointProperty(CORBA::Object_ptr objref)
Setting endpoint info from corba.endpoints .
static void removeTask(TaskId id)
Remove the task from the Manager timer.
Definition Manager.h:426
ReturnCode_t load(const std::string &fname, const std::string &initfunc)
[CORBA interface] Load module
void cleanupComponent(RTObject_impl *comp)
Unregister RT-Components.
void invokeInitProc()
static Manager * manager
The pointer to the Manager .
Definition Manager.h:2051
bool unregisterComponent(RTObject_impl *comp)
Unregister RT-Components.
bool initComposite()
PeriodicECSharedComposite initialization.
bool initExecContext()
ExecutionContextManager initialization.
bool initORB()
CORBA ORB initialization.
coil::Argv m_argv
The argument of ORB_init .
Definition Manager.h:2114
void createORBEndpoints(coil::vstring &endpoints)
Create Endpoints.
ECFactoryManager m_ecfactory
ExecutionContext Manager .
Definition Manager.h:2401
Manager()
Protected Constructor.
ModuleInitProc m_initProc
User's initialization function's pointer .
Definition Manager.h:2138
void addRtcLifecycleActionListener(RTM::RtcLifecycleActionListener *listener, bool autoclean=true)
std::vector< coil::Properties > getLoadableModules()
Get a list of loadable modules.
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
Register RT-Component Factory.
bool initLocalService()
LocalService initialization.
std::vector< coil::Properties > getLoadedModules()
Get a list of loaded modules.
Manager(const Manager &)=delete
CORBA::ORB_ptr theORB()
Get the pointer to ORB (ownership retained)
void shutdownComponents()
NamingManager finalization.
coil::Properties m_config
Managaer's configuration Properties .
Definition Manager.h:2147
void endpointPropertySwitch(const std::string &ipver, bool &ip, std::vector< int > &ip_list)
Getting option info from corba.endpoint_property .
void initCpuAffinity()
RTM::ManagerServant * m_mgrservant
The pointer to the ManagerServant .
Definition Manager.h:1938
CORBA::ORB_var m_pORB
The pointer to the ORB .
Definition Manager.h:2081
PortableServer::POAManager_ptr thePOAManager()
Get POAManager that Manager has (ownership retained)
void initPreCreation()
NamingManager * m_namingManager
The pointer to the NamingManager .
Definition Manager.h:2165
std::vector< std::filebuf * > m_logfiles
Files for log output .
Definition Manager.h:2249
bool procContextArgs(const char *ec_args, std::string &ec_id, coil::Properties &ec_conf)
Extracting ExecutionContext's name/properties from the given string.
NamingManager * getNaming()
Getting NamingManager.
ExecutionContextBase * createContext(const char *ec_args)
Create Context.
void initPreActivation()
CORBA::ORB_ptr getORB()
Get the pointer to ORB (ownership duplicated)
static Manager & instance()
Get instance of the manager.
void deleteComponent(RTObject_impl *comp)
Unregister RT-Components that have been registered to Manager.
bool registerComponent(RTObject_impl *comp)
Register RT-Component directly without Factory.
void cleanupComponents()
This method deletes RT-Components.
std::string createORBOptions()
Create ORB command options.
static Manager * init(int argc, char **argv)
Initialize manager.
void createORBEndpointOption(std::string &opt, coil::vstring endpoints)
Create a command optional line of Endpoint of ORB.
bool initLogger()
System logger initialization.
coil::Timer< coil::DelayedFunction > m_invoker
Timer Object for delay call on the Manager thread .
Definition Manager.h:2174
static std::mutex mutex
The mutex of the pointer to the Manager .
Definition Manager.h:2060
void mainThread()
The main function of Manager main thread. .
Finalized m_finalized
Definition Manager.h:2428
bool initFactories()
Factories initialization.
std::thread m_threadOrb
ORB thread. .
Definition Manager.h:2192
int m_argvSize
The argument of ORB_init .
Definition Manager.h:2126
FactoryManager m_factory
ComponentManager .
Definition Manager.h:2374
void removeNamingActionListener(RTM::NamingActionListener *listener)
void connectDataPorts(PortService_ptr port, PortServiceList_var &target_ports)
coil::Timer< coil::PeriodicFunction >::TaskId TaskId
Definition Manager.h:374
void removeRtcLifecycleActionListener(RTM::RtcLifecycleActionListener *listener)
void setModuleInitProc(ModuleInitProc proc)
Set initial procedure.
void notifyFinalized(RTObject_impl *comp)
This method deletes RT-Components.
ReturnCode_t load(coil::Properties &prop, const std::string &initfunc)
[CORBA interface] Load module
PortableServer::POA_var m_pPOA
The pointer to the POA .
Definition Manager.h:2090
void addManagerActionListener(RTM::ManagerActionListener *listener, bool autoclean=true)
PortableServer::POA_ptr getPOA()
Get a pointer to RootPOA held by Manager.
bool mergeProperty(coil::Properties &prop, const char *file_name)
Merge property information.
void addLocalServiceActionListener(RTM::LocalServiceActionListener *listener, bool autoclean=true)
void initPreConnection()
bool registerECFactory(const char *name, ECNewFunc new_func, ECDeleteFunc delete_func)
Register ExecutionContext Factory.
bool activateManager()
Activate the Manager.
ComponentManager m_compManager
ComponentManager .
Definition Manager.h:2274
RTObject_impl * getComponent(const char *instance_name)
Get RT-Component's pointer.
void configureComponent(RTObject_impl *comp, const coil::Properties &prop)
Configure RT-Component.
Logger rtclog
Logger stream .
Definition Manager.h:2240
PortableServer::POAManager_ptr getPOAManager()
Get POAManager that Manager has (ownership duplicated)
static bool isORBEndPoint(const std::string &endpoint)
void publishPorts(RTObject_impl *comp)
NamingManager & getNamingManager()
Getting NamingManager.
std::string & getLogLevel()
Get the log level of the configuration.
Definition Manager.h:260
void unload(const char *fname)
Unload module.
RTM::ManagerServant & getManagerServant()
Getting ManagerServant.
void runManager(bool no_block=false)
Run the Manager.
PortableServer::POA_ptr thePOA()
Get a pointer to RootPOA held by Manager.
void shutdown()
Shutdown Manager.
std::list< coil::SignalAction > m_signals
An array for signals management .
Definition Manager.h:2210
void initManager(int argc, char **argv)
Manager internal initialization.
bool initManagerServant()
ManagerServant initialization.
void shutdownORB()
ORB finalization.
static std::atomic_flag m_isRunning
A flag to stop the main thread. .
Definition Manager.h:2069
std::vector< ExecutionContextBase * > m_ecs
ExecutionContext list .
Definition Manager.h:2410
void initLogstreamOthers()
std::thread m_threadMain
Manager main thread. .
Definition Manager.h:2201
void invoke(std::function< void(void)> fn, std::chrono::nanoseconds delay=std::chrono::seconds::zero())
Run a function on the Manager main thread.
void shutdownManagerServant()
Manager Servant finalization.
bool m_needsTimer
A flag that Manager use Timer or not. .
Definition Manager.h:2219
void unloadAll()
Unload all modules.
void connectServicePorts(PortService_ptr port, PortServiceList_var &target_ports)
void initLogstreamPlugins()
PortServiceList * getPortsOnNameServers(const std::string &nsname, const std::string &kind)
std::vector< coil::Properties > getFactoryProfiles()
Get profiles of factories.
void removeModuleActionListener(RTM::ModuleActionListener *listener)
void shutdownNaming()
NamingManager finalization.
std::vector< std::string > getModulesFactories()
Get the list of all Factories.
PortableServer::POAManager_var m_pPOAManager
The pointer to the POAManager .
Definition Manager.h:2102
LogStreamBuf & getLogStreamBuf()
Get the log buffer.
Definition Manager.h:241
std::vector< RTObject_impl * > getComponents()
Get all RT-Components registered in the Manager.
bool initNaming()
NamingManager initialization.
void deleteComponent(const char *instance_name)
Unregister RT-Components that have been registered to Manager.
coil::Properties & getConfig()
Get the manager configuration.
Definition Manager.h:279
bool procComponentArgs(const char *comp_arg, coil::Properties &comp_id, coil::Properties &comp_conf)
Extracting component type/properties from the given string.
void removeLocalServiceActionListener(RTM::LocalServiceActionListener *listener)
void initLogstreamFile()
void addModuleActionListener(RTM::ModuleActionListener *listener, bool autoclean=true)
static void terminate()
Terminate manager.
void subscribePorts(RTObject_impl *comp)
coil::Timer< coil::PeriodicFunction > m_scheduler
Timer Object for delay call on the Manager thread .
Definition Manager.h:2183
LogStreamBuf m_logStreamBuf
Logger buffer .
Definition Manager.h:2231
::RTM::ManagerActionListeners m_listeners
Definition Manager.h:2430
void removeManagerActionListener(RTM::ManagerActionListener *listener)
TaskId addTask(std::function< void(void)> fn, std::chrono::nanoseconds period)
Add a task to the Manager timer.
void shutdownLogger()
System Logger finalization.
void addNamingActionListener(RTM::NamingActionListener *listener, bool autoclean=true)
RTObject_impl * createComponent(const char *comp_args)
Create RT-Components.
ModuleManager * m_module
The pointer to the ModuleManager .
Definition Manager.h:2156
void join()
Wait for Manager's termination.
Manager & operator=(const Manager &)=delete
ModuleManager class.
Definition ModuleManager.h:72
NamingServer management class.
Definition NamingManager.h:626
RT-Component class.
Definition RTObject.h:93
LocalServiceActionListener class.
Definition ManagerActionListener.h:716
Definition ManagerActionListener.h:62
ManagerActionListeners class.
Definition ManagerActionListener.h:967
Manager CORBA class.
Definition ManagerServant.h:66
ModuleActionListener class.
Definition ManagerActionListener.h:193
NamingActionListener class.
Definition ManagerActionListener.h:558
RtcLifecycleActionListener class.
Definition ManagerActionListener.h:355
RT-Component.
void(*)(Manager *) ModuleInitProc
Definition Manager.h:68
ExecutionContextBase *(*)() ECNewFunc
Definition ECFactory.h:29
void(*)(RTObject_impl *) RtcDeleteFunc
Definition Factory.h:34
void(*)(ExecutionContextBase *) ECDeleteFunc
Definition ECFactory.h:30
RTObject_impl *(*)(Manager *) RtcNewFunc
Definition Factory.h:33
::coil::LogStreamBuffer LogStreamBuf
Definition SystemLogger.h:34
RT-Middleware.
Definition FactoryInit.h:22
Definition DefaultPeriodicTask.h:24
Definition Manager.h:2381
ECFactoryPredicate(ECFactoryBase *factory)
Definition Manager.h:2383
bool operator()(ECFactoryBase *factory)
Definition Manager.h:2385
std::string m_name
Definition Manager.h:2389
ECFactoryPredicate(const char *name)
Definition Manager.h:2382
Definition Manager.h:2423
std::mutex mutex
Definition Manager.h:2425
std::vector< RTObject_impl * > comps
Definition Manager.h:2426
Definition Manager.h:2256
InstanceName(std::string name)
InstanceName(const char *name)
InstanceName(RTObject_impl *comp)
std::string m_name
Definition Manager.h:2261
bool operator()(RTObject_impl *comp)
Definition Manager.h:2414
void operator()(FactoryBase *f)
Definition Manager.h:2415
std::vector< std::string > modlist
Definition Manager.h:2419