[openrtm-commit:01057] r558 - in trunk/OpenRTM-aist-Python: . OpenRTM_aist OpenRTM_aist/examples OpenRTM_aist/test

openrtm @ openrtm.org openrtm @ openrtm.org
2013年 4月 26日 (金) 23:52:58 JST


Author: n-ando
Date: 2013-04-26 23:52:58 +0900 (Fri, 26 Apr 2013)
New Revision: 558

Added:
   trunk/OpenRTM-aist-Python/OpenRTM_aist/ClockManager.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextProfile.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextWorker.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObjectStateMachine.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ClockManager.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextBase.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextProfile.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextWorker.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_RTObjectStateMachine.py
Modified:
   trunk/OpenRTM-aist-Python/
   trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextBase.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/ExtTrigExecutionContext.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/GlobalFactory.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceAdmin.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/ManagerConfig.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/OpenHRPExecutionContext.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObject.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/StateMachine.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/TimeMeasure.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/examples/component.conf
   trunk/OpenRTM-aist-Python/OpenRTM_aist/examples/rtc.conf.sample
   trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExtTrigExecutionContext.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_GlobalFactory.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_PeriodicExecutionContext.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_RTObject.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_TimeMeasure.py
Log:
merged r504-542


Property changes on: trunk/OpenRTM-aist-Python
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/RELENG_1_0/OpenRTM-aist-Python:345-404
/branches/RELENG_1_1/OpenRTM-aist-Python:396-478,488-497
/branches/work/OpenRTM-aist-Python:505-509
   + /branches/RELENG_1_0/OpenRTM-aist-Python:345-404
/branches/RELENG_1_1/OpenRTM-aist-Python:396-478,488-497
/branches/work/OpenRTM-aist-Python:504-542

Copied: trunk/OpenRTM-aist-Python/OpenRTM_aist/ClockManager.py (from rev 542, branches/work/OpenRTM-aist-Python/OpenRTM_aist/ClockManager.py)
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/ClockManager.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/ClockManager.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -0,0 +1,221 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file ClockManager.py
+# @brief Global clock management class
+# @date $Date$
+# @author Noriaki Ando <n-ando at aist.go.jp>
+#
+# Copyright (C) 2012
+#     Noriaki Ando
+#     Intelligent Systems Research Institute,
+#     National Institute of
+#         Advanced Industrial Science and Technology (AIST), Japan
+#     All rights reserved.
+#
+# $Id$
+#
+
+import threading
+import OpenRTM_aist
+
+
+##
+# @if jp
+# @class 時刻設定・取得オブジェクトのインターフェース
+#
+# このクラスは ClockManager によって管理されるクロックオブジェクトの
+# ためのインターフェースである。ClockManager は複数のクロックオブジェ
+# クトを管理し、必要に応じて適切なクロックオブジェクトを IClock イン
+# ターフェースをもつオブジェクトとして返す。クロックオブジェクトは単
+# にシステム時刻を返すものや、独自の論理時刻を持つクロックオブジェク
+# ト等が考えられる。
+#
+# @else
+# @brief An interface to set and get time
+#
+# This class is a interface for clock objects managed by
+# ClockManager. ClockManager manages one or more clocks, and it
+# returns appropriate clock objects according to demands. The clock
+# object might be clock which just returns system time, or a clock
+# which returns individual logical time.
+#
+# @endif
+class IClock:
+  """
+  """
+
+  ##
+  # @if jp
+  # @brief 時刻を取得する
+  # @return 現在の時刻
+  # @else
+  # @brief Getting time
+  # @return Current time
+  # @endif
+  # virtual coil::TimeValue gettime() const = 0;
+  def gettime(self):
+    pass
+
+
+  ##
+  # @if jp
+  # @brief 時刻を設定する
+  # @param clocktime 現在の時刻
+  # @else
+  # @brief Setting time
+  # @param clocktime Current time
+  # @endif
+  # virtual bool settime(coil::TimeValue clocktime) = 0;
+  def settime(self, clocktime):
+    pass
+
+
+##
+# @if jp
+# @class システム時刻を扱うクロックオブジェクト
+#
+# このクラスはシステムクロックを設定または取得するクラスである。
+#
+# @else
+# @brief clock object to handle system clock
+#
+# This class sets and gets system clock.
+#
+# @endif
+class SystemClock(IClock):
+  """
+  """
+
+  # virtual coil::TimeValue gettime() const;
+  def gettime(self):
+    return OpenRTM_aist.Time().getTime()
+
+  # virtual bool settime(coil::TimeValue clocktime);
+  def settime(self, clocktime):
+    return OpenRTM_aist.Time().settimeofday(clocktime, 0)
+
+
+##
+# @if jp
+# @class 論理時間を扱うクロックオブジェクト
+#
+# このクラスは論理時間を設定または取得するクラスである。
+# 単純に settime() によって設定された時刻を gettime() によって取得する。
+#
+# @else
+# @brief Clock object to handle logical clock
+#
+# This class sets and gets system clock.
+# It just sets time by settime() and gets time by gettime().
+#
+# @endif
+class LogicalClock(IClock):
+  """
+  """
+
+  def __init__(self):
+    self._currentTime = OpenRTM_aist.TimeValue(0.0)
+    self._currentTimeMutex = threading.RLock()
+    return
+
+  # virtual coil::TimeValue gettime() const;
+  def gettime(self):
+    guard = OpenRTM_aist.ScopedLock(self._currentTimeMutex)
+    return self._currentTime
+
+  # virtual bool settime(coil::TimeValue clocktime);
+  def settime(self, clocktime):
+    guard = OpenRTM_aist.ScopedLock(self._currentTimeMutex)
+    self._currentTime = clocktime
+    return True
+    
+
+##
+# @if jp
+# @class 調整済み時刻を扱うクロックオブジェクト
+#
+# settime() 呼び出し時に現在時刻との差をオフセットとして保持し、
+# gettime() によってオフセット調整済みの時刻を返す。
+#
+# @else
+# @brief Clock object to handle adjusted clock
+#
+# This class stores a offset time with current system clock when
+# settime(), and gettime() returns adjusted clock by the offset.
+#
+# @endif
+class AdjustedClock(IClock):
+  """
+  """
+
+  def __init__(self):
+    self._offset = OpenRTM_aist.TimeValue(0.0)
+    self._offsetMutex = threading.RLock()
+    return
+
+
+  # virtual coil::TimeValue gettime() const;
+  def gettime(self):
+    guard = OpenRTM_aist.ScopedLock(self._offsetMutex)
+    return OpenRTM_aist.Time().getTime() - self._offset
+    
+  # virtual bool settime(coil::TimeValue clocktime);
+  def settime(self, clocktime):
+    guard = OpenRTM_aist.ScopedLock(self._offsetMutex)
+    self._offset = OpenRTM_aist.Time().getTime() - clocktime
+    return True
+
+clockmgr = None
+clockmgr_mutex = threading.RLock()
+
+##
+# @if jp
+# @class グローバルなクロック管理クラス。
+#
+# このクラスはグローバルにクロックオブジェクトを提供するシングルトン
+# クラスである。getClocK(クロック名) により IClock 型のクロックオブ
+# ジェクトを返す。利用可能なクロックは "system", "logical" および
+# "adjusted" の3種類である。
+#
+# @else
+# @brief A global clock management class
+#
+# This class is a singleton class that provides clock objects
+# globally. It provides a IClock object by getClock(<clock
+# type>). As clock types, "system", "logical" and "adjusted" are
+# available.
+#
+# @endif
+class ClockManager:
+  """
+  """
+  
+  def __init__(self):
+    self._systemClock   = SystemClock()
+    self._logicalClock  = LogicalClock()
+    self._adjustedClock = AdjustedClock()
+    return
+
+  def getClock(self, clocktype):
+    if clocktype == "logical":
+      return self._logicalClock
+    elif clocktype == "adjusted":
+      return self._adjustedClock
+    elif clocktype == "system":
+      return self._systemClock
+
+    return self._systemClock
+
+  def instance():
+    global clockmgr
+    global clockmgr_mutex
+
+    if not clockmgr:
+      guard = OpenRTM_aist.ScopedLock(clockmgr_mutex)
+      clockmgr = ClockManager()
+
+    return clockmgr
+  instance = staticmethod(instance)
+

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -64,7 +64,8 @@
                  "corba.nameservice.replace_endpoint", "NO",
                  "exec_cxt.periodic.type",           "PeriodicExecutionContext",
                  "exec_cxt.periodic.rate",           "1000",
-                 "exec_cxt.evdriven.type",           "EventDrivenExecutionContext",
+                 "exec_cxt.sync_transition",         "YES",
+                 "exec_cxt.transition_timeout",      "0.5",
                  "manager.modules.load_path",        "./",
                  "manager.modules.abs_path_allowed", "YES",
                  "manager.is_master",                "NO",

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextBase.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextBase.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextBase.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -7,35 +7,421 @@
 # @date $Date: 2007/08/31$
 # @author Noriaki Ando <n-ando at aist.go.jp> and Shinji Kurihara
 #
-# Copyright (C) 2007-2008
+# Copyright (C) 2011
 #    Task-intelligence Research Group,
 #    Intelligent Systems Research Institute,
 #    National Institute of
 #       Advanced Industrial Science and Technology (AIST), Japan
 #    All rights reserved.
 
-
-import OpenRTM__POA
+import time
 import OpenRTM_aist
+import RTC
 
+DEFAULT_EXECUTION_RATE = 1000
+
 ##
 # @if jp
 # @class ExecutionContextBase
 # @brief ExecutionContext用基底クラス
 #
+# ECの実装クラスでは、この基底クラスを継承し、かつECのCORBAオペレー
+# ションを実装しなければならない。さらに、実際にロジックを駆動するた
+# め、幾つかの約束に則りExecutionContextBaseの関数を呼び出す必要があ
+# る。ECのCORBAオペレーションは以下のものがあり、それぞれ
+# ExecutionContextBaseのメンバ関数に対応している。
+#
+# - is_running(): ExecutionContextBase.isRunning()
+# - start(): ExecutionContextBase.start()
+# - stop(): ExecutionContextBase.stop()
+#
+# - get_rate(): ExecutionContextBase.gatRate()
+# - set_rate(): ExecutioinContextBase.setRate()
+#
+# - add_component(): ExecutionContextBase.addComponent()
+# - remove_component(): ExecutionContextBase.removeComponent()
+#
+# - activate_component(): ExecutionContextBase.activateComponent()
+# - deactivate_component(): ExecutionContextBase.deactivateComponent()
+# - reset_component(): ExecutionContextBase.resetComponent()
+#
+# - get_component_state(): ExecutionContextBase.getComponentState()
+# - get_kind(): ExecutionContextBase.getKind()
+# - get_profile(): ExecutionContextBase.getProfile()
+#
+# @par 実行状態に関係する関数と実装方法
+# - is_running(): ExecutionContextBase.isRunning()
+# - start(): ExecutionContextBase.start()
+# - stop(): ExecutionContextBase.stop()
+#
+# 実行状態に関係する関数は、is_running(), start(), stop() の3つがあ
+# る。ExecutionContextBaseでは単純に running/stopped のフラグを持っ
+# ており、start/stopでフラグのON/OFF切り替え、is_running()で状態読み
+# 出しを行っている。通常、ECの実装クラスでは、protected な仮想メン
+# バ関数 onStarting(), onStarted(), onStopping(), onStopped() 関数を
+# 実装したうえで、CORBAオペレーションを以下のように実装する必要がある。
+#
+# is_running() のCORBAオペレーションでは、単純に
+# ExecutionContextBase の isRunning() を呼び出すだけである。この関数
+# に関連する protected 仮想関数はonIsRunning() が用意されているが、
+# 通常特に実装する必要はない。あえて、現在の running/stopped 状態を
+# 書き換えたい場合にこの関数を利用することができるが推奨はされない。
+#
+# <pre>
+# public:
+#  CORBA::Boolean is_runing()
+#  {
+#    return ExecutionContextBase::isRunning();
+#  }
+# protected:
+#  CORBA::Boolean onIsRunning(CORBA::Boolean running)
+#  {
+#    return running;
+#  }
+# </pre>
+#
+# start(), stop() CORBAオペレーションでは、通常
+# ExecutionContextBase の start(), stop() 関数を呼び出すよう実装する。
+# この関数に関連する protected 仮想関数は、start() および stop() に
+# ついてそれぞれ2つづつの onStarting(), onStarted(), および
+# onStopping(), onStopped() 関数がある。ECの実装クラスにおいては、そ
+# れぞれ以下のように実装する。
+#
+# <pre>
+#  RTC::ReturnCode_t start()
+#  {
+#    return ExecutionContextBase::start();
+#  }
+#  RTC::ReturnCode_t stop()
+#  {
+#    return ExecutionContextBase::stop();
+#  }
+# protected:
+#  RTC::ReturnCode_t onStarting()
+#  {
+#    RTC::ReturnCode_t ret = // スレッドを開始する処理など
+#    return ret;
+#  }
+#  RTC::ReturnCode_t onStarted()
+#  {
+#    RTC::ReturnCode_t ret = // スレッドを開始する処理など
+#    return ret;
+#  }
+#  RTC::ReturnCode_t onStopping()
+#  {
+#    // スレッドを停止する処理など
+#    return retcode;
+#  }
+#  RTC::ReturnCode_t onStopped()
+#  {
+#    // スレッドを停止する処理など
+#    return retcode;
+#  }
+# </pre>
+#
+# @par 実行周期に関する関数と実装方法
+# - get_rate(): ExecutionContextBase.gatRate()
+# - set_rate(): ExecutioinContextBase.setRate()
+#
+# 実行周期に関する関数は set_rate(), get_rate() の2種類がある。実装
+# する実行コンテキストがもし set_rate() により指定される周期を利用する
+# 場合、テンプレート関数 onSetRate() をオーバーライドし実装する。
+# onSetRate() は引数に double 型の周期を取り、この値は正当な値である
+# ことが保証されている。onSetRate() がRTC::RTC_OK 以外の値を返した場
+# 合、ECのProfileの周期は設定される以前の値を保持することが保証され
+# る。
+#
+# set_rate() 同様 get_rate() 呼び出し時にonGetRate() が呼び出される
+# が、これは通常オーバーライドする必要はない。ただし、get_rate() が
+# 返す値を変更したい場合、onGetRate() をオーバーライドすることでその
+# 値を書き換えることができる。ただし、これは推奨されない。
+#
+# <pre>
+# public:
+#  RTC::ReturnCode_t set_rate(double rate)
+#  {
+#    return setRate(rate);
+#  }
+#  double get_rate(void) const
+#  {
+#    return getRate();
+#  }
+# protected:
+#  virtual RTC::ReturnCode_t onSetRate(double rate)
+#  {
+#    RTC::ReturnCode_t ret = // 周期を設定する何らかの処理
+#    if (ret != RTC::RTC_OK)
+#      {
+#        RTC_ERROR(("Error message"));
+#      }
+#    return ret;
+#  }
+#  virtual double onGetRate(rate)
+#  {
+#    // get_rate() が返す値を加工したい場合
+#    // 通常はこの関数を実装する必要はない。
+#    return rate;
+#  }
+# </pre>
+#
+# @par コンポーネントの追加と削除に関する関数
+# - add_component(): ExecutionContextBase.addComponent()
+# - remove_component(): ExecutionContextBase.removeComponent()
+#
+# コンポーネントの追加と削除に関する関数は、add_component(),
+# remove_component() の二種類がある。実行コンテキストの実装クラスに
+# おいては、ExecutionContextBase のそれぞれ addComponent(),
+# removeComponent() を呼び出す形で実装を行う。これらの関数に関連する
+# protected 仮想関数は onAddingComponent(), onAddedComponent(),
+# onRemovingComponent(), onRemovedComponent() の4種類ある。ただし、
+# これらの仮想関数は通常オーバーライドする必要はなく、使用は推奨され
+# ない。
+#
+# <pre>
+# public:
+#  RTC::ReturnCode_t add_component(RTC::LightweightRTObject_ptr comp)
+#  {
+#    return ExecutionContextBase::addComponent(comp);
+#  }
+#  RTC::ReturnCode_t remove_component(RTC::LightweightRTObject_ptr comp)
+#  {
+#    return ExecutionContextBase::removeComponent(comp);
+#  }
+# protected:
+#  virtual RTC::ReturnCode_t
+#  onAddingComponent(RTC::LightweightRTObject rtobj)
+#  {
+#     // コンポーネント追加時に実行したい処理を記述
+#     // RTC::RTC_OK 以外を返した場合、コンポーネントの追加は行われない。
+#     return RTC::RTC_OK;
+#  }
+#  virtual RTC::ReturnCode_t
+#  onAddedComponent(RTC::LightweightRTObject rtobj)
+#  {
+#     // コンポーネント追加時に実行したい処理を記述
+#     // RTC::RTC_OK 以外を返した場合、removeComponent() が呼び出され、
+#     // 追加されたコンポーネントが削除される。
+#     return RTC::RTC_OK;
+#  }
+#  virtual RTC::ReturnCode_t
+#  onRemovingComponent(RTC::LightweightRTObject rtobj)
+#  {
+#     // コンポーネント削除時に実行したい処理を記述
+#     // RTC::RTC_OK 以外を返した場合、コンポーネントの削除は行われない。
+#     return RTC::RTC_OK;
+#  }
+#  virtual RTC::ReturnCode_t
+#  onRemovedComponent(RTC::LightweightRTObject rtobj)
+#  {
+#     // コンポーネント追加時に実行したい処理を記述
+#     // RTC::RTC_OK 以外を返した場合、addComponent() が呼び出され、
+#     // 削除されたコンポーネントが再び追加される。
+#     return RTC::RTC_OK;
+#  }
+# </pre>
+#
+# @par コンポーネントのアクティブ化等に関する関数
+# - activate_component(): ExecutionContextBase.activateComponent()
+# - deactivate_component(): ExecutionContextBase.deactivateComponent()
+# - reset_component(): ExecutionContextBase.resetComponent()
+#
+# コンポーネントのアクティブ化等に関する関数は、
+# activate_component(), deactivate_component(), reset_component() の
+# 三種類がある。実行コンテキストの実装クラスにおいては、
+# ExecutionContextBase のそれぞれ activateComponent(),
+# deactivateComponent(), resetComponent() を呼び出す形で実装を行う。
+# これらの関数に関連する protected 仮想関数は
+# onActivatingComponent(), onAtivatingComponent(),
+# onActivatedComponent(), onDeactivatingComponent(),
+# onDeactivatedComponent(), onResettingComponent(),
+# onResetComponent() の6種類ある。ただし、これらの仮想関数は通常オー
+# バーライドする必要はなく、使用は推奨されない。
+#
+# <pre>
+# public:
+#  RTC::ReturnCode_t add_component(RTC::LightweightRTObject_ptr comp)
+#  {
+#    return ExecutionContextBase::addComponent(comp);
+#  }
+#  RTC::ReturnCode_t remove_component(RTC::LightweightRTObject_ptr comp)
+#  {
+#    return ExecutionContextBase::removeComponent(comp);
+#  }
+# protected:
+#  virtual RTC::ReturnCode_t
+#  onAddingComponent(RTC::LightweightRTObject rtobj)
+#  {
+#    // コンポーネント追加時に実行したい処理を記述
+#    // RTC::RTC_OK 以外を返した場合、コンポーネントの追加は行われない。
+#    return RTC::RTC_OK;
+#  }
+#  virtual RTC::ReturnCode_t
+#  onAddedComponent(RTC::LightweightRTObject rtobj)
+#  {
+#    // コンポーネント追加時に実行したい処理を記述
+#    // RTC::RTC_OK 以外を返した場合、removeComponent() が呼び出され、
+#    // 追加されたコンポーネントが削除される。
+#    return RTC::RTC_OK;
+#  }
+#  virtual RTC::ReturnCode_t
+#  onRemovingComponent(RTC::LightweightRTObject rtobj)
+#  {
+#    // コンポーネント削除時に実行したい処理を記述
+#    // RTC::RTC_OK 以外を返した場合、コンポーネントの削除は行われない。
+#    return RTC::RTC_OK;
+#  }
+#  virtual RTC::ReturnCode_t
+#  onRemovedComponent(RTC::LightweightRTObject rtobj)
+#  {
+#    // コンポーネント追加時に実行したい処理を記述
+#    // RTC::RTC_OK 以外を返した場合、addComponent() が呼び出され、
+#    // 削除されたコンポーネントが再び追加される。
+#    return RTC::RTC_OK;
+#  }
+# </pre>
+#
+# @par 実行コンテキストの情報取得に関する関数
+# - get_component_state(): ExecutionContextBase.getComponentState()
+# - get_kind(): ExecutionContextBase.getKind()
+# - get_profile(): ExecutionContextBase.getProfile()
+#
+# 実行コンテキストの情報取得に関する関数は、get_component_state(),
+# get_kind(), get_profile() の3種類がある。実行コンテキストの実装ク
+# ラスにおいては、ExecutionContextBase のそれぞれ
+# getComponentState(), getKind(), getProfile() を呼び出す形で実装を
+# 行う。これらの関数に関連する protected 仮想関数は
+# onGetComponentState(), onGetKind(), onGetProfile() の3種類ある。こ
+# れらの仮想関数は通常オーバーライドする必要はなく、使用は推奨されな
+# い。ただし、返す情報を変更したい場合は、これらの関数を適切に実装す
+# ることで、呼び出し側に返す値を上書きすることができる。
+#
+# <pre>
+# public:
+#  LifeCycleState get_component_state(RTC::LightweightRTObject_ptr comp)
+#  {
+#    return getComponentState(comp);
+#  }
+#  ExecutionKind PeriodicExecutionContext::get_kind()
+#  {
+#    return getKind();
+#  }
+#  ExecutionContextProfile* get_profile()
+#  {
+#    return getProfile();
+#  }
+#
+# protected:
+#  virtual LifeCycleState onGetComponentState(LifeCycleState state)
+#  { // 返すstateを書き換えたい場合はこの関数を実装する
+#    return state;
+#  }
+#  virtual ExecutionKind onGetKind(ExecutionKind kind)
+#  { // 返すkindを書き換えたい場合はこの関数を実装する
+#    return kind;
+#  }
+#  virtual ExecutionContextProfile*
+#  onGetProfile(ExecutionContextProfile*& profile)
+#  { // 返すprofileを書き換えたい場合はこの関数を実装する
+#    return profile;
+#  }
+# </pre>
+#
 # ExecutionContextの基底クラス。
 #
 # @since 0.4.0
 #
 # @else
+# @class ExecutionContextBase
+# @brief A base class for ExecutionContext
+#
+# A base class of ExecutionContext.
+#
+# @since 0.4.0
+#
 # @endif
-class ExecutionContextBase(OpenRTM__POA.ExtTrigExecutionContextService):
+#
+class ExecutionContextBase:
   """
   """
 
-  def __del__(self):
+  def __init__(self, name):
+    self._rtcout  = OpenRTM_aist.Manager.instance().getLogbuf("ec_base")
+    self._activationTimeout   = OpenRTM_aist.TimeValue(0.5)
+    self._deactivationTimeout = OpenRTM_aist.TimeValue(0.5)
+    self._resetTimeout        = OpenRTM_aist.TimeValue(0.5)
+    self._syncActivation   = True
+    self._syncDeactivation = True
+    self._syncReset        = True
+    self._worker  = OpenRTM_aist.ExecutionContextWorker()
+    self._profile = OpenRTM_aist.ExecutionContextProfile()
+
+
+  ##
+  # @if jp
+  # @brief ExecutionContextの初期化処理
+  #
+  # @else
+  # @brief Initialization function of the ExecutionContext
+  #
+  # @endif
+  # virtual void init(coil::Properties& props);
+  def init(self, props):
+    self._rtcout.RTC_TRACE("init()")
+    self._rtcout.RTC_DEBUG(props)
+    
+    # setting rate
+    self.setExecutionRate(props)
+    
+    # getting sync/async mode flag
+    transitionMode_ = [False]
+    if self.setTransitionMode(props, "sync_transition", transitionMode_):
+      self._syncActivation   = transitionMode_[0]
+      self._syncDeactivation = transitionMode_[0]
+      self._syncReset        = transitionMode_[0]
+
+    syncactivation_   = [self._syncActivation]
+    syncdeactivation_ = [self._syncDeactivation]
+    syncreset_        = [self._syncReset]
+    self.setTransitionMode(props, "sync_activation", syncactivation_)
+    self.setTransitionMode(props, "sync_deactivation", syncdeactivation_)
+    self.setTransitionMode(props, "sync_reset", syncreset_)
+    self._syncActivation   = syncactivation_[0]
+    self._syncDeactivation = syncdeactivation_[0]
+    self._syncReset        = syncreset_[0]
+    
+    # getting transition timeout
+    timeout_ = [0.0]
+    if self.setTimeout(props, "transition_timeout", timeout_):
+      self._activationTimeout   = timeout_[0]
+      self._deactivationTimeout = timeout_[0]
+      self._resetTimeout        = timeout_[0]
+
+    activationTO_   = [self._activationTimeout]
+    deactivationTO_ = [self._deactivationTimeout]
+    resetTO_        = [self._resetTimeout]
+    self.setTimeout(props, "activation_timeout",   activationTO_)
+    self.setTimeout(props, "deactivation_timeout", deactivationTO_)
+    self.setTimeout(props, "reset_timeout",        resetTO_)
+    self._activationTimeout   = activationTO_[0]
+    self._deactivationTimeout = deactivationTO_[0]
+    self._resetTimeout        = resetTO_[0]
+
+    self._rtcout.RTC_DEBUG("ExecutionContext's configurations:")
+    self._rtcout.RTC_DEBUG("Exec rate   : %f [Hz]", self.getRate())
+
+    toSTR_ = lambda x: "YES" if x else "NO"
+
+    self._rtcout.RTC_DEBUG("Activation  : Sync = %s, Timeout = %f",
+                           (toSTR_(self._syncActivation), float(self._activationTimeout.toDouble())))
+    self._rtcout.RTC_DEBUG("Deactivation: Sync = %s, Timeout = %f",
+                           (toSTR_(self._syncActivation), float(self._deactivationTimeout.toDouble())))
+    self._rtcout.RTC_DEBUG("Reset       : Sync = %s, Timeout = %f",
+                           (toSTR_(self._syncReset), float(self._resetTimeout.toDouble())))
+    # Setting given Properties to EC's profile::properties
+    self.setProperties(props)
     return
 
+
   ##
   # @if jp
   # @brief ExecutionContextの処理を進める(サブクラス実装用)
@@ -48,13 +434,1058 @@
   # @else
   # @brief Destructor
   # @endif
-  def tick(self):
-    pass
+  #def tick(self):
+  #  pass
 
 
+  ##
+  # @if jp
+  # @brief コンポーネントをバインドする。
+  #
+  # コンポーネントをバインドする。
+  #
+  # @else
+  # @brief Bind the component.
+  #
+  # Bind the component.
+  #
+  # @endif
   def bindComponent(self, rtc):
