19 #include <coil/Process.h> 33 : m_mgr(::
RTC::Manager::instance())
44 RTC_WARN((
"Manager CORBA servant creation failed."));
49 RTC_WARN((
"Manager CORBA servant was successfully created."));
57 RTM::Manager_var owner;
59 if (CORBA::is_nil(owner))
61 RTC_INFO((
"Master manager not found"));
66 RTC_WARN((
"Manager CORBA servant creation failed."));
70 owner->add_slave_manager(
m_objref.in());
83 for (CORBA::ULong i(0); i <
m_masters.length(); ++i)
87 if (CORBA::is_nil(
m_masters[i])) {
continue; }
89 ->remove_slave_manager(RTM::Manager::_duplicate(
m_objref));
99 for (CORBA::ULong i(0); i <
m_slaves.length(); ++i)
103 if (CORBA::is_nil(
m_slaves[i])) {
continue; }
105 ->remove_master_manager(RTM::Manager::_duplicate(
m_objref));
126 RTC_TRACE((
"ManagerServant::load_module(%s, %s)", pathname, initfunc));
142 RTC_TRACE((
"ManagerServant::unload_module(%s)", pathname));
161 ::RTM::ModuleProfileList_var cprof = new ::RTM::ModuleProfileList();
164 cprof->length((CORBA::Long)prof.size());
165 for (
int i(0), len(prof.size()); i < len; ++i)
176 for (
int i(0), len(
m_slaves.length()); i < len; ++i)
182 ::RTM::ModuleProfileList_var sprof;
183 sprof =
m_slaves[i]->get_loadable_modules();
186 #else // ORB_IS_RTORB 188 #endif // ORB_IS_RTORB 194 RTC_INFO((
"slave (%d) has disappeared.", i));
200 return cprof._retn();
215 ::RTM::ModuleProfileList_var cprof =
new RTM::ModuleProfileList();
218 cprof->length(prof.size());
219 for (
int i(0), len(prof.size()); i < len; ++i)
230 for (
int i(0), len(
m_slaves.length()); i < len; ++i)
236 ::RTM::ModuleProfileList_var sprof;
237 sprof =
m_slaves[i]->get_loaded_modules();
240 #else // ORB_IS_RTORB 242 #endif // ORB_IS_RTORB 248 RTC_INFO((
"slave (%d) has disappeared.", i));
254 return cprof._retn();
269 ::RTM::ModuleProfileList_var cprof =
new RTM::ModuleProfileList();
272 cprof->length(prof.size());
273 for (
int i(0), len(prof.size()); i < len; ++i)
284 for (
int i(0), len(
m_slaves.length()); i < len; ++i)
290 ::RTM::ModuleProfileList_var sprof;
291 sprof =
m_slaves[i]->get_factory_profiles();
294 #else // ORB_IS_RTORB 296 #endif // ORB_IS_RTORB 302 RTC_INFO((
"slave (%d) has disappeared.", i));
308 return cprof._retn();
320 RTC_TRACE((
"create_component(%s)", module_name));
322 std::string arg(module_name);
323 std::string::size_type pos0(arg.find(
"&manager="));
324 std::string::size_type pos1(arg.find(
"?manager="));
326 if (pos0 == std::string::npos && pos1 == std::string::npos)
330 RTC_ERROR((
"Master manager cannot create component: %s",
332 return RTC::RTObject::_nil();
338 return RTC::RTObject::_nil();
340 return RTC::RTObject::_duplicate(rtc->
getObjRef());
345 std::string::size_type pos;
346 pos = (pos0 != std::string::npos) ? pos0 : pos1;
348 std::string::size_type endpos;
349 endpos = arg.find(
'&', pos + 1);
350 std::string mgrstr(arg.substr(pos + 1, endpos - 1 - pos));
353 if (mgrvstr.size() != 2)
355 RTC_WARN((
"Invalid manager name: %s", mgrstr.c_str()));
356 return RTC::RTObject::_nil();
358 std::string::size_type eqpos(mgrstr.find(
"="));
359 if (eqpos == std::string::npos)
361 RTC_WARN((
"Invalid argument: %s", module_name));
362 return RTC::RTObject::_nil();
364 mgrstr.erase(0, eqpos + 1);
365 RTC_DEBUG((
"Manager is %s", mgrstr.c_str()))
368 RTM::Manager_var mgrobj =
findManager(mgrstr.c_str());
369 if (CORBA::is_nil(mgrobj))
371 std::string
cmd(
"rtcd -p ");
374 RTC_DEBUG((
"Invoking command: %s.", cmd.c_str()));
379 return RTC::RTObject::_nil();
385 while (CORBA::is_nil(mgrobj))
389 if (count > 1000) {
break; }
394 if (CORBA::is_nil(mgrobj))
396 RTC_WARN((
"Manager cannot be found."));
397 return RTC::RTObject::_nil();
401 arg.erase(pos + 1, endpos - pos);
402 RTC_DEBUG((
"Creating component on %s", mgrstr.c_str()));
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();
411 catch (CORBA::SystemException& e)
413 RTC_DEBUG((
"Exception was caught while creating component."));
414 return RTC::RTObject::_nil();
416 return RTC::RTObject::_nil();
428 RTC_TRACE((
"delete_component(%s)", instance_name));
449 crtcs->length((CORBA::Long)rtcs.size());
450 for (
int i(0), len(rtcs.size()); i < len; ++i)
452 crtcs[(CORBA::Long)i] = RTC::RTObject::_duplicate(rtcs[i]->
getObjRef());
457 for (
int i(0), len(
m_slaves.length()); i < len; ++i)
463 ::RTC::RTCList_var srtcs;
464 srtcs =
m_slaves[i]->get_components();
467 #else // ORB_IS_RTORB 469 #endif // ORB_IS_RTORB 475 RTC_INFO((
"slave (%d) has disappeared.", i));
480 return crtcs._retn();
495 ::RTC::ComponentProfileList_var cprofs = new ::RTC::ComponentProfileList();
497 cprofs->length(rtcs.size());
498 for (
int i(0), len(rtcs.size()); i < len; ++i)
500 ::RTC::ComponentProfile_var prof = rtcs[i]->get_component_profile();
501 cprofs[(CORBA::Long)i] = prof;
507 for (
int i(0), len(
m_slaves.length()); i < len; ++i)
513 ::RTC::ComponentProfileList_var sprofs;
514 sprofs =
m_slaves[i]->get_component_profiles();
517 #else // ORB_IS_RTORB 519 #endif // ORB_IS_RTORB 525 RTC_INFO((
"slave (%d) has disappeared.", i));
530 return cprofs._retn();
544 RTM::ManagerProfile* prof =
new RTM::ManagerProfile();
565 RTC_NVList nvlist_in;
582 RTC_TRACE((
"set_configuration(name = %s, value = %s)", name, value));
753 return ::CORBA::Object::_nil();
767 CORBA::Object_var obj;
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();
778 PortableServer::ObjectId_var
id;
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 787 poa->activate_object_with_id(
id.in(),
this);
788 CORBA::Object_var mgrobj = poa->id_to_reference(
id);
791 m_objref = ::RTM::Manager::_narrow(mgrobj);
793 CORBA::String_var
ior;
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",
811 RTC_TRACE((
"findManager(host_port = %s)", host_port));
817 std::string mgrloc(
"corbaloc::");
819 mgrloc +=
"/" +
config[
"manager.name"];
821 RTC_DEBUG((
"corbaloc: %s", mgrloc.c_str()));
823 CORBA::Object_var mobj;
824 mobj =
m_mgr.
getORB()->string_to_object(mgrloc.c_str());
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))
831 return RTM::Manager_ptr();
835 mgr = ::RTM::Manager::_narrow(mobj);
837 #endif // ORB_IS_RTORB 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",
847 catch(CORBA::SystemException& e)
850 RTC_DEBUG((
"CORBA SystemException cought (CORBA::%s)", e._name()));
851 #endif // ORB_IS_RTORB 855 RTC_ERROR((
"Unknown exception cought."));
857 return RTM::Manager::_nil();
Functor to inspect if Manster_var is equivalent.
#define RTC_ERROR(fmt)
Error log output macro.
void erase(CorbaSequence &seq, CORBA::ULong index)
Erase the element of the specified index.
RTObject_impl * createComponent(const char *comp_args)
Create RT-Components.
RTM::ManagerList * get_slave_managers()
Getting slave managers.
void deleteComponent(RTObject_impl *comp)
Unregister RT-Components that have been registered to Manager.
std::vector< coil::Properties > getLoadedModules()
Get a list of loaded modules.
bool createINSManager()
Generate INSManager.
int launch_shell(std::string command)
Launching a process.
std::vector< std::pair< std::string, std::string > > NVList
std::vector< coil::Properties > getLoadableModules()
Get a list of loadable modules.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
std::string formatIORinfo(const char *iorstr)
Extracts information from IOR string and returns formatted string.
void terminate()
Terminate manager.
void load(const char *fname, const char *initfunc)
[CORBA interface] Load module
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.
RTM::NVList * get_configuration()
Getting this manager'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.
#define RTC_VERBOSE_STR(str)
RTM::ManagerList * get_master_managers()
Getting master managers.
#define RTC_WARN(fmt)
Warning log output macro.
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
RTC::ReturnCode_t remove_slave_manager(RTM::Manager_ptr mgr)
Removing a slave manager.
std::vector< coil::Properties > getFactoryProfiles()
Get profiles of factories.
RTC::ReturnCode_t set_configuration(const char *name, const char *value)
Setting manager's configuration.
coil::Properties & getConfig()
Get the manager configuration.
::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.
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
::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.
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.
RTObject_ptr getObjRef() const
[local interface] Get the object reference
RTM::Manager_ptr getObjRef() const
Get the reference of Manager.
::RTC::Logger rtclog
Logger object.
CORBA IOR manipulation utility functions.
Class represents a set of properties.
void unload(const char *fname)
Unload module.
bool toBool(std::string str, std::string yes, std::string no, bool default_value)
Convert given string into bool value.
RTM::ManagerProfile * get_profile()
Getting this manager's profile.
::CORBA::Boolean is_master()
Whether this manager is master or not.
#define RTC_INFO(fmt)
Information level log output macro.
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.
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.
::RTM::Manager_var m_objref
An object reference of ManagerServant.
RTC::ComponentProfileList * get_component_profiles()
Getting RT-Component'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.
RTC::ReturnCode_t add_slave_manager(RTM::Manager_ptr mgr)
Getting a slave manager.
RTC::ReturnCode_t fork()
The copy of the process is generated.
std::vector< RTObject_impl * > getComponents()
Get all RT-Components registered in the Manager.
int usleep(useconds_t usec)
Stop a processing at specified micro second time.