PeriodicECSharedComposite.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef PeriodicECSharedComposite_h
00021 #define PeriodicECSharedComposite_h
00022 
00023 #include <rtm/idl/RTCSkel.h>
00024 #include <rtm/idl/OpenRTMSkel.h>
00025 #include <rtm/RTObject.h>
00026 #include <rtm/PeriodicExecutionContext.h>
00027 #include <rtm/SdoOrganization.h>
00028 #include <coil/stringutil.h>
00029 
00045 #ifdef WIN32
00046 #pragma warning( disable : 4290 )
00047 #endif
00048 
00049 namespace SDOPackage
00050 {
00051   class PeriodicECOrganization
00052     : public Organization_impl
00053   {
00054     typedef std::vector<std::string> PortList;
00055 
00056   public:
00057     PeriodicECOrganization(::RTC::RTObject_impl* rtobj);
00058     virtual ~PeriodicECOrganization(void);
00059 
00082     virtual ::CORBA::Boolean add_members(const SDOList& sdo_list)
00083       throw (::CORBA::SystemException,
00084              InvalidParameter, NotAvailable, InternalError);
00085 
00109     virtual ::CORBA::Boolean set_members(const SDOList& sdos)
00110       throw (::CORBA::SystemException,
00111              InvalidParameter, NotAvailable, InternalError);
00112 
00134     virtual ::CORBA::Boolean remove_member(const char* id)
00135       throw (::CORBA::SystemException,
00136              InvalidParameter, NotAvailable, InternalError);
00137 
00138     void removeAllMembers(void);
00139     void updateDelegatedPorts(void);
00140 
00141   protected:
00142     class Member;
00150     bool sdoToDFC(const SDO_ptr sdo, ::OpenRTM::DataFlowComponent_ptr& dfc);
00151 
00159     void stopOwnedEC(Member& member);
00160 
00168     void startOwnedEC(Member& member);
00169 
00177     void addOrganizationToTarget(Member& member);
00178 
00186     void removeOrganizationFromTarget(Member& member);
00187 
00195     void addParticipantToEC(Member& member);
00196 
00204     void removeParticipantFromEC(Member& member);
00205 
00213     void addPort(Member& member, PortList& portlist);
00214 
00222     void removePort(Member& member, PortList& portlist);
00223 
00224 
00225     void updateExportedPortsList(void);
00226 
00227   protected:
00228     RTC::Logger rtclog;
00229     ::RTC::RTObject_impl* m_rtobj;
00230     ::RTC::ExecutionContext_ptr m_ec;
00231 
00232     class Member
00233     {
00234     public:
00235       Member(RTC::RTObject_ptr rtobj)
00236       //        : rtobj_(rtobj),
00237       //          profile_(rtobj->get_component_profile()),
00238       //          eclist_(rtobj->get_owned_contexts()),
00239       //          config_(rtobj->get_configuration())
00240       {
00241         rtobj_   = RTC::RTObject::_duplicate(rtobj);
00242         profile_ = rtobj->get_component_profile();
00243         eclist_  = rtobj->get_owned_contexts();
00244         config_  = rtobj->get_configuration();
00245       }
00246 
00247       virtual ~Member(void)
00248       {
00249         /*
00250         rtobj_.out();
00251         profile_.out();
00252         eclist_.out();
00253         config_.out();
00254         */
00255       }
00256 
00257       Member(const Member& x)
00258       //        : rtobj_(x.rtobj_),
00259       //          profile_(x.profile_),
00260       //          eclist_(x.eclist_),
00261       //          config_(x.config_)
00262       {
00263         rtobj_   = x.rtobj_;
00264         profile_ = x.profile_;
00265         eclist_  = x.eclist_;
00266         config_  = x.config_;
00267       }
00268 
00269       Member& operator=(const Member& x)
00270       {
00271 //        std::cout << "####################op=" << std::endl;
00272         Member tmp(x);
00273         tmp.swap(*this);
00274         return *this;
00275       }
00276 //
00277       void swap(Member& x)
00278       {
00279         RTC::RTObject_var rtobj(x.rtobj_);
00280         RTC::ComponentProfile_var profile(x.profile_);
00281         RTC::ExecutionContextList_var eclist(x.eclist_);
00282         SDOPackage::Configuration_var config(x.config_);
00283 
00284         x.rtobj_ = this->rtobj_;
00285         x.profile_ = this->profile_;
00286         x.eclist_ = this->eclist_;
00287         x.config_ = this->config_;
00288 
00289         this->rtobj_ = rtobj;
00290         this->profile_ = profile;
00291         this->eclist_ = eclist;
00292         this->config_ = config;
00293       }
00294 
00295       RTC::RTObject_var rtobj_;
00296       RTC::ComponentProfile_var profile_;
00297       RTC::ExecutionContextList_var eclist_;
00298       SDOPackage::Configuration_var config_;
00299     };
00300 
00301     std::vector<Member> m_rtcMembers;
00302     typedef std::vector<Member>::iterator MemIt;
00303     PortList m_expPorts;
00304     
00305     void print(PortList p)
00306     {
00307       for (int i(0), len(p.size()); i < len; ++i)
00308         {
00309           std::cout << p[i] << std::endl;
00310         }
00311     }
00312   };
00313 };
00314 
00315 
00330 namespace RTC
00331 {
00332   class Manager;
00333 
00356   class PeriodicECSharedComposite
00357     : public RTObject_impl
00358   {
00359   public:
00377     PeriodicECSharedComposite(Manager* manager);
00378     
00392     virtual ~PeriodicECSharedComposite(void);
00393     
00409     virtual ReturnCode_t onInitialize(void);
00410     virtual ReturnCode_t onActivated(RTC::UniqueId exec_handle);
00411     virtual ReturnCode_t onDeactivated(RTC::UniqueId exec_handle);
00412     virtual ReturnCode_t onReset(RTC::UniqueId exec_handle);
00413     virtual ReturnCode_t onFinalize(void);
00414     
00415   protected:
00416     std::vector<std::string> m_members;
00417 
00418     OpenRTM::DataFlowComponent_var m_ref;
00419     PeriodicExecutionContext* m_pec;
00420     ExecutionContextService_var m_ecref;
00421     SDOPackage::PeriodicECOrganization* m_org;
00422   };  // class PeriodicECOrganization
00423 }; // namespace RTC
00424 
00425 #ifdef WIN32
00426 #pragma warning( default : 4290 )
00427 #endif
00428 
00429 
00430 extern "C"
00431 {
00432   DLL_EXPORT void PeriodicECSharedCompositeInit(RTC::Manager* manager);
00433 };
00434 
00435 #endif // PeriodicECSharedComposite_h

Generated on Sun May 24 14:08:45 2009 for OpenRTM by  doxygen 1.5.3