メインページ | ネームスペース一覧 | クラス階層 | 構成 | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ

RtcBase.h

説明を見る。
00001 // -*- C++ -*-
00022 #ifndef RtcBase_h
00023 #define RtcBase_h
00024 
00025 // CORBA header include
00026 #include "rtm/RTC.h"
00027 
00028 // STL includes
00029 #include <list>
00030 #include <string>
00031 #include <algorithm>
00032 #include <functional>
00033 
00034 // ACE
00035 #include <ace/Task.h>
00036 
00037 // local includes 
00038 #include "rtm/idl/RTCBaseSkel.h"
00039 #include "rtm/idl/RTCBaseStub.h"
00040 #include "rtm/RtcOutPort.h"
00041 #include "rtm/RtcModuleProfile.h"
00042 #include "rtm/RtcSystemLogger.h"
00043 
00044 
00045 #define USLEEP(x) usleep(x);
00046 
00047 namespace RTM {
00048   // namespace
00049   using namespace std;
00050   
00051   
00052   class InPortBase;
00053   class OutPortBase;
00054   class RtcManager;
00055   
00056   static char* StateString[] =
00057         {
00058           "RTC_UNKNOWN",
00059           "RTC_BORN",
00060           "RTC_INITIALIZING",
00061           "RTC_READY",
00062           "RTC_STARTING",
00063           "RTC_ACTIVE",
00064           "RTC_STOPPING",
00065           "RTC_ABORTING",
00066           "RTC_ERROR",
00067           "RTC_FATAL_ERROR",
00068           "RTC_EXITING",
00069           "UNKNOWN"
00070         };
00071 
00079   typedef RTM::RTComponent::ComponentState ComponentState;
00080   
00081   const ComponentState RTC_UNKNOWN      = RTM::RTComponent::RTC_UNKNOWN;
00082   const ComponentState RTC_BORN         = RTM::RTComponent::RTC_BORN;
00083   const ComponentState RTC_INITIALIZING = RTM::RTComponent::RTC_INITIALIZING;
00084   const ComponentState RTC_READY        = RTM::RTComponent::RTC_READY;
00085   const ComponentState RTC_STARTING     = RTM::RTComponent::RTC_STARTING;
00086   const ComponentState RTC_ACTIVE       = RTM::RTComponent::RTC_ACTIVE;
00087   const ComponentState RTC_STOPPING     = RTM::RTComponent::RTC_STOPPING;
00088   const ComponentState RTC_ABORTING     = RTM::RTComponent::RTC_ABORTING;
00089   const ComponentState RTC_ERROR        = RTM::RTComponent::RTC_ERROR;
00090   const ComponentState RTC_FATAL_ERROR  = RTM::RTComponent::RTC_FATAL_ERROR;
00091   const ComponentState RTC_EXITING      = RTM::RTComponent::RTC_EXITING;
00092   
00093 
00094   typedef enum NamingPolicy {
00095         UNKNOWN = 0,
00096         LONGNAME_ENABLE = 1,
00097         ALIAS_ENABLE = 2
00098   };
00099 
00147   class RtcBase  
00148         : public virtual POA_RTM::RTCBase, 
00149       public virtual PortableServer::RefCountServantBase,
00150       public ACE_Task<ACE_MT_SYNCH>
00151   {
00152   public:
00153 
00173         RtcBase();
00174         
00199         RtcBase(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
00200 
00218         RtcBase(RtcManager* manager);
00219         
00231         virtual ~RtcBase();
00232         
00233         //============================================================
00234         //
00235         // <<< CORBA interfaces >>>
00236         //
00237         //============================================================
00238         
00239         //============================================================
00240         // State implementation functions 
00241         //============================================================
00242         /*
00243          * 
00244          *                                   __                      __
00245          *                         _________V_ \          __________V_ \
00246          *                        |           |/  (any)->|            |/
00247          *                        |  Active   |          | FatalError |
00248          *                        |___________|--,       |____________|
00249          *                            A    |  ___|______      |
00250          *                      ______|___ | |          |     |
00251          *                     |          || | Aborting |     |
00252          *                     | Starting || |__________|     |
00253          *                     |__________||     |   __       |
00254          *             ____________   |    |   __V__V_ \   ___V_____
00255          *   _____    |            |<-+----+--|       |/  |         |    ___
00256          *  (Start)-->|Initializing|  |    |  | Error |-->| Exiting |-->(End)
00257          *   ~~~~~    |____________|--+----+->|_______|   |_________|    ~~~
00258          *                A  |        | ___|______  A         A
00259          *                |  |        ||          | |         |
00260          *                |  |        || Stopping | |         |
00261          *                |  |        ||__________| |         |
00262          *                |  |        |    |        |         |
00263          *                |  |     ___|____V__      |         |
00264          *                |  `--->|           |-----'         |
00265          *                `-------|   Ready   |               |
00266          *                       /|___________|---------------'
00267          *                       \__A
00268          *
00269          */
00270         
00271         //------------------------------------------------------------
00272         // Transition operation of component activity state
00273         //------------------------------------------------------------
00289         virtual RtmRes rtc_start()
00290           throw (CORBA::SystemException, RTM::RTComponent::IllegalTransition);
00291         
00307         virtual RtmRes rtc_stop()
00308           throw (CORBA::SystemException, RTM::RTComponent::IllegalTransition);
00309         
00326         virtual RtmRes rtc_reset()
00327           throw (CORBA::SystemException, RTM::RTComponent::IllegalTransition);
00328         
00343         virtual RtmRes rtc_exit()
00344           throw (CORBA::SystemException, RTM::RTComponent::IllegalTransition);
00345         
00360         virtual RtmRes rtc_kill();
00361         
00362         //------------------------------------------------------------
00363         // Main activity
00364         //------------------------------------------------------------
00384         virtual RtmRes rtc_worker();
00385         
00386         
00387         // ** Steady state **
00388         //------------------------------------------------------------
00389         // Ready state methods
00390         //------------------------------------------------------------
00406         virtual RtmRes rtc_ready_entry()
00407         {USLEEP(1000); return RTM_OK;};
00408         
00423         virtual RtmRes rtc_ready_do()
00424         {USLEEP(1000); return RTM_OK;};
00425         
00440         virtual RtmRes rtc_ready_exit()
00441         {USLEEP(1000); return RTM_OK;};
00442         
00443         
00444         //------------------------------------------------------------
00445         // Active state methods
00446         //------------------------------------------------------------
00461         virtual RtmRes rtc_active_entry()
00462         {USLEEP(1000); return RTM_OK;};
00463         
00478         virtual RtmRes rtc_active_do()
00479         {USLEEP(1000); return RTM_OK;};
00480         
00495         virtual RtmRes rtc_active_exit()
00496         {USLEEP(1000); return RTM_OK;};
00497         
00498         
00499         //------------------------------------------------------------
00500         // Error state methods
00501         //------------------------------------------------------------
00516         virtual RtmRes rtc_error_entry()
00517         {USLEEP(1000); return RTM_OK;};
00518         
00533         virtual RtmRes rtc_error_do()
00534         {USLEEP(1000); return RTM_OK;};
00535         
00550         virtual RtmRes rtc_error_exit()
00551         {USLEEP(1000); return RTM_OK;};
00552         
00553         
00554         //------------------------------------------------------------
00555         // FatalError state methods
00556         //------------------------------------------------------------
00572         virtual RtmRes rtc_fatal_entry()
00573         {USLEEP(1000); return RTM_OK;};
00574         
00590         virtual RtmRes rtc_fatal_do()
00591         {USLEEP(1000); return RTM_OK;};
00592         
00608         virtual RtmRes rtc_fatal_exit()
00609         {USLEEP(1000); return RTM_OK;};
00610         //------------------------------------------------------------
00611         
00612         // ** Transient state **
00630         virtual RtmRes rtc_init_entry()
00631         {USLEEP(1000); return RTM_OK;};
00632         
00650         virtual RtmRes rtc_starting_entry()
00651         {USLEEP(1000); return RTM_OK;};
00652         
00670         virtual RtmRes rtc_stopping_entry()
00671         {USLEEP(1000); return RTM_OK;};
00672         
00690         virtual RtmRes rtc_aborting_entry()
00691         {USLEEP(1000); return RTM_OK;};
00692         
00710         virtual RtmRes rtc_exiting_entry()
00711         {USLEEP(1000); return RTM_OK;};
00712         
00713         
00714         //------------------------------------------------------------
00715         // Status handling
00716         //------------------------------------------------------------
00729         virtual OutPort_ptr rtc_state();
00730         
00731         //------------------------------------------------------------
00732         // Get inports and outport object reference
00733         //------------------------------------------------------------
00746         virtual InPortList* inports() ;
00747 
00764         virtual InPort_ptr get_inport(const char* name)
00765           throw (CORBA::SystemException, RTM::RTComponent::NoSuchName); 
00766         
00779         virtual OutPortList* outports() ;
00780 
00797         virtual OutPort_ptr get_outport(const char* name)
00798           throw (CORBA::SystemException, RTM::RTComponent::NoSuchName);
00799         
00800         //------------------------------------------------------------
00801         // [CORBA interface] Getting component property
00802         //------------------------------------------------------------
00803         //  CORBA::Any* get_property(const char* name) {return NULL;};
00804         //  char* get_properties_xml() {return NULL;};
00805         //  virtual char* instance_name() {return "RtcBase0";}
00806         //  virtual char* class_name() {return "RtcBase";}
00807 
00820         virtual char* instance_id();
00821 
00834     virtual char* implementation_id();
00835 
00848     virtual char* description();
00849 
00862     virtual char* version();
00863 
00876     virtual char* maker();
00877 
00890     virtual char* category();
00891 
00904         virtual RTCProfile* profile() ;
00905         //      virtual RTCConfiguration* configuration() ;
00906 
00907         
00908         
00909         //------------------------------------------------------------
00910         // [CORBA interface] composit component interfaces
00911         //
00912         // These interfaces are methods for RTCompositComponet
00913         // Almost all methods do nothing. Only rtc_components and 
00914         // rtc_get_componet methods return this component itself.
00915         //------------------------------------------------------------
00928         virtual RtmRes rtc_start_thread();
00929 
00942         virtual RtmRes rtc_suspend_thread();
00943 
00956         virtual RtmRes rtc_stop_thread();
00957 
00970         virtual RtmRes rtc_set_parent(RTCBase_ptr comp);
00971 
00985         virtual RtmRes rtc_add_component(RTCBase_ptr comp)
00986         {return RTM_ERR;};
00987 
01001         virtual RtmRes rtc_delete_component(RTCBase_ptr comp)
01002         {return RTM_ERR;} ;
01003 
01018         virtual RtmRes rtc_replace_component(RTCBase_ptr comp1, RTCBase_ptr comp2)
01019         {return RTM_ERR;};
01020 
01034         virtual RtmRes rtc_replace_component_by_name(const char* name1, const char* name2)
01035         {return RTM_ERR;};
01036 
01050         virtual RTCBaseList* rtc_components()
01051         {
01052           RTCBaseList_var myself = new RTCBaseList();
01053           myself->length(1);
01054 
01055 #ifdef ORB_IS_TAO
01056           (*myself)[0] = RTM::RTCBase::_narrow(m_pPOA->servant_to_reference(this));
01057 #else
01058           myself[0] = RTM::RTCBase::_narrow(m_pPOA->servant_to_reference(this));
01059 #endif
01060           return myself._retn();
01061         };
01062 
01076         virtual RTCBase_ptr rtc_get_component(const char* name)
01077         {
01078           return dynamic_cast<RTCBase_ptr>(m_pPOA->servant_to_reference(this));
01079         };
01080 
01094         virtual RtmRes rtc_attach_inport(InPort_ptr in_port)
01095         {return RTM_ERR;};
01096 
01111         virtual RtmRes rtc_attach_inport_by_name(RTCBase_ptr comp, const char* name)
01112         {return RTM_ERR;};
01113 
01114 
01128         virtual RtmRes rtc_detatch_inport(InPort_ptr in_port)
01129         {return RTM_ERR;};
01130 
01145         virtual RtmRes rtc_detatch_inport_by_name(const char* name)
01146         {return RTM_ERR;};
01147 
01161         virtual RtmRes rtc_attach_outport(OutPort_ptr out_port)
01162         {return RTM_ERR;} ;
01163 
01178         virtual RtmRes rtc_attach_outport_by_name(RTCBase_ptr comp,
01179                                                                                           const char* name)
01180         {return RTM_ERR;};
01181 
01195         virtual RtmRes rtc_detatch_outport(OutPort_ptr out_port)
01196         {return RTM_ERR;}
01197 
01212         virtual RtmRes rtc_detatch_outport_by_name(const char* name)
01213          {return RTM_ERR;};
01214         
01215         // end of CORBA interface definition
01216         //============================================================
01217         
01218         
01219         
01220         //============================================================
01221         //
01222         // <<< Local interfaces >>>
01223         //
01224         //============================================================
01225         
01244         virtual void init_orb(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
01245         
01265         virtual int open(void *args);
01266         
01283         virtual int svc(void);
01284         
01285 
01304         virtual int close(unsigned long flags);
01305 
01319         virtual RTM::RTComponent::ComponentState getState();
01320 
01321         //============================================================
01322         // Component Property handling methods
01323         //============================================================
01324         // @brief Get component class name.
01325 
01344         virtual void initModuleProfile(RtcModuleProfile prof);
01345 
01361         virtual RtcModuleProfile& getModuleProfile()
01362         {
01363           return m_Profile;
01364         }
01365         /*
01366         virtual RtcComponentProfile& getProfile()
01367         {
01368           return m_Profile;
01369         }
01370         */
01371         /*
01372         virtual RtcConfiguration& getConfiguration()
01373         {
01374           return m_Configuration;
01375         }
01376         */
01400         virtual string setComponentName(int num);
01401 
01402         //============================================================
01403         // Input port handling
01404         //============================================================
01427         bool registerInPort(InPortBase& in_ch);
01428 
01451         bool registerPort(InPortBase& in_ch)
01452         {
01453           return registerInPort(in_ch);
01454         };
01455         
01476         bool deleteInPort(InPortBase& in_ch);
01477 
01498         bool deletePort(InPortBase& in_ch)
01499         {
01500           return deleteInPort(in_ch);
01501         };
01502         
01523         bool deleteInPortByName(const char* ch_name);
01524 
01542         void readAllInPorts();
01543 
01544 
01560         void finalizeInPorts();
01561 
01562         //============================================================
01563         // Output channel handling
01564         //============================================================
01587         bool registerOutPort(OutPortBase& out_ch);
01588         bool registerPort(OutPortBase& out_ch)
01589         {
01590           return registerOutPort(out_ch);
01591         };
01592         
01614         bool deleteOutPort(OutPortBase& out_ch);
01615 
01637         bool deletePort(OutPortBase& out_ch)
01638         {
01639           return deleteOutPort(out_ch);
01640         };
01641         
01662         bool deleteOutPortByName(const char* ch_name);
01663 
01681         void writeAllOutPorts();
01682 
01683         
01700         void finalizeOutPorts();
01701 
01702         
01733         void appendAlias(const char* alias);
01734 
01765         void appendAlias(const std::string alias);
01766 
01780         std::list<string> getAliases();
01781 
01782         void setNamingPolicy(NamingPolicy policy);
01783         NamingPolicy getNamingPolicy();
01784         bool isLongNameEnable();
01785         bool isAliasEnable();
01786 
01787         void forceExit();
01788 
01804         void finalize();
01805   
01806         bool isThreadRunning();
01807         
01808         
01809 
01810         
01811   protected:
01819         CORBA::ORB_ptr m_pORB;
01820 
01828         PortableServer::POA_ptr m_pPOA;
01829 
01837         RtcManager* m_pManager;
01838 
01846         RTCBase_var m_Parent;
01847 
01855         typedef enum ThreadStates {
01856           UNKNOWN,
01857           RUNNING,
01858           SUSPEND,
01859           STOP
01860         };
01861         class ThreadState
01862         {
01863         public:
01864           ThreadState() : m_Flag(RUNNING){};
01865           ThreadStates m_Flag;
01866           ACE_Thread_Mutex m_Mutex;
01867         };
01875         ThreadState m_ThreadState;
01876 
01884         class eq_name
01885         {
01886         public:
01887           const string m_name;
01888           eq_name(const char* name) : m_name(name){};
01889           bool operator()(InPortBase* ch)
01890           {
01891                 string ch_name(ch->name());
01892                 return m_name == ch_name;
01893           };
01894           bool operator()(OutPortBase* ch)
01895           {
01896                 string ch_name(ch->name());
01897                 return m_name == ch_name;
01898           };
01899         };
01900 
01908         struct ComponentStateMtx {
01909         public:
01917           ComponentStateMtx():_state(RTM::RTComponent::RTC_BORN){};
01918 
01926           ComponentState _state;
01927           
01935           ACE_Thread_Mutex _mutex;
01936         };
01937 
01945         ComponentStateMtx m_CurrentState;
01946 
01954         ComponentStateMtx m_NextState;
01955         
01963         typedef RtmRes (RtcBase::*StateFunc)();
01964         
01965         //------------------------------------------------------------
01966         // Function pointer tables for state action functions.
01967         //------------------------------------------------------------
01975         StateFunc _exit_func[11];
01976 
01984         StateFunc _entry_func[11];
01985 
01993         StateFunc _do_func[11];
01994         
01995         //------------------------------------------------------------
01996         // State action functions
01997         //------------------------------------------------------------
01998         // 
02006         RtmRes _check_error(RtmRes result);
02007 
02015         RtmRes _nop(){return RTM_OK;}
02016 
02024         RtmRes _rtc_initializing();
02025 
02033         RtmRes _rtc_ready_entry();
02041         RtmRes _rtc_starting();
02049         RtmRes _rtc_active_entry();
02057         RtmRes _rtc_stopping();
02065         RtmRes _rtc_aborting();
02066 
02074         RtmRes _rtc_error_entry();
02075 
02083         RtmRes _rtc_fatal_entry();
02084 
02092         RtmRes _rtc_exiting();
02093 
02101         RtmRes _rtc_ready();
02102 
02110         RtmRes _rtc_active();
02111 
02119         RtmRes _rtc_error();
02120 
02128         RtmRes _rtc_fatal();
02129 
02137         RtmRes _rtc_ready_exit();
02138 
02146         RtmRes _rtc_active_exit();
02147 
02155         RtmRes _rtc_error_exit();
02156 
02164         RtmRes _rtc_fatal_exit();
02165         
02173         void init_state_func_table();
02174         
02175 
02183         typedef list<InPortBase*>::iterator InPorts_it;
02184         
02192         typedef list<OutPortBase*>::iterator OutPorts_it;
02193         
02201         struct InPorts
02202         {
02203           list<InPortBase*> m_List;
02204           ACE_Thread_Mutex m_Mutex;
02205         };
02213         InPorts m_InPorts;
02214         
02222         struct OutPorts
02223         {
02224           list<OutPortBase*> m_List;
02225           ACE_Thread_Mutex m_Mutex;
02226         };
02234         OutPorts m_OutPorts;
02235         
02237         //  list<const bool*> m_InFlags;
02238         
02246         TimedState m_TimedState;
02254         OutPortAny<TimedState> m_StatePort;                                                                       
02255 
02263         RtcModuleProfile m_Profile;
02264         //      RtcManagerProfile m_ManagerProfile;
02265         //      RtcComponentProfile m_Profile;
02266         //      RtcConfiguration m_Configuration;
02267 
02275         std::list<string> m_Alias;
02276 
02277         NamingPolicy m_NamingPolicy;
02278 
02286         RtcMedLogbuf m_MedLogbuf;
02287 
02295         RtcLogStream rtcout;
02296 
02297   };
02298 
02299   //------------------------------------------------------------
02300   // RTComponent factory function type
02301   //------------------------------------------------------------
02302 
02303   class RtcManager;
02311   typedef RtcBase* (*RtcNewFunc)(RtcManager* manager);
02312 
02320   typedef void (*RtcDeleteFunc)(RtcBase* rtc);
02321 
02322 };  // end of namespace RTM
02323 
02324 
02325 #endif // __RtcBase_h__

OpenRTMに対してWed Apr 6 14:22:11 2005に生成されました。 doxygen 1.3.6