[openrtm-commit:00562] r2271 - trunk/OpenRTM-aist/src/lib/rtm

openrtm @ openrtm.org openrtm @ openrtm.org
2012年 1月 9日 (月) 22:32:18 JST


Author: n-ando
Date: 2012-01-09 22:32:18 +0900 (Mon, 09 Jan 2012)
New Revision: 2271

Modified:
   trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h
   trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp
   trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h
Log:
[incomaptible API] Now ExecutionContextProfile management has been moved to ExecutionContextBase. getObjRef() is also moved to ExecutionContextBase.
[incompatible behavior] Now onExecute and onStateUpdate execution behavior has been changed when two or more RTCs attached to the EC.
  Old: A::onExecute, A::onStateUpdate, B::onExecute, B::onStateUpdate
  New: A::onExecute, B::onExecute, A::onStateUpdate, B::onStateUpdate


Modified: trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h	2012-01-09 13:23:02 UTC (rev 2270)
+++ trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h	2012-01-09 13:32:18 UTC (rev 2271)
@@ -104,21 +104,6 @@
      */
     virtual RTC::ReturnCode_t bindComponent(RTObject_impl* rtc) = 0;
 
-    /*!
-     * @if jp
-     * @brief オブジェクトのリファレンスを取得する。
-     *
-     * オブジェクトのリファレンスを取得する。
-     *
-     * @else
-     * @brief Get the reference of the object. 
-     *
-     * Get the reference of the object.
-     *
-     * @endif
-     */
-    virtual RTC::ExecutionContextService_ptr getObjRef() = 0;
-
     //============================================================
     // Delegated functions to ExecutionContextProfile
     //============================================================
@@ -165,7 +150,10 @@
      *
      * @endif
      */
