Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

RTObject.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00019 /*
00020  * $Log: RTObject.h,v $
00021  * Revision 1.7  2007/04/23 04:57:44  n-ando
00022  * Finalization processed was modified.
00023  * Configuration admin class was introduced.
00024  *
00025  * Revision 1.6  2007/04/13 15:55:43  n-ando
00026  * RTObject interface operations in RTC.idl were changed.
00027  * - attach_executioncontext()
00028  * - detach_executioncontext()
00029  *
00030  * Revision 1.5  2007/01/14 22:59:01  n-ando
00031  * A bug fix about template argument for buffer-type.
00032  *
00033  * Revision 1.4  2007/01/14 19:46:14  n-ando
00034  * The component action implementation functions for Users' business logic
00035  * were added (i.e onInitialize(), onExecute(), etc..)
00036  *
00037  * Revision 1.3  2007/01/12 14:38:48  n-ando
00038  * The registeInPort()/registerOutPort functions are added.
00039  *
00040  * Revision 1.2  2007/01/09 15:21:47  n-ando
00041  * SDO interfaces are marged.
00042  * Some RTObject's operation signatures were changed.
00043  *
00044  * Revision 1.1  2006/09/11 19:04:38  n-ando
00045  * The first commit.
00046  *
00047  *
00048  */
00049 
00050 #ifndef RTObject_h
00051 #define RTObject_h
00052 
00053 // CORBA header include
00054 #include "rtm/RTC.h"
00055 #include "rtm/Properties.h"
00056 #include "rtm/idl/RTCSkel.h"
00057 #include "rtm/idl/OpenRTMSkel.h"
00058 #include "rtm/PortBase.h"
00059 //#include "rtm/ObjectManager.h"
00060 #include "rtm/PortAdmin.h"
00061 #include <rtm/DataInPort.h>
00062 #include <rtm/DataOutPort.h>
00063 #include <rtm/InPort.h>
00064 #include <rtm/OutPort.h>
00065 #include <rtm/ConfigAdmin.h>
00066 
00067 // ACE
00068 #include <ace/Task.h>
00069 
00070 
00071 namespace SDOPackage
00072 {
00073   class Configuration_impl;
00074 };
00075 
00076 namespace RTC
00077 {
00078   class Manager;
00079 
00080   class RTObject_impl
00081     : public virtual POA_RTC::DataFlowComponent, 
00082       public virtual PortableServer::RefCountServantBase
00083   {
00084   public:
00085     RTObject_impl(Manager* manager);
00086     RTObject_impl(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
00087     virtual ~RTObject_impl();
00088 
00089 
00090   protected:
00091     //============================================================
00092     // Overridden functions
00093     //============================================================
00094     // The initialize action (on CREATED->ALIVE transition)
00095     // formaer rtc_init_entry() 
00096     virtual ReturnCode_t onInitialize();
00097     
00098     // The finalize action (on ALIVE->END transition)
00099     // formaer rtc_exiting_entry()
00100     virtual ReturnCode_t onFinalize();
00101     
00102     // The startup action when ExecutionContext startup
00103     // former rtc_starting_entry()
00104     virtual ReturnCode_t onStartup(RTC::UniqueId ec_id);
00105     
00106     // The shutdown action when ExecutionContext stop
00107     // former rtc_stopping_entry()
00108     virtual ReturnCode_t onShutdown(RTC::UniqueId ec_id);
00109     
00110     // The activated action (Active state entry action)
00111     // former rtc_active_entry()
00112     virtual ReturnCode_t onActivated(RTC::UniqueId ec_id);
00113     
00114     // The deactivated action (Active state exit action)
00115     // former rtc_active_exit()
00116     virtual ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
00117     
00118     // The execution action that is invoked periodically
00119     // former rtc_active_do()
00120     virtual ReturnCode_t onExecute(RTC::UniqueId ec_id);
00121     
00122     // The aborting action when main logic error occurred.
00123     // former rtc_aborting_entry()
00124     virtual ReturnCode_t onAborting(RTC::UniqueId ec_id);
00125     
00126     // The error action in ERROR state
00127     // former rtc_error_do()
00128     virtual ReturnCode_t onError(RTC::UniqueId ec_id);
00129     
00130     // The reset action that is invoked resetting
00131     // This is same but different the former rtc_init_entry()
00132     virtual ReturnCode_t onReset(RTC::UniqueId ec_id);
00133     
00134     // The state update action that is invoked after onExecute() action
00135     // no corresponding operation exists in OpenRTm-aist-0.2.0
00136     virtual ReturnCode_t onStateUpdate(RTC::UniqueId ec_id);
00137 
00138     // The action that is invoked when execution context's rate is changed
00139     // no corresponding operation exists in OpenRTm-aist-0.2.0
00140     virtual ReturnCode_t onRateChanged(RTC::UniqueId ec_id);
00141 
00142 
00143   public:
00144     //============================================================
00145     // RTC::LightweightRTObject
00146     //============================================================
00177     virtual ReturnCode_t initialize();
00178 
00179 
00217     virtual ReturnCode_t finalize();
00218 
00219 
00255     virtual ReturnCode_t exit(); 
00256 
00277     virtual CORBA::Boolean is_alive();
00278 
00279 
00287     virtual ExecutionContextList* get_contexts();
00288 
00296     virtual ExecutionContext_ptr get_context(const UniqueId ec_id);
00297 
00298     /*
00299     virtual UniqueId 
00300     set_execution_context_service(const ExecutionContextService_ptr ec);
00301     */
00302 
00303     //============================================================
00304     // RTC::RTObject
00305     //============================================================
00321     virtual ComponentProfile* get_component_profile();
00322 
00323 
00339     virtual PortList* get_ports();
00340 
00341 
00359     virtual ExecutionContextServiceList* get_execution_context_services();
00360 
00361 
00362 
00363     // RTC::ComponentAction
00364     UniqueId attach_executioncontext(ExecutionContext_ptr exec_context);
00365     ReturnCode_t detach_executioncontext(UniqueId ec_id);
00366     virtual ReturnCode_t on_initialize();
00367     virtual ReturnCode_t on_finalize();
00368     virtual ReturnCode_t on_startup(UniqueId ec_id);
00369     virtual ReturnCode_t on_shutdown(UniqueId ec_id);
00370     virtual ReturnCode_t on_activated(UniqueId ec_id);
00371     virtual ReturnCode_t on_deactivated(UniqueId ec_id);
00372     virtual ReturnCode_t on_aborting(UniqueId ec_id);
00373     virtual ReturnCode_t on_error(UniqueId ec_id);
00374     virtual ReturnCode_t on_reset(UniqueId ec_id);
00375 
00376     virtual ReturnCode_t on_execute(UniqueId ec_id);
00377     virtual ReturnCode_t on_state_update(UniqueId ec_id);
00378     virtual ReturnCode_t on_rate_changed(UniqueId ec_id);
00379 
00380 
00381 
00382     //============================================================
00383     // SDOPackage::SdoSystemElement
00384     //============================================================
00406     virtual SDOPackage::OrganizationList* get_owned_organizations()
00407       throw (SDOPackage::NotAvailable);
00408 
00409 
00410     //============================================================
00411     // SDOPackage::SDO
00412     //============================================================
00442     virtual char* get_sdo_id()
00443       throw (SDOPackage::NotAvailable, SDOPackage::InternalError);
00444     
00474     virtual char* get_sdo_type()
00475       throw (SDOPackage::NotAvailable, SDOPackage::InternalError);
00476 
00507     virtual SDOPackage::DeviceProfile* get_device_profile()
00508       throw (SDOPackage::NotAvailable, SDOPackage::InternalError);
00509     
00541     virtual SDOPackage::ServiceProfileList* get_service_profiles()
00542       throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
00543              SDOPackage::InternalError);
00544     
00573     virtual SDOPackage::ServiceProfile* get_service_profile(const char* id)
00574       throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
00575              SDOPackage::InternalError);
00576     
00604     virtual SDOPackage::SDOService_ptr get_sdo_service(const char* id)
00605       throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
00606              SDOPackage::InternalError);
00607     
00647     virtual SDOPackage::Configuration_ptr get_configuration()
00648       throw (SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
00649              SDOPackage::InternalError);
00650     
00689     virtual SDOPackage::Monitoring_ptr get_monitoring()
00690       throw (SDOPackage::InterfaceNotImplemented, SDOPackage::NotAvailable,
00691              SDOPackage::InternalError);
00692 
00723     virtual SDOPackage::OrganizationList* get_organizations()
00724       throw (SDOPackage::NotAvailable, SDOPackage::InternalError);
00725     
00752     virtual SDOPackage::NVList* get_status_list()
00753       throw (SDOPackage::NotAvailable, SDOPackage::InternalError);
00754     
00784     virtual CORBA::Any* get_status(const char* name)
00785       throw (SDOPackage::InvalidParameter, SDOPackage::NotAvailable,
00786              SDOPackage::InternalError);
00787 
00788 
00789 
00790     //============================================================
00791     // Local interfaces
00792     //============================================================
00793     const char* getInstanceName() {return m_profile.instance_name;}
00794     void setInstanceName(const char* instance_name);
00795     const char* getTypeName() {return m_profile.type_name;}
00796     const char* getDescription() { return m_profile.description;}
00797     const char* getVersion() {return m_profile.version;}
00798     const char* getVendor() {return m_profile.vendor;}
00799     const char* getCategory() {return m_profile.category;}
00800 
00801     std::vector<std::string> getNamingNames();
00802 
00803     void setObjRef(const RTObject_ptr rtobj);
00804     RTObject_ptr getObjRef() const;
00805 
00806 
00807 
00833     void setProperties(const Properties& prop);
00834 
00856     Properties& getProperties();
00857 
00858 
00859     template <typename VarType>
00860     bool bindParameter(const char* param_name, VarType& var,
00861                        const char* def_val,
00862                        bool (*trans)(VarType&, const char*) = ::stringTo)
00863     {
00864       m_configsets.bindParameter(param_name, var, def_val, trans);
00865       return true;
00866     }
00867 
00868     void updateParameters(const char* config_set);
00869 
00901     void registerPort(PortBase& port);
00902 
00903     template <class DataType, template <class DataType> class Buffer>
00904     void registerInPort(const char* name,
00905                         InPort<DataType, Buffer>& inport)
00906     {
00907       PortBase* port = new DataInPort(name, inport);
00908       registerPort(*port);
00909     }
00910 
00911     template <class DataType, template <class DataType> class Buffer>
00912     void registerOutPort(const char* name,
00913                          OutPort<DataType, Buffer>& outport)
00914     {
00915       PortBase* port = new DataOutPort(name, outport);
00916       registerPort(*port);
00917     }
00918       
00919 
00945     void deletePort(PortBase& port);
00946     void deletePortByName(const char* port_name);
00947     void finalizePorts();
00948 
00949 
00950 
00951     /*
00952     template <class DataType>
00953     void registerInPort(BufferBase<DataType>& buffer)
00954     {
00955       CorbaInPort<DataType>* port;
00956       p = new CorbaInPort<DataType>(buffer);
00957       Port_var inport;
00958       inport = new PortInPort();
00959       inport->setInPortRef(p->_this());
00960     }
00961     */
00962 
00963   protected:
00964     void shutdown();
00965 
00966 
00967 
00968 
00969 
00970   protected:
00971     Manager* m_pManager;
00972     CORBA::ORB_var m_pORB;
00973     PortableServer::POA_var m_pPOA;
00974 
00975     //============================================================
00976     // SDO 関係の変数
00977     //============================================================
00981     SDOPackage::OrganizationList m_sdoOwnedOrganizations;
00982 
00986     SDOPackage::ServiceProfileList m_sdoSvcProfiles;
00987 
00991     struct svc_name
00992     {
00993       svc_name (const char* id) : m_id(id) {};
00994       bool operator()(const SDOPackage::ServiceProfile& prof)
00995       {
00996         return m_id == std::string(prof.id);
00997       }
00998       std::string m_id;
00999     };
01000 
01004     SDOPackage::Configuration_impl* m_pSdoConfigImpl;
01005     SDOPackage::Configuration_var  m_pSdoConfig;
01006 
01010     SDOPackage::OrganizationList m_sdoOrganizations;
01011 
01015     SDOPackage::NVList m_sdoStatus;
01016 
01017     
01018     //============================================================
01019     // RTC 関係の変数
01020     //============================================================
01024     ComponentProfile m_profile;
01025 
01026     RTObject_ptr m_objref;
01030     PortAdmin m_portAdmin;
01031 
01032     ExecutionContextServiceList m_execContexts;
01033 
01034     bool m_created;
01035     bool m_alive;
01036 
01040     Properties m_properties;
01041 
01042     ConfigAdmin m_configsets;
01043 
01044     //------------------------------------------------------------
01045     // Functor
01046     //------------------------------------------------------------
01047     struct nv_name
01048     {
01049       nv_name(const char* name) : m_name(name) {};
01050       bool operator()(const SDOPackage::NameValue& nv)
01051       {
01052         return m_name == std::string(nv.name);
01053       }
01054       std::string m_name;
01055     };
01056 
01057 
01058     struct ec_copy
01059     {
01060       ec_copy(ExecutionContextList& eclist)
01061         : m_eclist(eclist)
01062       {
01063       }
01064       void operator()(ExecutionContextService_ptr ecs)
01065       {
01066         CORBA_SeqUtil::push_back(m_eclist, ExecutionContext::_duplicate(ecs));
01067       }
01068       ExecutionContextList& m_eclist;
01069     };
01070     //    ExecutionContextAdminList m_execContextList;
01071 
01072     struct deactivate_comps
01073     {
01074       deactivate_comps(LightweightRTObject_ptr comp)
01075         : m_comp(comp)
01076       {
01077       }
01078       void operator()(ExecutionContextService_ptr ec)
01079       {
01080         ec->deactivate_component(RTC::LightweightRTObject::_duplicate(m_comp));
01081       }
01082       LightweightRTObject_var m_comp;
01083     };
01084 
01085 
01086   };
01087 };
01088 #endif // RTObject

Generated on Tue May 29 16:45:37 2007 for OpenRTM by  doxygen 1.4.1