[openrtm-commit:00559] r2268 - trunk/OpenRTM-aist/src/lib/rtm

openrtm @ openrtm.org openrtm @ openrtm.org
2012年 1月 9日 (月) 14:22:21 JST


Author: n-ando
Date: 2012-01-09 14:22:21 +0900 (Mon, 09 Jan 2012)
New Revision: 2268

Added:
   trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.cpp
   trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextProfile.cpp
   trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextProfile.h
Modified:
   trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h
   trunk/OpenRTM-aist/src/lib/rtm/ExtTrigExecutionContext.cpp
   trunk/OpenRTM-aist/src/lib/rtm/Makefile.am
   trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp
   trunk/OpenRTM-aist/src/lib/rtm/OpenHRPExecutionContext.cpp
   trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp
   trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h
   trunk/OpenRTM-aist/src/lib/rtm/RTObject.cpp
Log:
[incompatible] ExecutionContextBase's super classes have been moved to PeriodicExecutionContext class. Delegation to ExecutionContextProfile has been added.
ExecutionContextBase.cpp, ExecutionContextProfile.h/cpp have been added.
[incmpatible] ExecutionContextFactory is now coil's global factory. Manager's EC factory is obsolete.


Added: trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.cpp	                        (rev 0)
+++ trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.cpp	2012-01-09 05:22:21 UTC (rev 2268)
@@ -0,0 +1,69 @@
+// -*- C++ -*-
+/*!
+ * @file ExecutionContextBase.cpp
+ * @brief ExecutionContext base class
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2011
+ *     Task-intelligence Research Group,
+ *     Intelligent Systems Research Institute,
+ *     National Institute of
+ *         Advanced Industrial Science and Technology (AIST), Japan
+ *     All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#include <rtm/ExecutionContextBase.h>
+
+namespace RTC
+{
+  /*!
+   * @if jp
+   * @brief 仮想デストラクタ
+   * @else
+   * @brief Virtual Destructor
+   * @endif
+   */
+  ExecutionContextBase::~ExecutionContextBase(void)
+  {
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionContextの処理を進める
+   * @else
+   * @brief Proceed with tick of ExecutionContext
+   * @endif
+   */
+  void ExecutionContextBase::init(coil::Properties& props)
+  {
+  }
+
+
+    /*!
+     * @if jp
+     * @brief コンポーネントをバインドする。
+     * @else
+     * @brief Bind the component.
+     * @endif
+     */
+  //  TC::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;
+};  // namespace RTC

Modified: trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h	2012-01-06 07:14:38 UTC (rev 2267)
+++ trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h	2012-01-09 05:22:21 UTC (rev 2268)
@@ -19,14 +19,22 @@
 #ifndef RTC_EXECUTIONCONTEXTBASE_H
 #define RTC_EXECUTIONCONTEXTBASE_H
 
+#include <coil/Factory.h>
+
 #include <rtm/idl/RTCSkel.h>
 #include <rtm/idl/OpenRTMSkel.h>
 #include <rtm/Factory.h>
+#include <rtm/ExecutionContextProfile.h>
 
 #ifdef WIN32
 #pragma warning( disable : 4290 )
 #endif
 
