ManagerServant.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
19 #include <coil/Process.h>
20 #include <rtm/Manager.h>
21 #include <rtm/ManagerServant.h>
22 #include <rtm/NVUtil.h>
23 #include <rtm/RTObject.h>
24 #include <rtm/CORBA_SeqUtil.h>
25 #include <rtm/CORBA_IORUtil.h>
26 
27 namespace RTM
28 {
29  //
30  // Example implementational code for IDL interface RTM::Manager
31  //
33  : m_mgr(::RTC::Manager::instance())
34  {
35  rtclog.setName("ManagerServant");
37 
38  if (coil::toBool(config["manager.is_master"], "YES", "NO", true))
39  { // this is master manager
40  RTC_TRACE(("This manager is master."));
41 
42  if (!createINSManager())
43  {
44  RTC_WARN(("Manager CORBA servant creation failed."));
45  return;
46 
47  }
48  m_isMaster = true;
49  RTC_WARN(("Manager CORBA servant was successfully created."));
50  return;
51  }
52  else
53  { // manager is slave
54  RTC_TRACE(("This manager is slave."));
55  try
56  {
57  RTM::Manager_var owner;
58  owner = findManager(config["corba.master_manager"].c_str());
59  if (CORBA::is_nil(owner))
60  {
61  RTC_INFO(("Master manager not found"));
62  return;
63  }
64  if (!createINSManager())
65  {
66  RTC_WARN(("Manager CORBA servant creation failed."));
67  return;
68  }
69  add_master_manager(owner);
70  owner->add_slave_manager(m_objref.in());
71  return;
72  }
73  catch (...)
74  {
75  RTC_ERROR(("Unknown exception cought."));
76  }
77  }
78  }
79 
81  {
82  Guard guardm(m_masterMutex);
83  for (CORBA::ULong i(0); i < m_masters.length(); ++i)
84  {
85  try
86  {
87  if (CORBA::is_nil(m_masters[i])) { continue; }
88  m_masters[i]
89  ->remove_slave_manager(RTM::Manager::_duplicate(m_objref));
90  }
91  catch (...)
92  {
93  m_masters[i] = RTM::Manager::_nil();
94  }
95  }
96  m_masters.length(0);
97 
98  Guard guards(m_slaveMutex);
99  for (CORBA::ULong i(0); i < m_slaves.length(); ++i)
100  {
101  try
102  {
103  if (CORBA::is_nil(m_slaves[i])) { continue; }
104  m_slaves[i]
105  ->remove_master_manager(RTM::Manager::_duplicate(m_objref));
106  }
107  catch (...)
108  {
109  m_slaves[i] = RTM::Manager::_nil();
110  }
111  }
112  m_slaves.length(0);
113 
114  }
115 
124  ManagerServant::load_module(const char* pathname, const char* initfunc)
125  {
126  RTC_TRACE(("ManagerServant::load_module(%s, %s)", pathname, initfunc));
127 
128  m_mgr.load(pathname, initfunc);
129 
131  }
132 
141  {
142  RTC_TRACE(("ManagerServant::unload_module(%s)", pathname));
143 
144  m_mgr.unload(pathname);
145 
147  }
148 
156  RTM::ModuleProfileList* ManagerServant::get_loadable_modules()
157  {
158  RTC_TRACE(("get_loadable_modules()"));
159 
160  // copy local module profiles
161  ::RTM::ModuleProfileList_var cprof = new ::RTM::ModuleProfileList();
162  std::vector<coil::Properties> prof(m_mgr.getLoadableModules());
163 
164  cprof->length((CORBA::Long)prof.size());
165  for (int i(0), len(prof.size()); i < len; ++i)
166  {
167  RTC_VERBOSE_STR((prof[i]));
168  NVUtil::copyFromProperties(cprof[(CORBA::Long)i].properties, prof[i]);
169  }
170 
171  if (0)
172  {
173  // copy slaves' module profiles
174  Guard gurad(m_slaveMutex);
175  RTC_DEBUG(("%d slaves exists.", m_slaves.length()));
176  for (int i(0), len(m_slaves.length()); i < len; ++i)
177  {
178  try
179  {
180  if (!CORBA::is_nil(m_slaves[i]))
181  {
182  ::RTM::ModuleProfileList_var sprof;
183  sprof = m_slaves[i]->get_loadable_modules();
184 #ifndef ORB_IS_RTORB
185  CORBA_SeqUtil::push_back_list(cprof.inout(), sprof.in());
186 #else // ORB_IS_RTORB
187  CORBA_SeqUtil::push_back_list(cprof, sprof);
188 #endif // ORB_IS_RTORB
189  continue;
190  }
191  }
192  catch (...)
193  {
194  RTC_INFO(("slave (%d) has disappeared.", i));
195  m_slaves[i] = RTM::Manager::_nil();
196  }
198  }
199  }
200  return cprof._retn();
201  }
202 
210  RTM::ModuleProfileList* ManagerServant::get_loaded_modules()
211  {
212  RTC_TRACE(("get_loaded_modules()"));
213 
214  // copy local module profiles
215  ::RTM::ModuleProfileList_var cprof = new RTM::ModuleProfileList();
216  std::vector<coil::Properties> prof(m_mgr.getLoadedModules());
217 
218  cprof->length(prof.size());
219  for (int i(0), len(prof.size()); i < len; ++i)
220  {
221  RTC_VERBOSE_STR((prof[i]));
222  NVUtil::copyFromProperties(cprof[(CORBA::Long)i].properties, prof[i]);
223  }
224 
225  if (0)
226  {
227  // copy slaves' module profile
228  Guard guard(m_slaveMutex);
229  RTC_DEBUG(("%d slave managers exists.", m_slaves.length()));
230  for (int i(0), len(m_slaves.length()); i < len; ++i)
231  {
232  try
233  {
234  if (!CORBA::is_nil(m_slaves[i]))
235  {
236  ::RTM::ModuleProfileList_var sprof;
237  sprof = m_slaves[i]->get_loaded_modules();
238 #ifndef ORB_IS_RTORB
239  CORBA_SeqUtil::push_back_list(cprof.inout(), sprof.in());
240 #else // ORB_IS_RTORB
241  CORBA_SeqUtil::push_back_list(cprof, sprof);
242 #endif // ORB_IS_RTORB
243  continue;
244  }
245  }
246  catch (...)
247  {
248  RTC_INFO(("slave (%d) has disappeared.", i));
249  m_slaves[i] = RTM::Manager::_nil();
250  }
252  }
253  }
254  return cprof._retn();
255  }
256 
264  RTM::ModuleProfileList* ManagerServant::get_factory_profiles()
265  {
266  RTC_TRACE(("get_factory_profiles()"));
267 
268  // copy local factory profiles
269  ::RTM::ModuleProfileList_var cprof = new RTM::ModuleProfileList();
270  std::vector<coil::Properties> prof(m_mgr.getFactoryProfiles());
271 
272  cprof->length(prof.size());
273  for (int i(0), len(prof.size()); i < len; ++i)
274  {
275  RTC_VERBOSE_STR((prof[i]));
276  NVUtil::copyFromProperties(cprof[(CORBA::Long)i].properties, prof[i]);
277  }
278 
279  if (0)
280  {
281  // copy slaves' factory profile
282  Guard guard(m_slaveMutex);
283  RTC_DEBUG(("%d slave managers exists.", m_slaves.length()));
284  for (int i(0), len(m_slaves.length()); i < len; ++i)
285  {
286  try
287  {
288  if (!CORBA::is_nil(m_slaves[i]))
289  {
290  ::RTM::ModuleProfileList_var sprof;
291  sprof = m_slaves[i]->get_factory_profiles();
292 #ifndef ORB_IS_RTORB
293  CORBA_SeqUtil::push_back_list(cprof.inout(), sprof.in());
294 #else // ORB_IS_RTORB
295  CORBA_SeqUtil::push_back_list(cprof, sprof);
296 #endif // ORB_IS_RTORB
297  continue;
298  }
299  }
300  catch (...)
301  {
302  RTC_INFO(("slave (%d) has disappeared.", i));
303  m_slaves[i] = RTM::Manager::_nil();
304  }
306  }
307  }
308  return cprof._retn();
309  }
310 
318  RTC::RTObject_ptr ManagerServant::create_component(const char* module_name)
319  {
320  RTC_TRACE(("create_component(%s)", module_name));
321 
322  std::string arg(module_name);
323  std::string::size_type pos0(arg.find("&manager="));
324  std::string::size_type pos1(arg.find("?manager="));
325 
326  if (pos0 == std::string::npos && pos1 == std::string::npos)
327  {
328  if (false) //is_master())
329  {
330  RTC_ERROR(("Master manager cannot create component: %s",
331  module_name));
332  return RTC::RTObject::_nil();
333  }
334  // create on this manager
335  RTC::RTObject_impl* rtc = m_mgr.createComponent(module_name);
336  if (rtc == NULL)
337  {
338  return RTC::RTObject::_nil();
339  }
340  return RTC::RTObject::_duplicate(rtc->getObjRef());
341  }
342  // create other manager
343 
344  // extract manager's location
345  std::string::size_type pos;
346  pos = (pos0 != std::string::npos) ? pos0 : pos1;
347 
348  std::string::size_type endpos;
349  endpos = arg.find('&', pos + 1);
350  std::string mgrstr(arg.substr(pos + 1, endpos - 1 - pos));
351  RTC_VERBOSE(("Manager arg: %s", mgrstr.c_str()));
352  coil::vstring mgrvstr(coil::split(mgrstr, ":"));
353  if (mgrvstr.size() != 2)
354  {
355  RTC_WARN(("Invalid manager name: %s", mgrstr.c_str()));
356  return RTC::RTObject::_nil();
357  }
358  std::string::size_type eqpos(mgrstr.find("="));
359  if (eqpos == std::string::npos)
360  {
361  RTC_WARN(("Invalid argument: %s", module_name));
362  return RTC::RTObject::_nil();
363  }
364  mgrstr.erase(0, eqpos + 1);
365  RTC_DEBUG(("Manager is %s", mgrstr.c_str()))
366 
367  // find manager
368  RTM::Manager_var mgrobj = findManager(mgrstr.c_str());
369  if (CORBA::is_nil(mgrobj))
370  {
371  std::string cmd("rtcd -p ");
372  cmd += mgrvstr[1]; // port number
373 
374  RTC_DEBUG(("Invoking command: %s.", cmd.c_str()));
375  int ret(coil::launch_shell(cmd.c_str()));
376  if (ret == -1)
377  {
378  RTC_DEBUG(("%s: failed", cmd.c_str()));
379  return RTC::RTObject::_nil();
380  }
381 
382  // find manager
383  coil::usleep(10000);
384  int count(0);
385  while (CORBA::is_nil(mgrobj))
386  {
387  mgrobj = findManager(mgrstr.c_str());
388  ++count;
389  if (count > 1000) { break; }
390  coil::usleep(10000);
391  }
392  }
393 
394  if (CORBA::is_nil(mgrobj))
395  {
396  RTC_WARN(("Manager cannot be found."));
397  return RTC::RTObject::_nil();
398  }
399 
400  // create component on the manager
401  arg.erase(pos + 1, endpos - pos);
402  RTC_DEBUG(("Creating component on %s", mgrstr.c_str()));
403  RTC_DEBUG(("arg: %s", arg.c_str()));
404  try
405  {
406  RTC::RTObject_var rtobj;
407  rtobj = mgrobj->create_component(arg.c_str());
408  RTC_DEBUG(("Component created %s", arg.c_str()));
409  return rtobj._retn();
410  }
411  catch (CORBA::SystemException& e)
412  {
413  RTC_DEBUG(("Exception was caught while creating component."));
414  return RTC::RTObject::_nil();
415  }
416  return RTC::RTObject::_nil();
417  }
418 
427  {
428  RTC_TRACE(("delete_component(%s)", instance_name));
429 
430  m_mgr.deleteComponent(instance_name);
432  }
433 
442  {
443  RTC_TRACE(("get_components()"));
444 
445  // get local component references
446  std::vector<RTC::RTObject_impl*> rtcs = m_mgr.getComponents();
447  ::RTC::RTCList_var crtcs = new ::RTC::RTCList();
448 
449  crtcs->length((CORBA::Long)rtcs.size());
450  for (int i(0), len(rtcs.size()); i < len; ++i)
451  {
452  crtcs[(CORBA::Long)i] = RTC::RTObject::_duplicate(rtcs[i]->getObjRef());
453  }
454 
455  // get slaves' component references
456  RTC_DEBUG(("%d slave managers exists.", m_slaves.length()));
457  for (int i(0), len(m_slaves.length()); i < len; ++i)
458  {
459  try
460  {
461  if (!CORBA::is_nil(m_slaves[i]))
462  {
463  ::RTC::RTCList_var srtcs;
464  srtcs = m_slaves[i]->get_components();
465 #ifndef ORB_IS_RTORB
466  CORBA_SeqUtil::push_back_list(crtcs.inout(), srtcs.in());
467 #else // ORB_IS_RTORB
468  CORBA_SeqUtil::push_back_list(srtcs, crtcs);
469 #endif // ORB_IS_RTORB
470  continue;
471  }
472  }
473  catch (...)
474  {
475  RTC_INFO(("slave (%d) has disappeared.", i));
476  m_slaves[i] = RTM::Manager::_nil();
477  }
479  }
480  return crtcs._retn();
481  }
482 
490  RTC::ComponentProfileList* ManagerServant::get_component_profiles()
491  {
492  RTC_TRACE(("get_component_profiles()"));
493 
494  // copy local component profiles
495  ::RTC::ComponentProfileList_var cprofs = new ::RTC::ComponentProfileList();
496  std::vector<RTC::RTObject_impl*> rtcs = m_mgr.getComponents();
497  cprofs->length(rtcs.size());
498  for (int i(0), len(rtcs.size()); i < len; ++i)
499  {
500  ::RTC::ComponentProfile_var prof = rtcs[i]->get_component_profile();
501  cprofs[(CORBA::Long)i] = prof;
502  }
503 
504  // copy slaves' component profiles
505  Guard guard(m_slaveMutex);
506  RTC_DEBUG(("%d slave managers exists.", m_slaves.length()));
507  for (int i(0), len(m_slaves.length()); i < len; ++i)
508  {
509  try
510  {
511  if (!CORBA::is_nil(m_slaves[i]))
512  {
513  ::RTC::ComponentProfileList_var sprofs;
514  sprofs = m_slaves[i]->get_component_profiles();
515 #ifndef ORB_IS_RTORB
516  CORBA_SeqUtil::push_back_list(cprofs.inout(), sprofs.in());
517 #else // ORB_IS_RTORB
518  CORBA_SeqUtil::push_back_list(cprofs, sprofs);
519 #endif // ORB_IS_RTORB
520  continue;
521  }
522  }
523  catch (...)
524  {
525  RTC_INFO(("slave (%d) has disappeared.", i));
526  m_slaves[i] = RTM::Manager::_nil();
527  }
529  }
530  return cprofs._retn();
531  }
532 
533  // manager ´ðËÜ /*! * @if jp * @brief ¥Þ¥Í¡¼¥¸¥ã¤Î¥×¥í¥Õ¥¡¥¤¥ë¤ò¼èÆÀ¤¹¤ë * @else * @brief Getting this manager's profile. * @endig */ RTM::ManagerProfile* ManagerServant::get_profile() { RTC_TRACE(("get_profile()")); RTM::ManagerProfile* prof = new RTM::ManagerProfile(); NVUtil::copyFromProperties(prof->properties, m_mgr.getConfig().getNode("manager")); return prof; } /*! * @if jp * @brief ¥Þ¥Í¡¼¥¸¥ã¤Î¥³¥ó¥Õ¥£¥®¥å¥ì¡¼¥·¥ç¥ó¤ò¼èÆÀ¤¹¤ë * @else * @brief Getting this manager's configuration. * @endig */ RTM::NVList* ManagerServant::get_configuration() { RTC_TRACE(("get_configuration()")); #ifndef ORB_IS_RTORB ::RTC::NVList* nvlist = new ::RTC::NVList(); NVUtil::copyFromProperties(*nvlist, m_mgr.getConfig()); #else ::RTC::NVList* nvlist; RTC_NVList nvlist_in; NVUtil::copyFromProperties(nvlist_in, m_mgr.getConfig()); nvlist = new ::RTC::NVList(nvlist_in); #endif return nvlist; } /*! * @if jp * @brief ¥Þ¥Í¡¼¥¸¥ã¤Î¥³¥ó¥Õ¥£¥®¥å¥ì¡¼¥·¥ç¥ó¤òÀßÄꤹ¤ë * @else * @brief Setting manager's configuration * @endig */ RTC::ReturnCode_t ManagerServant::set_configuration(const char* name, const char* value) { RTC_TRACE(("set_configuration(name = %s, value = %s)", name, value)); m_mgr.getConfig().setProperty(name, value); return ::RTC::RTC_OK; } /*! * @if jp * @brief ¥Þ¥Í¡¼¥¸¥ã¤¬¥Þ¥¹¥¿¡¼¤«¤É¤¦¤« * @else * @brief Whether this manager is master or not * @endig */ CORBA::Boolean ManagerServant::is_master() { RTC_TRACE(("is_master(): %s", m_isMaster ? "YES" : "NO")); return m_isMaster; } /*! * @if jp * @brief ¥Þ¥¹¥¿¡¼¥Þ¥Í¡¼¥¸¥ã¤Î¼èÆÀ * @else * @brief Getting master managers * @endig */ RTM::ManagerList* ManagerServant::get_master_managers() { RTC_TRACE(("get_master_managers()")); Guard guard(m_masterMutex); return new ManagerList(m_masters); } /*! * @if jp * @brief ¥Þ¥¹¥¿¡¼¥Þ¥Í¡¼¥¸¥ã¤ÎÄɲà * @else * @brief Getting a master manager * @endig */ RTC::ReturnCode_t ManagerServant::add_master_manager(RTM::Manager_ptr mgr) { Guard guard(m_masterMutex); CORBA::Long index; RTC_TRACE(("add_master_manager(), %d masters", m_masters.length())); index = CORBA_SeqUtil::find(m_masters, is_equiv(mgr)); if (!(index < 0)) // found in my list { RTC_ERROR(("Already exists.")); return RTC::BAD_PARAMETER; } CORBA_SeqUtil::push_back(m_masters, RTM::Manager::_duplicate(mgr)); RTC_TRACE(("add_master_manager() done, %d masters", m_masters.length())); return RTC::RTC_OK; } /*! * @if jp * @brief ¥Þ¥¹¥¿¡¼¥Þ¥Í¡¼¥¸¥ã¤Îºï½ü * @else * @brief Removing a master manager * @endig */ RTC::ReturnCode_t ManagerServant::remove_master_manager(RTM::Manager_ptr mgr) { Guard guard(m_masterMutex); RTC_TRACE(("remove_master_manager(), %d masters", m_masters.length())); CORBA::Long index; index = CORBA_SeqUtil::find(m_masters, is_equiv(mgr)); if (index < 0) // not found in my list { RTC_ERROR(("Not found.")); return RTC::BAD_PARAMETER; } CORBA_SeqUtil::erase(m_masters, index); RTC_TRACE(("remove_master_manager() done, %d masters", m_masters.length())); return RTC::RTC_OK; } /*! * @if jp * @brief ¥¹¥ì¡¼¥Ö¥Þ¥Í¡¼¥¸¥ã¤Î¼èÆÀ * @else * @brief Getting slave managers * @endig */ ManagerList* ManagerServant::get_slave_managers() { Guard guard(m_slaveMutex); RTC_TRACE(("get_slave_managers(), %d slaves", m_slaves.length())); return new ManagerList(m_slaves); } /*! * @if jp * @brief ¥¹¥ì¡¼¥Ö¥Þ¥Í¡¼¥¸¥ã¤ÎÄɲà * @else * @brief Getting a slave manager * @endig */ RTC::ReturnCode_t ManagerServant::add_slave_manager(RTM::Manager_ptr mgr) { Guard guard(m_slaveMutex); RTC_TRACE(("add_slave_manager(), %d slaves", m_slaves.length())); CORBA::Long index; index = CORBA_SeqUtil::find(m_slaves, is_equiv(mgr)); if (!(index < 0)) // found in my list { RTC_ERROR(("Already exists.")); return RTC::BAD_PARAMETER; } CORBA_SeqUtil::push_back(m_slaves, RTM::Manager::_duplicate(mgr)); RTC_TRACE(("add_slave_manager() done, %d slaves", m_slaves.length())); return RTC::RTC_OK;; } /*! * @if jp * @brief ¥¹¥ì¡¼¥Ö¥Þ¥Í¡¼¥¸¥ã¤Îºï½ü * @else * @brief Removing a slave manager * @endig */ RTC::ReturnCode_t ManagerServant::remove_slave_manager(RTM::Manager_ptr mgr) { Guard guard(m_slaveMutex); RTC_TRACE(("remove_slave_manager(), %d slaves", m_slaves.length())); CORBA::Long index; index = CORBA_SeqUtil::find(m_slaves, is_equiv(mgr)); if (index < 0) // not found in my list { RTC_ERROR(("Not found.")); return RTC::BAD_PARAMETER; } CORBA_SeqUtil::erase(m_slaves, index); RTC_TRACE(("remove_slave_manager() done, %d slaves", m_slaves.length())); return RTC::RTC_OK; } RTC::ReturnCode_t ManagerServant::fork() { // m_mgr.fork(); return ::RTC::RTC_OK; } RTC::ReturnCode_t ManagerServant::shutdown() { m_mgr.terminate(); return ::RTC::RTC_OK; } RTC::ReturnCode_t ManagerServant::restart() { // m_mgr.restart(); return ::RTC::RTC_OK; } CORBA::Object_ptr ManagerServant::get_service(const char* name) { return ::CORBA::Object::_nil(); } RTM::Manager_ptr ManagerServant::getObjRef() const { return m_objref; } bool ManagerServant::createINSManager() { try { //Ppreparing INS POA CORBA::Object_var obj; #ifndef ORB_IS_RTORB obj = m_mgr.getORB()->resolve_initial_references("omniINSPOA"); #else // ROB_IS_RTORB obj = m_mgr.getORB()->resolve_initial_references((char*)"omniINSPOA"); #endif // ORB_IS_RTORB PortableServer::POA_ptr poa = PortableServer::POA::_narrow(obj); poa->the_POAManager()->activate(); // Create readable object ID coil::Properties config(m_mgr.getConfig()); PortableServer::ObjectId_var id; #ifndef ORB_IS_RTORB id = PortableServer::string_to_ObjectId(config["manager.name"].c_str()); #else // ORB_IS_RTORB id = PortableServer:: string_to_ObjectId((char *)config["manager.name"].c_str()); #endif // ORB_IS_RTORB // Object activation poa->activate_object_with_id(id.in(), this); CORBA::Object_var mgrobj = poa->id_to_reference(id); // Set m_objref m_objref = ::RTM::Manager::_narrow(mgrobj); CORBA::String_var ior; ior = m_mgr.getORB()-> object_to_string(RTM::Manager::_duplicate(m_objref)); std::string iorstr((const char*)ior); RTC_DEBUG(("Manager's IOR information:\n %s", CORBA_IORUtil::formatIORinfo(iorstr.c_str()).c_str())); } catch (...) { return false; } return true; } RTM::Manager_ptr ManagerServant::findManager(const char* host_port) { RTC_TRACE(("findManager(host_port = %s)", host_port)); try { coil::Properties config(m_mgr.getConfig()); // Why RtORB does not allow corbaloc:iiop: ? // std::string mgrloc("corbaloc:iiop:"); std::string mgrloc("corbaloc::"); mgrloc += host_port; mgrloc += "/" + config["manager.name"]; RTC_DEBUG(("corbaloc: %s", mgrloc.c_str())); CORBA::Object_var mobj; mobj = m_mgr.getORB()->string_to_object(mgrloc.c_str()); #ifndef ORB_IS_RTORB RTM::Manager_var mgr = ::RTM::Manager::_narrow(mobj); #else // ORB_IS_RTORB RTM::Manager_var mgr; if(!make_client_connection(mobj->impl()->connection)) { return RTM::Manager_ptr(); } else { mgr = ::RTM::Manager::_narrow(mobj); } #endif // ORB_IS_RTORB CORBA::String_var ior; ior = m_mgr.getORB()->object_to_string(RTM::Manager::_duplicate(mgr)); std::string iorstr((const char*)ior); RTC_DEBUG(("Manager's IOR information:\n %s", CORBA_IORUtil::formatIORinfo(iorstr.c_str()).c_str())); return mgr._retn(); } catch(CORBA::SystemException& e) { #ifndef ORB_IS_RTORB RTC_DEBUG(("CORBA SystemException cought (CORBA::%s)", e._name())); #endif // ORB_IS_RTORB } catch (...) { RTC_ERROR(("Unknown exception cought.")); } return RTM::Manager::_nil(); } };
541  RTM::ManagerProfile* ManagerServant::get_profile()
542  {
543  RTC_TRACE(("get_profile()"));
544  RTM::ManagerProfile* prof = new RTM::ManagerProfile();
545  NVUtil::copyFromProperties(prof->properties,
546  m_mgr.getConfig().getNode("manager"));
547  return prof;
548  }
549 
558  {
559  RTC_TRACE(("get_configuration()"));
560 #ifndef ORB_IS_RTORB
561  ::RTC::NVList* nvlist = new ::RTC::NVList();
563 #else
564  ::RTC::NVList* nvlist;
565  RTC_NVList nvlist_in;
567  nvlist = new ::RTC::NVList(nvlist_in);
568 #endif
569  return nvlist;
570  }
571 
580  ManagerServant::set_configuration(const char* name, const char* value)
581  {
582  RTC_TRACE(("set_configuration(name = %s, value = %s)", name, value));
583  m_mgr.getConfig().setProperty(name, value);
585  }
593  CORBA::Boolean ManagerServant::is_master()
594  {
595  RTC_TRACE(("is_master(): %s", m_isMaster ? "YES" : "NO"));
596  return m_isMaster;
597  }
598 
607  {
608  RTC_TRACE(("get_master_managers()"));
609  Guard guard(m_masterMutex);
610  return new ManagerList(m_masters);
611  }
612 
621  {
622  Guard guard(m_masterMutex);
623  CORBA::Long index;
624  RTC_TRACE(("add_master_manager(), %d masters", m_masters.length()));
625  index = CORBA_SeqUtil::find(m_masters, is_equiv(mgr));
626 
627  if (!(index < 0)) // found in my list
628  {
629  RTC_ERROR(("Already exists."));
630  return RTC::BAD_PARAMETER;
631  }
632 
633  CORBA_SeqUtil::push_back(m_masters, RTM::Manager::_duplicate(mgr));
634  RTC_TRACE(("add_master_manager() done, %d masters", m_masters.length()));
635  return RTC::RTC_OK;
636  }
637 
647  {
648  Guard guard(m_masterMutex);
649  RTC_TRACE(("remove_master_manager(), %d masters", m_masters.length()));
650 
651  CORBA::Long index;
652  index = CORBA_SeqUtil::find(m_masters, is_equiv(mgr));
653 
654  if (index < 0) // not found in my list
655  {
656  RTC_ERROR(("Not found."));
657  return RTC::BAD_PARAMETER;
658  }
659 
661  RTC_TRACE(("remove_master_manager() done, %d masters", m_masters.length()));
662  return RTC::RTC_OK;
663  }
664 
673  {
674  Guard guard(m_slaveMutex);
675  RTC_TRACE(("get_slave_managers(), %d slaves", m_slaves.length()));
676 
677  return new ManagerList(m_slaves);
678  }
679 
688  {
689  Guard guard(m_slaveMutex);
690  RTC_TRACE(("add_slave_manager(), %d slaves", m_slaves.length()));
691 
692  CORBA::Long index;
693  index = CORBA_SeqUtil::find(m_slaves, is_equiv(mgr));
694 
695  if (!(index < 0)) // found in my list
696  {
697  RTC_ERROR(("Already exists."));
698  return RTC::BAD_PARAMETER;
699  }
700 
701  CORBA_SeqUtil::push_back(m_slaves, RTM::Manager::_duplicate(mgr));
702  RTC_TRACE(("add_slave_manager() done, %d slaves", m_slaves.length()));
703  return RTC::RTC_OK;;
704  }
705 
714  {
715  Guard guard(m_slaveMutex);
716  RTC_TRACE(("remove_slave_manager(), %d slaves", m_slaves.length()));
717  CORBA::Long index;
718  index = CORBA_SeqUtil::find(m_slaves, is_equiv(mgr));
719 
720  if (index < 0) // not found in my list
721  {
722  RTC_ERROR(("Not found."));
723  return RTC::BAD_PARAMETER;
724  }
725 
727  RTC_TRACE(("remove_slave_manager() done, %d slaves", m_slaves.length()));
728  return RTC::RTC_OK;
729  }
730 
731 
732 
734  {
735  // m_mgr.fork();
737  }
738 
740  {
741  m_mgr.terminate();
743  }
744 
746  {
747  // m_mgr.restart();
749  }
750 
751  CORBA::Object_ptr ManagerServant::get_service(const char* name)
752  {
753  return ::CORBA::Object::_nil();
754  }
755 
756  RTM::Manager_ptr ManagerServant::getObjRef() const
757  {
758  return m_objref;
759  }
760 
761 
763  {
764  try
765  {
766  //Ppreparing INS POA
767  CORBA::Object_var obj;
768 #ifndef ORB_IS_RTORB
769  obj = m_mgr.getORB()->resolve_initial_references("omniINSPOA");
770 #else // ROB_IS_RTORB
771  obj = m_mgr.getORB()->resolve_initial_references((char*)"omniINSPOA");
772 #endif // ORB_IS_RTORB
773  PortableServer::POA_ptr poa = PortableServer::POA::_narrow(obj);
774  poa->the_POAManager()->activate();
775 
776  // Create readable object ID
778  PortableServer::ObjectId_var id;
779 #ifndef ORB_IS_RTORB
780  id = PortableServer::string_to_ObjectId(config["manager.name"].c_str());
781 #else // ORB_IS_RTORB
782  id = PortableServer::
783  string_to_ObjectId((char *)config["manager.name"].c_str());
784 #endif // ORB_IS_RTORB
785 
786  // Object activation
787  poa->activate_object_with_id(id.in(), this);
788  CORBA::Object_var mgrobj = poa->id_to_reference(id);
789 
790  // Set m_objref
791  m_objref = ::RTM::Manager::_narrow(mgrobj);
792 
793  CORBA::String_var ior;
794  ior = m_mgr.getORB()->
795  object_to_string(RTM::Manager::_duplicate(m_objref));
796  std::string iorstr((const char*)ior);
797  RTC_DEBUG(("Manager's IOR information:\n %s",
798  CORBA_IORUtil::formatIORinfo(iorstr.c_str()).c_str()));
799  }
800  catch (...)
801  {
802  return false;
803  }
804  return true;
805  }
806 
807 
808 
809  RTM::Manager_ptr ManagerServant::findManager(const char* host_port)
810  {
811  RTC_TRACE(("findManager(host_port = %s)", host_port));
812  try
813  {
815  // Why RtORB does not allow corbaloc:iiop: ?
816  // std::string mgrloc("corbaloc:iiop:");
817  std::string mgrloc("corbaloc::");
818  mgrloc += host_port;
819  mgrloc += "/" + config["manager.name"];
820 
821  RTC_DEBUG(("corbaloc: %s", mgrloc.c_str()));
822 
823  CORBA::Object_var mobj;
824  mobj = m_mgr.getORB()->string_to_object(mgrloc.c_str());
825 #ifndef ORB_IS_RTORB
826  RTM::Manager_var mgr = ::RTM::Manager::_narrow(mobj);
827 #else // ORB_IS_RTORB
828  RTM::Manager_var mgr;
829  if(!make_client_connection(mobj->impl()->connection))
830  {
831  return RTM::Manager_ptr();
832  }
833  else
834  {
835  mgr = ::RTM::Manager::_narrow(mobj);
836  }
837 #endif // ORB_IS_RTORB
838 
839  CORBA::String_var ior;
840  ior = m_mgr.getORB()->object_to_string(RTM::Manager::_duplicate(mgr));
841  std::string iorstr((const char*)ior);
842  RTC_DEBUG(("Manager's IOR information:\n %s",
843  CORBA_IORUtil::formatIORinfo(iorstr.c_str()).c_str()));
844 
845  return mgr._retn();
846  }
847  catch(CORBA::SystemException& e)
848  {
849 #ifndef ORB_IS_RTORB
850  RTC_DEBUG(("CORBA SystemException cought (CORBA::%s)", e._name()));
851 #endif // ORB_IS_RTORB
852  }
853  catch (...)
854  {
855  RTC_ERROR(("Unknown exception cought."));
856  }
857  return RTM::Manager::_nil();
858  }
859 
860 
861 
862 };
Functor to inspect if Manster_var is equivalent.
#define RTC_ERROR(fmt)
Error log output macro.
Definition: SystemLogger.h:422
void erase(CorbaSequence &seq, CORBA::ULong index)
Erase the element of the specified index.
RTObject_impl * createComponent(const char *comp_args)
Create RT-Components.
Definition: Manager.cpp:520
RTM::ManagerList * get_slave_managers()
Getting slave managers.
RT-Component.
void deleteComponent(RTObject_impl *comp)
Unregister RT-Components that have been registered to Manager.
Definition: Manager.cpp:748
std::vector< coil::Properties > getLoadedModules()
Get a list of loaded modules.
Definition: Manager.cpp:404
bool createINSManager()
Generate INSManager.
int launch_shell(std::string command)
Launching a process.
ReturnCode_t
Definition: doil.h:53
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
std::vector< coil::Properties > getLoadableModules()
Get a list of loadable modules.
Definition: Manager.cpp:417
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
RT-Component class.
Definition: RTObject.h:89
std::string formatIORinfo(const char *iorstr)
Extracts information from IOR string and returns formatted string.
void terminate()
Terminate manager.
Definition: Manager.cpp:169
void load(const char *fname, const char *initfunc)
[CORBA interface] Load module
Definition: Manager.cpp:346
CORBA::Object_ptr get_service(const char *name)
Get the reference of RTC.
RTC::ReturnCode_t shutdown()
This method shutdowns RTC.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:341
RTM::NVList * get_configuration()
Getting this manager&#39;s configuration.
::RTM::ManagerList m_slaves
List of slave managers.
RTC::RTObject_ptr create_component(const char *module_name)
Creating an RT-Component.
void setName(const char *name)
Set suffix of date/time string of header.
CORBA::ORB_ptr getORB()
Get the pointer to ORB.
Definition: Manager.cpp:832
#define RTC_VERBOSE_STR(str)
Definition: SystemLogger.h:534
RTM::ManagerList * get_master_managers()
Getting master managers.
#define RTC_WARN(fmt)
Warning log output macro.
Definition: SystemLogger.h:444
RTComponent manager class.
RTM::Manager_ptr findManager(const char *host_port)
Find the reference of Manager.
virtual ~ManagerServant(void)
Virtual destructor.
std::vector< std::string > vstring
Definition: stringutil.h:37
RTC::ReturnCode_t remove_slave_manager(RTM::Manager_ptr mgr)
Removing a slave manager.
std::vector< coil::Properties > getFactoryProfiles()
Get profiles of factories.
Definition: Manager.cpp:456
RTC::ReturnCode_t set_configuration(const char *name, const char *value)
Setting manager&#39;s configuration.
coil::Properties & getConfig()
Get the manager configuration.
Definition: Manager.h:305
list cmd
Definition: omniwxs.py:88
::coil::Mutex m_masterMutex
Mutex of m_masters.
RTC::ReturnCode_t delete_component(const char *instance_name)
Deleting an RT-Component.
::RTC::Manager & m_mgr
Reference to the RTC::Manager.
RTC::ReturnCode_t load_module(const char *pathname, const char *initfunc)
Loading a module.
RTC::ReturnCode_t remove_master_manager(RTM::Manager_ptr mgr)
Removing a master manager.
#define RTC_DEBUG(fmt)
Debug level log output macro.
Definition: SystemLogger.h:488
#define RTC_TRACE(fmt)
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
list index
Definition: rtimages.py:10
::RTM::ManagerList m_masters
List of master managers.
RTComponent manager servant implementation class.
std::string setProperty(const std::string &key, const std::string &value)
Set a value associated with key in the property list.
Definition: Properties.cpp:236
NameValue and NVList utility functions.
RTC::ReturnCode_t restart()
This method restarts RTC.
CORBA sequence utility template functions.
RTM::ModuleProfileList * get_loaded_modules()
Getting loaded module profiles.
RTC::ReturnCode_t unload_module(const char *pathname)
Unloading a module.
RTC::ReturnCode_t add_master_manager(RTM::Manager_ptr mgr)
Getting a master manager.
::RTC::Logger rtclog
Logger object.
CORBA IOR manipulation utility functions.
Class represents a set of properties.
Definition: Properties.h:101
void unload(const char *fname)
Unload module.
Definition: Manager.cpp:376
bool toBool(std::string str, std::string yes, std::string no, bool default_value)
Convert given string into bool value.
Definition: stringutil.cpp:410
RTM::ManagerProfile * get_profile()
Getting this manager&#39;s profile.
::CORBA::Boolean is_master()
Whether this manager is master or not.
#define RTC_INFO(fmt)
Information level log output macro.
Definition: SystemLogger.h:466
RTM::Manager_ptr getObjRef() const
Get the reference of Manager.
void push_back_list(CorbaSequence &seq1, const CorbaSequence &seq2)
Merge the elements of the CORBA sequence.
RTM::ModuleProfileList * get_factory_profiles()
Getting component factory profiles.
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
CORBA::Boolean m_isMaster
Flag if this is master.
void copyFromProperties(SDOPackage::NVList &nv, const coil::Properties &prop)
Copy the properties to NVList.
Definition: NVUtil.cpp:108
RTC::RTCList * get_components()
Getting RT-Component list running on this manager.
std::vector< IRTObject * > RTCList
Properties & getNode(const std::string &key)
Get node of properties.
Definition: Properties.cpp:455
::RTM::Manager_var m_objref
An object reference of ManagerServant.
RTC::ComponentProfileList * get_component_profiles()
Getting RT-Component&#39;s profile list running on this manager.
ManagerServant()
Constructor.
::coil::Mutex m_slaveMutex
Mutex of m_slaves.
RTM::ModuleProfileList * get_loadable_modules()
Getting loadable module profiles.
#define RTC_VERBOSE(fmt)
Verbose level log output macro.
Definition: SystemLogger.h:533
RTC::ReturnCode_t add_slave_manager(RTM::Manager_ptr mgr)
Getting a slave manager.
RT-Middleware.
Definition: Manager.h:38
RTC::ReturnCode_t fork()
The copy of the process is generated.
RTObject_ptr getObjRef() const
[local interface] Get the object reference
Definition: RTObject.cpp:1483
std::vector< RTObject_impl * > getComponents()
Get all RT-Components registered in the Manager.
Definition: Manager.cpp:816
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
Definition: ace/coil/Time.h:51


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