+    return self._worker.bindComponent(rtc)
+
+
+  #============================================================
+  # Functions to be delegated by EC's CORBA operations
+
+  ##
+  # @if jp
+  # @brief ExecutionContext 実行状態確認関数
+  # @else
+  # @brief Check for ExecutionContext running state
+  # @endif
+  # CORBA::Boolean ExecutionContextBase::isRunning()
+  def isRunning(self):
+    self._rtcout.RTC_TRACE("isRunning()")
+    return self._worker.isRunning()
+
+  
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行を開始
+  # @else
+  # @brief Start the ExecutionContext
+  # @endif
+  # RTC::ReturnCode_t ExecutionContextBase::start()
+  def start(self):
+    self._rtcout.RTC_TRACE("start()")
+    ret_ = self.onStarting() # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onStarting() failed. Starting EC aborted.")
+      return ret_
+
+    ret_ = self._worker.start() # Actual start()
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Invoking on_startup() for each RTC failed.")
+      return ret_
+
+    ret_ = self.onStarted() # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onStartted() failed. Started EC aborted..")
+      self._worker.stop()
+      self._rtcout.RTC_ERROR("on_shutdown() was invoked, because of onStarted")
+      return ret_
+
+    return ret_
+
+  
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行を停止
+  # @else
+  # @brief Stopping the ExecutionContext
+  # @endif
+  # RTC::ReturnCode_t ExecutionContextBase::stop()
+  def stop(self):
+    self._rtcout.RTC_TRACE("stop()")
+    ret_ = self.onStopping() # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onStopping() failed. Stopping EC aborted.")
+      return ret_
+
+    ret_ = self._worker.stop() # Actual stop()
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Invoking on_shutdown() for each RTC failed.")
+      return ret_
+
+    ret_ = self.onStopped() # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onStopped() failed. Stopped EC aborted.")
+      return ret_
+
+    return ret_
+
+  
+  ##
+  # @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
+  def getRate(self):
+    rate_ = self._profile.getRate() # Actual getRate()
+    return self.onGetRate(rate_) # Template
+
+  
+  # coil::TimeValue ExecutionContextBase::getPeriod(void) const
+  def getPeriod(self):
+    return self._profile.getPeriod()
+
+  
+  ##
+  # @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)
+  def setRate(self, rate):
+    self._rtcout.RTC_TRACE("setRate(%f)", rate)
+    ret_ = self._profile.setRate(self.onSettingRate(rate))
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Setting execution rate failed. %f", rate)
+      return ret_
+
+    ret_ = self.onSetRate(rate)
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onSetRate(%f) failed.", rate)
+      return ret_
+
+    self._rtcout.RTC_INFO("setRate(%f) done", rate)
+    return ret_
+
+  
+  ##
+  # @if jp
+  # @brief RTコンポーネントを追加する
+  # @else
+  # @brief Add an RT-component
+  # @endif
+  # RTC::ReturnCode_t ExecutionContextBase::
+  # addComponent(RTC::LightweightRTObject_ptr comp)
+  def addComponent(self, comp):
+    self._rtcout.RTC_TRACE("addComponent()")
+    ret_ = self.onAddingComponent(comp) # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Error: onAddingComponent(). RTC is not attached.")
+      return ret_
+
+    ret_ = self._worker.addComponent(comp) # Actual addComponent()
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Error: ECWorker addComponent() faild.")
+      return ret_
+
+    ret_ = self._profile.addComponent(comp) # Actual addComponent()
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Error: ECProfile addComponent() faild.")
+      return ret_
+
+    ret_ = self.onAddedComponent(comp) # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Error: onAddedComponent() faild.")
+      self._rtcout.RTC_INFO("Removing attached RTC.")
+      self._worker.removeComponent(comp)
+      self._profile.removeComponent(comp)
+      return ret_
+
+    self._rtcout.RTC_INFO("Component has been added to this EC.")
+    return RTC.RTC_OK
+
+  
+  ##
+  # @if jp
+  # @brief RTコンポーネントを参加者リストから削除する
+  # @else
+  # @brief Remove the RT-Component from participant list
+  # @endif
+  # RTC::ReturnCode_t ExecutionContextBase::
+  # removeComponent(RTC::LightweightRTObject_ptr comp)
+  def removeComponent(self, comp):
+    self._rtcout.RTC_TRACE("removeComponent()")
+    ret_ = self.onRemovingComponent(comp) # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Error: onRemovingComponent(). "
+                             "RTC will not not attached.")
+      return ret_
+
+    ret_ = self._worker.removeComponent(comp) # Actual removeComponent()
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Error: ECWorker removeComponent() faild.")
+      return ret_
+
+    ret_ = self._profile.removeComponent(comp) # Actual removeComponent()
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Error: ECProfile removeComponent() faild.")
+      return ret_
+
+    ret_ = self.onRemovedComponent(comp) # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Error: onRemovedComponent() faild.")
+      self._rtcout.RTC_INFO("Removing attached RTC.")
+      self._worker.removeComponent(comp)
+      self._profile.removeComponent(comp)
+      return ret_
+
+    self._rtcout.RTC_INFO("Component has been removeed to this EC.")
+    return RTC.RTC_OK
+
+  
+  ##
+  # @if jp
+  # @brief RTコンポーネントをアクティブ化する
+  # @else
+  # @brief Activate an RT-component
+  # @endif
+  # RTC::ReturnCode_t ExecutionContextBase::
+  # activateComponent(RTC::LightweightRTObject_ptr comp)
+  def activateComponent(self, comp):
+    self._rtcout.RTC_TRACE("activateComponent()")
+    ret_ = self.onActivating(comp) # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onActivating() failed.")
+      return ret_
+
+    rtobj_ = [None]
+    ret_ = self._worker.activateComponent(comp, rtobj_) # Actual activateComponent()
+    if ret_ != RTC.RTC_OK:
+      return ret_
+
+    if not self._syncActivation: # Asynchronous activation mode
+      ret_ = self.onActivated(rtobj_[0], -1)
+      if ret_ != RTC.RTC_OK:
+        self._rtcout.RTC_ERROR("onActivated() failed.")
+
+      return ret_
+
+    #------------------------------------------------------------
+    # Synchronized activation mode
+    self._rtcout.RTC_DEBUG("Synchronous activation mode. "
+                           "Waiting for the RTC to be ACTIVE state. ")
+    return self.waitForActivated(rtobj_[0])
+
+
+  # RTC::ReturnCode_t ExecutionContextBase::
+  # waitForActivated(RTC_impl::RTObjectStateMachine* rtobj)
+  def waitForActivated(self, rtobj):
+    count_ = 0
+    ret_ = self.onWaitingActivated(rtobj, count_)
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onWaitingActivated failed.")
+      return ret_
+
+    cycle_ = int(float(self._activationTimeout.toDouble()) / float(self.getPeriod().toDouble()))
+    self._rtcout.RTC_DEBUG("Timeout is %f [s] (%f [s] in %d times)",
+                           (float(self._activationTimeout.toDouble()), self.getRate(), cycle_))
+    # Wating INACTIVE -> ACTIVE
+    starttime_ = OpenRTM_aist.Time().gettimeofday()
+    while rtobj.isCurrentState(RTC.INACTIVE_STATE):
+      ret_ = self.onWaitingActivated(rtobj, count_) # Template method
+      if ret_ != RTC.RTC_OK:
+        self._rtcout.RTC_ERROR("onWaitingActivated failed.")
+        return ret_
+
+      time.sleep(self.getPeriod().toDouble())
+      delta_ = OpenRTM_aist.Time().gettimeofday() - starttime_
+      self._rtcout.RTC_DEBUG("Waiting to be ACTIVE state. %f [s] slept (%d/%d)",
+                             (float(delta_.toDouble()), count_, cycle_))
+      count_ += 1
+      if delta_.toDouble() > self._activationTimeout.toDouble() or count_ > cycle_:
+        self._rtcout.RTC_WARN("The component is not responding.")
+        break
+
+
+    # Now State must be ACTIVE or ERROR
+    if rtobj.isCurrentState(RTC.INACTIVE_STATE):
+      self._rtcout.RTC_ERROR("Unknown error: Invalid state transition.")
+      return RTC.RTC_ERROR
+
+    self._rtcout.RTC_DEBUG("Current state is %s", self.getStateString(rtobj.getState()))
+    ret_ = self.onActivated(rtobj, count_) # Template method
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onActivated() failed.")
+
+    self._rtcout.RTC_DEBUG("onActivated() done.")
+    return ret_
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントを非アクティブ化する
+  # @else
+  # @brief Deactivate an RT-component
+  # @endif
+  # RTC::ReturnCode_t ExecutionContextBase::
+  # deactivateComponent(RTC::LightweightRTObject_ptr comp)
+  def deactivateComponent(self, comp):
+    self._rtcout.RTC_TRACE("deactivateComponent()")
+    ret_ = self.onDeactivating(comp) # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onDeactivatingComponent() failed.")
+      return ret_
+
+    # Deactivate all the RTCs
+    rtobj_ = [None]
+    ret_ = self._worker.deactivateComponent(comp, rtobj_)
+    if ret_ != RTC.RTC_OK:
+      return ret_
+
+    if not self._syncDeactivation:
+      ret_ = self.onDeactivated(rtobj_[0], -1)
+      if ret_ != RTC.RTC_OK:
+        self._rtcout.RTC_ERROR("onDeactivated() failed.")
+      return ret_
+
+    #------------------------------------------------------------
+    # Waiting for synchronized deactivation
+    self._rtcout.RTC_DEBUG("Synchronous deactivation mode. "
+                           "Waiting for the RTC to be INACTIVE state. ")
+    return self.waitForDeactivated(rtobj_[0])
+
+
+  # RTC::ReturnCode_t ExecutionContextBase::
+  # waitForDeactivated(RTC_impl::RTObjectStateMachine* rtobj)
+  def waitForDeactivated(self, rtobj):
+    count_ = 0
+    ret_ = self.onWaitingDeactivated(rtobj, count_)
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onWaitingDeactivated failed.")
+      return ret_
+
+    cycle_ = int(float(self._deactivationTimeout.toDouble()) / float(self.getPeriod().toDouble()))
+    self._rtcout.RTC_DEBUG("Timeout is %f [s] (%f [s] in %d times)",
+                           (float(self._deactivationTimeout.toDouble()), self.getRate(), cycle_))
+    # Wating ACTIVE -> INACTIVE
+    starttime_ = OpenRTM_aist.Time().gettimeofday()
+    while rtobj.isCurrentState(RTC.ACTIVE_STATE):
+      ret_ = self.onWaitingDeactivated(rtobj, count_) # Template method
+      if ret_ != RTC.RTC_OK:
+        self._rtcout.RTC_ERROR("onWaitingDeactivated failed.")
+        return ret_
+
+      time.sleep(self.getPeriod().toDouble())
+      delta_ = OpenRTM_aist.Time().gettimeofday() - starttime_
+      self._rtcout.RTC_DEBUG("Waiting to be INACTIVE state. Sleeping %f [s] (%d/%d)",
+                             (float(delta_.toDouble()), count_, cycle_))
+      count_ += 1
+      if delta_.toDouble() > self._deactivationTimeout.toDouble() or count_ > cycle_:
+        self._rtcout.RTC_ERROR("The component is not responding.")
+        break
+
+
+    # Now State must be INACTIVE or ERROR
+    if rtobj.isCurrentState(RTC.ACTIVE_STATE):
+      self._rtcout.RTC_ERROR("Unknown error: Invalid state transition.")
+      return RTC.RTC_ERROR
+
+    self._rtcout.RTC_DEBUG("Current state is %s", self.getStateString(rtobj.getState()))
+    ret_ = self.onDeactivated(rtobj, count_)
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onDeactivated() failed.")
+
+    self._rtcout.RTC_DEBUG("onDeactivated() done.")
+    return ret_
+
+  
+  ##
+  # @if jp
+  # @brief RTコンポーネントをリセットする
+  # @else
+  # @brief Reset the RT-component
+  # @endif
+  # RTC::ReturnCode_t ExecutionContextBase::
+  # resetComponent(RTC::LightweightRTObject_ptr comp)
+  def resetComponent(self, comp):
+    self._rtcout.RTC_TRACE("resetComponent()")
+    ret_ = self.onResetting(comp) # Template
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onResetting() failed.")
+      return ret_
+
+    rtobj_ = [None]
+    ret_ = self._worker.resetComponent(comp, rtobj_) # Actual resetComponent()
+    if ret_ != RTC.RTC_OK:
+      return ret_
+    if not self._syncReset:
+      ret_ = self.onReset(rtobj_[0], -1)
+      if ret_ != RTC.RTC_OK:
+        self._rtcout.RTC_ERROR("onReset() failed.")
+      return ret_
+
+    #------------------------------------------------------------
+    # Waiting for synchronized reset
+    self._rtcout.RTC_DEBUG("Synchronous reset mode. "
+                           "Waiting for the RTC to be INACTIVE state. ")
+    return self.waitForReset(rtobj_[0])
+
+  
+  # RTC::ReturnCode_t ExecutionContextBase::
+  # waitForReset(RTC_impl::RTObjectStateMachine* rtobj)
+  def waitForReset(self, rtobj):
+    count_ = 0
+    ret_ = self.onWaitingReset(rtobj, count_)
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onWaitingReset() failed.")
+      return ret_
+
+    cycle_ = int(float(self._resetTimeout.toDouble()) / float(self.getPeriod().toDouble()))
+    self._rtcout.RTC_DEBUG("Timeout is %f [s] (%f [s] in %d times)",
+                           (float(self._resetTimeout.toDouble()), self.getRate(), cycle_))
+    # Wating ERROR -> INACTIVE
+    starttime_ = OpenRTM_aist.Time().gettimeofday()
+    while rtobj.isCurrentState(RTC.ERROR_STATE):
+      ret_ = self.onWaitingReset(rtobj, count_) # Template
+      if ret_ != RTC.RTC_OK:
+        self._rtcout.RTC_ERROR("onWaitingReset failed.")
+        return ret_
+
+      time.sleep(self.getPeriod().toDouble())
+      delta_ = OpenRTM_aist.Time().gettimeofday() - starttime_
+      self._rtcout.RTC_DEBUG("Waiting to be INACTIVE state. Sleeping %f [s] (%d/%d)",
+                             (float(delta_.toDouble()), count_, cycle_))
+      count_ += 1
+      if delta_.toDouble() > self._resetTimeout.toDouble() or count_ > cycle_:
+        self._rtcout.RTC_ERROR("The component is not responding.")
+        break
+
+    # Now State must be INACTIVE
+    if not rtobj.isCurrentState(RTC.INACTIVE_STATE):
+      self._rtcout.RTC_ERROR("Unknown error: Invalid state transition.")
+      return RTC.RTC_ERROR
+
+    self._rtcout.RTC_DEBUG("Current state is %s", self.getStateString(rtobj.getState()))
+    ret_ = self.onReset(rtobj, count_) # Template method
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("onResetd() failed.")
+
+    self._rtcout.RTC_DEBUG("onReset() done.")
+    return ret_
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントの状態を取得する
+  #
+  # 指定したRTコンポーネントの状態(LifeCycleState)を取得する。指定し
+  # たRTコンポーネントが参加者リストに含まれない場合は、
+  # UNKNOWN_STATE が返される。
+  #
+  # @param comp 状態取得対象RTコンポーネント
+  #
+  # @return 現在の状態(LifeCycleState)
+  #
+  # @else
+  #
+  # @brief Get RT-component's state
+  #
+  # This operation shall report the LifeCycleState of the given
+  # participant RTC.  UNKNOWN_STATE will be returned, if the given
+  # RT-Component is not inclued in the participant list.
+  #
+  # @param comp The target RT-Component to get the state
+  #
+  # @return The current state of the target RT-Component(LifeCycleState)
+  #
+  # @endif
+  # RTC::LifeCycleState ExecutionContextBase::
+  # getComponentState(RTC::LightweightRTObject_ptr comp)
+  def getComponentState(self, comp):
+    state_ = self._worker.getComponentState(comp)
+    self._rtcout.RTC_TRACE("getComponentState() = %s", self.getStateString(state_))
+    if state_ == RTC.CREATED_STATE:
+      self._rtcout.RTC_ERROR("CREATED state: not initialized "
+                             "RTC or unknwon RTC specified.")
+
+    return self.onGetComponentState(state_)
+
+
+  # const char* ExecutionContextBase::getStateString(RTC::LifeCycleState state)
+  def getStateString(self, state):
+    return self._worker.getStateString(state)
+
+
+  ##
+  # @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 ExecutionContextBase::getKind(void) const
+  def getKind(self):
+    kind_ = self._profile.getKind()
+    self._rtcout.RTC_TRACE("getKind() = %s", self.getKindString(kind_))
+    kind_ = self.onGetKind(kind_)
+    self._rtcout.RTC_DEBUG("onGetKind() returns %s", self.getKindString(kind_))
+    return kind_
+
+  
+  ##
+  # @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* ExecutionContextBase::getProfile(void)
+  def getProfile(self):
+    self._rtcout.RTC_TRACE("getProfile()")
+    prof_ = self._profile.getProfile()
+    self._rtcout.RTC_DEBUG("kind: %s", self.getKindString(prof_.kind))
+    self._rtcout.RTC_DEBUG("rate: %f", prof_.rate)
+    self._rtcout.RTC_DEBUG("properties:")
+    props_ = OpenRTM_aist.Properties()
+    OpenRTM_aist.NVUtil.copyToProperties(props_, prof_.properties)
+    self._rtcout.RTC_DEBUG(props_)
+    return self.onGetProfile(prof_)
+
+  
+
+  #============================================================
+  # 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)
+  def setObjRef(self, ec_ptr):
+    self._worker.setECRef(ec_ptr)
+    self._profile.setObjRef(ec_ptr)
+    return
+
+
+  ##
+  # @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
+  def getObjRef(self):
+    return self._profile.getObjRef()
+
+
+  ##
+  # @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
+  def getKindString(self, kind):
+    return self._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)
+  def setKind(self, kind):
+    return self._profile.setKind(kind)
+
+
+  ##
+  # @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)
+  def setOwner(self, comp):
+    return self._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
+  def getOwner(self):
+    return self._profile.getOwner()
+
+
+  ##
+  # @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
+  def getComponentList(self):
+    return self._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)
+  def setProperties(self, props):
+    self._profile.setProperties(props)
+    return
+
+
+  ##
+  # @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
+  def getProperties(self):
+    return self._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)
+  def getProfile(self):
+    return self._profile.getProfile()
+
+
+  # end of delegated functions to ExecutionContextProfile
+  #============================================================
+
+  #============================================================
+  # Delegated functions to ExecutionContextWorker
+  #============================================================
+  # bool isAllCurrentState(RTC::LifeCycleState state)
+  def isAllCurrentState(self, state):
+    return self._worker.isAllCurrentState(state)
+
+  # bool isAllNextState(RTC::LifeCycleState state)
+  def isAllNextState(self, state):
+    return self._worker.isAllNextState(state)
+
+  # bool isOneOfCurrentState(RTC::LifeCycleState state)
+  def isOneOfCurrentState(self, state):
+    return self._worker.isOneOfCurrentState(state)
+
+  # bool isOneOfNextState(RTC::LifeCycleState state)
+  def isOneOfNextState(self, state):
+    return self._worker.isOneOfNextState(state)
+    
+  # void invokeWorker()       { m_worker.invokeWorker(); }
+  def invokeWorker(self):
+    self._worker.invokeWorker()
+    return
+
+  # void invokeWorkerPreDo()  { m_worker.invokeWorkerPreDo(); }
+  def invokeWorkerPreDo(self):
+    self._worker.invokeWorkerPreDo()
+    return
+
+  # void invokeWorkerDo()     { m_worker.invokeWorkerDo(); }
+  def invokeWorkerDo(self):
+    self._worker.invokeWorkerDo()
+    return
+
+  # void invokeWorkerPostDo() { m_worker.invokeWorkerPostDo(); }
+  def invokeWorkerPostDo(self):
+    self._worker.invokeWorkerPostDo()
+    return
+
+  # template virtual functions related to start/stop
+  # virtual bool onIsRunning(bool running) { return running; }
+  def onIsRunning(self, running):
+    return running
+
+  # virtual RTC::ReturnCode_t onStarting() { return RTC::RTC_OK; }
+  def onStarting(self):
+    return RTC.RTC_OK
+  
+  # virtual RTC::ReturnCode_t onStarted() { return RTC::RTC_OK; }
+  def onStarted(self):
+    return RTC.RTC_OK
+  
+  # virtual RTC::ReturnCode_t onStopping() { return RTC::RTC_OK; }
+  def onStopping(self):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t onStopped() { return RTC::RTC_OK; }
+  def onStopped(self):
+    return RTC.RTC_OK
+
+  # template virtual functions getting/setting execution rate
+  # virtual double onGetRate(double rate) const { return rate; }
+  def onGetRate(self, rate):
+    return rate
+
+  # virtual double onSettingRate(double rate) { return rate; }
+  def onSettingRate(self, rate):
+    return rate
+
+  # virtual RTC::ReturnCode_t onSetRate(double rate) { return RTC::RTC_OK; }
+  def onSetRate(self, rate):
+    return RTC.RTC_OK
+
+  # template virtual functions adding/removing component
+  # virtual RTC::ReturnCode_t
+  # onAddingComponent(RTC::LightweightRTObject_ptr rtobj)
+  def onAddingComponent(self, rtobj):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t
+  # onAddedComponent(RTC::LightweightRTObject_ptr rtobj)
+  def onAddedComponent(self, rtobj):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t
+  # onRemovingComponent(RTC::LightweightRTObject_ptr rtobj)
+  def onRemovingComponent(self, rtobj):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t
+  # onRemovedComponent(RTC::LightweightRTObject_ptr rtobj)
+  def onRemovedComponent(self, rtobj):
+    return RTC.RTC_OK
+
+  # template virtual functions related to activation/deactivation/reset
+  # virtual RTC::ReturnCode_t
+  # onActivating(RTC::LightweightRTObject_ptr comp)
+  def onActivating(self, comp):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t
+  # onWaitingActivated(RTC_impl::RTObjectStateMachine* comp, long int count)
+  def onWaitingActivated(self, comp, count):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t
+  # onActivated(RTC_impl::RTObjectStateMachine* comp,
+  #             long int count)
+  def onActivated(self, comp, count):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t
+  # onDeactivating(RTC::LightweightRTObject_ptr comp)
+  def onDeactivating(self, comp):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t
+  # onWaitingDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count)
+  def onWaitingDeactivated(self, comp, count):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t
+  # onDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count)
+  def onDeactivated(self, comp, count):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t onResetting(RTC::LightweightRTObject_ptr comp)
+  def onResetting(self, comp):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t
+  # onWaitingReset(RTC_impl::RTObjectStateMachine* comp, long int count)
+  def onWaitingReset(self, comp, count):
+    return RTC.RTC_OK
+
+  # virtual RTC::ReturnCode_t
+  # onReset(RTC_impl::RTObjectStateMachine* comp, long int count)
+  def onReset(self, comp, count):
+    return RTC.RTC_OK
+
+  # virtual RTC::LifeCycleState
+  # onGetComponentState(RTC::LifeCycleState state)
+  def onGetComponentState(self, state):
+    return state
+
+  # virtual RTC::ExecutionKind
+  # onGetKind(RTC::ExecutionKind kind) const
+  def onGetKind(self, kind):
+    return kind
+
+  # virtual RTC::ExecutionContextProfile*
+  # onGetProfile(RTC::ExecutionContextProfile*& profile)
+  def onGetProfile(self, profile):
+    return profile
+
+
+  #============================================================
+  # private functions
+
+  ##
+  # @if jp
+  # @brief Propertiesから実行コンテキストをセットする
+  # @else
+  # @brief Setting execution rate from given properties.
+  # @endif
+  # bool ExecutionContextBase::setExecutionRate(coil::Properties& props)
+  def setExecutionRate(self, props):
+    if props.findNode("rate"):
+      rate_ = [0.0]
+      if OpenRTM_aist.stringTo(rate_, props.getProperty("rate")):
+        self.setRate(rate_[0])
+        return True
+    return False
+
+  
+  ##
+  # @if jp
+  # @brief Propertiesから状態遷移モードをセットする
+  # @else
+  # @brief Setting state transition mode from given properties.
+  # @endif
+  # bool ExecutionContextBase::
+  # setTransitionMode(coil::Properties& props, const char* key, bool& flag)
+  def setTransitionMode(self, props, key, flag):
+    self._rtcout.RTC_TRACE("setTransitionMode(%s)", key)
+    toSTR_ = lambda x: "YES" if x else "NO"
+    if props.findNode(key):
+      flag[0] = OpenRTM_aist.toBool(props.getProperty(key), "YES", "NO", "YES")
+      self._rtcout.RTC_DEBUG("Transition Mode: %s = %s",
+                             (key, toSTR_(flag[0])))
+      return True
+
+    self._rtcout.RTC_DEBUG("Configuration %s not found.", key)
+    return False
+
+  
+  ##
+  # @if jp
+  # @brief Propertiesから状態遷移Timeoutをセットする
+  # @else
+  # @brief Setting state transition timeout from given properties.
+  # @endif
+  # bool ExecutionContextBase::
+  # setTimeout(coil::Properties& props, const char* key,
+  #            coil::TimeValue& timevalue)
+  def setTimeout(self, props, key, timevalue):
+    self._rtcout.RTC_TRACE("setTimeout(%s)", key)
+    if props.findNode(key):
+      timeout_ = [0.0]
+      if OpenRTM_aist.stringTo(timeout_, props.getProperty(key)):
+        timevalue[0] = OpenRTM_aist.TimeValue(timeout_[0])
+        self._rtcout.RTC_DEBUG("Timeout (%s): %f [s]", (key, timeout_[0]))
+        return True
+    self._rtcout.RTC_DEBUG("Configuration %s not found.", key)
+    return False
+
+
+executioncontextfactory = None
+  
+class ExecutionContextFactory(OpenRTM_aist.Factory,ExecutionContextBase):
+  def __init__(self):
+    OpenRTM_aist.Factory.__init__(self)
+    return
+
+  def __del__(self):
     pass
 
+  def instance():
+    global executioncontextfactory
 
-  def getObjeRef(self):
-    pass
+    if executioncontextfactory is None:
+      executioncontextfactory = ExecutionContextFactory()
+
+    return executioncontextfactory
+
+  instance = staticmethod(instance)
+

Copied: trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextProfile.py (from rev 542, branches/work/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextProfile.py)
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextProfile.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextProfile.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -0,0 +1,654 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file ExecutionContextProfile.py
+# @brief ExecutionContextProfile class
+# @date $Date$
+# @author Noriaki Ando <n-ando at aist.go.jp> and Shinji Kurihara
+#
+# Copyright (C) 2011
+#     Noriaki Ando
+#     Intelligent Systems Research Institute,
+#     National Institute of
+#         Advanced Industrial Science and Technology (AIST), Japan
+#     All rights reserved.
+#
+# $Id$
+#
+
+import threading
+from omniORB import CORBA, PortableServer
+
+import OpenRTM_aist
+import RTC
+
+DEFAULT_PERIOD = 0.000001
+
+##
+# @if jp
+# @class ExecutionContextProfile
+# @brief ExecutionContextProfile クラス
+#
+# @since 1.2.0
+#
+# @else
+# @class ExecutionContextProfile
+# @brief ExecutionContextProfile class
+#
+# @since 1.2.0
+#
+# @endif
+class ExecutionContextProfile:
+  """
+  """
+
+  ##
+  # @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);
+  def __init__(self, kind = RTC.PERIODIC):
+    global DEFAULT_PERIOD
+    self._rtcout  = OpenRTM_aist.Manager.instance().getLogbuf("periodic_ecprofile")
+    self._period = OpenRTM_aist.TimeValue(DEFAULT_PERIOD)
+    self._rtcout.RTC_TRACE("ExecutionContextProfile.__init__()")
+    self._rtcout.RTC_DEBUG("Actual rate: %d [sec], %d [usec]",
+                           (self._period.sec(), self._period.usec()))
+    self._profileMutex = threading.RLock()
+    self._ref = None
+    self._profile = RTC.ExecutionContextProfile(RTC.PERIODIC,
+                                                (1.0/self._period.toDouble()),
+                                                None, [], [])
+    return
+
+
+  ##
+  # @if jp
+  # @brief デストラクタ
+  #
+  # デストラクタ
+  #
+  # @else
+  # @brief Destructor
+  #
+  # Destructor
+  #
+  # @endif
+  def __del__(self):
+    self._rtcout.RTC_TRACE("ExecutionContextProfile.__del__()")
+
+    # cleanup EC's profile
+    self._profile.owner = None
+    self._profile.participants = []
+    self._profile.properties = []
+    self._ref = None
+    return
+
+
+  ##
+  # @if jp
+  # @brief CORBA オブジェクト参照をセット
+  #
+  # ExecutioncontextService としての CORBA オブジェ
+  # クト参照をセットする。
+  #
+  # @param ec_ptr CORBA オブジェクト参照
+  #
+  # @else
+  # @brief Set the reference to the CORBA object
+  #
+  # Set the reference to the CORBA object as
+  # ExecutioncontextService of this object.
+  #
+  # @param ec_ptr The reference to CORBA object
+  #
+  # @endif
+  # void setObjRef(RTC::ExecutionContextService_ptr ec_ptr);
+  def setObjRef(self, ec_ptr):
+    self._rtcout.RTC_TRACE("setObjRef()")
+    assert(not CORBA.is_nil(ec_ptr))
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    self._ref = ec_ptr
+    del guard
+    return
+
+
+  ##
+  # @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;
+  def getObjRef(self):
+    self._rtcout.RTC_TRACE("getObjRef()")
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    return self._ref
+
+
+  ##
+  # @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);
+  def setRate(self, rate):
+    self._rtcout.RTC_TRACE("setRate(%f)", rate)
+    if rate < 0.0:
+      return RTC.BAD_PARAMETER
+
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    self._profile.rate = rate
+    self._period = OpenRTM_aist.TimeValue(1.0 / rate)
+    return RTC.RTC_OK
+
+
+  # RTC::ReturnCode_t setPeriod(double sec, coil::TimeValue tv);
+  def setPeriod(self, sec=None, tv=None):
+    if sec:
+      self._rtcout.RTC_TRACE("setPeriod(%f [sec])", sec)
+      if sec < 0.0:
+        return RTC.BAD_PARAMETER
+
+      guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+      self._profile.rate = 1.0 / sec
+      self._period = OpenRTM_aist.TimeValue(sec)
+      del guard
+      return RTC.RTC_OK;
+    elif tv:
+      self._rtcout.RTC_TRACE("setPeriod(%f [sec])", tv.toDouble())
+      if tv.toDouble() < 0.0:
+        return RTC.BAD_PARAMETER
+
+      guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+      self._profile.rate = 1.0 / tv.toDouble()
+      self._period = tv
+      del guard
+      return RTC.RTC_OK
+    return RTC.BAD_PARAMETER
+
+
+  ##
+  # @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;
+  def getRate(self):
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    return self._profile.rate
+
+
+  # coil::TimeValue getPeriod(void) const;
+  def getPeriod(self):
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    return self._period
+
+
+  ##
+  # @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;
+  def getKindString(self, kind=None):
+    kinds_ = ["PERIODIC", "EVENT_DRIVEN", "OTHER"]
+    if not kind:
+      kind_ = self._profile.kind
+    else:
+      kind_ = kind
+
+    if kind_ < RTC.PERIODIC or kind_ > RTC.OTHER:
+      return ""
+
+    return kinds_[kind_._v]
+
+
+  ##
+  # @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);
+  def setKind(self, kind):
+    if kind < RTC.PERIODIC or kind > RTC.OTHER:
+      self._rtcout.RTC_ERROR("Invalid kind is given. %d", kind._v)
+      return RTC.BAD_PARAMETER
+
+    self._rtcout.RTC_TRACE("setKind(%s)", self.getKindString(kind))
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    self._profile.kind = kind
+    del guard
+    return RTC.RTC_OK
+
+
+  ##
+  # @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;
+  def getKind(self):
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    self._rtcout.RTC_TRACE("%s = getKind()", self.getKindString(self._profile.kind))
+    return self._profile.kind
+
+
+  ##
+  # @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);
+  def setOwner(self, comp):
+    self._rtcout.RTC_TRACE("setOwner()")
+    assert(not CORBA.is_nil(comp))
+    rtobj_ = comp._narrow(RTC.RTObject)
+    if CORBA.is_nil(rtobj_):
+      self._rtcout.RTC_ERROR("Narrowing failed.")
+      return RTC.BAD_PARAMETER
+
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    self._profile.owner = rtobj_
+    del guard
+    return RTC.RTC_OK
+
+
+  ##
+  # @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;
+  def getOwner(self):
+    self._rtcout.RTC_TRACE("getOwner()")
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    return self._profile.owner
+
+
+  ##
+  # @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);
+  def addComponent(self, comp):
+    self._rtcout.RTC_TRACE("addComponent()")
+    if CORBA.is_nil(comp):
+      self._rtcout.RTC_ERROR("A nil reference was given.")
+      return RTC.BAD_PARAMETER
+
+    rtobj_ = comp._narrow(RTC.RTObject)
+    if CORBA.is_nil(rtobj_):
+      self._rtcout.RTC_ERROR("Narrowing was failed.")
+      return RTC.RTC_ERROR
+
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    OpenRTM_aist.CORBA_SeqUtil.push_back(self._profile.participants,
+                                         rtobj_)
+    del guard
+    return RTC.RTC_OK
+
+
+  ##
+  # @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);
+  def removeComponent(self, comp):
+    self._rtcout.RTC_TRACE("removeComponent()")
+    if CORBA.is_nil(comp):
+      self._rtcout.RTC_ERROR("A nil reference was given.")
+      return RTC.BAD_PARAMETER
+
+    rtobj_ = comp._narrow(RTC.RTObject)
+    if CORBA.is_nil(rtobj_):
+      self._rtcout.RTC_ERROR("Narrowing was failed.")
+      return RTC.RTC_ERROR
+
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+
+    index_ = OpenRTM_aist.CORBA_SeqUtil.find(self._profile.participants,
+                                             self.find_participant(rtobj_))
+    if index_ < 0:
+      self._rtcout.RTC_ERROR("The given RTObject does not exist in the EC.")
+      return RTC.BAD_PARAMETER
+    OpenRTM_aist.CORBA_SeqUtil.erase(self._profile.participants, index_)
+    return RTC.RTC_OK
+
+
+  ##
+  # @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;
+  def getComponentList(self):
+    self._rtcout.RTC_TRACE("getComponentList(%d)", len(self._profile.participants))
+    return self._profile.participants
+
+
+  ##
+  # @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);
+  def setProperties(self, props):
+    self._rtcout.RTC_TRACE("setProperties()")
+    self._rtcout.RTC_DEBUG(props)
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    OpenRTM_aist.NVUtil.copyFromProperties(self._profile.properties, props)
+    del guard
+    return
+
+  
+  ##
+  # @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;
+  def getProperties(self):
+    self._rtcout.RTC_TRACE("getProperties()")
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    props_ = OpenRTM_aist.Properties()
+    OpenRTM_aist.NVUtil.copyToProperties(props_, self._profile.properties)
+    del guard
+    self._rtcout.RTC_DEBUG(props_)
+    return props_
+
+
+  ##
+  # @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);
+  def getProfile(self):
+    self._rtcout.RTC_TRACE("getProfile()")
+    guard = OpenRTM_aist.ScopedLock(self._profileMutex)
+    return self._profile
+
+
+  ##
+  # @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;
+  def lock(self):
+    self._profileMutex.acquire()
+    return
+
+
+  ##
+  # @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;
+  def unlock(self):
+    self._profileMutex.release()
+    return
+
+  class find_participant:
+    def __init__(self, comp):
+      self._comp = comp
+      return
+
+    def __call__(self, comp):
+      return self._comp._is_equivalent(comp)