+namespace coil
+{
+  class Properties;
+}
+
 namespace RTC
 {
   /*!
@@ -49,8 +57,6 @@
    * @endif
    */
   class ExecutionContextBase
-    : public virtual POA_OpenRTM::ExtTrigExecutionContextService,
-      public virtual PortableServer::RefCountServantBase
   {
   public:
     /*!
@@ -66,8 +72,8 @@
      *
      * @endif
      */
-    virtual ~ExecutionContextBase(void){};
-    
+    virtual ~ExecutionContextBase(void);
+
     /*!
      * @if jp
      * @brief ExecutionContextの処理を進める
@@ -81,9 +87,7 @@
      *
      * @endif
      */
-    virtual void tick()
-      throw (CORBA::SystemException)
-    {};
+    virtual void init(coil::Properties& props);
 
     /*!
      * @if jp
@@ -114,7 +118,440 @@
      * @endif
      */
     virtual RTC::ExecutionContextService_ptr getObjRef() = 0;
+
+    //============================================================
+    // Delegated functions to ExecutionContextProfile
+    //============================================================
+    /*!
+     * @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
+     */
+    void setObjRef(RTC::ExecutionContextService_ptr ec_ptr)
+    {
+      m_profile.setObjRef(ec_ptr);
+    }
+
+    /*!
+     * @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
+     */
+    //    RTC::ExecutionContextService_ptr getObjRef(void) const;
+
+    /*!
+     * @if jp
+     * @brief ExecutionContext の実行周期(Hz)を設定する
+     *
+     * Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を設定す
+     * る。実行周期の変更は、DataFlowComponentAction の
+     * on_rate_changed によって各RTコンポーネントに伝達される。
+     *
+     * @param rate 処理周期(単位:Hz)
+     *
+     * @return ReturnCode_t 型のリターンコード
+     *         RTC_OK: 正常終了
+     *         BAD_PARAMETER: 設定値が負の値
+     *
+     * @else
+     *
+     * @brief Set execution rate(Hz) of ExecutionContext
+     *
+     * This operation shall set the rate (in hertz) at which this
+     * context’s Active participating RTCs are being called.  If the
+     * execution kind of the context is PERIODIC, a rate change shall
+     * result in the invocation of on_rate_changed on any RTCs
+     * realizing DataFlowComponentAction that are registered with any
+     * RTCs participating in the context.
+     *
+     * @param rate Execution cycle(Unit:Hz)
+     *
+     * @return The return code of ReturnCode_t type
+     *         RTC_OK: Succeed
+     *         BAD_PARAMETER: Invalid value. The value might be negative.
+     *
+     * @endif
+     */
+    RTC::ReturnCode_t setRate(double rate)
+    {
+      return m_profile.setRate(rate);;
+    }
+
+    /*!
+     * @if jp
+     * @brief ExecutionContext の実行周期(Hz)を取得する
+     *
+     * Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を取得す
+     * る。
+     *
+     * @return 処理周期(単位:Hz)
+     *
+     * @else
+     *
+     * @brief Get execution rate(Hz) of ExecutionContext
+     *
+     * This operation shall return the rate (in hertz) at which its
+     * Active participating RTCs are being invoked.
+     *
+     * @return Execution cycle(Unit:Hz)
+     *
+     * @endif
+     */
+    double getRate(void) const
+    {
+      return m_profile.getRate();
+    }
+
+    /*!
+     * @if jp
+     * @brief ExecutionKind を文字列化する
+     *
+     * RTC::ExecutionKind で定義されている PERIODIC, EVENT_DRIVEN,
+     * OTHER を文字列化する。
+     *
+     * @param kind ExecutionKind
+     * @return 文字列化されたExecutionKind
+     *
+     * @else
+     *
+     * @brief Converting ExecutionKind enum to string 
+     *
+     * This function converts enumeration (PERIODIC, EVENT_DRIVEN,
+     * OTHER) defined in RTC::ExecutionKind to string.
+     *
+     * @param kind ExecutionKind
+     * @return String of ExecutionKind
+     *
+     * @endif
+     */
+    const char* getKindString(RTC::ExecutionKind kind) const
+    {
+      return m_profile.getKindString(kind);
+    }
+
+    /*!
+     * @if jp
+     * @brief ExecutionKind を設定する
+     *
+     * この ExecutionContext の ExecutionKind を設定する
+     *
+     * @param kind ExecutionKind
+     *
+     * @else
+     *
+     * @brief Set the ExecutionKind
+     *
+     * This operation sets the kind of the execution context.
+     *
+     * @param kind ExecutionKind
+     *
+     * @endif
+     */
+    RTC::ReturnCode_t setKind(RTC::ExecutionKind kind)
+    {
+      return m_profile.setKind(kind);
+    }
+
+    /*!
+     * @if jp
+     * @brief ExecutionKind を取得する
+     *
+     * 本 ExecutionContext の ExecutionKind を取得する
+     *
+     * @return ExecutionKind
+     *
+     * @else
+     *
+     * @brief Get the ExecutionKind
+     *
+     * This operation shall report the execution kind of the execution
+     * context.
+     *
+     * @return ExecutionKind
+     *
+     * @endif
+     */
+    RTC::ExecutionKind getKind(void) const
+    {
+      return m_profile.getKind();
+    }
+
+    /*!
+     * @if jp
+     * @brief Ownerコンポーネントをセットする。
+     *
+     * このECのOwnerとなるRTCをセットする。
+     *
+     * @param comp OwnerとなるRTコンポーネント
+     * @return ReturnCode_t 型のリターンコード
+     * @else
+     * @brief Setting owner component of the execution context
+     *
+     * This function sets an RT-Component to be owner of the execution context.
+     *
+     * @param comp an owner RT-Component of this execution context
+     * @return The return code of ReturnCode_t type
+     * @endif
+     */
+    RTC::ReturnCode_t setOwner(RTC::LightweightRTObject_ptr comp)
+    {
+      return m_profile.setOwner(comp);
+    }
+
+    /*!
+     * @if jp
+     * @brief Ownerコンポーネントの参照を取得する
+     *
+     * このECのOwnerであるRTCの参照を取得する。
+     *
+     * @return OwnerRTコンポーネントの参照
+     * @else
+     * @brief Getting a reference of the owner component
+     *
+     * This function returns a reference of the owner RT-Component of
+     * this execution context
+     *
+     * @return a reference of the owner RT-Component
+     * @endif
+     */
+    const RTC::RTObject_ptr getOwner() const
+    {
+      return m_profile.getOwner();
+    }
+
+    /*!
+     * @if jp
+     * @brief RTコンポーネントを追加する
+     *
+     * 指定したRTコンポーネントを参加者リストに追加する。追加されたRTコ
+     * ンポーネントは attach_context が呼ばれ、Inactive 状態に遷移する。
+     * 指定されたRTコンポーネントがnullの場合は、BAD_PARAMETER が返され
+     * る。指定されたRTコンポーネントが DataFlowComponent 以外の場合は、
+     * BAD_PARAMETER が返される。
+     *
+     * @param comp 追加対象RTコンポーネント
+     *
+     * @return ReturnCode_t 型のリターンコード
+     *
+     * @else
+     *
+     * @brief Add an RT-component
+     *
+     * The operation causes the given RTC to begin participating in
+     * the execution context.  The newly added RTC will receive a call
+     * to LightweightRTComponent::attach_context and then enter the
+     * Inactive state.  BAD_PARAMETER will be invoked, if the given
+     * RT-Component is null or if the given RT-Component is other than
+     * DataFlowComponent.
+     *
+     * @param comp The target RT-Component for add
+     *
+     * @return The return code of ReturnCode_t type
+     *
+     * @endif
+     */
+    RTC::ReturnCode_t addComponent(RTC::LightweightRTObject_ptr comp)
+    {
+      return m_profile.addComponent(comp);
+    }
+
+    /*!
+     * @if jp
+     * @brief RTコンポーネントを参加者リストから削除する
+     *
+     * 指定したRTコンポーネントを参加者リストから削除する。削除された
+     * RTコンポーネントは detach_context が呼ばれる。指定されたRTコンポー
+     * ネントが参加者リストに登録されていない場合は、BAD_PARAMETER が返
+     * される。
+     *
+     * @param comp 削除対象RTコンポーネント
+     *
+     * @return ReturnCode_t 型のリターンコード
+     *
+     * @else
+     *
+     * @brief Remove the RT-Component from participant list
+     *
+     * This operation causes a participant RTC to stop participating in the
+     * execution context.
+     * The removed RTC will receive a call to
+     * LightweightRTComponent::detach_context.
+     * BAD_PARAMETER will be returned, if the given RT-Component is not
+     * participating in the participant list.
+     *
+     * @param comp The target RT-Component for delete
+     *
+     * @return The return code of ReturnCode_t type
+     *
+     * @endif
+     */
+    RTC::ReturnCode_t removeComponent(RTC::LightweightRTObject_ptr comp)
+    {
+      return m_profile.removeComponent(comp);
+    }
+
+    /*!
+     * @if jp
+     * @brief RTコンポーネントの参加者リストを取得する
+     *
+     * 現在登録されている参加者RTCのリストを取得する。
+     *
+     * @return 参加者RTCのリスト
+     *
+     * @else
+     *
+     * @brief Getting participant RTC list
+     *
+     * This function returns a list of participant RTC of the execution context.
+     *
+     * @return Participants RTC list
+     *
+     * @endif
+     */
+    const RTC::RTCList& getComponentList() const
+    {
+      return m_profile.getComponentList();
+    }
+
+    /*!
+     * @if jp
+     * @brief Propertiesをセットする
+     *
+     * ExecutionContextProfile::properties をセットする。
+     *
+     * @param props ExecutionContextProfile::properties にセットするプ
+     *              ロパティー
+     *
+     * @else
+     * @brief Setting Properties
+     *
+     * This function sets ExecutionContextProfile::properties by
+     * coil::Properties.
+     *
+     * @param props Properties to be set to
+     *              ExecutionContextProfile::properties.
+     *
+     * @endif
+     */
+    void setProperties(coil::Properties& props)
+    {
+      m_profile.setProperties(props);
+    }
+
+    /*!
+     * @if jp
+     * @brief Propertiesを取得する
+     *
+     * ExecutionContextProfile::properties を取得する。
+     *
+     * @return coil::Propertiesに変換された
+     *              ExecutionContextProfile::properties
+     *
+     * @else
+     * @brief Setting Properties
+     *
+     * This function sets ExecutionContextProfile::properties by
+     * coil::Properties.
+     *
+     * @param props Properties to be set to ExecutionContextProfile::properties.
+     *
+     * @endif
+     */
+    const coil::Properties getProperties() const
+    {
+      return m_profile.getProperties();
+    }
+
+    /*!
+     * @if jp
+     * @brief Profileを取得する
+     *
+     * RTC::ExecutionContextProfile を取得する。取得した
+     * ExecutionContextProfile の所有権は呼び出し側にある。取得されたオ
+     * ブジェクトが不要になった場合、呼び出し側が開放する責任を負う。
+     *
+     * @return RTC::ExecutionContextProfile
+     *
+     * @else
+     * @brief Getting Profile
+     *
+     * This function gets RTC::ExecutionContextProfile.  The ownership
+     * of the obtained ExecutionContextProfile is given to caller. The
+     * caller should release obtained object when it is unneccessary
+     * anymore.
+     *
+     * @return RTC::ExecutionContextProfile
+     *
+     * @endif
+     */
+    RTC::ExecutionContextProfile* getProfile(void)
+    {
+      return m_profile.getProfile();
+    }
+
+    /*!
+     * @if jp
+     * @brief Profileを取得する
+     *
+     * RTC::ExecutionContextProfile を取得する。
+     *
+     * @return RTC::ExecutionContextProfile
+     *
+     * @else
+     * @brief Getting Profile
+     *
+     * This function gets RTC::ExecutionContextProfile.
+     *
+     * @return RTC::ExecutionContextProfile
+     *
+     * @endif
+     */
+    const RTC::ExecutionContextProfile& getProfile(void) const
+    {
+      return m_profile.getProfile();
+    }
+    // end of delegated functions to ExecutionContextProfile
+    //============================================================
+
+
+
+  protected:
+    RTC_impl::ExecutionContextProfile m_profile;
   };  // class ExecutionContextBase
+
+  typedef coil::GlobalFactory<ExecutionContextBase> ExecutionContextFactory;
+
+#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
+  EXTERN template class DLL_PLUGIN coil::GlobalFactory<ExecutionContextBase>;
+#endif
 };  // namespace RTC
 
 #ifdef WIN32

