Manager.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
19 #include <rtm/Manager.h>
20 #include <rtm/ManagerConfig.h>
21 #include <rtm/ModuleManager.h>
22 #include <rtm/CorbaNaming.h>
23 #include <rtm/NamingManager.h>
24 #include <rtm/RTC.h>
29 #include <rtm/RTCUtil.h>
30 #include <rtm/ManagerServant.h>
31 #include <fstream>
32 #include <iostream>
33 #include <coil/Properties.h>
34 #include <coil/stringutil.h>
35 #include <coil/Signal.h>
36 #include <coil/TimeValue.h>
37 #include <coil/Timer.h>
38 #include <coil/OS.h>
39 #include <rtm/FactoryInit.h>
40 #include <rtm/CORBA_IORUtil.h>
42 
43 #if defined(minor)
44 #undef minor
45 #endif
46 
47 //static sig_atomic_t g_mgrActive = true;
48 extern "C" void handler (int)
49 {
51 }
52 
53 namespace RTC
54 {
55  Manager* Manager::manager = NULL;
57 
59  : m_name(comp->getInstanceName())
60  {}
62  : m_name(name)
63  {}
64  Manager::InstanceName::InstanceName(const std::string name)
65  : m_name(name)
66  {}
68  {
69  return m_name == comp->getInstanceName();
70  }
71 
72 
81  : m_initProc(0), m_namingManager(0), m_timer(0),
83  m_runner(0), m_terminator(0)
84  {
86  }
87 
96  : m_initProc(0), m_namingManager(0), m_timer(0),
98  m_runner(0), m_terminator(0)
99  {
101  }
102 
110  Manager* Manager::init(int argc, char** argv)
111  {
112  // DCL for singleton
113  if (!manager)
114  {
115  Guard guard(mutex);
116  if (!manager)
117  {
118  manager = new Manager();
119  manager->initManager(argc, argv);
120  manager->initLogger();
121  manager->initORB();
122  manager->initNaming();
126  manager->initTimer();
128  }
129  }
130  return manager;
131  }
132 
141  {
142  // DCL for singleton
143  if (!manager)
144  {
145  Guard guard(mutex);
146  if (!manager)
147  {
148  manager = new Manager();
149  manager->initManager(0, NULL);
150  manager->initLogger();
151  manager->initORB();
152  manager->initNaming();
156  manager->initTimer();
157  }
158  }
159  return *manager;
160  }
161 
170  {
171  if (m_terminator != NULL)
173  }
174 
182  {
183  RTC_TRACE(("Manager::shutdown()"));
185  shutdownNaming();
186  shutdownORB();
187  shutdownManager();
188  // ½ªÎ»ÂÔ¤Á¹ç¤E»
189  if (m_runner != NULL)
190  {
191  m_runner->wait();
192  }
193  else
194  {
195  join();
196  }
197  shutdownLogger();
198  }
199 
208  {
209  RTC_TRACE(("Manager::wait()"));
210  {
211  Guard guard(m_terminate.mutex);
213  }
214  while (1)
215  {
216  {
217  Guard guard(m_terminate.mutex);
218  if (m_terminate.waiting > 1) break;
219  }
220  coil::usleep(100000);
221  }
222  }
223 
232  {
233  m_initProc = proc;
234  }
235 
244  {
245  RTC_TRACE(("Manager::activateManager()"));
246 
247  try
248  {
249  if(CORBA::is_nil(this->getPOAManager()))
250  {
251  RTC_ERROR(("Could not get POA manager."));
252  return false;
253  }
254  this->getPOAManager()->activate();
255  RTC_TRACE(("POA Manager activated."));
256  }
257  catch (...)
258  {
259  RTC_ERROR(("POA Manager activatatin failed."));
260  return false;
261  }
262 
263  std::vector<std::string> mods;
264  mods = coil::split(m_config["manager.modules.preload"], ",");
265 
266  for (int i(0), len(mods.size()); i < len; ++i)
267  {
268  size_t begin_pos(mods[i].find_first_of('('));
269  size_t end_pos(mods[i].find_first_of(')'));
270  std::string filename, initfunc;
271  if (begin_pos != std::string::npos && end_pos != std::string::npos &&
272  begin_pos < end_pos)
273  {
274  initfunc = mods[i].substr(begin_pos + 1, end_pos - (begin_pos + 1));
275  filename = mods[i].substr(0, begin_pos);
276  coil::eraseBothEndsBlank(initfunc);
277  coil::eraseBothEndsBlank(filename);
278  }
279  else
280  {
281  initfunc = coil::split(mods[i], ".").operator[](0) + "Init";
282  filename = mods[i];
283  }
284  if (filename.find_first_of('.') == std::string::npos)
285  {
286  std::cout << m_config["manager.modules.C++.suffixes"] << std::endl;
287  if (m_config.findNode("manager.modules.C++.suffixes") != 0)
288  {
289  filename += "." + m_config["manager.modules.C++.suffixes"];
290  }
291  }
292  try
293  {
294  m_module->load(mods[i], initfunc);
295  }
296  catch (ModuleManager::Error& e)
297  {
298  RTC_ERROR(("Module load error: %s", e.reason.c_str()));
299  }
301  {
302  RTC_ERROR(("Symbol not found: %s", e.name.c_str()));
303  }
305  {
306  RTC_ERROR(("Module not found: %s", e.name.c_str()));
307  }
308  catch (...)
309  {
310  RTC_ERROR(("Unknown Exception"));
311  }
312  }
313 
314  m_config["sdo.service.consumer.available_services"]
316 
317  if (m_initProc != NULL)
318  {
319  m_initProc(this);
320  }
321 
322  RTC_TRACE(("Components pre-creation: %s",
323  m_config["manager.components.precreate"].c_str()));
324  std::vector<std::string> comp;
325  comp = coil::split(m_config["manager.components.precreate"], ",");
326  for (int i(0), len(comp.size()); i < len; ++i)
327  {
328  this->createComponent(comp[i].c_str());
329  }
330 
331  { // pre-connection
332  RTC_TRACE(("Connection pre-creation: %s",
333  m_config["manager.components.preconnect"].c_str()));
334  std::vector<std::string> connectors;
335  connectors = coil::split(m_config["manager.components.preconnect"], ",");
336  for (int i(0), len(connectors.size()); i < len; ++i)
337  {
338  // ConsoleIn.out:Console.in(dataflow_type=push,....)
339  coil::vstring conn_prop = coil::split(connectors[i], "(");
340  coil::replaceString(conn_prop[1], ")", "");
341  coil::vstring comp_ports;
342  comp_ports = coil::split(conn_prop[0], ":");
343  if (comp_ports.size() != 2)
344  {
345  RTC_ERROR(("Invalid format for pre-connection."));
346  RTC_ERROR(("Format must be Comp0.port0:Comp1.port1"));
347  continue;
348  }
349  std::string comp0_name = coil::split(comp_ports[0], ".")[0];
350  std::string comp1_name = coil::split(comp_ports[1], ".")[0];
351  RTObject_impl* comp0 = getComponent(comp0_name.c_str());
352  RTObject_impl* comp1 = getComponent(comp1_name.c_str());
353  if (comp0 == NULL)
354  { RTC_ERROR(("%s not found.", comp0_name.c_str())); continue; }
355  if (comp1 == NULL)
356  { RTC_ERROR(("%s not found.", comp1_name.c_str())); continue; }
357  std::string port0 = comp_ports[0];
358  std::string port1 = comp_ports[1];
359 
360  PortServiceList_var ports0 = comp0->get_ports();
361  PortServiceList_var ports1 = comp1->get_ports();
362  RTC_DEBUG(("%s has %d ports.", comp0_name.c_str(), ports0->length()));
363  RTC_DEBUG(("%s has %d ports.", comp1_name.c_str(), ports1->length()));
364 
365  PortService_var port0_var;
366  for (size_t p(0); p < ports0->length(); ++p)
367  {
368  PortProfile_var pp = ports0[p]->get_port_profile();
369  std::string s(CORBA::string_dup(pp->name));
370  if (comp_ports[0] == s)
371  {
372  RTC_DEBUG(("port %s found: ", comp_ports[0].c_str()));
373  port0_var = ports0[p];
374  }
375  }
376  PortService_var port1_var;
377  for (size_t p(0); p < ports1->length(); ++p)
378  {
379  PortProfile_var pp = ports1[p]->get_port_profile();
380  std::string s(CORBA::string_dup(pp->name));
381  if (port1 == s)
382  {
383  RTC_DEBUG(("port %s found: ", comp_ports[1].c_str()));
384  port1_var = ports1[p];
385  }
386  }
387  if (CORBA::is_nil(port0_var))
388  {
389  RTC_ERROR(("port0 %s is nil obj", comp_ports[0].c_str()));
390  continue;
391  }
392  if (CORBA::is_nil(port1_var))
393  {
394  RTC_ERROR(("port1 %s is nil obj", comp_ports[1].c_str()));
395  continue;
396  }
397  ConnectorProfile conn_prof;
398  std::string prof_name;
399  conn_prof.name = CORBA::string_dup(connectors[i].c_str());
400  conn_prof.connector_id = CORBA::string_dup("");
401  conn_prof.ports.length(2);
402  conn_prof.ports[0] = port0_var;
403  conn_prof.ports[1] = port1_var;
405  prop["dataport.dataflow_type"] = "push";
406  prop["dataport.interface_type"] = "corba_cdr";
407  coil::vstring opt_props = coil::split(conn_prop[1], "&");
408  for (size_t o(0); o < opt_props.size(); ++o)
409  {
410  coil::vstring temp = coil::split(opt_props[o], "=");
411  prop["dataport." + temp[0]] = temp[1];
412  }
413  NVUtil::copyFromProperties(conn_prof.properties, prop);
414  if (RTC::RTC_OK != port0_var->connect(conn_prof))
415  {
416  RTC_ERROR(("Connection error: %s",
417  connectors[i].c_str()));
418  }
419  }
420  } // end of pre-connection
421 
422  { // pre-activation
423  RTC_TRACE(("Components pre-activation: %s",
424  m_config["manager.components.preactivation"].c_str()));
425  std::vector<std::string> comps;
426  comps = coil::split(m_config["manager.components.preactivation"],
427  ",");
428  for (int i(0), len(comps.size()); i < len; ++i)
429  {
430  RTObject_impl* comp = getComponent(comps[i].c_str());
431  if (comp == NULL)
432  { RTC_ERROR(("%s not found.", comps[i].c_str())); continue; }
433 
434  ExecutionContextList_var ecs = comp->get_owned_contexts();
435  ecs[0]->activate_component(comp->getObjRef());
436  }
437  } // end of pre-activation
438  return true;
439  }
440 
448  void Manager::runManager(bool no_block)
449  {
450  if (no_block)
451  {
452  RTC_TRACE(("Manager::runManager(): non-blocking mode"));
453  m_runner = new OrbRunner(m_pORB);
454  m_runner->open(0);
455  }
456  else
457  {
458  RTC_TRACE(("Manager::runManager(): blocking mode"));
459  m_pORB->run();
460  RTC_TRACE(("Manager::runManager(): ORB was terminated"));
461  join();
462  }
463  return;
464  }
465 
466  //============================================================
467  // Module management
468  //============================================================
476  void Manager::load(const char* fname, const char* initfunc)
477  {
478  RTC_TRACE(("Manager::load(fname = %s, initfunc = %s)",
479  fname, initfunc));
480  std::string file_name(fname);
481  std::string init_func(initfunc);
482  try
483  {
484  if (init_func.empty())
485  {
486  coil::vstring mod(coil::split(fname, "."));
487  init_func = mod[0] + "Init";
488  }
489  std::string path(m_module->load(file_name, init_func));
490  RTC_DEBUG(("module path: %s", path.c_str()));
491  }
492  catch (...)
493  {
494  RTC_ERROR(("module load error."));
495  }
496  return;
497  }
498 
506  void Manager::unload(const char* fname)
507  {
508  RTC_TRACE(("Manager::unload()"));
509  m_module->unload(fname);
510  return;
511  }
512 
521  {
522  RTC_TRACE(("Manager::unloadAll()"));
523  m_module->unloadAll();
524  return;
525  }
526 
533  std::vector<coil::Properties> Manager::getLoadedModules()
534  {
535  RTC_TRACE(("Manager::getLoadedModules()"));
536  return m_module->getLoadedModules();
537  }
538 
545 std::vector<coil::Properties> Manager::getLoadableModules()
546  {
547  RTC_TRACE(("Manager::getLoadableModules()"));
548  return m_module->getLoadableModules();
549  }
550 
551  //============================================================
552  // Component factory management
553  //============================================================
561  RtcNewFunc new_func,
562  RtcDeleteFunc delete_func)
563  {
564  RTC_TRACE(("Manager::registerFactory(%s)", profile["type_name"].c_str()));
565  FactoryBase* factory;
566  factory = new FactoryCXX(profile, new_func, delete_func);
567  try
568  {
569  bool ret = m_factory.registerObject(factory);
570  if (!ret) {
571  delete factory;
572  return false;
573  }
574  return true;
575  }
576  catch (...)
577  {
578  delete factory;
579  return false;
580  }
581  }
582 
583  std::vector<coil::Properties> Manager::getFactoryProfiles()
584  {
585  std::vector<FactoryBase*> factories(m_factory.getObjects());
586  std::vector<coil::Properties> props;
587  for (int i(0), len(factories.size()); i < len; ++i)
588  {
589  props.push_back(factories[i]->profile());
590  }
591  return props;
592  }
593 
600  bool Manager::registerECFactory(const char* name,
601  ECNewFunc new_func,
602  ECDeleteFunc delete_func)
603  {
604  RTC_TRACE(("Manager::registerECFactory(%s)", name));
605  try
606  {
607  ECFactoryBase* factory;
608  factory = new ECFactoryCXX(name, new_func, delete_func);
609  if(m_ecfactory.registerObject(factory))
610  {
611  return true;
612  }
613  }
614  catch (...)
615  {
616  return false;
617  }
618  return false;
619  }
620 
627  std::vector<std::string> Manager::getModulesFactories()
628  {
629  RTC_TRACE(("Manager::getModulesFactories()"));
630 
631  ModuleFactories m;
632  return m_factory.for_each(m).modlist;
633  }
634 
635  //============================================================
636  // Component management
637  //============================================================
644  RTObject_impl* Manager::createComponent(const char* comp_args)
645  {
646  RTC_TRACE(("Manager::createComponent(%s)", comp_args));
647  //------------------------------------------------------------
648  // extract "comp_type" and "comp_prop" from comp_arg
649  coil::Properties comp_prop, comp_id;
650  if (!procComponentArgs(comp_args, comp_id, comp_prop)) return NULL;
651 
652  //------------------------------------------------------------
653  // Because the format of port-name had been changed from <port_name>
654  // to <instance_name>.<port_name>, the following processing was added.
655  // (since r1648)
656 
657  if (comp_prop.findNode("exported_ports") != 0)
658  {
659  coil::vstring exported_ports;
660  exported_ports = coil::split(comp_prop["exported_ports"], ",");
661 
662  std::string exported_ports_str("");
663  for (size_t i(0), len(exported_ports.size()); i < len; ++i)
664  {
665  coil::vstring keyval(coil::split(exported_ports[i], "."));
666  if (keyval.size() > 2)
667  {
668  exported_ports_str += (keyval[0] + "." + keyval.back());
669  }
670  else
671  {
672  exported_ports_str += exported_ports[i];
673  }
674 
675  if (i != exported_ports.size() - 1)
676  {
677  exported_ports_str += ",";
678  }
679  }
680 
681  comp_prop["exported_ports"] = exported_ports_str;
682  comp_prop["conf.default.exported_ports"] = exported_ports_str;
683 
684  }
685  //------------------------------------------------------------
686 
687  //------------------------------------------------------------
688  // Create Component
689  FactoryBase* factory(m_factory.find(comp_id));
690  if (factory == 0)
691  {
692  RTC_ERROR(("Factory not found: %s",
693  comp_id["implementation_id"].c_str()));
694 
695  // automatic module loading
696  std::vector<coil::Properties> mp(m_module->getLoadableModules());
697  RTC_INFO(("%d loadable modules found", mp.size()));
698 
699  std::vector<coil::Properties>::iterator it;
700  it = std::find_if(mp.begin(), mp.end(), ModulePredicate(comp_id));
701  if (it == mp.end())
702  {
703  RTC_ERROR(("No module for %s in loadable modules list",
704  comp_id["implementation_id"].c_str()));
705  return 0;
706  }
707  if (it->findNode("module_file_name") == 0)
708  {
709  RTC_ERROR(("Hmm...module_file_name key not found."));
710  return 0;
711  }
712  // module loading
713  RTC_INFO(("Loading module: %s", (*it)["module_file_name"].c_str()))
714  load((*it)["module_file_name"].c_str(), "");
715  factory = m_factory.find(comp_id);
716  if (factory == 0)
717  {
718  RTC_ERROR(("Factory not found for loaded module: %s",
719  comp_id["implementation_id"].c_str()));
720  return 0;
721  }
722  }
723 
725  prop = factory->profile();
726 
727  const char* inherit_prop[] = {
728  "config.version",
729  "openrtm.name",
730  "openrtm.version",
731  "os.name",
732  "os.release",
733  "os.version",
734  "os.arch",
735  "os.hostname",
736  "corba.endpoint",
737  "corba.id",
738  "exec_cxt.periodic.type",
739  "exec_cxt.periodic.rate",
740  "exec_cxt.evdriven.type",
741  "logger.enable",
742  "logger.log_level",
743  "naming.enable",
744  "naming.type",
745  "naming.formats",
746  ""
747  };
748 
749  for (int i(0); inherit_prop[i][0] != '\0'; ++i)
750  {
751  const char* key(inherit_prop[i]);
752  if (m_config.findNode(key) != NULL)
753  {
754  prop[key] = m_config[key];
755  }
756  }
757 
758  RTObject_impl* comp;
759  comp = factory->create(this);
760  if (comp == NULL)
761  {
762  RTC_ERROR(("RTC creation failed: %s",
763  comp_id["implementation_id"].c_str()));
764  return NULL;
765  }
766  RTC_TRACE(("RTC created: %s", comp_id["implementation_id"].c_str()));
767 
768  prop << comp_prop;
769 
770  //------------------------------------------------------------
771  // Load configuration file specified in "rtc.conf"
772  //
773  // rtc.conf:
774  // [category].[type_name].config_file = file_name
775  // [category].[instance_name].config_file = file_name
776  configureComponent(comp, prop);
777 
778  // comp->setProperties(prop);
779 
780  //------------------------------------------------------------
781  // Component initialization
782  if (comp->initialize() != RTC::RTC_OK)
783  {
784  RTC_TRACE(("RTC initialization failed: %s",
785  comp_id["implementation_id"].c_str()));
786  RTC_TRACE(("%s was finalized", comp_id["implementation_id"].c_str()));
787  if (comp->exit() != RTC::RTC_OK)
788  {
789  RTC_DEBUG(("%s finalization was failed.",
790  comp_id["implementation_id"].c_str()));
791  }
792  return NULL;
793  }
794  RTC_TRACE(("RTC initialization succeeded: %s",
795  comp_id["implementation_id"].c_str()));
796  //------------------------------------------------------------
797  // Bind component to naming service
798  registerComponent(comp);
799  return comp;
800  }
801 
809  {
810  RTC_TRACE(("Manager::registerComponent(%s)", comp->getInstanceName()));
811  // ### NamingManager ¤Î¤ß¤ÇÂåÍѲÄǽ
813 
814  std::vector<std::string> names(comp->getNamingNames());
815 
816  for (int i(0), len(names.size()); i < len; ++i)
817  {
818  RTC_TRACE(("Bind name: %s", names[i].c_str()));
819  m_namingManager->bindObject(names[i].c_str(), comp);
820  }
821  return true;
822  }
823 
831  {
832  RTC_TRACE(("Manager::unregisterComponent(%s)", comp->getInstanceName()));
833  // ### NamingManager ¤Î¤ß¤ÇÂåÍѲÄǽ
835 
836  coil::vstring names(comp->getNamingNames());
837 
838  for (int i(0), len(names.size()); i < len; ++i)
839  {
840  RTC_TRACE(("Unbind name: %s", names[i].c_str()));
841  m_namingManager->unbindObject(names[i].c_str());
842  }
843 
844  return true;
845  }
846 
847 
849  {
850  RTC_TRACE(("Manager::createContext()"));
851  RTC_TRACE(("ExecutionContext type: %s",
852  m_config.getProperty("exec_cxt.periodic.type").c_str()));
853 
854  std::string ec_id;
855  coil::Properties ec_prop;
856  if (!procContextArgs(ec_args, ec_id, ec_prop)) return NULL;
857 
858  ECFactoryBase* factory(m_ecfactory.find(ec_id.c_str()));
859  if (factory == NULL)
860  {
861  RTC_ERROR(("Factory not found: %s", ec_id.c_str()));
862  return NULL;
863  }
864 
866  ec = factory->create();
867  return ec;
868  }
869 
877  {
878  RTC_TRACE(("deleteComponent(RTObject*)"));
879  // cleanup from manager's table, and naming serivce
880  unregisterComponent(comp);
881 
882  // find factory
883  coil::Properties& comp_id(comp->getProperties());
884  FactoryBase* factory(m_factory.find(comp_id));
885  if (factory == NULL)
886  {
887  RTC_DEBUG(("Factory not found: %s",
888  comp_id["implementation_id"].c_str()));
889  return;
890  }
891  else
892  {
893  RTC_DEBUG(("Factory found: %s",
894  comp_id["implementation_id"].c_str()));
895  factory->destroy(comp);
896  }
897 
898  if (coil::toBool(m_config["manager.shutdown_on_nortcs"],
899  "YES", "NO", true) &&
900  !coil::toBool(m_config["manager.is_master"], "YES", "NO", false))
901  {
902  std::vector<RTObject_impl*> comps;
903  comps = getComponents();
904  if (comps.size() == 0)
905  {
906  shutdown();
907  }
908  }
909  }
910 
911  void Manager::deleteComponent(const char* instance_name)
912  {
913  RTC_TRACE(("deleteComponent(%s)", instance_name));
914  RTObject_impl* comp;
915  comp = m_compManager.find(instance_name);
916  if (comp == 0)
917  {
918  RTC_WARN(("RTC %s was not found in manager.", instance_name));
919  return;
920  }
921  deleteComponent(comp);
922  }
923 
930  RTObject_impl* Manager::getComponent(const char* instance_name)
931  {
932  RTC_TRACE(("Manager::getComponent(%s)", instance_name));
933  return m_compManager.find(instance_name);
934  }
935 
942  std::vector<RTObject_impl*> Manager::getComponents()
943  {
944  RTC_TRACE(("Manager::getComponents()"));
945  return m_compManager.getObjects();
946  }
947 
948  //============================================================
949  // CORBA ´ØÏ¢
950  //============================================================
957  CORBA::ORB_ptr Manager::getORB()
958  {
959  RTC_TRACE(("Manager::getORB()"));
960  return m_pORB;
961  }
962 
969  PortableServer::POA_ptr Manager::getPOA()
970  {
971  RTC_TRACE(("Manager::getPOA()"));
972  return m_pPOA;
973  }
974 
981  PortableServer::POAManager_ptr Manager::getPOAManager()
982  {
983  RTC_TRACE(("Manager::getPOAManager()"));
984  return m_pPOAManager;
985  }
986 
987  //============================================================
988  // Protected functions
989  //============================================================
990 
991  //============================================================
992  // Manager initialization and finalization
993  //============================================================
1001  void Manager::initManager(int argc, char** argv)
1002  {
1003  // load configurations
1004  ManagerConfig config(argc, argv);
1005  config.configure(m_config);
1006  m_config["logger.file_name"] =
1007  formatString(m_config["logger.file_name"].c_str(), m_config);
1008 
1009  // initialize ModuleManager
1011 
1012  // initialize Terminator
1013  m_terminator = new Terminator(this);
1014  {
1015  Guard guard(m_terminate.mutex);
1016  m_terminate.waiting = 0;
1017  }
1018 
1019  // initialize Timer
1020  if (coil::toBool(m_config["timer.enable"], "YES", "NO", true))
1021  {
1022  coil::TimeValue tm(0, 100000);
1023  std::string tick(m_config["timer.tick"]);
1024  if (!tick.empty())
1025  {
1026  tm = atof(tick.c_str());
1027  m_timer = new coil::Timer(tm);
1028  m_timer->start();
1029  }
1030  }
1031 
1032  if (coil::toBool(m_config["manager.shutdown_auto"], "YES", "NO", true) &&
1033  !coil::toBool(m_config["manager.is_master"], "YES", "NO", false))
1034  {
1035  coil::TimeValue tm(10, 0);
1036  if (m_config.findNode("manager.auto_shutdown_duration") != NULL)
1037  {
1038  double duration;
1039  const char* s = m_config["manager.auto_shutdown_duration"].c_str();
1040  if (coil::stringTo(duration, s))
1041  {
1042  tm = duration;
1043  }
1044  }
1045  if (m_timer != NULL)
1046  {
1049  }
1050  }
1051 
1052  {
1053  coil::TimeValue tm(1, 0);
1054  if (m_timer != NULL)
1055  {
1058  }
1059  }
1060 
1061  }
1062 
1071  {
1072  RTC_TRACE(("Manager::shutdownManager()"));
1073  m_timer->stop();
1074  }
1075 
1077  {
1078  RTC_TRACE(("Manager::shutdownOnNoRtcs()"));
1079  if (coil::toBool(m_config["manager.shutdown_on_nortcs"], "YES", "NO", true))
1080  {
1081  std::vector<RTObject_impl*> comps(getComponents());
1082  if (comps.size() == 0)
1083  {
1084  shutdown();
1085  }
1086  }
1087 
1088  }
1089 
1090  //============================================================
1091  // Logger initialization and finalization
1092  //============================================================
1101  {
1102  rtclog.setLevel("SILENT");
1103  rtclog.setName("manager");
1104 
1105  if (!coil::toBool(m_config["logger.enable"], "YES", "NO", true))
1106  {
1107  return true;
1108  }
1109 
1110  std::vector<std::string> logouts;
1111  logouts = coil::split(m_config["logger.file_name"], ",");
1112 
1113  for (int i(0), len(logouts.size()); i < len; ++i)
1114  {
1115  std::string logfile(logouts[i]);
1116  if (logfile == "") continue;
1117 
1118  // Open logfile
1119  if (logfile == "STDOUT" || logfile == "stdout")
1120  {
1121  m_logStreamBuf.addStream(std::cout.rdbuf());
1122  continue;
1123  }
1124 
1125  std::filebuf* of = new std::filebuf();
1126  of->open(logfile.c_str(), std::ios::out | std::ios::app);
1127 
1128  if (!of->is_open())
1129  {
1130  std::cerr << "Error: cannot open logfile: "
1131  << logfile << std::endl;
1132  delete of;
1133  continue;
1134  }
1135  m_logStreamBuf.addStream(of, true);
1136  m_logfiles.push_back(of);
1137  }
1138 
1139 
1140  // Set date format for log entry header
1141  rtclog.setDateFormat(m_config["logger.date_format"].c_str());
1142 
1143  // Loglevel was set from configuration file.
1144  rtclog.setLevel(m_config["logger.log_level"].c_str());
1145 
1146  // Log stream mutex locking mode
1147  coil::toBool(m_config["logger.stream_lock"],
1148  "enable", "disable", false) ?
1150 
1151 
1152  RTC_INFO(("%s", m_config["openrtm.version"].c_str()));
1153  RTC_INFO(("Copyright (C) 2003-2014"));
1154  RTC_INFO((" Noriaki Ando"));
1155  RTC_INFO((" Intelligent Systems Research Institute, AIST"));
1156  RTC_INFO(("Manager starting."));
1157  RTC_INFO(("Starting local logging."));
1158 
1159  return true;;
1160  }
1161 
1170  {
1171  RTC_TRACE(("Manager::shutdownLogger()"));
1172  rtclog.flush();
1173 
1174  for (int i(0), len(m_logfiles.size()); i < len; ++i)
1175  {
1176  m_logfiles[i]->close();
1177  // m_logStreamBuf.removeStream(m_logfiles[i]->rdbuf());
1178  delete m_logfiles[i];
1179  }
1180  if (!m_logfiles.empty())
1181  {
1182  m_logfiles.clear();
1183  }
1184  }
1185 
1186  //============================================================
1187  // ORB initialization and finalization
1188  //============================================================
1197  {
1198  RTC_TRACE(("Manager::initORB()"));
1199  // Initialize ORB
1200  try
1201  {
1202  std::vector<std::string> args(coil::split(createORBOptions(), " "));
1203  // TAO's ORB_init needs argv[0] as command name.
1204  args.insert(args.begin(), "manager");
1205  char** argv = coil::toArgv(args);
1206  int argc(args.size());
1207 
1208  // ORB initialization
1209  m_pORB = CORBA::ORB_init(argc, argv);
1210  // Get the RootPOA
1211  CORBA::Object_var obj =
1212  m_pORB->resolve_initial_references((char*)"RootPOA");
1213  m_pPOA = PortableServer::POA::_narrow(obj);
1214  if (CORBA::is_nil(m_pPOA))
1215  {
1216  RTC_ERROR(("Could not resolve RootPOA."));
1217  return false;
1218  }
1219  // Get the POAManager
1220  m_pPOAManager = m_pPOA->the_POAManager();
1221 
1222 #ifdef ORB_IS_OMNIORB
1223  const char* conf = "corba.alternate_iiop_addresses";
1224  if (m_config.findNode(conf) != NULL)
1225  {
1226  coil::vstring addr_list;
1227  addr_list = coil::split(m_config[conf], ",", true);
1228 
1229  for (size_t i(0); i < addr_list.size(); ++i)
1230  {
1231  coil::vstring addr_port = coil::split(addr_list[i], ":");
1232  if (addr_port.size() == 2)
1233  {
1234  IIOP::Address iiop_addr;
1235  iiop_addr.host = addr_port[0].c_str();
1236  CORBA::UShort port;
1237  coil::stringTo(port, addr_port[1].c_str());
1238  iiop_addr.port = port;
1239 #if defined(RTM_OMNIORB_40) || defined(RTM_OMNIORB_41)
1240  omniIOR::add_IIOP_ADDRESS(iiop_addr);
1241 #else
1242  omniIOR::add_IIOP_ADDRESS(iiop_addr, 0);
1243 #endif // defined(RTC_OMNIORB_40) and defined(RTC_OMNIORB_41)
1244  }
1245  }
1246  }
1247 #endif // ORB_IS_OMNIORB
1248  }
1249  catch (...)
1250  {
1251  RTC_ERROR(("Exception: Caught unknown exception in initORB()." ));
1252  return false;
1253  }
1254  return true;
1255  }
1256 
1265  {
1266  std::string opt(m_config["corba.args"]);
1267  RTC_DEBUG(("corba.args: %s", opt.c_str()));
1268 
1270 
1271  coil::vstring endpoints;
1272  createORBEndpoints(endpoints);
1273  createORBEndpointOption(opt, endpoints);
1274 
1275  RTC_PARANOID(("ORB options: %s", opt.c_str()));
1276  return opt;
1277  }
1278 
1280  {
1281  // corba.endpoint is obsolete
1282  // corba.endpoints with comma separated values are acceptable
1283  if (m_config.findNode("corba.endpoints") != 0)
1284  {
1285  endpoints = coil::split(m_config["corba.endpoints"], ",");
1286  RTC_DEBUG(("corba.endpoints: %s", m_config["corba.endpoints"].c_str()));
1287  }
1288 
1289  if (m_config.findNode("corba.endpoint") != 0)
1290  {
1291  coil::vstring tmp(coil::split(m_config["corba.endpoint"], ","));
1292  endpoints.insert(endpoints.end(), tmp.begin(), tmp.end());
1293  RTC_DEBUG(("corba.endpoint: %s", m_config["corba.endpoint"].c_str()));
1294  }
1295  // If this process has master manager,
1296  // master manager's endpoint inserted at the top of endpoints
1297  RTC_DEBUG(("manager.is_master: %s",
1298  m_config["manager.is_master"].c_str()));
1299  if (coil::toBool(m_config["manager.is_master"], "YES", "NO", false))
1300  {
1301  std::string mm(m_config.getProperty("corba.master_manager", ":2810"));
1302  coil::vstring mmm(coil::split(mm, ":"));
1303  if (mmm.size() == 2)
1304  {
1305  endpoints.insert(endpoints.begin(), std::string(":") + mmm[1]);
1306  }
1307  else
1308  {
1309  endpoints.insert(endpoints.begin(), ":2810");
1310  }
1311  }
1312  coil::vstring tmp(endpoints);
1313  endpoints = coil::unique_sv(tmp);
1314  }
1315 
1316  void Manager::createORBEndpointOption(std::string& opt,
1317  coil::vstring& endpoints)
1318  {
1319  std::string corba(m_config["corba.id"]);
1320  RTC_DEBUG(("corba.id: %s", corba.c_str()));
1321 
1322  for (size_t i(0); i < endpoints.size(); ++i)
1323  {
1324  std::string& endpoint(endpoints[i]);
1325  RTC_DEBUG(("Endpoint is : %s", endpoint.c_str()));
1326  if (endpoint.find(":") == std::string::npos) { endpoint += ":"; }
1327 
1328  if (corba == "omniORB")
1329  {
1330  coil::normalize(endpoint);
1331  if (coil::normalize(endpoint) == "all:")
1332  {
1333 #ifdef ORB_IS_OMNIORB
1334 #ifdef RTC_CORBA_CXXMAPPING11
1335  // omniORB 4.1 or later
1336  opt += " -ORBendPointPublish all(addr)";
1337 #else
1338  // omniORB 4.0
1339  opt += " -ORBendPointPublishAllIFs 1";
1340 #endif // RTC_CORBA_CXXMAPPING1
1341 #endif // ORB_IS_OMNIORB
1342  }
1343  else
1344  {
1345  opt += " -ORBendPoint giop:tcp:" + endpoint;
1346  }
1347  }
1348  else if (corba == "TAO")
1349  {
1350  opt += "-ORBEndPoint iiop://" + endpoint;
1351  }
1352  else if (corba == "MICO")
1353  {
1354  opt += "-ORBIIOPAddr inet:" + endpoint;
1355  }
1356  }
1357  }
1358 
1359 
1368  {
1369  RTC_TRACE(("Manager::shutdownORB()"));
1370  if(CORBA::is_nil(m_pORB))
1371  {
1372  return;
1373  }
1374  try
1375  {
1376  while (m_pORB->work_pending())
1377  {
1378  RTC_PARANOID(("Pending work still exists."));
1379  if (m_pORB->work_pending())
1380  m_pORB->perform_work();
1381  }
1382  RTC_DEBUG(("No pending works of ORB. Shutting down POA and ORB."));
1383  }
1384  catch(...)
1385  {
1386  RTC_ERROR(("Caught SystemException during perform_work."));
1387  }
1388 
1389  if (!CORBA::is_nil(m_pPOA))
1390  {
1391  try
1392  {
1393  if (!CORBA::is_nil(m_pPOAManager))
1394  m_pPOAManager->deactivate(false, true);
1395  RTC_DEBUG(("POA Manager was deactivated."));
1396  m_pPOA->destroy(false, true);
1397  m_pPOA = PortableServer::POA::_nil();
1398  RTC_DEBUG(("POA was destroid."));
1399  }
1400  catch (CORBA::SystemException& ex)
1401  {
1402  RTC_ERROR(("Exception cought during root POA destruction"));
1403 #ifndef ORB_IS_RTORB
1404  RTC_ERROR(("CORBA::SystemException(minor=%d)", ex.minor()));
1405 #endif // ORB_IS_RTORB
1406  }
1407  catch (...)
1408  {
1409  RTC_ERROR(("Caught unknown exception during POA destruction."));
1410  }
1411  }
1412 
1413  if (!CORBA::is_nil(m_pORB))
1414  {
1415  try
1416  {
1417  m_pORB->shutdown(true);
1418  RTC_DEBUG(("ORB was shutdown."));
1419  //m_pORB->destroy();
1420  RTC_DEBUG(("ORB was destroied."));
1421  m_pORB = CORBA::ORB::_nil();
1422  }
1423  catch (CORBA::SystemException& ex)
1424  {
1425  RTC_ERROR(("Exception caught during ORB shutdown"));
1426 #ifndef ORB_IS_RTORB
1427  RTC_ERROR(("CORBA::SystemException(minodor=%d)", ex.minor()));
1428 #endif // ORB_IS_RTORB
1429  }
1430  catch (...)
1431  {
1432  RTC_ERROR(("Caught unknown exception during ORB shutdown."));
1433  }
1434  }
1435  }
1436 
1437  //============================================================
1438  // Naming initialization and finalization
1439  //============================================================
1448  {
1449  RTC_TRACE(("Manager::initNaming()"));
1450 
1451  m_namingManager = new NamingManager(this);
1452 
1453  // If NameService is disabled, return immediately
1454  if (!coil::toBool(m_config["naming.enable"], "YES", "NO", true))
1455  {
1456  return true;
1457  }
1458 
1459  // NameServer registration for each method and servers
1460  std::vector<std::string> meth(coil::split(m_config["naming.type"], ","));
1461 
1462  for (int i(0), len_i(meth.size()); i < len_i; ++i)
1463  {
1464  std::vector<std::string> names;
1465  names = coil::split(m_config[meth[i] + ".nameservers"], ",");
1466 
1467 
1468  for (int j(0), len_j(names.size()); j < len_j; ++j)
1469  {
1470  RTC_TRACE(("Register Naming Server: %s/%s", \
1471  meth[i].c_str(), names[j].c_str()));
1472  m_namingManager->registerNameServer(meth[i].c_str(),
1473  names[j].c_str());
1474  }
1475  }
1476 
1477  // NamingManager Timer update initialization
1478  if (coil::toBool(m_config["naming.update.enable"], "YES", "NO", true))
1479  {
1480  coil::TimeValue tm(10, 0); // default interval = 10sec for safty
1481  std::string intr(m_config["naming.update.interval"]);
1482  if (!intr.empty())
1483  {
1484  tm = atof(intr.c_str());
1485  }
1486  if (m_timer != NULL)
1487  {
1489  &NamingManager::update, tm);
1490  }
1491  }
1492  return true;
1493  }
1494 
1503  {
1504  RTC_TRACE(("Manager::shutdownNaming()"));
1506  delete m_namingManager;
1507  }
1508 
1509  //============================================================
1510  // Naming initialization and finalization
1511  //============================================================
1520  {
1521  RTC_TRACE(("Manager::initExecContext()"));
1525  return true;
1526  }
1527 
1529  {
1530  RTC_TRACE(("Manager::initComposite()"));
1532 
1533  return true;
1534  }
1535 
1537  {
1538  RTC_TRACE(("Manager::initFactories()"));
1539  FactoryInit();
1540  return true;
1541  }
1542 
1551  {
1552  return true;
1553  }
1554 
1555 
1557  {
1558  RTC_TRACE(("Manager::initManagerServant()"));
1559  if (!coil::toBool(m_config["manager.corba_servant"], "YES", "NO", true))
1560  {
1561  return true;
1562  }
1563  m_mgrservant = new ::RTM::ManagerServant();
1564  coil::Properties& prop(m_config.getNode("manager"));
1565  std::vector<std::string> names(coil::split(prop["naming_formats"], ","));
1566 
1567  if (coil::toBool(prop["is_master"], "YES", "NO", true))
1568  {
1569  for (int i(0), len(names.size()); i < len; ++i)
1570  {
1571  std::string mgr_name(formatString(names[i].c_str(), prop));
1572  m_namingManager->bindObject(mgr_name.c_str(), m_mgrservant);
1573  }
1574  }
1575 
1576  std::ifstream otherref(m_config["manager.refstring_path"].c_str());
1577  if (otherref.fail() != 0)
1578  {
1579  otherref.close();
1580  std::ofstream reffile(m_config["manager.refstring_path"].c_str());
1581  RTM::Manager_var mgr_v(RTM::Manager::
1582  _duplicate(m_mgrservant->getObjRef()));
1583  CORBA::String_var str_var = m_pORB->object_to_string(mgr_v);
1584  reffile << str_var;
1585  reffile.close();
1586  }
1587  else
1588  {
1589  std::string refstring;
1590  otherref >> refstring;
1591  otherref.close();
1592 
1593  CORBA::Object_var obj = m_pORB->string_to_object(refstring.c_str());
1594  RTM::Manager_var mgr = RTM::Manager::_narrow(obj);
1595  // if (CORBA::is_nil(mgr)) return false;
1596  // mgr->set_child(m_mgrservant->getObjRef());
1597  // m_mgrservant->set_owner(mgr);
1598  }
1599 
1600  return true;
1601  }
1602 
1611  {
1612  RTC_TRACE(("Manager::shutdownComponents()"));
1613  std::vector<RTObject_impl*> comps;
1614  comps = m_namingManager->getObjects();
1615  for (int i(0), len(comps.size()); i < len; ++i)
1616  {
1617  try
1618  {
1619  comps[i]->exit();
1620  coil::Properties p(comps[i]->getInstanceName());
1621  p << comps[i]->getProperties();
1622  rtclog.lock();
1624  rtclog.unlock();
1625  }
1626  catch (...)
1627  {
1628  ;
1629  }
1630  }
1631  for (CORBA::ULong i(0), len(m_ecs.size()); i < len; ++i)
1632  {
1633  try{
1634  PortableServer::ObjectId_var oid = m_pPOA->servant_to_id(m_ecs[i]);
1635  m_pPOA->deactivate_object(oid);
1636  }
1637  catch (...)
1638  {
1639  ;
1640  }
1641  }
1642  }
1643 
1651  {
1652  RTC_TRACE(("Manager::cleanupComponent()"));
1653  unregisterComponent(comp);
1654  }
1655 
1657  {
1658  RTC_VERBOSE(("Manager::cleanupComponents()"));
1659  Guard guard(m_finalized.mutex);
1660  RTC_VERBOSE(("%d components are marked as finalized.",
1661  m_finalized.comps.size()));
1662  for (size_t i(0); i < m_finalized.comps.size(); ++i)
1663  {
1665  }
1666  m_finalized.comps.clear();
1667  }
1668 
1670  {
1671  RTC_TRACE(("Manager::notifyFinalized()"));
1672  Guard guard(m_finalized.mutex);
1673  m_finalized.comps.push_back(comp);
1674  }
1675 
1682  bool Manager::procComponentArgs(const char* comp_arg,
1683  coil::Properties& comp_id,
1684  coil::Properties& comp_conf)
1685  {
1686  std::vector<std::string> id_and_conf(coil::split(comp_arg, "?"));
1687  // arg should be "id?key0=value0&key1=value1...".
1688  // id is mandatory, conf is optional
1689  if (id_and_conf.size() != 1 && id_and_conf.size() != 2)
1690  {
1691  RTC_ERROR(("Invalid arguments. Two or more '?' in arg : %s", comp_arg));
1692  return false;
1693  }
1694  if (id_and_conf[0].find(":") == std::string::npos)
1695  {
1696  id_and_conf[0].insert(0, "RTC:::");
1697  id_and_conf[0] += ":";
1698  }
1699  std::vector<std::string> id(coil::split(id_and_conf[0], ":"));
1700 
1701  // id should be devided into 1 or 5 elements
1702  // RTC:[vendor]:[category]:impl_id:[version] => 5
1703  if (id.size() != 5)
1704  {
1705  RTC_ERROR(("Invalid RTC id format.: %s", id_and_conf[0].c_str()));
1706  return false;
1707  }
1708 
1709  const char* prof[] =
1710  {
1711  "RTC", "vendor", "category", "implementation_id", "version"
1712  };
1713 
1714  if (id[0] != prof[0])
1715  {
1716  RTC_ERROR(("Invalid id type: %s", id[0].c_str()));
1717  return false;
1718  }
1719  for (int i(1); i < 5; ++i)
1720  {
1721  comp_id[prof[i]] = id[i];
1722  RTC_TRACE(("RTC basic propfile %s: %s", prof[i], id[i].c_str()));
1723  }
1724 
1725  if (id_and_conf.size() == 2)
1726  {
1727  std::vector<std::string> conf(coil::split(id_and_conf[1], "&"));
1728  for (int i(0), len(conf.size()); i < len; ++i)
1729  {
1730  if (conf[i].empty()) { continue; }
1731  std::vector<std::string> keyval(coil::split(conf[i], "="));
1732  if (keyval.size() != 2) { continue; }
1733  comp_conf[keyval[0]] = keyval[1];
1734  RTC_TRACE(("RTC property %s: %s",
1735  keyval[0].c_str(), keyval[1].c_str()));
1736  }
1737  }
1738  return true;
1739  }
1740 
1741  bool Manager::procContextArgs(const char* ec_args,
1742  std::string& ec_id,
1743  coil::Properties& ec_conf)
1744  {
1745  std::vector<std::string> id_and_conf(coil::split(ec_args, "?"));
1746  if (id_and_conf.size() != 1 && id_and_conf.size() != 2)
1747  {
1748  RTC_ERROR(("Invalid arguments. Two or more '?' in arg : %s", ec_args));
1749  return false;
1750  }
1751  if (id_and_conf[0].empty())
1752  {
1753  RTC_ERROR(("Empty ExecutionContext's name"));
1754  return false;
1755  }
1756  ec_id =id_and_conf[0];
1757 
1758  if (id_and_conf.size() == 2)
1759  {
1760  std::vector<std::string> conf(coil::split(id_and_conf[1], "&"));
1761  for (int i(0), len(conf.size()); i < len; ++i)
1762  {
1763  std::vector<std::string> k(coil::split(conf[i], "="));
1764  ec_conf[k[0]] = k[1];
1765  RTC_TRACE(("EC property %s: %s", k[0].c_str(), k[1].c_str()));
1766  }
1767  }
1768  return true;
1769  }
1770 
1779  const coil::Properties& prop)
1780  {
1781  std::string category(comp->getCategory());
1782  std::string type_name(comp->getTypeName());
1783  std::string inst_name(comp->getInstanceName());
1784 
1785  std::string type_conf(category + "." + type_name + ".config_file");
1786  std::string name_conf(category + "." + inst_name + ".config_file");
1787  coil::vstring config_fname;
1788 
1789  coil::Properties type_prop, name_prop;
1790 
1791  // Load "category.instance_name.config_file"
1792  if (!m_config[name_conf].empty())
1793  {
1794  std::ifstream conff(m_config[name_conf].c_str());
1795  if (!conff.fail())
1796  {
1797  name_prop.load(conff);
1798  RTC_INFO(("Component instance conf file: %s loaded.",
1799  m_config[name_conf].c_str()));
1800  RTC_DEBUG_STR((name_prop))
1801  config_fname.push_back(m_config[name_conf].c_str());
1802  }
1803  }
1804  if (m_config.findNode(category + "." + inst_name) != NULL)
1805  {
1806  coil::Properties& temp(m_config.getNode(category + "." + inst_name));
1807  coil::vstring keys(temp.propertyNames());
1808  if (!(keys.size() == 1 && keys.back() == "config_file"))
1809  {
1810  name_prop << m_config.getNode(category + "." + inst_name);
1811  RTC_INFO(("Component type conf exists in rtc.conf. Merged."));
1812  RTC_DEBUG_STR((name_prop));
1813  if (m_config.findNode("config_file") != NULL)
1814  {
1815  config_fname.push_back(m_config["config_file"]);
1816  }
1817  }
1818  }
1819 
1820  if (!m_config[type_conf].empty())
1821  {
1822  std::ifstream conff(m_config[type_conf].c_str());
1823  if (!conff.fail())
1824  {
1825  type_prop.load(conff);
1826  RTC_INFO(("Component type conf file: %s loaded.",
1827  m_config[type_conf].c_str()));
1828  RTC_DEBUG_STR((type_prop));
1829  config_fname.push_back(m_config[type_conf].c_str());
1830  }
1831  }
1832  if (m_config.findNode(category + "." + type_name) != NULL)
1833  {
1834  coil::Properties& temp(m_config.getNode(category + "." + type_name));
1835  coil::vstring keys(temp.propertyNames());
1836  if (!(keys.size() == 1 && keys.back() == "config_file"))
1837  {
1838  type_prop << m_config.getNode(category + "." + type_name);
1839  RTC_INFO(("Component type conf exists in rtc.conf. Merged."));
1840  RTC_DEBUG_STR((type_prop));
1841  if (m_config.findNode("config_file") != NULL)
1842  {
1843  config_fname.push_back(m_config["config_file"]);
1844  }
1845  }
1846  }
1847 
1848  // Merge Properties. type_prop is merged properties
1849  comp->setProperties(prop);
1850  type_prop << name_prop;
1851  type_prop["config_file"] = coil::flatten(coil::unique_sv(config_fname));
1852  comp->setProperties(type_prop);
1853 
1854  //------------------------------------------------------------
1855  // Format component's name for NameService
1856  std::string naming_formats;
1857  coil::Properties& comp_prop(comp->getProperties());
1858 
1859  naming_formats += m_config["naming.formats"];
1860  if (comp_prop.findNode("naming.formats") != 0)
1861  {
1862  naming_formats = comp_prop["naming.formats"];
1863  }
1864  naming_formats = coil::flatten(coil::unique_sv(coil::split(naming_formats,
1865  ",")));
1866 
1867  std::string naming_names;
1868  naming_names = formatString(naming_formats.c_str(), comp->getProperties());
1869  comp->getProperties()["naming.formats"] = naming_formats;
1870  comp->getProperties()["naming.names"] = naming_names;
1871  }
1872 
1880  bool Manager::mergeProperty(coil::Properties& prop, const char* file_name)
1881  {
1882  if (file_name == NULL)
1883  {
1884  RTC_ERROR(("Invalid configuration file name."));
1885  return false;
1886  }
1887  if (file_name[0] != '\0')
1888  {
1889  std::ifstream conff(file_name);
1890  if (!conff.fail())
1891  {
1892  prop.load(conff);
1893  conff.close();
1894  return true;
1895  }
1896  }
1897  return false;
1898  }
1899 
1906  std::string Manager::formatString(const char* naming_format,
1908  {
1909  std::string name(naming_format), str("");
1910  std::string::iterator it, it_end;
1911  int count(0);
1912 
1913  it = name.begin();
1914  it_end = name.end();
1915  for ( ; it != it_end; ++it)
1916  {
1917  char c(*it);
1918  if (c == '%')
1919  {
1920  ++count;
1921  if (!(count % 2)) str.push_back((*it));
1922  }
1923  else if (c == '$')
1924  {
1925  count = 0;
1926  ++it;
1927  if (*it == '{' || *it == '(')
1928  {
1929  ++it;
1930  std::string env;
1931  for ( ; it != it_end && (*it) != '}' && (*it) != ')'; ++it)
1932  {
1933  env += *it;
1934  }
1935  char* envval = coil::getenv(env.c_str());
1936  if (envval != NULL) str += envval;
1937  }
1938  else
1939  {
1940  str.push_back(c);
1941  }
1942  }
1943  else
1944  {
1945  if (count > 0 && (count % 2))
1946  {
1947  count = 0;
1948  if (c == 'n') str += prop["instance_name"];
1949  else if (c == 't') str += prop["type_name"];
1950  else if (c == 'm') str += prop["type_name"];
1951  else if (c == 'v') str += prop["version"];
1952  else if (c == 'V') str += prop["vendor"];
1953  else if (c == 'c') str += prop["category"];
1954  else if (c == 'i') str += prop["implementation_id"];
1955  else if (c == 'N')
1956  {
1957  size_t n = prop["implementation_id"].size();
1958  str += prop["instance_name"].substr(n);
1959  }
1960  else if (c == 'h') str += m_config["os.hostname"];
1961  else if (c == 'M') str += m_config["manager.name"];
1962  else if (c == 'p') str += m_config["manager.pid"];
1963  else str.push_back(c);
1964  }
1965  else
1966  {
1967  count = 0;
1968  str.push_back(c);
1969  }
1970  }
1971  }
1972  return str;
1973  }
1974 
1975 };
void setDateFormat(const char *format)
Set date/time format for adding the header.
RTObject_impl *(* RtcNewFunc)(Manager *manager)
Definition: rtm/Factory.h:33
ECFactoryCXX class.
Definition: ECFactory.h:221
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
static Mutex mutex
The mutex of the pointer to the Manager.
Definition: Manager.h:1555
PortableServer::POAManager_ptr getPOAManager()
Get POAManager that Manager has.
Definition: Manager.cpp:981
std::string normalize(std::string &str)
Erase the head/tail blank and replace upper case to lower case.
Definition: stringutil.cpp:308
void(* ModuleInitProc)(Manager *manager)
Definition: Manager.h:58
RTObject_impl * createComponent(const char *comp_args)
Create RT-Components.
Definition: Manager.cpp:644
std::string createORBOptions()
Create ORB command options.
Definition: Manager.cpp:1264
Logger rtclog
Logger stream.
Definition: Manager.h:1654
bool procContextArgs(const char *ec_args, std::string &ec_id, coil::Properties &ec_conf)
Extracting ExecutionContext&#39;s name/properties from the given string.
Definition: Manager.cpp:1741
const char * getCategory()
[local interface] Get category information
Definition: RTObject.h:2099
RT-Component.
void deleteComponent(RTObject_impl *comp)
Unregister RT-Components that have been registered to Manager.
Definition: Manager.cpp:876
std::vector< coil::Properties > getLoadedModules()
Get a list of loaded modules.
Definition: Manager.cpp:533
std::vector< Object * > getObjects() const
Get a list of obejects that are registerd.
virtual int open(void *args)
ORB activation processing.
Definition: Manager.h:1894
Structure for exception handling when file open is failed.
RTComponent utils.
virtual ReturnCode_t initialize()
[CORBA interface] Initialize the RTC that realizes this interface.
Definition: RTObject.cpp:314
Term m_terminate
Synchronous flag for manager termination.
Definition: Manager.h:2103
bool stringTo(To &val, const char *str)
Convert the given std::string to object.
Definition: stringutil.h:597
PortableServer::POA_ptr getPOA()
Get a pointer to RootPOA held by Manager.
Definition: Manager.cpp:969
std::vector< coil::Properties > getLoadableModules()
Get the loadable module list.
FactoryManager m_factory
ComponentManager.
Definition: Manager.h:1780
factory initialization function
Mutex class.
void runManager(bool no_block=false)
Run the Manager.
Definition: Manager.cpp:448
void terminate()
Termination processing.
Definition: Manager.h:2019
RTObject_impl * getComponent(const char *instance_name)
Get RT-Component&#39;s pointer.
Definition: Manager.cpp:930
bool initFactories()
Factories initialization.
Definition: Manager.cpp:1536
void cleanupComponents()
This method deletes RT-Components.
Definition: Manager.cpp:1656
RTM::ManagerServant * m_mgrservant
The pointer to the ManagerServant.
Definition: Manager.h:1450
bool registerComponent(RTObject_impl *comp)
Register RT-Component directly without Factory.
Definition: Manager.cpp:808
std::vector< RTObject_impl * > getObjects()
Get all bound objects.
std::vector< coil::Properties > getLoadableModules()
Get a list of loadable modules.
Definition: Manager.cpp:545
void shutdown()
Shutdown Manager.
Definition: Manager.cpp:181
A base class for ExecutionContext.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
std::vector< std::string > getNamingNames()
[local interface] Get Naming Server information
Definition: RTObject.cpp:1461
RT-Component class.
Definition: RTObject.h:89
virtual ExecutionContextBase * create()=0
Pure virtual function to create ExecutionContext.
void terminate()
Terminate manager.
Definition: Manager.cpp:169
void load(const char *fname, const char *initfunc)
[CORBA interface] Load module
Definition: Manager.cpp:476
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:346
RTC manager configuration.
Manager class.
Definition: Manager.h:80
void bindObject(const char *name, const RTObject_impl *rtobj)
Bind the specified objects to NamingService.
Structure for exception handling when specified symbol cannot be found.
virtual PortServiceList * get_ports()
[RTObject CORBA interface] Get Ports
Definition: RTObject.cpp:752
bool initExecContext()
ExecutionContextManager initialization.
Definition: Manager.cpp:1519
void setName(const char *name)
Set suffix of date/time string of header.
vstring unique_sv(vstring sv)
Eliminate duplication from the given string list.
Definition: stringutil.cpp:542
void registerNameServer(const char *method, const char *name_server)
Regster the NameServer.
CORBA::ORB_ptr getORB()
Get the pointer to ORB.
Definition: Manager.cpp:957
std::string load(const std::string &file_name)
Load the module.
void PeriodicExecutionContextInit(RTC::Manager *manager)
Initialization function to register to ECFactory.
bool initComposite()
PeriodicECSharedComposite initialization.
Definition: Manager.cpp:1528
coil::Timer * m_timer
Timer Object.
Definition: Manager.h:1633
coil::Properties & getProperties()
[local interface] Get RTC property
Definition: RTObject.cpp:1529
void configure(coil::Properties &prop)
Specify the configuration information to the Property.
ListenerId registerListenerObj(ListenerClass *obj, void(ListenerClass::*cbf)(), TimeValue tm)
Register listener.
Definition: Timer.h:255
std::vector< coil::Properties > getLoadedModules()
Get the module list that has been loaded.
static GlobalFactory< AbstractClass, Identifier, Compare, Creator, Destructor > & instance()
Create instance.
Definition: Singleton.h:131
void OpenHRPExecutionContextInit(RTC::Manager *manager)
Initialization function to register to ECFactory.
static Manager & instance()
Get instance of the manager.
Definition: Manager.cpp:140
NamingManager * m_namingManager
The pointer to the NamingManager.
Definition: Manager.h:1624
void(* SignalHandler)(int)
void eraseBothEndsBlank(std::string &str)
Erase the head blank and the tail blank characters of string.
Definition: stringutil.cpp:295
TimeValue class.
Definition: TimeValue.h:40
#define RTC_WARN(fmt)
Warning log output macro.
Definition: SystemLogger.h:444
string mgr_name
Get Manager object reference.
RTComponent manager class.
#define RTC_DEBUG_STR(str)
Definition: SystemLogger.h:489
#define RTC_PARANOID(fmt)
Paranoid level log output macro.
Definition: SystemLogger.h:555
virtual int wait(void)
Waiting for the thread terminate.
std::vector< std::string > vstring
Definition: stringutil.h:37
const char * getTypeName()
[local interface] Get type name
Definition: RTObject.h:1998
void FactoryInit()
Definition: FactoryInit.cpp:36
std::vector< coil::Properties > getFactoryProfiles()
Get profiles of factories.
Definition: Manager.cpp:583
env
¥Í¡¼¥à¥µ¡¼¥Ð¡¼ÄêµÁ env = RtmEnv(sys.argv, ["localhost:2809"]) list0 = env.name_space["localhost:2809"].list_obj() env.name_space[&#39;localhost:2809&#39;].rtc_handles.keys() ns = env.name_space[&#39;localhost:2809&#39;]
Definition: ConnectTest.py:25
void stop()
Stop Timer task.
Definition: Timer.cpp:107
void addStream(streambuf_type *stream, bool cleanup=false)
Destructor.
static Manager * manager
The pointer to the Manager.
Definition: Manager.h:1546
void configureComponent(RTObject_impl *comp, const coil::Properties &prop)
Configure RT-Component.
Definition: Manager.cpp:1778
ECFactoryBase abstract class.
Definition: ECFactory.h:115
std::vector< std::filebuf * > m_logfiles
Files for log output.
Definition: Manager.h:1663
Periodic Execution Context Shared Composite Component class.
void notifyFinalized(RTObject_impl *comp)
This method deletes RT-Components.
Definition: Manager.cpp:1669
#define RTC_DEBUG(fmt)
Debug level log output macro.
Definition: SystemLogger.h:488
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
Definition: Properties.cpp:160
std::vector< ExecutionContextBase * > m_ecs
ExecutionContext list.
Definition: Manager.h:1817
CORBA naming service helper class.
std::string flatten(vstring sv)
Create CSV file from the given string list.
Definition: stringutil.cpp:554
void shutdownNaming()
NamingManager finalization.
Definition: Manager.cpp:1502
LogStreamBuf m_logStreamBuf
Logger buffer.
Definition: Manager.h:1645
Finalized m_finalized
Definition: Manager.h:2110
bool registerObject(Object *obj)
Register the specified object.
#define RTC_TRACE(fmt)
void shutdownLogger()
System Logger finalization.
Definition: Manager.cpp:1169
std::vector< std::string > getModulesFactories()
Get the list of all Factories.
Definition: Manager.cpp:627
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
void ExtTrigExecutionContextInit(RTC::Manager *manager)
Register Factory class for this ExecutionContext.
Properties *const findNode(const std::string &key) const
Get node of properties.
Definition: Properties.cpp:444
void handler(int)
Definition: Manager.cpp:48
Object * unregisterObject(const Identifier &id)
Unregister the specified object.
static Manager * init(int argc, char **argv)
Initialize manager.
Definition: Manager.cpp:110
OrbRunner class.
Definition: Manager.h:1851
Structure for exception handling when specified module cannot be found.
RTComponent manager servant implementation class.
void initManager(int argc, char **argv)
Manager internal initialization.
Definition: Manager.cpp:1001
char ** toArgv(const vstring &args)
Convert the given string list into the argument list.
Definition: stringutil.cpp:573
coil::Properties m_config
Managaer&#39;s configuration Properties.
Definition: Manager.h:1606
ExtTrigExecutionContext class.
CORBA::ORB_var m_pORB
The pointer to the ORB.
Definition: Manager.h:1567
Loadable modules manager class.
bool procComponentArgs(const char *comp_arg, coil::Properties &comp_id, coil::Properties &comp_conf)
Extracting component type/properties from the given string.
Definition: Manager.cpp:1682
ExecutionContextBase * createContext(const char *ec_args)
Create Context.
Definition: Manager.cpp:848
void load(std::istream &inStream)
Loads property list that consists of key:value from input stream.
Definition: Properties.cpp:338
Object * find(const Identifier &id) const
Find the object.
void enableLock()
Enable the lock mode.
InstanceName(RTObject_impl *comp)
Definition: Manager.cpp:58
void createORBEndpoints(coil::vstring &endpoints)
Create Endpoints.
Definition: Manager.cpp:1279
bool unregisterComponent(RTObject_impl *comp)
Unregister RT-Components.
Definition: Manager.cpp:830
Manager()
Protected Constructor.
Definition: Manager.cpp:80
void join()
Wait for Manager&#39;s termination.
Definition: Manager.cpp:207
virtual ReturnCode_t exit()
[CORBA interface]top the RTC&#39;s execution context(s) and finalize it along with its contents...
Definition: RTObject.cpp:398
unsigned int replaceString(std::string &str, const std::string from, const std::string to)
Replace string.
Definition: stringutil.cpp:322
void shutdownManager()
Shutdown Manager.
Definition: Manager.cpp:1070
RTObject_ptr getObjRef() const
[local interface] Get the object reference
Definition: RTObject.cpp:1487
RTM::Manager_ptr getObjRef() const
Get the reference of Manager.
ACE_Sig_Action SignalAction
const char * getInstanceName()
[local interface] Get instance name
Definition: RTObject.h:1952
Execution context for OpenHRP3.
Pred for_each(Pred p)
Functor for searching object.
bool activateManager()
Activate the Manager.
Definition: Manager.cpp:243
bool setLevel(const char *level)
Set log level by string.
bool registerECFactory(const char *name, ECNewFunc new_func, ECDeleteFunc delete_func)
Register ExecutionContext Factory.
Definition: Manager.cpp:600
prop
Organization::get_organization_property ();.
ModuleManager * m_module
The pointer to the ModuleManager.
Definition: Manager.h:1615
naming Service helper class
virtual ExecutionContextList * get_owned_contexts()
[CORBA interface] Get ExecutionContextList.
Definition: RTObject.cpp:503
CORBA IOR manipulation utility functions.
ostream_type & level(int level)
Acquire log stream.
Terminator * m_terminator
The pointer to ORB termination helper class.
Definition: Manager.h:2083
void unloadAll()
Unload all modules.
Definition: Manager.cpp:520
Timer class.
Definition: Timer.h:53
bool mergeProperty(coil::Properties &prop, const char *file_name)
Merge property information.
Definition: Manager.cpp:1880
Class represents a set of properties.
Definition: Properties.h:101
void unloadAll()
Unload all modules.
void unload(const char *fname)
Unload module.
Definition: Manager.cpp:506
char * getenv(const char *name)
Get environment variable.
Definition: ace/coil/OS.h:48
bool toBool(std::string str, std::string yes, std::string no, bool default_value)
Convert given string into bool value.
Definition: stringutil.cpp:415
void createORBEndpointOption(std::string &opt, coil::vstring &endpoint)
Create a command optional line of Endpoint of ORB.
Definition: Manager.cpp:1316
int size(void) const
Get the number of Properties.
Definition: Properties.cpp:432
ExecutionContextBase *(* ECNewFunc)()
Definition: ECFactory.h:29
void update()
Update information of NamingServer.
std::vector< RTObject_impl * > comps
Definition: Manager.h:2108
void setModuleInitProc(ModuleInitProc proc)
Set initial procedure.
Definition: Manager.cpp:231
PeriodicExecutionContext class.
bool initManagerServant()
ManagerServant initialization.
Definition: Manager.cpp:1556
FactoryBase base class.
Definition: rtm/Factory.h:118
void shutdownOnNoRtcs()
Shutdown Manager.
Definition: Manager.cpp:1076
bool initLogger()
System logger initialization.
Definition: Manager.cpp:1100
bool initNaming()
NamingManager initialization.
Definition: Manager.cpp:1447
#define RTC_INFO(fmt)
Information level log output macro.
Definition: SystemLogger.h:466
void unload(const std::string &file_name)
Unload the module.
void lock()
Acquire log lock Acquire log lock when the lock mode is set.
void(* RtcDeleteFunc)(RTObject_impl *rtc)
Definition: rtm/Factory.h:34
ComponentManager m_compManager
ComponentManager.
Definition: Manager.h:1687
RTComponent header.
void copyFromProperties(SDOPackage::NVList &nv, const coil::Properties &prop)
Copy the properties to NVList.
Definition: NVUtil.cpp:108
bool operator()(RTObject_impl *comp)
Definition: Manager.cpp:67
void cleanupComponent(RTObject_impl *comp)
Unregister RT-Components.
Definition: Manager.cpp:1650
Properties & getNode(const std::string &key)
Get node of properties.
Definition: Properties.cpp:460
PortableServer::POA_var m_pPOA
The pointer to the POA.
Definition: Manager.h:1576
FactoryCXX class.
Definition: rtm/Factory.h:286
void disableLock()
Disable the lock mode.
void unlock()
Release the log lock Release the log lock when the lock mode is set.
void shutdownORB()
ORB finalization.
Definition: Manager.cpp:1367
ECFactoryManager m_ecfactory
ExecutionContext Manager.
Definition: Manager.h:1808
void PeriodicECSharedCompositeInit(RTC::Manager *manager)
bool initTimer()
Timer initialization.
Definition: Manager.cpp:1550
std::string formatString(const char *naming_format, coil::Properties &prop)
Construct registration information when registering to Naming server.
Definition: Manager.cpp:1906
void unbindObject(const char *name)
Unbind the specified objects from NamingService.
void(* ECDeleteFunc)(ExecutionContextBase *ec)
Definition: ECFactory.h:30
OrbRunner * m_runner
The pointer to ORB helper class.
Definition: Manager.h:1959
SDO service consumer base class and its factory.
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
Register RT-Component Factory.
Definition: Manager.cpp:560
void shutdownComponents()
NamingManager finalization.
Definition: Manager.cpp:1610
#define RTC_VERBOSE(fmt)
Verbose level log output macro.
Definition: SystemLogger.h:533
void setProperties(const coil::Properties &prop)
[local interface] Set RTC property
Definition: RTObject.cpp:1501
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
std::vector< RTObject_impl * > getComponents()
Get all RT-Components registered in the Manager.
Definition: Manager.cpp:942
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
Definition: ace/coil/Time.h:51
bool initORB()
CORBA ORB initialization.
Definition: Manager.cpp:1196
void unbindAll()
Unbind all objects from NamingService.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:43