Copied: trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextWorker.py (from rev 542, branches/work/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextWorker.py)
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextWorker.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/ExecutionContextWorker.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -0,0 +1,745 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file ExecutionContextWorker.py
+# @brief ExecutionContext's state machine worker class
+# @date $Date$
+# @author Noriaki Ando <n-ando at aist.go.jp> and Shinji Kurihara
+#
+# Copyright (C) 2011
+#     Noriaki Ando
+#     Intelligent Systems Research Institute,
+#     National Institute of
+#         Advanced Industrial Science and Technology (AIST), Japan
+#     All rights reserved.
+#
+# $Id$
+#
+
+import threading
+from omniORB import CORBA, PortableServer
+
+import OpenRTM_aist
+import RTC
+
+
+##
+# @if jp
+# @class PeriodicExecutionContext
+# @brief PeriodicExecutionContext クラス
+#
+# Periodic Sampled Data Processing(周期実行用)ExecutionContextクラス。
+#
+# @since 0.4.0
+#
+# @else
+# @class PeriodicExecutionContext
+# @brief PeriodicExecutionContext class
+#
+# Periodic Sampled Data Processing (for the execution cycles)
+# ExecutionContext class
+#
+# @since 0.4.0
+#
+# @endif
+class ExecutionContextWorker:
+  """
+  """
+
+  ##
+  # @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
+  def __init__(self):
+    self._rtcout  = OpenRTM_aist.Manager.instance().getLogbuf("ec_worker")
+    self._running = False
+    self._rtcout.RTC_TRACE("ExecutionContextWorker.__init__")
+    self._ref = None
+    self._comps = []
+    self._addedComps = []
+    self._removedComps = []
+    self._mutex = threading.RLock()
+    self._addedMutex = threading.RLock()
+    self._removedMutex = threading.RLock()
+    return
+
+
+  ##
+  # @if jp
+  # @brief デストラクタ
+  #
+  # デストラクタ
+  #
+  # @else
+  # @brief Destructor
+  #
+  # Destructor
+  #
+  # @endif
+  def __del__(self):
+    self._rtcout.RTC_TRACE("~ExecutionContextWorker.__del__")
+    return
+
+
+  #============================================================
+  # Object reference to EC
+  #============================================================
+  # void setECRef(RTC::ExecutionContextService_ptr ref);
+  def setECRef(self, ref):
+    self._ref = ref
+    return
+
+
+  #RTC::ExecutionContextService_ptr getECRef();
+  def getECRef(self):
+    return self._ref
+
+
+  #============================================================
+  # ExecutionContext
+  #============================================================
+  ##
+  # @if jp
+  # @brief ExecutionContext 実行状態確認関数
+  #
+  # この操作は ExecutionContext が Runnning 状態の場合に true を返す。
+  # Executioncontext が Running の間、当該 Executioncontext に参加し
+  # ている全てのアクティブRTコンポーネントが、ExecutionContext の実
+  # 行種類に応じて実行される。
+  #
+  # @return 状態確認関数(動作中:true、停止中:false)
+  #
+  # @else
+  #
+  # @brief Check for ExecutionContext running state
+  #
+  # This operation shall return true if the context is in the
+  # Running state.  While the context is Running, all Active RTCs
+  # participating in the context shall be executed according to the
+  # context’s execution kind.
+  #
+  # @return Check state function (Running:true、Stopping:false)
+  #
+  # @endif
+  # bool isRunning(void);
+  def isRunning(self):
+    self._rtcout.RTC_TRACE("isRunning()")
+    return self._running
+
+
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行を開始
+  #
+  # ExecutionContext の実行状態を Runnning とするためのリクエストを
+  # 発行する。ExecutionContext の状態が遷移すると
+  # ComponentAction::on_startup が呼び出される。参加しているRTコンポー
+  # ネントが、初期化されるまで ExecutionContext を開始することはでき
+  # ない。ExecutionContext は複数回開始/停止を繰り返すことができる。
+  #
+  # @return ReturnCode_t 型のリターンコード
+  #
+  # @else
+  #
+  # @brief Start the ExecutionContext
+  #
+  # Request that the context enter the Running state.  Once the
+  # state transition occurs, the ComponentAction::on_startup
+  # operation will be invoked.  An execution context may not be
+  # started until the RT-Components that participate in it have
+  # been initialized.  An execution context may be started and
+  # stopped multiple times.
+  #
+  # @return The return code of ReturnCode_t type
+  #
+  # @endif
+  # RTC::ReturnCode_t start(void);
+  def start(self):
+    self._rtcout.RTC_TRACE("start()")
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    if self._running:
+      del guard
+      self._rtcout.RTC_WARN("ExecutionContext is already running.")
+      return RTC.PRECONDITION_NOT_MET
+
+    # invoke ComponentAction::on_startup for each comps.
+    for comp in self._comps:
+      comp.onStartup()
+
+    self._rtcout.RTC_DEBUG("%d components started.", len(self._comps))
+    # change EC thread state
+    self._running = True
+    del guard
+    return RTC.RTC_OK
+
+
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行を停止
+  #
+  # ExecutionContext の状態を Stopped とするためのリクエストを発行す
+  # る。遷移が発生した場合は、ComponentAction::on_shutdown が呼び出
+  # される。参加しているRTコンポーネントが終了する前に
+  # ExecutionContext を停止する必要がある。ExecutionContext は複数回
+  # 開始/停止を繰り返すことができる。
+  #
+  # @return ReturnCode_t 型のリターンコード
+  #
+  # @else
+  #
+  # @brief Stop the ExecutionContext
+  #
+  # Request that the context enter the Stopped state.  Once the
+  # transition occurs, the ComponentAction::on_shutdown operation
+  # will be invoked.  An execution context must be stopped before
+  # the RT components that participate in it are finalized.  An
+  # execution context may be started and stopped multiple times.
+  #
+  # @return The return code of ReturnCode_t type
+  #
+  # @endif
+  # RTC::ReturnCode_t stop(void);
+  def stop(self):
+    self._rtcout.RTC_TRACE("stop()")
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    if not self._running:
+      del guard
+      self._rtcout.RTC_WARN("ExecutionContext is already stopped.")
+      return RTC.PRECONDITION_NOT_MET
+
+    # stop thread
+    self._running = False
+
+    # invoke on_shutdown for each comps.
+    for comp in self._comps:
+      comp.onShutdown()
+      
+    del guard
+    return RTC.RTC_OK
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントをアクティブ化する
+  #
+  # Inactive 状態にあるRTコンポーネントをActive に遷移させ、アクティ
+  # ブ化する。この操作が呼ばれた結果、on_activate が呼び出される。指
+  # 定したRTコンポーネントが参加者リストに含まれない場合は、
+  # BAD_PARAMETER が返される。指定したRTコンポーネントの状態が
+  # Inactive 以外の場合は、PRECONDITION_NOT_MET が返される。
+  #
+  # @param comp アクティブ化対象RTコンポーネント
+  #
+  # @return ReturnCode_t 型のリターンコード
+  #
+  # @else
+  #
+  # @brief Activate an RT-component
+  #
+  # The given participant RTC is Inactive and is therefore not
+  # being invoked according to the execution context’s execution
+  # kind. This operation shall cause the RTC to transition to the
+  # Active state such that it may subsequently be invoked in this
+  # execution context.  The callback on_activate shall be called as
+  # a result of calling this operation. This operation shall not
+  # return until the callback has returned, and shall result in an
+  # error if the callback does.
+  #
+  # @param comp The target RT-Component for activation
+  #
+  # @return The return code of ReturnCode_t type
+  #
+  # @endif
+  # RTC::ReturnCode_t activateComponent(RTC::LightweightRTObject_ptr comp,
+  #                                     RTObjectStateMachine*& rtobj);
+  def activateComponent(self, comp, rtobj):
+    self._rtcout.RTC_TRACE("activateComponent()")
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    obj_ = self.findComponent(comp)
+    if not obj_:
+      del guard
+      self._rtcout.RTC_ERROR("Given RTC is not participant of this EC.")
+      return RTC.BAD_PARAMETER
+
+    self._rtcout.RTC_DEBUG("Component found in the EC.")
+    if not obj_.isCurrentState(RTC.INACTIVE_STATE):
+      del guard
+      self._rtcout.RTC_ERROR("State of the RTC is not INACTIVE_STATE.")
+      return RTC.PRECONDITION_NOT_MET
+
+    self._rtcout.RTC_DEBUG("Component is in INACTIVE state. Going to ACTIVE state.")
+    obj_.goTo(RTC.ACTIVE_STATE)
+    rtobj[0] = obj_
+    del guard
+    self._rtcout.RTC_DEBUG("activateComponent() done.")
+    return RTC.RTC_OK
+
+
+  # RTC::ReturnCode_t waitActivateComplete(RTObjectStateMachine*& rtobj,
+  #                                        coil::TimeValue timeout = 1.0,
+  #                                        long int cycle = 1000);
+  def waitActivateComplete(self, rtobj, timeout = 1.0, cycle = 1000):
+    pass
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントを非アクティブ化する
+  #
+  # Inactive 状態にあるRTコンポーネントを非アクティブ化し、Inactive
+  # に遷移させる。この操作が呼ばれた結果、on_deactivate が呼び出され
+  # る。指定したRTコンポーネントが参加者リストに含まれない場合は、
+  # BAD_PARAMETER が返される。指定したRTコンポーネントの状態が
+  # Active 以外の場合は、PRECONDITION_NOT_MET が返される。
+  #
+  # @param comp 非アクティブ化対象RTコンポーネント
+  #
+  # @return ReturnCode_t 型のリターンコード
+  #
+  # @else
+  #
+  # @brief Deactivate an RT-component
+  #
+  # The given RTC is Active in the execution context. Cause it to
+  # transition to the Inactive state such that it will not be
+  # subsequently invoked from the context unless and until it is
+  # activated again.  The callback on_deactivate shall be called as
+  # a result of calling this operation. This operation shall not
+  # return until the callback has returned, and shall result in an
+  # error if the callback does.
+  #
+  # @param comp The target RT-Component for deactivate
+  #
+  # @return The return code of ReturnCode_t type
+  #
+  # @endif
+  # RTC::ReturnCode_t deactivateComponent(RTC::LightweightRTObject_ptr comp,
+  #                                       RTObjectStateMachine*& rtobj);
+  def deactivateComponent(self, comp, rtobj):
+    self._rtcout.RTC_TRACE("deactivateComponent()")
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+
+    rtobj[0] = self.findComponent(comp)
+    if not rtobj[0]: 
+      del guard
+      self._rtcout.RTC_ERROR("Given RTC is not participant of this EC.")
+      return RTC.BAD_PARAMETER
+
+    if not rtobj[0].isCurrentState(RTC.ACTIVE_STATE):
+      del guard
+      self._rtcout.RTC_ERROR("State of the RTC is not ACTIVE_STATE.")
+      return RTC.PRECONDITION_NOT_MET
+
+    rtobj[0].goTo(RTC.INACTIVE_STATE)
+    del guard
+    return RTC.RTC_OK
+
+
+  # RTC::ReturnCode_t waitDeactivateComplete(RTObjectStateMachine*& rtobj,
+  #                                            coil::TimeValue timeout = 1.0,
+  #                                            long int cycle = 1000);
+  def waitDeactivateComplete(self, rtobj, timeout = 1.0, cycle = 1000):
+    pass
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントをリセットする
+  #
+  # Error 状態のRTコンポーネントの復帰を試みる。この操作が呼ばれた結
+  # 果、on_reset が呼び出される。指定したRTコンポーネントが参加者リ
+  # ストに含まれない場合は、BAD_PARAMETER が返される。指定したRTコン
+  # ポーネントの状態が Error 以外の場合は、PRECONDITION_NOT_MET が返
+  # される。
+  #
+  # @param comp リセット対象RTコンポーネント
+  #
+  # @return ReturnCode_t 型のリターンコード
+  #
+  # @else
+  #
+  # @brief Reset the RT-component
+  #
+  # Attempt to recover the RTC when it is in Error.  The
+  # ComponentAction::on_reset callback shall be invoked. This
+  # operation shall not return until the callback has returned, and
+  # shall result in an error if the callback does. If possible, the
+  # RTC developer should implement that callback such that the RTC
+  # may be returned to a valid state.
+  #
+  # @param comp The target RT-Component for reset
+  #
+  # @return The return code of ReturnCode_t type
+  #
+  # @endif
+  # RTC::ReturnCode_t resetComponent(RTC::LightweightRTObject_ptr com,
+  #                                  RTObjectStateMachine*& rtobj);
+  def resetComponent(self, comp, rtobj):
+    self._rtcout.RTC_TRACE("resetComponent()")
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+
+    rtobj[0] = self.findComponent(comp)
+    if not rtobj[0]:
+      del guard
+      self._rtcout.RTC_ERROR("Given RTC is not participant of this EC.")
+      return RTC.BAD_PARAMETER
+
+    if not rtobj[0].isCurrentState(RTC.ERROR_STATE):
+      del guard
+      self._rtcout.RTC_ERROR("State of the RTC is not ERROR_STATE.")
+      return RTC.PRECONDITION_NOT_MET
+
+    rtobj[0].goTo(RTC.INACTIVE_STATE)
+    del guard
+    return RTC.RTC_OK
+
+
+  # RTC::ReturnCode_t waitResetComplete(RTObjectStateMachine*& rtobj,
+  #                                     coil::TimeValue timeout = 1.0,
+  #                                     long int cycle = 1000);
+  def waitResetComplete(self, rtobj, timeout = 1.0, cycle = 1000):
+    pass
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントの状態を取得する
+  #
+  # 指定したRTコンポーネントの状態(LifeCycleState)を取得する。指定し
+  # たRTコンポーネントが参加者リストに含まれない場合は、
+  # UNKNOWN_STATE が返される。
+  #
+  # @param comp 状態取得対象RTコンポーネント
+  #
+  # @return 現在の状態(LifeCycleState)
+  #
+  # @else
+  #
+  # @brief Get RT-component's state
+  #
+  # This operation shall report the LifeCycleState of the given
+  # participant RTC.  UNKNOWN_STATE will be returned, if the given
+  # RT-Component is not inclued in the participant list.
+  #
+  # @param comp The target RT-Component to get the state
+  #
+  # @return The current state of the target RT-Component(LifeCycleState)
+  #
+  # @endif
+  # RTC::LifeCycleState getComponentState(RTC::LightweightRTObject_ptr comp);
+  def getComponentState(self, comp):
+    self._rtcout.RTC_TRACE("getComponentState()")
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    rtobj_ = self.findComponent(comp)
+    if not rtobj_:
+      del guard
+      self._rtcout.RTC_WARN("Given RTC is not participant of this EC.")
+      return RTC.CREATED_STATE
+
+    state_ = rtobj_.getState()
+    self._rtcout.RTC_DEBUG("getComponentState() = %s done", self.getStateString(state_))
+    return state_
+
+
+  # const char* getStateString(RTC::LifeCycleState state)
+  def getStateString(self, state):
+    st = ["CREATED_STATE",
+          "INACTIVE_STATE",
+          "ACTIVE_STATE",
+          "ERROR_STATE"]
+
+    f = lambda x: st[x._v] if x >= RTC.CREATED_STATE and x <= RTC.ERROR_STATE else ""
+    return f(state)
+
+  ##
+  # @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);
+  def addComponent(self, comp):
+    self._rtcout.RTC_TRACE("addComponent()")
+    if CORBA.is_nil(comp):
+      self._rtcout.RTC_ERROR("nil reference is given.")
+      return RTC.BAD_PARAMETER
+
+    try:
+      guard = OpenRTM_aist.ScopedLock(self._addedMutex)
+      ec_ = self.getECRef()
+      id_ = comp.attach_context(ec_)
+      self._addedComps.append(OpenRTM_aist.RTObjectStateMachine(id_, comp))
+      del guard
+    except:
+      del guard
+      self._rtcout.RTC_ERROR("addComponent() failed.")
+      return RTC.RTC_ERROR
+
+    self._rtcout.RTC_DEBUG("addComponent() succeeded.")
+    return RTC.RTC_OK
+
+
+  ##
+  # @if jp
+  # @brief コンポーネントをバインドする。
+  #
+  # コンポーネントをバインドする。
+  #
+  # @param rtc RTコンポーネント
+  # @return ReturnCode_t 型のリターンコード
+  # @else
+  # @brief Bind the component.
+  #
+  # Bind the component.
+  #
+  # @param rtc RT-Component's instances
+  # @return The return code of ReturnCode_t type
+  # @endif
+  # RTC::ReturnCode_t bindComponent(RTC::RTObject_impl* rtc);
+  def bindComponent(self, rtc):
+    self._rtcout.RTC_TRACE("bindComponent()")
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    if not rtc:
+      del guard
+      self._rtcout.RTC_ERROR("NULL pointer is given.")
+      return RTC.BAD_PARAMETER
+
+    ec_ = self.getECRef()
+    id_ = rtc.bindContext(ec_)
+    if id_ < 0 or id_ > OpenRTM_aist.ECOTHER_OFFSET:
+      # id should be owned context id < ECOTHER_OFFSET
+      del guard
+      self._rtcout.RTC_ERROR("bindContext returns invalid id: %d", id_)
+      return RTC.RTC_ERROR
+
+    self._rtcout.RTC_DEBUG("bindContext returns id = %d", id_)
+    
+    # rtc is owner of this EC
+    comp_ = rtc.getObjRef()
+    #    RTObjectStateMachine o(id, comp);
+    self._comps.append(OpenRTM_aist.RTObjectStateMachine(id_, comp_))
+    del guard
+    self._rtcout.RTC_DEBUG("bindComponent() succeeded.")
+    return RTC.RTC_OK
+
+
+  ##
+  # @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);
+  def removeComponent(self, comp):
+    self._rtcout.RTC_TRACE("removeComponent()")
+    if CORBA.is_nil(comp):
+      self._rtcout.RTC_ERROR("nil reference is given.")
+      return RTC.BAD_PARAMETER
+
+
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    rtobj_ = self.findComponent(comp)
+    del guard
+
+    if not rtobj_:
+      self._rtcout.RTC_ERROR("no RTC found in this context.")
+      return  RTC.BAD_PARAMETER
+
+    guard = OpenRTM_aist.ScopedLock(self._removedMutex)
+    self._removedComps.append(rtobj_)
+    del guard
+    return RTC.RTC_OK
+
+
+  # RTObjectStateMachine* findComponent(RTC::LightweightRTObject_ptr comp);
+  def findComponent(self, comp):
+    for comp_ in self._comps:
+      if comp_.isEquivalent(comp):
+        return comp_
+
+    return None
+
+
+  # bool isAllCurrentState(RTC::LifeCycleState state);
+  def isAllCurrentState(self, state):
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    for comp in self._comps:
+      if not comp.isCurrentState(state):
+        del guard
+        return False
+
+    del guard
+    return True
+
+
+  # bool isAllNextState(RTC::LifeCycleState state);
+  def isAllNextState(self, state):
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    for comp in self._comps:
+      if not comp.isNextState(state):
+        del guard
+        return False
+
+    del guard
+    return True
+
+
+  # bool isOneOfCurrentState(RTC::LifeCycleState state);
+  def isOneOfCurrentState(self, state):
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    for comp in self._comps:
+      if comp.isCurrentState(state):
+        del guard
+        return True
+    
+    del guard
+    return False
+
+
+  # bool isOneOfNextState(RTC::LifeCycleState state);
+  def isOneOfNextState(self, state):
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    for comp in self._comps:
+      if comp.isNextState(state):
+        del guard
+        return True
+
+    del guard
+    return False
+
+
+  # void invokeWorker();
+  def invokeWorker(self):
+    self._rtcout.RTC_PARANOID("invokeWorker()")
+    # m_comps never changes its size here
+    len_ = len(self._comps)
+    
+    for i in range(len_):
+      self._comps[i].workerPreDo()
+
+    for i in range(len_):
+      self._comps[i].workerDo()
+
+    for i in range(len_):
+      self._comps[i].workerPostDo()
+
+    self.updateComponentList()
+    return
+
+
+  # void invokeWorkerPreDo();
+  def invokeWorkerPreDo(self):
+    self._rtcout.RTC_PARANOID("invokeWorkerPreDo()")
+    # m_comps never changes its size here
+    for comp in self._comps:
+      comp.workerPreDo()
+    return
+
+  # void invokeWorkerDo();
+  def invokeWorkerDo(self):
+    self._rtcout.RTC_PARANOID("invokeWorkerDo()")
+    # m_comps never changes its size here
+    for comp in self._comps:
+      comp.workerDo()
+    return
+
+  # void invokeWorkerPostDo();
+  def invokeWorkerPostDo(self):
+    self._rtcout.RTC_PARANOID("invokeWorkerPostDo()")
+    # m_comps never changes its size here
+    for comp in self._comps:
+      comp.workerPostDo()
+    # m_comps might be changed here
+    self.updateComponentList()
+    return
+    
+  # void updateComponentList();
+  def updateComponentList(self):
+    guard = OpenRTM_aist.ScopedLock(self._mutex)
+    # adding component
+    guard_added = OpenRTM_aist.ScopedLock(self._addedMutex)
+    for comp in self._addedComps:
+      self._comps.append(comp)
+      self._rtcout.RTC_TRACE("Component added.")
+
+    self._addedComps = []
+    del guard_added
+
+    # removing component
+    guard_removed = OpenRTM_aist.ScopedLock(self._removedMutex)
+    for comp in self._removedComps:
+      lwrtobj_ = comp.getRTObject()
+      lwrtobj_.detach_context(comp.getExecutionContextHandle())
+      idx_ = -1
+      try:
+        idx_ = self._comps.index(comp)
+      except:
+        idx_ = -1
+
+      if idx_ >= 0:
+        del self._comps[idx_]
+        self._rtcout.RTC_TRACE("Component deleted.")
+
+    self._removedComps = []
+    return

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/ExtTrigExecutionContext.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/ExtTrigExecutionContext.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/ExtTrigExecutionContext.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -20,9 +20,9 @@
 import time
 
 import OpenRTM_aist
+import OpenRTM, OpenRTM__POA, RTC, RTC__POA
 
 
-
 ##
 # @if jp
 # @class ExtTrigExecutionContext
@@ -37,11 +37,12 @@
 # @else
 # @class ExtTrigExecutionContext
 # @endif
-class ExtTrigExecutionContext(OpenRTM_aist.PeriodicExecutionContext):
+class ExtTrigExecutionContext(OpenRTM_aist.ExecutionContextBase,
+                              OpenRTM__POA.ExtTrigExecutionContextService,
+                              OpenRTM_aist.Task):
   """
   """
 
-
   ##
   # @if jp
   # @brief コンストラクタ
@@ -54,62 +55,407 @@
   # @brief Constructor
   # @endif
   def __init__(self):
-    OpenRTM_aist.PeriodicExecutionContext.__init__(self)
-    self._worker = self.Worker()
-    self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("rtobject.exttrig_ec")
+    self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("rtobject.exttrig_async_ec")
+    self._rtcout.RTC_TRACE("ExtTrigExecutionContext.__init__()")
+    OpenRTM_aist.ExecutionContextBase.__init__(self,"exttrig_async_ec")
+    OpenRTM_aist.Task.__init__(self)
 
+    # getting my reference
+    self.setObjRef(self._this())
+
+    # profile initialization
+    self.setKind(RTC.PERIODIC)
+    self.setRate(OpenRTM_aist.DEFAULT_EXECUTION_RATE)
+
+    self._rtcout.RTC_DEBUG("Actual period: %d [sec], %d [usec]",
+                           (self._profile.getPeriod().sec(), self._profile.getPeriod().usec()))
+    self._svc = False
+    self._workerthread = self.Worker()
+    self._svcmutex = threading.RLock()
+    return
+
+
+  def __del__(self):
+    self._rtcout.RTC_TRACE("ExtTrigExecutionContext.__del__()")
+    guard = OpenRTM_aist.ScopedLock(self._svcmutex)
+    self._svc = False
+    del guard
+
+    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+    self._workerthread._cond.acquire()
+    self._workerthread._ticked = True
+    self._workerthread._cond.notify()
+    self._workerthread._cond.release()
+    del guard
+    self.wait()
+    Task.__del__(self)
+    return
+
+
   ##
+  # Start activity
+  # ACE_Task class method over ride.
+  # ------------------------------------------------------------
+
+  ##
   # @if jp
-  # @brief 処理を1ステップ進める
-  #
-  # ExecutionContextの処理を1周期分進める。
-  #
-  # @param self
-  #
+  # @brief ExecutionContext用アクティビティスレッドを生成する
   # @else
-  #
+  # @brief Generate internal activity thread for ExecutionContext
   # @endif
+  # int ExtTrigExecutionContext::open(void *args)
+  def open(self, *args):
+    self._rtcout.RTC_TRACE("open()")
+    self.activate()
+    return 0
+
+
+  ##
+  # @if jp
+  # @brief 各 Component の処理を呼び出す。
+  # @else
+  # @brief Invoke each component's operation
+  # @endif
+  # int ExtTrigExecutionContext::svc(void)
+  def svc(self):
+    self._rtcout.RTC_TRACE("svc()")
+
+    toSTR_ = lambda x: "True" if x else "False"
+
+    while self.threadRunning():
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      self._rtcout.RTC_DEBUG("Start of worker invocation. ticked = %s",
+                             toSTR_(self._workerthread._ticked))
+
+      while not self._workerthread._ticked:
+        self._workerthread._cond.wait() # wait for tick
+        self._rtcout.RTC_DEBUG("Thread was woken up.")
+
+      if not self._workerthread._ticked:
+        continue
+      del guard
+
+      t0_ = OpenRTM_aist.Time()
+      OpenRTM_aist.ExecutionContextBase.invokeWorkerPreDo(self)
+      OpenRTM_aist.ExecutionContextBase.invokeWorkerDo(self)
+      OpenRTM_aist.ExecutionContextBase.invokeWorkerPostDo(self)
+      t1_ = OpenRTM_aist.Time()
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      self._workerthread._ticked = False
+      del guard
+
+      period_ = self.getPeriod()
+
+      exctm_ = (t1_ - t0_).getTime().toDouble()
+      slptm_ = period_.toDouble() - exctm_
+      self._rtcout.RTC_PARANOID("Period:    %f [s]", period_.toDouble())
+      self._rtcout.RTC_PARANOID("Execution: %f [s]", exctm_)
+      self._rtcout.RTC_PARANOID("Sleep:     %f [s]", slptm_)
+
+      t2_ = OpenRTM_aist.Time()
+
+      if period_.toDouble() > ((t1_ - t0_).getTime().toDouble()):
+        self._rtcout.RTC_PARANOID("sleeping...")
+        slptm_ = period_.toDouble() - (t1_ - t0_).getTime().toDouble()
+        time.sleep(slptm_)
+
+      t3_ = OpenRTM_aist.Time()
+      self._rtcout.RTC_PARANOID("Slept:     %f [s]", (t3_ - t2_).getTime().toDouble())
+    return 0
+
+
+  ##
+  # @if jp
+  # @brief ExecutionContext 用のスレッド実行関数
+  # @else
+  # @brief Thread execution function for ExecutionContext
+  # @endif
+  # int ExtTrigExecutionContext::close(unsigned long flags)
+  def close(self, flags):
+    self._rtcout.RTC_TRACE("close()")
+    # At this point, this component have to be finished.
+    # Current state and Next state should be RTC_EXITING.
+    return 0
+
+
+  #============================================================
+  # ExtTrigExecutionContextService
+  #============================================================
+
+  ##
+  # @if jp
+  # @brief 処理を1ステップ進める
+  # @else
+  # @brief Move forward one step of ExecutionContext
+  # @endif
+  # void ExtTrigExecutionContext::tick()
+  #   throw (CORBA::SystemException)
   def tick(self):
     self._rtcout.RTC_TRACE("tick()")
-    if not self._worker._cond.acquire():
+    if not self.isRunning():
+      self._rtcout.RTC_DEBUG("EC is not running. do nothing.")
       return
-    self._worker._called = True
-    self._worker._cond.notify()
-    self._worker._cond.release()
+
+    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+    self._workerthread._ticked = True
+    self._workerthread._cond.acquire()
+    self._workerthread._cond.notify()
+    self._workerthread._cond.release()
+    self._rtcout.RTC_PARANOID("EC was ticked. Signal was sent to worker thread.")
+    del guard
     return
 
+
+  #============================================================
+  # ExecutionContextService
+  #============================================================
+
   ##
   # @if jp
-  # @brief 各 Component の処理を呼び出す。
-  # 
-  # ExecutionContext に attach されている各 Component の処理を呼び出す。
-  # 全 Component の処理を呼び出した後、次の呼出が発生するまで休止する。
-  # 
-  # @param self
-  # 
+  # @brief ExecutionContext 実行状態確認関数
   # @else
-  # 
+  # @brief Check for ExecutionContext running state
   # @endif
-  # 
-  def svc(self):
-    self._rtcout.RTC_TRACE("svc()")
-    flag = True
+  # CORBA::Boolean ExtTrigExecutionContext::is_running()
+  #   throw (CORBA::SystemException)
+  def is_running(self):
+    return OpenRTM_aist.ExecutionContextBase.isRunning(self)
 
-    while flag:
-      sec_ = float(self._period.usec())/1000000.0
-      self._worker._cond.acquire()
-      while not self._worker._called and self._running:
-        self._worker._cond.wait()
-      if self._worker._called:
-        self._worker._called = False
-        for comp in self._comps:
-          comp._sm.worker()
 
-      self._worker._cond.release()
-      flag = self._running
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行を開始
+  # @else
+  # @brief Start the ExecutionContext
+  # @endif
+  # RTC::ReturnCode_t ExtTrigExecutionContext::start()
+  #   throw (CORBA::SystemException)
+  def start(self):
+    return OpenRTM_aist.ExecutionContextBase.start(self)
 
+
   ##
   # @if jp
