00001
00019 #ifndef RTObject_h
00020 #define RTObject_h
00021
00022
00023 #include <coil/Properties.h>
00024
00025 #include <rtm/RTC.h>
00026 #include <rtm/idl/RTCSkel.h>
00027 #include <rtm/idl/OpenRTMSkel.h>
00028 #include <rtm/PortBase.h>
00029 #include <rtm/PortAdmin.h>
00030 #include <rtm/InPortBase.h>
00031 #include <rtm/OutPortBase.h>
00032
00033
00034 #include <rtm/ConfigAdmin.h>
00035 #include <rtm/SystemLogger.h>
00036
00037 #define ECOTHER_OFFSET 1000
00038
00039 namespace SDOPackage
00040 {
00041 class Configuration_impl;
00042 };
00043
00044 #ifdef WIN32
00045 #pragma warning( disable : 4290 )
00046 #endif
00047
00048 namespace RTC
00049 {
00050 class Manager;
00051 class ExecutionContextBase;
00052 typedef ExecutionContextHandle_t UniqueId;
00053
00088 class RTObject_impl
00089 : public virtual POA_OpenRTM::DataFlowComponent,
00090 public virtual PortableServer::RefCountServantBase
00091 {
00092 public:
00111 RTObject_impl(Manager* manager);
00112
00133 RTObject_impl(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
00134
00146 virtual ~RTObject_impl(void);
00147
00148 protected:
00149
00150
00151
00179
00180
00181 virtual ReturnCode_t onInitialize();
00182
00210
00211
00212 virtual ReturnCode_t onFinalize();
00213
00245
00246
00247 virtual ReturnCode_t onStartup(RTC::UniqueId exec_handle);
00248
00280
00281
00282 virtual ReturnCode_t onShutdown(RTC::UniqueId exec_handle);
00283
00315
00316
00317 virtual ReturnCode_t onActivated(RTC::UniqueId exec_handle);
00318
00350
00351
00352 virtual ReturnCode_t onDeactivated(RTC::UniqueId exec_handle);
00353
00389
00390
00391 virtual ReturnCode_t onExecute(RTC::UniqueId exec_handle);
00392
00424
00425
00426 virtual ReturnCode_t onAborting(RTC::UniqueId exec_handle);
00427
00458
00459
00460 virtual ReturnCode_t onError(RTC::UniqueId exec_handle);
00461
00492
00493
00494 virtual ReturnCode_t onReset(RTC::UniqueId exec_handle);
00495
00531
00532
00533 virtual ReturnCode_t onStateUpdate(RTC::UniqueId exec_handle);
00534
00570
00571
00572 virtual ReturnCode_t onRateChanged(RTC::UniqueId exec_handle);
00573
00574 public:
00575
00576
00577
00613 virtual ReturnCode_t initialize()
00614 throw (CORBA::SystemException);
00615
00660 virtual ReturnCode_t finalize()
00661 throw (CORBA::SystemException);
00662
00706 virtual ReturnCode_t exit()
00707 throw (CORBA::SystemException);
00708
00741 virtual CORBA::Boolean is_alive(ExecutionContext_ptr exec_context)
00742 throw (CORBA::SystemException);
00743
00771 virtual ExecutionContext_ptr get_context(UniqueId exec_handle)
00772 throw (CORBA::SystemException);
00773
00792 virtual ExecutionContextList* get_owned_contexts()
00793 throw (CORBA::SystemException);
00794
00813 virtual ExecutionContextList* get_participating_contexts()
00814 throw (CORBA::SystemException);
00815
00830 virtual ExecutionContextHandle_t
00831 get_context_handle(ExecutionContext_ptr cxt)
00832 throw (CORBA::SystemException);
00833
00864 UniqueId attach_context(ExecutionContext_ptr exec_context)
00865 throw (CORBA::SystemException);
00866
00867 UniqueId bindContext(ExecutionContext_ptr exec_context);
00868
00910 ReturnCode_t detach_context(UniqueId exec_handle)
00911 throw (CORBA::SystemException);
00912
00913
00914
00915
00935 virtual ComponentProfile* get_component_profile()
00936 throw (CORBA::SystemException);
00937
00957 virtual PortServiceList* get_ports()
00958 throw (CORBA::SystemException);
00959
00981
00982
00983
00984
00985
00986
01011 virtual ReturnCode_t on_initialize()
01012 throw (CORBA::SystemException);
01013
01038 virtual ReturnCode_t on_finalize()
01039 throw (CORBA::SystemException);
01040
01069 virtual ReturnCode_t on_startup(UniqueId exec_handle)
01070 throw (CORBA::SystemException);
01071
01100 virtual ReturnCode_t on_shutdown(UniqueId exec_handle)
01101 throw (CORBA::SystemException);
01102
01129 virtual ReturnCode_t on_activated(UniqueId exec_handle)
01130 throw (CORBA::SystemException);
01131
01159 virtual ReturnCode_t on_deactivated(UniqueId exec_handle)
01160 throw (CORBA::SystemException);
01161
01194 virtual ReturnCode_t on_aborting(UniqueId exec_handle)
01195 throw (CORBA::SystemException);
01196
01240 virtual ReturnCode_t on_error(UniqueId exec_handle)
01241 throw (CORBA::SystemException);
01242
01276 virtual ReturnCode_t on_reset(UniqueId exec_handle)
01277 throw (CORBA::SystemException);
01278
01279
01280
01281
01323 virtual ReturnCode_t on_execute(UniqueId exec_handle)
01324 throw (CORBA::SystemException);
01325
01369 virtual ReturnCode_t on_state_update(UniqueId exec_handle)
01370 throw (CORBA::SystemException);
01371
01408 virtual ReturnCode_t on_rate_changed(UniqueId exec_handle)
01409 throw (CORBA::SystemException);
01410
01411
01412
01413
01451 virtual SDOPackage::OrganizationList* get_owned_organizations()
01452 throw (CORBA::SystemException,
01453 SDOPackage::NotAvailable, SDOPackage::InternalError);
01454
01455
01456
01457
01491 virtual char* get_sdo_id()
01492 throw (CORBA::SystemException,
01493 SDOPackage::NotAvailable, SDOPackage::InternalError);
01494
01528 virtual char* get_sdo_type()
01529 throw (CORBA::SystemException,
01530 SDOPackage::NotAvailable, SDOPackage::InternalError);
01531
01568 virtual SDOPackage::DeviceProfile* get_device_profile()
01569 throw (CORBA::SystemException,
01570 SDOPackage::NotAvailable, SDOPackage::InternalError);
01571
01608 virtual SDOPackage::ServiceProfileList* get_service_profiles()
01609 throw (CORBA::SystemException,
01610 SDOPackage::NotAvailable, SDOPackage::InternalError);
01611
01653 virtual SDOPackage::ServiceProfile* get_service_profile(const char* id)
01654 throw (CORBA::SystemException,
01655 SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
01656 SDOPackage::InternalError);
01657
01705 virtual SDOPackage::SDOService_ptr get_sdo_service(const char* id)
01706 throw (CORBA::SystemException,
01707 SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
01708 SDOPackage::InternalError);
01709
01754 virtual SDOPackage::Configuration_ptr get_configuration()
01755 throw (CORBA::SystemException,
01756 SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
01757 SDOPackage::InternalError);
01758
01802 virtual SDOPackage::Monitoring_ptr get_monitoring()
01803 throw (CORBA::SystemException,
01804 SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
01805 SDOPackage::InternalError);
01806
01842 virtual SDOPackage::OrganizationList* get_organizations()
01843 throw (CORBA::SystemException,
01844 SDOPackage::NotAvailable, SDOPackage::InternalError);
01845
01877 virtual SDOPackage::NVList* get_status_list()
01878 throw (CORBA::SystemException,
01879 SDOPackage::NotAvailable, SDOPackage::InternalError);
01880
01917 virtual CORBA::Any* get_status(const char* name)
01918 throw (CORBA::SystemException,
01919 SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
01920 SDOPackage::InternalError);
01921
01922
01923
01924
01944 const char* getInstanceName()
01945 {
01946 RTC_TRACE(("getInstanceName()"));
01947 return m_profile.instance_name;
01948 }
01949
01969 void setInstanceName(const char* instance_name);
01970
01990 const char* getTypeName()
01991 {
01992 RTC_TRACE(("getTypeName()"));
01993 return m_profile.type_name;
01994 }
01995
02015 const char* getDescription()
02016 {
02017 RTC_TRACE(("getDescription()"));
02018 return m_profile.description;
02019 }
02020
02041 const char* getVersion()
02042 {
02043 RTC_TRACE(("getVersion()"));
02044 return m_profile.version;
02045 }
02046
02066 const char* getVendor()
02067 {
02068 RTC_TRACE(("getVendor()"));
02069 return m_profile.vendor;
02070 }
02071
02091 const char* getCategory()
02092 {
02093 RTC_TRACE(("getCategory()"));
02094 return m_profile.category;
02095 }
02096
02116 std::vector<std::string> getNamingNames();
02117
02137 void setObjRef(const RTObject_ptr rtobj);
02138
02158 RTObject_ptr getObjRef() const;
02159
02185 void setProperties(const coil::Properties& prop);
02186
02208 coil::Properties& getProperties();
02209
02242 template <typename VarType>
02243 bool bindParameter(const char* param_name, VarType& var,
02244 const char* def_val,
02245 bool (*trans)(VarType&, const char*) = coil::stringTo)
02246 {
02247 RTC_TRACE(("bindParameter(%s (default: %s))", param_name, def_val));
02248 m_configsets.bindParameter(param_name, var, def_val, trans);
02249 return true;
02250 }
02251
02273 void updateParameters(const char* config_set);
02274
02306 void registerPort(PortBase& port);
02307 void registerPort(PortService_ptr port);
02308
02335 void registerInPort(const char* name, InPortBase& inport);
02336
02363 void registerOutPort(const char* name, OutPortBase& outport);
02364
02384 void deletePort(PortBase& port);
02385 void deletePort(PortService_ptr port);
02386
02406 void deletePortByName(const char* port_name);
02407
02424 void finalizePorts();
02425 void finalizeContexts();
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438 protected:
02458 void shutdown();
02459
02460 protected:
02461 mutable Logger rtclog;
02469 Manager* m_pManager;
02470
02478 CORBA::ORB_var m_pORB;
02479
02487 PortableServer::POA_var m_pPOA;
02488
02489
02490
02491
02499 SDOPackage::OrganizationList m_sdoOwnedOrganizations;
02500
02508 SDOPackage::ServiceProfileList m_sdoSvcProfiles;
02509
02517 struct svc_name
02518 {
02519 svc_name (const char* id) : m_id(id) {};
02520 bool operator()(const SDOPackage::ServiceProfile& prof)
02521 {
02522 return m_id == std::string(prof.id);
02523 }
02524 std::string m_id;
02525 };
02526
02534 SDOPackage::Configuration_impl* m_pSdoConfigImpl;
02535
02543 SDOPackage::Configuration_var m_pSdoConfig;
02544
02552 SDOPackage::OrganizationList m_sdoOrganizations;
02553
02561 SDOPackage::NVList m_sdoStatus;
02562
02563
02564
02565
02573 ComponentProfile m_profile;
02574
02582 RTObject_ptr m_objref;
02583
02591 PortAdmin m_portAdmin;
02592
02600 ExecutionContextServiceList m_ecMine;
02601 std::vector<ExecutionContextBase*> m_eclist;
02602
02610 ExecutionContextServiceList m_ecOther;
02611
02619 bool m_created;
02620
02628
02629
02637 coil::Properties m_properties;
02638
02646 ConfigAdmin m_configsets;
02647
02648
02649
02650
02658 struct nv_name
02659 {
02660 nv_name(const char* name) : m_name(name) {};
02661 bool operator()(const SDOPackage::NameValue& nv)
02662 {
02663 return m_name == std::string(nv.name);
02664 }
02665 std::string m_name;
02666 };
02667
02675 struct ec_copy
02676 {
02677 ec_copy(ExecutionContextList& eclist)
02678 : m_eclist(eclist)
02679 {
02680 }
02681 void operator()(ExecutionContextService_ptr ecs)
02682 {
02683 CORBA_SeqUtil::push_back(m_eclist, ExecutionContext::_duplicate(ecs));
02684 }
02685 ExecutionContextList& m_eclist;
02686 };
02687
02688 struct ec_find
02689 {
02690 ec_find(ExecutionContext_ptr& ec)
02691 : m_ec(ec)
02692 {
02693 }
02694 bool operator()(ExecutionContextService_ptr ecs)
02695 {
02696 try
02697 {
02698 ExecutionContext_ptr ec;
02699 ec = ExecutionContext::_narrow(ecs);
02700 return m_ec->_is_equivalent(ec);
02701 }
02702 catch (...)
02703 {
02704 return false;
02705 }
02706 return false;
02707 }
02708 ExecutionContext_ptr m_ec;
02709 };
02710
02711
02719 struct deactivate_comps
02720 {
02721 deactivate_comps(LightweightRTObject_ptr comp)
02722 : m_comp(comp)
02723 {
02724 }
02725 void operator()(ExecutionContextService_ptr ec)
02726 {
02727 ec->deactivate_component(RTC::LightweightRTObject::_duplicate(m_comp));
02728 }
02729 LightweightRTObject_var m_comp;
02730 };
02731 };
02732 };
02733
02734 #ifdef WIN32
02735 #pragma warning( default : 4290 )
02736 #endif
02737
02738 #endif // RTObject