00001
00019 #ifndef RTC_RTOBJECT_H
00020 #define RTC_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 #include <rtm/CorbaPort.h>
00033
00034
00035 #include <rtm/ConfigAdmin.h>
00036 #include <rtm/SystemLogger.h>
00037
00038 #define ECOTHER_OFFSET 1000
00039
00040 namespace SDOPackage
00041 {
00042 class Configuration_impl;
00043 };
00044
00045 #ifdef WIN32
00046 #pragma warning( disable : 4290 )
00047 #endif
00048
00049 namespace RTC
00050 {
00051 class Manager;
00052 class ExecutionContextBase;
00053 typedef ExecutionContextHandle_t UniqueId;
00054
00089 class RTObject_impl
00090 : public virtual POA_OpenRTM::DataFlowComponent,
00091 public virtual PortableServer::RefCountServantBase
00092 {
00093 public:
00112 RTObject_impl(Manager* manager);
00113
00134 RTObject_impl(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
00135
00147 virtual ~RTObject_impl(void);
00148
00149 protected:
00150
00151
00152
00180
00181
00182 virtual ReturnCode_t onInitialize();
00183
00211
00212
00213 virtual ReturnCode_t onFinalize();
00214
00246
00247
00248 virtual ReturnCode_t onStartup(RTC::UniqueId exec_handle);
00249
00281
00282
00283 virtual ReturnCode_t onShutdown(RTC::UniqueId exec_handle);
00284
00316
00317
00318 virtual ReturnCode_t onActivated(RTC::UniqueId exec_handle);
00319
00351
00352
00353 virtual ReturnCode_t onDeactivated(RTC::UniqueId exec_handle);
00354
00390
00391
00392 virtual ReturnCode_t onExecute(RTC::UniqueId exec_handle);
00393
00425
00426
00427 virtual ReturnCode_t onAborting(RTC::UniqueId exec_handle);
00428
00459
00460
00461 virtual ReturnCode_t onError(RTC::UniqueId exec_handle);
00462
00493
00494
00495 virtual ReturnCode_t onReset(RTC::UniqueId exec_handle);
00496
00532
00533
00534 virtual ReturnCode_t onStateUpdate(RTC::UniqueId exec_handle);
00535
00571
00572
00573 virtual ReturnCode_t onRateChanged(RTC::UniqueId exec_handle);
00574
00575 public:
00576
00577
00578
00614 virtual ReturnCode_t initialize()
00615 throw (CORBA::SystemException);
00616
00661 virtual ReturnCode_t finalize()
00662 throw (CORBA::SystemException);
00663
00707 virtual ReturnCode_t exit()
00708 throw (CORBA::SystemException);
00709
00742 virtual CORBA::Boolean is_alive(ExecutionContext_ptr exec_context)
00743 throw (CORBA::SystemException);
00744
00772 virtual ExecutionContext_ptr get_context(UniqueId exec_handle)
00773 throw (CORBA::SystemException);
00774
00793 virtual ExecutionContextList* get_owned_contexts()
00794 throw (CORBA::SystemException);
00795
00814 virtual ExecutionContextList* get_participating_contexts()
00815 throw (CORBA::SystemException);
00816
00831 virtual ExecutionContextHandle_t
00832 get_context_handle(ExecutionContext_ptr cxt)
00833 throw (CORBA::SystemException);
00834
00865 UniqueId attach_context(ExecutionContext_ptr exec_context)
00866 throw (CORBA::SystemException);
00867
00868 UniqueId bindContext(ExecutionContext_ptr exec_context);
00869
00911 ReturnCode_t detach_context(UniqueId exec_handle)
00912 throw (CORBA::SystemException);
00913
00914
00915
00916
00936 virtual ComponentProfile* get_component_profile()
00937 throw (CORBA::SystemException);
00938
00958 virtual PortServiceList* get_ports()
00959 throw (CORBA::SystemException);
00960
00982
00983
00984
00985
00986
00987
01012 virtual ReturnCode_t on_initialize()
01013 throw (CORBA::SystemException);
01014
01039 virtual ReturnCode_t on_finalize()
01040 throw (CORBA::SystemException);
01041
01070 virtual ReturnCode_t on_startup(UniqueId exec_handle)
01071 throw (CORBA::SystemException);
01072
01101 virtual ReturnCode_t on_shutdown(UniqueId exec_handle)
01102 throw (CORBA::SystemException);
01103
01130 virtual ReturnCode_t on_activated(UniqueId exec_handle)
01131 throw (CORBA::SystemException);
01132
01160 virtual ReturnCode_t on_deactivated(UniqueId exec_handle)
01161 throw (CORBA::SystemException);
01162
01195 virtual ReturnCode_t on_aborting(UniqueId exec_handle)
01196 throw (CORBA::SystemException);
01197
01241 virtual ReturnCode_t on_error(UniqueId exec_handle)
01242 throw (CORBA::SystemException);
01243
01277 virtual ReturnCode_t on_reset(UniqueId exec_handle)
01278 throw (CORBA::SystemException);
01279
01280
01281
01282
01324 virtual ReturnCode_t on_execute(UniqueId exec_handle)
01325 throw (CORBA::SystemException);
01326
01370 virtual ReturnCode_t on_state_update(UniqueId exec_handle)
01371 throw (CORBA::SystemException);
01372
01409 virtual ReturnCode_t on_rate_changed(UniqueId exec_handle)
01410 throw (CORBA::SystemException);
01411
01412
01413
01414
01452 virtual SDOPackage::OrganizationList* get_owned_organizations()
01453 throw (CORBA::SystemException,
01454 SDOPackage::NotAvailable, SDOPackage::InternalError);
01455
01456
01457
01458
01492 virtual char* get_sdo_id()
01493 throw (CORBA::SystemException,
01494 SDOPackage::NotAvailable, SDOPackage::InternalError);
01495
01529 virtual char* get_sdo_type()
01530 throw (CORBA::SystemException,
01531 SDOPackage::NotAvailable, SDOPackage::InternalError);
01532
01569 virtual SDOPackage::DeviceProfile* get_device_profile()
01570 throw (CORBA::SystemException,
01571 SDOPackage::NotAvailable, SDOPackage::InternalError);
01572
01609 virtual SDOPackage::ServiceProfileList* get_service_profiles()
01610 throw (CORBA::SystemException,
01611 SDOPackage::NotAvailable, SDOPackage::InternalError);
01612
01654 virtual SDOPackage::ServiceProfile* get_service_profile(const char* id)
01655 throw (CORBA::SystemException,
01656 SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
01657 SDOPackage::InternalError);
01658
01706 virtual SDOPackage::SDOService_ptr get_sdo_service(const char* id)
01707 throw (CORBA::SystemException,
01708 SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
01709 SDOPackage::InternalError);
01710
01755 virtual SDOPackage::Configuration_ptr get_configuration()
01756 throw (CORBA::SystemException,
01757 SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
01758 SDOPackage::InternalError);
01759
01803 virtual SDOPackage::Monitoring_ptr get_monitoring()
01804 throw (CORBA::SystemException,
01805 SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
01806 SDOPackage::InternalError);
01807
01843 virtual SDOPackage::OrganizationList* get_organizations()
01844 throw (CORBA::SystemException,
01845 SDOPackage::NotAvailable, SDOPackage::InternalError);
01846
01878 virtual SDOPackage::NVList* get_status_list()
01879 throw (CORBA::SystemException,
01880 SDOPackage::NotAvailable, SDOPackage::InternalError);
01881
01918 virtual CORBA::Any* get_status(const char* name)
01919 throw (CORBA::SystemException,
01920 SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
01921 SDOPackage::InternalError);
01922
01923
01924
01925
01945 const char* getInstanceName()
01946 {
01947 RTC_TRACE(("getInstanceName()"));
01948 return m_profile.instance_name;
01949 }
01950
01970 void setInstanceName(const char* instance_name);
01971
01991 const char* getTypeName()
01992 {
01993 RTC_TRACE(("getTypeName()"));
01994 return m_profile.type_name;
01995 }
01996
02016 const char* getDescription()
02017 {
02018 RTC_TRACE(("getDescription()"));
02019 return m_profile.description;
02020 }
02021
02042 const char* getVersion()
02043 {
02044 RTC_TRACE(("getVersion()"));
02045 return m_profile.version;
02046 }
02047
02067 const char* getVendor()
02068 {
02069 RTC_TRACE(("getVendor()"));
02070 return m_profile.vendor;
02071 }
02072
02092 const char* getCategory()
02093 {
02094 RTC_TRACE(("getCategory()"));
02095 return m_profile.category;
02096 }
02097
02117 std::vector<std::string> getNamingNames();
02118
02138 void setObjRef(const RTObject_ptr rtobj);
02139
02159 RTObject_ptr getObjRef() const;
02160
02186 void setProperties(const coil::Properties& prop);
02187
02209 coil::Properties& getProperties();
02210
02243 template <typename VarType>
02244 bool bindParameter(const char* param_name, VarType& var,
02245 const char* def_val,
02246 bool (*trans)(VarType&, const char*) = coil::stringTo)
02247 {
02248 RTC_TRACE(("bindParameter(%s (default: %s))", param_name, def_val));
02249 m_configsets.bindParameter(param_name, var, def_val, trans);
02250 return true;
02251 }
02252
02274 void updateParameters(const char* config_set);
02275
02309 bool addPort(PortBase& port);
02343 bool addPort(PortService_ptr port);
02377 bool addPort(CorbaPort& port);
02409 void registerPort(PortBase& port);
02441 void registerPort(PortService_ptr port);
02473 void registerPort(CorbaPort& port);
02474
02503 bool addInPort(const char* name, InPortBase& inport);
02530 void registerInPort(const char* name, InPortBase& inport);
02531
02560 bool addOutPort(const char* name, OutPortBase& outport);
02587 void registerOutPort(const char* name, OutPortBase& outport);
02588
02610 bool removeInPort(InPortBase& port);
02611
02633 bool removeOutPort(OutPortBase& port);
02634
02656 bool removePort(PortBase& port);
02678 bool removePort(PortService_ptr port);
02700 bool removePort(CorbaPort& port);
02720 void deletePort(PortBase& port);
02740 void deletePort(PortService_ptr port);
02760 void deletePort(CorbaPort& port);
02761
02781 void deletePortByName(const char* port_name);
02782
02803 bool readAll();
02804
02825 bool writeAll();
02826
02860 void setReadAll(bool read=true, bool completion=false);
02861
02893 void setWriteAll(bool write=true, bool completion=false);
02894
02895
02912 void finalizePorts();
02924 void finalizeContexts();
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934
02935
02936
02937
02938 protected:
02958 void shutdown();
02959
02960 protected:
02968 mutable Logger rtclog;
02976 Manager* m_pManager;
02977
02985 CORBA::ORB_var m_pORB;
02986
02994 PortableServer::POA_var m_pPOA;
02995
02996
02997
02998
03006 SDOPackage::OrganizationList m_sdoOwnedOrganizations;
03007
03015 SDOPackage::ServiceProfileList m_sdoSvcProfiles;
03016
03024 struct svc_name
03025 {
03026 svc_name (const char* id) : m_id(id) {};
03027 bool operator()(const SDOPackage::ServiceProfile& prof)
03028 {
03029 return m_id == std::string(prof.id);
03030 }
03031 std::string m_id;
03032 };
03033
03041 SDOPackage::Configuration_impl* m_pSdoConfigImpl;
03042
03050 SDOPackage::Configuration_var m_pSdoConfig;
03051
03059 SDOPackage::OrganizationList m_sdoOrganizations;
03060
03068 SDOPackage::NVList m_sdoStatus;
03069
03070
03071
03072
03080 ComponentProfile m_profile;
03081
03089 RTObject_var m_objref;
03090
03098 PortAdmin m_portAdmin;
03099
03107 std::vector<InPortBase*> m_inports;
03108
03116 std::vector<OutPortBase*> m_outports;
03117
03125 ExecutionContextServiceList m_ecMine;
03126
03134 std::vector<ExecutionContextBase*> m_eclist;
03135
03143 ExecutionContextServiceList m_ecOther;
03144
03152 bool m_created;
03153
03161 bool m_exiting;
03162
03170
03171
03179 coil::Properties m_properties;
03180
03188 ConfigAdmin m_configsets;
03189
03190
03198 bool m_readAll;
03199
03207 bool m_writeAll;
03208
03225 bool m_readAllCompletion;
03226
03243 bool m_writeAllCompletion;
03244
03245
03246
03247
03255 struct nv_name
03256 {
03257 nv_name(const char* name) : m_name(name) {};
03258 bool operator()(const SDOPackage::NameValue& nv)
03259 {
03260 return m_name == std::string(nv.name);
03261 }
03262 std::string m_name;
03263 };
03264
03272 struct ec_copy
03273 {
03274 ec_copy(ExecutionContextList& eclist)
03275 : m_eclist(eclist)
03276 {
03277 }
03278 void operator()(ExecutionContextService_ptr ecs)
03279 {
03280 if (!::CORBA::is_nil(ecs))
03281 {
03282 CORBA_SeqUtil::push_back(m_eclist, ExecutionContext::_duplicate(ecs));
03283 }
03284 }
03285 ExecutionContextList& m_eclist;
03286 };
03287
03288 struct ec_find
03289 {
03290 ec_find(ExecutionContext_ptr& ec)
03291 : m_ec(ExecutionContext::_duplicate(ec))
03292 {
03293 }
03294 bool operator()(ExecutionContextService_ptr ecs)
03295 {
03296 try
03297 {
03298 if (!::CORBA::is_nil(ecs))
03299 {
03300 ExecutionContext_var ec;
03301 ec = ExecutionContext::_narrow(ecs);
03302 return m_ec->_is_equivalent(ec);
03303 }
03304 }
03305 catch (...)
03306 {
03307 return false;
03308 }
03309 return false;
03310 }
03311 ExecutionContext_var m_ec;
03312
03313 };
03314
03315
03323 struct deactivate_comps
03324 {
03325 deactivate_comps(LightweightRTObject_ptr comp)
03326 : m_comp(RTC::LightweightRTObject::_duplicate(comp))
03327 {
03328 }
03329 void operator()(ExecutionContextService_ptr ec)
03330 {
03331 if (!::CORBA::is_nil(ec) && !ec->_non_existent())
03332 {
03333 ec->deactivate_component(RTC::LightweightRTObject::_duplicate(m_comp));
03334 }
03335 }
03336 LightweightRTObject_var m_comp;
03337 };
03338 };
03339 };
03340
03341 #ifdef WIN32
03342 #pragma warning( default : 4290 )
03343 #endif
03344
03345 #endif // RTC_RTOBJECT