+  # @brief ExecutionContext の実行を停止
+  # @else
+  # @brief Stop the ExecutionContext
+  # @endif
+  # RTC::ReturnCode_t ExtTrigExecutionContext::stop()
+  #   throw (CORBA::SystemException)
+  def stop(self):
+    return OpenRTM_aist.ExecutionContextBase.stop(self)
+
+
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行周期(Hz)を取得する
+  # @else
+  # @brief Get execution rate(Hz) of ExecutionContext
+  # @endif
+  # CORBA::Double ExtTrigExecutionContext::get_rate()
+  #   throw (CORBA::SystemException)
+  def get_rate(self):
+    return OpenRTM_aist.ExecutionContextBase.getRate(self)
+
+
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行周期(Hz)を設定する
+  # @else
+  # @brief Set execution rate(Hz) of ExecutionContext
+  # @endif
+  # RTC::ReturnCode_t ExtTrigExecutionContext::set_rate(CORBA::Double rate)
+  #   throw (CORBA::SystemException)
+  def set_rate(self, rate):
+    return OpenRTM_aist.ExecutionContextBase.setRate(self, rate)
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントを追加する
+  # @else
+  # @brief Add an RT-Component
+  # @endif
+  # RTC::ReturnCode_t
+  # ExtTrigExecutionContext::add_component(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def add_component(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.addComponent(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief コンポーネントをコンポーネントリストから削除する
+  # @else
+  # @brief Remove the RT-Component from participant list
+  # @endif
+  # RTC::ReturnCode_t ExtTrigExecutionContext::
+  # remove_component(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def remove_component(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.removeComponent(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントをアクティブ化する
+  # @else
+  # @brief Activate an RT-Component
+  # @endif
+  # RTC::ReturnCode_t ExtTrigExecutionContext::
+  # activate_component(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def activate_component(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.activateComponent(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントを非アクティブ化する
+  # @else
+  # @brief Deactivate an RT-Component
+  # @endif
+  # RTC::ReturnCode_t ExtTrigExecutionContext::
+  # deactivate_component(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def deactivate_component(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.deactivateComponent(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントをリセットする
+  # @else
+  # @brief Reset the RT-Component
+  # @endif
+  # RTC::ReturnCode_t ExtTrigExecutionContext::
+  # reset_component(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def reset_component(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.resetComponent(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントの状態を取得する
+  # @else
+  # @brief Get RT-Component's state
+  # @endif
+  # RTC::LifeCycleState ExtTrigExecutionContext::
+  # get_component_state(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def get_component_state(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.getComponentState(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief ExecutionKind を取得する
+  # @else
+  # @brief Get the ExecutionKind
+  # @endif
+  # RTC::ExecutionKind ExtTrigExecutionContext::get_kind()
+  #   throw (CORBA::SystemException)
+  def get_kind(self):
+    return OpenRTM_aist.ExecutionContextBase.getKind(self)
+
+
+  #------------------------------------------------------------
+  # ExecutionContextService interfaces
+  #------------------------------------------------------------
+
+  ##
+  # @if jp
+  # @brief ExecutionContextProfile を取得する
+  # @else
+  # @brief Get the ExecutionContextProfile
+  # @endif
+  # RTC::ExecutionContextProfile* ExtTrigExecutionContext::get_profile()
+  #   throw (CORBA::SystemException)
+  def get_profile(self):
+    return OpenRTM_aist.ExecutionContextBase.getProfile(self)
+
+
+  #============================================================
+  # protected functions
+  #============================================================
+
+  ##
+  # @brief onStarted() template function
+  # RTC::ReturnCode_t ExtTrigExecutionContext::onStarted()
+  def onStarted(self):
+    # change EC thread state
+    guard = OpenRTM_aist.ScopedLock(self._svcmutex)
+    if not self._svc:
+      # If start() is called first time, start the worker thread.
+      self._svc = True
+      self.open(0)
+
+    return RTC.RTC_OK
+
+
+  ##
+  # @brief onWaitingActivated() template function
+  # RTC::ReturnCode_t ExtTrigExecutionContext::
+  # onWaitingActivated(RTC_impl::RTObjectStateMachine* comp, long int count)
+  def onWaitingActivated(self, comp, count):
+    self._rtcout.RTC_TRACE("onWaitingActivated(count = %d)", count)
+    self._rtcout.RTC_PARANOID("curr: %s, next: %s",
+                              (self.getStateString(comp.getStates().curr),
+                               self.getStateString(comp.getStates().next)))
+    # Now comp's next state must be ACTIVE state
+    # If worker thread is stopped, restart worker thread.
+    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+    self._workerthread._ticked = True
+    self._workerthread._cond.acquire()
+    self._workerthread._cond.notify()
+    self._workerthread._cond.release()
+    return RTC.RTC_OK
+
+
+  ##
+  # @brief onWaitingDeactivated() template function
+  # RTC::ReturnCode_t ExtTrigExecutionContext::
+  # onWaitingDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count)
+  def onWaitingDeactivated(self, comp, count):
+    self._rtcout.RTC_TRACE("onWaitingDeactivated(count = %d)", count)
+    self._rtcout.RTC_PARANOID("curr: %s, next: %s",
+                              (self.getStateString(comp.getStates().curr),
+                               self.getStateString(comp.getStates().next)))
+    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+    self._workerthread._ticked = True
+    self._workerthread._cond.acquire()
+    self._workerthread._cond.notify()
+    self._workerthread._cond.release()
+    return RTC.RTC_OK
+
+
+  ##
+  # @brief onWaitingReset() template function
+  # RTC::ReturnCode_t ExtTrigExecutionContext::
+  # onWaitingReset(RTC_impl::RTObjectStateMachine* comp, long int count)
+  def onWaitingReset(self, comp, count):
+    self._rtcout.RTC_TRACE("onWaitingReset(count = %d)", count)
+    self._rtcout.RTC_PARANOID("curr: %s, next: %s",
+                              (self.getStateString(comp.getStates().curr),
+                               self.getStateString(comp.getStates().next)))
+    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+    self._workerthread._ticked = True
+    self._workerthread._cond.acquire()
+    self._workerthread._cond.notify()
+    self._workerthread._cond.release()
+    return RTC.RTC_OK
+
+
+  # bool threadRunning()
+  def threadRunning(self):
+    guard = OpenRTM_aist.ScopedLock(self._svcmutex)
+    return self._svc
+
+
+
+  ##
+  # @if jp
   # @class Worker
   # @brief ExecutionContext 駆動クラス
   #
@@ -138,7 +484,7 @@
     def __init__(self):
       self._mutex = threading.RLock()
       self._cond = threading.Condition(self._mutex)
-      self._called = False
+      self._ticked = False
 
 
 
@@ -153,6 +499,6 @@
 #
 # @endif
 def ExtTrigExecutionContextInit(manager):
-  manager.registerECFactory("ExtTrigExecutionContext",
-                            OpenRTM_aist.ExtTrigExecutionContext,
-                            OpenRTM_aist.ECDelete)
+  OpenRTM_aist.ExecutionContextFactory.instance().addFactory("ExtTrigExecutionContext",
+                                                             OpenRTM_aist.ExtTrigExecutionContext,
+                                                             OpenRTM_aist.ECDelete)

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/GlobalFactory.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/GlobalFactory.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/GlobalFactory.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -21,6 +21,8 @@
 
 
 class Factory:
+  """
+  """
 
   FACTORY_OK     = 0
   FACTORY_ERROR  = 1
@@ -29,9 +31,53 @@
   INVALID_ARG    = 4
   UNKNOWN_ERROR  = 5
 
+  ##
+  # @if jp
+  #
+  # @class FactoryEntry
+  # @brief FactoryEntry クラス
+  #
+  # @else
+  #
+  # @class FactoryEntry
+  # @brief FactoryEntry class
+  #
+  # @endif
+  class FactoryEntry:
+    """
+    """
 
+    ##
+    # @if jp
+    #
+    # @brief コンストラクタ
+    #
+    # コンストラクタ。
+    #
+    # @param creator クリエータ用ファンクタ
+    # @param destructor デストラクタ用ファンクタ
+    #
+    # @else
+    #
+    # @brief Constructor
+    #
+    # Constructor
+    #
+    # @param creator Functor for creator.
+    # @param destructor Functor for destructor.
+    #
+    # @endif
+    # FactoryEntry(Identifier id, Creator creator, Destructor destructor)
+    def __init__(self, id, creator, destructor):
+      self.id_ = id
+      self.creator_ = creator
+      self.destructor_ = destructor
+      return
+
+
   def __init__(self):
     self._creators = {}
+    self._objects = {}
 
 
   ## bool hasFactory(const Identifier& id)
@@ -55,13 +101,13 @@
   ##                       Creator creator,
   ##                       Destructor destructor)
   def addFactory(self, id, creator, destructor):
-    if not creator:
+    if not creator or not destructor:
       return self.INVALID_ARG
 
     if self._creators.has_key(id):
       return self.ALREADY_EXISTS
     
-    self._creators[id] = creator
+    self._creators[id] = Factory.FactoryEntry(id, creator, destructor)
     return self.FACTORY_OK
 
 
@@ -79,18 +125,170 @@
     if not self._creators.has_key(id):
       print "Factory.createObject return None id: ", id
       return None
-    return self._creators[id]()
+    obj_ = self._creators[id].creator_()
+    assert(not self._objects.has_key(obj_))
+    self._objects[obj_] = self._creators[id]
+    return obj_
 
 
-  ## void deleteObject(const Identifier& id, AbstractClass*& obj)
+  ## ReturnCode deleteObject(const Identifier& id, AbstractClass*& obj)
   def deleteObject(self, obj, id=None):
     if id:
-      if not self._creators.has_key(id):
-        return
+      if self._creators.has_key(id):
+        self._creators[id].destructor_(obj)
+        del self._objects[obj]
+        return self.FACTORY_OK
 
-    del obj
-    return
+    if not self._objects.has_key(obj):
+      return self.NOT_FOUND
 
+    tmp = obj
+    self._objects[obj].destructor_(obj)
+    del self._objects[tmp]
+    return self.FACTORY_OK
+
+
+  ##
+  # @if jp
+  #
+  # @brief 生成済みオブジェクトリストの取得
+  #
+  # このファクトリで生成されたオブジェクトのリストを取得する。
+  #
+  # @return 生成済みオブジェクトリスト
+  #
+  # @else
+  #
+  # @brief Getting created objects
+  #
+  # This operation returns a list of created objects by the factory.
+  #
+  # @return created object list
+  #
+  # @endif
+  # std::vector<AbstractClass*> createdObjects()
+  def createdObjects(self):
+    objects_ = []
+    for id_ in self._objects.keys():
+      objects_.append(id_)
+
+    return objects_
+
+
+  ##
+  # @if jp
+  #
+  # @brief オブジェクトがこのファクトリの生成物かどうか調べる
+  #
+  # @param obj 対象オブジェクト
+  # @return true: このファクトリの生成物
+  #         false: このファクトリの生成物ではない
+  #
+  # @else
+  #
+  # @brief Whether a object is a product of this factory
+  #
+  # @param obj A target object
+  # @return true: The object is a product of the factory
+  #         false: The object is not a product of the factory
+  #
+  # @return created object list
+  #
+  # @endif
+  # bool isProducerOf(AbstractClass* obj)
+  def isProducerOf(self, obj):
+    return self._objects.has_key(obj)
+
+
+  ##
+  # @if jp
+  #
+  # @brief オブジェクトからクラス識別子(ID)を取得する
+  #
+  # 当該オブジェクトのクラス識別子(ID)を取得する。
+  #
+  # @param obj [in] クラス識別子(ID)を取得したいオブジェクト
+  # @param id [out] クラス識別子(ID)
+  # @return リターンコード NOT_FOUND: 識別子が存在しない
+  #                        FACTORY_OK: 正常終了
+  # @else
+  #
+  # @brief Getting class identifier (ID) from a object
+  #
+  # This operation returns a class identifier (ID) from a object.
+  #
+  # @param obj [in] An object to investigate its class ID.
+  # @param id [out] Class identifier (ID)
+  # @return Return code NOT_FOUND: ID not found
+  #                        FACTORY_OK: normal return
+  # @endif
+  # ReturnCode objectToIdentifier(AbstractClass* obj, Identifier& id)
+  def objectToIdentifier(self, obj, id):
+    if not self._objects.has_key(obj):
+      return self.NOT_FOUND
+
+    id[0] = self._objects[obj].id_
+    return self.FACTORY_OK
+
+
+  ##
+  # @if jp
+  #
+  # @brief オブジェクトのコンストラクタを取得する
+  #
+  # このファクトリで生成されたオブジェクトのコンストラクタを取得する。
+  # obj はこのファクトリで生成されたものでなければならない。予め
+  # isProducerOf() 関数で当該オブジェクトがこのファクトリの生成物で
+  # あるかどうかをチェックしなければならない。
+  #
+  # @return オブジェクトのデストラクタ
+  #
+  # @else
+  #
+  # @brief Getting destructor of the object
+  #
+  # This operation returns a constructor of the object created by
+  # the factory.  obj must be a product of the factory.  User must
+  # check if the object is a product of the factory by using
+  # isProducerOf()-function, before using this function.
+  #
+  # @return destructor of the object
+  #
+  # @endif
+  #Creator objectToCreator(AbstractClass* obj)
+  def objectToCreator(self, obj):
+    return self._objects[obj].creator_
+
+
+  ##
+  # @if jp
+  #
+  # @brief オブジェクトのデストラクタを取得する
+  #
+  # このファクトリで生成されたオブジェクトのデストラクタを取得する。
+  # obj はこのファクトリで生成されたものでなければならない。予め
+  # isProducerOf() 関数で当該オブジェクトがこのファクトリの生成物で
+  # あるかどうかをチェックしなければならない。
+  #
+  # @return オブジェクトのデストラクタ
+  #
+  # @else
+  #
+  # @brief Getting destructor of the object
+  #
+  # This operation returns a destructor of the object created by
+  # the factory.  obj must be a product of the factory.  User must
+  # check if the object is a product of the factory by using
+  # isProducerOf()-function, before using this function.
+  #
+  # @return destructor of the object
+  #
+  # @endif
+  #Destructor objectToDestructor(AbstractClass* obj)
+  def objectToDestructor(self, obj):
+    return self._objects[obj].destructor_
+
+
     
 gfactory = None
 

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceAdmin.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceAdmin.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/LocalServiceAdmin.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -64,28 +64,15 @@
     self._services = []
     self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("LocalServiceAdmin")
     self._rtcout.RTC_TRACE("LocalServiceAdmin.__init__()")
+    self._factory = OpenRTM_aist.LocalServiceFactory.instance()
     return
 
-    
-  ##
-  # @if jp
-  #
-  # @brief 仮想デストラクタ
-  # 
-  # 仮想デストラクタ。
-  # 
-  # @else
-  #
-  # @brief Virtual destractor
-  #
-  # Virtual destractor.
-  #
-  # @endif
+
   def __del__(self):
     self.finalize()
     return
-    
 
+
   ##
   # @if jp
   #
@@ -110,13 +97,12 @@
       self._rtcout.RTC_INFO("All the local services are enabled.")
       all_enable_ = True
     
-    factory_ = OpenRTM_aist.LocalServiceFactory.instance()
-    ids_ = factory_.getIdentifiers()
+    ids_ = self._factory.getIdentifiers()
     self._rtcout.RTC_DEBUG("Available services: %s", OpenRTM_aist.flatten(ids_))
     for id_ in ids_:
       if all_enable_ or self.isEnabled(id_, svcs_):
         if self.notExisting(id_):
-          service_ = factory_.createObject(id_)
+          service_ = self._factory.createObject(id_)
           self._rtcout.RTC_DEBUG("Service created: %s", id_)
           prop_ = props.getNode(id_)
           service_.init(prop_)
@@ -140,11 +126,11 @@
   # @endif
   # void finalize();
   def finalize(self):
-    factory_ = OpenRTM_aist.LocalServiceFactory.instance()
     for svc_ in self._services:
       svc_.finalize()
-      factory_.deleteObject(svc_)
+      self._factory.deleteObject(svc_)
     self._services = []
+
     return
     
 
@@ -289,8 +275,7 @@
     for (i,svc_) in enumerate(self._services):
       if name == svc_.getProfile().name:
         svc_.finalize()
-        factory_ = OpenRTM_aist.LocalServiceFactory.instance()
-        factory_.deleteObject(svc_)
+        self._factory.deleteObject(svc_)
         del self._services[i]
         self._rtcout.RTC_INFO("SDO service  has been deleted: %s", name)
         del guard_

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -862,7 +862,15 @@
                     "corba.id",
                     "exec_cxt.periodic.type",
                     "exec_cxt.periodic.rate",
-                    "exec_cxt.evdriven.type",
+                    "exec_cxt.event_driven.type",
+                    "exec_cxt.sync_transition",
+                    "exec_cxt.sync_activation",
+                    "exec_cxt.sync_deactivation",
+                    "exec_cxt.sync_reset",
+                    "exec_cxt.transition_timeout",
+                    "exec_cxt.activation_timeout",
+                    "exec_cxt.deactivation_timeout",
+                    "exec_cxt.reset_timeout",
                     "logger.enable",
                     "logger.log_level",
                     "naming.enable",
@@ -870,7 +878,8 @@
                     "naming.formats"]
 
     for i in range(len(inherit_prop)):
-      prop.setProperty(inherit_prop[i],self._config.getProperty(inherit_prop[i]))
+      if self._config.findNode(inherit_prop[i]):
+        prop.setProperty(inherit_prop[i],self._config.getProperty(inherit_prop[i]))
 
     comp = factory.create(self)
 
@@ -1879,7 +1888,6 @@
   # bool Manager::initLocalService()
   def initLocalService(self):
     self._rtcout.RTC_TRACE("Manager::initLocalService()")
-
     admin_ = OpenRTM_aist.LocalServiceAdmin.instance()
     prop_ = OpenRTM_aist.Properties(prop=self._config.getNode("manager.local_service"))
     admin_.init(prop_)
@@ -2110,6 +2118,7 @@
         name_prop.load(conff)
         self._rtcout.RTC_INFO("Component instance conf file: %s loaded.",
                               self._config.getProperty(name_conf))
+        self._rtcout.RTC_DEBUG(name_prop)
         config_fname.append(self._config.getProperty(name_conf))
       except:
         print "Not found. : %s" % self._config.getProperty(name_conf)
@@ -2123,6 +2132,7 @@
       if not (len(keys_) == 1 and keys_[-1] == "config_file"):
         name_prop.mergeProperties(self._config.getNode(category + "." + inst_name))
         self._rtcout.RTC_INFO("Component name conf exists in rtc.conf. Merged.")
+        self._rtcout.RTC_DEBUG(name_prop)
         if self._config.findNode("config_file"):
           config_fname.append(self._config.getProperty("config_file"))
 
@@ -2132,6 +2142,7 @@
         type_prop.load(conff)
         self._rtcout.RTC_INFO("Component type conf file: %s loaded.",
                               self._config.getProperty(type_conf))
+        self._rtcout.RTC_DEBUG(type_prop)
         config_fname.append(self._config.getProperty(type_conf))
       except:
         print "Not found. : %s" % self._config.getProperty(type_conf)
@@ -2145,6 +2156,7 @@
       if not (len(keys_) == 1 and keys_[-1] == "config_file"):
         type_prop.mergeProperties(self._config.getNode(category + "." + type_name))
         self._rtcout.RTC_INFO("Component type conf exists in rtc.conf. Merged.")
+        self._rtcout.RTC_DEBUG(type_prop)
         if self._config.findNode("config_file"):
           config_fname.append(self._config.getProperty("config_file"))
 


Property changes on: trunk/OpenRTM-aist-Python/OpenRTM_aist/ManagerConfig.py
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/RELENG_1_0/OpenRTM-aist-Python/OpenRTM_aist/ManagerConfig.py:345-395
/branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/ManagerConfig.py:396-478,488-497
/branches/work/OpenRTM-aist-Python/OpenRTM_aist/ManagerConfig.py:505-509
   + /branches/RELENG_1_0/OpenRTM-aist-Python/OpenRTM_aist/ManagerConfig.py:345-395
/branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/ManagerConfig.py:396-478,488-497
/branches/work/OpenRTM-aist-Python/OpenRTM_aist/ManagerConfig.py:504-542

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/OpenHRPExecutionContext.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/OpenHRPExecutionContext.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OpenHRPExecutionContext.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -14,25 +14,260 @@
 #         Advanced Industrial Science and Technology (AIST), Japan
 #     All rights reserved.
 
+import threading
+import time
 
 import OpenRTM_aist
+import OpenRTM, OpenRTM__POA, RTC, RTC__POA
 
-class OpenHRPExecutionContext(OpenRTM_aist.PeriodicExecutionContext):
 
-    def __init__(self):
-        OpenRTM_aist.PeriodicExecutionContext.__init__(self)
-        return
+class OpenHRPExecutionContext(OpenRTM_aist.ExecutionContextBase,
+                              OpenRTM__POA.ExtTrigExecutionContextService):
+  """
+  """
 
+  def __init__(self):
+    self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("rtobject.exttrig_sync_ec")
+    self._rtcout.RTC_TRACE("OpenHRPExecutionContext.__init__()")
+    OpenRTM_aist.ExecutionContextBase.__init__(self, "exttrig_sync_ec")
 
-    def tick(self):
-        for comp in self._comps:
-            comp._sm.worker()
+    self.setObjRef(self._this())
+    self.setKind(RTC.PERIODIC)
+    self.setRate(OpenRTM_aist.DEFAULT_EXECUTION_RATE)
+    self._rtcout.RTC_DEBUG("Actual rate: %d [sec], %d [usec]",
+                           (self._profile.getPeriod().sec(), self._profile.getPeriod().usec()))    
+    self._tickmutex = threading.RLock()
+    self._count = 0
+    return
 
-    def svc(self):
-        return 0
 
+  def __del__(self):
+    self._rtcout.RTC_TRACE("OpenHRPExecutionContext().__del__()")
+    return
 
+
+  #============================================================
+  # OpenHRPExecutionContextService
+  #============================================================
+  ##
+  # @if jp
+  # @brief 処理を1ステップ進める
+  # @else
+  # @brief Move forward one step of ExecutionContext
+  # @endif
+  def tick(self):
+    self._rtcout.RTC_TRACE("tick()")
+    if not self.isRunning():
+      return
+
+    guard = OpenRTM_aist.ScopedLock(self._tickmutex)
+
+    OpenRTM_aist.ExecutionContextBase.invokeWorkerPreDo(self) # update state
+    t0 = OpenRTM_aist.Time()
+    OpenRTM_aist.ExecutionContextBase.invokeWorkerDo(self)
+    t1 = OpenRTM_aist.Time()
+    OpenRTM_aist.ExecutionContextBase.invokeWorkerPostDo(self)
+    t2 = OpenRTM_aist.Time()
+
+    period = self.getPeriod()
+
+    if self._count > 1000:
+      excdotm = (t1 - t0).getTime().toDouble()
+      excpdotm = (t2 - t1).getTime().toDouble()
+      slptm = period.toDouble() - (t2 - t0).getTime().toDouble()
+      self._rtcout.RTC_PARANOID("Period:      %f [s]", period.toDouble())
+      self._rtcout.RTC_PARANOID("Exec-Do:     %f [s]", excdotm)
+      self._rtcout.RTC_PARANOID("Exec-PostDo: %f [s]", excpdotm)
+      self._rtcout.RTC_PARANOID("Sleep:       %f [s]", slptm)
+
+    t3 = OpenRTM_aist.Time()
+    if period.toDouble() > (t2 - t0).getTime().toDouble():
+      if self._count > 1000:
+        self._rtcout.RTC_PARANOID("sleeping...")
+        slptm = period.toDouble() - (t2 - t0).getTime().toDouble()
+        time.sleep(slptm)
+
+    if self._count > 1000:
+      t4 = OpenRTM_aist.Time()
+      self._rtcout.RTC_PARANOID("Slept:       %f [s]", (t4 - t3).getTime().toDouble())
+      self._count = 0
+
+    self._count += 1
+    return
+
+
+  #============================================================
+  # ExecutionContextService
+  #============================================================
+  ##
+  # @if jp
+  # @brief ExecutionContext 実行状態確認関数
+  # @else
+  # @brief Check for ExecutionContext running state
+  # @endif
+  # CORBA::Boolean OpenHRPExecutionContext::is_running()
+  #   throw (CORBA::SystemException)
+  def is_running(self):
+    return OpenRTM_aist.ExecutionContextBase.isRunning(self)
+
+
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行を開始
+  # @else
+  # @brief Start the ExecutionContext
+  # @endif
+  # RTC::ReturnCode_t OpenHRPExecutionContext::start()
+  #   throw (CORBA::SystemException)
+  def start(self):
+    return OpenRTM_aist.ExecutionContextBase.start(self)
+
+
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行を停止
+  # @else
+  # @brief Stop the ExecutionContext
+  # @endif
+  # RTC::ReturnCode_t OpenHRPExecutionContext::stop()
+  #   throw (CORBA::SystemException)
+  def stop(self):
+    return OpenRTM_aist.ExecutionContextBase.stop(self)
+
+
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行周期(Hz)を取得する
+  # @else
+  # @brief Get execution rate(Hz) of ExecutionContext
+  # @endif
+  # CORBA::Double OpenHRPExecutionContext::get_rate()
+  #   throw (CORBA::SystemException)
+  def get_rate(self):
+    return OpenRTM_aist.ExecutionContextBase.getRate(self)
+
+
+  ##
+  # @if jp
+  # @brief ExecutionContext の実行周期(Hz)を設定する
+  # @else
+  # @brief Set execution rate(Hz) of ExecutionContext
+  # @endif
+  # RTC::ReturnCode_t OpenHRPExecutionContext::set_rate(CORBA::Double rate)
+  #   throw (CORBA::SystemException)
+  def set_rate(self, rate):
+    return OpenRTM_aist.ExecutionContextBase.setRate(self, rate)
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントを追加する
+  # @else
+  # @brief Add an RT-Component
+  # @endif
+  # RTC::ReturnCode_t
+  # OpenHRPExecutionContext::add_component(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def add_component(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.addComponent(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief コンポーネントをコンポーネントリストから削除する
+  # @else
+  # @brief Remove the RT-Component from participant list
+  # @endif
+  # RTC::ReturnCode_t OpenHRPExecutionContext::
+  # remove_component(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def remove_component(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.removeComponent(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントをアクティブ化する
+  # @else
+  # @brief Activate an RT-Component
+  # @endif
+  # RTC::ReturnCode_t OpenHRPExecutionContext::
+  # activate_component(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def activate_component(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.activateComponent(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントを非アクティブ化する
+  # @else
+  # @brief Deactivate an RT-Component
+  # @endif
+  # RTC::ReturnCode_t OpenHRPExecutionContext::
+  # deactivate_component(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def deactivate_component(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.deactivateComponent(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントをリセットする
+  # @else
+  # @brief Reset the RT-Component
+  # @endif
+  # RTC::ReturnCode_t OpenHRPExecutionContext::
+  # reset_component(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def reset_component(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.resetComponent(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief RTコンポーネントの状態を取得する
+  # @else
+  # @brief Get RT-Component's state
+  # @endif
+  # RTC::LifeCycleState OpenHRPExecutionContext::
+  # get_component_state(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  # get_component_state(RTC::LightweightRTObject_ptr comp)
+  #   throw (CORBA::SystemException)
+  def get_component_state(self, comp):
+    return OpenRTM_aist.ExecutionContextBase.getComponentState(self, comp)
+
+
+  ##
+  # @if jp
+  # @brief ExecutionKind を取得する
+  # @else
+  # @brief Get the ExecutionKind
+  # @endif
+  # RTC::ExecutionKind OpenHRPExecutionContext::get_kind()
+  #   throw (CORBA::SystemException)
+  def get_kind(self):
+    return OpenRTM_aist.ExecutionContextBase.getKind(self)
+
+
+  #------------------------------------------------------------
+  # ExecutionContextService interfaces
+  #------------------------------------------------------------
+  ##
+  # @if jp
+  # @brief ExecutionContextProfile を取得する
+  # @else
+  # @brief Get the ExecutionContextProfile
+  # @endif
+  # RTC::ExecutionContextProfile* OpenHRPExecutionContext::get_profile()
+  #   throw (CORBA::SystemException)
+  def get_profile(self):
+    return OpenRTM_aist.ExecutionContextBase.getProfile(self)
+
+
 def OpenHRPExecutionContextInit(manager):
-  manager.registerECFactory("OpenHRPExecutionContext",
-                            OpenRTM_aist.OpenHRPExecutionContext,
-                            OpenRTM_aist.ECDelete)
+  OpenRTM_aist.ExecutionContextFactory.instance().addFactory("OpenHRPExecutionContext",
+                                                             OpenRTM_aist.OpenHRPExecutionContext,
+                                                             OpenRTM_aist.ECDelete)
+  return

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -22,7 +22,7 @@
 
 import OpenRTM_aist
 import OpenRTM
-import RTC
+import RTC, RTC__POA
 
 DEFAULT_PERIOD = 0.000001
 
@@ -40,383 +40,59 @@
 # @brief PeriodicExecutionContext class
 # @endif
 class PeriodicExecutionContext(OpenRTM_aist.ExecutionContextBase,
+                               RTC__POA.ExecutionContextService,
                                OpenRTM_aist.Task):
   """
   """
 
-
-
   ##
   # @if jp