-    //    RTC::ExecutionContextService_ptr getObjRef(void) const;
+    RTC::ExecutionContextService_ptr getObjRef(void) const
+    {
+      return m_profile.getObjRef();
+    }
 
     /*!
      * @if jp

Modified: trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp	2012-01-09 13:23:02 UTC (rev 2270)
+++ trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp	2012-01-09 13:32:18 UTC (rev 2271)
@@ -40,21 +40,19 @@
   {
     RTC_TRACE(("PeriodicExecutionContext()"));
 
-    m_period = (double)DEEFAULT_PERIOD;
-    RTC_DEBUG(("Actual rate: %d [sec], %d [usec]",
-               m_period.sec(), m_period.usec()));
 
     // getting my reference
-    m_ref = this->_this();
+    m_profile.setObjRef(this->_this());
 
     // profile initialization
-    m_profile.kind = PERIODIC;
-    m_profile.rate = 1.0 / m_period;
-    m_profile.owner = RTC::RTObject::_nil();
-    m_profile.participants.length(0);
-    m_profile.properties.length(0);
+    m_profile.setKind(PERIODIC);
+    m_profile.setRate(1.0 / (double)DEEFAULT_PERIOD);
+    m_profile.setOwner(RTC::RTObject::_nil());
+
+    RTC_DEBUG(("Actual period: %d [sec], %d [usec]",
+               m_profile.getPeriod().sec(), m_profile.getPeriod().usec()));
   }
-  
+
   /*!
    * @if jp
    * @brief コンストラクタ
@@ -64,26 +62,24 @@
    */
   PeriodicExecutionContext::
   PeriodicExecutionContext(OpenRTM::DataFlowComponent_ptr owner,
-			   double rate)
+                           double rate)
     : rtclog("periodic_ec"), m_running(false), m_svc(true), m_nowait(true)
   {
     RTC_TRACE(("PeriodicExecutionContext(owner, rate = %f)", rate));
 
     if (rate == 0) { rate = 1.0 / DEEFAULT_PERIOD; }
-    m_period = coil::TimeValue(1.0 / rate);
+    m_profile.setPeriod(coil::TimeValue(1.0 / rate));
     if (m_period < 0.000001) { m_nowait = true; }
-    RTC_DEBUG(("Actual rate: %d [sec], %d [usec]",
-               m_period.sec(), m_period.usec()));
+    RTC_DEBUG(("Actual period: %d [sec], %d [usec]",
+               m_profile.getPeriod().sec(), m_profile.getPeriod().usec()));
 
     // getting my reference
-    m_ref = this->_this();
+    m_profile.setObjRef(this->_this());
 
     // profile initialization
-    m_profile.kind = PERIODIC;
-    m_profile.rate = 1.0 / m_period;
-    m_profile.owner = RTC::RTObject::_nil();
-    m_profile.participants.length(0);
-    m_profile.properties.length(0);
+    m_profile.setKind(PERIODIC);
+    m_profile.setRate(1.0 / (double)DEEFAULT_PERIOD);
+    m_profile.setOwner(RTC::RTObject::_nil());
   }
   
   /*!
@@ -103,10 +99,6 @@
     m_svc = false;
     wait();
 
-    // cleanup EC's profile
-    m_profile.owner = RTC::RTObject::_nil();
-    m_profile.participants.length(0);
-    m_profile.properties.length(0);
   }
   
   /*------------------------------------------------------------
@@ -142,19 +134,21 @@
   {
     RTC_TRACE(("svc()"));
     int count(0);
-    do 
+    do
       {
         m_worker.mutex_.lock();
-	while (!m_worker.running_)
-	  {
-	    m_worker.cond_.wait();
-	  }
+        while (!m_worker.running_)
+          {
+            m_worker.cond_.wait();
+          }
         coil::TimeValue t0(coil::gettimeofday());
-	if (m_worker.running_)
-	  {
-	    std::for_each(m_comps.begin(), m_comps.end(), invoke_worker());
-	  }
-	m_worker.mutex_.unlock();
+        if (m_worker.running_)
+          {
+            std::for_each(m_comps.begin(), m_comps.end(), invoke_worker_pre());
+            std::for_each(m_comps.begin(), m_comps.end(), invoke_worker_do());
+            std::for_each(m_comps.begin(), m_comps.end(), invoke_worker_post());
+          }
+        m_worker.mutex_.unlock();
         coil::TimeValue t1(coil::gettimeofday());
         if (count > 1000)
           {
@@ -284,8 +278,7 @@
     throw (CORBA::SystemException)
   {
     RTC_TRACE(("get_rate()"));
-    Guard guard(m_profileMutex);
-    return m_profile.rate;
+    return m_profile.getRate();
   }
 
   /*!
@@ -301,15 +294,11 @@
     RTC_TRACE(("set_rate(%f)", rate));
     if (rate > 0.0)
       {
-        {
-          Guard guard(m_profileMutex);
-          m_profile.rate = rate;
-        }
-        m_period = coil::TimeValue(1.0/rate);
-        if (m_period == 0.0) { m_nowait = true; }
+        m_profile.setRate(rate);
+        if ((double)m_profile.getRate() == 0.0) { m_nowait = true; }
         std::for_each(m_comps.begin(), m_comps.end(), invoke_on_rate_changed());
-        RTC_DEBUG(("Actual rate: %d [sec], %d [usec]",
-                   m_period.sec(), m_period.usec()));
+        RTC_DEBUG(("Actual period: %d [sec], %d [usec]",
+                   m_profile.getPeriod().sec(), m_profile.getPeriod().usec()));
         return RTC::RTC_OK;
       }
     return RTC::BAD_PARAMETER;
@@ -515,8 +504,9 @@
   ExecutionKind PeriodicExecutionContext::get_kind()
     throw (CORBA::SystemException)
   {
-    RTC_TRACE(("get_kind()"));
-    return m_profile.kind;
+    RTC_TRACE(("get_kind() = %s",
+               m_profile.getKindString()));
+    return getKind();
   }
 
   /*!
@@ -544,10 +534,11 @@
           {
             return RTC::BAD_PARAMETER;
           }
+        ExecutionContextService_var ec = m_profile.getObjRef();
         ExecutionContextHandle_t id;
-        id = dfp->attach_context(m_ref);
+        id = dfp->attach_context(ec);
         m_comps.push_back(Comp(comp, dfp, id));
-        CORBA_SeqUtil::push_back(m_profile.participants, rtc._retn());
+        m_profile.addComponent(rtc._retn());
         return RTC::RTC_OK;
       }
     catch (CORBA::Exception& e)
@@ -566,8 +557,8 @@
     LightweightRTObject_var comp = RTC::RTObject::_duplicate(rtc->getObjRef());
     OpenRTM::DataFlowComponent_var dfp;
     dfp = OpenRTM::DataFlowComponent::_narrow(comp);
-
-    ExecutionContextHandle_t id = rtc->bindContext(m_ref);
+    ExecutionContextService_var ec = m_profile.getObjRef();
+    ExecutionContextHandle_t id = rtc->bindContext(ec);
     if (id < 0 || id > ECOTHER_OFFSET) 
       {
         // id should be owned context id < ECOTHER_OFFSET
@@ -578,8 +569,7 @@
 
     // rtc is owner of this EC
     m_comps.push_back(Comp(comp,dfp,id));
-    m_profile.owner = RTC::RTObject::_duplicate(dfp);
-
+    m_profile.setOwner(RTC::RTObject::_duplicate(dfp));
     return RTC::RTC_OK;
   }
 
@@ -610,17 +600,8 @@
     m_comps.erase(it);
     RTC_TRACE(("remove_component(): an RTC removed from this context."));
 
-    RTObject_var rtcomp = RTObject::_narrow(comp);
-    if (CORBA::is_nil(rtcomp))
-      {
-        RTC_ERROR(("Invalid object reference."));
-        return RTC::RTC_ERROR;
-      }
-    {
-      Guard guard(m_profileMutex);
-      CORBA_SeqUtil::erase_if(m_profile.participants,
-                              find_participant(rtcomp));
-    }
+    m_profile.removeComponent(comp);
+
     return RTC::RTC_OK;
   }
   
@@ -638,12 +619,7 @@
     throw (CORBA::SystemException)
   {
     RTC_TRACE(("get_profile()"));
-    ExecutionContextProfile_var p;
-    {
-      Guard guard(m_profileMutex);
-      p = new ExecutionContextProfile(m_profile);
-    }
-    return p._retn();
+    return m_profile.getProfile();
   }
 }; // namespace RTC  
 

Modified: trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h	2012-01-09 13:23:02 UTC (rev 2270)
+++ trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h	2012-01-09 13:32:18 UTC (rev 2271)
@@ -131,30 +131,9 @@
      * @endif
      */
     virtual ~PeriodicExecutionContext(void);
