RTObject.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00019 #include <assert.h>
00020 #include <rtm/RTObject.h>
00021 #include <rtm/SdoConfiguration.h>
00022 #include <rtm/CORBA_SeqUtil.h>
00023 #include <rtm/Manager.h>
00024 #include <coil/stringutil.h>
00025 #include <iostream>
00026 #include <typeinfo>
00027 
00028 namespace RTC
00029 {
00037   static const char* default_conf[] =
00038     {
00039       "implementation_id", "",
00040       "type_name",         "",
00041       "description",       "",
00042       "version",           "",
00043       "vendor",            "",
00044       "category",          "",
00045       "activity_type",     "",
00046       "max_instance",      "",
00047       "language",          "",
00048       "lang_type",         "",
00049       "conf",              "",
00050       ""
00051     };
00052   
00060   RTObject_impl::RTObject_impl(Manager* manager)
00061     : m_pManager(manager),
00062       m_pORB(CORBA::ORB::_duplicate(manager->getORB())),
00063       m_pPOA(PortableServer::POA::_duplicate(manager->getPOA())),
00064       m_portAdmin(manager->getORB(), manager->getPOA()),
00065       m_created(true), m_exiting(false),
00066       m_properties(default_conf), m_configsets(m_properties.getNode("conf")),
00067       m_sdoservice(*this),
00068       m_readAll(false),m_writeAll(false),
00069       m_readAllCompletion(false),m_writeAllCompletion(false)
00070   {
00071     m_objref = this->_this();
00072     m_pSdoConfigImpl = new SDOPackage::Configuration_impl(m_configsets,
00073                                                           m_sdoservice);
00074     m_pSdoConfig = SDOPackage::Configuration::
00075       _duplicate(m_pSdoConfigImpl->getObjRef());
00076   }
00077   
00085   RTObject_impl::RTObject_impl(CORBA::ORB_ptr orb,
00086                                PortableServer::POA_ptr poa)
00087     : m_pManager(NULL),
00088       m_pORB(CORBA::ORB::_duplicate(orb)),
00089       m_pPOA(PortableServer::POA::_duplicate(poa)),
00090       m_portAdmin(orb, poa),
00091       m_created(true), m_exiting(false),
00092       m_properties(default_conf), m_configsets(m_properties.getNode("conf")),
00093       m_sdoservice(*this),
00094       m_readAll(false),m_writeAll(false),
00095       m_readAllCompletion(false),m_writeAllCompletion(false)
00096   {
00097     m_objref = this->_this();
00098     m_pSdoConfigImpl = new SDOPackage::Configuration_impl(m_configsets,
00099                                                           m_sdoservice);
00100     m_pSdoConfig = SDOPackage::Configuration::
00101       _duplicate(m_pSdoConfigImpl->getObjRef());
00102   }
00103   
00111   RTObject_impl::~RTObject_impl()
00112   {
00113     RTC_TRACE(("~RTObject_impl()"));
00114     m_pSdoConfigImpl->_remove_ref();
00115   }
00116   
00117   //============================================================
00118   // Overridden functions
00119   //============================================================
00127   // The initialize action (on CREATED->ALIVE transition)
00128   // former rtc_init_entry() 
00129   ReturnCode_t RTObject_impl::onInitialize()
00130   {
00131     RTC_TRACE(("onInitialize()"));
00132     return RTC::RTC_OK;
00133   }
00134   
00142   // The finalize action (on ALIVE->END transition)
00143   // former rtc_exiting_entry()
00144   ReturnCode_t RTObject_impl::onFinalize()
00145   {
00146     RTC_TRACE(("onFinalize()"));
00147     return RTC::RTC_OK;
00148   }
00149   
00157   // The startup action when ExecutionContext startup
00158   // former rtc_starting_entry()
00159   ReturnCode_t RTObject_impl::onStartup(RTC::UniqueId ec_id)
00160   {
00161     RTC_TRACE(("onStartup(%d)", ec_id));
00162     return RTC::RTC_OK;
00163   }
00164   
00172   // The shutdown action when ExecutionContext stop
00173   // former rtc_stopping_entry()
00174   ReturnCode_t RTObject_impl::onShutdown(RTC::UniqueId ec_id)
00175   {
00176     RTC_TRACE(("onShutdown(%d)", ec_id));
00177     return RTC::RTC_OK;
00178   }
00179   
00187   // The activated action (Active state entry action)
00188   // former rtc_active_entry()
00189   ReturnCode_t RTObject_impl::onActivated(RTC::UniqueId ec_id)
00190   {
00191     RTC_TRACE(("onActivated(%d)", ec_id));
00192     return RTC::RTC_OK;
00193   }
00194   
00202   // The deactivated action (Active state exit action)
00203   // former rtc_active_exit()
00204   ReturnCode_t RTObject_impl::onDeactivated(RTC::UniqueId ec_id)
00205   {
00206     RTC_TRACE(("onDeactivated(%d)", ec_id));
00207     return RTC::RTC_OK;
00208   }
00209   
00217   // The execution action that is invoked periodically
00218   // former rtc_active_do()
00219   ReturnCode_t RTObject_impl::onExecute(RTC::UniqueId ec_id)
00220   {
00221     RTC_PARANOID(("onExecute(%d)", ec_id));
00222     return RTC::RTC_OK;
00223   }
00224   
00232   // The aborting action when main logic error occurred.
00233   // former rtc_aborting_entry()
00234   ReturnCode_t RTObject_impl::onAborting(RTC::UniqueId ec_id)
00235   {
00236     RTC_TRACE(("onAborting(%d)", ec_id));
00237     return RTC::RTC_OK;
00238   }
00239   
00247   // The error action in ERROR state
00248   // former rtc_error_do()
00249   ReturnCode_t RTObject_impl::onError(RTC::UniqueId ec_id)
00250   {
00251     RTC_TRACE(("onError(%d)", ec_id));
00252     return RTC::RTC_OK;
00253   }
00254   
00262   // The reset action that is invoked resetting
00263   // This is same but different the former rtc_init_entry()
00264   ReturnCode_t RTObject_impl::onReset(RTC::UniqueId ec_id)
00265   {
00266     RTC_TRACE(("onReset(%d)", ec_id));
00267     return RTC::RTC_OK;
00268   }
00269   
00277   // The state update action that is invoked after onExecute() action
00278   // no corresponding operation exists in OpenRTm-aist-0.2.0
00279   ReturnCode_t RTObject_impl::onStateUpdate(RTC::UniqueId ec_id)
00280   {
00281     RTC_PARANOID(("onStateUpdate(%d)", ec_id));
00282     return RTC::RTC_OK;
00283   }
00284   
00292   // The action that is invoked when execution context's rate is changed
00293   // no corresponding operation exists in OpenRTm-aist-0.2.0
00294   ReturnCode_t RTObject_impl::onRateChanged(RTC::UniqueId ec_id)
00295   {
00296     RTC_TRACE(("onRatechanged(%d)", ec_id));
00297     return RTC::RTC_OK;
00298   }
00299   
00300   //============================================================
00301   // RTC::LightweightRTObject
00302   //============================================================
00310   ReturnCode_t RTObject_impl::initialize()
00311     throw (CORBA::SystemException)
00312   {
00313     RTC_TRACE(("initialize()"));
00314     std::string ec_args;
00315 
00316     ec_args += m_properties["exec_cxt.periodic.type"];
00317     ec_args += "?";
00318     ec_args += "rate=" + m_properties["exec_cxt.periodic.rate"];
00319 
00320     RTC::ExecutionContextBase* ec;
00321     ec = RTC::Manager::instance().createContext(ec_args.c_str());
00322     if (ec == NULL) return RTC::RTC_ERROR;
00323 
00324     ec->set_rate(atof(m_properties["exec_cxt.periodic.rate"].c_str()));
00325     m_eclist.push_back(ec);
00326     ExecutionContextService_var ecv;
00327     ecv = RTC::ExecutionContextService::_duplicate(ec->getObjRef());
00328     if (CORBA::is_nil(ecv)) return RTC::RTC_ERROR;
00329 
00330     ec->bindComponent(this);
00331     // -- entering alive state --
00332     // at least one EC must be attached
00333     if (m_ecMine.length() == 0) return RTC::PRECONDITION_NOT_MET;
00334 
00335     ReturnCode_t ret;
00336     ret = on_initialize();
00337     if (ret != RTC::RTC_OK) return ret;
00338     m_created = false;
00339 
00340     for (::CORBA::ULong i(0), len(m_ecMine.length()); i < len; ++i)
00341       {
00342         RTC_DEBUG(("EC[%d] starting.", i));
00343         m_ecMine[i]->start();
00344       }
00345 
00346     // ret must be RTC_OK
00347     return ret;
00348   }
00349   
00357   ReturnCode_t RTObject_impl::finalize()
00358     throw (CORBA::SystemException)
00359   {
00360     RTC_TRACE(("finalize()"));
00361     if (m_created) return RTC::PRECONDITION_NOT_MET;
00362     if (!m_exiting) return RTC::PRECONDITION_NOT_MET;
00363     // Return RTC::PRECONDITION_NOT_MET,
00364     // When the component is registered in ExecutionContext.
00365     // m_ecMine.length() != 0 || 
00366     if(m_ecOther.length() != 0)
00367     {
00368 
00369         for (CORBA::ULong ic(0), len(m_ecOther.length()); ic < len; ++ic)
00370           {
00371             if(! CORBA::is_nil(m_ecOther[ic]))
00372               {
00373                 return RTC::PRECONDITION_NOT_MET;
00374               }
00375           }
00376         CORBA_SeqUtil::clear(m_ecOther);
00377     }
00378     
00379     ReturnCode_t ret(on_finalize());
00380 
00381     shutdown();
00382     return ret;
00383   }
00384   
00394   ReturnCode_t RTObject_impl::exit()
00395     throw (CORBA::SystemException)
00396   {
00397     RTC_TRACE(("exit()"));
00398     if (m_created) { return RTC::PRECONDITION_NOT_MET; }
00399     if (m_exiting) { return RTC::RTC_OK; }
00400 
00401     // deactivate myself on owned EC
00402     CORBA_SeqUtil::for_each(m_ecMine,
00403                             deactivate_comps(m_objref));
00404     // deactivate myself on other EC
00405     CORBA_SeqUtil::for_each(m_ecOther,
00406                             deactivate_comps(m_objref));
00407 
00408     // owned EC will be finalised later in finalizeContext().
00409 
00410     // detach myself from other EC
00411     for (CORBA::ULong ic(0), len(m_ecOther.length()); ic < len; ++ic)
00412       {
00413         //        m_ecOther[ic]->stop();
00414         RTC::LightweightRTObject_var comp(this->_this());
00415         if (! ::CORBA::is_nil(m_ecOther[ic]))
00416           {
00417             m_ecOther[ic]->remove_component(comp.in());
00418           }
00419       }
00420     m_exiting = true;
00421     ReturnCode_t ret(finalize());
00422 
00423     return ret;
00424   }
00425   
00433   CORBA::Boolean RTObject_impl::is_alive(ExecutionContext_ptr exec_context)
00434     throw (CORBA::SystemException)
00435   {
00436     RTC_TRACE(("is_alive()"));
00437     for (::CORBA::ULong i(0), len(m_ecMine.length()); i < len; ++i)
00438       {
00439         if (exec_context->_is_equivalent(m_ecMine[i]))
00440           return true;
00441       }
00442 
00443     for (::CORBA::ULong i(0), len(m_ecOther.length()); i < len; ++i)
00444       {
00445         if (! ::CORBA::is_nil(m_ecOther[i]))
00446           {
00447             if (exec_context->_is_equivalent(m_ecOther[i]))
00448                 return true;
00449           }
00450       }
00451     return false;
00452   }
00453   
00461   ExecutionContext_ptr RTObject_impl::get_context(UniqueId ec_id)
00462     throw (CORBA::SystemException)
00463   {
00464     RTC_TRACE(("get_context(%d)", ec_id));
00465     // owned EC
00466     if (ec_id < ECOTHER_OFFSET)
00467       {
00468         if ((::CORBA::ULong)ec_id < m_ecMine.length())
00469           {
00470             return ExecutionContext::_duplicate(m_ecMine[ec_id]);
00471           }
00472         else
00473           {
00474             return ExecutionContext::_nil();
00475           }
00476       }
00477 
00478     // participating EC
00479     ::CORBA::ULong index(ec_id - ECOTHER_OFFSET);
00480 
00481     if (index < m_ecOther.length())
00482       {
00483         if (! ::CORBA::is_nil(m_ecOther[index]))
00484           {
00485             return ExecutionContext::_duplicate(m_ecOther[index]);
00486           }
00487       }
00488 
00489     return ExecutionContext::_nil();
00490   }
00491     
00499   ExecutionContextList* RTObject_impl::get_owned_contexts()
00500     throw (CORBA::SystemException)
00501   {
00502     RTC_TRACE(("get_owned_context()"));
00503 
00504 #ifndef ORB_IS_RTORB
00505     ExecutionContextList_var execlist;
00506     execlist = new ExecutionContextList();
00507     
00508     CORBA_SeqUtil::for_each(m_ecMine, ec_copy(execlist));
00509 #else // ORB_IS_RTORB
00510     ExecutionContextList_var execlist;
00511     execlist = new ExecutionContextList();
00512 
00513     int n = m_ecMine.length();
00514     for(int i(0), j(0); i < n ; ++i)
00515       {
00516         RTC_ExecutionContext ec_mine = m_ecMine.cobj()->_buffer[i];
00517 
00518         if (ec_mine)
00519           {
00520             execlist.length(j+1);
00521             execlist->cobj()->_buffer[j] = CORBA_Object_dup(ec_mine);
00522             ++j;
00523           }
00524       }
00525 #endif // ORB_IS_RTORB 
00526     return execlist._retn();
00527   }
00528 
00536   ExecutionContextList* RTObject_impl::get_participating_contexts()
00537     throw (CORBA::SystemException)
00538   {
00539     RTC_TRACE(("get_participating_contexts()"));
00540     ExecutionContextList_var execlist;
00541     execlist = new ExecutionContextList();
00542     
00543     CORBA_SeqUtil::for_each(m_ecOther, ec_copy(execlist));
00544     
00545     return execlist._retn();
00546   }
00547 
00548 
00556   ExecutionContextHandle_t
00557   RTObject_impl::get_context_handle(ExecutionContext_ptr cxt)
00558     throw (CORBA::SystemException)
00559   {
00560     RTC_TRACE(("get_context_handle()"));
00561     CORBA::Long num;
00562     num = CORBA_SeqUtil::find(m_ecMine, ec_find(cxt));
00563     if (num != -1)
00564       { 
00565         return (ExecutionContextHandle_t)num;
00566       }
00567     num = CORBA_SeqUtil::find(m_ecOther, ec_find(cxt));
00568     if (num != -1)
00569       { 
00570         return (ExecutionContextHandle_t)(ECOTHER_OFFSET + num);
00571       }
00572     return (ExecutionContextHandle_t)(-1);
00573   }
00574 
00575 
00583   UniqueId RTObject_impl::attach_context(ExecutionContext_ptr exec_context)
00584     throw (CORBA::SystemException)
00585   {
00586     RTC_TRACE(("attach_context()"));
00587     // ID: 0 - (offset-1) : owned ec
00588     // ID: offset -       : participating ec
00589     // owned       ec index = ID
00590     // participate ec index = ID - offset
00591     ExecutionContextService_var ecs;
00592     ecs = ExecutionContextService::_narrow(exec_context);
00593     if (CORBA::is_nil(ecs))
00594       {
00595         return -1;
00596       }
00597     
00598     // if m_ecOther has nil element, insert attached ec to there.
00599     for (::CORBA::ULong i(0), len(m_ecOther.length()); i < len; ++i)
00600       {
00601         if (::CORBA::is_nil(m_ecOther[i]))
00602           {
00603             m_ecOther[i] = ExecutionContextService::_duplicate(ecs);
00604             UniqueId ec_id(i + ECOTHER_OFFSET);
00605             onAttachExecutionContext(ec_id);
00606             return ec_id;
00607           }
00608       }
00609 
00610     // no space in the list, push back ec to the last.
00611     CORBA_SeqUtil::
00612       push_back(m_ecOther, ExecutionContextService::_duplicate(ecs));
00613     
00614     UniqueId ec_id((m_ecOther.length() - 1) + ECOTHER_OFFSET);
00615     onAttachExecutionContext(ec_id);
00616     return ec_id;
00617   }
00618   
00619   UniqueId
00620   RTObject_impl::bindContext(ExecutionContext_ptr exec_context)
00621   {
00622     RTC_TRACE(("bindContext()"));
00623     // ID: 0 - (offset-1) : owned ec
00624     // ID: offset -       : participating ec
00625     // owned       ec index = ID
00626     // participate ec index = ID - offset
00627     ExecutionContextService_var ecs;
00628     ecs = ExecutionContextService::_narrow(exec_context);
00629     if (CORBA::is_nil(ecs))
00630       {
00631         return -1;
00632       }
00633     
00634     // if m_ecMine has nil element, insert attached ec to there.
00635     for (::CORBA::ULong i(0), len(m_ecMine.length()); i < len; ++i)
00636       {
00637         if (::CORBA::is_nil(m_ecMine[i]))
00638           {
00639             m_ecMine[i] = ExecutionContextService::_duplicate(ecs);
00640             onAttachExecutionContext(i);
00641             return i;
00642           }
00643       }
00644 
00645     // no space in the list, push back ec to the last.
00646     CORBA_SeqUtil::
00647       push_back(m_ecMine, ExecutionContextService::_duplicate(ecs));
00648     
00649     UniqueId ec_id(m_ecMine.length() - 1);
00650     return ec_id;
00651   }
00652 
00660   ReturnCode_t RTObject_impl::detach_context(UniqueId ec_id)
00661     throw (CORBA::SystemException)
00662   {
00663     RTC_TRACE(("detach_context(%d)", ec_id));
00664     ::CORBA::ULong len(m_ecOther.length());
00665 
00666     // ID: 0 - (offset-1) : owned ec
00667     // ID: offset -       : participating ec
00668     // owned       ec index = ID
00669     // participate ec index = ID - offset
00670     if ((CORBA::ULong)ec_id < ECOTHER_OFFSET || 
00671         (CORBA::ULong)(ec_id - ECOTHER_OFFSET) > len)
00672       {
00673         return RTC::BAD_PARAMETER;
00674       }
00675     ::CORBA::ULong index(ec_id - ECOTHER_OFFSET);
00676 
00677     if (CORBA::is_nil(m_ecOther[index]))
00678       {
00679         return RTC::BAD_PARAMETER;
00680       }
00681     
00682     m_ecOther[index] = ::RTC::ExecutionContextService::_nil();
00683     onDetachExecutionContext(ec_id);
00684     return RTC::RTC_OK;
00685   }
00686   
00687   //============================================================
00688   // RTC::RTObject
00689   //============================================================
00690   
00698   ComponentProfile* RTObject_impl::get_component_profile()
00699     throw (CORBA::SystemException)
00700   {
00701     RTC_TRACE(("get_component_profile()"));
00702     try
00703       {
00704         ComponentProfile_var profile
00705           = new ComponentProfile();
00706 #ifndef ORB_IS_RTORB
00707         profile->instance_name = 
00708           CORBA::string_dup(m_properties["instance_name"].c_str());
00709         profile->type_name     = 
00710           CORBA::string_dup(m_properties["type_name"].c_str());
00711         profile->description   = 
00712           CORBA::string_dup(m_properties["description"].c_str());
00713         profile->version       = 
00714           CORBA::string_dup(m_properties["version"].c_str());
00715         profile->vendor        = 
00716           CORBA::string_dup(m_properties["vendor"].c_str());
00717         profile->category      = 
00718           CORBA::string_dup(m_properties["category"].c_str());
00719         profile->port_profiles = m_portAdmin.getPortProfileList();
00720 #else // ORB_IS_RTORB
00721         profile->instance_name = (char *)m_properties["instance_name"].c_str();
00722         profile->type_name     = (char *)m_properties["type_name"].c_str();
00723         profile->description   = (char *)m_properties["description"].c_str();
00724         profile->version       = (char *)m_properties["version"].c_str();
00725         profile->vendor        = (char *)m_properties["vendor"].c_str();
00726         profile->category      = (char *)m_properties["category"].c_str();
00727         PortProfileList ppl    = m_portAdmin.getPortProfileList();
00728         profile->port_profiles = ppl._retn();
00729 #endif // ORB_IS_RTORB
00730         NVUtil::copyFromProperties(profile->properties, m_properties);
00731         return profile._retn();
00732       }
00733     catch (...)
00734       {
00735         ; // This operation throws no exception.
00736       }
00737     assert(false);
00738     return 0;
00739   }
00740   
00748   PortServiceList* RTObject_impl::get_ports()
00749     throw (CORBA::SystemException)
00750   {
00751     RTC_TRACE(("get_ports()"));
00752     try
00753       {
00754         return m_portAdmin.getPortServiceList();
00755       }
00756     catch (...)
00757       {
00758         ; // This operation throws no exception.
00759       }
00760     assert(false);
00761     return 0;
00762   }
00763   
00764   
00765   //============================================================
00766   // RTC::ComponentAction
00767   //============================================================
00775   ReturnCode_t RTObject_impl::on_initialize()
00776     throw (CORBA::SystemException)
00777   {
00778     RTC_TRACE(("on_initialize()"));
00779     ReturnCode_t ret(RTC::RTC_ERROR);
00780     try
00781       {
00782         preOnInitialize(0);
00783         ret = onInitialize();
00784       }
00785     catch (...)
00786       {
00787         ret = RTC::RTC_ERROR;
00788       }
00789     std::string active_set;
00790     active_set = m_properties.getProperty("configuration.active_config",
00791                                           "default");
00792     if (m_configsets.haveConfig(active_set.c_str()))
00793       {
00794         m_configsets.update(active_set.c_str());
00795       }
00796     else
00797       {
00798         m_configsets.update("default");
00799       }
00800     postOnInitialize(0, ret);
00801     return ret;
00802   }
00803   
00811   ReturnCode_t RTObject_impl::on_finalize()
00812     throw (CORBA::SystemException)
00813   {
00814     RTC_TRACE(("on_finalize()"));
00815     ReturnCode_t ret(RTC::RTC_ERROR);
00816     try
00817       {
00818         preOnFinalize(0);
00819         ret = onFinalize();
00820       }
00821     catch (...)
00822       {
00823         ret = RTC::RTC_ERROR;
00824       }
00825     postOnFinalize(0, ret);
00826     return ret;
00827   }
00828   
00836   ReturnCode_t RTObject_impl::on_startup(UniqueId ec_id)
00837     throw (CORBA::SystemException)
00838   {
00839     RTC_TRACE(("on_startup(%d)", ec_id));
00840     ReturnCode_t ret(RTC::RTC_ERROR);
00841     try
00842       {
00843         preOnStartup(ec_id);
00844         ret = onStartup(ec_id);
00845       }
00846     catch (...)
00847       {
00848         ret = RTC::RTC_ERROR;
00849       }
00850     postOnStartup(ec_id, ret);
00851     return ret;
00852   }
00853   
00861   ReturnCode_t RTObject_impl::on_shutdown(UniqueId ec_id)
00862     throw (CORBA::SystemException)
00863   {
00864     RTC_TRACE(("on_shutdown(%d)", ec_id));
00865     ReturnCode_t ret(RTC::RTC_ERROR);
00866     try
00867       {
00868         preOnShutdown(ec_id);
00869         ret = onShutdown(ec_id);
00870       }
00871     catch (...)
00872       {
00873         ret = RTC::RTC_ERROR;
00874       }
00875     postOnShutdown(ec_id, ret);
00876     return ret;
00877   }
00878   
00886   ReturnCode_t RTObject_impl::on_activated(UniqueId ec_id)
00887     throw (CORBA::SystemException)
00888   {
00889     RTC_TRACE(("on_activated(%d)", ec_id));
00890     ReturnCode_t ret(RTC::RTC_ERROR);
00891     try
00892       {
00893         preOnActivated(ec_id);
00894         m_configsets.update();
00895         ret = onActivated(ec_id);
00896         m_portAdmin.activatePorts();
00897       }
00898     catch (...)
00899       {
00900         ret = RTC::RTC_ERROR;
00901       }
00902     postOnActivated(ec_id, ret);
00903     return ret;
00904   }
00905   
00913   ReturnCode_t RTObject_impl::on_deactivated(UniqueId ec_id)
00914     throw (CORBA::SystemException)
00915   {
00916     RTC_TRACE(("on_deactivated(%d)", ec_id));
00917     ReturnCode_t ret(RTC::RTC_ERROR);
00918     try
00919       {
00920         preOnDeactivated(ec_id);
00921         m_portAdmin.deactivatePorts();
00922         ret = onDeactivated(ec_id);
00923       }
00924     catch (...)
00925       {
00926         ret = RTC::RTC_ERROR;
00927       }
00928     postOnDeactivated(ec_id, ret);
00929     return ret;
00930   }
00931   
00939   ReturnCode_t RTObject_impl::on_aborting(UniqueId ec_id)
00940     throw (CORBA::SystemException)
00941   {
00942     RTC_TRACE(("on_aborting(%d)", ec_id));
00943     ReturnCode_t ret(RTC::RTC_ERROR);
00944     try
00945       {
00946         preOnAborting(ec_id);
00947         ret = onAborting(ec_id);
00948       }
00949     catch (...)
00950       {
00951         ret = RTC::RTC_ERROR;
00952       }
00953     postOnAborting(ec_id, ret);
00954     return ret;
00955   }
00956   
00964   ReturnCode_t RTObject_impl::on_error(UniqueId ec_id)
00965     throw (CORBA::SystemException)
00966   {
00967     RTC_TRACE(("on_error(%d)", ec_id));
00968     ReturnCode_t ret(RTC::RTC_ERROR);
00969     try
00970       {
00971         preOnError(ec_id);
00972         ret = onError(ec_id);
00973       }
00974     catch (...)
00975       {
00976         ret = RTC::RTC_ERROR;
00977       }
00978     m_configsets.update();
00979     postOnError(ec_id, ret);
00980     return ret;
00981   }
00982   
00990   ReturnCode_t RTObject_impl::on_reset(UniqueId ec_id)
00991     throw (CORBA::SystemException)
00992   {
00993     RTC_TRACE(("on_reset(%d)", ec_id));
00994     ReturnCode_t ret(RTC::RTC_ERROR);
00995     try
00996       {
00997         preOnReset(ec_id);
00998         ret = onReset(ec_id);
00999       }
01000     catch (...)
01001       {
01002         ret = RTC::RTC_ERROR;
01003       }
01004     postOnReset(ec_id, ret);
01005     return ret;
01006   }
01007   
01016   ReturnCode_t RTObject_impl::on_execute(UniqueId ec_id)
01017     throw (CORBA::SystemException)
01018   {
01019     RTC_PARANOID(("on_execute(%d)", ec_id));
01020     ReturnCode_t ret(RTC::RTC_ERROR);
01021     try
01022       {
01023         preOnExecute(ec_id);
01024         if (m_readAll) {readAll(); }
01025         ret = onExecute(ec_id);
01026         if (m_writeAll) { writeAll();}
01027       }
01028     catch (...)
01029       {
01030         ret = RTC::RTC_ERROR;
01031       }
01032     postOnExecute(ec_id, ret);
01033     return ret;
01034   }
01035   
01044   ReturnCode_t RTObject_impl::on_state_update(UniqueId ec_id)
01045     throw (CORBA::SystemException)
01046   {
01047     RTC_PARANOID(("on_state_update(%d)", ec_id));
01048     ReturnCode_t ret(RTC::RTC_ERROR);
01049     try
01050       {
01051         preOnStateUpdate(ec_id);
01052         ret = onStateUpdate(ec_id);
01053         m_configsets.update();
01054       }
01055     catch (...)
01056       {
01057         ret = RTC::RTC_ERROR;
01058       }
01059     postOnStateUpdate(ec_id, ret);
01060     return ret;
01061   }
01062   
01070   ReturnCode_t RTObject_impl::on_rate_changed(UniqueId ec_id)
01071     throw (CORBA::SystemException)
01072   {
01073     RTC_TRACE(("on_rate_changed(%d)", ec_id));
01074     ReturnCode_t ret(RTC::RTC_ERROR);
01075     try
01076       {
01077         preOnRateChanged(ec_id);
01078         ret = onRateChanged(ec_id);
01079       }
01080     catch (...)
01081       {
01082         ret = RTC::RTC_ERROR;
01083       }
01084     postOnRateChanged(ec_id, ret);
01085     return ret;
01086   }
01087   
01088   //============================================================
01089   // SDO interfaces
01090   //============================================================
01098   SDOPackage::OrganizationList* RTObject_impl::get_owned_organizations()
01099     throw (CORBA::SystemException,
01100            SDOPackage::NotAvailable, SDOPackage::InternalError)
01101   {
01102     RTC_TRACE(("get_owned_organizations()"));
01103     try
01104       {
01105         SDOPackage::OrganizationList_var org_list;
01106         org_list = new SDOPackage::OrganizationList(m_sdoOwnedOrganizations);
01107         return org_list._retn();
01108       }
01109     catch (...)
01110       {
01111         throw SDOPackage::NotAvailable();
01112       }
01113     return new SDOPackage::OrganizationList();
01114   }
01115   
01116   // SDOPackage::SDO
01124   char* RTObject_impl::get_sdo_id()
01125     throw (CORBA::SystemException, 
01126            SDOPackage::NotAvailable, SDOPackage::InternalError)
01127   {
01128     RTC_TRACE(("get_sdo_id()"));
01129     try
01130       {
01131         CORBA::String_var sdo_id;
01132         sdo_id = CORBA::string_dup(m_profile.instance_name);
01133         return sdo_id._retn();
01134       }
01135     catch (...)
01136       {
01137         throw SDOPackage::InternalError("get_sdo_id()");
01138       }
01139   }
01140   
01148   char* RTObject_impl::get_sdo_type()
01149     throw (CORBA::SystemException, 
01150            SDOPackage::NotAvailable, SDOPackage::InternalError)
01151   {
01152     RTC_TRACE(("get_sdo_type()"));
01153     CORBA::String_var sdo_type;
01154     try
01155       {
01156         sdo_type = CORBA::string_dup(m_profile.description);
01157         return sdo_type._retn();
01158       }
01159     catch (...)
01160       {
01161         throw SDOPackage::InternalError("get_sdo_type()");
01162       }
01163     sdo_type = "";
01164     return sdo_type._retn();
01165   }
01166   
01174   SDOPackage::DeviceProfile* RTObject_impl::get_device_profile()
01175     throw (CORBA::SystemException, 
01176            SDOPackage::NotAvailable, SDOPackage::InternalError)
01177   {
01178     RTC_TRACE(("get_device_profile()"));
01179     try
01180       {
01181         SDOPackage::DeviceProfile_var dprofile;
01182         dprofile =
01183           new SDOPackage::DeviceProfile(m_pSdoConfigImpl->getDeviceProfile());
01184         return dprofile._retn();
01185       }
01186     catch (...)
01187       {
01188         throw SDOPackage::InternalError("get_device_profile()");
01189       }
01190     return new SDOPackage::DeviceProfile();
01191   }
01192 
01193   //------------------------------------------------------------
01194   // SDO service
01195   //------------------------------------------------------------
01203   SDOPackage::ServiceProfileList* RTObject_impl::get_service_profiles()
01204     throw (CORBA::SystemException, 
01205            SDOPackage::NotAvailable, SDOPackage::InternalError)
01206   {
01207     RTC_TRACE(("get_service_profiles()"));
01208 
01209     SDOPackage::ServiceProfileList_var sprofiles;
01210     try
01211       {
01212         sprofiles = m_sdoservice.getServiceProviderProfiles();
01213         RTC_DEBUG(("SDO ServiceProfiles[%d]", sprofiles->length()));
01214       }
01215     catch (...)
01216       {
01217         RTC_ERROR(("Unknown exception cought in get_service_profiles()."));
01218         throw SDOPackage::InternalError("get_service_profiles()");
01219       }
01220     return sprofiles._retn();
01221   }
01222   
01230   SDOPackage::ServiceProfile*
01231   RTObject_impl::get_service_profile(const char* id)
01232     throw (CORBA::SystemException, 
01233            SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
01234            SDOPackage::InternalError)
01235   {
01236     if (!id)
01237       {
01238         throw SDOPackage::
01239           InvalidParameter("get_service_profile(): Empty name.");
01240       }
01241     RTC_TRACE(("get_service_profile(%s))", id));
01242     
01243     SDOPackage::ServiceProfile_var prof;
01244     try
01245       {
01246         prof = m_sdoservice.getServiceProviderProfile(id);
01247       }
01248     catch (SDOPackage::InvalidParameter &e)
01249       {
01250         RTC_ERROR(("InvalidParameter exception: name (%s) is not found", id));
01251         throw e;
01252       }
01253     catch (...)
01254       {
01255         RTC_ERROR(("Unknown exception cought in get_service_profile(%s).", id));
01256         throw SDOPackage::InternalError("get_service_profile()");
01257       }
01258     return prof._retn();
01259   }
01260   
01268   SDOPackage::SDOService_ptr RTObject_impl::get_sdo_service(const char* id)
01269     throw (CORBA::SystemException, 
01270            SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
01271            SDOPackage::InternalError)
01272   {
01273     RTC_TRACE(("get_sdo_service(%s))", id));
01274     if (!id)
01275       {
01276         throw SDOPackage::InvalidParameter("get_service(): Empty name.");
01277       }
01278 
01279     SDOPackage::SDOService_var sdo;
01280     try
01281       {
01282         sdo = m_sdoservice.getServiceProvider(id);
01283       }
01284     catch (SDOPackage::InvalidParameter &e)
01285       {
01286         throw e;
01287       }
01288     catch (...)
01289       {
01290         throw SDOPackage::InternalError("get_service()");
01291       }
01292     return sdo;
01293   }
01294   
01302   SDOPackage::Configuration_ptr RTObject_impl::get_configuration()
01303     throw (CORBA::SystemException, 
01304            SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
01305            SDOPackage::InternalError)
01306   {
01307     RTC_TRACE(("get_configuration()"));
01308     if (m_pSdoConfig == NULL)
01309       throw SDOPackage::InterfaceNotImplemented();
01310     try
01311       {
01312 #ifdef ORB_IS_RTORB
01313         SDOPackage::Configuration_ptr config;
01314         config = m_pSdoConfig;
01315         return config;
01316 #else // ORB_IS_RTORB
01317         SDOPackage::Configuration_var config;
01318         config = m_pSdoConfig;
01319         return config._retn();
01320 #endif // ORB_IS_RTORB
01321       }
01322     catch (...)
01323       {
01324         SDOPackage::InternalError("get_configuration()");
01325       }
01326     return SDOPackage::Configuration::_nil();
01327   }
01328   
01336   SDOPackage::Monitoring_ptr RTObject_impl::get_monitoring()
01337     throw (CORBA::SystemException, 
01338            SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
01339            SDOPackage::InternalError)
01340   {
01341     RTC_TRACE(("get_monitoring()"));
01342     throw SDOPackage::InterfaceNotImplemented();
01343     return SDOPackage::Monitoring::_nil();
01344   }
01345   
01353   SDOPackage::OrganizationList* RTObject_impl::get_organizations()
01354     throw (CORBA::SystemException, 
01355            SDOPackage::NotAvailable, SDOPackage::InternalError)
01356   {
01357     RTC_TRACE(("get_organizations()"));
01358     m_sdoOrganizations = m_pSdoConfigImpl->getOrganizations();
01359     try
01360       {
01361         SDOPackage::OrganizationList_var org;
01362         org = new SDOPackage::OrganizationList(m_sdoOrganizations);
01363         return org._retn();
01364       }
01365     catch (...)
01366       {
01367         throw SDOPackage::InternalError("get_organizations()");
01368       }
01369     return new SDOPackage::OrganizationList(0);
01370   }
01371   
01379   SDOPackage::NVList* RTObject_impl::get_status_list()
01380     throw (CORBA::SystemException, 
01381            SDOPackage::NotAvailable, SDOPackage::InternalError)
01382   {
01383     RTC_TRACE(("get_status_list()"));
01384     try
01385       {
01386         NVList_var status;
01387         status = new NVList(m_sdoStatus);
01388         return status._retn();
01389       }
01390     catch (...)
01391       {
01392         SDOPackage::InternalError("get_status_list()");
01393       }
01394     return new SDOPackage::NVList(0);
01395   }
01396   
01404   CORBA::Any* RTObject_impl::get_status(const char* name)
01405     throw (CORBA::SystemException, 
01406            SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
01407            SDOPackage::InternalError)
01408   {
01409     RTC_TRACE(("get_status(%s)", name));
01410     CORBA::Long index;
01411     index = CORBA_SeqUtil::find(m_sdoStatus, nv_name(name));
01412     if (index < 0)
01413       throw SDOPackage::InvalidParameter("get_status(): Not found");
01414     try
01415       {
01416         CORBA::Any_var status;
01417         status = new CORBA::Any(m_sdoStatus[index].value);
01418         return status._retn();
01419       }
01420     catch (...)
01421       {
01422         throw SDOPackage::InternalError("get_status()");
01423       }
01424     return new CORBA::Any();
01425   }
01426   
01427   //============================================================
01428   // Local methods
01429   //============================================================
01437   void RTObject_impl::setInstanceName(const char* instance_name)
01438   {
01439     rtclog.setName(instance_name);
01440     RTC_TRACE(("setInstanceName(%s)", instance_name));
01441 
01442     m_properties["instance_name"] = instance_name;
01443 #ifndef ORB_IS_RTORB
01444     m_profile.instance_name = m_properties["instance_name"].c_str();
01445 #else // ORB_IS_RTORB
01446     m_profile.instance_name = (char *)m_properties["instance_name"].c_str();
01447 #endif // ORB_IS_RTORB
01448   }
01449   
01457   std::vector<std::string> RTObject_impl::getNamingNames()
01458   {
01459     RTC_TRACE(("getNamingNames()"));
01460     return coil::split(m_properties["naming.names"], ",");
01461   }
01462   
01470   void RTObject_impl::setObjRef(const RTObject_ptr rtobj)
01471   {
01472     RTC_TRACE(("setObjRef()"));
01473     m_objref = RTC::RTObject::_duplicate(rtobj);
01474   }
01475   
01483   RTObject_ptr RTObject_impl::getObjRef() const
01484   {
01485     RTC_TRACE(("getObjRef()"));
01486 
01487     return m_objref;
01488   }
01489   
01497   void RTObject_impl::setProperties(const coil::Properties& prop)
01498   {
01499     RTC_TRACE(("setProperties()"));
01500     m_properties << prop;
01501 #ifndef ORB_IS_RTORB
01502     m_profile.instance_name = m_properties["instance_name"].c_str();
01503     m_profile.type_name     = m_properties["type_name"].c_str();
01504     m_profile.description   = m_properties["description"].c_str();
01505     m_profile.version       = m_properties["version"].c_str();
01506     m_profile.vendor        = m_properties["vendor"].c_str();
01507     m_profile.category      = m_properties["category"].c_str();
01508 #else // ORB_IS_RTORB
01509     m_profile.instance_name = (char*)m_properties["instance_name"].c_str();
01510     m_profile.type_name     = (char*)m_properties["type_name"].c_str();
01511     m_profile.description   = (char*)m_properties["description"].c_str();
01512     m_profile.version       = (char*)m_properties["version"].c_str();
01513     m_profile.vendor        = (char*)m_properties["vendor"].c_str();
01514     m_profile.category      = (char*)m_properties["category"].c_str();
01515 #endif //ORB_IS_RTORB
01516   }
01517   
01525   coil::Properties& RTObject_impl::getProperties()
01526   {
01527     RTC_TRACE(("getProperties()"));
01528     return m_properties;
01529   }
01530   
01538   void RTObject_impl::updateParameters(const char* config_set)
01539   {
01540     RTC_TRACE(("updateParameters(%s)", config_set));
01541     m_configsets.update(config_set);
01542     return;
01543   }
01544   
01552   void RTObject_impl::registerPort(PortBase& port)
01553   {
01554     RTC_TRACE(("registerPort(PortBase&)"));
01555     if (!addPort(port))
01556       RTC_ERROR(("addPort(PortBase&) failed."));
01557   }
01558   bool RTObject_impl::addPort(PortBase& port)
01559   {
01560     RTC_TRACE(("addPort(PortBase&)"));
01561     port.setOwner(this->getObjRef());
01562     port.setPortConnectListenerHolder(&m_portconnListeners);
01563     onAddPort(port.getPortProfile());
01564     return m_portAdmin.addPort(port);
01565   }
01566   
01567   void RTObject_impl::registerPort(PortService_ptr port)
01568   {
01569     RTC_TRACE(("registerPort(PortBase&)"));
01570     if (!addPort(port))
01571       RTC_ERROR(("addPort(PortBase&) failed."));
01572   }
01573   bool RTObject_impl::addPort(PortService_ptr port)
01574   {
01575     RTC_TRACE(("addPort(PortService_ptr)"));
01576     return m_portAdmin.addPort(port);
01577   }
01578 
01579   void RTObject_impl::registerPort(CorbaPort& port)
01580   {
01581     RTC_TRACE(("registerPort(CorbaPort&)"));
01582     if (!addPort(port))
01583       RTC_ERROR(("addPort(CorbaPort&) failed."));
01584   }
01585 
01586   bool RTObject_impl::addPort(CorbaPort& port)
01587   {
01588     RTC_TRACE(("addPort(CrobaPort)"));
01589     std::string propkey("port.corbaport.");
01590     m_properties.getNode(propkey) 
01591       << m_properties.getNode("port.corba");
01592     
01593     port.init(m_properties.getNode(propkey));
01594     return addPort((PortBase&)port);
01595   }
01596 
01604   bool RTObject_impl::addInPort(const char* name,
01605                                 InPortBase& inport)
01606   {
01607     RTC_TRACE(("addInPort(%s)", name));
01608 
01609     std::string propkey("port.inport.");
01610     propkey += name;
01611     m_properties.getNode(propkey)
01612       << m_properties.getNode("port.inport.dataport");
01613 
01614     bool ret(addPort(inport));
01615     
01616     if (!ret)
01617       {
01618         RTC_ERROR(("addInPort() failed."));
01619         return ret;
01620       }
01621 
01622     inport.init(m_properties.getNode(propkey));
01623     m_inports.push_back(&inport);
01624     return ret;
01625   }
01626 
01627   void RTObject_impl::registerInPort(const char* name,
01628                                      InPortBase& inport)
01629   {
01630     RTC_TRACE(("registerInPort(%s)", name));
01631 
01632     if (!addInPort(name, inport))
01633       {
01634         RTC_ERROR(("addInPort(%s) failed.", name));
01635       }
01636   }
01637 
01645   bool RTObject_impl::addOutPort(const char* name,
01646                                  OutPortBase& outport)
01647   {
01648     RTC_TRACE(("addOutPort(%s)", name));
01649     
01650     std::string propkey("port.outport.");
01651     propkey += name;
01652     m_properties.getNode(propkey) 
01653       << m_properties.getNode("port.outport.dataport");
01654     
01655     bool ret(addPort(outport));
01656     
01657     if (!ret)
01658       {
01659         RTC_ERROR(("addOutPort() failed."));
01660         return ret;
01661       }
01662 
01663     outport.init(m_properties.getNode(propkey));
01664     m_outports.push_back(&outport);
01665     return ret;
01666   }
01667   
01668   void RTObject_impl::registerOutPort(const char* name,
01669                                       OutPortBase& outport)
01670   {
01671     RTC_TRACE(("registerOutPort(%s)", name));
01672 
01673     if (!addOutPort(name, outport))
01674       {
01675         RTC_ERROR(("addOutPort(%s) failed.", name));
01676       }
01677   }
01678   
01686   bool RTObject_impl::removeInPort(InPortBase& inport)
01687   {
01688     RTC_TRACE(("removeInPort()"));
01689     bool ret(removePort(inport));
01690 
01691     std::vector<InPortBase*>::iterator it = m_inports.begin();
01692 
01693     if (ret)
01694       {
01695         while (it != m_inports.end())
01696           {
01697             if ( (*it) == &inport )
01698               {
01699                 m_inports.erase(it);
01700                 return true;
01701               }
01702             ++it;
01703           }
01704       }
01705 
01706     return false;
01707   }
01708 
01716   bool RTObject_impl::removeOutPort(OutPortBase& outport)
01717   {
01718     RTC_TRACE(("removeOutPort()"));
01719 
01720     bool ret(removePort(outport));
01721 
01722     if (ret)
01723       {
01724         std::vector<OutPortBase*>::iterator it = m_outports.begin();
01725         while (it != m_outports.end())
01726           {
01727             if ( (*it) == &outport )
01728               {
01729                 m_outports.erase(it);
01730                 return true;
01731               }
01732             ++it;
01733           }
01734       }
01735 
01736     return false;
01737   }
01738 
01746   bool RTObject_impl::removePort(PortBase& port)
01747   {
01748     RTC_TRACE(("removePort(PortBase&)"));
01749     onRemovePort(port.getPortProfile());
01750     return m_portAdmin.removePort(port);
01751   }
01752   bool RTObject_impl::removePort(PortService_ptr port)
01753   {
01754     RTC_TRACE(("removePort(PortService_pt)"));
01755     return m_portAdmin.removePort(port);
01756   }
01757   bool RTObject_impl::removePort(CorbaPort& port)
01758   {
01759     RTC_TRACE(("removePort(PortBase&)"));
01760     onRemovePort(port.getPortProfile());
01761     return m_portAdmin.removePort((PortBase&)port);
01762   }
01763 
01764   void RTObject_impl::deletePort(PortBase& port)
01765   {
01766     RTC_TRACE(("deletePort(PortBase&)"));
01767     if (!removePort(port))
01768       RTC_ERROR(("removePort(PortBase&) failed."));
01769     return;
01770   }
01771   void RTObject_impl::deletePort(PortService_ptr port)
01772   {
01773     RTC_TRACE(("deletePort(PortService_pt)"));
01774     if (!removePort(port))
01775       RTC_ERROR(("removePort(PortService_pt) failed."));
01776     return;
01777   }
01778   void RTObject_impl::deletePort(CorbaPort& port)
01779   {
01780     RTC_TRACE(("deletePort(CorbaPort)"));
01781     if (!removePort(port))
01782       RTC_ERROR(("removePort(CorbaPort) failed."));
01783     return;
01784   }
01785 
01793   void RTObject_impl::deletePortByName(const char* port_name)
01794   {
01795     RTC_TRACE(("deletePortByName(%s)", port_name));
01796     m_portAdmin.deletePortByName(port_name);
01797     return;
01798   }
01799 
01807   ExecutionContext_ptr
01808   RTObject_impl::getExecutionContext(RTC::UniqueId ec_id)
01809   {
01810     return get_context(ec_id);
01811   }
01812 
01820   double RTObject_impl::getExecutionRate(RTC::UniqueId ec_id)
01821   {
01822     ExecutionContext_var ec(getExecutionContext(ec_id));
01823     if (CORBA::is_nil(ec))
01824       {
01825         return 0.0;
01826       }
01827     return ec->get_rate();
01828   }
01829 
01837   ReturnCode_t
01838   RTObject_impl::setExecutionRate(RTC::UniqueId ec_id, double rate)
01839   {
01840     ExecutionContext_var ec(getExecutionContext(ec_id));
01841     if (CORBA::is_nil(ec))
01842       {
01843         return RTC::RTC_ERROR;
01844       }
01845     ec->set_rate(rate);
01846     return RTC::RTC_OK;
01847   }
01848 
01856  bool RTObject_impl::isOwnExecutionContext(RTC::UniqueId ec_id)
01857   {
01858     if (ec_id < ECOTHER_OFFSET)
01859       {
01860         return true;
01861       }
01862     return false;
01863   }
01864 
01872   ReturnCode_t RTObject_impl::deactivate(RTC::UniqueId ec_id)
01873   {
01874     ExecutionContext_var ec(getExecutionContext(ec_id));
01875     if (CORBA::is_nil(ec))
01876       {
01877         return RTC::RTC_ERROR;
01878       }
01879     return ec->deactivate_component(::RTC::RTObject::_duplicate(getObjRef()));
01880   }
01881 
01889   ReturnCode_t RTObject_impl::activate(RTC::UniqueId ec_id)
01890   {
01891     ExecutionContext_var ec(getExecutionContext(ec_id));
01892     if (CORBA::is_nil(ec))
01893       {
01894         return RTC::RTC_ERROR;
01895       }
01896     return ec->activate_component(::RTC::RTObject::_duplicate(getObjRef()));
01897   }
01898 
01906   ReturnCode_t RTObject_impl::reset(RTC::UniqueId ec_id)
01907   {
01908     ExecutionContext_var ec(getExecutionContext(ec_id));
01909     if (CORBA::is_nil(ec))
01910       {
01911         return RTC::RTC_ERROR;
01912       }
01913     return ec->reset_component(::RTC::RTObject::_duplicate(getObjRef()));
01914   }
01915 
01923   bool RTObject_impl::
01924   addSdoServiceProvider(const SDOPackage::ServiceProfile& prof,
01925                         SdoServiceProviderBase* provider)
01926   {
01927     return m_sdoservice.addSdoServiceProvider(prof, provider);
01928   }
01929 
01937   bool RTObject_impl::removeSdoServiceProvider(const char* id)
01938   {
01939     return m_sdoservice.removeSdoServiceProvider(id);
01940   }
01941 
01949   bool RTObject_impl::
01950   addSdoServiceConsumer(const SDOPackage::ServiceProfile& prof)
01951   {
01952     return m_sdoservice.addSdoServiceConsumer(prof);
01953   }
01954 
01962   bool RTObject_impl::removeSdoServiceConsumer(const char* id)
01963   {
01964     return m_sdoservice.removeSdoServiceConsumer(id);
01965   }
01966 
01976   bool RTObject_impl::readAll()
01977   {
01978     RTC_TRACE(("readAll()"));
01979     std::vector<InPortBase*>::iterator it     = m_inports.begin(); 
01980     std::vector<InPortBase*>::iterator it_end = m_inports.end(); 
01981     bool ret(true);
01982 
01983     while( it != it_end )
01984       {
01985 
01986         if (!((*it)->read()))
01987           {
01988             RTC_DEBUG(("The error occurred in readAll()."));
01989             ret = false;
01990             if (!m_readAllCompletion)
01991               return false;
01992           }
01993         ++it;
01994       }
01995 
01996     return ret;
01997   }
01998 
02008   bool RTObject_impl::writeAll()
02009   {
02010     RTC_TRACE(("writeAll()"));
02011     std::vector<OutPortBase*>::iterator it     = m_outports.begin(); 
02012     std::vector<OutPortBase*>::iterator it_end = m_outports.end(); 
02013 
02014     bool ret(true);
02015 
02016     while( it != it_end )
02017       {
02018         if (!((*it)->write()))
02019           {
02020             RTC_DEBUG(("The error occurred in writeAll()."));
02021             ret = false;
02022             if (!m_writeAllCompletion)
02023               return false;
02024           }
02025         ++it;
02026       }
02027     return ret;
02028   }
02029 
02054   void RTObject_impl::setReadAll(bool read, bool completion)
02055   {
02056     m_readAll = read;
02057     m_readAllCompletion = completion;
02058   }
02059 
02084   void RTObject_impl::setWriteAll(bool write, bool completion)
02085   {
02086     m_writeAll = write;
02087     m_writeAllCompletion = completion;
02088   }
02089 
02097   void RTObject_impl::finalizePorts()
02098   {
02099     RTC_TRACE(("finalizePorts()"));
02100     m_portAdmin.finalizePorts();
02101     m_inports.clear();
02102     m_outports.clear();
02103   }
02104 
02105   void RTObject_impl::finalizeContexts()
02106   {
02107     RTC_TRACE(("finalizeContexts()"));
02108     for (int i(0), len(m_eclist.size()); i < len; ++i)
02109       {
02110         m_eclist[i]->stop();
02111         try
02112           {
02113             PortableServer::ObjectId_var oid
02114               = m_pPOA->servant_to_id(m_eclist[i]);
02115             m_pPOA->deactivate_object(oid);
02116           }
02117         catch (PortableServer::POA::ServantNotActive &e)
02118           {
02119             RTC_ERROR(("%s", e._name()));
02120           }
02121         catch (PortableServer::POA::WrongPolicy &e)
02122           {
02123             RTC_ERROR(("%s", e._name()));
02124           }
02125         catch (...)
02126           {
02127             // never throws exception
02128             RTC_ERROR(("Unknown exception caught."));
02129           }
02130         delete m_eclist[i];
02131       }
02132     if (!m_eclist.empty())
02133       {
02134         m_eclist.clear();
02135       }
02136   }
02137   
02147   void RTObject_impl::
02148   addPreComponentActionListener(PreComponentActionListenerType listener_type,
02149                                 PreComponentActionListener* listener,
02150                                 bool autoclean)
02151   {
02152     m_actionListeners.
02153       preaction_[listener_type].addListener(listener, autoclean);
02154   }
02155   
02156   
02166   void RTObject_impl::
02167   removePreComponentActionListener(
02168                                    PreComponentActionListenerType listener_type,
02169                                    PreComponentActionListener* listener)
02170   {
02171     m_actionListeners.
02172       preaction_[listener_type].removeListener(listener);
02173   }
02174 
02175 
02185   void RTObject_impl::
02186   addPostComponentActionListener(
02187                                  PostComponentActionListenerType listener_type,
02188                                  PostComponentActionListener* listener,
02189                                  bool autoclean)
02190   {
02191     m_actionListeners.
02192       postaction_[listener_type].addListener(listener, autoclean);
02193   }
02194 
02195 
02205   void RTObject_impl::
02206   removePostComponentActionListener(
02207                                 PostComponentActionListenerType listener_type,
02208                                 PostComponentActionListener* listener)
02209   {
02210     m_actionListeners.
02211       postaction_[listener_type].removeListener(listener);
02212   }
02213 
02223   void RTObject_impl::
02224   addPortActionListener(PortActionListenerType listener_type,
02225                         PortActionListener* listener,
02226                         bool autoclean)
02227   {
02228     m_actionListeners.
02229       portaction_[listener_type].addListener(listener, autoclean);
02230   }
02231 
02232 
02242   void RTObject_impl::
02243   removePortActionListener(PortActionListenerType listener_type,
02244                            PortActionListener* listener)
02245   {
02246     m_actionListeners.
02247       portaction_[listener_type].removeListener(listener);
02248   }
02249 
02250 
02260   void RTObject_impl::
02261   addExecutionContextActionListener(ECActionListenerType listener_type,
02262                                     ECActionListener* listener,
02263                                     bool autoclean)
02264   {
02265     m_actionListeners.
02266       ecaction_[listener_type].addListener(listener, autoclean);
02267   }
02268 
02269 
02279   void RTObject_impl::
02280   removeExecutionContextActionListener(ECActionListenerType listener_type,
02281                                        ECActionListener* listener)
02282   {
02283     m_actionListeners.
02284       ecaction_[listener_type].removeListener(listener);
02285   }
02286 
02294   void RTObject_impl::
02295   addPortConnectListener(PortConnectListenerType listener_type,
02296                          PortConnectListener* listener,
02297                          bool autoclean)
02298   {
02299     m_portconnListeners.
02300       portconnect_[listener_type].addListener(listener, autoclean);
02301   }
02302 
02310   void RTObject_impl::
02311   removePortConnectListener(PortConnectListenerType listener_type,
02312                             PortConnectListener* listener)
02313   {
02314     m_portconnListeners.
02315       portconnect_[listener_type].removeListener(listener);
02316   }
02317 
02325   void RTObject_impl::
02326   addPortConnectRetListener(PortConnectRetListenerType listener_type,
02327                             PortConnectRetListener* listener,
02328                             bool autoclean)
02329   {
02330     m_portconnListeners.
02331       portconnret_[listener_type].addListener(listener, autoclean);
02332   }
02333 
02341   void RTObject_impl::
02342   removePortConnectRetListener(PortConnectRetListenerType listener_type,
02343                                PortConnectRetListener* listener)
02344   {
02345     m_portconnListeners.
02346       portconnret_[listener_type].removeListener(listener);
02347   }
02348 
02356   void RTObject_impl::
02357   addConfigurationParamListener(ConfigurationParamListenerType type,
02358                                 ConfigurationParamListener* listener,
02359                                 bool autoclean)
02360   {
02361     m_configsets.addConfigurationParamListener(type, listener, autoclean);
02362   }
02363 
02371   void RTObject_impl::
02372   removeConfigurationParamListener(ConfigurationParamListenerType type,
02373                                    ConfigurationParamListener* listener)
02374   {
02375     m_configsets.removeConfigurationParamListener(type, listener);
02376   }
02377 
02385   void RTObject_impl::
02386   addConfigurationSetListener(ConfigurationSetListenerType type,
02387                               ConfigurationSetListener* listener,
02388                               bool autoclean)
02389   {
02390     m_configsets.addConfigurationSetListener(type, listener, autoclean);
02391   }
02392   
02400   void RTObject_impl::
02401   removeConfigurationSetListener(ConfigurationSetListenerType type,
02402                                  ConfigurationSetListener* listener)
02403   {
02404     m_configsets.removeConfigurationSetListener(type, listener);
02405   }
02406   
02414   void RTObject_impl::
02415   addConfigurationSetNameListener(ConfigurationSetNameListenerType type,
02416                                   ConfigurationSetNameListener* listener,
02417                                   bool autoclean)
02418   {
02419     m_configsets.addConfigurationSetNameListener(type, listener, autoclean);
02420   }
02421   
02429   void RTObject_impl::
02430   removeConfigurationSetNameListener(ConfigurationSetNameListenerType type,
02431                                      ConfigurationSetNameListener* listener)
02432   {
02433     m_configsets.removeConfigurationSetNameListener(type, listener);
02434   }
02435   
02436   
02444   void RTObject_impl::shutdown()
02445   {
02446     RTC_TRACE(("shutdown()"));
02447     try
02448       {
02449         finalizePorts();
02450         finalizeContexts();
02451         PortableServer::ObjectId_var oid1;
02452         oid1 = m_pPOA->servant_to_id(m_pSdoConfigImpl);
02453         PortableServer::ObjectId_var oid2;
02454         oid2 = m_pPOA->servant_to_id(this);
02455         m_pPOA->deactivate_object(oid1);
02456         m_pPOA->deactivate_object(oid2);
02457       }
02458     catch (PortableServer::POA::ServantNotActive &e)
02459       {
02460         RTC_ERROR(("%s", e._name()));
02461       }
02462     catch (PortableServer::POA::WrongPolicy &e)
02463       {
02464         RTC_ERROR(("%s", e._name()));
02465       }
02466     catch (...)
02467       {
02468         // never throws exception
02469         RTC_ERROR(("Unknown exception caught."));
02470       }
02471     
02472     if (m_pManager != NULL)
02473       {
02474         RTC_DEBUG(("Cleanup on Manager"));
02475         m_pManager->notifyFinalized(this);
02476       }
02477   }
02478 
02479 
02480 
02481 }


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