-  # @class DFP
-  # @brief DFP クラス
-  #
-  # 参加者リストに登録された DataFlowParticipant の関数を起動するための
-  # 内部クラス。
-  #
-  # @param Object 管理対象コンポーネントの型
-  #
-  # @else
-  #
-  # @endif
-  class DFP:
-    """
-    """
-
-    ##
-    # @if jp
-    # @brief デフォルトコンストラクタ
-    #
-    # デフォルトコンストラクタ
-    #
-    # @param self
-    # @param obj 管理対象コンポーネント
-    # @param id_ 所属する ExecutionContext のID
-    #
-    # @else
-    # @brief Constructor
-    # @endif
-    def __init__(self, obj, id_):
-      self._obj = obj
-      self._active = True
-      self.ec_id = id_
-      self._sm = OpenRTM_aist.StateMachine(4)
-      self._sm.setListener(self)
-      self._sm.setEntryAction (RTC.ACTIVE_STATE,
-                               self.on_activated)
-      self._sm.setDoAction    (RTC.ACTIVE_STATE,
-                               self.on_execute)
-      self._sm.setPostDoAction(RTC.ACTIVE_STATE,
-                               self.on_state_update)
-      self._sm.setExitAction  (RTC.ACTIVE_STATE,
-                               self.on_deactivated)
-      self._sm.setEntryAction (RTC.ERROR_STATE,
-                               self.on_aborting)
-      self._sm.setDoAction    (RTC.ERROR_STATE,
-                               self.on_error)
-      self._sm.setExitAction  (RTC.ERROR_STATE,
-                               self.on_reset)
-      st = OpenRTM_aist.StateHolder()
-      st.prev = RTC.INACTIVE_STATE
-      st.curr = RTC.INACTIVE_STATE
-      st.next = RTC.INACTIVE_STATE
-      self._sm.setStartState(st)
-      self._sm.goTo(RTC.INACTIVE_STATE)
-
-
-    ##
-    # @if jp
-    # @brief ExecutionContext 実行開始時に呼ばれる関数
-    #
-    # 参加している ExecutionContext が実行を開始する時(Running状態へ遷移時)
-    # に、管理対象コンポーネントの on_startup を呼びだす。
-    #
-    # @param self
-    #
-    # @else
-    #
-    # @brief
-    #
-    # @endif
-    def on_startup(self):
-      return self._obj.on_startup(self.ec_id)
-
-
-    ##
-    # @if jp
-    # @brief ExecutionContext 停止時に呼ばれる関数
-    #
-    # 参加している ExecutionContext が実行を停止する時(Stopped状態へ遷移時)
-    # に、管理対象コンポーネントの on_shutdown を呼びだす。
-    #
-    # @param self
-    #
-    # @else
-    #
-    # @endif
-    def on_shutdown(self):
-      return self._obj.on_shutdown(self.ec_id)
-
-
-    ##
-    # @if jp
-    # @brief RTコンポーネントがアクティブ化された時に呼ばれる関数
-    #
-    # 管理対象のRTコンポーネントがアクティブ化された時(Active状態へ遷移時)
-    # に、管理対象コンポーネントの on_activated を呼びだす。
-    # 管理対象コンポーネントのアクティブ化が失敗した場合には、ステートマシン
-    # を Error 状態に遷移させる。
-    #
-    # @param self
-    # @param st 対象RTコンポーネントの現在の状態
-    #
-    # @else
-    #
-    # @endif
-    def on_activated(self, st):
-      if self._obj.on_activated(self.ec_id) != RTC.RTC_OK:
-        self._sm.goTo(RTC.ERROR_STATE)
-        return
-      return
-
-
-    ##
-    # @if jp
-    # @brief RTコンポーネントが非アクティブ化された時に呼ばれる関数
-    #
-    # 管理対象のRTコンポーネントが非アクティブ化された時
-    # (Deactive状態へ遷移時)に、管理対象コンポーネントの on_deactivated を
-    # 呼びだす。
-    #
-    # @param self
-    # @param st 対象RTコンポーネントの現在の状態
-    #
-    # @else
-    #
-    # @endif
-    def on_deactivated(self, st):
-      self._obj.on_deactivated(self.ec_id)
-
-
-    ##
-    # @if jp
-    # @brief RTコンポーネントでエラーが発生した時に呼ばれる関数
-    #
-    # 管理対象のRTコンポーネントにエラーが発生した時(Error状態へ遷移時)
-    # に管理対象コンポーネントの on_aborting を呼びだす。
-    #
-    # @param self
-    # @param st 対象RTコンポーネントの現在の状態
-    #
-    # @else
-    #
-    # @brief
-    #
-    # @endif
-    def on_aborting(self, st):
-      self._obj.on_aborting(self.ec_id)
-
-
-    ##
-    # @if jp
-    # @brief RTコンポーネントがエラー状態の時に呼ばれる関数
-    #
-    # 管理対象のRTコンポーネントがエラー状態にいる間、 
-    # 管理対象コンポーネントの on_error を定期的に呼びだす。
-    #
-    # @param self
-    # @param st 対象RTコンポーネントの現在の状態
-    #
-    # @else
-    #
-    # @brief
-    #
-    # @endif
-    def on_error(self, st):
-      self._obj.on_error(self.ec_id)
-
-
-    ##
-    # @if jp
-    # @brief RTコンポーネントをリセットする時に呼ばれる関数
-    #
-    # 管理対象のRTコンポーネントをリセットする際に、管理対象コンポーネント
-    # の on_reset を呼びだす。
-    #
-    # @param self
-    # @param st 対象RTコンポーネントの現在の状態
-    #
-    # @else
-    #
-    # @endif
-    def on_reset(self, st):
-      if self._obj.on_reset(self.ec_id) != RTC.RTC_OK:
-        self._sm.goTo(RTC.ERROR_STATE)
-        return
-      return
-
-
-    ##
-    # @if jp
-    # @brief RTコンポーネント実行時に定期的に呼ばれる関数
-    #
-    # 管理対象のRTコンポーネントが Active 状態であるとともに、
-    # ExecutionContext が Running 状態の場合に、設定された動作周期で定期的に
-    # 管理対象コンポーネントの on_execute を呼びだす。
-    # 関数の実行に失敗した場合(返値が RTC_OK 以外)、管理対象コンポーネントの
-    # 状態を Error 状態に遷移させる。
-    #
-    # @param self
-    # @param st 対象RTコンポーネントの現在の状態
-    #
-    # @else
-    #
-    # @endif
-    def on_execute(self, st):
-      if self._obj.on_execute(self.ec_id) != RTC.RTC_OK:
-        self._sm.goTo(RTC.ERROR_STATE)
-        return
-      return
-
-
-    ##
-    # @if jp
-    # @brief RTコンポーネント実行時に定期的に呼ばれる関数
-    #
-    # 管理対象のRTコンポーネントが Active 状態であるとともに、
-    # ExecutionContext が Running 状態の場合に、設定された動作周期で定期的に
-    # 管理対象コンポーネントの on_state_update を呼びだす。
-    # 関数の実行に失敗した場合(返値が RTC_OK 以外)、管理対象コンポーネントの
-    # 状態を Error 状態に遷移させる。
-    #
-    # @param self
-    # @param st 対象RTコンポーネントの現在の状態
-    #
-    # @else
-    #
-    # @endif
-    def on_state_update(self, st):
-      if self._obj.on_state_update(self.ec_id) != RTC.RTC_OK:
-        self._sm.goTo(RTC.ERROR_STATE)
-        return
-      return
-
-
-    ##
-    # @if jp
-    # @brief ExecutionContext の実行周期変更時に呼ばれる関数
-    #
-    # 参加している ExecutionContext の実行周期が変更となった場合に、
-    # 管理対象コンポーネントの on_rate_changed を呼びだす。
-    #
-    # @param self
-    #
-    # @else
-    #
-    # @endif
-    def on_rate_changed(self):
-      self._obj.on_rate_changed(self.ec_id)
-
-
-    ##
-    # @if jp
-    # @brief 状態遷移を実行するワーカーを取得する
-    #
-    # 管理対象RTコンポーネントの状態遷移を実行するワーカーを取得する。
-    #
-    # @param self
-    #
-    # @return ワーカー
-    #
-    # @else
-    #
-    # @brief
-    #
-    # @endif
-    def worker(self):
-      return self._sm.worker()
-
-
-    ##
-    # @if jp
-    # @brief 現在の状態を取得する
-    #
-    # 管理対象RTコンポーネントの現在の状態を取得する。
-    #
-    # @param self
-    #
-    # @return 現在状態
-    #
-    # @else
-    #
-    # @brief
-    #
-    # @endif
-    def get_state(self):
-      return self._sm.getState()
-
-
-  ##
-  # @if jp
   # @brief コンストラクタ
   #
   # コンストラクタ
   # 設定された値をプロファイルに設定する。
   #
-  # @param self
-  # @param owner 当該 Executioncontext の owner(デフォルト値:None)
-  # @param rate 動作周期(Hz)(デフォルト値:None)
-  #
   # @else
   # @brief Constructor
   # @endif
-  def __init__(self, owner=None, rate=None):
+  def __init__(self):
     self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("rtobject.periodic_ec")
-    self._rtcout.RTC_TRACE("PeriodicExecutionContext()")
-
+    self._rtcout.RTC_TRACE("PeriodicExecutionContext.__init__()")
+    OpenRTM_aist.ExecutionContextBase.__init__(self, "periodic_ec")
     OpenRTM_aist.Task.__init__(self)
 
+    self._svc = False
     self._nowait = False
-    self._running = False
+    self._svcmutex = threading.RLock()
+    self._workerthread = self.WorkerThreadCtrl()
 
-    self._worker = self.Worker()
-
     global DEFAULT_PERIOD
-
-    if rate is None:
-      self._period = OpenRTM_aist.TimeValue(DEFAULT_PERIOD)
-    else:
-      if rate == 0:
-        rate = 1.0 / DEFAULT_PERIOD
-      self._period = OpenRTM_aist.TimeValue(1.0 / rate)
-
-      if self._period.sec() == 0  and self._period.usec() < 0.000001:
-        self._nowait = True
-
+    self.setObjRef(self._this())
+    self.setKind(RTC.PERIODIC)
+    self.setRate(1.0 / DEFAULT_PERIOD)
     self._rtcout.RTC_DEBUG("Actual rate: %d [sec], %d [usec]",
-                           (self._period.sec(), self._period.usec()))    
+                           (self._profile.getPeriod().sec(), self._profile.getPeriod().usec()))    
 
-    self._comps = []
-    self._profile = RTC.ExecutionContextProfile(RTC.PERIODIC, (1.0/self._period.toDouble()), None, [], [])
-    self._ref = self._this()
-    self._mutex_del = threading.RLock()
     return
 
 
   def __del__(self, Task=OpenRTM_aist.Task):
-    self._rtcout.RTC_TRACE("~PeriodicExecutionContext()")
-    self._worker._cond.acquire()
-    self._worker._running = True
-    self._worker._cond.notify()
-    self._worker._cond.release()
-    self._running = False
-    #self.wait()
+    self._rtcout.RTC_TRACE("PeriodicExecutionContext.__del__()")
+    guard = OpenRTM_aist.ScopedLock(self._svcmutex)
+    self._svc = False
+    del guard
 
-    self._profile.owner = None
-    self._profile.paarticipants = []
-    self._profile.properties = []
-    guard = OpenRTM_aist.ScopedLock(self._mutex_del)
-    Task.__del__(self)
+    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+    self._workerthread._cond.acquire()
+    self._workerthread._running = True
+    self._workerthread._cond.notify()
+    self._workerthread._cond.release()
     del guard
+    self.wait()
+    Task.__del__(self)
+    return
 
-  ##
-  # @if jp
-  # @brief CORBA オブジェクト参照の取得
-  #
-  # 本オブジェクトの ExecutioncontextService としての CORBA オブジェクト参照
-  # を取得する。
-  #
-  # @return CORBA オブジェクト参照
-  #
-  # @param self
-  #
-  # @else
-  #
-  # @endif
-  def getObjRef(self):
-    return self._ref
 
-
   ##
   # @if jp
   # @brief コンポーネントのアクティビティスレッド関数
@@ -434,38 +110,39 @@
   # @endif
   def svc(self):
     self._rtcout.RTC_TRACE("svc()")
-    flag = True
     count_ = 0
     
-    guard = OpenRTM_aist.ScopedLock(self._mutex_del)
-    while flag:
-      self._worker._cond.acquire()
-      while not self._worker._running:
-        self._worker._cond.wait()
+    while self.threadRunning():
+      OpenRTM_aist.ExecutionContextBase.invokeWorkerPreDo(self)
+      # Thread will stopped when all RTCs are INACTIVE.
+      # Therefore WorkerPreDo(updating state) have to be invoked
+      # before stopping thread.
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      while not self._workerthread._running:
+        self._workerthread._cond.wait()
+      del guard
 
       t0_ = OpenRTM_aist.Time()
-
-      if self._worker._running:
-        for comp in self._comps:
-          comp._sm.worker()
-
-      self._worker._cond.release()
-
+      OpenRTM_aist.ExecutionContextBase.invokeWorkerDo(self)
+      OpenRTM_aist.ExecutionContextBase.invokeWorkerPostDo(self)
       t1_ = OpenRTM_aist.Time()
 
+      period_ = self.getPeriod()
+
       if count_ > 1000:
         exctm_ = (t1_ - t0_).getTime().toDouble()
-        slptm_ = self._period.toDouble() - exctm_
-        self._rtcout.RTC_PARANOID("Period:    %f [s]", self._period.toDouble())
+        slptm_ = period_.toDouble() - exctm_
+        self._rtcout.RTC_PARANOID("Period:    %f [s]", period_.toDouble())
         self._rtcout.RTC_PARANOID("Execution: %f [s]", exctm_)
         self._rtcout.RTC_PARANOID("Sleep:     %f [s]", slptm_)
 
+
       t2_ = OpenRTM_aist.Time()
 
-      if not self._nowait and self._period.toDouble() > ((t1_ - t0_).getTime().toDouble()):
+      if not self._nowait and period_.toDouble() > ((t1_ - t0_).getTime().toDouble()):
         if count_ > 1000:
           self._rtcout.RTC_PARANOID("sleeping...")
-        slptm_ = self._period.toDouble() - (t1_ - t0_).getTime().toDouble()
+        slptm_ = period_.toDouble() - (t1_ - t0_).getTime().toDouble()
         time.sleep(slptm_)
 
       if count_ > 1000:
@@ -473,13 +150,27 @@
         self._rtcout.RTC_PARANOID("Slept:     %f [s]", (t3_ - t2_).getTime().toDouble())
         count_ = 0
       count_ += 1
-      flag = self._running
-    del guard
+
+    self._rtcout.RTC_DEBUG("Thread terminated.")
     return 0
 
 
   ##
   # @if jp
+  # @brief ExecutionContext用アクティビティスレッドを生成する
+  # @else
+  # @brief Generate internal activity thread for ExecutionContext
+  # @endif
+  #
+  # int PeriodicExecutionContext::open(void *args)
+  def open(self, *args):
+    self._rtcout.RTC_TRACE("open()")
+    self.activate()
+    return 0
+
+
+  ##
+  # @if jp
   # @brief ExecutionContext 用のスレッド実行関数
   #
   # ExecutionContext 用のスレッド終了時に呼ばれる。
@@ -530,7 +221,7 @@
   # @endif
   def is_running(self):
     self._rtcout.RTC_TRACE("is_running()")
-    return self._running
+    return OpenRTM_aist.ExecutionContextBase.isRunning(self)
 
 
   ##
@@ -561,34 +252,9 @@
   #
   # @endif
   def start(self):
-    self._rtcout.RTC_TRACE("start()")
-    if self._running:
-      return RTC.PRECONDITION_NOT_MET
+    return OpenRTM_aist.ExecutionContextBase.start(self)
 
-    for comp in self._comps:
-      comp._sm.on_startup()
 
-    self._running = True
-
-    self._worker._cond.acquire()
-    self._worker._running = True
-    self._worker._cond.notify()
-    self._worker._cond.release()
-
-    try:
-      self.activate()
-    except:
-      self._running = False
-
-      self._worker._cond.acquire()
-      self._worker._running = False
-      self._worker._cond.notify()
-      self._worker._cond.release()
-      self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
-
-    return RTC.RTC_OK
-
-
   ##
   # @if jp
   # @brief ExecutionContext の実行を停止
@@ -616,22 +282,9 @@
   #
   # @endif
   def stop(self):
-    self._rtcout.RTC_TRACE("stop()")
-    if not self._running:
-      return RTC.PRECONDITION_NOT_MET
+    return OpenRTM_aist.ExecutionContextBase.stop(self)
 
-    self._running = False
-    self._worker._cond.acquire()
-    self._worker._running = False
-    self._worker._cond.release()
 
-    for comp in self._comps:
-      comp._sm.on_shutdown()
-
-    #self.wait()
-    return RTC.RTC_OK
-
-
   ##
   # @if jp
   # @brief ExecutionContext の実行周期(Hz)を取得する
@@ -651,8 +304,7 @@
   #
   # @endif
   def get_rate(self):
-    self._rtcout.RTC_TRACE("get_rate()")
-    return self._profile.rate
+    return OpenRTM_aist.ExecutionContextBase.getRate(self)
 
 
   ##
@@ -681,19 +333,9 @@
   #
   # @endif
   def set_rate(self, rate):
-    self._rtcout.RTC_TRACE("set_rate(%f)", rate)
-    if rate > 0.0:
-      self._profile.rate = rate
-      self._period.set_time(1.0/rate)
-      if self._period.toDouble() == 0.0:
-        self._nowait = True
+    return OpenRTM_aist.ExecutionContextBase.setRate(self, rate)
 
-      for comp in self._comps:
-        comp._sm.on_rate_changed()
-      return RTC.RTC_OK
-    return RTC.BAD_PARAMETER
 
-
   ##
   # @if jp
   # @brief RTコンポーネントをアクティブ化する
@@ -724,17 +366,9 @@
   #
   # @endif
   def activate_component(self, comp):
-    self._rtcout.RTC_TRACE("activate_component()")
-    for compIn in self._comps:
-      if compIn._ref._is_equivalent(comp):
-        if not compIn._sm._sm.isIn(RTC.INACTIVE_STATE):
-          return RTC.PRECONDITION_NOT_MET
-        compIn._sm._sm.goTo(RTC.ACTIVE_STATE)
-        return RTC.RTC_OK
+    return OpenRTM_aist.ExecutionContextBase.activateComponent(self, comp)
 
-    return RTC.BAD_PARAMETER
 
-
   ##
   # @if jp
   # @brief RTコンポーネントを非アクティブ化する
@@ -765,32 +399,9 @@
   #
   # @endif
   def deactivate_component(self, comp):
-    self._rtcout.RTC_TRACE("deactivate_component()")
-    for compIn in self._comps:
-      if compIn._ref._is_equivalent(comp):
-        if not compIn._sm._sm.isIn(RTC.ACTIVE_STATE):
-          return RTC.PRECONDITION_NOT_MET
-        compIn._sm._sm.goTo(RTC.INACTIVE_STATE)
-        count_ = 0
-        usec_per_sec_ = 1.0e6
-        sleeptime_ = usec_per_sec_ / float(self.get_rate())
-        self._rtcout.RTC_PARANOID("Sleep time is %f [us]", sleeptime_)
-        while compIn._sm._sm.isIn(RTC.ACTIVE_STATE):
-          self._rtcout.RTC_TRACE("Waiting to be the INACTIVE state %d %f", (count_, float(time.time())))
-          time.sleep(sleeptime_/usec_per_sec_)
-          if count_ > 1000:
-            self._rtcout.RTC_ERROR("The component is not responding.")
-            break
-          count_ += 1
-        if compIn._sm._sm.isIn(RTC.INACTIVE_STATE):
-          self._rtcout.RTC_TRACE("The component has been properly deactivated.")
-          return RTC.RTC_OK
-        self._rtcout.RTC_ERROR("The component could not be deactivated.")
-        return RTC.RTC_ERROR
+    return OpenRTM_aist.ExecutionContextBase.deactivateComponent(self, comp)
 
-    return RTC.BAD_PARAMETER
 
-
   ##
   # @if jp
   # @brief RTコンポーネントをリセットする
@@ -820,17 +431,9 @@
   #
   # @endif
   def reset_component(self, comp):
-    self._rtcout.RTC_TRACE("reset_component()")
-    for compIn in self._comps:
-      if compIn._ref._is_equivalent(comp):
-        if not compIn._sm._sm.isIn(RTC.ERROR_STATE):
-          return RTC.PRECONDITION_NOT_MET
-        compIn._sm._sm.goTo(RTC.INACTIVE_STATE)
-        return RTC.RTC_OK
+    return OpenRTM_aist.ExecutionContextBase.resetComponent(self, comp)
 
-    return RTC.BAD_PARAMETER
 
-
   ##
   # @if jp
   # @brief RTコンポーネントの状態を取得する
@@ -853,14 +456,9 @@
   #
   # @endif
   def get_component_state(self, comp):
-    self._rtcout.RTC_TRACE("get_component_state()")
-    for compIn in self._comps:
-      if compIn._ref._is_equivalent(comp):
-        return compIn._sm._sm.getState()
+    return OpenRTM_aist.ExecutionContextBase.getComponentState(self, comp)
 
-    return RTC.CREATED_STATE
 
-
   ##
   # @if jp
   # @brief ExecutionKind を取得する
@@ -879,8 +477,7 @@
   #
   # @endif
   def get_kind(self):
-    self._rtcout.RTC_TRACE("get_kind()")
-    return self._profile.kind
+    return OpenRTM_aist.ExecutionContextBase.getKind(self)
 
 
   ##
@@ -910,46 +507,9 @@
   #
   # @endif
   def add_component(self, comp):
-    self._rtcout.RTC_TRACE("add_component()")
-    if CORBA.is_nil(comp):
-      return RTC.BAD_PARAMETER
-    try:
-      dfp_  = comp._narrow(OpenRTM.DataFlowComponent)
-      rtc_  = comp._narrow(RTC.RTObject)
-      if CORBA.is_nil(dfp_) or CORBA.is_nil(rtc_):
-        return RTC.BAD_PARAMETER
+    return OpenRTM_aist.ExecutionContextBase.addComponent(self, comp)
 
-      id_   = dfp_.attach_context(self._ref)
-      comp_ = self.Comp(ref=comp, dfp=dfp_, id=id_)
-      self._comps.append(comp_)
-      self._profile.participants.append(rtc_)
-      return RTC.RTC_OK
-    except CORBA.Exception:
-      self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
-      return RTC.BAD_PARAMETER
 
-    return RTC.RTC_OK
-
-
-  def bindComponent(self, rtc):
-    self._rtcout.RTC_TRACE("bindComponent()")
-    if rtc is None:
-      return RTC.BAD_PARAMETER
-
-    comp_ = rtc.getObjRef()
-    dfp_  = comp_._narrow(OpenRTM.DataFlowComponent)
-    id_   = rtc.bindContext(self._ref)
-    if id_ < 0 or id_ > OpenRTM_aist.ECOTHER_OFFSET:
-      self._rtcout.RTC_ERROR("bindContext returns invalid id: %d", id_)
-      return RTC.RTC_ERROR
-
-    self._rtcout.RTC_DEBUG("bindContext returns id = %d", id_)
-    # rtc is owner of this EC
-    self._comps.append(self.Comp(ref=comp_, dfp=dfp_, id=id_))
-    self._profile.owner = dfp_
-    return RTC.RTC_OK
-
-
   ##
   # @if jp
   # @brief RTコンポーネントを参加者リストから削除する
@@ -975,24 +535,9 @@
   #
   # @endif
   def remove_component(self, comp):
-    self._rtcout.RTC_TRACE("remove_component()")
-    len_ = len(self._comps)
-    for i in range(len_):
-      idx = (len_ - 1) - i
-      if self._comps[idx]._ref._is_equivalent(comp):
-        self._comps[idx]._ref.detach_context(self._comps[idx]._sm.ec_id)
-        del self._comps[idx]
-        rtcomp = comp._narrow(RTC.RTObject)
-        if CORBA.is_nil(rtcomp):
-          self._rtcout.RTC_ERROR("Invalid object reference.")
-          return RTC.RTC_ERROR
-        OpenRTM_aist.CORBA_SeqUtil.erase_if(self._profile.participants,
-                                            self.find_participant(rtcomp))
-        return RTC.RTC_OK
+    return OpenRTM_aist.ExecutionContextBase.removeComponent(self, comp)
 
-    return RTC.BAD_PARAMETER
 
-
   ##
   # @if jp
   # @brief ExecutionContextProfile を取得する
@@ -1012,47 +557,167 @@
   #
   # @endif
   def get_profile(self):
-    self._rtcout.RTC_TRACE("get_profile()")
-    return self._profile
+    return OpenRTM_aist.ExecutionContextBase.getProfile(self)
 
 
-  class find_participant:
-    def __init__(self, comp):
-      self._comp = comp
-      return
+  # virtual RTC::ReturnCode_t onStarted();
+  def onStarted(self):
+    # change EC thread state
+    guard = OpenRTM_aist.ScopedLock(self._svcmutex)
+    if not self._svc:
+      self._svc = True
+      self.open(0)
+    del guard
 
-    def __call__(self, comp):
-      return self._comp._is_equivalent(comp)
+    if self.isAllNextState(RTC.INACTIVE_STATE):
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      self._workerthread._running = False
+      del guard
+    else:
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      self._workerthread._running = True
+      self._workerthread._cond.acquire()
+      self._workerthread._cond.notify()
+      self._workerthread._cond.release()
+      del guard
+    return RTC.RTC_OK
 
-      
-  ##
-  # @if jp
-  # @class Comp
-  # @brief コンポーネント管理用内部クラス
-  # @else
-  # @endif
-  class Comp:
-    def __init__(self, ref=None, dfp=None, id=None, comp=None):
-      if comp is None:
-        self._ref = ref
-        self._sm = PeriodicExecutionContext.DFP(dfp,id)
-      else:
-        self._ref = comp._ref
-        self._sm  = PeriodicExecutionContext.DFP(comp._sm._obj,comp._sm.ec_id)
 
+  # virtual RTC::ReturnCode_t onStopping();
+  def onStopping(self):
+    # stop thread
+    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+    self._workerthread._running = False
+    return RTC.RTC_OK
+
+
+  # virtual RTC::ReturnCode_t
+  # onWaitingActivated(RTC_impl::RTObjectStateMachine* comp, long int count);
+  def onWaitingActivated(self, comp, count):
+    self._rtcout.RTC_TRACE("onWaitingActivated(count = %d)", count)
+    self._rtcout.RTC_PARANOID("curr: %s, next: %s",
+                              (self.getStateString(comp.getStates().curr),
+                               self.getStateString(comp.getStates().next)))
+    # Now comp's next state must be ACTIVE state
+    # If worker thread is stopped, restart worker thread.
+    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+    if self._workerthread._running == False:
+      self._workerthread._running = True
+      self._workerthread._cond.acquire()
+      self._workerthread._cond.notify()
+      self._workerthread._cond.release()
+    del guard
+    return RTC.RTC_OK
+
+
+  # virtual RTC::ReturnCode_t
+  # onActivated(RTC_impl::RTObjectStateMachine* comp, long int count);
+  def onActivated(self, comp, count):
+    self._rtcout.RTC_TRACE("onActivated(count = %d)", count)
+    self._rtcout.RTC_PARANOID("curr: %s, next: %s",
+                              (self.getStateString(comp.getStates().curr),
+                               self.getStateString(comp.getStates().next)))
+    # count = -1; Asynch mode. Since onWaitingActivated is not
+    # called, onActivated() have to send restart singnal to worker
+    # thread.
+    # count > 0: Synch mode.
+
+    # Now comp's next state must be ACTIVE state
+    # If worker thread is stopped, restart worker thread.
+    guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+    if self._workerthread._running == False:
+      self._workerthread._running = True
+      self._workerthread._cond.acquire()
+      self._workerthread._cond.notify()
+      self._workerthread._cond.release()
+    del guard
+    return RTC.RTC_OK
+
+
+  # virtual RTC::ReturnCode_t
+  # onWaitingDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count);
+  def onWaitingDeactivated(self, comp, count):
+    self._rtcout.RTC_TRACE("onWaitingDeactivated(count = %d)", count)
+    self._rtcout.RTC_PARANOID("curr: %s, next: %s",
+                              (self.getStateString(comp.getStates().curr),
+                               self.getStateString(comp.getStates().next)))
+    if self.isAllNextState(RTC.INACTIVE_STATE):
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      if self._workerthread._running == True:
+        self._workerthread._running = False
+        self._rtcout.RTC_TRACE("All RTCs are INACTIVE. Stopping worker thread.")
+      del guard
+
+    return RTC.RTC_OK
+
+
+  # virtual RTC::ReturnCode_t 
+  # onDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count);
+  def onDeactivated(self, comp, count):
+    self._rtcout.RTC_TRACE("onDeactivated(count = %d)", count)
+    self._rtcout.RTC_PARANOID("curr: %s, next: %s",
+                              (self.getStateString(comp.getStates().curr),
+                               self.getStateString(comp.getStates().next)))
+    if self.isAllNextState(RTC.INACTIVE_STATE):
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      if self._workerthread._running == True:
+        self._workerthread._running = False
+        self._rtcout.RTC_TRACE("All RTCs are INACTIVE. Stopping worker thread.")
+      del guard
+
+    return RTC.RTC_OK
+
+
+  # virtual RTC::ReturnCode_t
+  # onWaitingReset(RTC_impl::RTObjectStateMachine* comp, long int count);
+  def onWaitingReset(self, comp, count):
+    self._rtcout.RTC_TRACE("onWaitingReset(count = %d)", count)
+    self._rtcout.RTC_PARANOID("curr: %s, next: %s",
+                              (self.getStateString(comp.getStates().curr),
+                               self.getStateString(comp.getStates().next)))
+    if self.isAllNextState(RTC.INACTIVE_STATE):
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      if self._workerthread._running == True:
+        self._workerthread._running = False
+        self._rtcout.RTC_TRACE("All RTCs are INACTIVE. Stopping worker thread.")
+      del guard
+
+    return RTC.RTC_OK
+
+
+  # virtual RTC::ReturnCode_t 
+  # onReset(RTC_impl::RTObjectStateMachine* comp, long int count);
+  def onReset(self, comp, count):
+    self._rtcout.RTC_TRACE("onReset(count = %d)", count)
+    self._rtcout.RTC_PARANOID("curr: %s, next: %s",
+                              (self.getStateString(comp.getStates().curr),
+                               self.getStateString(comp.getStates().next)))
+    if self.isAllNextState(RTC.INACTIVE_STATE):
+      guard = OpenRTM_aist.ScopedLock(self._workerthread._mutex)
+      if self._workerthread._running == True:
+        self._workerthread._running = False
+        self._rtcout.RTC_TRACE("All RTCs are INACTIVE. Stopping worker thread.")
+      del guard
+
+    return RTC.RTC_OK
+    return
+
+  # bool threadRunning()
+  def threadRunning(self):
+    guard = OpenRTM_aist.ScopedLock(self._svcmutex)
+    return self._svc
+
+
   ##
   # @if jp
-  # @class Worker
-  # @brief ExecutionContext 駆動クラス
+  # @class WorkerThreadCtrl
+  # @brief worker 用状態変数クラス
   #
-  # 実行処理に関する排他制御など、実際の処理を監視・制御するためのクラス。
-  #
-  # @since 0.4.0
-  #
   # @else
-  #
+  # @class WorkerThreadCtrl
+  # @brief Condition variable class for worker
   # @endif
-  class Worker:
+  class WorkerThreadCtrl:
     
     ##
     # @if jp
@@ -1082,6 +747,7 @@
 #
 # @endif
 def PeriodicExecutionContextInit(manager):
-  manager.registerECFactory("PeriodicExecutionContext",
-                            OpenRTM_aist.PeriodicExecutionContext,
-                            OpenRTM_aist.ECDelete)
+  OpenRTM_aist.ExecutionContextFactory.instance().addFactory("PeriodicExecutionContext",
+                                                             OpenRTM_aist.PeriodicExecutionContext,
+                                                             OpenRTM_aist.ECDelete)
+  return

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObject.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObject.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObject.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -487,39 +487,36 @@
   def initialize(self):
     self._rtcout.RTC_TRACE("initialize()")
 
-    ec_args = self._properties.getProperty("exec_cxt.periodic.type")
-    ec_args += "?"
-    ec_args += "rate="
-    ec_args += self._properties.getProperty("exec_cxt.periodic.rate")
+    # EC creation
+    ec_args_ = []
+    if self.getContextOptions(ec_args_) != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("Valid EC options are not available. Aborting")
+      return RTC.BAD_PARAMETER
 
-    ec = OpenRTM_aist.Manager.instance().createContext(ec_args)
-    if ec is None:
-      return RTC.RTC_ERROR
+    if self.createContexts(ec_args_) != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("EC creation failed. Maybe out of resources. Aborting.")
+      return RTC.OUT_OF_RESOURCES
 
-    ec.set_rate(float(self._properties.getProperty("exec_cxt.periodic.rate")))
-    self._eclist.append(ec)
-    ecv = ec.getObjRef()
-    if CORBA.is_nil(ecv):
-      return RTC.RTC_ERROR
 
-    ec.bindComponent(self)
+    # -- entering alive state --
+    toSTR_ = lambda x: " was" if len(x) == 1 else "s were"
+    self._rtcout.RTC_INFO("%d execution context%s created.", 
+                          (len(self._ecMine), toSTR_(self._ecMine)))
 
-    # at least one EC must be attached
-    if len(self._ecMine) == 0:
-      return RTC.PRECONDITION_NOT_MET
-
-    ret = self.on_initialize()
+    ret_ = self.on_initialize()
     self._created = False
-    if ret is not RTC.RTC_OK:
-      return ret
+    if ret_ != RTC.RTC_OK:
+      self._rtcout.RTC_ERROR("on_initialize() failed.")
+      return ret_
 
