ManagerServant.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00019 #include <coil/Process.h>
00020 #include <rtm/Manager.h>
00021 #include <rtm/ManagerServant.h>
00022 #include <rtm/NVUtil.h>
00023 #include <rtm/RTObject.h>
00024 #include <rtm/CORBA_SeqUtil.h>
00025 #include <rtm/CORBA_IORUtil.h>
00026 
00027 namespace RTM
00028 {
00029   //
00030   // Example implementational code for IDL interface RTM::Manager
00031   //
00032   ManagerServant::ManagerServant()
00033     : m_mgr(::RTC::Manager::instance())
00034   {
00035     rtclog.setName("ManagerServant");
00036     coil::Properties config(m_mgr.getConfig());    
00037     
00038     if (coil::toBool(config["manager.is_master"], "YES", "NO", true))
00039       { // this is master manager
00040         RTC_TRACE(("This manager is master."));
00041 
00042         if (!createINSManager())
00043           {
00044             RTC_WARN(("Manager CORBA servant creation failed."));
00045             return;
00046             
00047           }
00048         m_isMaster = true;
00049         RTC_WARN(("Manager CORBA servant was successfully created."));
00050         return;
00051       }
00052     else
00053       { // manager is slave
00054         RTC_TRACE(("This manager is slave."));
00055         try
00056           {
00057             RTM::Manager_var owner;
00058             owner = findManager(config["corba.master_manager"].c_str());
00059             if (CORBA::is_nil(owner))
00060               {
00061                 RTC_INFO(("Master manager not found"));
00062                 return;
00063               }
00064             if (!createINSManager())
00065               {
00066                 RTC_WARN(("Manager CORBA servant creation failed."));
00067                 return;
00068               }
00069             add_master_manager(owner);
00070             owner->add_slave_manager(m_objref.in());
00071             return;
00072           }
00073         catch (...)
00074           {
00075             RTC_ERROR(("Unknown exception cought."));
00076           }
00077       }
00078   }
00079   
00080   ManagerServant::~ManagerServant()
00081   {
00082     Guard guardm(m_masterMutex);
00083     for (CORBA::ULong i(0); i < m_masters.length(); ++i)
00084       {
00085         try
00086           {
00087             if (CORBA::is_nil(m_masters[i])) { continue; }
00088             m_masters[i]
00089               ->remove_slave_manager(RTM::Manager::_duplicate(m_objref));
00090           }
00091         catch (...)
00092           {
00093             m_masters[i] = RTM::Manager::_nil();
00094           }
00095       }
00096     m_masters.length(0);
00097 
00098     Guard guards(m_slaveMutex);
00099     for (CORBA::ULong i(0); i < m_slaves.length(); ++i)
00100       {
00101         try
00102           {
00103             if (CORBA::is_nil(m_slaves[i])) { continue; }
00104             m_slaves[i]
00105               ->remove_master_manager(RTM::Manager::_duplicate(m_objref));
00106           }
00107         catch (...)
00108           {
00109             m_slaves[i] = RTM::Manager::_nil();
00110           }
00111       }
00112     m_slaves.length(0);
00113 
00114   }
00115   
00123   RTC::ReturnCode_t
00124   ManagerServant::load_module(const char* pathname, const char* initfunc)
00125   {
00126     RTC_TRACE(("ManagerServant::load_module(%s, %s)", pathname, initfunc));
00127 
00128     m_mgr.load(pathname, initfunc);
00129     
00130     return ::RTC::RTC_OK;
00131   }
00132   
00140   RTC::ReturnCode_t ManagerServant::unload_module(const char* pathname)
00141   {
00142     RTC_TRACE(("ManagerServant::unload_module(%s)", pathname));
00143     
00144     m_mgr.unload(pathname);
00145     
00146     return ::RTC::RTC_OK;
00147   }
00148   
00156   RTM::ModuleProfileList* ManagerServant::get_loadable_modules()
00157   {
00158     RTC_TRACE(("get_loadable_modules()"));
00159     
00160     // copy local module profiles
00161     ::RTM::ModuleProfileList_var cprof = new ::RTM::ModuleProfileList();
00162     std::vector<coil::Properties> prof(m_mgr.getLoadableModules());
00163 
00164     cprof->length((CORBA::Long)prof.size());
00165     for (int i(0), len(prof.size()); i < len; ++i)
00166       {
00167         RTC_VERBOSE_STR((prof[i]));
00168         NVUtil::copyFromProperties(cprof[(CORBA::Long)i].properties, prof[i]);
00169       }
00170 
00171     if (0)
00172       {
00173         // copy slaves' module profiles
00174         Guard gurad(m_slaveMutex);
00175         RTC_DEBUG(("%d slaves exists.", m_slaves.length()));
00176         for (int i(0), len(m_slaves.length()); i < len; ++i)
00177           {
00178             try
00179               {
00180                 if (!CORBA::is_nil(m_slaves[i]))
00181                   {
00182                     ::RTM::ModuleProfileList_var sprof;
00183                     sprof = m_slaves[i]->get_loadable_modules();
00184 #ifndef ORB_IS_RTORB
00185                     CORBA_SeqUtil::push_back_list(cprof.inout(), sprof.in());
00186 #else // ORB_IS_RTORB
00187                     CORBA_SeqUtil::push_back_list(cprof, sprof);
00188 #endif // ORB_IS_RTORB
00189                     continue; 
00190                   }
00191               }
00192             catch (...)
00193               {
00194             RTC_INFO(("slave (%d) has disappeared.", i));
00195             m_slaves[i] = RTM::Manager::_nil();
00196               }
00197             CORBA_SeqUtil::erase(m_slaves, i); --i;
00198           }
00199       }
00200     return cprof._retn();
00201   }
00202   
00210   RTM::ModuleProfileList* ManagerServant::get_loaded_modules()
00211   {
00212     RTC_TRACE(("get_loaded_modules()"));
00213     
00214     // copy local module profiles
00215     ::RTM::ModuleProfileList_var cprof = new RTM::ModuleProfileList();
00216     std::vector<coil::Properties> prof(m_mgr.getLoadedModules());
00217     
00218     cprof->length(prof.size());
00219     for (int i(0), len(prof.size()); i < len; ++i)
00220       {
00221         RTC_VERBOSE_STR((prof[i]));
00222         NVUtil::copyFromProperties(cprof[(CORBA::Long)i].properties, prof[i]);
00223       }
00224 
00225     if (0)
00226       {
00227         // copy slaves' module profile
00228         Guard guard(m_slaveMutex);
00229         RTC_DEBUG(("%d slave managers exists.", m_slaves.length()));
00230         for (int i(0), len(m_slaves.length()); i < len; ++i)
00231           {
00232             try
00233               {
00234                 if (!CORBA::is_nil(m_slaves[i]))
00235                   {
00236                     ::RTM::ModuleProfileList_var sprof;
00237                     sprof = m_slaves[i]->get_loaded_modules();
00238 #ifndef ORB_IS_RTORB
00239                     CORBA_SeqUtil::push_back_list(cprof.inout(), sprof.in());
00240 #else // ORB_IS_RTORB
00241                     CORBA_SeqUtil::push_back_list(cprof, sprof);
00242 #endif // ORB_IS_RTORB
00243                     continue;
00244                   }
00245               }
00246             catch (...)
00247               {
00248                 RTC_INFO(("slave (%d) has disappeared.", i));
00249                 m_slaves[i] = RTM::Manager::_nil();
00250               }
00251             CORBA_SeqUtil::erase(m_slaves, i); --i;
00252           }
00253       }
00254     return cprof._retn();
00255   }
00256   
00264   RTM::ModuleProfileList* ManagerServant::get_factory_profiles()
00265   {
00266     RTC_TRACE(("get_factory_profiles()"));
00267 
00268     // copy local factory profiles
00269     ::RTM::ModuleProfileList_var cprof = new RTM::ModuleProfileList();
00270     std::vector<coil::Properties> prof(m_mgr.getFactoryProfiles());
00271     
00272     cprof->length(prof.size());
00273     for (int i(0), len(prof.size()); i < len; ++i)
00274       {
00275         RTC_VERBOSE_STR((prof[i]));
00276         NVUtil::copyFromProperties(cprof[(CORBA::Long)i].properties, prof[i]);
00277       }
00278 
00279     if (0)
00280       {
00281         // copy slaves' factory profile
00282         Guard guard(m_slaveMutex);
00283         RTC_DEBUG(("%d slave managers exists.", m_slaves.length()));
00284         for (int i(0), len(m_slaves.length()); i < len; ++i)
00285           {
00286             try
00287               {
00288                 if (!CORBA::is_nil(m_slaves[i]))
00289                   {
00290                     ::RTM::ModuleProfileList_var sprof;
00291                     sprof = m_slaves[i]->get_factory_profiles();
00292 #ifndef ORB_IS_RTORB
00293                     CORBA_SeqUtil::push_back_list(cprof.inout(), sprof.in());
00294 #else // ORB_IS_RTORB
00295                     CORBA_SeqUtil::push_back_list(cprof, sprof);
00296 #endif // ORB_IS_RTORB
00297                     continue;
00298                   }
00299               }
00300             catch (...)
00301               {
00302                 RTC_INFO(("slave (%d) has disappeared.", i));
00303                 m_slaves[i] = RTM::Manager::_nil();
00304               }
00305             CORBA_SeqUtil::erase(m_slaves, i); --i;
00306           }
00307       }
00308     return cprof._retn();
00309   }
00310   
00318   RTC::RTObject_ptr ManagerServant::create_component(const char* module_name)
00319   {
00320     RTC_TRACE(("create_component(%s)", module_name));
00321     
00322     std::string arg(module_name);
00323     std::string::size_type pos0(arg.find("&manager="));
00324     std::string::size_type pos1(arg.find("?manager="));
00325 
00326     if (pos0 == std::string::npos && pos1 == std::string::npos)
00327       {
00328         if (false) //is_master())
00329           {
00330             RTC_ERROR(("Master manager cannot create component: %s",
00331                        module_name));
00332             return RTC::RTObject::_nil();
00333           }
00334         // create on this manager
00335         RTC::RTObject_impl* rtc = m_mgr.createComponent(module_name);
00336         if (rtc == NULL)
00337           {
00338             return RTC::RTObject::_nil();
00339           }
00340         return RTC::RTObject::_duplicate(rtc->getObjRef());
00341       }
00342     // create other manager
00343 
00344     // extract manager's location
00345     std::string::size_type pos;
00346     pos = (pos0 != std::string::npos) ? pos0 : pos1;
00347     
00348     std::string::size_type endpos;
00349     endpos = arg.find('&', pos + 1);
00350     std::string mgrstr(arg.substr(pos + 1, endpos - 1 - pos));
00351     RTC_VERBOSE(("Manager arg: %s", mgrstr.c_str()));
00352     coil::vstring mgrvstr(coil::split(mgrstr, ":"));
00353     if (mgrvstr.size() != 2)
00354       {
00355         RTC_WARN(("Invalid manager name: %s", mgrstr.c_str()));
00356         return RTC::RTObject::_nil();
00357       }
00358     std::string::size_type eqpos(mgrstr.find("="));
00359     if (eqpos == std::string::npos)
00360       {
00361         RTC_WARN(("Invalid argument: %s", module_name));
00362         return RTC::RTObject::_nil();
00363       }
00364     mgrstr.erase(0, eqpos + 1);
00365     RTC_DEBUG(("Manager is %s", mgrstr.c_str()))
00366 
00367     // find manager
00368     RTM::Manager_var mgrobj = findManager(mgrstr.c_str());
00369     if (CORBA::is_nil(mgrobj))
00370       {
00371         std::string cmd("rtcd -p ");
00372         cmd += mgrvstr[1]; // port number
00373 
00374         RTC_DEBUG(("Invoking command: %s.", cmd.c_str()));
00375         int ret(coil::launch_shell(cmd.c_str()));
00376         if (ret == -1)
00377           {
00378             RTC_DEBUG(("%s: failed", cmd.c_str()));
00379             return RTC::RTObject::_nil();
00380           }
00381 
00382         // find manager
00383         coil::usleep(10000);
00384         int count(0);
00385         while (CORBA::is_nil(mgrobj))
00386           {
00387             mgrobj = findManager(mgrstr.c_str());
00388             ++count;
00389             if (count > 1000) { break; }
00390             coil::usleep(10000);
00391           }
00392       }
00393 
00394     if (CORBA::is_nil(mgrobj))
00395       {
00396         RTC_WARN(("Manager cannot be found."));
00397         return RTC::RTObject::_nil();
00398       }
00399     
00400     // create component on the manager    
00401     arg.erase(pos + 1, endpos - pos);
00402     RTC_DEBUG(("Creating component on %s",  mgrstr.c_str()));
00403     RTC_DEBUG(("arg: %s", arg.c_str()));
00404     try
00405       {
00406         RTC::RTObject_var rtobj;
00407         rtobj = mgrobj->create_component(arg.c_str());
00408         RTC_DEBUG(("Component created %s",  arg.c_str()));
00409         return rtobj._retn();
00410       }
00411     catch (CORBA::SystemException& e)
00412       {
00413         RTC_DEBUG(("Exception was caught while creating component."));
00414         return RTC::RTObject::_nil();
00415       }
00416     return RTC::RTObject::_nil();
00417   }
00418   
00426   RTC::ReturnCode_t ManagerServant::delete_component(const char* instance_name)
00427   {
00428     RTC_TRACE(("delete_component(%s)", instance_name));
00429     
00430     m_mgr.deleteComponent(instance_name);
00431     return ::RTC::RTC_OK;
00432   }
00433   
00441   RTC::RTCList* ManagerServant::get_components()
00442   {
00443     RTC_TRACE(("get_components()"));
00444 
00445     // get local component references
00446     std::vector<RTC::RTObject_impl*> rtcs = m_mgr.getComponents();
00447     ::RTC::RTCList_var crtcs = new ::RTC::RTCList();
00448 
00449     crtcs->length((CORBA::Long)rtcs.size());
00450     for (int i(0), len(rtcs.size()); i < len; ++i)
00451       {
00452         crtcs[(CORBA::Long)i] = RTC::RTObject::_duplicate(rtcs[i]->getObjRef());
00453       }
00454 
00455     // get slaves' component references
00456     RTC_DEBUG(("%d slave managers exists.", m_slaves.length()));
00457     for (int i(0), len(m_slaves.length()); i < len; ++i)
00458       {
00459         try
00460           {
00461             if (!CORBA::is_nil(m_slaves[i]))
00462               {
00463                 ::RTC::RTCList_var srtcs;
00464                 srtcs = m_slaves[i]->get_components();
00465 #ifndef ORB_IS_RTORB
00466                 CORBA_SeqUtil::push_back_list(crtcs.inout(), srtcs.in());
00467 #else // ORB_IS_RTORB
00468                 CORBA_SeqUtil::push_back_list(srtcs, crtcs);
00469 #endif // ORB_IS_RTORB
00470                 continue;
00471               }
00472           }
00473         catch (...)
00474           {
00475             RTC_INFO(("slave (%d) has disappeared.", i));
00476             m_slaves[i] = RTM::Manager::_nil();
00477           }
00478         CORBA_SeqUtil::erase(m_slaves, i); --i;
00479       }
00480     return crtcs._retn();
00481   }
00482   
00490   RTC::ComponentProfileList* ManagerServant::get_component_profiles()
00491   {
00492     RTC_TRACE(("get_component_profiles()"));
00493 
00494     // copy local component profiles
00495     ::RTC::ComponentProfileList_var cprofs = new ::RTC::ComponentProfileList();
00496     std::vector<RTC::RTObject_impl*> rtcs = m_mgr.getComponents();
00497     cprofs->length(rtcs.size());
00498     for (int i(0), len(rtcs.size()); i < len; ++i)
00499       {
00500         ::RTC::ComponentProfile_var prof = rtcs[i]->get_component_profile();
00501         cprofs[(CORBA::Long)i] = prof;
00502       }
00503 
00504     // copy slaves' component profiles
00505     Guard guard(m_slaveMutex);
00506     RTC_DEBUG(("%d slave managers exists.", m_slaves.length()));
00507     for (int i(0), len(m_slaves.length()); i < len; ++i)
00508       {
00509         try
00510           {
00511             if (!CORBA::is_nil(m_slaves[i]))
00512               {
00513                 ::RTC::ComponentProfileList_var sprofs;
00514                 sprofs = m_slaves[i]->get_component_profiles();
00515 #ifndef ORB_IS_RTORB
00516                 CORBA_SeqUtil::push_back_list(cprofs.inout(), sprofs.in());
00517 #else // ORB_IS_RTORB
00518                 CORBA_SeqUtil::push_back_list(cprofs, sprofs);
00519 #endif // ORB_IS_RTORB
00520                 continue;
00521               }
00522           }
00523         catch (...)
00524           {
00525             RTC_INFO(("slave (%d) has disappeared.", i));
00526             m_slaves[i] = RTM::Manager::_nil();
00527           }
00528         CORBA_SeqUtil::erase(m_slaves, i); --i;
00529       }
00530     return cprofs._retn();
00531   }
00532   
00533   // manager ΄πΛά
00541   RTM::ManagerProfile* ManagerServant::get_profile()
00542   {
00543     RTC_TRACE(("get_profile()"));
00544     RTM::ManagerProfile* prof = new RTM::ManagerProfile();
00545     NVUtil::copyFromProperties(prof->properties,
00546                                m_mgr.getConfig().getNode("manager"));
00547     return prof;
00548   }
00549   
00557   RTM::NVList* ManagerServant::get_configuration()
00558   {
00559     RTC_TRACE(("get_configuration()"));
00560 #ifndef ORB_IS_RTORB
00561     ::RTC::NVList* nvlist = new ::RTC::NVList();
00562     NVUtil::copyFromProperties(*nvlist, m_mgr.getConfig());
00563 #else
00564     ::RTC::NVList* nvlist;
00565     RTC_NVList nvlist_in;
00566     NVUtil::copyFromProperties(nvlist_in, m_mgr.getConfig());
00567     nvlist = new ::RTC::NVList(nvlist_in);
00568 #endif
00569     return nvlist;
00570   }
00571   
00579   RTC::ReturnCode_t
00580   ManagerServant::set_configuration(const char* name, const char* value)
00581   {
00582     RTC_TRACE(("set_configuration(name = %s, value = %s)", name, value));
00583     m_mgr.getConfig().setProperty(name, value);
00584     return ::RTC::RTC_OK;
00585   }
00593   CORBA::Boolean ManagerServant::is_master()
00594   {
00595     RTC_TRACE(("is_master(): %s", m_isMaster ? "YES" : "NO"));
00596     return m_isMaster;
00597   }
00598   
00606   RTM::ManagerList* ManagerServant::get_master_managers()
00607   {
00608     RTC_TRACE(("get_master_managers()"));
00609     Guard guard(m_masterMutex);
00610     return new ManagerList(m_masters);
00611   }
00612   
00620   RTC::ReturnCode_t ManagerServant::add_master_manager(RTM::Manager_ptr mgr)
00621   {
00622     Guard guard(m_masterMutex);
00623     CORBA::Long index;
00624     RTC_TRACE(("add_master_manager(), %d masters", m_masters.length()));
00625     index = CORBA_SeqUtil::find(m_masters, is_equiv(mgr));
00626     
00627     if (!(index < 0)) // found in my list
00628       {
00629         RTC_ERROR(("Already exists."));
00630         return RTC::BAD_PARAMETER;
00631       }
00632     
00633     CORBA_SeqUtil::push_back(m_masters, RTM::Manager::_duplicate(mgr));
00634     RTC_TRACE(("add_master_manager() done, %d masters", m_masters.length()));
00635     return RTC::RTC_OK;
00636   }
00637   
00645   RTC::ReturnCode_t
00646   ManagerServant::remove_master_manager(RTM::Manager_ptr mgr)
00647   {
00648     Guard guard(m_masterMutex);
00649     RTC_TRACE(("remove_master_manager(), %d masters", m_masters.length()));
00650 
00651     CORBA::Long index;
00652     index = CORBA_SeqUtil::find(m_masters, is_equiv(mgr));
00653     
00654     if (index < 0) // not found in my list
00655       {
00656         RTC_ERROR(("Not found."));
00657         return RTC::BAD_PARAMETER;
00658       }
00659     
00660     CORBA_SeqUtil::erase(m_masters, index);
00661     RTC_TRACE(("remove_master_manager() done, %d masters", m_masters.length()));
00662     return RTC::RTC_OK;
00663   }
00664   
00672   ManagerList* ManagerServant::get_slave_managers()
00673   {
00674     Guard guard(m_slaveMutex);
00675     RTC_TRACE(("get_slave_managers(), %d slaves", m_slaves.length()));
00676     
00677     return new ManagerList(m_slaves);
00678   }
00679 
00687   RTC::ReturnCode_t ManagerServant::add_slave_manager(RTM::Manager_ptr mgr)
00688   {
00689     Guard guard(m_slaveMutex);
00690     RTC_TRACE(("add_slave_manager(), %d slaves", m_slaves.length()));
00691     
00692     CORBA::Long index;
00693     index = CORBA_SeqUtil::find(m_slaves, is_equiv(mgr));
00694     
00695     if (!(index < 0)) // found in my list
00696       {
00697         RTC_ERROR(("Already exists."));
00698         return RTC::BAD_PARAMETER;
00699       }
00700     
00701     CORBA_SeqUtil::push_back(m_slaves, RTM::Manager::_duplicate(mgr));
00702     RTC_TRACE(("add_slave_manager() done, %d slaves", m_slaves.length()));
00703     return RTC::RTC_OK;;
00704   }
00705   
00713   RTC::ReturnCode_t ManagerServant::remove_slave_manager(RTM::Manager_ptr mgr)
00714   {
00715     Guard guard(m_slaveMutex);
00716     RTC_TRACE(("remove_slave_manager(), %d slaves", m_slaves.length()));
00717     CORBA::Long index;
00718     index = CORBA_SeqUtil::find(m_slaves, is_equiv(mgr));
00719     
00720     if (index < 0) // not found in my list
00721       {
00722         RTC_ERROR(("Not found."));
00723         return RTC::BAD_PARAMETER;
00724       }
00725     
00726     CORBA_SeqUtil::erase(m_slaves, index);
00727     RTC_TRACE(("remove_slave_manager() done, %d slaves", m_slaves.length()));
00728     return RTC::RTC_OK;
00729   }
00730   
00731   
00732   
00733   RTC::ReturnCode_t ManagerServant::fork()
00734   {
00735     //    m_mgr.fork();
00736     return ::RTC::RTC_OK;
00737   }
00738   
00739   RTC::ReturnCode_t ManagerServant::shutdown()
00740   {
00741     m_mgr.terminate();
00742     return ::RTC::RTC_OK;
00743   }
00744   
00745   RTC::ReturnCode_t ManagerServant::restart()
00746   {
00747     //    m_mgr.restart();
00748     return ::RTC::RTC_OK;
00749   }
00750   
00751   CORBA::Object_ptr ManagerServant::get_service(const char* name)
00752   {
00753     return ::CORBA::Object::_nil();
00754   }
00755   
00756   RTM::Manager_ptr ManagerServant::getObjRef() const
00757   {
00758     return m_objref;
00759   }
00760 
00761 
00762   bool ManagerServant::createINSManager()
00763   {
00764     try
00765       {
00766         //Ppreparing INS POA
00767         CORBA::Object_var obj;
00768 #ifndef ORB_IS_RTORB
00769         obj = m_mgr.getORB()->resolve_initial_references("omniINSPOA");
00770 #else // ROB_IS_RTORB
00771         obj = m_mgr.getORB()->resolve_initial_references((char*)"omniINSPOA");
00772 #endif // ORB_IS_RTORB
00773         PortableServer::POA_ptr poa = PortableServer::POA::_narrow(obj);
00774         poa->the_POAManager()->activate();
00775 
00776         // Create readable object ID
00777         coil::Properties config(m_mgr.getConfig());
00778         PortableServer::ObjectId_var id; 
00779 #ifndef ORB_IS_RTORB
00780         id = PortableServer::string_to_ObjectId(config["manager.name"].c_str());
00781 #else // ORB_IS_RTORB
00782         id = PortableServer::
00783           string_to_ObjectId((char *)config["manager.name"].c_str());
00784 #endif // ORB_IS_RTORB
00785 
00786         // Object activation
00787         poa->activate_object_with_id(id.in(), this);
00788         CORBA::Object_var mgrobj = poa->id_to_reference(id);
00789 
00790         // Set m_objref 
00791         m_objref = ::RTM::Manager::_narrow(mgrobj);
00792 
00793         CORBA::String_var ior;
00794         ior = m_mgr.getORB()->
00795           object_to_string(RTM::Manager::_duplicate(m_objref));
00796         std::string iorstr((const char*)ior);
00797         RTC_DEBUG(("Manager's IOR information:\n %s",
00798                    CORBA_IORUtil::formatIORinfo(iorstr.c_str()).c_str()));
00799       }
00800     catch (...)
00801       {
00802         return false;
00803       }
00804     return true;
00805   }
00806 
00807 
00808 
00809   RTM::Manager_ptr ManagerServant::findManager(const char* host_port)
00810   {
00811     RTC_TRACE(("findManager(host_port = %s)", host_port));
00812     try
00813       {
00814         coil::Properties config(m_mgr.getConfig());
00815         // Why RtORB does not allow corbaloc:iiop: ?
00816         //        std::string mgrloc("corbaloc:iiop:");
00817         std::string mgrloc("corbaloc::");
00818         mgrloc += host_port;
00819         mgrloc += "/" + config["manager.name"];
00820 
00821         RTC_DEBUG(("corbaloc: %s", mgrloc.c_str()));
00822 
00823         CORBA::Object_var mobj;
00824         mobj = m_mgr.getORB()->string_to_object(mgrloc.c_str());
00825 #ifndef ORB_IS_RTORB
00826         RTM::Manager_var mgr = ::RTM::Manager::_narrow(mobj);
00827 #else // ORB_IS_RTORB
00828         RTM::Manager_var mgr;
00829         if(!make_client_connection(mobj->impl()->connection))
00830           {
00831             return RTM::Manager_ptr();
00832           }
00833         else
00834           {
00835             mgr = ::RTM::Manager::_narrow(mobj);
00836           }
00837 #endif // ORB_IS_RTORB
00838 
00839         CORBA::String_var ior;
00840         ior = m_mgr.getORB()->object_to_string(RTM::Manager::_duplicate(mgr));
00841         std::string iorstr((const char*)ior);
00842         RTC_DEBUG(("Manager's IOR information:\n %s",
00843                    CORBA_IORUtil::formatIORinfo(iorstr.c_str()).c_str()));
00844      
00845         return mgr._retn();
00846       }
00847     catch(CORBA::SystemException& e)
00848       {
00849 #ifndef ORB_IS_RTORB
00850         RTC_DEBUG(("CORBA SystemException cought (CORBA::%s)", e._name()));
00851 #endif // ORB_IS_RTORB
00852       }
00853     catch (...)
00854       {
00855         RTC_ERROR(("Unknown exception cought."));
00856       }
00857     return RTM::Manager::_nil();
00858   }
00859 
00860   
00861 
00862 };


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:16