-    
+
     /*!
      * @if jp
-     * @brief CORBA オブジェクト参照の取得
-     *
-     * 本オブジェクトの ExecutioncontextService としての CORBA オブジェ
-     * クト参照を取得する。
-     *
-     * @return CORBA オブジェクト参照
-     *
-     * @else
-     * @brief Get the reference to the CORBA object
-     *
-     * Get the reference to the CORBA object as
-     * ExecutioncontextService of this object.
-     *
-     * @return The reference to CORBA object
-     *
-     * @endif
-     */
-    virtual ExecutionContextService_ptr getObjRef(void) {return m_ref;}
-    
-    /*!
-     * @if jp
      * @brief ExecutionContext用アクティビティスレッドを生成する
      *
      * Executioncontext 用の内部アクティビティスレッドを生成し起動する。
@@ -176,7 +155,7 @@
      * @return The generation result
      *
      * @endif
-     */     
+     */
     virtual int open(void *args);
     
     /*!
@@ -197,7 +176,7 @@
      * @return The execution result
      *
      * @endif
-     */     
+     */
     virtual int svc(void);
     
     /*!
@@ -981,6 +960,9 @@
        * @endif
        */
       virtual void worker(void) {return m_sm.worker();}
+      virtual void worker_pre(void) {return m_sm.worker_pre();}
+      virtual void worker_do(void) {return m_sm.worker_do();}
+      virtual void worker_post(void) {return m_sm.worker_post();}
       
       /*!
        * @if jp
@@ -1469,9 +1451,30 @@
     {
       void operator()(Comp& comp)
       {
-	comp._sm.worker();
+        comp._sm.worker();
       }
     };
+    struct invoke_worker_pre
+    {
+      void operator()(Comp& comp)
+      {
+        comp._sm.worker_pre();
+      }
+    };
+    struct invoke_worker_do
+    {
+      void operator()(Comp& comp)
+      {
+        comp._sm.worker_do();
+      }
+    };
+    struct invoke_worker_post
+    {
+      void operator()(Comp& comp)
+      {
+        comp._sm.worker_post();
+      }
+    };
     
     /*!
      * @if jp
@@ -1535,37 +1538,18 @@
      * @endif
      */
     Worker m_worker;
-    
+
     /*!
      * @if jp
-     * @brief ExecutionContextProfile
-     * @else
-     * @brief ExecutionContextProfile
-     * @endif
-     */
-    ExecutionContextProfile m_profile;
-    coil::Mutex m_profileMutex;
-    
-    /*!
-     * @if jp
      * @brief ExecutionContext の実行周期
      * @else
      * @brief Execution cycle of ExecutionContext
      * @endif
      */
     coil::TimeValue m_period;
-    
+
     /*!
      * @if jp
-     * @brief ExecutionContextService オブジェクトへの参照
-     * @else
-     * @brief Reference to ExecutionContextService object
-     * @endif
-     */
-    ExecutionContextService_var m_ref;
-    
-    /*!
-     * @if jp
      * @brief ExecutionContext 即時実行(wait無し実行)フラグ
      * @else
      * @brief Flag of ExecutionContext to run immediately



openrtm-commit メーリングリストの案内