-    # -- entering alive state --
-    for i in range(len(self._ecMine)):
-      self._rtcout.RTC_DEBUG("EC[%d] starting.", i)
-      self._ecMine[i].start()
+    self._rtcout.RTC_DEBUG("on_initialize() was properly done.")
+    for (idx_, ec_) in enumerate(self._ecMine):
+      self._rtcout.RTC_DEBUG("EC[%d] starting.", idx_)
+      ec_.start()
 
     # ret must be RTC_OK
-    return ret
+    assert(ret_ == RTC.RTC_OK)
+    return ret_
 
 
   ##
@@ -1142,7 +1139,13 @@
     ret = RTC.RTC_ERROR
     try:
       self.preOnInitialize(0)
+      self._rtcout.RTC_DEBUG("Calling onInitialize().")
       ret = self.onInitialize()
+      if ret != RTC.RTC_OK:
+        self._rtcout.RTC_ERROR("onInitialize() returns an ERROR (%d)", ret._v)
+      else:
+        self._rtcout.RTC_DEBUG("onInitialize() succeeded.")
+
     except:
       self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
       ret = RTC.RTC_ERROR
@@ -1151,11 +1154,15 @@
                                               "default")
 
     if self._configsets.haveConfig(active_set):
+      self._rtcout.RTC_DEBUG("Active configuration set: %s exists.", active_set)
+      self._configsets.activateConfigurationSet(active_set)
       self._configsets.update(active_set)
-      self._configsets.activateConfigurationSet(active_set)
+      self._rtcout.RTC_INFO("Initial active configuration set is %s.", active_set)
     else:
+      self._rtcout.RTC_DEBUG("Active configuration set: %s does not exists.", active_set)
+      self._configsets.activateConfigurationSet("default")
       self._configsets.update("default")
-      self._configsets.activateConfigurationSet("default")
+      self._rtcout.RTC_INFO("Initial active configuration set is default-set.")
 
     self.postOnInitialize(0,ret)
     return ret
@@ -4679,6 +4686,203 @@
     self._actionListeners.ecaction_[OpenRTM_aist.ExecutionContextActionListenerType.EC_DETACHED].notify(ec_id)
     return
 
+
+  # ReturnCode_t getInheritedECOptions(coil::Properties& default_opts);
+  def getInheritedECOptions(self, default_opts):
+    inherited_opts_ = ["sync_transition",
+                       "sync_activation",
+                       "sync_deactivation",
+                       "sync_reset",
+                       "transition_timeout",
+                       "activation_timeout",
+                       "deactivation_timeout",
+                       "reset_timeout"]
+
+    p_ = self._properties.findNode("exec_cxt")
+    if not p_:
+      self._rtcout.RTC_WARN("No exec_cxt option found.")
+      return RTC.RTC_ERROR
+
+    self._rtcout.RTC_DEBUG("Copying inherited EC options.")
+    for opt_ in inherited_opts_:
+        if p_.findNode(opt_):
+          self._rtcout.RTC_PARANOID("Option %s exists.", opt_)
+          default_opts.setProperty(opt_, p_.getProperty(opt_))
+
+    return RTC.RTC_OK
+
+  
+  ##
+  # @brief getting individual EC options from RTC's configuration file
+  #
+  # ReturnCode_t
+  # getPrivateContextOptions(std::vector<coil::Properties>& ec_args);
+  def getPrivateContextOptions(self, ec_args):
+    self._rtcout.RTC_TRACE("getPrivateContextOptions()")
+    # Component specific multiple EC option available
+    if not self._properties.findNode("execution_contexts"):
+      self._rtcout.RTC_DEBUG("No component specific EC specified.")
+      return RTC.RTC_ERROR
+
+    args_ = self._properties.getProperty("execution_contexts")
+    ecs_tmp_ = [s.strip() for s in args_.split(",")]
+    if not ecs_tmp_:
+      return RTC.RTC_ERROR
+    self._rtcout.RTC_DEBUG("Component specific e EC option available,")
+    self._rtcout.RTC_DEBUG("%s", args_)
+
+    default_opts_ = OpenRTM_aist.Properties()
+    self.getInheritedECOptions(default_opts_)
+    for ec_tmp in ecs_tmp_:
+      if OpenRTM_aist.normalize([ec_tmp]) == "none":
+        self._rtcout.RTC_INFO("EC none. EC will not be bound to the RTC.")
+        ec_args = []
+        return RTC.RTC_OK
+
+      type_and_name_ = [s.strip() for s in ec_tmp.split("(")]
+      if len(type_and_name) > 2:
+        self._rtcout.RTC_DEBUG("Invalid EC type specified: %s", ec_tmp)
+        continue
+
+      p_ = default_opts;
+
+      # create EC's properties
+      p_.setProperty("type",type_and_name_[0])
+      self._rtcout.RTC_DEBUG("p_type: %s", p_.getProperty("type"))
+      p_type_ = self._properties.findNode("ec." + p.getProperty("type"))
+      if p_type_:
+        self._rtcout.RTC_DEBUG("p_type props:")
+        self._rtcout.RTC_DEBUG(p_type_)
+        p_.mergeProperties(p_type_)
+
+      else:
+        self._rtcout.RTC_DEBUG("p_type none")
+
+      # EC name specified
+      self._rtcout.RTC_DEBUG("size: %d, name: %s",
+                             (len(type_and_name_), type_and_name_[1]))
+
+      if len(type_and_name_) == 2 and type_and_name_[1][len(type_and_name_[1]) - 1] == ')':
+        del type_and_name_[1][len(type_and_name_[1]) - 1]
+        p_.setProperty("name", type_and_name_[1])
+        p_name_ = self._properties.findNode("ec." + p.getProperty("name"))
+        if p_name_:
+          self._rtcout.RTC_DEBUG("p_name props:")
+          self._rtcout.RTC_DEBUG(p_name_)
+          p_.mergeProperties(p_name_)
+
+        else:
+          self._rtcout.RTC_DEBUG("p_name none")
+
+      ec_args.append(p_)
+      self._rtcout.RTC_DEBUG("New EC properties stored:")
+      self._rtcout.RTC_DEBUG(p_)
+
+    return RTC.RTC_OK
+
+
+  ##
+  # @brief getting global EC options from rtc.conf
+  #
+  # ReturnCode_t
+  # getGlobalContextOptions(coil::Properties& global_ec_props);
+  def getGlobalContextOptions(self, global_ec_props):
+    # exec_cxt option is obsolete
+    self._rtcout.RTC_TRACE("getGlobalContextOptions()")
+
+    prop_ = self._properties.findNode("exec_cxt.periodic")
+    if not prop_:
+      self._rtcout.RTC_WARN("No global EC options found.")
+      return RTC.RTC_ERROR
+
+    self._rtcout.RTC_DEBUG("Global EC options are specified.")
+    self._rtcout.RTC_DEBUG(prop_)
+    self.getInheritedECOptions(global_ec_props)
+    global_ec_props.mergeProperties(prop_)
+    return RTC.RTC_OK
+
+
+  ##
+  # @brief getting EC options
+  #
+  # ReturnCode_t
+  # getContextOptions(std::vector<coil::Properties>& ec_args);
+  def getContextOptions(self, ec_args):
+    self._rtcout.RTC_DEBUG("getContextOptions()")
+    global_props_ = OpenRTM_aist.Properties()
+    ret_global_  = self.getGlobalContextOptions(global_props_)
+    ret_private_ = self.getPrivateContextOptions(ec_args)
+
+    # private(X), global(X) -> error
+    # private(O), global(O) -> private
+    # private(X), global(O) -> global
+    # private(O), global(X) -> private
+    if ret_global_ != RTC.RTC_OK and ret_private_ != RTC.RTC_OK:
+      return RTC.RTC_ERROR
+
+    if ret_global_ == RTC.RTC_OK and ret_private_ != RTC.RTC_OK:
+      ec_args.append(global_props_)
+
+    return RTC.RTC_OK
+
+
+  ##
+  # @brief fiding existing EC from the factory
+  #
+  # ReturnCode_t findExistingEC(coil::Properties& ec_arg,
+  #                             RTC::ExecutionContextBase*& ec);
+  def findExistingEC(self, ec_arg, ec):
+    eclist_ = OpenRTM_aist.ExecutionContextFactory.instance().createdObjects()
+    for ec_ in eclist_:
+      if ec_.getProperties().getProperty("type") == ec_arg.getProperty("type") and \
+            ec_.getProperties().getProperty("name") == ec_arg.getProperty("name"):
+        ec[0] = ec_
+        return RTC.RTC_OK
+
+    return RTC.RTC_ERROR
+
+
+  ##
+  # @brief creating, initializing and binding context
+  #
+  # ReturnCode_t createContexts(std::vector<coil::Properties>& ec_args);
+  def createContexts(self, ec_args):
+    ret_ = RTC.RTC_OK
+    avail_ec_ = OpenRTM_aist.ExecutionContextFactory.instance().getIdentifiers()
+
+    for ec_arg_ in ec_args:
+      ec_type_ = ec_arg_.getProperty("type")
+      ec_name_ = ec_arg_.getProperty("name")
+      ec_ = [None]
+      if ec_name_ and self.findExistingEC(ec_arg_, ec_) == RTC.RTC_OK:
+        # if EC's name exists, find existing EC in the factory.
+        self._rtcout.RTC_DEBUG("EC: type=%s, name=%s already exists.",
+                               (ec_type_, ec_name_))
+      else:
+        # If EC's name is empty or no existing EC, create new EC.
+        if not ec_type_ in avail_ec_:
+          self._rtcout.RTC_WARN("EC %s is not available.", ec_type_)
+          self._rtcout.RTC_DEBUG("Available ECs: %s",
+                                 OpenRTM_aist.flatten(avail_ec_))
+          continue
+        ec_[0] = OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_type_)
+
+      if not ec_[0]:
+        # EC factory available but creation failed. Resource full?
+        self._rtcout.RTC_ERROR("EC (%s) creation failed.", ec_type_)
+        self._rtcout.RTC_DEBUG("Available EC list: %s",
+                               OpenRTM_aist.flatten(avail_ec_))
+        ret_ = RTC.RTC_ERROR
+        continue
+
+      self._rtcout.RTC_DEBUG("EC (%s) created.", ec_type_)
+      
+      ec_[0].init(ec_arg_)
+      self._eclist.append(ec_[0])
+      ec_[0].bindComponent(self)
+
+    return ret_
+
     
   ##
   # @if jp
@@ -4775,3 +4979,39 @@
 
 
 # RtcBase = RTObject_impl
+"""
+    ec_args = self._properties.getProperty("exec_cxt.periodic.type")
+    ec_args += "?"
+    ec_args += "rate="
+    ec_args += self._properties.getProperty("exec_cxt.periodic.rate")
+
+    ec = OpenRTM_aist.Manager.instance().createContext(ec_args)
+    if ec is None:
+      return RTC.RTC_ERROR
+
+    ec.set_rate(float(self._properties.getProperty("exec_cxt.periodic.rate")))
+    self._eclist.append(ec)
+    ecv = ec.getObjRef()
+    if CORBA.is_nil(ecv):
+      return RTC.RTC_ERROR
+
+    ec.bindComponent(self)
+
+    # at least one EC must be attached
+    if len(self._ecMine) == 0:
+      return RTC.PRECONDITION_NOT_MET
+
+    ret = self.on_initialize()
+    self._created = False
+    if ret is not RTC.RTC_OK:
+      return ret
+
+    # -- entering alive state --
+    for i in range(len(self._ecMine)):
+      self._rtcout.RTC_DEBUG("EC[%d] starting.", i)
+      self._ecMine[i].start()
+
+    # ret must be RTC_OK
+    return ret
+"""
+

Copied: trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObjectStateMachine.py (from rev 542, branches/work/OpenRTM-aist-Python/OpenRTM_aist/RTObjectStateMachine.py)
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObjectStateMachine.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObjectStateMachine.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -0,0 +1,272 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file RTObjectStateMachine.py
+# @brief ExecutionContext's state machine worker class
+# @date $Date$
+# @author Noriaki Ando <n-ando at aist.go.jp> and Shinji Kurihara
+#
+# Copyright (C) 2011
+#     Noriaki Ando
+#     Intelligent Systems Research Institute,
+#     National Institute of
+#         Advanced Industrial Science and Technology (AIST), Japan
+#     All rights reserved.
+#
+# $Id$
+#
+
+from omniORB import CORBA, PortableServer
+
+import OpenRTM_aist
+import RTC
+
+NUM_OF_LIFECYCLESTATE = 4
+
+class RTObjectStateMachine:
+  """
+  """
+
+  # RTObjectStateMachine(RTC::ExecutionContextHandle_t id,
+  #                      RTC::LightweightRTObject_ptr comp);
+  def __init__(self, id, comp):
+    global NUM_OF_LIFECYCLESTATE
+    self._id = id
+    self._rtobj = comp
+    self._sm = OpenRTM_aist.StateMachine(NUM_OF_LIFECYCLESTATE)
+    self._ca   = False
+    self._dfc  = False
+    self._fsm  = False
+    self._mode = False
+    self._caVar   = None
+    self._dfcVar  = None
+    self._fsmVar  = None
+    self._modeVar = None
+
+    # Setting Action callback objects
+    self.setComponentAction(comp)
+    self.setDataFlowComponentAction(comp)
+    self.setFsmParticipantAction(comp)
+    self.setMultiModeComponentAction(comp)
+    # Setting callback functions to StateMachine
+    self._sm.setListener(self)
+    self._sm.setEntryAction (RTC.ACTIVE_STATE,
+                             self.onActivated)
+    self._sm.setDoAction    (RTC.ACTIVE_STATE,
+                             self.onExecute)
+    self._sm.setPostDoAction(RTC.ACTIVE_STATE,
+                             self.onStateUpdate)
+    self._sm.setExitAction  (RTC.ACTIVE_STATE,
+                             self.onDeactivated)
+    self._sm.setEntryAction (RTC.ERROR_STATE,
+                             self.onAborting)
+    self._sm.setDoAction    (RTC.ERROR_STATE,
+                             self.onError)
+    self._sm.setExitAction  (RTC.ERROR_STATE,
+                             self.onReset)
+    # Setting inital state
+    st = OpenRTM_aist.StateHolder()
+    st.prev = RTC.INACTIVE_STATE
+    st.curr = RTC.INACTIVE_STATE
+    st.next = RTC.INACTIVE_STATE
+    self._sm.setStartState(st)
+    self._sm.goTo(RTC.INACTIVE_STATE)
+    return
+
+
+  def __del__(self):
+    if self._ca:
+      self._ca = False
+      self._caVar = None
+
+    if self._dfc:
+      self._dfc = False
+      self._dfcVar = None
+
+    if self._fsm:
+      self._fsm = False
+      self._fsmVar = None
+
+    if self._mode:
+      self._mode = False
+      self._modeVar = None
+
+    return
+
+
+  # functions for stored RTObject reference
+  # RTC::LightweightRTObject_ptr getRTObject();
+  def getRTObject(self):
+    return self._rtobj
+
+  # bool isEquivalent(RTC::LightweightRTObject_ptr comp);
+  def isEquivalent(self, comp):
+    return self._rtobj._is_equivalent(comp)
+
+  # RTC::ExecutionContextHandle_t getExecutionContextHandle();
+  def getExecutionContextHandle(self):
+    return self._id
+
+  # RTC::ComponentAction operations
+  # void onStartup(void);
+  def onStartup(self):
+    if not self._ca:
+      return
+    self._caVar.on_startup(self._id)
+    return
+
+  # void onShutdown(void);
+  def onShutdown(self):
+    if not self._ca:
+      return
+    self._caVar.on_shutdown(self._id)
+    return
+
+  # void onActivated(const ExecContextStates& st);
+  def onActivated(self, st):
+    if not self._ca:
+      return
+    if self._caVar.on_activated(self._id) != RTC.RTC_OK:
+      self._sm.goTo(RTC.ERROR_STATE)
+    return
+
+  # void onDeactivated(const ExecContextStates& st);
+  def onDeactivated(self, st):
+    if not self._ca:
+      return
+    self._caVar.on_deactivated(self._id)
+    return
+
+  # void onAborting(const ExecContextStates& st);
+  def onAborting(self, st):
+    if not self._ca:
+      return
+    self._caVar.on_error(self._id)
+    return
+
+  # void onError(const ExecContextStates& st);
+  def onError(self, st):
+    if not self._ca:
+      return
+    self._caVar.on_error(self._id)
+    return
+
+  # void onReset(const ExecContextStates& st);
+  def onReset(self, st):
+    if not self._ca:
+      return
+    if self._caVar.on_reset(self._id) != RTC.RTC_OK:
+      self._sm.goTo(RTC.ERROR_STATE)
+    return
+
+  # RTC::DataflowComponentAction
+  # void onExecute(const ExecContextStates& st);
+  def onExecute(self, st):
+    if not self._dfc:
+      return
+    
+    if self._dfcVar.on_execute(self._id) != RTC.RTC_OK:
+      self._sm.goTo(RTC.ERROR_STATE)
+    return
+
+  # void onStateUpdate(const ExecContextStates& st);
+  def onStateUpdate(self, st):
+    if not self._dfc:
+      return
+    
+    if self._dfcVar.on_state_update(self._id) != RTC.RTC_OK:
+      self._sm.goTo(RTC.ERROR_STATE)
+    return
+
+  # void onRateChanged(void);
+  def onRateChanged(self):
+    if not self._dfc:
+      return
+    
+    if self._dfcVar.on_rate_changed(self._id) != RTC.RTC_OK:
+      self._sm.goTo(RTC.ERROR_STATE)
+    return
+
+  # FsmParticipantAction
+  # void onAction(const ExecContextStates& st);
+  def onAction(self, st):
+    if not self._fsm:
+      return
+
+    if self._fsmVar.on_action(self._id) != RTC.RTC_OK:
+      self._sm.goTo(RTC.ERROR_STATE)
+    return
+  
+  # MultiModeComponentAction
+  # void onModeChanged(const ExecContextStates& st);
+  def onModeChanged(self, st):
+    if not self._mode:
+      return
+
+    if self._modeVar.on_mode_changed(self._id) != RTC.RTC_OK:
+      self._sm.goTo(RTC.ERROR_STATE)
+    return
+  
+  # Getting state of the context
+  # ExecContextState getState(void);
+  def getState(self):
+    return self._sm.getState()
+
+  # ExecContextStates getStates(void);
+  def getStates(self):
+    return self._sm.getStates()
+
+  # bool isCurrentState(ExecContextState state);
+  def isCurrentState(self, state):
+    return self.getState() == state
+
+  # bool isNextState(ExecContextState state);
+  def isNextState(self, state):
+    return self._sm.getStates().next == state
+
+  # void goTo(ExecContextState state);
+  def goTo(self, state):
+    self._sm.goTo(state)
+    return
+    
+  # Workers
+  # void workerPreDo(void);
+  def workerPreDo(self):
+    return self._sm.worker_pre()
+
+  # void workerDo(void);
+  def workerDo(self):
+    return self._sm.worker_do()
+
+  # void workerPostDo(void);
+  def workerPostDo(self):
+    return self._sm.worker_post()
+
+  # void setComponentAction(const RTC::LightweightRTObject_ptr comp);
+  def setComponentAction(self, comp):
+    self._caVar = comp._narrow(RTC.ComponentAction)
+    if not CORBA.is_nil(self._caVar):
+      self._ca = True
+    return
+
+  # void setDataFlowComponentAction(const RTC::LightweightRTObject_ptr comp);
+  def setDataFlowComponentAction(self, comp):
+    self._dfcVar = comp._narrow(RTC.DataFlowComponentAction)
+    if not CORBA.is_nil(self._dfcVar):
+      self._dfc = True
+    return
+
+  # void setFsmParticipantAction(const RTC::LightweightRTObject_ptr comp);
+  def setFsmParticipantAction(self, comp):
+    self._fsmVar = comp._narrow(RTC.FsmParticipantAction)
+    if not CORBA.is_nil(self._fsmVar):
+      self._fsm = True
+    return
+
+  # void setMultiModeComponentAction(const RTC::LightweightRTObject_ptr comp);
+  def setMultiModeComponentAction(self, comp):
+    self._modeVar = comp._narrow(RTC.MultiModeComponentAction)
+    if not CORBA.is_nil(self._modeVar):
+      self._mode = True
+    return

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/StateMachine.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/StateMachine.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/StateMachine.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -154,6 +154,7 @@
   # @endif
   def __init__(self, num_of_state):
     self._num = num_of_state
+    self._listener = None
     self._entry  = {}
     self._predo  = {}
     self._do     = {}
@@ -166,6 +167,7 @@
     self.setNullFunc(self._predo,  None)
     self.setNullFunc(self._postdo, None)
     self._transit = None
+    self._selftrans = False
     self._mutex = threading.RLock()
 
 
@@ -203,7 +205,9 @@
   # @brief Set Listener Object
   # @endif
   def setListener(self, listener):
+    assert(listener)
     self._listener = listener
+    return
 
 
   ##
@@ -225,7 +229,7 @@
     if self._entry.has_key(state):
       self._entry[state] = call_back
     else:
-      self._entry.setdefault(state, call_back)
+      return False
     return True
 
 
@@ -248,7 +252,7 @@
     if self._predo.has_key(state):
       self._predo[state] = call_back
     else:
-      self._predo.setdefault(state, call_back)
+      return False
     return True
 
 
@@ -271,7 +275,7 @@
     if self._do.has_key(state):
       self._do[state] = call_back
     else:
-      self._do.setdefault(state, call_back)
+      return False
     return True
 
 
@@ -294,7 +298,7 @@
     if self._postdo.has_key(state):
       self._postdo[state] = call_back
     else:
-      self._postdo.setdefault(state, call_back)
+      return False
     return True
 
 
@@ -317,7 +321,7 @@
     if self._exit.has_key(state):
       self._exit[state] = call_back
     else:
-      self._exit.setdefault(state, call_back)
+      return False
     return True
 
 
@@ -438,6 +442,9 @@
   def goTo(self, state):
     guard = OpenRTM_aist.ScopedLock(self._mutex)
     self._states.next = state
+    if self._states.curr == state:
+      self._selftrans = True
+    return
 
 
   ##
@@ -461,22 +468,26 @@
       # pre-do
       if self._predo[states.curr]:
         self._predo[states.curr](states)
+
       if self.need_trans():
         return
 
       # do
       if self._do[states.curr]:
         self._do[states.curr](states)
+
       if self.need_trans():
         return
 
       # post-do
       if self._postdo[states.curr]:
         self._postdo[states.curr](states)
+
     # If state transition required, exit current state and enter next state
     else:
       if self._exit[states.curr]:
         self._exit[states.curr](states)
+
       self.sync(states)
 
       # If state transition still required, move to the next state
@@ -486,7 +497,52 @@
           self._entry[states.curr](states)
         self.update_curr(states.curr)
 
+    return
 
+
+  # void worker_pre()
+  def worker_pre(self):
+    state = StateHolder()
+    self.sync(state)
+    if state.curr == state.next:
+      if self._predo[state.curr]:
+        self._predo[state.curr](state)
+      return
+
+    # State changed
+    if self._exit[state.curr]:
+      self._exit[state.curr](state)
+
+    self.sync(state)
+    if state.curr != state.next:
+      state.curr = state.next
+      if self._entry[state.curr]:
+        self._entry[state.curr](state)
+      self.update_curr(state.curr)
+
+    return
+
+  # void worker_do()
+  def worker_do(self):
+    state = StateHolder()
+    self.sync(state)
+
+    if self._do[state.curr]:
+      self._do[state.curr](state)
+
+    return
+
+
+  # void worker_post()
+  def worker_post(self):
+    state = StateHolder()
+    self.sync(state)
+    if self._postdo[state.curr]:
+      self._postdo[state.curr](state)
+
+    return
+
+
   ##
   # @if jp
   # @brief NOP関数を設定
@@ -506,6 +562,7 @@
         s[StateMachine.state_array[i]] = nullfunc
       else:
         s.setdefault(StateMachine.state_array[i], nullfunc)
+    return
 
 
   ##


Property changes on: trunk/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/RELENG_1_0/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py:345-395
/branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py:396-478,488-497
/branches/work/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py:505-509
   + /branches/RELENG_1_0/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py:345-395
/branches/RELENG_1_1/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py:396-478,488-497
/branches/work/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py:504-542

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/TimeMeasure.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/TimeMeasure.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/TimeMeasure.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -19,6 +19,7 @@
 #
 #
 
+import sys, os
 import time
 import math
 
@@ -124,6 +125,54 @@
     return OpenRTM_aist.TimeValue(self.sec, self.usec)
 
 
+  # inline int settimeofday(const struct timeval *tv , const struct timezone *tz)
+  def settimeofday(self, tv, tz):
+    if sys.platform == "win32":
+      from ctypes import windll, Structure, c_ushort, byref, c_ulong, c_long
+      class SYSTEMTIME(Structure):
+        _fields_ = [('wYear', c_ushort), 
+                    ('wMonth', c_ushort), 
+                    ('wDayOfWeek', c_ushort), 
+                    ('wDay', c_ushort), 
+                    ('wHour', c_ushort), 
+                    ('wMinute', c_ushort), 
+                    ('wSecond', c_ushort), 
+                    ('wMilliseconds', c_ushort)]
+
+
+      class LARGE_INTEGER(Structure):
+        _fields_ = [('low', c_ulong), 
+                    ('high', c_long)]
+
+
+      tm = long(tv.tv_sec*1e6) + long(tv.tv_usec)
+      st = SYSTEMTIME(0,0,0,0,0,0,0,0)
+      ft = LARGE_INTEGER(tm&0xFFFFFFFFL,tm>>32)
+      # 100 nanosecond units (since 16010101)
+      ret = windll.kernel32.FileTimeToSystemTime(byref(ft),
+                                                 byref(st))
+      if not ret:
+        return -1
+
+      #windll.kernel32.SetSystemTime(byref(st))
+      print "settime Yer:", st.wYear, " Month:", st.wMonth, \
+          " DayOfWeek:", st.wDayOfWeek, " wDay:", st.wDay,  \
+          " Hour:", st.wHour, "Minute:", st.wMinute, \
+          " Second:", st.wSecond, "Milliseconds:", st.wMilliseconds
+      
+
+    else:
+      import ctypes
+      class timespec(ctypes.Structure):
+        _fields_ = [('tv_sec', ctypes.c_long),
+                    ('tv_nsec', ctypes.c_long)]
+
+      librt = ctypes.cdll.LoadLibrary('librt.so')
+      ts = timespec(long(tv.tv_sec),long(tv.tv_usec*1000))
+      #return librt.clock_settime(0, ctypes.pointer(ts))
+
+    return 0
+
 ##
 # TimeMeasure object
 #

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -20,6 +20,7 @@
 from SystemLogger import *
 from TimeValue import *
 from TimeMeasure import *
+from ClockManager import *
 from Singleton import *
 from Factory import *
 from GlobalFactory import *
@@ -48,6 +49,9 @@
 from Timer import *
 from ModuleManager import *
 from NamingManager import *
+from ExecutionContextProfile import *
+from RTObjectStateMachine import *
+from ExecutionContextWorker import *
 from ExecutionContextBase import *
 from StateMachine import *
 from PeriodicExecutionContext import *

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/examples/component.conf
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/examples/component.conf	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/examples/component.conf	2013-04-26 14:52:58 UTC (rev 558)
@@ -15,12 +15,128 @@
 
 #============================================================
 # execution context options
+#============================================================
 #
+# Periodic type ExecutionContext
+#
+# Other availabilities in OpenRTM-aist
+#
+# - ExtTrigExecutionContext: External triggered EC. It is embedded in
+#                            OpenRTM library.
+# - OpenHRPExecutionContext: External triggred paralell execution
+#                            EC. It is embedded in OpenRTM
+#                            library. This is usually used with
+#                            OpenHRP3.
+# - RTPreemptEC:             Real-time execution context for Linux
+#                            RT-preemptive pathed kernel.
+# - ArtExecutionContext:     Real-time execution context for ARTLinux
+#                            (http://sourceforge.net/projects/art-linux/)
 # exec_cxt.periodic.type: [specify periodic type EC]
+
+#
+# The execution cycle of ExecutionContext
+#
 # exec_cxt.periodic.rate: [Hz]
+
+#
+# Event driven execution context (not implemented yet)
+#
 # exec_cxt.event_driven.type: [specify event driven type EC]
 #
 
+#
+# State transition mode settings YES/NO
+#
+# Default: YES (efault setting is recommended.)
+#
+# Activating, deactivating and resetting of RTC performs state
+# transition. Some execution contexts might execute main logic in
+# different thread. If these flags are set to YES, activation,
+# deactivation and resetting will be performed synchronously. In other
+# words, if these flags are YES,
+# activation/deactivation/resetting-operations must be returned after
+# state transition completed.
+#
+# "sync_transition" will set synchronous transition flags to all other
+# synchronous transition flags sync_activation/deactivation/reset.
+#
+# exec_cxt.sync_transition: YES
+# exec_cxt.sync_activation: YES
+# exec_cxt.sync_deactivation: YES
+# exec_cxt.sync_reset: YES
+
+#
+# Timeout of synchronous state transition [s]
+#
+# Default: 0.5 [s]
+#
+# When synchronous transition flags are set to YES, the following
+# timeout settings are valid. If "transition_timeout" is set, the
+# value will be set to all other timeout of activation/deactivation
+# and resetting
+#
+# exec_cxt.transition_timeout: 0.5
+# exec_cxt.activation_timeout: 0.5
+# exec_cxt.deactivation_timeout: 0.5
+# exec_cxt.reset_timeout: 0.5
+
+#
+# Specifying Execution Contexts
+#
+# Default: No default
+#
+# execution_contexts: None or <EC0>,<EC1>,...
+# <EC?>: ECtype(ECname)
+#
+# RTC can be attached with zero or more Execution
+# Contexts. "execution_contexts" option specifies RTC-specific
+# attached ECs and its name. If the option is not specified, the
+# internal global options or rtc.conf options related to EC will be
+# used. If None is specified, no EC will be created.
+#
+# Availabilities in OpenRTM-aist
+#
+# - ExtTrigExecutionContext: External triggered EC. It is embedded in
+#                            OpenRTM library.
+# - OpenHRPExecutionContext: External triggred paralell execution
+#                            EC. It is embedded in OpenRTM
+#                            library. This is usually used with
+#                            OpenHRP3.
+# - RTPreemptEC:             Real-time execution context for Linux
+#                            RT-preemptive pathed kernel.
+# - ArtExecutionContext:     Real-time execution context for ARTLinux
+#                            (http://sourceforge.net/projects/art-linux/)
+#
+# execution_contexts: PeriodicExecutionContext(pec1000Hz), \
+#                     PeriodicExecutionContext(pec500Hz)
+
+#
+# EC specific configurations
+#
+# Default: No default
+#
+# Each EC can have its own configuration. Individual configuration can
+# be specified by using EC type name or EC instance name. Attached ECs
+# would be specified in execution_context option like <EC type
+# name>(<EC instance name>), ...  EC specific option can be specified
+# as follows.
+#
+# ec.<EC type name>.<option>
+# ec.<EC instance name>.<option>
+#
+# Example:
+# ec.PeriodicExecutionContext.sync_transition: NO
+# ec.pec1000Hz.rate: 1000
+# ec.pec1000Hz.synch_transition: YES
+# ec.pec1000Hz.transition_timeout: 0.5
+# ec.pec500Hz.rate: 500
+# ec.pec500Hz.synch_activation: YES
+# ec.pec500Hz.synch_deactivation: NO
+# ec.pec500Hz.synch_reset: YES
+# ec.pec500Hz.activation_timeout: 0.5
+# ec.pec500Hz.reset_timeout: 0.5
+
+
 #============================================================
 # port configurations
 #