Added: trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextProfile.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextProfile.cpp	                        (rev 0)
+++ trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextProfile.cpp	2012-01-09 05:22:21 UTC (rev 2268)
@@ -0,0 +1,384 @@
+// -*- C++ -*-
+/*!
+ * @file ExecutionContextProfile.cpp
+ * @brief ExecutionContextProfile class
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2011
+ *     Noriaki Ando
+ *     Intelligent Systems Research Institute,
+ *     National Institute of
+ *         Advanced Industrial Science and Technology (AIST), Japan
+ *     All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#include <rtm/ExecutionContextProfile.h>
+#include <rtm/CORBA_SeqUtil.h>
+#include <rtm/NVUtil.h>
+
+#define DEEFAULT_PERIOD 0.000001
+
+namespace RTC_impl
+{
+
+  /*!
+   * @if jp
+   * @brief デフォルトコンストラクタ
+   * @else
+   * @brief Default constructor
+   * @endif
+   */
+  ExecutionContextProfile::
+  ExecutionContextProfile(RTC::ExecutionKind kind)
+    : rtclog("periodic_ecprofile"),
+      m_period((double)DEEFAULT_PERIOD),
+      m_ref(RTC::ExecutionContextService::_nil())
+  {
+    RTC_TRACE(("ExecutionContextProfile()"));
+    RTC_DEBUG(("Actual rate: %d [sec], %d [usec]",
+               m_period.sec(), m_period.usec()));
+    // profile initialization
+    m_profile.kind = RTC::PERIODIC;
+    m_profile.rate = 1.0 / m_period;
+    m_profile.owner = RTC::RTObject::_nil();
+    m_profile.participants.length(0);
+    m_profile.properties.length(0);
+  }
+
+  /*!
+   * @if jp
+   * @brief デストラクタ
+   * @else
+   * @brief Destructor
+   * @endif
+   */
+  ExecutionContextProfile::~ExecutionContextProfile()
+  {
+    RTC_TRACE(("~ExecutionContextProfile()"));
+
+    // cleanup EC's profile
+    m_profile.owner = RTC::RTObject::_nil();
+    m_profile.participants.length(0);
+    m_profile.properties.length(0);
+    m_ref = RTC::ExecutionContextService::_nil();
+  }
+
+  /*!
+   * @if jp
+   * @brief CORBA オブジェクト参照の取得
+   * @else
+   * @brief Get the reference to the CORBA object
+   * @endif
+   */
+  void ExecutionContextProfile::
+  setObjRef(RTC::ExecutionContextService_ptr ec_ptr)
+  {
+    m_ref = RTC::ExecutionContextService::_duplicate(ec_ptr);
+  }
+
+  /*!
+   * @if jp
+   * @brief CORBA オブジェクト参照の取得
+   * @else
+   * @brief Get the reference to the CORBA object
+   * @endif
+   */
+  RTC::ExecutionContextService_ptr
+  ExecutionContextProfile::getObjRef(void) const
+  {
+    return RTC::ExecutionContextService::_duplicate(m_ref);
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionContext の実行周期(Hz)を設定する
+   * @else
+   * @brief Set execution rate(Hz) of ExecutionContext
+   * @endif
+   */
+  RTC::ReturnCode_t ExecutionContextProfile::setRate(double rate)
+  {
+    RTC_TRACE(("set_rate(%f)", rate));
+    if (rate < 0.0) { return RTC::BAD_PARAMETER; }
+
+    Guard guard(m_profileMutex);
+    m_profile.rate = rate;
+    m_period = coil::TimeValue(1.0/rate);
+    return RTC::RTC_OK;
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionContext の実行周期(Hz)を取得する
+   * @else
+   * @brief Get execution rate(Hz) of ExecutionContext
+   * @endif
+   */
+  CORBA::Double ExecutionContextProfile::getRate() const
+  {
+    RTC_TRACE(("get_rate()"));
+    Guard guard(m_profileMutex);
+    return m_profile.rate;
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionKind を文字列化する
+   * @else
+   * @brief Converting ExecutionKind enum to string
+   * @endif
+   */
+  const char*
+  ExecutionContextProfile::getKindString(RTC::ExecutionKind kind) const
+  {
+    const char* kinds[] = {"PERIODIC", "EVENT_DRIVEN", "OTHER"};
+    if (kind < RTC::PERIODIC || kind > RTC::OTHER)
+      {
+        return "";
+      }
+    return kinds[kind];
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionKind を取得する
+   * @else
+   * @brief Get the ExecutionKind
+   * @endif
+   */
+  RTC::ReturnCode_t ExecutionContextProfile::setKind(RTC::ExecutionKind kind)
+  {
+    if (kind < RTC::PERIODIC || kind > RTC::OTHER)
+      {
+        RTC_ERROR(("Invalid kind is given. %d", kind));
+        return RTC::BAD_PARAMETER;
+      }
+    RTC_TRACE(("setKind(%s)", getKindString(kind)));
+    Guard guard(m_profileMutex);
+    m_profile.kind = kind;
+    return RTC::RTC_OK;
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionKind を取得する
+   * @else
+   * @brief Get the ExecutionKind
+   * @endif
+   */
+  RTC::ExecutionKind ExecutionContextProfile::getKind(void) const
+  {
+    RTC_TRACE(("%s = getKind()", getKindString(m_profile.kind)));
+    return m_profile.kind;
+  }
+
+  /*!
+   * @if jp
+   * @brief Ownerコンポーネントをセットする。
+   * @else
+   * @brief Setting owner component of the execution context
+   * @endif
+   */
+  RTC::ReturnCode_t ExecutionContextProfile::
+  setOwner(RTC::LightweightRTObject_ptr comp)
+  {
+    RTC_TRACE(("setOwner()"));
+    if (CORBA::is_nil(comp))
+      {
+        RTC_ERROR(("nil reference is given."));
+        return RTC::BAD_PARAMETER;
+      }
+    RTC::RTObject_var rtobj;
+    rtobj = RTC::RTObject::_narrow(comp);
+    if (CORBA::is_nil(rtobj))
+      {
+        RTC_ERROR(("Narrowing failed."));
+        return RTC::RTC_ERROR;
+      }
+    m_profile.owner = RTC::RTObject::_duplicate(m_profile.owner);
+    return RTC::RTC_OK;
+  }
+
+  /*!
+   * @if jp
+   * @brief Ownerコンポーネントの参照を取得する
+   * @else
+   * @brief Getting a reference of the owner component
+   * @endif
+   */
+  const RTC::RTObject_ptr ExecutionContextProfile::getOwner() const
+  {
+    RTC_TRACE(("getOwner()"));
+    return RTC::RTObject::_duplicate(m_profile.owner);
+  }
+
+  /*!
+   * @if jp
+   * @brief RTコンポーネントを追加する
+   * @else
+   * @brief Add an RT-component
+   * @endif
+   */
+  RTC::ReturnCode_t
+  ExecutionContextProfile::addComponent(RTC::LightweightRTObject_ptr comp)
+  {
+    RTC_TRACE(("addComponent()"));
+    if (CORBA::is_nil(comp))
+      {
+        RTC_ERROR(("A nil reference was given."));
+        return RTC::BAD_PARAMETER;
+      }
+    RTC::RTObject_var rtobj = RTC::RTObject::_narrow(comp);
+    if (CORBA::is_nil(rtobj))
+      {
+        RTC_ERROR(("Narrowing was failed."));
+        return RTC::RTC_ERROR;
+      }
+    CORBA_SeqUtil::push_back(m_profile.participants, rtobj._retn());
+    return RTC::RTC_OK;
+  }
+
+  /*!
+   * @if jp
+   * @brief RTコンポーネントを参加者リストから削除する
+   * @else
+   * @brief Remove the RT-Component from participant list
+   * @endif
+   */
+  RTC::ReturnCode_t
+  ExecutionContextProfile::removeComponent(RTC::LightweightRTObject_ptr comp)
+  {
+    RTC_TRACE(("removeComponent()"));
+    if (CORBA::is_nil(comp))
+      {
+        RTC_ERROR(("A nil reference was given."));
+        return RTC::BAD_PARAMETER;
+      }
+    RTC::RTObject_var rtobj = RTC::RTObject::_narrow(comp);
+    if (CORBA::is_nil(rtobj))
+      {
+        RTC_ERROR(("Narrowing was failed."));
+        return RTC::RTC_ERROR;
+      }
+    {
+      Guard guard(m_profileMutex);
+      CORBA::Long index;
+      index = CORBA_SeqUtil::find(m_profile.participants,
+                                  find_participant(rtobj));
+      if (index < 0)
+        {
+          RTC_ERROR(("The given RTObject does not exist in the EC."));
+          return RTC::BAD_PARAMETER;
+        }
+      CORBA_SeqUtil::erase(m_profile.participants, index);
+    }
+    return RTC::RTC_OK;
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionKind を取得する
+   * @else
+   * @brief Get the ExecutionKind
+   * @endif
+   */
+  const RTC::RTCList& ExecutionContextProfile::getComponentList() const
+  {
+    RTC_TRACE(("getComponentList(%d)", m_profile.participants.length()));
+    return m_profile.participants;
+  }
+
+  /*!
+   * @if jp
+   * @brief Propertiesをセットする
+   * @else
+   * @brief Setting Properties
+   * @endif
+   */
+  void ExecutionContextProfile::setProperties(coil::Properties& props)
+  {
+    RTC_TRACE(("setProperties()"));
+    RTC_DEBUG_STR((props));
+    Guard guard(m_profileMutex);
+    NVUtil::copyFromProperties(m_profile.properties, props);
+  }
+
+  /*!
+   * @if jp
+   * @brief Propertiesを取得する
+   * @else
+   * @brief Setting Properties
+   * @endif
+   */
+  const coil::Properties ExecutionContextProfile::getProperties() const
+  {
+    RTC_TRACE(("getProperties()"));
+    Guard guard(m_profileMutex);
+    coil::Properties props;
+    NVUtil::copyToProperties(props, m_profile.properties);
+    RTC_DEBUG_STR((props));
+    return props;
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionContextProfile を取得する
+   * @else
+   * @brief Get the ExecutionContextProfile
+   * @endif
+   */
+  RTC::ExecutionContextProfile* ExecutionContextProfile::getProfile()
+  {
+    RTC_TRACE(("getProfile()"));
+    RTC::ExecutionContextProfile_var p;
+    {
+      Guard guard(m_profileMutex);
+      p = new RTC::ExecutionContextProfile(m_profile);
+    }
+    return p._retn();
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionContextProfile を取得する
+   * @else
+   * @brief Get the ExecutionContextProfile
+   * @endif
+   */
+  const RTC::ExecutionContextProfile&
+  ExecutionContextProfile::getProfile() const
+  {
+    RTC_TRACE(("getProfile()"));
+    Guard guard(m_profileMutex);
+    return m_profile;
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionContextProfileをロックする
+   * @else
+   * @brief Getting a lock of RTC::ExecutionContextProfile
+   * @endif
+   */
+  void ExecutionContextProfile::lock() const
+  {
+    m_profileMutex.lock();
+  }
+
+  /*!
+   * @if jp
+   * @brief ExecutionContextProfileをアンロックする
+   * @else
+   * @brief Release a lock of the RTC::ExecutionContextProfile
+   * @endif
+   */
+  void ExecutionContextProfile::unlock() const
+  {
+    m_profileMutex.unlock();
+  }
+
+}; // namespace RTC


Property changes on: trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextProfile.cpp
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextProfile.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextProfile.h	                        (rev 0)
+++ trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextProfile.h	2012-01-09 05:22:21 UTC (rev 2268)
@@ -0,0 +1,565 @@
+// -*- C++ -*-
+/*!
+ * @file ExecutionContextProfile.h
+ * @brief ExecutionContextProfile class
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2011
+ *     Noriaki Ando
+ *     Intelligent Systems Research Institute,
+ *     National Institute of
+ *         Advanced Industrial Science and Technology (AIST), Japan
+ *     All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef RTC_EXECUTIONCONTEXTPROFILE_H
+#define RTC_EXECUTIONCONTEXTPROFILE_H
+
+#include <coil/Mutex.h>
+#include <coil/Guard.h>
+#include <coil/Properties.h>
+#include <coil/TimeValue.h>
+
+#include <rtm/idl/RTCStub.h>
+#include <rtm/SystemLogger.h>
+
+#ifdef WIN32
+#pragma warning( disable : 4290 )
+#endif
+
+namespace RTC_impl
+{
+  /*!
+   * @if jp
+   * @class ExecutionContextProfile
+   * @brief ExecutionContextProfile クラス
+   *
+   * Periodic Sampled Data Processing(周期実行用)ExecutionContextクラス。
+   *
+   * @since 0.4.0
+   *
+   * @else
+   * @class ExecutionContextProfile
+   * @brief ExecutionContextProfile class
+   *
+   * Periodic Sampled Data Processing (for the execution cycles)
+   * ExecutionContext class
+   *
+   * @since 0.4.0
+   *
+   * @endif
+   */
+  class ExecutionContextProfile
+  {
+    typedef coil::Guard<coil::Mutex> Guard;
+  public:
+    /*!
+     * @if jp
+     * @brief デフォルトコンストラクタ
+     *
+     * デフォルトコンストラクタ
+     * プロファイルに以下の項目を設定する。
+     *  - kind : PERIODIC
+     *  - rate : 0.0
+     *
+     * @else
+     * @brief Default Constructor
+     *
+     * Default Constructor
+     * Set the following items to profile.
+     *  - kind : PERIODIC
+     *  - rate : 0.0
+     *
+     * @endif
+     */
+    ExecutionContextProfile(RTC::ExecutionKind kind = RTC::PERIODIC);
+
+    /*!
+     * @if jp
+     * @brief デストラクタ
+     *
+     * デストラクタ
+     *
+     * @else
+     * @brief Destructor
+     *
+     * Destructor
+     *
+     * @endif
+     */
+    virtual ~ExecutionContextProfile(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
+     */
+    void setObjRef(RTC::ExecutionContextService_ptr ec_ptr);
+
+    /*!
+     * @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
+     */
+    RTC::ExecutionContextService_ptr getObjRef(void) const;
+
+    /*!
+     * @if jp
+     * @brief ExecutionContext の実行周期(Hz)を設定する
+     *
+     * Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を設定す
+     * る。実行周期の変更は、DataFlowComponentAction の
+     * on_rate_changed によって各RTコンポーネントに伝達される。
+     *
+     * @param rate 処理周期(単位:Hz)
+     *
+     * @return ReturnCode_t 型のリターンコード
+     *         RTC_OK: 正常終了
+     *         BAD_PARAMETER: 設定値が負の値
+     *
+     * @else
+     *
+     * @brief Set execution rate(Hz) of ExecutionContext
+     *
+     * This operation shall set the rate (in hertz) at which this
+     * context’s Active participating RTCs are being called.  If the
+     * execution kind of the context is PERIODIC, a rate change shall
+     * result in the invocation of on_rate_changed on any RTCs
+     * realizing DataFlowComponentAction that are registered with any
+     * RTCs participating in the context.
+     *
+     * @param rate Execution cycle(Unit:Hz)
+     *
+     * @return The return code of ReturnCode_t type
+     *         RTC_OK: Succeed
+     *         BAD_PARAMETER: Invalid value. The value might be negative.
+     *
+     * @endif
+     */
+    RTC::ReturnCode_t setRate(double rate);
+
+    /*!
+     * @if jp
+     * @brief ExecutionContext の実行周期(Hz)を取得する
+     *
+     * Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を取得す
+     * る。
+     *
+     * @return 処理周期(単位:Hz)
+     *
+     * @else
+     *
+     * @brief Get execution rate(Hz) of ExecutionContext
+     *
+     * This operation shall return the rate (in hertz) at which its
+     * Active participating RTCs are being invoked.
+     *
+     * @return Execution cycle(Unit:Hz)
+     *
+     * @endif
+     */
+    double getRate(void) const;
+
+    /*!
+     * @if jp
+     * @brief ExecutionKind を文字列化する
+     *
+     * RTC::ExecutionKind で定義されている PERIODIC, EVENT_DRIVEN,
+     * OTHER を文字列化する。
+     *
+     * @param kind ExecutionKind
+     * @return 文字列化されたExecutionKind
+     *
+     * @else
+     *
+     * @brief Converting ExecutionKind enum to string 
+     *
+     * This function converts enumeration (PERIODIC, EVENT_DRIVEN,
+     * OTHER) defined in RTC::ExecutionKind to string.
+     *
+     * @param kind ExecutionKind
+     * @return String of ExecutionKind
+     *
+     * @endif
+     */
+    const char* getKindString(RTC::ExecutionKind kind) const;
+
+    /*!
+     * @if jp
+     * @brief ExecutionKind を設定する
+     *
+     * この ExecutionContext の ExecutionKind を設定する
+     *
+     * @param kind ExecutionKind
+     *
+     * @else
+     *
+     * @brief Set the ExecutionKind
+     *
+     * This operation sets the kind of the execution context.
+     *
+     * @param kind ExecutionKind
+     *
+     * @endif
+     */
+    RTC::ReturnCode_t setKind(RTC::ExecutionKind kind);
+
+    /*!
+     * @if jp
+     * @brief ExecutionKind を取得する
+     *
+     * 本 ExecutionContext の ExecutionKind を取得する
+     *
+     * @return ExecutionKind
+     *
+     * @else
+     *
+     * @brief Get the ExecutionKind
+     *
+     * This operation shall report the execution kind of the execution
+     * context.
+     *
+     * @return ExecutionKind
+     *
+     * @endif
+     */
+    RTC::ExecutionKind getKind(void) const;
+
+    /*!
+     * @if jp
+     * @brief Ownerコンポーネントをセットする。
+     *
+     * このECのOwnerとなるRTCをセットする。
+     *
+     * @param comp OwnerとなるRTコンポーネント
+     * @return ReturnCode_t 型のリターンコード
+     * @else
+     * @brief Setting owner component of the execution context
+     *
+     * This function sets an RT-Component to be owner of the execution context.
+     *
+     * @param comp an owner RT-Component of this execution context
+     * @return The return code of ReturnCode_t type
+     * @endif
+     */
+    RTC::ReturnCode_t setOwner(RTC::LightweightRTObject_ptr comp);
+
+    /*!
+     * @if jp
+     * @brief Ownerコンポーネントの参照を取得する
+     *
+     * このECのOwnerであるRTCの参照を取得する。
+     *
+     * @return OwnerRTコンポーネントの参照
+     * @else
+     * @brief Getting a reference of the owner component
+     *
+     * This function returns a reference of the owner RT-Component of
+     * this execution context
+     *
+     * @return a reference of the owner RT-Component
+     * @endif
+     */
+    const RTC::RTObject_ptr getOwner() const;
+
+    /*!
+     * @if jp
+     * @brief RTコンポーネントを追加する
+     *
+     * 指定したRTコンポーネントを参加者リストに追加する。追加されたRTコ
+     * ンポーネントは attach_context が呼ばれ、Inactive 状態に遷移する。
+     * 指定されたRTコンポーネントがnullの場合は、BAD_PARAMETER が返され
+     * る。指定されたRTコンポーネントが DataFlowComponent 以外の場合は、
+     * BAD_PARAMETER が返される。
+     *
+     * @param comp 追加対象RTコンポーネント
+     *
+     * @return ReturnCode_t 型のリターンコード
+     *
+     * @else
+     *
+     * @brief Add an RT-component
+     *
+     * The operation causes the given RTC to begin participating in
+     * the execution context.  The newly added RTC will receive a call
+     * to LightweightRTComponent::attach_context and then enter the
+     * Inactive state.  BAD_PARAMETER will be invoked, if the given
+     * RT-Component is null or if the given RT-Component is other than
+     * DataFlowComponent.
+     *
+     * @param comp The target RT-Component for add
+     *
+     * @return The return code of ReturnCode_t type
+     *
+     * @endif
+     */
+    RTC::ReturnCode_t addComponent(RTC::LightweightRTObject_ptr comp);
+
+    /*!
+     * @if jp
+     * @brief RTコンポーネントを参加者リストから削除する
+     *
+     * 指定したRTコンポーネントを参加者リストから削除する。削除された
+     * RTコンポーネントは detach_context が呼ばれる。指定されたRTコンポー
+     * ネントが参加者リストに登録されていない場合は、BAD_PARAMETER が返
+     * される。
+     *
+     * @param comp 削除対象RTコンポーネント
+     *
+     * @return ReturnCode_t 型のリターンコード
+     *
+     * @else
+     *
+     * @brief Remove the RT-Component from participant list
+     *
+     * This operation causes a participant RTC to stop participating in the
+     * execution context.
+     * The removed RTC will receive a call to
+     * LightweightRTComponent::detach_context.
+     * BAD_PARAMETER will be returned, if the given RT-Component is not
+     * participating in the participant list.
+     *
+     * @param comp The target RT-Component for delete
+     *
+     * @return The return code of ReturnCode_t type
+     *
+     * @endif
+     */
+    RTC::ReturnCode_t removeComponent(RTC::LightweightRTObject_ptr comp);
+
+    /*!
+     * @if jp
+     * @brief RTコンポーネントの参加者リストを取得する
+     *
+     * 現在登録されている参加者RTCのリストを取得する。
+     *
+     * @return 参加者RTCのリスト
+     *
+     * @else
+     *
+     * @brief Getting participant RTC list
+     *
+     * This function returns a list of participant RTC of the execution context.
+     *
+     * @return Participants RTC list
+     *
+     * @endif
+     */
+    const RTC::RTCList& getComponentList() const;
+
+    /*!
+     * @if jp
+     * @brief Propertiesをセットする
+     *
+     * ExecutionContextProfile::properties をセットする。
+     *
+     * @param props ExecutionContextProfile::properties にセットするプ
+     *              ロパティー
+     *
+     * @else
+     * @brief Setting Properties
+     *
+     * This function sets ExecutionContextProfile::properties by
+     * coil::Properties.
+     *
+     * @param props Properties to be set to
+     *              ExecutionContextProfile::properties.
+     *
+     * @endif
+     */
+    void setProperties(coil::Properties& props);
+
+    /*!
+     * @if jp
+     * @brief Propertiesを取得する
+     *
+     * ExecutionContextProfile::properties を取得する。
+     *
+     * @return coil::Propertiesに変換された
+     *              ExecutionContextProfile::properties
+     *
+     * @else
+     * @brief Setting Properties
+     *
+     * This function sets ExecutionContextProfile::properties by
+     * coil::Properties.
+     *
+     * @param props Properties to be set to ExecutionContextProfile::properties.
+     *
+     * @endif
+     */
+    const coil::Properties getProperties() const;
+
+    /*!
+     * @if jp
+     * @brief Profileを取得する
+     *
+     * RTC::ExecutionContextProfile を取得する。取得した
+     * ExecutionContextProfile の所有権は呼び出し側にある。取得されたオ
+     * ブジェクトが不要になった場合、呼び出し側が開放する責任を負う。
+     *
+     * @return RTC::ExecutionContextProfile
+     *
+     * @else
+     * @brief Getting Profile
+     *
+     * This function gets RTC::ExecutionContextProfile.  The ownership
+     * of the obtained ExecutionContextProfile is given to caller. The
+     * caller should release obtained object when it is unneccessary
+     * anymore.
+     *
+     * @return RTC::ExecutionContextProfile
+     *
+     * @endif
+     */
+    RTC::ExecutionContextProfile* getProfile(void);
+
+    /*!
+     * @if jp
+     * @brief Profileを取得する
+     *
+     * RTC::ExecutionContextProfile を取得する。
+     *
+     * @return RTC::ExecutionContextProfile
+     *
+     * @else
+     * @brief Getting Profile
+     *
+     * This function gets RTC::ExecutionContextProfile.
+     *
+     * @return RTC::ExecutionContextProfile
+     *
+     * @endif
+     */
+    const RTC::ExecutionContextProfile& getProfile(void) const;
+
+    /*!
+     * @if jp
+     * @brief ExecutionContextProfileをロックする
+     *
+     * このオブジェクトが管理する RTC::ExecutionContextProfile をロックする。
+     * ロックが不要になった際にはunlock()でロックを解除しなければならない。
+     *
+     * @else
+     * @brief Getting a lock of RTC::ExecutionContextProfile
+     *
+     * This function locks  RTC::ExecutionContextProfile in the object.
+     * The lock should be released when the lock is unneccessary.
+     *
+     * @endif
+     */
+    void lock() const;
+
+    /*!
+     * @if jp
+     * @brief ExecutionContextProfileをアンロックする
+     *
+     * このオブジェクトが管理する RTC::ExecutionContextProfile をアンロッ
+     * クする。
+     *
+     * @else
+     * @brief Release a lock of the RTC::ExecutionContextProfile
+     *
+     * This function release the lock of RTC::ExecutionContextProfile
+     * in the object.
+     *
+     * @endif
+     */
+    void unlock() const;
+
+  private:
+    /*!
+     * @if jp
+     * @brief Logger
+     * @else
+     * @brief Logger
+     * @endif
+     */
+    mutable RTC::Logger rtclog;
+    /*!
+     * @if jp
+     * @brief ECProfile
+     * @else
+     * @brief ECProfile
+     * @endif
+     */
+    RTC::ExecutionContextProfile m_profile;
+
+    /*!
+     * @if jp
+     * @brief mutex of ExecutionContextProfile
+     * @else
+     * @brief mutex ExecutionContextProfile
+     * @endif
+     */
+    mutable 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
+     */
+    RTC::ExecutionContextService_var m_ref;
+
+    class find_participant
+    {
+      RTC::RTObject_var m_comp;
+    public:      
+      find_participant(RTC::RTObject_ptr comp)
+        : m_comp(RTC::RTObject::_duplicate(comp)) {}
+      bool operator()(RTC::RTObject_ptr comp)
+      {
+        return m_comp->_is_equivalent(comp);
+      }
+    };
+  }; // class ExecutionContextProfile
+}; // namespace RTC
+
+#ifdef WIN32
+#pragma warning( default : 4290 )
+#endif
+
+#endif // RTC_EXECUTIONCONTEXTPROFILE_H

Modified: trunk/OpenRTM-aist/src/lib/rtm/ExtTrigExecutionContext.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/ExtTrigExecutionContext.cpp	2012-01-06 07:14:38 UTC (rev 2267)
+++ trunk/OpenRTM-aist/src/lib/rtm/ExtTrigExecutionContext.cpp	2012-01-09 05:22:21 UTC (rev 2268)
@@ -106,8 +106,11 @@
    */
   void ExtTrigExecutionContextInit(RTC::Manager* manager)
   {
-    manager->registerECFactory("ExtTrigExecutionContext",
-			       RTC::ECCreate<RTC::ExtTrigExecutionContext>,
-			       RTC::ECDelete<RTC::ExtTrigExecutionContext>);
+    RTC::ExecutionContextFactory::
+      instance().addFactory("ExtTrigExecutionContext",
+                            ::coil::Creator< ::RTC::ExecutionContextBase,
+                            ::RTC::ExtTrigExecutionContext>,
+                            ::coil::Destructor< ::RTC::ExecutionContextBase,
+                            ::RTC::ExtTrigExecutionContext>);
   }
 };

Modified: trunk/OpenRTM-aist/src/lib/rtm/Makefile.am
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/Makefile.am	2012-01-06 07:14:38 UTC (rev 2267)
+++ trunk/OpenRTM-aist/src/lib/rtm/Makefile.am	2012-01-09 05:22:21 UTC (rev 2268)
@@ -64,6 +64,8 @@
 
 COMP_SRC =                           \
 	DataFlowComponentBase.cpp    \
+	ExecutionContextBase.cpp     \
+	ExecutionContextProfile.cpp  \
 	PeriodicExecutionContext.cpp \
 	ExtTrigExecutionContext.cpp  \
 	OpenHRPExecutionContext.cpp  \

Modified: trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp	2012-01-06 07:14:38 UTC (rev 2267)
+++ trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp	2012-01-09 05:22:21 UTC (rev 2268)
@@ -1656,7 +1656,14 @@
     for (CORBA::ULong i(0), len(m_ecs.size()); i < len; ++i)
       {
 	try{
-          PortableServer::ObjectId_var oid = m_pPOA->servant_to_id(m_ecs[i]);
+      PortableServer::RefCountServantBase* servant;
+      servant = dynamic_cast<PortableServer::RefCountServantBase*>(m_ecs[i]);
+      if (servant == NULL)
+        {
+          RTC_ERROR(("Invalid dynamic cast. EC->RefCountServantBase failed."));
+          return;
+        }
+      PortableServer::ObjectId_var oid = m_pPOA->servant_to_id(servant);
 	  m_pPOA->deactivate_object(oid);
 	}
 	catch (...)
@@ -1664,6 +1671,7 @@
 	    ;
 	  }
       }
+    return;
   }
   
   /*!

Modified: trunk/OpenRTM-aist/src/lib/rtm/OpenHRPExecutionContext.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/OpenHRPExecutionContext.cpp	2012-01-06 07:14:38 UTC (rev 2267)
+++ trunk/OpenRTM-aist/src/lib/rtm/OpenHRPExecutionContext.cpp	2012-01-09 05:22:21 UTC (rev 2268)
@@ -67,9 +67,11 @@
    */
   void OpenHRPExecutionContextInit(RTC::Manager* manager)
   {
-    manager->registerECFactory("SynchExtTriggerEC",
-			       RTC::ECCreate<RTC::OpenHRPExecutionContext>,
-			       RTC::ECDelete<RTC::OpenHRPExecutionContext>);
-    
+    RTC::ExecutionContextFactory::
+      instance().addFactory("SynchExtTriggerEC",
+                            ::coil::Creator< ::RTC::ExecutionContextBase,
+                            ::RTC::OpenHRPExecutionContext>,
+                            ::coil::Destructor< ::RTC::ExecutionContextBase,
+                            ::RTC::OpenHRPExecutionContext>);
   }
 };

Modified: trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp	2012-01-06 07:14:38 UTC (rev 2267)
+++ trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp	2012-01-09 05:22:21 UTC (rev 2268)
@@ -256,8 +256,10 @@
     throw (CORBA::SystemException)
   {
     RTC_TRACE(("stop()"));
-    if (!m_running) return RTC::PRECONDITION_NOT_MET;
-    
+    if (!m_running)
+      {
+        return RTC::PRECONDITION_NOT_MET;
+      }
     // stop thread
     m_running = false;
     {
@@ -267,10 +269,10 @@
     }
     // invoke on_shutdown for each comps.
     std::for_each(m_comps.begin(), m_comps.end(), invoke_on_shutdown());
-   
+
     return RTC::RTC_OK;
   }
-  
+
   /*!
    * @if jp
    * @brief ExecutionContext の実行周期(Hz)を取得する
@@ -285,7 +287,7 @@
     Guard guard(m_profileMutex);
     return m_profile.rate;
   }
-  
+
   /*!
    * @if jp
    * @brief ExecutionContext の実行周期(Hz)を設定する
@@ -303,23 +305,23 @@
           Guard guard(m_profileMutex);
           m_profile.rate = rate;
         }
-	m_period = coil::TimeValue(1.0/rate);
-	if (m_period == 0.0) { m_nowait = true; }
-	std::for_each(m_comps.begin(), m_comps.end(), invoke_on_rate_changed());
+        m_period = coil::TimeValue(1.0/rate);
+        if (m_period == 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()));
-	return RTC::RTC_OK;
+        return RTC::RTC_OK;
       }
     return RTC::BAD_PARAMETER;
   }
-  
+
   /*!
    * @if jp
    * @brief RTコンポーネントをアクティブ化する
    * @else
    * @brief Activate an RT-Component
    * @endif
-   */ 
+   */
   ReturnCode_t
   PeriodicExecutionContext::activate_component(LightweightRTObject_ptr comp)
     throw (CORBA::SystemException)
@@ -329,7 +331,7 @@
 #ifndef ORB_IS_RTORB
     CompItr it;
     it = std::find_if(m_comps.begin(), m_comps.end(),
-		      find_comp(comp));
+                      find_comp(comp));
 
     if (it == m_comps.end())
       return RTC::BAD_PARAMETER;
@@ -356,14 +358,14 @@
     return RTC::BAD_PARAMETER;
 #endif // ORB_IS_RTORB
   }
-  
+
   /*!
    * @if jp
    * @brief RTコンポーネントを非アクティブ化する
    * @else
    * @brief Deactivate an RT-Component
    * @endif
-   */  
+   */
   ReturnCode_t
   PeriodicExecutionContext::deactivate_component(LightweightRTObject_ptr comp)
     throw (CORBA::SystemException)
@@ -373,13 +375,13 @@
 #ifndef ORB_IS_RTORB
     CompItr it;
     it = std::find_if(m_comps.begin(), m_comps.end(),
-		      find_comp(comp));
+                      find_comp(comp));
     if (it == m_comps.end()) { return RTC::BAD_PARAMETER; }
     if (!(it->_sm.m_sm.isIn(ACTIVE_STATE)))
       {
         return RTC::PRECONDITION_NOT_MET;
       }
-    
+
     it->_sm.m_sm.goTo(INACTIVE_STATE);
     int count(0);
     const double usec_per_sec(1.0e6);
@@ -387,7 +389,8 @@
     RTC_PARANOID(("Sleep time is %f [us]", sleeptime));
     while (it->_sm.m_sm.isIn(ACTIVE_STATE))
       {
-        RTC_TRACE(("Waiting to be the INACTIVE state %d %f", count, (double)coil::gettimeofday()));
+        RTC_TRACE(("Waiting to be the INACTIVE state %d %f",
+                   count, (double)coil::gettimeofday()));
         coil::usleep(sleeptime);
         if (count > 1000)
           {
@@ -421,7 +424,6 @@
               {
                 RTC_TRACE(("Waiting to be the INACTIVE state"));
                 coil::usleep(sleeptime);
-                
                 if (count > 1000)
                   {
                     RTC_ERROR(("The component is not responding."));
@@ -441,14 +443,14 @@
     return RTC::BAD_PARAMETER;
 #endif // ORB_IS_RTORB
   }
-  
+
   /*!
    * @if jp
    * @brief RTコンポーネントをリセットする
    * @else
    * @brief Reset the RT-Component
    * @endif
-   */  
+   */
   ReturnCode_t
   PeriodicExecutionContext::reset_component(LightweightRTObject_ptr comp)
     throw (CORBA::SystemException)
@@ -456,17 +458,19 @@
     RTC_TRACE(("reset_component()"));
     CompItr it;
     it = std::find_if(m_comps.begin(), m_comps.end(),
-		      find_comp(comp));
+                      find_comp(comp));
     if (it == m_comps.end())
-      return RTC::BAD_PARAMETER;
-    
+      {
+        return RTC::BAD_PARAMETER;
+      }
     if (!(it->_sm.m_sm.isIn(ERROR_STATE)))
-      return RTC::PRECONDITION_NOT_MET;
-    
+      {
+        return RTC::PRECONDITION_NOT_MET;
+      }
     it->_sm.m_sm.goTo(INACTIVE_STATE);
     return RTC::RTC_OK;
   }
-  
+
   /*!
    * @if jp
    * @brief RTコンポーネントの状態を取得する
@@ -485,9 +489,9 @@
 
     if (it == m_comps.end())
       {
-	return RTC::CREATED_STATE;
+        return RTC::CREATED_STATE;
       }
-    
+
     return it->_sm.m_sm.getState();
 #else // ORB_IS_RTORB
     for (int i(0); i < (int)m_comps.size(); ++i)
@@ -497,10 +501,10 @@
             return m_comps.at(i)._sm.m_sm.getState();
           }
       }
-    return RTC::CREATED_STATE; 
+    return RTC::CREATED_STATE;
 #endif // ORB_IS_RTORB
   }
-  
+
   /*!
    * @if jp
    * @brief ExecutionKind を取得する
@@ -514,7 +518,7 @@
     RTC_TRACE(("get_kind()"));
     return m_profile.kind;
   }
-  
+
   /*!
    * @if jp
    * @brief RTコンポーネントを追加する
@@ -528,28 +532,28 @@
   {
     RTC_TRACE(("add_component()"));
     if (CORBA::is_nil(comp)) return RTC::BAD_PARAMETER;
-    
+
     try
       {
-	OpenRTM::DataFlowComponent_var dfp;
-	dfp = OpenRTM::DataFlowComponent::_narrow(comp);
+        OpenRTM::DataFlowComponent_var dfp;
+        dfp = OpenRTM::DataFlowComponent::_narrow(comp);
         RTC::RTObject_var rtc;
         rtc = RTC::RTObject::_narrow(comp);
         //Check the pointer.
         if(CORBA::is_nil(dfp) || CORBA::is_nil(rtc))
           {
-	    return RTC::BAD_PARAMETER;
+            return RTC::BAD_PARAMETER;
           }
-	ExecutionContextHandle_t id;
-	id = dfp->attach_context(m_ref);
-	m_comps.push_back(Comp(comp, dfp, id));
+        ExecutionContextHandle_t id;
+        id = dfp->attach_context(m_ref);
+        m_comps.push_back(Comp(comp, dfp, id));
         CORBA_SeqUtil::push_back(m_profile.participants, rtc._retn());
-	return RTC::RTC_OK;
+        return RTC::RTC_OK;
       }
     catch (CORBA::Exception& e)
       {
-	(void)(e);
-	return RTC::BAD_PARAMETER;
+        (void)(e);
+        return RTC::BAD_PARAMETER;
       }
     return RTC::RTC_OK;
   }
@@ -578,14 +582,14 @@
 
     return RTC::RTC_OK;
   }
-  
+
   /*!
    * @if jp
    * @brief コンポーネントをコンポーネントリストから削除する
    * @else
    * @brief Remove the RT-Component from participant list
    * @endif
-   */	
+   */
   ReturnCode_t
   PeriodicExecutionContext::remove_component(LightweightRTObject_ptr comp)
     throw (CORBA::SystemException)
@@ -593,7 +597,7 @@
     RTC_TRACE(("remove_component()"));
     CompItr it;
     it = std::find_if(m_comps.begin(), m_comps.end(),
-		      find_comp(comp));
+                      find_comp(comp));
     if (it == m_comps.end())
       {
         RTC_TRACE(("remove_component(): no RTC found in this context."));
@@ -606,7 +610,6 @@
     m_comps.erase(it);
     RTC_TRACE(("remove_component(): an RTC removed from this context."));
 
-    //RTObject_var rtcomp = RTObject::_narrow(LightweightRTObject::_duplicate(comp));
     RTObject_var rtcomp = RTObject::_narrow(comp);
     if (CORBA::is_nil(rtcomp))
       {
@@ -655,9 +658,12 @@
    */
   void PeriodicExecutionContextInit(RTC::Manager* manager)
   {
-    manager->registerECFactory("PeriodicExecutionContext",
-			       RTC::ECCreate<RTC::PeriodicExecutionContext>,
-			       RTC::ECDelete<RTC::PeriodicExecutionContext>);
+    RTC::ExecutionContextFactory::
+      instance().addFactory("PeriodicExecutionContext",
+                            ::coil::Creator< ::RTC::ExecutionContextBase,
+                            ::RTC::PeriodicExecutionContext>,
+                            ::coil::Destructor< ::RTC::ExecutionContextBase,
+                            ::RTC::PeriodicExecutionContext>);
   }
 };
 

Modified: trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h	2012-01-06 07:14:38 UTC (rev 2267)
+++ trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h	2012-01-09 05:22:21 UTC (rev 2268)
@@ -62,11 +62,16 @@
    * @endif
    */
   class PeriodicExecutionContext
-    : public virtual ExecutionContextBase,
+    : public virtual POA_OpenRTM::ExtTrigExecutionContextService,
+      public virtual PortableServer::RefCountServantBase,
+      public virtual ExecutionContextBase,
       public coil::Task
   {
     typedef coil::Guard<coil::Mutex> Guard;
   public:
+    virtual void tick()
+      throw (CORBA::SystemException)
+    {};
     /*!
      * @if jp
      * @brief デフォルトコンストラクタ

Modified: trunk/OpenRTM-aist/src/lib/rtm/RTObject.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/RTObject.cpp	2012-01-06 07:14:38 UTC (rev 2267)
+++ trunk/OpenRTM-aist/src/lib/rtm/RTObject.cpp	2012-01-09 05:22:21 UTC (rev 2268)
@@ -311,26 +311,48 @@
     throw (CORBA::SystemException)
   {
     RTC_TRACE(("initialize()"));
+    std::string ec_type;
     std::string ec_args;
 
+    ec_type = m_properties["exec_cxt.periodic.type"];
     ec_args += m_properties["exec_cxt.periodic.type"];
     ec_args += "?";
     ec_args += "rate=" + m_properties["exec_cxt.periodic.rate"];
 
     RTC::ExecutionContextBase* ec;
-    ec = RTC::Manager::instance().createContext(ec_args.c_str());
-    if (ec == NULL) return RTC::RTC_ERROR;
+    ec = RTC::ExecutionContextFactory::instance().createObject(ec_type.c_str());
+    if (ec == NULL)
+      {
+        RTC_ERROR(("EC (%s) creation failed.", ec_type.c_str()));
+        coil::vstring ecs;
+        ecs = RTC::ExecutionContextFactory::instance().getIdentifiers();
+        RTC_DEBUG(("Available EC list: %s",
+                   coil::flatten(ecs).c_str()));
+        return RTC::RTC_ERROR;
+      }
+    RTC_DEBUG(("EC (%s) created.", ec_type.c_str()));
 
-    ec->set_rate(atof(m_properties["exec_cxt.periodic.rate"].c_str()));
     m_eclist.push_back(ec);
     ExecutionContextService_var ecv;
     ecv = RTC::ExecutionContextService::_duplicate(ec->getObjRef());
-    if (CORBA::is_nil(ecv)) return RTC::RTC_ERROR;
+    if (CORBA::is_nil(ecv))
+      {
+        RTC_ERROR(("Getting object reference of ec failed."));
+        return RTC::RTC_ERROR;
+      }
+    double ec_rate;
+    coil::stringTo(ec_rate, m_properties["exec_cxt.periodic.rate"].c_str());
+    ecv->set_rate(ec_rate);
+    RTC_DEBUG(("Execution context rate is set to %f.", ec_rate));
 
     ec->bindComponent(this);
     // -- entering alive state --
     // at least one EC must be attached
-    if (m_ecMine.length() == 0) return RTC::PRECONDITION_NOT_MET;
+    if (m_ecMine.length() == 0)
+      {
+        RTC_ERROR(("No EC of this RTC."));
+        return RTC::PRECONDITION_NOT_MET;
+      }
 
     ReturnCode_t ret;
     ret = on_initialize();
@@ -792,7 +814,7 @@
       }
     catch (...)
       {
-        RTC_ERRIR(("onInitialize() raised an exception."));
+        RTC_ERROR(("onInitialize() raised an exception."));
         ret = RTC::RTC_ERROR;
       }
     std::string active_set;
@@ -2125,12 +2147,22 @@
     RTC_TRACE(("finalizeContexts()"));
     for (int i(0), len(m_eclist.size()); i < len; ++i)
       {
-        m_eclist[i]->stop();
+        m_eclist[i]->getObjRef()->stop();
         try
           {
+            PortableServer::RefCountServantBase* servant(NULL);
+            servant =
+              dynamic_cast<PortableServer::RefCountServantBase*>(m_eclist[i]);
+            if (servant == NULL)
+              {
+                RTC_ERROR(("Dynamic cast error: ECBase -> Servant."));
+                continue;
+              }
+            RTC_DEBUG(("Deactivating Execution Context."));
             PortableServer::ObjectId_var oid
-              = m_pPOA->servant_to_id(m_eclist[i]);
+              = m_pPOA->servant_to_id(servant);
             m_pPOA->deactivate_object(oid);
+            RTC_DEBUG(("Deactivating EC done."));
           }
         catch (PortableServer::POA::ServantNotActive &e)
           {



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