RTObjectServant.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
19 #include <assert.h>
20 #include <rtc/IRTObject.h>
21 #include "RTObjectServant.h"
22 
23 namespace RTC
24 {
25 namespace CORBA
26 {
28  : doil::CORBA::CORBAServantBase(impl)
29  {
30  m_impl = dynamic_cast<IRTObject*>(impl);
31  if (m_impl == NULL) throw std::bad_alloc();
32  m_impl->incRef();
33  }
34 
36  {
37  m_impl->decRef();
38  }
39 
40  //============================================================
41  // RTC::LightweightRTObject
42  //============================================================
44  throw (::CORBA::SystemException)
45  {
46  return ret(m_impl->initialize());
47  }
48 
50  throw (::CORBA::SystemException)
51  {
52  return ret(m_impl->finalize());
53  }
54 
56  throw (::CORBA::SystemException)
57  {
58  return ret(m_impl->exit());
59  }
60 
61  ::CORBA::Boolean
62  RTObjectServant::is_alive(ExecutionContext_ptr exec_context)
63  throw (::CORBA::SystemException)
64  {
65  // ExecutionContext_ptr -> ExecutionContextInterface
66  // CORBA::Object -> doil::ImplBase
67  ImplBase* obj;
68  obj = doil::CORBA::CORBAManager::instance().toImpl(exec_context);
69 
70  IExecutionContext* ec;
71  if (obj == NULL)
72  {
73  ec = new ExecutioinContextAdapter(exec_context);
74  }
75  else
76  {
77  ec = dyanmic_cast<IExecutionContext>(obj);
78  }
79  if (ec == NULL) return false;
80 
81  return m_impl->is_alive(ec);
82  }
83 
91  ExecutionContext_ptr
93  throw (::CORBA::SystemException)
94  {
95  ExecutionContextInterface& ecif(m_impl->get_context(ec_id));
96 
97  return Local2Corba(ecif);
98  }
99 
108  throw (::CORBA::SystemException)
109  {
110  ExecutionContextInterfaceList& eclist(m_impl->get_owned_contexts());
111 
112  ExecutionContextList_var retval;
113  retval = new ExecutionContextList();
114  CORBA_SeqUtil::for_each(eclist, ec_copy(retval));
115 
116  return retval._retn();
117  }
118 
127  throw (::CORBA::SystemException)
128  {
129  ExecutionContextInterfaceList& eclist(m_impl->get_participating_contexts());
130  ExecutionContextList_var retval;
131  retval = new ExecutionContextList();
132  CORBA_SeqUtil::for_each(eclist, ec_copy(retval));
133 
134  return retval._retn();
135  }
136 
137 
146  RTObjectServant::get_context_handle(ExecutionContext_ptr cxt)
147  throw (::CORBA::SystemException)
148  {
149  ExecutionContextInterface ecif(Corba2Local(cxt));
150  return m_impl->get_context_handle(ecif);
151  }
152 
153 
161  UniqueId RTObjectServant::attach_context(ExecutionContext_ptr exec_context)
162  throw (::CORBA::SystemException)
163  {
164  return m_impl->attach_context(ExecutionContext_ptr exec_context);
165  }
166 
175  throw (::CORBA::SystemException)
176  {
177  return m_impl->detach_context(UniqueId ec_id);
178  }
179 
180  //============================================================
181  // RTC::RTObject
182  //============================================================
183 
191  ComponentProfile* RTObjectServant::get_component_profile()
192  throw (::CORBA::SystemException)
193  {
194  return m_impl->RTObject;
195  }
196 
205  throw (::CORBA::SystemException)
206  {
207  return m_impl->get_ports();
208  }
209 
210  //============================================================
211  // RTC::ComponentAction
212  //============================================================
221  throw (::CORBA::SystemException)
222  {
223  return ret(m_impl->on_initialize());
224  }
225 
234  throw (::CORBA::SystemException)
235  {
236  return ret(m_impl->on_finalize());
237  }
238 
247  throw (::CORBA::SystemException)
248  {
249  return ret(m_impl->on_startup(UniqueId ec_id));
250  }
251 
260  throw (::CORBA::SystemException)
261  {
262  return ret(m_impl->on_shutdown(UniqueId ec_id));
263  }
264 
273  throw (::CORBA::SystemException)
274  {
275  return ret(m_impl->on_activated(UniqueId ec_id));
276  }
277 
286  throw (::CORBA::SystemException)
287  {
288  return ret(m_impl->on_deactivated(UniqueId ec_id));
289  }
290 
299  throw (::CORBA::SystemException)
300  {
301  return ret(m_impl->on_aborting(UniqueId ec_id));
302  }
303 
312  throw (::CORBA::SystemException)
313  {
314  return ret(m_impl->on_error(UniqueId ec_id));
315  }
316 
325  throw (::CORBA::SystemException)
326  {
327  return ret(m_impl->on_reset(UniqueId ec_id));
328  }
329 
338  ReturnCode_t RTObjectServant::on_execute(UniqueId ec_id)
339  throw (::CORBA::SystemException)
340  {
341  return ret(m_impl->on_execute(UniqueId ec_id));
342  }
343 
352  ReturnCode_t RTObjectServant::on_state_update(UniqueId ec_id)
353  throw (::CORBA::SystemException)
354  {
355  return ret(m_impl->on_state_update(UniqueId ec_id));
356  }
357 
365  ReturnCode_t RTObjectServant::on_rate_changed(UniqueId ec_id)
366  throw (::CORBA::SystemException)
367  {
368  return ret(m_impl->on_rate_changed(UniqueId ec_id));
369  }
370 
371  //============================================================
372  // SDO interfaces
373  //============================================================
381  SDOPackage::OrganizationList* RTObjectServant::get_owned_organizations()
382  throw (::CORBA::SystemException, SDOPackage::NotAvailable)
383  {
384 
385  }
386 
387  // SDOPackage::SDO
396  throw (::CORBA::SystemException,
397  SDOPackage::NotAvailable, SDOPackage::InternalError)
398  {
399 
400  }
401 
410  throw (::CORBA::SystemException,
411  SDOPackage::NotAvailable, SDOPackage::InternalError)
412  {
413 
414  }
415 
423  SDOPackage::DeviceProfile* RTObjectServant::get_device_profile()
424  throw (::CORBA::SystemException,
425  SDOPackage::NotAvailable, SDOPackage::InternalError)
426  {
427  try
428  {
429  SDOPackage::DeviceProfile_var dprofile;
430  dprofile = new SDOPackage::DeviceProfile();
431  dprofile->device_type = ::CORBA::string_dup(m_profile.category);
432  dprofile->manufacturer = ::CORBA::string_dup(m_profile.vendor);
433  dprofile->model = ::CORBA::string_dup(m_profile.type_name);
434  dprofile->version = ::CORBA::string_dup(m_profile.version);
435  dprofile->properties = m_profile.properties;
436  return dprofile._retn();
437  }
438  catch (...)
439  {
440  throw SDOPackage::InternalError("get_device_profile()");
441  }
442  return new SDOPackage::DeviceProfile();
443  }
444 
452  SDOPackage::ServiceProfileList* RTObjectServant::get_service_profiles()
453  throw (::CORBA::SystemException,
454  SDOPackage::NotAvailable, SDOPackage::InternalError)
455  {
456  try
457  {
458  SDOPackage::ServiceProfileList_var sprofiles;
459  sprofiles = new SDOPackage::ServiceProfileList(m_sdoSvcProfiles);
460  return sprofiles._retn();
461  }
462  catch (...)
463  {
464  throw SDOPackage::InternalError("get_service_profiles()");
465  }
466  return new SDOPackage::ServiceProfileList();
467  }
468 
476  SDOPackage::ServiceProfile*
478  throw (::CORBA::SystemException,
479  SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
480  SDOPackage::InternalError)
481  {
482  if (!id)
483  throw SDOPackage::InvalidParameter("get_service_profile(): Empty name.");
484 
485  try
486  {
487  ::CORBA::Long index;
488  index = CORBA_SeqUtil::find(m_sdoSvcProfiles, svc_name(id));
489 
490  SDOPackage::ServiceProfile_var sprofile;
491  sprofile = new SDOPackage::ServiceProfile(m_sdoSvcProfiles[index]);
492  return sprofile._retn();
493  }
494  catch (...)
495  {
496  throw SDOPackage::InternalError("get_service_profile()");
497  }
498  return new SDOPackage::ServiceProfile();
499  }
500 
508  SDOPackage::SDOService_ptr RTObjectServant::get_sdo_service(const char* id)
509  throw (::CORBA::SystemException,
510  SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
511  SDOPackage::InternalError)
512  {
513  if (!id)
514  throw SDOPackage::InvalidParameter("get_service(): Empty name.");
515 
516  try
517  {
518  ::CORBA::Long index;
519  index = CORBA_SeqUtil::find(m_sdoSvcProfiles, svc_name(id));
520 
521  SDOPackage::SDOService_var service;
522  service = m_sdoSvcProfiles[index].service;
523  return service._retn();
524  }
525  catch (...)
526  {
527  throw SDOPackage::InternalError("get_service()");
528  }
529  return SDOPackage::SDOService::_nil();
530  }
531 
539  SDOPackage::Configuration_ptr RTObjectServant::get_configuration()
540  throw (::CORBA::SystemException,
541  SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
542  SDOPackage::InternalError)
543  {
544  if (m_pSdoConfig == NULL)
545  throw SDOPackage::InterfaceNotImplemented();
546  try
547  {
548  SDOPackage::Configuration_var config;
549  config = m_pSdoConfig;
550  return config._retn();
551  }
552  catch (...)
553  {
554  SDOPackage::InternalError("get_configuration()");
555  }
556  return SDOPackage::Configuration::_nil();
557  }
558 
566  SDOPackage::Monitoring_ptr RTObjectServant::get_monitoring()
567  throw (::CORBA::SystemException,
568  SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
569  SDOPackage::InternalError)
570  {
571  throw SDOPackage::InterfaceNotImplemented();
572  return SDOPackage::Monitoring::_nil();
573  }
574 
582  SDOPackage::OrganizationList* RTObjectServant::get_organizations()
583  throw (::CORBA::SystemException,
584  SDOPackage::NotAvailable, SDOPackage::InternalError)
585  {
586  try
587  {
588  SDOPackage::OrganizationList_var org;
589  org = new SDOPackage::OrganizationList(m_sdoOrganizations);
590  return org._retn();
591  }
592  catch (...)
593  {
594  throw SDOPackage::InternalError("get_organizations()");
595  }
596  return new SDOPackage::OrganizationList(0);
597  }
598 
607  throw (::CORBA::SystemException,
608  SDOPackage::NotAvailable, SDOPackage::InternalError)
609  {
610  try
611  {
612  NVList_var status;
613  status = new NVList(m_sdoStatus);
614  return status._retn();
615  }
616  catch (...)
617  {
618  SDOPackage::InternalError("get_status_list()");
619  }
620  return new SDOPackage::NVList(0);
621  }
622 
630  ::CORBA::Any* RTObjectServant::get_status(const char* name)
631  throw (::CORBA::SystemException,
632  SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
633  SDOPackage::InternalError)
634  {
635  ::CORBA::Long index;
636  index = CORBA_SeqUtil::find(m_sdoStatus, nv_name(name));
637  if (index < 0)
638  throw SDOPackage::InvalidParameter("get_status(): Not found");
639  try
640  {
641  ::CORBA::Any_var status;
642  status = new ::CORBA::Any(m_sdoStatus[index].value);
643  return status._retn();
644  }
645  catch (...)
646  {
647  throw SDOPackage::InternalError("get_status()");
648  }
649  return new ::CORBA::Any();
650  }
651 
652  //============================================================
653  // Local methods
654  //============================================================
662  void RTObjectServant::setInstanceName(const char* instance_name)
663  {
664  m_properties["instance_name"] = instance_name;
665  m_profile.instance_name = m_properties["instance_name"].c_str();
666  }
667 
675  std::vector<std::string> RTObjectServant::getNamingNames()
676  {
677  return split(m_properties["naming.names"], ",");
678  }
679 
687  void RTObjectServant::setObjRef(const RTObject_ptr rtobj)
688  {
689  m_objref = rtobj;
690  }
691 
699  RTObject_ptr RTObjectServant::getObjRef() const
700  {
701  return ret(RTC::RTObject::_duplicate(m_objref));
702  }
703 
711  void RTObjectServant::setProperties(const Properties& prop)
712  {
713  m_properties << prop;
714  m_profile.instance_name = m_properties["instance_name"].c_str();
715  m_profile.type_name = m_properties["type_name"].c_str();
716  m_profile.description = m_properties["description"].c_str();
717  m_profile.version = m_properties["version"].c_str();
718  m_profile.vendor = m_properties["vendor"].c_str();
719  m_profile.category = m_properties["category"].c_str();
720  }
721 
729  Properties& RTObjectServant::getProperties()
730  {
731  return m_properties;
732  }
733 
741  void RTObjectServant::updateParameters(const char* config_set)
742  {
743  m_configsets.update(config_set);
744  return;
745  }
746 
754  void RTObjectServant::registerPort(PortBase& port)
755  {
756  m_portAdmin.registerPort(port);
757  port.setOwner(this->getObjRef());
758  return;
759  }
760 
768  void RTObjectServant::deletePort(PortBase& port)
769  {
770  m_portAdmin.deletePort(port);
771  return;
772  }
773 
781  void RTObjectServant::deletePortByName(const char* port_name)
782  {
783  m_portAdmin.deletePortByName(port_name);
784  return;
785  }
786 
794  void RTObjectServant::finalizePorts()
795  {
796  m_portAdmin.finalizePorts();
797  }
798 
806  void RTObjectServant::shutdown()
807  {
808  try
809  {
810  finalizePorts();
811  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(m_pSdoConfigImpl));
812  m_pPOA->deactivate_object(*m_pPOA->servant_to_id(this));
813  }
814  catch (...)
815  {
816  ;
817  }
818 
819  if (m_pManager != NULL)
820  {
821  m_pManager->cleanupComponent(this);
822  }
823  }
824 };
virtual ReturnCode_t on_deactivated(EChandle exec_handle)
RTObjectServant(doil::ImplBase *impl)
virtual char * get_sdo_type()
EXECUTION_HANDLE_TYPE_NATIVE ExecutionContextHandle_t
Definition: IRTC.h:63
RT-Component.
virtual ::CORBA::Boolean is_alive(ExecutionContext_ptr exec_context)
virtual ReturnCode_t on_initialize()
virtual ReturnCode_t on_aborting(EChandle exec_handle)
virtual ReturnCode_t on_finalize()
std::vector< std::pair< std::string, std::string > > NVList
Definition: IRTC.h:67
RTC::Local::ReturnCode_t ReturnCode_t
virtual ReturnCode_t on_error(EChandle exec_handle)
virtual ReturnCode_t finalize()
ReturnCode_t detach_context(EChandle exec_handle)
virtual ImplBase * toImpl(doil::ServantBase *servant)
Getting impl object by servant.
static CORBAManager & instance()
getting instance
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
virtual ReturnCode_t exit()
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:341
virtual ExecutionContextList * get_owned_contexts()
virtual SDOPackage::SDOService_ptr get_sdo_service(const char *id)
virtual ReturnCode_t on_reset(EChandle exec_handle)
::RTC::Local::IRTObject IRTObject
virtual SDOPackage::ServiceProfile * get_service_profile(const char *id)
virtual SDOPackage::OrganizationList * get_owned_organizations()
SDO Package.
virtual SDOPackage::ServiceProfileList * get_service_profiles()
std::vector< ExecutionContext * > ExecutionContextList
Definition: IRTC.h:69
ExecutionContextHandle_t UniqueId
virtual ExecutionContext_ptr get_context(EChandle exec_handle)
virtual ExecutionContextHandle_t get_context_handle(ExecutionContext_ptr cxt)
string service
Definition: README_gen.py:139
virtual SDOPackage::Monitoring_ptr get_monitoring()
virtual SDOPackage::DeviceProfile * get_device_profile()
RTObject corba servant class.
virtual SDOPackage::OrganizationList * get_organizations()
CORBA::Long find(const CorbaSequence &seq, Functor f)
Return the index of CORBA sequence element that functor matches.
list index
Definition: rtimages.py:10
virtual ::CORBA::Any * get_status(const char *name)
virtual ExecutionContextList * get_participating_contexts()
virtual char * get_sdo_id()
virtual ReturnCode_t initialize()
prop
Organization::get_organization_property ();.
virtual ReturnCode_t on_activated(EChandle exec_handle)
EChandle attach_context(ExecutionContext_ptr exec_context)
std::vector< IPortService * > PortServiceList
Definition: IPortService.h:39
virtual ComponentProfile * get_component_profile()
IRTObject interface class.
virtual SDOPackage::NVList * get_status_list()
virtual PortServiceList * get_ports()
virtual SDOPackage::Configuration_ptr get_configuration()
Functor for_each(CorbaSequence &seq, Functor f)
Apply the functor to all CORBA sequence elements.
Definition: CORBA_SeqUtil.h:98
virtual ReturnCode_t on_startup(EChandle exec_handle)
virtual ReturnCode_t on_shutdown(EChandle exec_handle)


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:26:00