@@ -72,10 +188,10 @@
 # configuration parameters
 #
 # conf.[configuration_set_name].[parameter_name]:
-# conf.constraint.[parameter_name]:
+# conf.__widget__.[parameter_name]: GUI control type for RTSystemEditor
+# conf.__constraint__.[parameter_name]: Constraints for the value
 #
 #
-#
 
 #------------------------------------------------------------
 # configuration sets
@@ -83,12 +199,49 @@
 # conf.[configuration_set_name].[parameter_name]:
 
 #------------------------------------------------------------
-# constraint condition of configuration parameter 
+# GUI control option for RTSystemEditor
+#------------------------------------------------------------
 #
-# substitute variable name: "x"
+# Available GUI control options [__widget__]:
 #
-# available constraint formats
+# conf.__widget__.[widget_name]:
 #
+# available wdget name:
+# - text:          text box [default].
+# - slider.<step>: Horizontal slider. <step> is step for the slider.
+#                  A range constraints option is required. 
+# - spin:          Spin button. A range constraitns option is required.
+# - radio:         Radio button. An enumeration constraints is required.
+# - checkbox:      Checkbox control. An enumeration constraints is
+#                  required. The parameter has to be able to accept a
+#                  comma separated list.
+# - orderd_list:   Orderd list control.  An enumeration constraint is
+#                  required. The parameter has to be able to accept a
+#                  comma separated list. In this control, Enumerated
+#                  elements can appear one or more times in the given list.
+# examples:
+# conf.__widget__.int_param0: slider.10
+# conf.__widget__.int_param1: spin
+# conf.__widget__.double_param0: slider.10
+# conf.__widget__.double_param1: text
+# conf.__widget__.str_param0: radio
+# conf.__widget__.vector_param0: checkbox
+# conf.__widget__.vector_param1: orderd_list
+
+#
+# Available GUI control constraint options [__constraints__]:
+#
+# conf.__constraints__.[parameter_name]:
+#
+# available constraints:
+# - none:         blank
+# - direct value: 100 (constant value)
+# - range:        <, >, <=, >= can be used.
+# - enumeration:  (enum0, enum1, ...)
+# - array:        <constraints0>, ,constraints1>, ... for only array value
+# - hash:         {key0: value0, key1:, value0, ...}
+#
+# available constraint formats (substitute variable name: "x"):
 # - No constraint              : (blank)
 # - Direct                     : 100 (read only)
 # - 100 or over                : x >= 100
@@ -101,4 +254,12 @@
 # - Array                      : x < 1, x < 10, x > 100
 # - Hash                       : {key0: 100<x<200, key1: x>=100}
 #
-# conf.constraint.[parameter_name]:
+# examples:
+# conf.__constraints__.int_param0: 0<=x<=150
+# conf.__constraints__.int_param1: 0<=x<=1000
+# conf.__constraints__.double_param0: 0<=x<=100
+# conf.__constraints__.double_param1:
+# conf.__constraints__.str_param0: (default,mode0,mode1)
+# conf.__constraints__.vector_param0: (dog,monky,pheasant,cat)
+# conf.__constraints__.vector_param1: (pita,gora,switch)
+

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/examples/rtc.conf.sample
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/examples/rtc.conf.sample	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/examples/rtc.conf.sample	2013-04-26 14:52:58 UTC (rev 558)
@@ -9,7 +9,7 @@
 #          Advanced Industrial Science and Technology (AIST), Japan
 #      All rights reserved.
 #
-# $Id: rtc.conf.sample 1900 2010-02-27 14:28:48Z n-ando $
+# $Id: rtc.conf.sample 2312 2012-02-07 02:55:32Z n-ando $
 # 
 #----------------------------------------------------------------------
 
@@ -45,6 +45,7 @@
 #   process will be shutdown in case no rtc exists on periodic check.
 manager.shutdown_on_nortcs: YES
 manager.shutdown_auto: YES
+manager.auto_shutdown_duration: 10.0
 
 #============================================================
 # CORBA configuration
@@ -117,6 +118,35 @@
 #
 corba.nameservice.replace_endpoint: NO
 
+#
+# IOR alternate IIOP addresses
+#
+# This option adds alternate IIOP addresses into the IOR Profiles.
+# IOR can include additional endpoints for a servant. It is almost
+# same as "corba.endpoints" option, but this option does not create
+# actual endpoint on the ORB. (corba.endpoints try to create actual
+# endpoint, and if it cannot be created, error will be returned.)
+# This option just add alternate IIOP endpoint address information to
+# an IOR.
+#
+# This option can be used when RTCs are located inside of NAT or
+# router.  Generally speaking, RTCs in a private network cannot
+# connect to RTCs in the global network, because global client cannot
+# reach to private servants. However, if route (or NAT) is properly
+# configured for port forwarding, global RTCs can reach to RTCs in
+# private network.
+#
+# A setting example is as follows.
+# 1) Configure your router properly for port-forwarding.
+#    ex. global 2810 port is forwarded to private 2810
+# 2) Set the following options in rtc.conf
+#  corba.nameservers: my.global.nameserver.com <- name server in global network
+#  corba.endpoints: :2810 <- actual port number
+#  corba.additional_ior_addresses: w.x.y.z:2810 <- routers global IP addr/port
+# 3) Launch global RTCs and private RTC, and connect them.
+#
+corba.alternate_iiop_addresses: addr:port
+
 #============================================================
 # Naming configurations
 #============================================================
@@ -273,6 +303,8 @@
 #    from 0-11. 
 # %M minute as a number (0-59) 
 # %p locale's equivalent of AM or PM 
+# %Q millisecond as a number (0-999) from ver 1.1
+# %q microsecond as a number (0-999) from ver 1.1
 # %S second as a number (0-59) 
 # %U week of the year, sunday as the first day 
 # %w weekday as a decimal (0-6, sunday=0) 
@@ -318,6 +350,22 @@
 #
 logger.log_level: NORMAL
 
+#
+# Logger's clock time
+#
+# logger.clock_type option specifies a type of clock to be used for
+# timestamp of log message. Now these three types are available.
+#
+# - system: system clock [default]
+# - logical: logical clock
+# - adjusted: adjusted clock
+#
+# To use logical time clock, call and set time by the following
+# function in somewhere.
+# coil::ClockManager::instance().getClock("logical").settime()
+#
+logger.clock_type: system
+
 #============================================================
 # Timer configuration
 #============================================================
@@ -337,9 +385,76 @@
 #
 # Periodic type ExecutionContext
 #
+# Other availabilities in OpenRTM-aist
+#
+# - ExtTrigExecutionContext: External triggered EC. It is embedded in
+#                            OpenRTM library.
+# - OpenHRPExecutionContext: External triggred paralell execution
+#                            EC. It is embedded in OpenRTM
+#                            library. This is usually used with
+#                            OpenHRP3.
+# - RTPreemptEC:             Real-time execution context for Linux
+#                            RT-preemptive pathed kernel.
+# - ArtExecutionContext:     Real-time execution context for ARTLinux
+#                            (http://sourceforge.net/projects/art-linux/)
+#
 exec_cxt.periodic.type: PeriodicExecutionContext
+# exec_cxt.event_driven_type: to be implemented
 
 #
 # The execution cycle of ExecutionContext
 #
 exec_cxt.periodic.rate: 1000
+
+#
+# State transition mode settings YES/NO
+#
+# Default: YES (efault setting is recommended.)
+#
+# Activating, deactivating and resetting of RTC makes state
+# transition.  Some execution contexts execute main logic in different
+# thread.  If these flags set to YES, activation, deactivation and
+# resetting will be performed synchronously.  In other words, if these
+# flags are YES, activation/deactivation/resetting-operations must be
+# returned after state transition completed.
+#
+# "synchronous_transition" will set synchronous transition flags to
+# all other synchronous transition flags
+# (synchronous_activation/deactivation/resetting.
+#
+exec_cxt.sync_transition: YES
+exec_cxt.sync_activation: YES
+exec_cxt.sync_deactivation: YES
+exec_cxt.sync_reset: YES
+
+#
+# Timeout of synchronous state transition [s]
+#
+# Default: 1.0 [s]
+#
+# When synchronous transition flags are set to YES, the following
+# timeout settings are valid. If "transition_timeout" is set, the
+# value will be set to all other timeout of activation/deactivation
+# and resetting
+#
+exec_cxt.transition_timeout: 0.5
+exec_cxt.activation_timeout: 0.5
+exec_cxt.deactivation_timeout: 0.5
+exec_cxt.reset_timeout: 0.5
+
+
+
+#============================================================
+# SDO service settings
+#============================================================
+#
+# SDO service provider settings
+#
+sdo.service.provider.available_services: [read only]
+sdo.service.provider.enabled_services: ALL
+sdo.service.provider.providing_services: [read only]
+#
+# SDO service consumer settings
+#
+sdo.service.consumer.available_services: [read only]
+sdo.service.consumer.enabled_services: ALL

Copied: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ClockManager.py (from rev 542, branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_ClockManager.py)
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ClockManager.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ClockManager.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file test_ClockManager.py
+# @brief test for ClockManager class
+# @date $Date$
+# @author Noriaki Ando <n-ando at aist.go.jp>
+#
+# Copyright (C) 2012
+#     Noriaki Ando
+#     Intelligent Systems Research Institute,
+#     National Institute of
+#         Advanced Industrial Science and Technology (AIST), Japan
+#     All rights reserved.
+#
+# $Id$
+#
+
+import time
+import sys
+import math
+sys.path.insert(1,"../")
+
+import unittest
+from ClockManager import *
+
+
+
+class TestClockManager(unittest.TestCase):
+  def setUp(self):
+    self._cm = ClockManager.instance()
+    return
+  
+  def test_LogicalClock(self):
+    tm = self._cm.getClock("logical").gettime()
+    self.assertEqual(0.0,tm.tv_sec)
+    self.assertEqual(0.0,tm.tv_usec)
+    stm = OpenRTM_aist.TimeValue(1,1)
+    tm = self._cm.getClock("logical").settime(stm)
+    tm = self._cm.getClock("logical").gettime()
+    self.assertEqual(1,tm.tv_sec)
+    self.assertEqual(1,tm.tv_usec)
+    tm = ClockManager.instance().getClock("logical").gettime()
+    self.assertEqual(1,tm.tv_sec)
+    self.assertEqual(1,tm.tv_usec)
+    return
+  
+  def test_AdjustedClock(self):
+    tm = self._cm.getClock("adjusted").gettime()
+    stm = OpenRTM_aist.TimeValue(1,1)
+    tm = self._cm.getClock("adjusted").settime(stm)
+    tm = self._cm.getClock("adjusted").gettime()
+    return
+  
+  def test_SystemClock(self):
+    tm = self._cm.getClock("system").gettime()
+    stm = OpenRTM_aist.TimeValue(1,1)
+    tm = self._cm.getClock("system").settime(stm)
+    return
+  
+############### test #################
+if __name__ == '__main__':
+  unittest.main()

Copied: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextBase.py (from rev 542, branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextBase.py)
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextBase.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextBase.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -0,0 +1,321 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file test_ExecutionContextBase.py
+# @brief test for ExecutionContext base class
+# @date $Date: 2007/08/31$
+# @author Shinji Kurihara
+#
+# Copyright (C) 2011
+#    Task-intelligence Research Group,
+#    Intelligent Systems Research Institute,
+#    National Institute of
+#       Advanced Industrial Science and Technology (AIST), Japan
+#    All rights reserved.
+
+import sys
+sys.path.insert(1,"../")
+sys.path.insert(1,"../RTM_IDL")
+
+import time
+import unittest
+
+from ExecutionContextBase import *
+import OpenRTM__POA, RTC__POA, RTC
+import OpenRTM_aist
+
+testcomp_spec = ["implementation_id", "TestComp",
+                 "type_name",         "TestComp",
+                 "description",       "Test example component",
+                 "version",           "1.0",
+                 "vendor",            "Shinji Kurihara, AIST",
+                 "category",          "example",
+                 "activity_type",     "DataFlowComponent",
+                 "max_instance",      "10",
+                 "language",          "Python",
+                 "lang_type",         "compile",
+                 ""]
+
+class TestComp(OpenRTM_aist.DataFlowComponentBase):
+  def __init_(self, manager):
+    OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
+
+    
+def TestCompInit(manager):
+  global com
+  profile = OpenRTM_aist.Properties(defaults_str=configsample_spec)
+  manager.registerFactory(profile,
+        TestComp,
+        OpenRTM_aist.Delete)
+
+
+class MyEC(OpenRTM__POA.ExtTrigExecutionContextService):
+  def __init__(self):
+    self._ref = self._this()
+    return
+
+
+class MyEC2(ExecutionContextBase):
+  def __init__(self, name):
+    ExecutionContextBase.__init__(self, name)
+    return
+
+  def onStarting(self):
+    return RTC.RTC_OK
+
+  def onStarted(self):
+    return RTC.RTC_OK
+
+  def onGetRate(self, rate):
+    return rate
+
+
+class MyEC3(ExecutionContextBase,
+            RTC__POA.ExecutionContextService,
+            OpenRTM_aist.Task):
+
+  def __init__(self, name):
+    ExecutionContextBase.__init__(self, name)
+    OpenRTM_aist.Task.__init__(self)
+    self.setObjRef(self._this())
+    self._svc = False
+    return
+
+  def __del__(self, Task=OpenRTM_aist.Task):
+    self._svc = False
+    return
+
+  def start(self):
+    return ExecutionContextBase.start(self)
+
+  def stop(self):
+    self._svc = False
+    return
+
+  def open(self, *args):
+    self.activate()
+    return 0
+
+  def onStarting(self):
+    self._svc = True
+    self.open(0)
+    return RTC.RTC_OK
+
+
+  def svc(self):
+    while self._svc:
+      ExecutionContextBase.invokeWorkerPreDo(self)
+      ExecutionContextBase.invokeWorkerDo(self)
+      ExecutionContextBase.invokeWorkerPostDo(self)
+
+    return 0
+
+  def onGetRate(self, rate):
+    return rate
+
+    
+class TestExecutioncontextBase(unittest.TestCase):
+  def setUp(self):
+    self.ecbase = ExecutionContextBase("test")
+
+  def tearDown(self):
+    OpenRTM_aist.Manager.instance().shutdownManager()
+    return
+
+  def test_init(self):
+    default_conf = ["sync_transition",      "YES",
+                    "sync_activation",      "YES",
+                    "sync_deactivation",    "YES",
+                    "sync_reset",           "YES",
+                    "transition_timeout",   "0.5",
+                    "activation_timeout",   "0.5",
+                    "deactivation_timeout", "0.5",
+                    "reset_timeout",        "0.5",
+                    ""]
+
+    prop_ = OpenRTM_aist.Properties(defaults_str=default_conf)
+    self.ecbase.init(prop_)
+    return
+
+  def test_bindComponent(self):
+    mgr_ = OpenRTM_aist.Manager.instance()
+    mgr_.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+
+    mgr_.registerFactory(profile,
+                         TestComp,
+                         OpenRTM_aist.Delete)
+
+    comp = mgr_.createComponent("TestComp")
+    ec_ = MyEC()
+    self.ecbase.setObjRef(ec_._ref)
+    self.assertEqual(RTC.RTC_OK, self.ecbase.bindComponent(comp))
+    return
+
+  def test_isRunning(self):
+    ecbase = MyEC2("test ec")
+    self.assertEqual(False,      ecbase.isRunning())
+    self.assertEqual(RTC.RTC_OK, ecbase.start())
+    self.assertEqual(True,       ecbase.isRunning())
+    self.assertEqual(RTC.RTC_OK, ecbase.stop())
+    self.assertEqual(False,      ecbase.isRunning())
+    return
+
+  def test_getRate(self):
+    # default rate in DefaltConfig: 1000
+    # default rate in ExecutionContextProfile.__init__ : 1000000.0
+    self.assertEqual(1000000.0, self.ecbase.getRate())
+    self.assertEqual(RTC.RTC_OK, self.ecbase.setRate(1000.0))
+    self.assertEqual(1000.0, self.ecbase.getRate())
+    self.assertEqual(0.001, self.ecbase.getPeriod().toDouble())
+    return
+
+  def test_addRemoveComponent(self):
+    mgr_ = OpenRTM_aist.Manager.instance()
+    mgr_.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+
+    mgr_.registerFactory(profile,
+                         TestComp,
+                         OpenRTM_aist.Delete)
+
+    comp = mgr_.createComponent("TestComp")
+    ec_ = MyEC()
+    self.ecbase.setObjRef(ec_._ref)
+    self.assertEqual(ec_._ref, self.ecbase.getObjRef())
+    ret = comp.getObjRef()._is_equivalent(comp.getObjRef())
+    self.assertEqual(RTC.RTC_OK, self.ecbase.addComponent(comp.getObjRef()))
+    self.ecbase.invokeWorker()
+    self.assertEqual(RTC.BAD_PARAMETER, self.ecbase.removeComponent(None))
+    self.assertEqual(RTC.RTC_OK, self.ecbase.removeComponent(comp.getObjRef()))
+    return
+
+  def test_actDeactResetComponent(self):
+    mgr_ = OpenRTM_aist.Manager.instance()
+    mgr_.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+
+    mgr_.registerFactory(profile,
+                         TestComp,
+                         OpenRTM_aist.Delete)
+
+    comp = mgr_.createComponent("TestComp")
+    ec_ = MyEC3("test")
+    self.assertEqual(RTC.RTC_OK, ec_.bindComponent(comp))
+    ec_.start()
+    self.assertEqual(RTC.RTC_OK, ec_.activateComponent(comp.getObjRef()))
+    self.assertEqual(RTC.ACTIVE_STATE, ec_.getComponentState(comp.getObjRef()))
+    self.assertEqual(RTC.ACTIVE_STATE, ec_.getComponentState(comp.getObjRef()))
+    time.sleep(0.1)
+    self.assertEqual(RTC.RTC_OK, ec_.deactivateComponent(comp.getObjRef()))
+    self.assertEqual(RTC.INACTIVE_STATE, ec_.getComponentState(comp.getObjRef()))
+    rtobj_ = [None]
+    ec_._worker.activateComponent(comp.getObjRef(),rtobj_)
+    ec_.waitForActivated(rtobj_[0])
+    rtobj_[0].goTo(RTC.ERROR_STATE)
+    time.sleep(0.1)
+    self.assertEqual(RTC.ERROR_STATE, ec_.getComponentState(comp.getObjRef()))
+    self.assertEqual(RTC.RTC_OK, ec_.resetComponent(comp.getObjRef()))
+    self.assertEqual(RTC.INACTIVE_STATE, ec_.getComponentState(comp.getObjRef()))
+    ec_.stop()
+    return
+
+  def test_getStateString(self):
+    self.assertEqual("CREATED_STATE",  self.ecbase.getStateString(RTC.CREATED_STATE))
+    self.assertEqual("INACTIVE_STATE", self.ecbase.getStateString(RTC.INACTIVE_STATE))
+    self.assertEqual("ACTIVE_STATE",   self.ecbase.getStateString(RTC.ACTIVE_STATE))
+    self.assertEqual("ERROR_STATE",    self.ecbase.getStateString(RTC.ERROR_STATE))
+    return
+
+  def test_getKind(self):
+    self.assertEqual(RTC.PERIODIC,  self.ecbase.getKind())
+    self.assertEqual(RTC.RTC_OK,  self.ecbase.setKind(RTC.PERIODIC))
+    self.assertEqual(RTC.PERIODIC,  self.ecbase.getKind())
+    self.assertEqual(RTC.RTC_OK,  self.ecbase.setKind(RTC.EVENT_DRIVEN))
+    self.assertEqual(RTC.EVENT_DRIVEN,  self.ecbase.getKind())
+    self.assertEqual(RTC.RTC_OK,  self.ecbase.setKind(RTC.OTHER))
+    self.assertEqual(RTC.OTHER,  self.ecbase.getKind())
+    self.assertEqual("PERIODIC",  self.ecbase.getKindString(RTC.PERIODIC))
+    self.assertEqual("EVENT_DRIVEN",  self.ecbase.getKindString(RTC.EVENT_DRIVEN))
+    self.assertEqual("OTHER",  self.ecbase.getKindString(RTC.OTHER))
+    return
+
+  def test_getSetProfile(self):
+    self.assertEqual(RTC.PERIODIC,  self.ecbase.getProfile().kind)
+    self.assertEqual(1000000.0,  self.ecbase.getProfile().rate)
+    self.assertEqual(RTC.RTC_OK,  self.ecbase.setKind(RTC.EVENT_DRIVEN))
+    self.assertEqual(RTC.RTC_OK,  self.ecbase.setRate(1000))
+    self.assertEqual(RTC.EVENT_DRIVEN,  self.ecbase.getProfile().kind)
+    self.assertEqual(1000.0,  self.ecbase.getProfile().rate)
+    return
+
+  def test_setOwner(self):
+    mgr_ = OpenRTM_aist.Manager.instance()
+    mgr_.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+
+    mgr_.registerFactory(profile,
+                         TestComp,
+                         OpenRTM_aist.Delete)
+
+    comp = mgr_.createComponent("TestComp")
+    self.ecbase.setOwner(comp.getObjRef())
+    self.assertEqual(comp.getObjRef(), self.ecbase.getOwner())
+    return
+
+  def test_getComponentList(self):
+    mgr_ = OpenRTM_aist.Manager.instance()
+    mgr_.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+
+    mgr_.registerFactory(profile,
+                         TestComp,
+                         OpenRTM_aist.Delete)
+
+    comp = mgr_.createComponent("TestComp")
+    ec_ = MyEC()
+    self.ecbase.setObjRef(ec_._ref)
+    self.assertEqual(ec_._ref, self.ecbase.getObjRef())
+    ret = comp.getObjRef()._is_equivalent(comp.getObjRef())
+    self.assertEqual(RTC.RTC_OK, self.ecbase.addComponent(comp.getObjRef()))
+    self.assertEqual(1, len(self.ecbase.getComponentList()))
+    return
+
+  def test_setProperties(self):
+    prop_ = OpenRTM_aist.Properties()
+    prop_.setProperty("rate", 10)
+    prop_.setProperty("kind", RTC.PERIODIC)
+    self.ecbase.setProperties(prop_)
+    self.assertEqual("10", self.ecbase.getProperties().getProperty("rate"))
+    self.assertEqual("PERIODIC", self.ecbase.getProperties().getProperty("kind"))
+    return
+
+
+  def test_setExecutionRate(self):
+    prop_ = OpenRTM_aist.Properties()
+    prop_.setProperty("rate", 123)
+    self.assertEqual(True, self.ecbase.setExecutionRate(prop_))
+    self.assertEqual(123.0, self.ecbase.getRate())
+    return
+
+  def test_setTransitionMode(self):
+    prop_ = OpenRTM_aist.Properties()
+    prop_.setProperty("sync_transition", "NO")
+    ret_ = [True]
+    self.assertEqual(True, self.ecbase.setTransitionMode(prop_, "sync_transition", ret_))
+    self.assertEqual(False, ret_[0])
+    return
+
+  def test_setTimeout(self):
+    prop_ = OpenRTM_aist.Properties()
+    prop_.setProperty("transition_timeout", 321)
+    ret_ = [None]
+    self.assertEqual(True, self.ecbase.setTimeout(prop_, "transition_timeout", ret_))
+    self.assertEqual(321.0, ret_[0].toDouble())
+    return
+
+
+############### test #################
+if __name__ == '__main__':
+  unittest.main()

Copied: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextProfile.py (from rev 542, branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextProfile.py)
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextProfile.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextProfile.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -0,0 +1,165 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file test_ExecutionContextProfile.py
+# @brief test for ExecutionContextProfile class
+# @date $Date$
+# @author Shinji Kurihara
+#
+# Copyright (C) 2011
+#     Noriaki Ando
+#     Intelligent Systems Research Institute,
+#     National Institute of
+#         Advanced Industrial Science and Technology (AIST), Japan
+#     All rights reserved.
+#
+# $Id$
+#
+
+import sys
+sys.path.insert(1,"../")
+sys.path.insert(1,"../RTM_IDL")
+
+import unittest
+
+from ExecutionContextProfile import *
+import OpenRTM__POA, RTC
+import OpenRTM_aist
+
+
+testcomp_spec = ["implementation_id", "TestComp",
+                 "type_name",         "TestComp",
+                 "description",       "Test example component",
+                 "version",           "1.0",
+                 "vendor",            "Shinji Kurihara, AIST",
+                 "category",          "example",
+                 "activity_type",     "DataFlowComponent",
+                 "max_instance",      "10",
+                 "language",          "Python",
+                 "lang_type",         "compile",
+                 ""]
+
+class TestComp(OpenRTM_aist.DataFlowComponentBase):
+  def __init_(self, manager):
+    OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
+
+    
+def TestCompInit(manager):
+  global com
+  profile = OpenRTM_aist.Properties(defaults_str=configsample_spec)
+  manager.registerFactory(profile,
+        TestComp,
+        OpenRTM_aist.Delete)
+
+class MyEC(OpenRTM__POA.ExtTrigExecutionContextService):
+  def __init__(self):
+    self._ref = self._this()
+    return
+
+class TestExecutionContextProfile(unittest.TestCase):
+
+  def setUp(self):
+    self._ecprofile = ExecutionContextProfile()
+    return
+
+  def tearDown(self):
+    OpenRTM_aist.Manager.instance().shutdownManager()
+    return
+
+  def test_setGetObjRef(self):
+    ec_ = MyEC()
+    self._ecprofile.setObjRef(ec_._ref)
+    self.assertEqual(ec_._ref, self._ecprofile.getObjRef())
+    return
+
+  def test_setGetRate(self):
+    self._ecprofile.setRate(1000.0)
+    self.assertEqual(1000.0, self._ecprofile.getRate())
+    return
+
+  def test_setGetPeriod(self):
+    self.assertEqual(RTC.RTC_OK, self._ecprofile.setPeriod(0.1))
+    self.assertEqual(RTC.BAD_PARAMETER, self._ecprofile.setPeriod(-0.1))
+    self.assertEqual(0.1, self._ecprofile.getPeriod().toDouble())
+    tv_ = OpenRTM_aist.TimeValue(-0.01)
+    self.assertEqual(RTC.BAD_PARAMETER, self._ecprofile.setPeriod(tv=tv_))
+    tv_ = OpenRTM_aist.TimeValue(0.01)
+    self.assertEqual(RTC.RTC_OK, self._ecprofile.setPeriod(tv=tv_))
+    self.assertEqual(0.01, self._ecprofile.getPeriod().toDouble())
+    self.assertEqual(RTC.BAD_PARAMETER, self._ecprofile.setPeriod())
+    return
+
+
+  def test_getKindString(self):
+    self.assertEqual("PERIODIC", self._ecprofile.getKindString(RTC.PERIODIC))
+    self.assertEqual("EVENT_DRIVEN", self._ecprofile.getKindString(RTC.EVENT_DRIVEN))
+    self.assertEqual("OTHER", self._ecprofile.getKindString(RTC.OTHER))
+    self.assertEqual("", self._ecprofile.getKindString(RTC.UNSUPPORTED))
+    return
+
+  def test_setGetKind(self):
+    self.assertEqual(RTC.RTC_OK, self._ecprofile.setKind(RTC.PERIODIC))
+    self.assertEqual(RTC.PERIODIC, self._ecprofile.getKind())
+    self.assertEqual(RTC.RTC_OK, self._ecprofile.setKind(RTC.PERIODIC))
+    self.assertEqual("EVENT_DRIVEN", self._ecprofile.getKindString(RTC.EVENT_DRIVEN))
+    self.assertEqual("OTHER", self._ecprofile.getKindString(RTC.OTHER))
+    self.assertEqual("", self._ecprofile.getKindString(RTC.UNSUPPORTED))
+    return
+
+  def test_setOwner(self):
+    mgr_ = OpenRTM_aist.Manager.instance()
+    mgr_.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+
+    mgr_.registerFactory(profile,
+                         TestComp,
+                         OpenRTM_aist.Delete)
+
+    comp = mgr_.createComponent("TestComp")
+    self.assertEqual(RTC.RTC_OK, self._ecprofile.setOwner(comp.getObjRef()))
+    self.assertEqual(comp.getObjRef(), self._ecprofile.getOwner())
+    return
+
+  def test_addRemoveComponent(self):
+    mgr_ = OpenRTM_aist.Manager.instance()
+    mgr_.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+
+    mgr_.registerFactory(profile,
+                         TestComp,
+                         OpenRTM_aist.Delete)
+
+    comp = mgr_.createComponent("TestComp")
+    self.assertEqual(0, len(self._ecprofile.getComponentList()))
+    self.assertEqual(RTC.RTC_OK, self._ecprofile.addComponent(comp.getObjRef()))
+    self.assertEqual(RTC.BAD_PARAMETER, self._ecprofile.addComponent(None))
+    self.assertEqual(RTC.BAD_PARAMETER, self._ecprofile.removeComponent(None))
+    self.assertEqual(RTC.RTC_OK, self._ecprofile.removeComponent(comp.getObjRef()))
+    self.assertEqual(0, len(self._ecprofile.getComponentList()))
+    self.assertEqual(RTC.RTC_OK, self._ecprofile.addComponent(comp.getObjRef()))
+    self.assertEqual(RTC.RTC_OK, self._ecprofile.addComponent(comp.getObjRef()))
+    self.assertEqual(2, len(self._ecprofile.getComponentList()))
+    return
+
+
+  def test_setGetProperties(self):
+    prop_ = OpenRTM_aist.Properties()
+    prop_.setProperty("test", "test value")
+    self._ecprofile.setProperties(prop_)
+    self.assertEqual("test value", self._ecprofile.getProperties().getProperty("test"))
+    prop_ = OpenRTM_aist.Properties()
+    val_ = OpenRTM_aist.NVUtil.copyToProperties(prop_, self._ecprofile.getProfile().properties)
+    self.assertEqual("test value", prop_.getProperty("test"))
+    return
+
+
+  def test_lock_unlock(self):
+    self._ecprofile.lock()
+    self._ecprofile.unlock()
+    return
+
+
+############### test #################
+if __name__ == '__main__':
+  unittest.main()

