RTObjectServant.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00019 #include <assert.h>
00020 #include <rtc/IRTObject.h>
00021 #include "RTObjectServant.h"
00022 
00023 namespace RTC
00024 {
00025 namespace CORBA
00026 {
00027   RTObjectServant::RTObjectServant(doil::ImplBase* impl)
00028     : doil::CORBA::CORBAServantBase(impl)
00029   {
00030     m_impl = dynamic_cast<IRTObject*>(impl);
00031     if (m_impl == NULL) throw std::bad_alloc();
00032     m_impl->incRef();
00033   }
00034   
00035   RTObjectServant::~RTObjectServant()
00036   {
00037     m_impl->decRef();
00038   }
00039 
00040   //============================================================
00041   // RTC::LightweightRTObject
00042   //============================================================
00043   ReturnCode_t RTObjectServant::initialize()
00044     throw (::CORBA::SystemException)
00045   {
00046     return ret(m_impl->initialize());
00047   }
00048   
00049   ReturnCode_t RTObjectServant::finalize()
00050     throw (::CORBA::SystemException)
00051   {
00052     return ret(m_impl->finalize());
00053   }
00054 
00055   ReturnCode_t RTObjectServant::exit()
00056     throw (::CORBA::SystemException)
00057   {
00058     return ret(m_impl->exit());
00059   }
00060 
00061   ::CORBA::Boolean
00062   RTObjectServant::is_alive(ExecutionContext_ptr exec_context)
00063     throw (::CORBA::SystemException)
00064   {
00065     // ExecutionContext_ptr -> ExecutionContextInterface
00066     // CORBA::Object -> doil::ImplBase
00067     ImplBase* obj;
00068     obj = doil::CORBA::CORBAManager::instance().toImpl(exec_context);
00069 
00070     IExecutionContext* ec;
00071     if (obj == NULL)
00072       {
00073         ec = new ExecutioinContextAdapter(exec_context);
00074       }
00075     else
00076       {
00077         ec = dyanmic_cast<IExecutionContext>(obj);
00078       }
00079     if (ec == NULL) return false;
00080 
00081     return m_impl->is_alive(ec);
00082   }
00083   
00091   ExecutionContext_ptr
00092   RTObjectServant::get_context(ExecutionContextHandle_t ec_id)
00093     throw (::CORBA::SystemException)
00094   {
00095     ExecutionContextInterface& ecif(m_impl->get_context(ec_id));
00096 
00097     return Local2Corba(ecif);
00098   }
00099     
00107   ExecutionContextList* RTObjectServant::get_owned_contexts()
00108     throw (::CORBA::SystemException)
00109   {
00110     ExecutionContextInterfaceList& eclist(m_impl->get_owned_contexts());
00111 
00112     ExecutionContextList_var retval;
00113     retval = new ExecutionContextList();
00114     CORBA_SeqUtil::for_each(eclist, ec_copy(retval));
00115     
00116     return retval._retn();
00117   }
00118 
00126   ExecutionContextList* RTObjectServant::get_participating_contexts()
00127     throw (::CORBA::SystemException)
00128   {
00129     ExecutionContextInterfaceList& eclist(m_impl->get_participating_contexts());
00130     ExecutionContextList_var retval;
00131     retval = new ExecutionContextList();
00132     CORBA_SeqUtil::for_each(eclist, ec_copy(retval));
00133     
00134     return retval._retn();
00135   }
00136 
00137 
00145   ExecutionContextHandle_t
00146   RTObjectServant::get_context_handle(ExecutionContext_ptr cxt)
00147     throw (::CORBA::SystemException)
00148   {
00149     ExecutionContextInterface ecif(Corba2Local(cxt));
00150     return m_impl->get_context_handle(ecif);
00151   }
00152 
00153 
00161   UniqueId RTObjectServant::attach_context(ExecutionContext_ptr exec_context)
00162     throw (::CORBA::SystemException)
00163   {
00164     return m_impl->attach_context(ExecutionContext_ptr exec_context);
00165   }
00166   
00174   ReturnCode_t RTObjectServant::detach_context(UniqueId ec_id)
00175     throw (::CORBA::SystemException)
00176   {
00177     return m_impl->detach_context(UniqueId ec_id);
00178   }
00179   
00180   //============================================================
00181   // RTC::RTObject
00182   //============================================================
00183   
00191   ComponentProfile* RTObjectServant::get_component_profile()
00192     throw (::CORBA::SystemException)
00193   {
00194     return m_impl->RTObject;
00195   }
00196   
00204   PortServiceList* RTObjectServant::get_ports()
00205     throw (::CORBA::SystemException)
00206   {
00207     return m_impl->get_ports();
00208   }
00209   
00210   //============================================================
00211   // RTC::ComponentAction
00212   //============================================================
00220   ReturnCode_t RTObjectServant::on_initialize()
00221     throw (::CORBA::SystemException)
00222   {
00223     return ret(m_impl->on_initialize());
00224   }
00225   
00233   ReturnCode_t RTObjectServant::on_finalize()
00234     throw (::CORBA::SystemException)
00235   {
00236     return ret(m_impl->on_finalize());
00237   }
00238   
00246   ReturnCode_t RTObjectServant::on_startup(UniqueId ec_id)
00247     throw (::CORBA::SystemException)
00248   {
00249     return ret(m_impl->on_startup(UniqueId ec_id));
00250   }
00251   
00259   ReturnCode_t RTObjectServant::on_shutdown(UniqueId ec_id)
00260     throw (::CORBA::SystemException)
00261   {
00262     return ret(m_impl->on_shutdown(UniqueId ec_id));
00263   }
00264   
00272   ReturnCode_t RTObjectServant::on_activated(UniqueId ec_id)
00273     throw (::CORBA::SystemException)
00274   {
00275     return ret(m_impl->on_activated(UniqueId ec_id));
00276   }
00277   
00285   ReturnCode_t RTObjectServant::on_deactivated(UniqueId ec_id)
00286     throw (::CORBA::SystemException)
00287   {
00288     return ret(m_impl->on_deactivated(UniqueId ec_id));
00289   }
00290   
00298   ReturnCode_t RTObjectServant::on_aborting(UniqueId ec_id)
00299     throw (::CORBA::SystemException)
00300   {
00301     return ret(m_impl->on_aborting(UniqueId ec_id));
00302   }
00303   
00311   ReturnCode_t RTObjectServant::on_error(UniqueId ec_id)
00312     throw (::CORBA::SystemException)
00313   {
00314     return ret(m_impl->on_error(UniqueId ec_id));
00315   }
00316   
00324   ReturnCode_t RTObjectServant::on_reset(UniqueId ec_id)
00325     throw (::CORBA::SystemException)
00326   {
00327     return ret(m_impl->on_reset(UniqueId ec_id));
00328   }
00329   
00338   ReturnCode_t RTObjectServant::on_execute(UniqueId ec_id)
00339     throw (::CORBA::SystemException)
00340   {
00341     return ret(m_impl->on_execute(UniqueId ec_id));
00342   }
00343   
00352   ReturnCode_t RTObjectServant::on_state_update(UniqueId ec_id)
00353     throw (::CORBA::SystemException)
00354   {
00355     return ret(m_impl->on_state_update(UniqueId ec_id));
00356   }
00357   
00365   ReturnCode_t RTObjectServant::on_rate_changed(UniqueId ec_id)
00366     throw (::CORBA::SystemException)
00367   {
00368     return ret(m_impl->on_rate_changed(UniqueId ec_id));
00369   }
00370   
00371   //============================================================
00372   // SDO interfaces
00373   //============================================================
00381   SDOPackage::OrganizationList* RTObjectServant::get_owned_organizations()
00382     throw (::CORBA::SystemException, SDOPackage::NotAvailable)
00383   {
00384 
00385   }
00386   
00387   // SDOPackage::SDO
00395   char* RTObjectServant::get_sdo_id()
00396     throw (::CORBA::SystemException, 
00397            SDOPackage::NotAvailable, SDOPackage::InternalError)
00398   {
00399 
00400   }
00401   
00409   char* RTObjectServant::get_sdo_type()
00410     throw (::CORBA::SystemException, 
00411            SDOPackage::NotAvailable, SDOPackage::InternalError)
00412   {
00413 
00414   }
00415   
00423   SDOPackage::DeviceProfile* RTObjectServant::get_device_profile()
00424     throw (::CORBA::SystemException, 
00425            SDOPackage::NotAvailable, SDOPackage::InternalError)
00426   {
00427     try
00428       {
00429         SDOPackage::DeviceProfile_var dprofile;
00430         dprofile = new SDOPackage::DeviceProfile();
00431         dprofile->device_type  = ::CORBA::string_dup(m_profile.category);
00432         dprofile->manufacturer = ::CORBA::string_dup(m_profile.vendor);
00433         dprofile->model        = ::CORBA::string_dup(m_profile.type_name);
00434         dprofile->version      = ::CORBA::string_dup(m_profile.version);
00435         dprofile->properties   = m_profile.properties;
00436         return dprofile._retn();
00437       }
00438     catch (...)
00439       {
00440         throw SDOPackage::InternalError("get_device_profile()");
00441       }
00442     return new SDOPackage::DeviceProfile();
00443   }
00444   
00452   SDOPackage::ServiceProfileList* RTObjectServant::get_service_profiles()
00453     throw (::CORBA::SystemException, 
00454            SDOPackage::NotAvailable, SDOPackage::InternalError)
00455   {
00456     try
00457       {
00458         SDOPackage::ServiceProfileList_var sprofiles;
00459         sprofiles = new SDOPackage::ServiceProfileList(m_sdoSvcProfiles);
00460         return sprofiles._retn();
00461       }
00462     catch (...)
00463       {
00464         throw SDOPackage::InternalError("get_service_profiles()");
00465       }
00466     return new SDOPackage::ServiceProfileList();
00467   }
00468   
00476   SDOPackage::ServiceProfile*
00477   RTObjectServant::get_service_profile(const char* id)
00478     throw (::CORBA::SystemException, 
00479            SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
00480            SDOPackage::InternalError)
00481   {
00482     if (!id)
00483       throw SDOPackage::InvalidParameter("get_service_profile(): Empty name.");
00484     
00485     try
00486       {
00487         ::CORBA::Long index;
00488         index = CORBA_SeqUtil::find(m_sdoSvcProfiles, svc_name(id));
00489         
00490         SDOPackage::ServiceProfile_var sprofile;
00491         sprofile = new SDOPackage::ServiceProfile(m_sdoSvcProfiles[index]);
00492         return sprofile._retn();
00493       }
00494     catch (...)
00495       {
00496         throw SDOPackage::InternalError("get_service_profile()");
00497       }
00498     return new SDOPackage::ServiceProfile();
00499   }
00500   
00508   SDOPackage::SDOService_ptr RTObjectServant::get_sdo_service(const char* id)
00509     throw (::CORBA::SystemException, 
00510            SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
00511            SDOPackage::InternalError)
00512   {
00513     if (!id)
00514       throw SDOPackage::InvalidParameter("get_service(): Empty name.");
00515     
00516     try
00517       {
00518         ::CORBA::Long index;
00519         index = CORBA_SeqUtil::find(m_sdoSvcProfiles, svc_name(id));
00520         
00521         SDOPackage::SDOService_var service;
00522         service = m_sdoSvcProfiles[index].service;
00523         return service._retn();
00524       }
00525     catch (...)
00526       {
00527         throw SDOPackage::InternalError("get_service()");
00528       }
00529     return SDOPackage::SDOService::_nil();
00530   }
00531   
00539   SDOPackage::Configuration_ptr RTObjectServant::get_configuration()
00540     throw (::CORBA::SystemException, 
00541            SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
00542            SDOPackage::InternalError)
00543   {
00544     if (m_pSdoConfig == NULL)
00545       throw SDOPackage::InterfaceNotImplemented();
00546     try
00547       {
00548         SDOPackage::Configuration_var config;
00549         config = m_pSdoConfig;
00550         return config._retn();
00551       }
00552     catch (...)
00553       {
00554         SDOPackage::InternalError("get_configuration()");
00555       }
00556     return SDOPackage::Configuration::_nil();
00557   }
00558   
00566   SDOPackage::Monitoring_ptr RTObjectServant::get_monitoring()
00567     throw (::CORBA::SystemException, 
00568            SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
00569            SDOPackage::InternalError)
00570   {
00571     throw SDOPackage::InterfaceNotImplemented();
00572     return SDOPackage::Monitoring::_nil();
00573   }
00574   
00582   SDOPackage::OrganizationList* RTObjectServant::get_organizations()
00583     throw (::CORBA::SystemException, 
00584            SDOPackage::NotAvailable, SDOPackage::InternalError)
00585   {
00586     try
00587       {
00588         SDOPackage::OrganizationList_var org;
00589         org = new SDOPackage::OrganizationList(m_sdoOrganizations);
00590         return org._retn();
00591       }
00592     catch (...)
00593       {
00594         throw SDOPackage::InternalError("get_organizations()");
00595       }
00596     return new SDOPackage::OrganizationList(0);
00597   }
00598   
00606   SDOPackage::NVList* RTObjectServant::get_status_list()
00607     throw (::CORBA::SystemException, 
00608            SDOPackage::NotAvailable, SDOPackage::InternalError)
00609   {
00610     try
00611       {
00612         NVList_var status;
00613         status = new NVList(m_sdoStatus);
00614         return status._retn();
00615       }
00616     catch (...)
00617       {
00618         SDOPackage::InternalError("get_status_list()");
00619       }
00620     return new SDOPackage::NVList(0);
00621   }
00622   
00630   ::CORBA::Any* RTObjectServant::get_status(const char* name)
00631     throw (::CORBA::SystemException, 
00632            SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
00633            SDOPackage::InternalError)
00634   {
00635     ::CORBA::Long index;
00636     index = CORBA_SeqUtil::find(m_sdoStatus, nv_name(name));
00637     if (index < 0)
00638       throw SDOPackage::InvalidParameter("get_status(): Not found");
00639     try
00640       {
00641         ::CORBA::Any_var status;
00642         status = new ::CORBA::Any(m_sdoStatus[index].value);
00643         return status._retn();
00644       }
00645     catch (...)
00646       {
00647         throw SDOPackage::InternalError("get_status()");
00648       }
00649     return new ::CORBA::Any();
00650   }
00651   
00652   //============================================================
00653   // Local methods
00654   //============================================================
00662   void RTObjectServant::setInstanceName(const char* instance_name)
00663   {
00664     m_properties["instance_name"] = instance_name;
00665     m_profile.instance_name = m_properties["instance_name"].c_str();
00666   }
00667   
00675   std::vector<std::string> RTObjectServant::getNamingNames()
00676   {
00677     return split(m_properties["naming.names"], ",");
00678   }
00679   
00687   void RTObjectServant::setObjRef(const RTObject_ptr rtobj)
00688   {
00689     m_objref = rtobj;
00690   }
00691   
00699   RTObject_ptr RTObjectServant::getObjRef() const
00700   {
00701     return ret(RTC::RTObject::_duplicate(m_objref));
00702   }
00703   
00711   void RTObjectServant::setProperties(const Properties& prop)
00712   {
00713     m_properties << prop;
00714     m_profile.instance_name = m_properties["instance_name"].c_str();
00715     m_profile.type_name     = m_properties["type_name"].c_str();
00716     m_profile.description   = m_properties["description"].c_str();
00717     m_profile.version       = m_properties["version"].c_str();
00718     m_profile.vendor        = m_properties["vendor"].c_str();
00719     m_profile.category      = m_properties["category"].c_str();
00720   }
00721   
00729   Properties& RTObjectServant::getProperties()
00730   {
00731     return m_properties;
00732   }
00733   
00741   void RTObjectServant::updateParameters(const char* config_set)
00742   {
00743     m_configsets.update(config_set);
00744     return;
00745   }
00746   
00754   void RTObjectServant::registerPort(PortBase& port)
00755   {
00756     m_portAdmin.registerPort(port);
00757     port.setOwner(this->getObjRef());
00758     return;
00759   }
00760   
00768   void RTObjectServant::deletePort(PortBase& port)
00769   {
00770     m_portAdmin.deletePort(port);
00771     return;
00772   }
00773   
00781   void RTObjectServant::deletePortByName(const char* port_name)
00782   {
00783     m_portAdmin.deletePortByName(port_name);
00784     return;
00785   }
00786   
00794   void RTObjectServant::finalizePorts()
00795   {
00796     m_portAdmin.finalizePorts();
00797   }
00798   
00806   void RTObjectServant::shutdown()
00807   {
00808     try
00809       {
00810         finalizePorts();
00811         m_pPOA->deactivate_object(*m_pPOA->servant_to_id(m_pSdoConfigImpl));
00812         m_pPOA->deactivate_object(*m_pPOA->servant_to_id(this));
00813       }
00814     catch (...)
00815       {
00816         ;
00817       }
00818     
00819     if (m_pManager != NULL)
00820       {
00821         m_pManager->cleanupComponent(this);
00822       }
00823   }
00824 };


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