[openrtm-commit:00963] r679 - in trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC: . executionContext

openrtm @ openrtm.org openrtm @ openrtm.org
2013年 1月 31日 (木) 21:54:12 JST


Author: ga
Date: 2013-01-31 21:54:12 +0900 (Thu, 31 Jan 2013)
New Revision: 679

Added:
   trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObjectStateMachineHolder.java
Modified:
   trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObjectStateMachine.java
   trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObject_impl.java
   trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/StateMachine.java
   trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextBase.java
   trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextWorker.java
   trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java
   trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/IExecutionContextBase.java
   trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java
Log:
New ECBase have been implemented. refs #2322

Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObjectStateMachine.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObjectStateMachine.java	2013-01-31 12:46:19 UTC (rev 678)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObjectStateMachine.java	2013-01-31 12:54:12 UTC (rev 679)
@@ -34,6 +34,9 @@
         m_dfcVar  = null;
         m_fsmVar  = null;
         m_modeVar = null;
+		m_rtobjPtr = null;
+		m_measure = false;
+		m_count = 0;
         // Setting Action callback objects
         setComponentAction(comp);
         setDataFlowComponentAction(comp);
@@ -70,6 +73,14 @@
      */
     private class onActivated implements StateAction {
         public void doAction(StateHolder state) {
+			// call Servant
+			if (m_rtobjPtr != null) {
+				if (m_rtobjPtr.on_activated(m_id) != ReturnCode_t.RTC_OK) {
+					m_sm.goTo(LifeCycleState.ERROR_STATE);
+				}
+				return;
+			}
+			// call Object reference
             if (!m_ca) { 
                 return; 
             }
@@ -85,10 +96,47 @@
      */
     private class onExecute implements StateAction {
         public void doAction(StateHolder state) {
+            TimeMeasure.Statistics stat;
+            // call Servant
+            if (m_rtobjPtr != null) {
+                if (m_measure) { m_svtMeasure.tick(); }
+                if (m_rtobjPtr.on_execute(m_id) != ReturnCode_t.RTC_OK) {
+                    m_sm.goTo(LifeCycleState.ERROR_STATE);
+                }
+                if (m_measure) {
+                    m_svtMeasure.tack();
+                    if (m_count > 1000) {
+                        m_count = 0;
+                        stat = m_svtMeasure.getStatistics();
+                        System.out.println("[servant]");
+                        System.out.println(" max:  " + stat.max_interval);
+                        System.out.println(" min:  " + stat.min_interval);
+                        System.out.println(" mean:  " + stat.mean_interval);
+                        System.out.println(" stddev:  " + stat.std_deviation);
+                    }
+                    ++m_count;
+                }
+                return;
+            }
             if (!m_dfc) { 
                 return; 
             }
-            if (m_dfcVar.on_execute(m_id) != ReturnCode_t.RTC_OK) {
+            if (m_measure) { m_refMeasure.tick(); }
+            ReturnCode_t ret = m_dfcVar.on_execute(m_id);
+            if (m_measure) {
+                m_refMeasure.tack();
+                if (m_count > 1000) {
+                    m_count = 0;
+                    stat = m_refMeasure.getStatistics();
+                    System.out.println("[object]");
+                    System.out.println(" max:  " + stat.max_interval);
+                    System.out.println(" min:  " + stat.min_interval);
+                    System.out.println(" mean:  " + stat.mean_interval);
+                    System.out.println(" stddev:  " + stat.std_deviation);
+                }
+                ++m_count;
+            }
+            if (ret != ReturnCode_t.RTC_OK) {
                 m_sm.goTo(LifeCycleState.ERROR_STATE);
                 return;
             }
@@ -100,6 +148,14 @@
      */
     private class onStateUpdate implements StateAction {
         public void doAction(StateHolder state) {
+			// call Servant
+			if (m_rtobjPtr != null) {
+				if (m_rtobjPtr.on_state_update(m_id) != ReturnCode_t.RTC_OK) {
+					m_sm.goTo(LifeCycleState.ERROR_STATE);
+				}
+				return;
+			}
+			// call Object reference
             if (!m_dfc) { 
                 return; 
             }
@@ -115,6 +171,12 @@
      */
     private class onDeactivated implements StateAction {
         public void doAction(StateHolder state) {
+			// call Servant
+			if (m_rtobjPtr != null) {
+				m_rtobjPtr.on_deactivated(m_id);
+				return;
+			}
+			// call Object reference
             if (!m_ca) { 
                 return; 
             }
@@ -126,6 +188,12 @@
      */
     private class onAborting implements StateAction {
         public void doAction(StateHolder state) {
+			// call Servant
+			if (m_rtobjPtr != null) {
+				m_rtobjPtr.on_aborting(m_id);
+				return;
+			}
+			// call Object reference
             if (!m_ca) { 
                 return; 
             }
@@ -137,6 +205,12 @@
      */
     private class onError implements StateAction {
         public void doAction(StateHolder state) {
+			// call Servant
+			if (m_rtobjPtr != null) {
+				m_rtobjPtr.on_error(m_id);
+				return;
+			}
+			// call Object reference
             if (!m_ca) { 
                 return; 
             }
@@ -148,6 +222,14 @@
      */
     private class onReset implements StateAction {
         public void doAction(StateHolder state) {
+			// call Servant
+			if (m_rtobjPtr != null) {
+				if (m_rtobjPtr.on_reset(m_id) != ReturnCode_t.RTC_OK) {
+					m_sm.goTo(LifeCycleState.ERROR_STATE);
+				}
+				return;
+			}
+			// call Object reference
             if (!m_ca) { 
                 return; 
             }
@@ -185,6 +267,12 @@
      *
      */
     public void onStartup(){
+        // call Servant
+        if (m_rtobjPtr != null) {
+            m_rtobjPtr.on_startup(m_id);
+            return;
+        }
+        // call Object reference
         if (!m_ca) { 
             return; 
         }
@@ -194,6 +282,12 @@
      *
      */
     public void onShutdown(){
+        // call Servant
+        if (m_rtobjPtr != null) {
+            m_rtobjPtr.on_shutdown(m_id);
+            return;
+        }
+        // call Object reference
         if (!m_ca) { 
             return; 
         }
@@ -203,6 +297,14 @@
      *
      */
     public void onActivated(final StateHolder<LifeCycleState> st) {
+        // call Servant
+        if (m_rtobjPtr != null) {
+            if (m_rtobjPtr.on_activated(m_id) != ReturnCode_t.RTC_OK) {
+                m_sm.goTo(LifeCycleState.ERROR_STATE);
+            }
+            return;
+        }
+        // call Object reference
         if (!m_ca) { 
             return; 
         }
@@ -216,6 +318,12 @@
      *
      */
     public void onDeactivated(final StateHolder<LifeCycleState> st) {
+        // call Servant
+        if (m_rtobjPtr != null) {
+            m_rtobjPtr.on_deactivated(m_id);
+            return;
+        }
+        // call Object reference
         if (!m_ca) { 
             return; 
         }
@@ -225,6 +333,12 @@
      *
      */
     public void onAborting(final StateHolder<LifeCycleState> st) {
+        // call Servant
+        if (m_rtobjPtr != null) {
+            m_rtobjPtr.on_aborting(m_id);
+            return;
+        }
+        // call Object reference
         if (!m_ca) { 
             return; 
         }
@@ -234,6 +348,12 @@
      *
      */
     public void onError(final StateHolder<LifeCycleState> st){
+        // call Servant
+        if (m_rtobjPtr != null) {
+            m_rtobjPtr.on_error(m_id);
+            return;
+        }
+        // call Object reference
         if (!m_ca) { 
             return; 
         }
@@ -243,6 +363,14 @@
      *
      */
     public void onReset(final StateHolder<LifeCycleState> st){
+        // call Servant
+        if (m_rtobjPtr != null) {
+            if (m_rtobjPtr.on_reset(m_id) != ReturnCode_t.RTC_OK) {
+                m_sm.goTo(LifeCycleState.ERROR_STATE);
+            }
+            return;
+        }
+        // call Object reference
         if (!m_ca) { 
             return; 
         }
@@ -272,6 +400,14 @@
      *
      */
     public void onStateUpdate(final StateHolder<LifeCycleState> st){
+        // call Servant
+        if (m_rtobjPtr != null) {
+            if (m_rtobjPtr.on_state_update(m_id) != ReturnCode_t.RTC_OK) {
+                m_sm.goTo(LifeCycleState.ERROR_STATE);
+            }
+            return;
+        }
+        // call Object reference
         if (!m_dfc) { 
             return; 
         }
@@ -285,6 +421,14 @@
      *
      */
     public void onRateChanged(){
+        // call Servant
+        if (m_rtobjPtr != null) {
+            if (m_rtobjPtr.on_rate_changed(m_id) != ReturnCode_t.RTC_OK) {
+                m_sm.goTo(LifeCycleState.ERROR_STATE);
+            }
+            return;
+        }
+        // call Object reference
         if (!m_dfc) { 
             return; 
         }
@@ -385,25 +529,33 @@
 
     protected void setComponentAction(final LightweightRTObject comp) {
         m_caVar = ComponentActionHelper.narrow(comp);
-        if (m_caVar!=null) { 
-            m_ca = true; 
+        if (m_caVar==null) {
+            return; 
         }
+		m_ca = true;
+		Manager manager = Manager.instance();
+		try {
+		    m_rtobjPtr = (RTObject_impl)manager.getPOA().reference_to_servant(comp);
+		} catch (Exception ex) {
+
+		}
     }
     protected void setDataFlowComponentAction(final LightweightRTObject comp){
-        m_dfcVar = DataFlowComponentActionHelper.narrow(comp);
-        if (m_dfcVar!=null) { 
+        if(comp._is_a(DataFlowComponentActionHelper.id())) {
+            m_dfcVar = DataFlowComponentActionHelper.narrow(comp);
             m_dfc = true; 
         }
     }
     protected void setFsmParticipantAction(final LightweightRTObject comp){
-        m_fsmVar = FsmParticipantActionHelper.narrow(comp);
-        if (m_fsmVar!=null) { 
+        if(comp._is_a(FsmParticipantActionHelper.id())) {
+            m_fsmVar = FsmParticipantActionHelper.narrow(comp);
             m_fsm = true; 
         }
     }
+
     protected void setMultiModeComponentAction(final LightweightRTObject comp){
-        m_modeVar = MultiModeComponentActionHelper.narrow(comp);
-        if (m_modeVar!=null) { 
+        if(comp._is_a(MultiModeComponentActionHelper.id())) {
+            m_modeVar = MultiModeComponentActionHelper.narrow(comp);            
             m_mode = true; 
         }
     }
@@ -428,7 +580,11 @@
     private DataFlowComponentAction  m_dfcVar;
     private FsmParticipantAction     m_fsmVar;
     private MultiModeComponentAction m_modeVar;
-
+	private RTObject_impl m_rtobjPtr;
+	private boolean m_measure;
+	private TimeMeasure m_svtMeasure = new TimeMeasure();
+	private TimeMeasure m_refMeasure = new TimeMeasure();
+	private int m_count;
     //    char dara[1000];
     // Component action invoker
     

Added: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObjectStateMachineHolder.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObjectStateMachineHolder.java	                        (rev 0)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObjectStateMachineHolder.java	2013-01-31 12:54:12 UTC (rev 679)
@@ -0,0 +1,32 @@
+package jp.go.aist.rtm.RTC;
+
+  /**
+   * {@.ja RTObjectStateMachine保持用クラス。}
+   * {@.en RTObjectStateMachine holder class}
+   * 
+   * <p>
+   * {@.ja RTObjectStateMachineを保持するためのホルダークラス。}
+   * {@.en This is a holder class to hold RTObjectStateMachine.}
+   *
+   */
+public class RTObjectStateMachineHolder {
+  /**
+   * {@.ja デフォルトコンストラクタ}
+   * {@.en Default constructor}
+   */
+  public RTObjectStateMachineHolder() {
+      this.rtobjsm = null;
+  }
+  /**
+   * {@.ja コピーコンストラクタ}
+   * {@.en Copy constructor}
+   */
+  public RTObjectStateMachineHolder(RTObjectStateMachine rtobjsm) {
+      this.rtobjsm = rtobjsm;
+  }
+  /**
+   * {@.ja RTObjectStateMachineオブジェクト}
+   * {@.en RTObjectStateMachine object}
+   */   
+  public RTObjectStateMachine rtobjsm;
+}

Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObject_impl.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObject_impl.java	2013-01-31 12:46:19 UTC (rev 678)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObject_impl.java	2013-01-31 12:54:12 UTC (rev 679)
@@ -1295,7 +1295,7 @@
             preOnInitialize(0);
             rtcout.println(Logbuf.DEBUG, "Calling onInitialize().");
             ret = onInitialize();
-            if (ret == ReturnCode_t.RTC_OK) {
+            if (ret != ReturnCode_t.RTC_OK) {
                 rtcout.println(Logbuf.ERROR,
                         "onInitialize() returns an ERROR ("
                         +ret

Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/StateMachine.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/StateMachine.java	2013-01-31 12:46:19 UTC (rev 678)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/StateMachine.java	2013-01-31 12:54:12 UTC (rev 679)
@@ -1,9 +1,11 @@
 package jp.go.aist.rtm.RTC;
 
 import java.util.HashMap;
+import RTC.LifeCycleState;
 
 
 
+
 /**
  * {@.ja 状態マシンクラス。}
  * {@.en State machine class}
@@ -427,7 +429,9 @@
      *
      */
     public StateHolder<STATE> getStates() {
-        return m_states;
+        synchronized (m_states) {
+            return m_states;
+        }
     }
     
     /**
@@ -440,8 +444,10 @@
      *   {@.en Current state}
      *
      */
-    public synchronized STATE getState() {
-        return m_states.curr;
+    public STATE getState() {
+        synchronized (m_states) {
+            return m_states.curr;
+        }
     }
 
     /**
@@ -461,9 +467,11 @@
      *   {@.ja 状態確認結果}
      *   {@.en Check state result}
      */
-    public synchronized boolean isIn(STATE state) {
-        if( m_states.curr == state ) return true;
-        return false;
+    public boolean isIn(STATE state) {
+        synchronized (m_states) {
+            if( m_states.curr == state ) return true;
+            return false;
+        }
     }
 
     /**
@@ -487,8 +495,10 @@
      *   {@.ja 遷移先状態}
      *   {@.en State of the transition destination}
      */
-    public synchronized void goTo(STATE state) {
-        m_states.next = state;
+    public void goTo(STATE state) {
+        synchronized (m_states) {
+            m_states.next = state;
+        }
     }
 
     /**
@@ -597,7 +607,6 @@
 
     public void worker_post() {
         StateHolder state;
-        
         synchronized (m_states) {
             state = new StateHolder(m_states);
         }

Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextBase.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextBase.java	2013-01-31 12:46:19 UTC (rev 678)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextBase.java	2013-01-31 12:54:12 UTC (rev 679)
@@ -232,12 +232,11 @@
      * {@.en This function gets RTC::ExecutionContextProfile.}
      *
      * @return 
-     *   {@.ja RTC.ExecutionContextProfile}
-     *   {@.en RTC.ExecutionContextProfile}
+     *   {@.ja ExecutionContextProfile}
+     *   {@.en ExecutionContextProfile}
      *
      */
     public RTC.ExecutionContextProfile getProfile() ;
-    public boolean finalizeExecutionContext();
     /**
      * {@.ja Propertiesから実行コンテキストをセットする}
      * {@.en Setting execution rate from given properties.}
@@ -247,6 +246,15 @@
      */
     public boolean setExecutionRate(Properties props);
     /**
+     * <p>transitionMode保持用クラスです。</p>
+     */
+    public class transitionModeHolder {
+        public boolean flag;
+        public transitionModeHolder() {
+            flag = false;
+        }
+    }
+    /**
      * {@.ja Propertiesから状態遷移モードをセットする}
      * {@.en Setting state transition mode from given properties.}
      * @param props 
@@ -255,7 +263,7 @@
      * @param key 
      * @param flag 
      */
-    public boolean setTransitionMode(Properties props, String key, boolean flag);
+    public boolean setTransitionMode(Properties props, String key, transitionModeHolder flag);
     /**
      * {@.ja Propertiesから状態遷移Timeoutをセットする}
      * {@.en Setting state transition timeout from given properties.}
@@ -287,7 +295,7 @@
 
     public LifeCycleState onGetComponentState(LifeCycleState state);
     public ExecutionKind onGetKind(ExecutionKind kind);
-    public ExecutionContextProfile onGetProfile(ExecutionContextProfile profile);
+    public RTC.ExecutionContextProfile onGetProfile(RTC.ExecutionContextProfile profile);
 
     /**
      * {@.ja onWaitingActivated() template function}
@@ -306,5 +314,18 @@
      * {@.en onWaitingReset() template function}
      */
     public ReturnCode_t onWaitingReset(RTObjectStateMachine comp, long count);
+    
+    /*! ============================================================
+     * Delegated functions to ExecutionContextWorker
+     *  ============================================================ */
+    public boolean isAllCurrentState(RTC.LifeCycleState state);
+    public boolean isAllNextState(RTC.LifeCycleState state);
+    public boolean isOneOfCurrentState(RTC.LifeCycleState state);
+    public boolean isOneOfNextState(RTC.LifeCycleState state);
+    
+    public void invokeWorker();
+    public void invokeWorkerPreDo();
+    public void invokeWorkerDo();
+    public void invokeWorkerPostDo();
 
 }

Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextWorker.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextWorker.java	2013-01-31 12:46:19 UTC (rev 678)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextWorker.java	2013-01-31 12:54:12 UTC (rev 679)
@@ -5,6 +5,8 @@
 
 import jp.go.aist.rtm.RTC.RTObject_impl;
 import jp.go.aist.rtm.RTC.RTObjectStateMachine;
+import jp.go.aist.rtm.RTC.RTObjectStateMachineHolder;
+import jp.go.aist.rtm.RTC.util.Properties;
 import jp.go.aist.rtm.RTC.util.TimeValue;
 import jp.go.aist.rtm.RTC.log.Logbuf;
 
@@ -178,8 +180,8 @@
      * error if the callback does.}
      *
      * @param comp 
-     *   {@.ja アクティブ化対象RTコンポーネント}
-     *   {@.en The target RT-Component for activation}
+     *   {@.ja アクティブ化対象RTコンポーネントホルダークラス}
+     *   {@.en The target RT-Component holder for activation}
      *
      * @return 
      *   {@.ja ReturnCode_t 型のリターンコード}
@@ -187,25 +189,24 @@
      *
      */
     public ReturnCode_t activateComponent(LightweightRTObject comp,
-                                        RTObjectStateMachine rtobj) {
+            RTObjectStateMachineHolder rtobjhldr) {
         rtcout.println(Logbuf.TRACE, "activateComponent()");
         synchronized (m_mutex){
-            RTObjectStateMachine obj = findComponent(comp);
-            if (obj == null) {
+            rtobjhldr.rtobjsm = findComponent(comp);
+            if (rtobjhldr.rtobjsm == null) {
                 rtcout.println(Logbuf.ERROR, 
                                 "Given RTC is not participant of this EC.");
                 return ReturnCode_t.BAD_PARAMETER;
             }
             rtcout.println(Logbuf.DEBUG, "Component found in the EC.");
-            if (!(obj.isCurrentState(LifeCycleState.INACTIVE_STATE))) {
+            if (!(rtobjhldr.rtobjsm.isCurrentState(LifeCycleState.INACTIVE_STATE))) {
                 rtcout.println(Logbuf.ERROR, 
                                 "State of the RTC is not INACTIVE_STATE.");
                 return ReturnCode_t.PRECONDITION_NOT_MET;
             }
             rtcout.println(Logbuf.DEBUG,
                     "Component is in INACTIVE state. Going to ACTIVE state.");
-            obj.goTo(LifeCycleState.ACTIVE_STATE);
-            rtobj = obj;
+            rtobjhldr.rtobjsm.goTo(LifeCycleState.ACTIVE_STATE);
             rtcout.println(Logbuf.DEBUG,"activateComponent() done.");
             return ReturnCode_t.RTC_OK;
         }
@@ -244,8 +245,8 @@
      * error if the callback does.}
      *
      * @param comp 
-     *   {@.ja 非アクティブ化対象RTコンポーネント}
-     *   {@.en The target RT-Component for deactivate}
+     *   {@.ja 非アクティブ化対象RTコンポーネントホルダー}
+     *   {@.en The target RT-Component holder for deactivate}
      *
      * @return 
      *   {@.ja ReturnCode_t 型のリターンコード}
@@ -253,21 +254,21 @@
      *
      */
     public ReturnCode_t deactivateComponent(LightweightRTObject comp,
-                                          RTObjectStateMachine rtobj){
+                                            RTObjectStateMachineHolder rtobjhldr){
         rtcout.println(Logbuf.TRACE, "deactivateComponent()");
         synchronized (m_mutex){
-            rtobj = findComponent(comp);
-            if (rtobj == null) {
+            rtobjhldr.rtobjsm = findComponent(comp);
+            if (rtobjhldr.rtobjsm == null) {
                 rtcout.println(Logbuf.ERROR, 
                                 "Given RTC is not participant of this EC.");
                 return ReturnCode_t.BAD_PARAMETER;
             }
-            if (!(rtobj.isCurrentState(LifeCycleState.ACTIVE_STATE))) {
+            if (!(rtobjhldr.rtobjsm.isCurrentState(LifeCycleState.ACTIVE_STATE))) {
                 rtcout.println(Logbuf.ERROR, 
                                 "State of the RTC is not ACTIVE_STATE.");
                 return ReturnCode_t.PRECONDITION_NOT_MET;
               }
-            rtobj.goTo(LifeCycleState.INACTIVE_STATE);
+            rtobjhldr.rtobjsm.goTo(LifeCycleState.INACTIVE_STATE);
             return ReturnCode_t.RTC_OK;
         }
     }
@@ -305,8 +306,8 @@
      * may be returned to a valid state.}
      *
      * @param comp 
-     *   {@.ja リセット対象RTコンポーネント}
-     *   {@.en The target RT-Component for reset}
+     *   {@.ja リセット対象RTコンポーネントホルダー}
+     *   {@.en The target RT-Component holder for reset}
      *
      * @return 
      *   {@.ja ReturnCode_t 型のリターンコード}
@@ -314,22 +315,22 @@
      *
      */
     public ReturnCode_t resetComponent(LightweightRTObject comp,
-                                     RTObjectStateMachine rtobj) {
+                                        RTObjectStateMachineHolder rtobjhldr) {
         rtcout.println(Logbuf.TRACE, "resetComponent()");
         synchronized (m_mutex){
 
-            rtobj = findComponent(comp);
-            if (rtobj == null) {
+            rtobjhldr.rtobjsm = findComponent(comp);
+            if (rtobjhldr.rtobjsm == null) {
                 rtcout.println(Logbuf.ERROR, 
                                 "Given RTC is not participant of this EC.");
                 return ReturnCode_t.BAD_PARAMETER;
               }
-            if (!(rtobj.isCurrentState(LifeCycleState.ERROR_STATE))) {
+            if (!(rtobjhldr.rtobjsm.isCurrentState(LifeCycleState.ERROR_STATE))) {
                 rtcout.println(Logbuf.ERROR, 
                                 "State of the RTC is not ERROR_STATE.");
                 return ReturnCode_t.PRECONDITION_NOT_MET;
               }
-            rtobj.goTo(LifeCycleState.INACTIVE_STATE);
+            rtobjhldr.rtobjsm.goTo(LifeCycleState.INACTIVE_STATE);
             return ReturnCode_t.RTC_OK;
         }
     }
@@ -475,9 +476,8 @@
                                 "bindContext returns id = "+id);
     
             // rtc is owner of this EC
-            LightweightRTObject comp
-              = (LightweightRTObject)rtc.getObjRef()._duplicate();
-            //    RTObjectStateMachine o(id, comp);
+            RTC.LightweightRTObject comp
+              = (RTC.LightweightRTObject)rtc.getObjRef()._duplicate();
             m_comps.add(new RTObjectStateMachine(id, comp));
             rtcout.println(Logbuf.DEBUG,"bindComponent() succeeded.");
             return ReturnCode_t.RTC_OK;
@@ -694,13 +694,13 @@
      * {@.ja コンポーネントの参加者リスト}
      * {@.en List of the participating component}
      */
-    protected ArrayList<RTObjectStateMachine> m_comps;
+    protected ArrayList<RTObjectStateMachine> m_comps = new ArrayList<RTObjectStateMachine>();
 //    protected String m_mutex;
     protected String m_mutex = new String();
-    protected ArrayList<RTObjectStateMachine> m_addedComps;
+    protected ArrayList<RTObjectStateMachine> m_addedComps = new ArrayList<RTObjectStateMachine>();
 //    protected String m_addedMutex;
     protected String m_addedMutex = new String();
-    ArrayList<RTObjectStateMachine> m_removedComps;
+    protected ArrayList<RTObjectStateMachine> m_removedComps = new ArrayList<RTObjectStateMachine>();
 //    protected String m_removedMutex;
     protected String m_removedMutex = new String();
 

Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java	2013-01-31 12:46:19 UTC (rev 678)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java	2013-01-31 12:54:12 UTC (rev 679)
@@ -7,9 +7,11 @@
 import jp.go.aist.rtm.RTC.ObjectDestructor;
 import jp.go.aist.rtm.RTC.RTObject_impl;
 import jp.go.aist.rtm.RTC.RTObjectStateMachine;
+import jp.go.aist.rtm.RTC.RTObjectStateMachineHolder;
 import jp.go.aist.rtm.RTC.StateAction;
 import jp.go.aist.rtm.RTC.StateHolder;
 import jp.go.aist.rtm.RTC.StateMachine;
+import jp.go.aist.rtm.RTC.executionContext.ExecutionContextBase.transitionModeHolder;
 import jp.go.aist.rtm.RTC.log.Logbuf;
 import jp.go.aist.rtm.RTC.util.POAUtil;
 import jp.go.aist.rtm.RTC.util.Properties;
@@ -57,10 +59,9 @@
 
         rtcout = new Logbuf("ExtTrigExecutionContext");
         m_svc = false;
-        m_profile.setObjRef((ExecutionContextService)this.__this());
-
-        m_profile.setKind(ExecutionKind.PERIODIC);
-        m_profile.setRate(1000);
+        setObjRef((ExecutionContextService)this.__this());
+        setKind(ExecutionKind.PERIODIC);
+        setRate(1000);
         rtcout.println(Logbuf.DEBUG, "Actual period: " + m_profile.getPeriod().sec() + " [sec], "
                 + m_profile.getPeriod().usec() + " [usec]");
     }
@@ -84,25 +85,6 @@
 
         return this.m_ref;
     }
-    /**
-     * <p>終了処理用関数</p>
-     */
-    public boolean finalizeExecutionContext() {
-        synchronized (m_worker) {
-            //m_worker.running_ = true;
-            m_worker.ticked_ = true ;
-            m_worker.notifyAll();
-        }
-        m_svc = false;
-        try {
-            m_thread.join();
-        }
-        catch   (InterruptedException e) {
-            System.out.println(e);
-        }
-	
-        return true;
-    }
 
     /**
      * {@.ja ExecutionContextの処理を進める}
@@ -114,13 +96,15 @@
      *
      */
     public void tick() throws SystemException {
-
         rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.tick()");
-
-        synchronized (m_worker) {
-            m_worker.ticked_ = true;
-            m_worker.notifyAll();
+        if (!isRunning()) {
+            rtcout.println(Logbuf.DEBUG, "EC is not running. do nothing.");
+            return;
         }
+        synchronized (m_workerthread.mutex_) {
+            m_workerthread.ticked_ = true;
+            m_workerthread.mutex_.notifyAll();
+        }
     }
 
     /**
@@ -141,35 +125,32 @@
      * 全Componentの処理を呼び出した後、次のイベントが発生するまで休止します。</p>
      */
     public int svc() {
-        int count = 0 ;
         rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.svc()");
         do {
 
-            synchronized (m_worker) {
-                rtcout.println(Logbuf.DEBUG, "Start of worker invocation. ticked = "+ (m_worker.ticked_ ? "true" : "false"));
-                while (!m_worker.ticked_) {
+            synchronized (m_workerthread.mutex_) {
+                rtcout.println(Logbuf.DEBUG, "Start of worker invocation. ticked = "+ (m_workerthread.ticked_ ? "true" : "false"));
+                while (!m_workerthread.ticked_) {
                     try {
-                        m_worker.wait();
+                        m_workerthread.mutex_.wait();
                         rtcout.println(Logbuf.DEBUG, "Thread was woken up.");
                     } catch (InterruptedException e) {
                         break;
                     }
                 }
-                if(!m_worker.ticked_){continue;}
+                if(!m_workerthread.ticked_){continue;}
             }
             TimeValue t0 = new TimeValue();
-            t0.convert(System.nanoTime()/1000);
+            t0.convert(System.nanoTime()/1000000000.0);
             m_worker.invokeWorkerPreDo();
             m_worker.invokeWorkerDo();
             m_worker.invokeWorkerPostDo();
             TimeValue t1 = new TimeValue();
-            t1.convert(System.nanoTime()/1000);
-            synchronized (m_worker) {
-                m_worker.ticked_ = false ;
+            t1.convert(System.nanoTime()/1000000000.0);
+            synchronized (m_workerthread.mutex_) {
+                m_workerthread.ticked_ = false ;
             }
             TimeValue period = getPeriod();
-            TimeValue t2 = new TimeValue();
-            t2.convert(System.nanoTime()/1000);
             if(true){
                 TimeValue t1_w = t1;
                 TimeValue period_w = period ;
@@ -177,28 +158,23 @@
                 rtcout.println(Logbuf.PARANOID, "Execution: " + t1_w.minus(t0) + " [s]");
                 rtcout.println(Logbuf.PARANOID, "Sleep:     " + period_w.minus(t1_w) + " [s]");
             }
-            if( period.getUsec() > 0)
+            TimeValue t1_d = t1;
+            t1_d = t1_d.minus(t0);
+            if( period.toDouble() > t1_d.toDouble())
             {
                 if(true)
                 {
                     rtcout.println(Logbuf.PARANOID, "sleeping...");
                 }
                 try {
-                    Thread.sleep(period.getUsec());
+                    period = period.minus(t1_d);
+                    Thread.sleep((int)(period.toDouble() * 1000),(int)(period.toDouble() * 1000000000));
                 } catch (InterruptedException e){
                     e.printStackTrace();
                 }
             }
-            TimeValue t3 = new TimeValue();
-            t3.convert(System.nanoTime()/1000);
-            if(true)
-            {
-                rtcout.println(Logbuf.PARANOID, "Slept:     " + t3.minus(t2) + " [s]");
-                count = 0;
-            }
-            ++count;
             
-        } while (m_running);
+        } while (threadRunning());
         
         return 0;
     }
@@ -232,7 +208,10 @@
      *
      */
     public boolean is_running() {
-        rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.is_running()");
+        return isRunning();
+    }
+    public boolean isRunning() {
+        rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.isRunning()");
         return m_worker.isRunning();
     }
 
@@ -247,7 +226,7 @@
     public ReturnCode_t onStarted()
     {
       // change EC thread state
-        synchronized (m_worker) {
+        synchronized (m_svcmutex) {
             if (!m_svc)
             { // If start() is called first time, start the worker thread.
                 m_svc = true;
@@ -314,6 +293,12 @@
     {
         return ReturnCode_t.RTC_OK;
     }
+    public boolean threadRunning()
+    {
+        synchronized(m_svcmutex) {
+            return m_svc;
+        }
+    }
     public ReturnCode_t onReset(RTObjectStateMachine comp, long count)
     {
         return ReturnCode_t.RTC_OK;
@@ -327,7 +312,7 @@
     {
         return kind;
     }
-    public ExecutionContextProfile onGetProfile(ExecutionContextProfile profile)
+    public RTC.ExecutionContextProfile onGetProfile(RTC.ExecutionContextProfile profile)
     {
         return profile;
     }
@@ -344,8 +329,9 @@
 //                 "curr: " + comp.getStatus() +", next: " + comp.getStatus());
       // Now comp's next state must be ACTIVE state
       // If worker thread is stopped, restart worker thread.
-        synchronized (m_worker) {
-            m_worker.notifyAll();
+        synchronized (m_workerthread.mutex_) {
+            m_workerthread.ticked_ = true;
+            m_workerthread.mutex_.notifyAll();
             return ReturnCode_t.RTC_OK;
         }
     }
@@ -358,8 +344,8 @@
     {
         rtcout.println(Logbuf.TRACE, 
                 "ExtTrigExecutionContext.onWaitingDeactivated(count = " + count +")");
-        synchronized (m_worker) {
-            m_worker.notifyAll();
+        synchronized (m_workerthread.mutex_) {
+            m_workerthread.mutex_.notifyAll();
             return ReturnCode_t.RTC_OK;
         }
     }
@@ -371,8 +357,8 @@
     {
         rtcout.println(Logbuf.TRACE, 
               "ExtTrigExecutionContext.onWaitingReset(count = " + count +")");
-        synchronized (m_worker) {
-            m_worker.notifyAll();
+        synchronized (m_workerthread.mutex_) {
+            m_workerthread.mutex_.notifyAll();
             return ReturnCode_t.RTC_OK;
         }
     }
@@ -547,12 +533,14 @@
             rtcout.println(Logbuf.ERROR,"onActivating() failed.");
             return ret;
         }
-        RTObjectStateMachine rtobj = null;
-        ret = m_worker.activateComponent(comp, rtobj); // Actual activateComponent()
+
+        RTObjectStateMachineHolder rtobjhldr = new RTObjectStateMachineHolder();
+        ret = m_worker.activateComponent(comp, rtobjhldr); // Actual activateComponent()
+
         if (ret != ReturnCode_t.RTC_OK) { return ret; }
         if (!m_syncActivation) // Asynchronous activation mode
         {
-            ret = onActivated(rtobj, -1);
+            ret = onActivated(rtobjhldr.rtobjsm, -1);
             if (ret != ReturnCode_t.RTC_OK)
             {
                 rtcout.println(Logbuf.ERROR,"onActivated() failed.");
@@ -563,7 +551,7 @@
         // Synchronized activation mode
         rtcout.println(Logbuf.DEBUG,"Synchronous activation mode. "
                    +"Waiting for the RTC to be ACTIVE state. ");
-        return waitForActivated(rtobj);
+        return waitForActivated(rtobjhldr.rtobjsm);
     }
 
     public ReturnCode_t waitForActivated(RTObjectStateMachine rtobj)
@@ -578,9 +566,9 @@
         long cycle =
             (long )(m_activationTimeout.toDouble() / getPeriod().toDouble());
         rtcout.println(Logbuf.DEBUG,"Timeout is "+ m_activationTimeout.toDouble() + "[s] ("+ getRate() + "[s] in "+ cycle + " times");
-        // Wating INACTIVE -> ACTIVE
+                // Wating INACTIVE -> ACTIVE
         TimeValue starttime = new TimeValue();
-        starttime.convert(System.nanoTime()/1000);
+        starttime.convert(System.nanoTime()/1000000000.0);
         while (rtobj.isCurrentState(LifeCycleState.INACTIVE_STATE))
         {
             ret = onWaitingActivated(rtobj, count); // Template method
@@ -591,14 +579,14 @@
             }
             try
             {
-                Thread.sleep(getPeriod().getUsec());
+                Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000));
             }catch(InterruptedException e){}
             TimeValue delta= new TimeValue();
-            delta.convert(System.nanoTime()/1000);
-            delta.minus(starttime);
+            delta.convert(System.nanoTime()/1000000000.0);
+            delta = delta.minus(starttime);
             rtcout.println(Logbuf.DEBUG,"Waiting to be ACTIVE state. " + delta + " [s] slept (" + count +"/" + cycle);
             ++count;
-            if (delta.getUsec() > m_activationTimeout.getUsec() || count > cycle)
+            if (delta.toDouble() > m_activationTimeout.toDouble() || count > cycle)
             {
                 rtcout.println(Logbuf.WARN,"The component is not responding.");
                 break;
@@ -644,12 +632,12 @@
             return ret;
         }
         // Deactivate all the RTCs
-        RTObjectStateMachine rtobj = null;
-        ret = m_worker.deactivateComponent(comp, rtobj);
+        RTObjectStateMachineHolder rtobjhldr = new RTObjectStateMachineHolder();
+        ret = m_worker.deactivateComponent(comp, rtobjhldr);
         if (ret != ReturnCode_t.RTC_OK) { return ret; }
         if (!m_syncDeactivation)
         {
-            ret = onDeactivated(rtobj, -1);
+            ret = onDeactivated(rtobjhldr.rtobjsm, -1);
             if (ret != ReturnCode_t.RTC_OK)
             {
                 rtcout.println(Logbuf.ERROR,"onDeactivated() failed.");
@@ -660,7 +648,7 @@
         // Waiting for synchronized deactivation
         rtcout.println(Logbuf.DEBUG,"Synchronous deactivation mode. "
                  +"Waiting for the RTC to be INACTIVE state. ");
-        return waitForDeactivated(rtobj);
+        return waitForDeactivated(rtobjhldr.rtobjsm);
     }
     public ReturnCode_t waitForDeactivated(RTObjectStateMachine rtobj)
     {
@@ -676,7 +664,7 @@
         rtcout.println(Logbuf.DEBUG,"Timeout is "+ m_deactivationTimeout.toDouble() + "[s] ("+ getRate() + "[s] in "+ cycle + " times");
         // Wating ACTIVE -> INACTIVE
         TimeValue starttime = new TimeValue();
-        starttime.convert(System.nanoTime()/1000);
+        starttime.convert(System.nanoTime()/1000000000.0);
         while (rtobj.isCurrentState(LifeCycleState.ACTIVE_STATE))
         {
             ret = onWaitingDeactivated(rtobj, count); // Template method
@@ -687,14 +675,14 @@
             }
             try
             {
-                Thread.sleep(getPeriod().getUsec());
+                Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000));
             }catch(InterruptedException e){}
             TimeValue delta = new TimeValue();
-            delta.convert(System.nanoTime()/1000);
-            delta.minus(starttime);
+            delta.convert(System.nanoTime()/1000000000.0);
+            delta = delta.minus(starttime);
             rtcout.println(Logbuf.DEBUG,"Waiting to be INACTIVE state. Sleeping " + delta + " [s] (" + count +"/" + cycle);
             ++count;
-            if (delta.getUsec() > m_activationTimeout.getUsec() || count > cycle)
+            if (delta.toDouble() > m_activationTimeout.toDouble() || count > cycle)
             {
                 rtcout.println(Logbuf.WARN,"The component is not responding.");
                 break;
@@ -739,12 +727,12 @@
             rtcout.println(Logbuf.ERROR,"onResetting() failed.");
             return ret;
         }
-        RTObjectStateMachine rtobj = null;
-        ret = m_worker.resetComponent(comp, rtobj); // Actual resetComponent()
+        RTObjectStateMachineHolder rtobjhldr = new RTObjectStateMachineHolder();
+        ret = m_worker.resetComponent(comp, rtobjhldr); // Actual resetComponent()
         if (ret != ReturnCode_t.RTC_OK) { return ret; }
         if (!m_syncReset)
         {
-            ret = onReset(rtobj, -1);
+            ret = onReset(rtobjhldr.rtobjsm, -1);
             if (ret != ReturnCode_t.RTC_OK)
             {
                 rtcout.println(Logbuf.ERROR,"onReset() failed.");
@@ -755,7 +743,7 @@
         // Waiting for synchronized reset
         rtcout.println(Logbuf.DEBUG,"Synchronous reset mode. "
                    +"Waiting for the RTC to be INACTIVE state. ");
-        return waitForReset(rtobj);
+        return waitForReset(rtobjhldr.rtobjsm);
     }
     public ReturnCode_t waitForReset(RTObjectStateMachine rtobj)
     {
@@ -771,7 +759,7 @@
         rtcout.println(Logbuf.DEBUG,"Timeout is "+ m_resetTimeout.toDouble() + "[s] ("+ getRate() + "[s] in "+ cycle + " times");
         // Wating ERROR -> INACTIVE
         TimeValue starttime = new TimeValue();
-        starttime.convert(System.nanoTime()/1000);
+        starttime.convert(System.nanoTime()/1000000000.0);
         while (rtobj.isCurrentState(LifeCycleState.ERROR_STATE))
         {
             ret = onWaitingReset(rtobj, count); // Template method
@@ -782,14 +770,14 @@
             }
             try
             {
-                Thread.sleep(getPeriod().getUsec());
+                Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000));
             }catch(InterruptedException e){}
             TimeValue delta = new TimeValue();
-            delta.convert(System.nanoTime()/1000);
-            delta.minus(starttime);
+            delta.convert(System.nanoTime()/1000000000.0);
+            delta = delta.minus(starttime);
             rtcout.println(Logbuf.DEBUG,"Waiting to be INACTIVE state. Sleeping " + delta + " [s] (" + count +"/" + cycle);
             ++count;
-            if (delta.getUsec() > m_resetTimeout.getUsec() || count > cycle)
+            if (delta.toDouble() > m_resetTimeout.toDouble() || count > cycle)
             {
                 rtcout.println(Logbuf.WARN,"The component is not responding.");
                 break;
@@ -1393,18 +1381,22 @@
      * <p>ExecutionContext のスレッド実行フラグです。</p>
      */
     private boolean m_svc;
+    private String m_svcmutex = new String();
 
-    private class Worker {
-        
-        public Worker() {
-            this._called = false;
+    /**
+     * <p>Worke用状態変数クラスです。</p>
+     */
+    private class WorkerThreadCtrl {
+        private String mutex_ = new String();
+        private boolean ticked_; 
+        public WorkerThreadCtrl() {
+            ticked_ = false;
         }
-
-        public boolean _called;
     }
     
-//    private Worker m_worker = new Worker();
-    private ExecutionContextWorker m_worker = new ExecutionContextWorker();
+    // A condition variable for external triggered worker
+    private WorkerThreadCtrl m_workerthread = new WorkerThreadCtrl();
+    protected ExecutionContextWorker m_worker = new ExecutionContextWorker();
 
     /**
      * <p>ExecutionContextProfileです。</p>
@@ -1494,17 +1486,20 @@
         // getting rate
         setExecutionRate(props);
         // getting sync/async mode flag
-        boolean transitionMode=true;
+        transitionModeHolder transitionMode = new transitionModeHolder();
         if(setTransitionMode(props, "sync_transition", transitionMode))
         {
-            m_syncActivation = transitionMode;
-            m_syncDeactivation = transitionMode;
-            m_syncReset = transitionMode;
+            m_syncActivation = transitionMode.flag;
+            m_syncDeactivation = transitionMode.flag;
+            m_syncReset = transitionMode.flag;
             
         }
-        setTransitionMode(props, "sync_activation", m_syncActivation);
-        setTransitionMode(props, "sync_deactivation", m_syncDeactivation);
-        setTransitionMode(props, "sync_reset", m_syncReset);
+        setTransitionMode(props, "sync_activation", transitionMode);
+        m_syncActivation = transitionMode.flag;
+        setTransitionMode(props, "sync_deactivation", transitionMode);
+        m_syncDeactivation = transitionMode.flag;
+        setTransitionMode(props, "sync_reset", transitionMode);
+        m_syncReset = transitionMode.flag;
         // getting transition timeout
         TimeValue timeout = new TimeValue(0.0);
         if (setTimeout(props, "transition_timeout", timeout))
@@ -1542,7 +1537,9 @@
      *
      */
     public void setObjRef(final ExecutionContextService ref) {
+        m_worker.setECRef(ref);
         m_profile.setObjRef(ref);
+        m_ref = ref;
     }
     /**
      * {@.ja CORBA オブジェクト参照の取得}
@@ -1790,17 +1787,44 @@
      * @brief Setting state transition timeout from given properties.
      * @endif
      */
-    public boolean setTransitionMode(Properties props, String key, boolean flag)
+    public boolean setTransitionMode(Properties props, String key, transitionModeHolder tmhldr)
     {
         rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.setTransitionMode(" + key +")");
         if (props.findNode(key) != null)
         {
-            flag = props.getNode(key).getValue() == "YES";
-            rtcout.println(Logbuf.DEBUG, "Transition Mode: " + key +" = " + ( flag ? "YES" : "NO"));
+            tmhldr.flag = props.getNode(key).getValue() == "YES";
+            rtcout.println(Logbuf.DEBUG, "Transition Mode: " + key +" = " + ( tmhldr.flag ? "YES" : "NO"));
             return true;
        }
         rtcout.println(Logbuf.DEBUG, "Configuration " + key +" not found.");
         return false;
     }
 
+    /*! ============================================================
+     * Delegated functions to ExecutionContextWorker
+     *  ============================================================ */
+    public boolean isAllCurrentState(RTC.LifeCycleState state)
+    {
+      return m_worker.isAllCurrentState(state);
+    }
+    
+    public boolean isAllNextState(RTC.LifeCycleState state)
+    {
+      return m_worker.isAllNextState(state);
+    }
+    
+    public boolean isOneOfCurrentState(RTC.LifeCycleState state)
+    {
+      return m_worker.isOneOfCurrentState(state);
+    }
+    
+    public boolean isOneOfNextState(RTC.LifeCycleState state)
+    {
+      return m_worker.isOneOfNextState(state);
+    }
+    
+    public void invokeWorker() { m_worker.invokeWorker(); }
+    public void invokeWorkerPreDo()   { m_worker.invokeWorkerPreDo(); }
+    public void invokeWorkerDo()      { m_worker.invokeWorkerDo(); }
+    public void invokeWorkerPostDo()  { m_worker.invokeWorkerPostDo(); }
 }

Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/IExecutionContextBase.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/IExecutionContextBase.java	2013-01-31 12:46:19 UTC (rev 678)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/IExecutionContextBase.java	2013-01-31 12:54:12 UTC (rev 679)
@@ -33,7 +33,6 @@
      */
     public ReturnCode_t bindComponent(RTObject_impl rtc);
 
-    public boolean finalizeExecutionContext();
 /*
     public ExecutionContextProfile m_profile 
                                     = new jp.go.aist.rtm.RTC.executionContext.ExecutionContextProfile();

Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java	2013-01-31 12:46:19 UTC (rev 678)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java	2013-01-31 12:54:12 UTC (rev 679)
@@ -1,11 +1,13 @@
 package jp.go.aist.rtm.RTC.executionContext;
 
+import java.util.ArrayList;
 import java.util.Vector;
 
 import jp.go.aist.rtm.RTC.Manager;
 import jp.go.aist.rtm.RTC.ObjectCreator;
 import jp.go.aist.rtm.RTC.ObjectDestructor;
 import jp.go.aist.rtm.RTC.RTObjectStateMachine;
+import jp.go.aist.rtm.RTC.RTObjectStateMachineHolder;
 import jp.go.aist.rtm.RTC.RTObject_impl;
 import jp.go.aist.rtm.RTC.StateAction;
 import jp.go.aist.rtm.RTC.StateHolder;
@@ -65,28 +67,13 @@
         rtcout = new Logbuf("PeriodicExecutionContext");
         m_svc = false;
         m_nowait = false;
-        m_profile.setObjRef((ExecutionContextService)this.__this());
-
-        m_profile.setKind(ExecutionKind.PERIODIC);
-        m_profile.setRate(1000);
+        setObjRef((ExecutionContextService)this.__this());
+        setKind(ExecutionKind.PERIODIC);
+        setRate(1000);
         rtcout.println(Logbuf.DEBUG, "Actual period: " + m_profile.getPeriod().sec() + " [sec], "
                 + m_profile.getPeriod().usec() + " [usec]");
     }
 
-    /**
-     * <p>終了処理用関数</p>
-     */
-    public boolean finalizeExecutionContext() {
-        synchronized (m_svcmutex) {
-            m_svc = false;
-        }
-        synchronized (mutex_) {
-            m_workerthread.running_ = true;
-            mutex_.notifyAll();
-        }
-  
-        return true;
-    }
 
     /**
      * <p> __this() </p>
@@ -116,8 +103,9 @@
     public void setObjRef(final ExecutionContextService ref) {
 
         rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.setObjRef()");
-
-        m_ref = ref;
+        m_worker.setECRef(ref);
+        m_profile.setObjRef(ref);
+		m_ref = ref;
     }
 
     /**
@@ -154,54 +142,48 @@
         rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.svc()");
 
         do {
-
-            m_workerthread.invokeWorkerPreDo();
-            synchronized (mutex_) {
+            invokeWorkerPreDo();
+            synchronized (m_workerthread.mutex_) {
                 while (!m_workerthread.running_) {
                     try {
-                        mutex_.wait();
+                        m_workerthread.mutex_.wait();
                     } catch (InterruptedException e) {
                         break;
                     }
                 }
             }
             TimeValue t0 = new TimeValue();
-            t0.convert(System.nanoTime()/1000);
-            m_workerthread.invokeWorkerDo();
-            m_workerthread.invokeWorkerPostDo();
+            t0.convert(System.nanoTime()/1000000000.0);
+            invokeWorkerDo();
+            invokeWorkerPostDo();
             TimeValue t1 = new TimeValue();
-            t1.convert(System.nanoTime()/1000);
-
+            t1.convert(System.nanoTime()/1000000000.0);
             TimeValue period = getPeriod();
-            if(true){
-                rtcout.println(Logbuf.PARANOID, "Period:    " + period + " [s]");
-                rtcout.println(Logbuf.PARANOID, "Execution: " + t1.minus(t0) + " [s]");
-                rtcout.println(Logbuf.PARANOID, "Sleep:     " + period.minus(t1) + " [s]");
+            if(count > 1000){
+                TimeValue t1_w = t1;
+                TimeValue period_w = period;
+                rtcout.println(Logbuf.PARANOID, "Period:    " + period.getSec() + " [s]");
+                rtcout.println(Logbuf.PARANOID, "Execution: " + t1_w.minus(t0).getSec() + " [s]");
+                rtcout.println(Logbuf.PARANOID, "Sleep:     " + period_w.minus(t1_w).getSec() + " [s]");
             }
-            TimeValue t2 = new TimeValue();
-            t2.convert(System.nanoTime()/1000);
-            if( !m_nowait && period.getUsec() > 0)
+            TimeValue delta = t1.minus(t0);
+            if( !m_nowait && period.toDouble() > delta.toDouble())
             {
                 if(count > 1000)
                 {
                     rtcout.println(Logbuf.PARANOID, "sleeping...");
+                    count = 0;
                 }
                 try {
-                    Thread.sleep(period.getUsec());
+                    delta = period.minus(delta);
+                    Thread.sleep((int)(delta.toDouble()*1000),(int)(delta.toDouble()*1000000000)); // sec -> millisec, sec -> nanosec
                 } catch (InterruptedException e){
                     e.printStackTrace();
                 }
             }
-            if(true)
-            {
-                TimeValue t3 = new TimeValue();
-                t3.convert(System.nanoTime()/1000);
-                rtcout.println(Logbuf.PARANOID, "Slept:     " + t3.minus(t2) + " [s]");
-                count = 0;
-            }
             ++count;
             
-        } while (m_running);
+        } while (threadRunning());
         
         return 0;
     }
@@ -238,11 +220,16 @@
      * @return 実行判定結果
      */
     public boolean is_running() {
+        return isRunning();
+    }
+    public boolean isRunning() {
 
-        rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.is_running()");
+        rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.isRunning()");
 
-        return m_workerthread.isRunning();
+        return m_worker.isRunning();
     }
+    public boolean onIsRunning(boolean running) { return running; }
+
     public ReturnCode_t onStarting() { return ReturnCode_t.RTC_OK; }
 
     //============================================================
@@ -261,25 +248,25 @@
                 this.open();
             }
         }
-        if(m_workerthread.isAllNextState(LifeCycleState.INACTIVE_STATE))
+        if(isAllNextState(LifeCycleState.INACTIVE_STATE))
         {
-            synchronized(mutex_)
+            synchronized(m_workerthread.mutex_)
             {
                 m_workerthread.running_ = false ;
             }
         }
         else
         {
-            synchronized (mutex_) {
+            synchronized (m_workerthread.mutex_) {
                 m_workerthread.running_ = true ;
-                mutex_.notifyAll();
+                m_workerthread.mutex_.notifyAll();
             }
         }
         return ReturnCode_t.RTC_OK;
     }
     public ReturnCode_t onStopping()
     {
-        synchronized (mutex_) {
+        synchronized (m_workerthread.mutex_) {
             m_workerthread.running_ = false ;
             return ReturnCode_t.RTC_OK;
         }
@@ -320,8 +307,17 @@
     // template virtual functions related to activation/deactivation/reset
     public ReturnCode_t onActivating(LightweightRTObject comp)
     {
-        return ReturnCode_t.RTC_OK;
+        synchronized (m_workerthread.mutex_) {
+            if(m_workerthread.running_ == false)
+            {
+                m_workerthread.running_ = true ;
+                m_workerthread.mutex_.notifyAll();
+            }
+            return ReturnCode_t.RTC_OK;
+        }
+//        return ReturnCode_t.RTC_OK;
     }
+
     public ReturnCode_t onActivated(RTObjectStateMachine comp, long count)
     {
         rtcout.println(Logbuf.TRACE, 
@@ -330,11 +326,11 @@
 //                         "curr: " + comp.getStatus() +", next: " + comp.getStatus());
         // Now comp's next state must be ACTIVE state
         // If worker thread is stopped, restart worker thread.
-        synchronized (mutex_) {
+        synchronized (m_workerthread.mutex_) {
             if(m_workerthread.running_ == false)
             {
                 m_workerthread.running_ = true ;
-                mutex_.notifyAll();
+                m_workerthread.mutex_.notifyAll();
             }
             return ReturnCode_t.RTC_OK;
         }
@@ -351,9 +347,9 @@
 //                         "curr: " + comp.getStatus() +", next: " + comp.getStatus());
         // Now comp's next state must be ACTIVE state
         // If worker thread is stopped, restart worker thread.
-        if(m_workerthread.isAllCurrentState(LifeCycleState.INACTIVE_STATE))
+        if(isAllCurrentState(LifeCycleState.INACTIVE_STATE))
         {
-            synchronized (mutex_) {
+            synchronized (m_workerthread.mutex_) {
                 if(m_workerthread.running_ == true)
                 {
                     m_workerthread.running_ = false ;
@@ -375,9 +371,9 @@
 //                         "curr: " + comp.getStatus() +", next: " + comp.getStatus());
         // Now comp's next state must be ACTIVE state
         // If worker thread is stopped, restart worker thread.
-        if(m_workerthread.isAllCurrentState(LifeCycleState.INACTIVE_STATE))
+        if(isAllCurrentState(LifeCycleState.INACTIVE_STATE))
         {
-            synchronized (mutex_) {
+            synchronized (m_workerthread.mutex_) {
                 if(m_workerthread.running_ == true)
                 {
                     m_workerthread.running_ = false ;
@@ -388,6 +384,13 @@
         return ReturnCode_t.RTC_OK;
     }
 
+    public boolean threadRunning()
+    {
+        synchronized(m_svcmutex) {
+            return m_svc;
+        }
+    }
+    
     public LifeCycleState onGetComponentState(LifeCycleState state)
     {
         return state;
@@ -396,7 +399,7 @@
     {
         return kind;
     }
-    public ExecutionContextProfile onGetProfile(ExecutionContextProfile profile)
+    public RTC.ExecutionContextProfile onGetProfile(RTC.ExecutionContextProfile profile)
     {
         return profile;
     }
@@ -413,11 +416,11 @@
 //                 "curr: " + comp.getStatus() +", next: " + comp.getStatus());
       // Now comp's next state must be ACTIVE state
       // If worker thread is stopped, restart worker thread.
-        synchronized (mutex_) {
+        synchronized (m_workerthread.mutex_) {
             if(m_workerthread.running_ == false)
             {
                 m_workerthread.running_ = true ;
-                mutex_.notifyAll();
+                m_workerthread.mutex_.notifyAll();
             }
             return ReturnCode_t.RTC_OK;
         }
@@ -431,9 +434,9 @@
     {
         rtcout.println(Logbuf.TRACE, 
                 "PeriodicExecutionContext.onWaitingDeactivated(count = " + count +")");
-        if(m_workerthread.isAllNextState(LifeCycleState.INACTIVE_STATE))
+        if(isAllNextState(LifeCycleState.INACTIVE_STATE))
         {
-            synchronized (mutex_) {
+            synchronized (m_workerthread.mutex_) {
                 if(m_workerthread.running_ == true)
                 {
                     m_workerthread.running_ = false ;
@@ -451,9 +454,9 @@
     {
         rtcout.println(Logbuf.TRACE, 
                 "PeriodicExecutionContext.onWaitingReset(count = " + count +")");
-        if(m_workerthread.isAllNextState(LifeCycleState.INACTIVE_STATE))
+        if(isAllNextState(LifeCycleState.INACTIVE_STATE))
         {
-            synchronized (mutex_) {
+            synchronized (m_workerthread.mutex_) {
                 if(m_workerthread.running_ == true)
                 {
                     m_workerthread.running_ = false ;
@@ -479,7 +482,7 @@
             rtcout.println(Logbuf.ERROR, "onStarting() failed. Starting EC aborted.");
             return ret;
         }
-        ret = m_workerthread.start();
+        ret = m_worker.start();
         if(ret!=ReturnCode_t.RTC_OK)
         {
             rtcout.println(Logbuf.ERROR, "Invoking on_startup() for each RTC failed.");
@@ -489,7 +492,7 @@
         if(ret!=ReturnCode_t.RTC_OK)
         {
             rtcout.println(Logbuf.ERROR, "Invoking on_startup() for each RTC failed.");
-            m_workerthread.stop();
+            m_worker.stop();
             rtcout.println(Logbuf.ERROR, "on_shutdown() was invoked, because of on_startup");
             return ret;
         }
@@ -511,7 +514,7 @@
             rtcout.println(Logbuf.ERROR, "onStopping() failed. Stopping EC aborted.");
             return ret;
         }
-        ret = m_workerthread.stop(); // Actual stop()
+        ret = m_worker.stop(); // Actual stop()
         if (ret != ReturnCode_t.RTC_OK)
         {
             rtcout.println(Logbuf.ERROR, "Invoking on_shutdown() for each RTC failed.");
@@ -534,8 +537,8 @@
     public double get_rate() {
 
         rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.get_rate()");
-
-        return m_profile.getRate();
+        double rate = m_profile.getRate();
+        return onGetRate(rate);
     }
     public TimeValue getPeriod()
     {
@@ -585,19 +588,20 @@
     public ReturnCode_t activateComponent(LightweightRTObject comp) {
 
         rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.activateComponent()");
-
         ReturnCode_t ret = onActivating(comp); // Template
         if (ret != ReturnCode_t.RTC_OK)
         {
             rtcout.println(Logbuf.ERROR,"onActivating() failed.");
             return ret;
         }
-        RTObjectStateMachine rtobj = null;
-        ret = m_workerthread.activateComponent(comp, rtobj); // Actual activateComponent()
+
+        RTObjectStateMachineHolder rtobjhldr = new RTObjectStateMachineHolder();
+        ret = m_worker.activateComponent(comp, rtobjhldr); // Actual activateComponent()
+        RTObjectStateMachine rtobj = rtobjhldr.rtobjsm;
         if (ret != ReturnCode_t.RTC_OK) { return ret; }
         if (!m_syncActivation) // Asynchronous activation mode
         {
-            ret = onActivated(rtobj, -1);
+            ret = onActivated(rtobjhldr.rtobjsm, -1);
             if (ret != ReturnCode_t.RTC_OK)
             {
                 rtcout.println(Logbuf.ERROR,"onActivated() failed.");
@@ -608,7 +612,7 @@
         // Synchronized activation mode
         rtcout.println(Logbuf.DEBUG,"Synchronous activation mode. "
                    +"Waiting for the RTC to be ACTIVE state. ");
-        return waitForActivated(rtobj);
+        return waitForActivated(rtobjhldr.rtobjsm);
     }
     public ReturnCode_t waitForActivated(RTObjectStateMachine rtobj)
     {
@@ -624,7 +628,7 @@
         rtcout.println(Logbuf.DEBUG,"Timeout is "+ m_activationTimeout.toDouble() + "[s] ("+ getRate() + "[s] in "+ cycle + " times");
         // Wating INACTIVE -> ACTIVE
         TimeValue starttime = new TimeValue();
-        starttime.convert(System.nanoTime()/1000);
+        starttime.convert(System.nanoTime()/1000000000);
         while (rtobj.isCurrentState(LifeCycleState.INACTIVE_STATE))
         {
             ret = onWaitingActivated(rtobj, count); // Template method
@@ -635,14 +639,14 @@
             }
             try
             {
-                Thread.sleep(getPeriod().getUsec());
+                Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000)); // sec -> millisec, sec -> nanosec
             }catch(InterruptedException e){}
             TimeValue delta= new TimeValue();
-            delta.convert(System.nanoTime()/1000);
-            delta.minus(starttime);
+            delta.convert(System.nanoTime()/1000000000);
+            delta = delta.minus(starttime);
             rtcout.println(Logbuf.DEBUG,"Waiting to be ACTIVE state. " + delta + " [s] slept (" + count +"/" + cycle);
             ++count;
-            if (delta.getUsec() > m_activationTimeout.getUsec() || count > cycle)
+            if (delta.toDouble() > m_activationTimeout.toDouble() || count > cycle)
             {
                 rtcout.println(Logbuf.WARN,"The component is not responding.");
                 break;
@@ -686,8 +690,9 @@
             return ret;
         }
         // Deactivate all the RTCs
-        RTObjectStateMachine rtobj = null;
-        ret = m_workerthread.deactivateComponent(comp, rtobj);
+        RTObjectStateMachineHolder rtobjhldr = new RTObjectStateMachineHolder();
+        ret = m_worker.deactivateComponent(comp, rtobjhldr);
+        RTObjectStateMachine rtobj = rtobjhldr.rtobjsm;
         if (ret != ReturnCode_t.RTC_OK) { return ret; }
         if (!m_syncDeactivation)
         {
@@ -729,14 +734,14 @@
             }
             try
             {
-                Thread.sleep(getPeriod().getUsec());
+                Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000)); // sec -> millisec, sec -> nanosec
             }catch(InterruptedException e){}
             TimeValue delta = new TimeValue();
             delta.convert(System.nanoTime()/1000);
-            delta.minus(starttime);
+            delta = delta.minus(starttime);
             rtcout.println(Logbuf.DEBUG,"Waiting to be INACTIVE state. Sleeping " + delta + " [s] (" + count +"/" + cycle);
             ++count;
-            if (delta.getUsec() > m_activationTimeout.getUsec() || count > cycle)
+            if (delta.toDouble() > m_activationTimeout.toDouble() || count > cycle)
             {
                 rtcout.println(Logbuf.WARN,"The component is not responding.");
                 break;
@@ -768,9 +773,9 @@
     public ReturnCode_t reset_component(LightweightRTObject comp){
 
         rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.reset_component()");
-        return reset_component(comp);
+        return resetComponent(comp);
     }
-    public ReturnCode_t resetCcomponent(LightweightRTObject comp){
+    public ReturnCode_t resetComponent(LightweightRTObject comp){
 
         rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.resetComponent()");
 
@@ -780,8 +785,9 @@
             rtcout.println(Logbuf.ERROR,"onResetting() failed.");
             return ret;
         }
-        RTObjectStateMachine rtobj = null;
-        ret = m_workerthread.resetComponent(comp, rtobj); // Actual resetComponent()
+        RTObjectStateMachineHolder rtobjhldr = new RTObjectStateMachineHolder();
+        ret = m_worker.resetComponent(comp, rtobjhldr); // Actual resetComponent()
+        RTObjectStateMachine rtobj = rtobjhldr.rtobjsm;
         if (ret != ReturnCode_t.RTC_OK) { return ret; }
         if (!m_syncReset)
         {
@@ -823,21 +829,21 @@
             }
             try
             {
-                Thread.sleep(getPeriod().getUsec());
+                Thread.sleep((int)(getPeriod().toDouble()*1000),(int)(getPeriod().toDouble()*1000000000));  // sec -> millisec, sec -> nanosec
             }catch(InterruptedException e){}
             TimeValue delta = new TimeValue();
             delta.convert(System.nanoTime()/1000);
-            delta.minus(starttime);
+            delta = delta.minus(starttime);
             rtcout.println(Logbuf.DEBUG,"Waiting to be INACTIVE state. Sleeping " + delta + " [s] (" + count +"/" + cycle);
             ++count;
-            if (delta.getUsec() > m_resetTimeout.getUsec() || count > cycle)
+            if (delta.toDouble() > m_resetTimeout.toDouble() || count > cycle)
             {
                 rtcout.println(Logbuf.WARN,"The component is not responding.");
                 break;
             }
         }
         // Now State must be INACTIVE
-        if (rtobj.isCurrentState(LifeCycleState.INACTIVE_STATE))
+        if (!rtobj.isCurrentState(LifeCycleState.INACTIVE_STATE))
         {
             rtcout.println(Logbuf.ERROR,"Unknown error: Invalid state transition.");
             return ReturnCode_t.RTC_ERROR;
@@ -866,8 +872,8 @@
     }
     public LifeCycleState getComponentState(LightweightRTObject comp) {
 
-        LifeCycleState state = m_workerthread.getComponentState(comp);
-        rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.getComponentState() = " + state);
+        LifeCycleState state = m_worker.getComponentState(comp);
+        rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.getComponentState() = " + getStateString(state));
         if (state == LifeCycleState.CREATED_STATE)
         {
             rtcout.println(Logbuf.ERROR,"CREATED state: not initialized "
@@ -876,6 +882,10 @@
         return onGetComponentState(state);
     }
 
+    public final String getStateString(LifeCycleState state) {
+        return m_worker.getStateString(state);
+    }
+    
     /**
      * <p>ExecutionKindを取得します。</p>
      * 
@@ -941,7 +951,7 @@
             rtcout.println(Logbuf.ERROR,"Error: onAddingComponent(). RTC is not attached.");
             return ret;
         }
-        ret = m_workerthread.addComponent(comp); // Actual addComponent()
+        ret = m_worker.addComponent(comp); // Actual addComponent()
         if (ret != ReturnCode_t.RTC_OK)
         {
             rtcout.println(Logbuf.ERROR,"Error: ECWorker addComponent() faild.");
@@ -958,7 +968,7 @@
         {
             rtcout.println(Logbuf.ERROR,"Error: onAddedComponent() faild.");
             rtcout.println(Logbuf.INFO,"Removing attached RTC.");
-            m_workerthread.removeComponent(comp);
+            m_worker.removeComponent(comp);
             m_profile.removeComponent(comp);
             return ret;
         }
@@ -986,7 +996,7 @@
 
         rtcout.println(Logbuf.TRACE, 
                     "PeriodicExecutionContext.bindComponent()");
-        return m_workerthread.bindComponent(rtc);
+        return m_worker.bindComponent(rtc);
     }
 
     /**
@@ -1031,7 +1041,7 @@
                     +"RTC will not not attached.");
             return ret;
         }
-        ret = m_workerthread.removeComponent(comp); // Actual removeComponent()
+        ret = m_worker.removeComponent(comp); // Actual removeComponent()
         if (ret != ReturnCode_t.RTC_OK)
         {
             rtcout.println(Logbuf.ERROR,"Error: ECWorker removeComponent() faild.");
@@ -1048,7 +1058,7 @@
         {
             rtcout.println(Logbuf.ERROR,"Error: onRemovedComponent() faild.");
             rtcout.println(Logbuf.INFO,"Removing attached RTC.");
-            m_workerthread.removeComponent(comp);
+            m_worker.removeComponent(comp);
             m_profile.removeComponent(comp);
             return ret;
         }
@@ -1435,24 +1445,42 @@
      */
     protected Vector<Comp>  m_comps = new Vector<Comp>();
     /**
-     * <p>ExecutionContextの実行状態です。</p>
-     */
-    protected boolean m_running;
-    /**
      * <p>ExecutionContext のスレッド実行フラグです。</p>
      */
     private boolean m_svc;
     private String m_svcmutex  = new String();
 
 
-     private  boolean running_;
-     private String mutex_ = new String() ;
+    /**
+     * <p>Worke用状態変数クラスです。</p>
+     */
+    private class WorkerThreadCtrl {
+        private String mutex_ = new String();
+        private boolean running_; 
+        public WorkerThreadCtrl() {
+            running_ = false;
+        }
+    }
 
-
+    /**
+     * <p>transitionMode保持用クラスです。</p>
+     */
+    /*!
+    private class transitionModeHolder {
+        private boolean flag;
+        public transitionModeHolder() {
+            flag = false;
+        }
+    }
+*/
     // A condition variable for external triggered worker
-    private ExecutionContextWorker m_workerthread = new ExecutionContextWorker();
+    private WorkerThreadCtrl m_workerthread = new WorkerThreadCtrl();
 
     /**
+     * <p>ExecutionContextWorkerです。</p>
+     */
+    protected ExecutionContextWorker m_worker = new ExecutionContextWorker();
+    /**
      * <p>ExecutionContextProfileです。</p>
      */
     protected ExecutionContextProfile m_profile = new ExecutionContextProfile();
@@ -1545,6 +1573,49 @@
      * {@.en Initialization function of ExecutionContext class}
      */
     public void init(Properties props) {
+        String str = new String();
+        str = props._dump(str,props,0);
+        rtcout.println(Logbuf.TRACE,str);
+        
+        // getting rate
+        setExecutionRate(props);
+        
+        // getting sync/async mode flag
+        transitionModeHolder transitionMode = new transitionModeHolder();
+        if (setTransitionMode(props, "sync_transition", transitionMode)) {
+            m_syncActivation   = transitionMode.flag;
+            m_syncDeactivation = transitionMode.flag;
+            m_syncReset        = transitionMode.flag;
+        }
+        setTransitionMode(props, "sync_activation", transitionMode);
+        m_syncActivation = transitionMode.flag;
+        setTransitionMode(props, "sync_deactivation", transitionMode);
+        m_syncDeactivation = transitionMode.flag;
+        setTransitionMode(props, "sync_reset", transitionMode);
+        m_syncReset = transitionMode.flag;
+        TimeValue timeout = new TimeValue();
+        if (setTimeout(props, "transition_timeout", timeout)) {
+            m_activationTimeout   = timeout;
+            m_deactivationTimeout = timeout;
+            m_resetTimeout = timeout;
+        }
+        setTimeout(props, "activation_timeout",   m_activationTimeout);
+        setTimeout(props, "deactivation_timeout", m_deactivationTimeout);
+        setTimeout(props, "reset_timeout",        m_resetTimeout);
+
+        rtcout.println(Logbuf.DEBUG, "ExecutionContext's configurations:");
+        rtcout.println(Logbuf.DEBUG, "Exec rate  : "+getRate()+" [Hz]");
+        rtcout.println(Logbuf.DEBUG, "Activation : Sync ="
+                + (m_syncActivation == true ? "YES":"NO")
+                + ", Timeout = "+m_activationTimeout.toDouble());
+        rtcout.println(Logbuf.DEBUG, "Deactivation : Sync ="
+                + (m_syncDeactivation == true ? "YES":"NO")
+                + ", Timeout = "+m_deactivationTimeout.toDouble());
+        rtcout.println(Logbuf.DEBUG, "Reset : Sync ="
+                + (m_syncReset == true ? "YES":"NO")
+                + ", Timeout = "+m_resetTimeout.toDouble());
+        // Setting given Properties to EC's profile::properties
+        setProperties(props);
     }
 
 
@@ -1748,11 +1819,23 @@
      *
      */
     public RTC.ExecutionContextProfile getProfile(){
-        return m_profile.getProfile();
+        rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.getProfile()");
+        RTC.ExecutionContextProfile profile = m_profile.getProfile();
+        rtcout.println(Logbuf.DEBUG, "kind: "+getKindString(profile.kind));
+        rtcout.println(Logbuf.DEBUG, "rate: "+profile.rate);
+        rtcout.println(Logbuf.DEBUG, "properties: ");
+        String str = new String();
+        Properties prop = new Properties();
+        NVListHolder nvholder = 
+                new NVListHolder(profile.properties);
+        NVUtil.copyToProperties(prop,nvholder);
+        str = prop._dump(str,prop,0);
+        rtcout.println(Logbuf.TRACE,str);
+        return onGetProfile(profile);
     }
     public boolean setTimeout(Properties props, String key,TimeValue timevalue)
     {
-        rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.setTimeout(" + key +")");
+        rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.setTimeout(" + key +")");
         if (props.findNode(key) != null)
         {
            timevalue.convert(Double.valueOf(props.getNode(key).getValue())) ;
@@ -1782,22 +1865,49 @@
     }
     /*!
      * @if jp
-     * @brief Propertiesから状態遷移Timeoutをセットする
+     * @brief Propertiesから状態遷移モードをセットする
      * @else
-     * @brief Setting state transition timeout from given properties.
+     * @brief Setting state transition mode from given properties.
      * @endif
      */
-    public boolean setTransitionMode(Properties props, String key, boolean flag)
+    public boolean setTransitionMode(Properties props, String key, transitionModeHolder tmhldr)
     {
         rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.setTransitionMode(" + key +")");
         if (props.findNode(key) != null)
         {
-            flag = props.getNode(key).getValue() == "YES";
-            rtcout.println(Logbuf.DEBUG, "Transition Mode: " + key +" = " + ( flag ? "YES" : "NO"));
+            tmhldr.flag = props.getNode(key).getValue() == "YES";
+            rtcout.println(Logbuf.DEBUG, "Transition Mode: " + key +" = " + ( tmhldr.flag ? "YES" : "NO"));
             return true;
        }
         rtcout.println(Logbuf.DEBUG, "Configuration " + key +" not found.");
         return false;
     }
 
+    /*! ============================================================
+     * Delegated functions to ExecutionContextWorker
+     *  ============================================================ */
+    public boolean isAllCurrentState(RTC.LifeCycleState state)
+    {
+      return m_worker.isAllCurrentState(state);
+    }
+    
+    public boolean isAllNextState(RTC.LifeCycleState state)
+    {
+      return m_worker.isAllNextState(state);
+    }
+    
+    public boolean isOneOfCurrentState(RTC.LifeCycleState state)
+    {
+      return m_worker.isOneOfCurrentState(state);
+    }
+    
+    public boolean isOneOfNextState(RTC.LifeCycleState state)
+    {
+      return m_worker.isOneOfNextState(state);
+    }
+    
+    public void invokeWorker() { m_worker.invokeWorker(); }
+    public void invokeWorkerPreDo()   { m_worker.invokeWorkerPreDo(); }
+    public void invokeWorkerDo()      { m_worker.invokeWorkerDo(); }
+    public void invokeWorkerPostDo()  { m_worker.invokeWorkerPostDo(); }
 }



More information about the openrtm-commit mailing list