Copied: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextWorker.py (from rev 542, branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextWorker.py)
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextWorker.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExecutionContextWorker.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -0,0 +1,242 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file test_ExecutionContextWorker.py
+# @brief test for ExecutionContext's state machine worker class
+# @date $Date$
+# @author Shinji Kurihara
+#
+# Copyright (C) 2011
+#     Noriaki Ando
+#     Intelligent Systems Research Institute,
+#     National Institute of
+#         Advanced Industrial Science and Technology (AIST), Japan
+#     All rights reserved.
+#
+# $Id$
+#
+
+import sys
+sys.path.insert(1,"../")
+sys.path.insert(1,"../RTM_IDL")
+
+import time
+import unittest
+
+from ExecutionContextWorker import *
+import OpenRTM__POA, RTC__POA, RTC
+import OpenRTM_aist
+
+testcomp_spec = ["implementation_id", "TestComp",
+                 "type_name",         "TestComp",
+                 "description",       "Test example component",
+                 "version",           "1.0",
+                 "vendor",            "Shinji Kurihara, AIST",
+                 "category",          "example",
+                 "activity_type",     "DataFlowComponent",
+                 "max_instance",      "10",
+                 "language",          "Python",
+                 "lang_type",         "compile",
+                 ""]
+
+class TestComp(OpenRTM_aist.DataFlowComponentBase):
+  def __init_(self, manager):
+    OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
+
+    
+def TestCompInit(manager):
+  global com
+  profile = OpenRTM_aist.Properties(defaults_str=configsample_spec)
+  manager.registerFactory(profile,
+                          TestComp,
+                          OpenRTM_aist.Delete)
+
+
+class MyEC(OpenRTM__POA.ExtTrigExecutionContextService):
+  def __init__(self):
+    self._ref = self._this()
+    return
+
+class MyEC3(OpenRTM_aist.ExecutionContextBase,
+            RTC__POA.ExecutionContextService,
+            OpenRTM_aist.Task):
+
+  def __init__(self, name):
+    OpenRTM_aist.ExecutionContextBase.__init__(self, name)
+    OpenRTM_aist.Task.__init__(self)
+    self.setObjRef(self._this())
+    self._svc = False
+    return
+
+  def __del__(self, Task=OpenRTM_aist.Task):
+    self._svc = False
+    return
+
+  def start(self):
+    return OpenRTM_aist.ExecutionContextBase.start(self)
+
+  def stop(self):
+    self._svc = False
+    return
+
+  def open(self, *args):
+    self.activate()
+    return 0
+
+  def onStarting(self):
+    self._svc = True
+    self.open(0)
+    return RTC.RTC_OK
+
+
+  def svc(self):
+    while self._svc:
+      OpenRTM_aist.ExecutionContextBase.invokeWorkerPreDo(self)
+      OpenRTM_aist.ExecutionContextBase.invokeWorkerDo(self)
+      OpenRTM_aist.ExecutionContextBase.invokeWorkerPostDo(self)
+
+    return 0
+
+  def onGetRate(self, rate):
+    return rate
+
+class TestExecutionContextWorker(unittest.TestCase):
+
+  def setUp(self):
+    self._ecworker = ExecutionContextWorker()
+
+  def tearDown(self):
+    OpenRTM_aist.Manager.instance().shutdownManager()
+    return
+
+  def test_setGetECRef(self):
+    ec_ = MyEC()
+    ref_ = ec_._ref
+    self._ecworker.setECRef(ref_)
+    self.assertEqual(ref_,self._ecworker.getECRef())
+
+    return
+
+
+  def test_startStopIsRunning(self):
+    self.assertEqual(RTC.RTC_OK, self._ecworker.start())
+    self.assertEqual(RTC.PRECONDITION_NOT_MET, self._ecworker.start())
+    self.assertEqual(True, self._ecworker.isRunning())
+    self.assertEqual(RTC.RTC_OK, self._ecworker.stop())
+    self.assertEqual(False, self._ecworker.isRunning())
+    self.assertEqual(RTC.PRECONDITION_NOT_MET, self._ecworker.stop())
+    return
+
+  def test_actDeactResetState(self):
+    mgr_ = OpenRTM_aist.Manager.instance()
+    mgr_.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+    mgr_.registerFactory(profile,
+                         TestComp,
+                         OpenRTM_aist.Delete)
+    comp = mgr_.createComponent("TestComp")
+    ec_ = MyEC3("test")
+    self._ecworker.setECRef(ec_._this())
+    self.assertEqual(RTC.RTC_OK,self._ecworker.bindComponent(comp))
+    self._ecworker.start()
+    rtobj_ = [None]
+
+    # INACTIVE -> ACTIVE
+    self.assertEqual(RTC.RTC_OK, self._ecworker.activateComponent(comp.getObjRef(),rtobj_))
+    self.assertEqual(False, self._ecworker.isAllCurrentState(RTC.ACTIVE_STATE))
+    self.assertEqual(True, self._ecworker.isAllNextState(RTC.ACTIVE_STATE))
+    self.assertEqual(False, self._ecworker.isOneOfCurrentState(RTC.ACTIVE_STATE))
+    self._ecworker.invokeWorker()
+    self.assertEqual(RTC.ACTIVE_STATE, self._ecworker.getComponentState(comp.getObjRef()))
+    self.assertEqual(True, self._ecworker.isAllCurrentState(RTC.ACTIVE_STATE))
+    self.assertEqual(True, self._ecworker.isOneOfCurrentState(RTC.ACTIVE_STATE))
+
+    # ACTIVE -> INACTIVE
+    self.assertEqual(RTC.RTC_OK, self._ecworker.deactivateComponent(comp.getObjRef(),rtobj_))
+    self.assertEqual(False, self._ecworker.isAllCurrentState(RTC.INACTIVE_STATE))
+    self.assertEqual(True, self._ecworker.isOneOfNextState(RTC.INACTIVE_STATE))
+    self.assertEqual(True, self._ecworker.isAllNextState(RTC.INACTIVE_STATE))
+    self._ecworker.invokeWorker()
+    self.assertEqual(RTC.INACTIVE_STATE, self._ecworker.getComponentState(comp.getObjRef()))
+    self.assertEqual(True, self._ecworker.isAllCurrentState(RTC.INACTIVE_STATE))
+
+    # INACTIVE -> ACTIVE -> ERROR
+    self.assertEqual(RTC.RTC_OK, self._ecworker.activateComponent(comp.getObjRef(),rtobj_))
+    self._ecworker.invokeWorker()
+    rtobj_[0] = self._ecworker.findComponent(comp.getObjRef())
+    rtobj_[0].goTo(RTC.ERROR_STATE)
+    self.assertEqual(True, self._ecworker.isOneOfNextState(RTC.ERROR_STATE))
+    self._ecworker.invokeWorker()
+    self.assertEqual(RTC.ERROR_STATE, self._ecworker.getComponentState(comp.getObjRef()))
+
+    # ERROR -> INACTIVE
+    self.assertEqual(RTC.RTC_OK, self._ecworker.resetComponent(comp.getObjRef(),rtobj_))
+    self._ecworker.invokeWorker()
+    self.assertEqual(RTC.INACTIVE_STATE, self._ecworker.getComponentState(comp.getObjRef()))
+    self.assertEqual(True, self._ecworker.isAllCurrentState(RTC.INACTIVE_STATE))
+    self._ecworker.stop()
+    return
+
+  def waitActivateComplete(self):
+    # No implementation.
+    return
+
+  def waitDeactivateComplete(self):
+    # No implementation.
+    return
+
+  def waitResetComplete(self):
+    # No implementation.
+    return
+
+  def test_getStateString(self):
+    self.assertEqual("CREATED_STATE",  self._ecworker.getStateString(RTC.CREATED_STATE))
+    self.assertEqual("INACTIVE_STATE", self._ecworker.getStateString(RTC.INACTIVE_STATE))
+    self.assertEqual("ACTIVE_STATE",   self._ecworker.getStateString(RTC.ACTIVE_STATE))
+    self.assertEqual("ERROR_STATE",    self._ecworker.getStateString(RTC.ERROR_STATE))
+    return
+
+  def test_addRemoveComponent(self):
+    mgr_ = OpenRTM_aist.Manager.instance()
+    mgr_.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+
+    mgr_.registerFactory(profile,
+                         TestComp,
+                         OpenRTM_aist.Delete)
+
+    comp = mgr_.createComponent("TestComp")
+    ec_ = MyEC()
+    self._ecworker.setECRef(ec_._ref)
+    self.assertEqual(RTC.RTC_OK, self._ecworker.addComponent(comp.getObjRef()))
+    self._ecworker.invokeWorker()
+    self.assertEqual(RTC.BAD_PARAMETER, self._ecworker.removeComponent(None))
+    self.assertEqual(RTC.RTC_OK, self._ecworker.removeComponent(comp.getObjRef()))
+    return
+
+  def test_invokeWorker(self):
+    mgr_ = OpenRTM_aist.Manager.instance()
+    mgr_.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+
+    mgr_.registerFactory(profile,
+                         TestComp,
+                         OpenRTM_aist.Delete)
+
+    comp = mgr_.createComponent("TestComp")
+    ec_ = MyEC()
+    self._ecworker.setECRef(ec_._ref)
+    self.assertEqual(RTC.RTC_OK, self._ecworker.addComponent(comp.getObjRef()))
+    self._ecworker.invokeWorkerPreDo()
+    self._ecworker.invokeWorkerDo()
+    self._ecworker.invokeWorkerPostDo()
+    self._ecworker.updateComponentList()
+    self.assertEqual(RTC.BAD_PARAMETER, self._ecworker.removeComponent(None))
+    self.assertEqual(RTC.RTC_OK, self._ecworker.removeComponent(comp.getObjRef()))
+    return
+
+
+############### test #################
+if __name__ == '__main__':
+  unittest.main()

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExtTrigExecutionContext.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExtTrigExecutionContext.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_ExtTrigExecutionContext.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -45,6 +45,7 @@
     self._dfp._poa._get_the_POAManager().activate()
     self.etec = ExtTrigExecutionContext()
     #self.etec = ExtTrigExecutionContext(self._dfp._ref)
+    return
 
   def tearDown(self):
     OpenRTM_aist.Manager.instance().shutdownManager()
@@ -56,6 +57,8 @@
   def test_run(self):
     self.assertEqual(self.etec.start(),RTC.RTC_OK)
     self.assertEqual(self.etec.add_component(self._dfp._this()),RTC.RTC_OK)
+    self.etec.start()
+    self.etec.invokeWorker()
     self.assertEqual(self.etec.activate_component(self._dfp._this()),RTC.RTC_OK)
     import time
     time.sleep(1)
@@ -72,9 +75,12 @@
       th.join()
     self._dfp._poa.deactivate_object(self._dfp._poa.servant_to_id(self.etec))
     self._dfp._poa.deactivate_object(self._dfp._poa.servant_to_id(self._dfp))
+    self.etec.stop()
+    return
 
   def stop(self):
     self.etec.stop()
+    return
 
 ############### test #################
 if __name__ == '__main__':

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_GlobalFactory.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_GlobalFactory.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_GlobalFactory.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -24,91 +24,129 @@
 from GlobalFactory import *
 
 class Test:
-	def __init__(self):
-		pass
+  def __init__(self):
+    pass
 
-	def test(self):
-		return True
+  def test(self):
+    return True
 
 class TestGlobalFactory(unittest.TestCase):
 
-	def setUp(self):
-		self.factory = GlobalFactory.instance()
-		self.factory.addFactory("test",Test,OpenRTM_aist.Delete)
-		return
+  def setUp(self):
+    self.factory = GlobalFactory.instance()
+    self.creator = Test
+    self.destructor = OpenRTM_aist.Delete
+    self.factory.addFactory("test",self.creator,self.destructor)
+    return
 
-	def tearDown(self):
-		self.factory.removeFactory("test")
-		return
+  def tearDown(self):
+    self.factory.removeFactory("test")
+    return
 
-	def test_isinstance(self):
-		self.assertEqual(self.factory,GlobalFactory.instance())
+  def test_isinstance(self):
+    self.assertEqual(self.factory,GlobalFactory.instance())
 
-	def test_hasFactory(self):
-		# addFactoryにて登録したファクトリオブジェクトの問い合わせ。
-		self.assertEqual(self.factory.hasFactory("test"),True)
-		# addFactoryにて登録していないファクトリオブジェクトの問い合わせ。
-		self.assertEqual(self.factory.hasFactory("testtest"),False)
-		# addFactoryにて登録していないファクトリオブジェクトの問い合わせ(空文字)。
-		self.assertEqual(self.factory.hasFactory(""),False)
-		return
+  def test_hasFactory(self):
+    # addFactoryにて登録したファクトリオブジェクトの問い合わせ。
+    self.assertEqual(self.factory.hasFactory("test"),True)
+    # addFactoryにて登録していないファクトリオブジェクトの問い合わせ。
+    self.assertEqual(self.factory.hasFactory("testtest"),False)
+    # addFactoryにて登録していないファクトリオブジェクトの問い合わせ(空文字)。
+    self.assertEqual(self.factory.hasFactory(""),False)
+    return
 
-	def test_getIdentifiers(self):
-		# ファクトリが登録済みの場合の問い合わせ。
-		self.assertEqual(self.factory.getIdentifiers(),["test"])
-		GlobalFactory.instance().addFactory("test2",Test,OpenRTM_aist.Delete)
-		self.assertEqual(self.factory.getIdentifiers(),["test","test2"])
-		# ファクトリが登録されていない場合の問い合わせ。
-		self.factory.removeFactory("test")
-		self.factory.removeFactory("test2")
-		self.assertEqual(self.factory.getIdentifiers(),[])
-		return
-	
-	def test_addFactory(self):
-		# creatorを指定しない場合、INVALID_ARGが返されるか?
-		self.assertEqual(GlobalFactory.instance().addFactory("test",None,OpenRTM_aist.Delete),
-				 GlobalFactory.INVALID_ARG)
+  def test_getIdentifiers(self):
+    # ファクトリが登録済みの場合の問い合わせ。
+    self.assertEqual(self.factory.getIdentifiers(),["test"])
+    GlobalFactory.instance().addFactory("test2",Test,OpenRTM_aist.Delete)
+    self.assertEqual(self.factory.getIdentifiers(),["test","test2"])
+    # ファクトリが登録されていない場合の問い合わせ。
+    self.factory.removeFactory("test")
+    self.factory.removeFactory("test2")
+    self.assertEqual(self.factory.getIdentifiers(),[])
+    return
+  
+  def test_addFactory(self):
+    # creatorを指定しない場合、INVALID_ARGが返されるか?
+    self.assertEqual(GlobalFactory.instance().addFactory("test",None,OpenRTM_aist.Delete),
+                     GlobalFactory.INVALID_ARG)
 
-		# 既に登録済みのIDにてaddFactory()をコールした場合、ALREADY_EXISTSが返されるか?
-		self.assertEqual(GlobalFactory.instance().addFactory("test",Test,OpenRTM_aist.Delete),
-				 GlobalFactory.ALREADY_EXISTS)
+    # 既に登録済みのIDにてaddFactory()をコールした場合、ALREADY_EXISTSが返されるか?
+    self.assertEqual(GlobalFactory.instance().addFactory("test",Test,OpenRTM_aist.Delete),
+                     GlobalFactory.ALREADY_EXISTS)
 
-		# idとcreatorを指定してaddFactory()をコールした場合、FACTORY_OKが返されるか?
-		self.assertEqual(GlobalFactory.instance().addFactory("test1",Test,OpenRTM_aist.Delete),
-				 GlobalFactory.FACTORY_OK)
-		self.factory.removeFactory("test1")
+    # idとcreatorを指定してaddFactory()をコールした場合、FACTORY_OKが返されるか?
+    self.assertEqual(GlobalFactory.instance().addFactory("test1",Test,OpenRTM_aist.Delete),
+                     GlobalFactory.FACTORY_OK)
+    self.factory.removeFactory("test1")
 
+    return
 
-		return
+  def test_removeFactory(self):
+    # 登録していないIDでコールした場合、NOT_FOUNDが返されるか?
+    self.assertEqual(self.factory.removeFactory("testtest"),
+                     GlobalFactory.NOT_FOUND)
+         
+    # 登録済みのIDでコールした場合、FACTORY_OKが返されるか?
+    self.assertEqual(self.factory.removeFactory("test"),
+                     GlobalFactory.FACTORY_OK)
 
-	def test_removeFactory(self):
-		# 登録していないIDでコールした場合、NOT_FOUNDが返されるか?
-		self.assertEqual(self.factory.removeFactory("testtest"),
-				 GlobalFactory.NOT_FOUND)
-				 
-		# 登録済みのIDでコールした場合、FACTORY_OKが返されるか?
-		self.assertEqual(self.factory.removeFactory("test"),
-				 GlobalFactory.FACTORY_OK)
+    # ファクトリが正しく削除されたか?
+    self.assertEqual(self.factory.getIdentifiers(),[])
+    return
 
-		# ファクトリが正しく削除されたか?
-		self.assertEqual(self.factory.getIdentifiers(),[])
-		return
+  def test_createObject(self):
+    # 登録していないIDでコールした場合、Noneが返されるか?
+    self.assertEqual(self.factory.createObject("testtest"),
+                     None)
+    # 登録済みのIDでコールした場合、正しいオブジェクトが返されるか?
+    obj = self.factory.createObject("test")
+    self.assertEqual(obj.test(),True)
+    self.factory.deleteObject(obj)
+    return
 
-	def test_createObject(self):
-		# 登録していないIDでコールした場合、Noneが返されるか?
-		self.assertEqual(self.factory.createObject("testtest"),
-				 None)
-		# 登録済みのIDでコールした場合、正しいオブジェクトが返されるか?
-		self.assertEqual(self.factory.createObject("test").test(),True)
-		return
+  def test_deleteObject(self):
+    # 登録していないIDでコールした場合
+    self.factory.deleteObject(self.factory.createObject("test"),"testtest")
+    # IDを指定しないでコールした場合
+    self.factory.deleteObject(self.factory.createObject("test"))
+    return
 
-	def test_deleteObject(self):
-		# 登録していないIDでコールした場合
-		self.factory.deleteObject(self.factory.createObject("test"),"testtest")
-		# IDを指定しないでコールした場合
-		self.factory.deleteObject(self.factory.createObject("test"))
-		return
+  def test_createdObjects(self):
+    self.assertEqual(0, len(self.factory.createdObjects()))
+    obj = self.factory.createObject("test")
+    self.assertEqual(obj.test(),True)
+    self.assertEqual(1, len(self.factory.createdObjects()))
+    self.factory.deleteObject(obj)
+    return
 
+  def test_isProducerOf(self):
+    obj = self.factory.createObject("test")
+    self.assertEqual(True, self.factory.isProducerOf(obj))
+    self.factory.deleteObject(obj)
+    return
+
+  def test_objectToIdentifier(self):
+    obj = self.factory.createObject("test")
+    id_ = [None]
+    self.assertEqual(Factory.FACTORY_OK, self.factory.objectToIdentifier(obj, id_))
+    self.assertEqual("test",id_[0])
+    self.factory.deleteObject(obj)
+    return
+
+  def test_objectToCreator(self):
+    obj = self.factory.createObject("test")
+    self.assertEqual(self.creator, self.factory.objectToCreator(obj))
+    self.factory.deleteObject(obj)
+    return
+
+  def test_objectToDestructor(self):
+    obj = self.factory.createObject("test")
+    self.assertEqual(self.destructor, self.factory.objectToDestructor(obj))
+    self.factory.deleteObject(obj)
+    return
+
+
 ############### test #################
 if __name__ == '__main__':
         unittest.main()

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_PeriodicExecutionContext.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_PeriodicExecutionContext.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_PeriodicExecutionContext.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -165,7 +165,7 @@
     self._dfp = DFP()
     self._dfp._poa._get_the_POAManager().activate()
 
-    self._pec = PeriodicExecutionContext(self._dfp._ref, 10)
+    self._pec = PeriodicExecutionContext()
     self._pec.add_component(self._dfp.getRef())
     self._pec.start()
   

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_RTObject.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_RTObject.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_RTObject.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -152,8 +152,8 @@
     rtobj = TestComp(self._orb, self._poa)
     ec = rtobj.getObjRef().get_context(0)
     self.assertEqual(ec,None)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     self.assertNotEqual(rtobj.getObjRef().get_owned_contexts(),[])
     self.assertEqual(rtobj.is_alive(ec.getObjRef()),True)
@@ -166,8 +166,8 @@
   def test_get_owned_contexts(self):
     rtobj = TestComp(self._orb, self._poa)
     self.assertEqual(rtobj.getObjRef().get_owned_contexts(),[])
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     self.assertNotEqual(rtobj.getObjRef().get_owned_contexts(),[])
     ec.remove_component(rtobj.getObjRef())
@@ -201,7 +201,7 @@
 
   def test_attach_context(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec = OpenRTM_aist.PeriodicExecutionContext(rtobj.getObjRef(), 10)
+    ec = OpenRTM_aist.PeriodicExecutionContext()
     id = rtobj.getObjRef().attach_context(ec.getObjRef())
     print "attach_context: ", id
     print rtobj.getObjRef().detach_context(id)
@@ -318,24 +318,25 @@
   # since 1.1.0
   def test_getExecutionContext(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     self.assertNotEqual(rtobj.getExecutionContext(0),None)
     return
 
   def test_getExecutionRate(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
+    ec.set_rate(1000)
     ec.bindComponent(rtobj)
     self.assertEqual(rtobj.getExecutionRate(0),1000.0)
     return
 
   def test_setExecutionRate(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     self.assertEqual(rtobj.setExecutionRate(0,10000),RTC.RTC_OK)
     self.assertEqual(rtobj.getExecutionRate(0),10000.0)
@@ -343,20 +344,20 @@
 
   def test_isOwnExecutionContext(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     self.assertEqual(rtobj.isOwnExecutionContext(0),True)
     return
 
   def test_activate_deactivate(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.set_rate(1000.0)
     ec.bindComponent(rtobj)
+    ec.start()
     self.assertEqual(rtobj.activate(0),RTC.RTC_OK)
-    ec.start()
     time.sleep(0.1)
     ret = rtobj.deactivate(0)
     time.sleep(0.1)
@@ -366,12 +367,12 @@
 
   def test_reset(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
+    ec.start()
     self.assertEqual(rtobj.activate(0),RTC.RTC_OK)
-    ec.start()
-    ec._comps[0]._sm._sm.goTo(RTC.ERROR_STATE)
+    ec._worker._comps[0]._sm.goTo(RTC.ERROR_STATE)
     time.sleep(0.1)
     self.assertEqual(rtobj.reset(0),RTC.RTC_OK)
     ec.stop()
@@ -517,8 +518,8 @@
 
   def test_preOnInitialize(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     print "preOnInitialize()"
     rtobj.preOnInitialize(0)
@@ -526,216 +527,216 @@
 
   def test_preOnFinalize(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnFinalize(0)
     return
 
   def test_preOnStartup(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnStartup(0)
     return
 
   def test_preOnShutdown(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnShutdown(0)
     return
 
   def test_preOnActivated(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnActivated(0)
     return
 
   def test_preOnDeactivated(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnDeactivated(0)
     return
 
   def test_preOnAborting(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnAborting(0)
     return
 
   def test_preOnError(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnError(0)
     return
 
   def test_preOnReset(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnReset(0)
     return
 
   def test_preOnExecute(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnExecute(0)
     return
 
   def test_preOnStateUpdate(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnStateUpdate(0)
     return
 
   def test_preOnRateChanged(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.preOnRateChanged(0)
     return
 
   def test_postOnInitialize(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnInitialize(0,True)
     return
 
   def test_postOnFinalize(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnFinalize(0,True)
     return
 
   def test_postOnStartup(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnStartup(0,True)
     return
 
   def test_postOnShutdown(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnShutdown(0,True)
     return
 
   def test_postOnActivated(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnActivated(0,True)
     return
 
   def test_postOnDeactivated(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnDeactivated(0,True)
     return
 
   def test_postOnAborting(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnAborting(0,True)
     return
 
   def test_postOnError(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnError(0,True)
     return
 
   def test_postOnReset(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnReset(0,True)
     return
 
   def test_postOnExecute(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnExecute(0,True)
     return
 
   def test_postOnStateUpdate(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnStateUpdate(0,True)
     return
 
   def test_postOnRateChanged(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.postOnRateChanged(0,True)
     return
 
   def test_onAddPort(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.onAddPort(0)
     return
 
   def test_onRemovePort(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.onRemovePort(0)
     return
 
   def test_onAttachExecutionContext(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.onAttachExecutionContext(0)
     return
 
   def test_onDetachExecutionContext(self):
     rtobj = TestComp(self._orb, self._poa)
-    ec_args = "PeriodicExecutionContext"+"?" + "rate=1000"
-    ec=OpenRTM_aist.Manager.instance().createContext(ec_args)
+    ec_args = "PeriodicExecutionContext"
+    ec=OpenRTM_aist.ExecutionContextFactory.instance().createObject(ec_args)
     ec.bindComponent(rtobj)
     rtobj.onDetachExecutionContext(0)
     return

Copied: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_RTObjectStateMachine.py (from rev 542, branches/work/OpenRTM-aist-Python/OpenRTM_aist/test/test_RTObjectStateMachine.py)
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_RTObjectStateMachine.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_RTObjectStateMachine.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -0,0 +1,127 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file test_RTObjectStateMachine.py
+# @brief test for ExecutionContext's state machine worker class
+# @date $Date$
+# @author Shinji Kurihara
+#
+# Copyright (C) 2011
+#     Noriaki Ando
+#     Intelligent Systems Research Institute,
+#     National Institute of
+#         Advanced Industrial Science and Technology (AIST), Japan
+#     All rights reserved.
+#
+# $Id$
+#
+
+import sys
+sys.path.insert(1,"../")
+sys.path.insert(1,"../RTM_IDL")
+
+import unittest
+
+from RTObjectStateMachine import *
+import OpenRTM__POA, RTC
+import OpenRTM_aist
+
+
+testcomp_spec = ["implementation_id", "TestComp",
+                 "type_name",         "TestComp",
+                 "description",       "Test example component",
+                 "version",           "1.0",
+                 "vendor",            "Shinji Kurihara, AIST",
+                 "category",          "example",
+                 "activity_type",     "DataFlowComponent",
+                 "max_instance",      "10",
+                 "language",          "Python",
+                 "lang_type",         "compile",
+                 ""]
+
+class TestComp(OpenRTM_aist.DataFlowComponentBase):
+  def __init_(self, manager):
+    OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
+
+    
+def TestCompInit(manager):
+  global com
+  profile = OpenRTM_aist.Properties(defaults_str=configsample_spec)
+  manager.registerFactory(profile,
+        TestComp,
+        OpenRTM_aist.Delete)
+
+class TestRTObjectStateMachine(unittest.TestCase):
+  """
+  """
+
+  def setUp(self):
+    self._mgr = OpenRTM_aist.Manager.instance()
+    self._mgr.activateManager()
+    profile = OpenRTM_aist.Properties(defaults_str=testcomp_spec)
+    self._mgr.registerFactory(profile,
+                              TestComp,
+                              OpenRTM_aist.Delete)
+    self._comp = self._mgr.createComponent("TestComp")
+    self._rtsm = RTObjectStateMachine(0, self._comp.getObjRef())
+
+  def tearDown(self):
+    OpenRTM_aist.Manager.instance().shutdownManager()
+    return
+
+  def test_getRTObject(self):
+    self.assertEqual(self._comp.getObjRef(), self._rtsm.getRTObject())
+    return
+
+  def test_isEquivalent(self):
+    self.assertEqual(True, self._rtsm.isEquivalent(self._comp.getObjRef()))
+    return
+
+  def test_getExecutionContextHandle(self):
+    self.assertEqual(0, self._rtsm.getExecutionContextHandle())
+    return
+
+  def test_ComponentActionOperations(self):
+    self._rtsm.onStartup()
+    self._rtsm.onShutdown()
+    self._rtsm.onActivated(RTC.INACTIVE_STATE)
+    self._rtsm.onDeactivated(RTC.ACTIVE_STATE)
+    self._rtsm.onError(RTC.ACTIVE_STATE)
+    self._rtsm.onReset(RTC.ERROR_STATE)
+    self._rtsm.onExecute(RTC.ACTIVE_STATE)
+    self._rtsm.onStateUpdate(RTC.ACTIVE_STATE)
+    self._rtsm.onRateChanged()
+    self._rtsm.onAction(RTC.ACTIVE_STATE)
+    self._rtsm.onModeChanged(RTC.ACTIVE_STATE)
+    return
+
+  def test_getState(self):
+    self.assertEqual(RTC.INACTIVE_STATE, self._rtsm.getState())
+    self.assertEqual(RTC.INACTIVE_STATE, self._rtsm.getStates().curr)
+    self.assertEqual(True, self._rtsm.isCurrentState(RTC.INACTIVE_STATE))
+    self.assertEqual(True, self._rtsm.isNextState(RTC.INACTIVE_STATE))
+    self._rtsm.goTo(RTC.ACTIVE_STATE)
+    self.assertEqual(True, self._rtsm.isNextState(RTC.ACTIVE_STATE))
+    return
+
+
+  def test_worker(self):
+    self._rtsm.workerPreDo()
+    self._rtsm.workerDo()
+    self._rtsm.workerPostDo()
+    return
+
+
+  def test_ComponentAction(self):
+    self._rtsm.setComponentAction(self._comp.getObjRef())
+    self._rtsm.setDataFlowComponentAction(self._comp.getObjRef())
+    self._rtsm.setFsmParticipantAction(self._comp.getObjRef())
+    self._rtsm.setMultiModeComponentAction(self._comp.getObjRef())
+    return
+
+
+
+############### test #################
+if __name__ == '__main__':
+  unittest.main()

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_TimeMeasure.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_TimeMeasure.py	2013-04-18 07:18:34 UTC (rev 557)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_TimeMeasure.py	2013-04-26 14:52:58 UTC (rev 558)
@@ -150,7 +150,39 @@
     self.assert_(math.fabs(mean[0] - wait_) < 0.03)
     self.assert_(stdev[0] < (wait_ / 5.0))
     return
-  
+
+  def test_getsettimeofday(self):
+    """
+    if sys.platform == "win32":
+      from ctypes import windll, Structure, c_ushort, byref, c_ulong, c_long
+      class SYSTEMTIME(Structure):
+        _fields_ = [('wYear', c_ushort), 
+                    ('wMonth', c_ushort), 
+                    ('wDayOfWeek', c_ushort), 
+                    ('wDay', c_ushort), 
+                    ('wHour', c_ushort), 
+                    ('wMinute', c_ushort), 
+                    ('wSecond', c_ushort), 
+                    ('wMilliseconds', c_ushort)]
+
+
+      class LARGE_INTEGER(Structure):
+        _fields_ = [('low', c_ulong), 
+                    ('high', c_long)]
+
+
+      st = SYSTEMTIME(0,0,0,0,0,0,0,0)
+      windll.kernel32.GetSystemTime(byref(st))
+      ft = LARGE_INTEGER(0,0)
+      windll.kernel32.SystemTimeToFileTime(byref(st),byref(ft))
+      ret = windll.kernel32.FileTimeToSystemTime(byref(ft),
+                                                 byref(st))
+      print "settime Yer:", st.wYear, " Month:", st.wMonth, \
+          " DayOfWeek:", st.wDayOfWeek, " wDay:", st.wDay,  \
+          " Hour:", st.wHour, "Minute:", st.wMinute, \
+          " Second:", st.wSecond, "Milliseconds:", st.wMilliseconds
+    """
+    return
 ############### test #################
 if __name__ == '__main__':
   unittest.main()



More information about the openrtm-commit mailing list