[openrtm-commit:01634] r737 - in branches/RELENG_1_1: . jp.go.aist.rtm.RTC jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/RTC/log
openrtm @ openrtm.org
openrtm @ openrtm.org
2015年 10月 28日 (水) 18:27:41 JST
Author: kawauchi
Date: 2015-10-28 18:27:41 +0900 (Wed, 28 Oct 2015)
New Revision: 737
Modified:
branches/RELENG_1_1/
branches/RELENG_1_1/buildInstaller.bat
branches/RELENG_1_1/buildTests.sh
branches/RELENG_1_1/jp.go.aist.rtm.RTC/
branches/RELENG_1_1/jp.go.aist.rtm.RTC/build.xml
branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/ModuleManager.java
branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObject_impl.java
branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextBase.java
branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextProfile.java
branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextWorker.java
branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java
branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/OpenHRPExecutionContext.java
branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java
branches/RELENG_1_1/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/AllTest110.java
branches/RELENG_1_1/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/RTC/log/LogBufTimeTest.java
Log:
[compat,merge] r671,676,677,689,690,702,703,705 merged from trunk.
Property changes on: branches/RELENG_1_1
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/RELENG_1_0_0:60-401
/branches/work/ConfigurationCallback:631-635
/branches/work/DesignChangeOfEC:648-660
/branches/work/ForComponentActionListener:521-522
/branches/work/ForComponentObserverConsumer:534-543
/branches/work/ForConfigurationListener:524-526
/branches/work/ForLogFormat:518-519
/branches/work/ForPortConnectListener:528-532
/branches/work/ForSDOServiceAdminClass:505-507
/branches/work/LoggerService:666-669
/branches/work/SourceSharing:591-603
/branches/work/ToGetProperties:545-548
/branches/work/ToIFR_ID:509-514
/trunk:622,630-637,639-658,661,663-665,670,672-675,678,680-685,687-688,691-692,695-696,698,700,707-727
+ /branches/RELENG_1_0_0:60-401
/branches/work/ConfigurationCallback:631-635
/branches/work/DesignChangeOfEC:648-660
/branches/work/ForComponentActionListener:521-522
/branches/work/ForComponentObserverConsumer:534-543
/branches/work/ForConfigurationListener:524-526
/branches/work/ForLogFormat:518-519
/branches/work/ForPortConnectListener:528-532
/branches/work/ForSDOServiceAdminClass:505-507
/branches/work/LoggerService:666-669
/branches/work/SourceSharing:591-603
/branches/work/ToGetProperties:545-548
/branches/work/ToIFR_ID:509-514
/trunk:622,630-637,639-658,661,663-665,670-678,680-685,687-692,695-696,698,700,702-703,705,707-727
Modified: branches/RELENG_1_1/buildInstaller.bat
===================================================================
--- branches/RELENG_1_1/buildInstaller.bat 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/buildInstaller.bat 2015-10-28 09:27:41 UTC (rev 737)
@@ -1,5 +1,5 @@
cd jp.go.aist.rtm.RTC
-call ant javaInstaller -lib %ANT_HOME%\lib\
+call ant buildInstaller -lib %ANT_HOME%\lib\
if ERRORLEVEL 1 goto error_end
cd ..
exit /b 0
Modified: branches/RELENG_1_1/buildTests.sh
===================================================================
--- branches/RELENG_1_1/buildTests.sh 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/buildTests.sh 2015-10-28 09:27:41 UTC (rev 737)
@@ -41,7 +41,8 @@
#
#
cd jp.go.aist.rtm.RTC
-ant buildTests -lib $ANT_HOME/lib/
+ant compile_tests -lib $ANT_HOME/lib/
+ant junit -lib $ANT_HOME/lib/
if [ $? -ne 0 ];
then
exit 1
Property changes on: branches/RELENG_1_1/jp.go.aist.rtm.RTC
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/RELENG_1_0/jp.go.aist.rtm.RTC:408-498
/branches/RELENG_1_0_0/jp.go.aist.rtm.RTC:60-401
/branches/work/ConfigurationCallback/jp.go.aist.rtm.RTC:631-635
/branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC:648-660
/branches/work/ForComponentActionListener/jp.go.aist.rtm.RTC:521-522
/branches/work/ForComponentObserverConsumer/jp.go.aist.rtm.RTC:534-543
/branches/work/ForConfigurationListener/jp.go.aist.rtm.RTC:524-526
/branches/work/ForLogFormat/jp.go.aist.rtm.RTC:518-519
/branches/work/ForPortConnectListener/jp.go.aist.rtm.RTC:528-532
/branches/work/ForSDOServiceAdminClass/jp.go.aist.rtm.RTC:505-507
/branches/work/LoggerService/jp.go.aist.rtm.RTC:666-669
/branches/work/SourceSharing/jp.go.aist.rtm.RTC:591-603
/branches/work/ToGetProperties/jp.go.aist.rtm.RTC:545-548
/branches/work/ToIFR_ID/jp.go.aist.rtm.RTC:509-514
/trunk/jp.go.aist.rtm.RTC:622,630-637,639-658,661,663-665,670,672-675,678,680-685,687-688,691-692,695-696,698,700,707-727
+ /branches/RELENG_1_0/jp.go.aist.rtm.RTC:408-498
/branches/RELENG_1_0_0/jp.go.aist.rtm.RTC:60-401
/branches/work/ConfigurationCallback/jp.go.aist.rtm.RTC:631-635
/branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC:648-660
/branches/work/ForComponentActionListener/jp.go.aist.rtm.RTC:521-522
/branches/work/ForComponentObserverConsumer/jp.go.aist.rtm.RTC:534-543
/branches/work/ForConfigurationListener/jp.go.aist.rtm.RTC:524-526
/branches/work/ForLogFormat/jp.go.aist.rtm.RTC:518-519
/branches/work/ForPortConnectListener/jp.go.aist.rtm.RTC:528-532
/branches/work/ForSDOServiceAdminClass/jp.go.aist.rtm.RTC:505-507
/branches/work/LoggerService/jp.go.aist.rtm.RTC:666-669
/branches/work/SourceSharing/jp.go.aist.rtm.RTC:591-603
/branches/work/ToGetProperties/jp.go.aist.rtm.RTC:545-548
/branches/work/ToIFR_ID/jp.go.aist.rtm.RTC:509-514
/trunk/jp.go.aist.rtm.RTC:622,630-637,639-658,661,663-665,670-678,680-685,687-692,695-696,698,700,702-703,705,707-727
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/build.xml
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/build.xml 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/build.xml 2015-10-28 09:27:41 UTC (rev 737)
@@ -161,6 +161,18 @@
</target>
+ <target name="buildInstaller">
+
+ <taskdef name="jsmoothgen"
+ classname="net.charabia.jsmoothgen.ant.JSmoothGen"
+ classpath="${dir.jsmooth}/lib/jsmoothgen-ant.jar"/>
+ <antcall target="createExe" />
+
+ <antcall target="javaInstaller" />
+
+ </target>
+
+
<target name="buildAllLinux">
<antcall target="idlCompile" />
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/ModuleManager.java
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/ModuleManager.java 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/ModuleManager.java 2015-10-28 09:27:41 UTC (rev 737)
@@ -212,8 +212,7 @@
}
file = new File(fullClassName);
if(file.isAbsolute()){
- URLClassLoader url
- = createURLClassLoader(file.getParent());
+ URLClassLoader url = createURLClassLoader(file.getParent());
if(url!=null){
String name = file.getName();
name = getModuleName(name);
@@ -345,10 +344,8 @@
try{
URI uri = path.toURI();
urls[0] = uri.toURL();
- }
- catch(java.net.MalformedURLException ex){
- rtcout.println(Logbuf.WARN,
- "java.net.MalformedURLException: toURL() threw Exception."+ex);
+ } catch(java.net.MalformedURLException ex){
+ rtcout.println(Logbuf.WARN, "java.net.MalformedURLException: toURL() threw Exception."+ex);
return null;
}
URLClassLoader url = new URLClassLoader(urls);
@@ -485,7 +482,7 @@
//
Method initMethod;
try {
- initMethod = target.getMethod(method_name);
+ initMethod = target.getMethod(method_name, null);
} catch (SecurityException e) {
throw e;
} catch (NoSuchMethodException e) {
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObject_impl.java
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObject_impl.java 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObject_impl.java 2015-10-28 09:27:41 UTC (rev 737)
@@ -665,7 +665,7 @@
ArrayList<Properties> ec_args = new ArrayList<Properties>() ;
if (getContextOptions(ec_args)!=ReturnCode_t.RTC_OK )
{
- rtcout.println(Logbuf.ERROR,"Vaild EC options are nao available. Aborting");
+ rtcout.println(Logbuf.ERROR,"Valid EC options are not available. Aborting");
return ReturnCode_t.BAD_PARAMETER;
}
@@ -6296,7 +6296,6 @@
ReturnCode_t ret = ReturnCode_t.RTC_OK;
Set<String> avail_ec
= ExecutionContextFactory.instance().getIdentifiers();
-
for (int ic=0; ic < ec_args.size(); ++ic) {
String ec_type = ec_args.get(ic).getProperty("type");
String ec_name = ec_args.get(ic).getProperty("name");
@@ -6316,7 +6315,8 @@
Iterator it = avail_ec.iterator();
while (it.hasNext()) {
if(it.next().equals(ec_type)){
- find_flag= true;
+ find_flag= true;
+ break;
}
}
if (!find_flag) {
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextBase.java
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextBase.java 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextBase.java 2015-10-28 09:27:41 UTC (rev 737)
@@ -5,9 +5,13 @@
import RTC.ExecutionContextService;
import OpenRTM.ExtTrigExecutionContextServicePOA;
+import jp.go.aist.rtm.RTC.RTObjectStateMachine;
import jp.go.aist.rtm.RTC.RTObject_impl;
+import jp.go.aist.rtm.RTC.log.Logbuf;
import jp.go.aist.rtm.RTC.util.Properties;
+import jp.go.aist.rtm.RTC.util.TimeValue;
import RTC.ExecutionKind;
+import RTC.LifeCycleState;
import RTC.LightweightRTObject;
import RTC.ReturnCode_t;
import RTC.RTObject;
@@ -25,10 +29,7 @@
* {@.en Initialization function of ExecutionContext class}
*/
public void init(Properties props);
-/*
- public void init(Properties props) {
- }
-*/
+
/**
* {@.ja CORBA オブジェクトの設定}
* {@.en Sets the reference to the CORBA object}
@@ -44,11 +45,6 @@
*
*/
public void setObjRef(final ExecutionContextService ref);
-/*
- public void setObjRef(final ExecutionContextService ref) {
- m_profile.setObjRef(ref);
- }
-*/
/**
* <p> bindComponent </p>
@@ -58,7 +54,6 @@
*
*/
public ReturnCode_t bindComponent(RTObject_impl rtc);
-// public abstract ReturnCode_t bindComponent(RTObject_impl rtc);
/**
* {@.ja CORBA オブジェクト参照の取得}
@@ -75,11 +70,7 @@
*
*/
public ExecutionContextService getObjRef();
-/*
- public ExecutionContextService getObjRef() {
- return m_profile.getObjRef();
- }
-*/
+
/**
* {@.ja ExecutionContext の実行周期(Hz)を設定する}
* {@.en Set execution rate(Hz) of ExecutionContext}
@@ -108,11 +99,7 @@
*
*/
public ReturnCode_t setRate(double rate);
-/*
- public ReturnCode_t setRate(double rate) {
- return m_profile.setRate(rate);
- }
-*/
+
/**
* {@.ja ExecutionContext の実行周期(Hz)を取得する}
* {@.en Get execution rate(Hz) of ExecutionContext}
@@ -128,11 +115,7 @@
*
*/
public double getRate();
-/*
- public double getRate() {
- return m_profile.getRate();
- }
-*/
+
/**
* {@.ja ExecutionKind を文字列化する}
* {@.en Converting ExecutionKind enum to string}
@@ -151,13 +134,9 @@
*
*/
public String getKindString(ExecutionKind kind);
-/*
- public final String getKindString(ExecutionKind kind) {
- return m_profile.getKindString(kind);
- }
-*/
+
/**
- * {@.ja ExecutionKind を設定する
+ * {@.ja ExecutionKind を設定する}
* {@.en Set the ExecutionKind}
* <p>
* {@.ja この ExecutionContext の ExecutionKind を設定する}
@@ -259,14 +238,73 @@
*/
public RTC.ExecutionContextProfile getProfile() ;
public boolean finalizeExecutionContext();
-// public abstract boolean finalizeExecutionContext();
-/*
- public ExecutionContextProfile m_profile
- = new ExecutionContextProfile();
-*/
-/*
- protected ExecutionContextProfile m_profile
- = new ExecutionContextProfile();
-*/
+ /**
+ * {@.ja Propertiesから実行コンテキストをセットする}
+ * {@.en Setting execution rate from given properties.}
+ * @param props
+ * {@.ja ExecutionContextProfile::properties にセットするプロパティー}
+ * {@.en Properties to be set to ExecutionContextProfile::properties.}
+ */
+ public boolean setExecutionRate(Properties props);
+ /**
+ * {@.ja Propertiesから状態遷移モードをセットする}
+ * {@.en Setting state transition mode from given properties.}
+ * @param props
+ * {@.ja ExecutionContextProfile::properties にセットするプロパティー}
+ * {@.en Properties to be set to ExecutionContextProfile::properties.}
+ * @param key
+ * @param flag
+ */
+ public boolean setTransitionMode(Properties props, String key, boolean flag);
+ /**
+ * {@.ja Propertiesから状態遷移Timeoutをセットする}
+ * {@.en Setting state transition timeout from given properties.}
+ * @param props
+ * {@.ja ExecutionContextProfile::properties にセットするプロパティー}
+ * {@.en Properties to be set to ExecutionContextProfile::properties.}
+ * @param key
+ * @param timevalue
+ */
+ public boolean setTimeout(Properties props, String key,TimeValue timevalue);
+ public ReturnCode_t onStarted();
+ public ReturnCode_t onStopping();
+ public ReturnCode_t onStopped();
+ public double onGetRate(double rate);
+ public double onSettingRate(double rate);
+ public ReturnCode_t onSetRate(double rate);
+ public ReturnCode_t onAddingComponent(LightweightRTObject rtobj);
+ public ReturnCode_t onAddedComponent(LightweightRTObject rtobj);
+ public ReturnCode_t onRemovingComponent(LightweightRTObject rtobj);
+ public ReturnCode_t onRemovedComponent(LightweightRTObject rtobj);
+ // template virtual functions related to activation/deactivation/reset
+ public ReturnCode_t onActivating(LightweightRTObject comp);
+ public ReturnCode_t onActivated(RTObjectStateMachine comp, long count);
+ public ReturnCode_t onDeactivating(LightweightRTObject comp);
+ public ReturnCode_t onDeactivated(RTObjectStateMachine comp, long count);
+ public ReturnCode_t onResetting(LightweightRTObject comp);
+ public ReturnCode_t onReset(RTObjectStateMachine comp, long count);
+
+ public LifeCycleState onGetComponentState(LifeCycleState state);
+ public ExecutionKind onGetKind(ExecutionKind kind);
+ public ExecutionContextProfile onGetProfile(ExecutionContextProfile profile);
+
+ /**
+ * {@.ja onWaitingActivated() template function}
+ * {@.en onWaitingActivated() template function}
+ */
+ public ReturnCode_t onWaitingActivated(RTObjectStateMachine comp, long count);
+
+ /**
+ * {@.ja onWaitingDeactivated() template function}
+ * {@.en onWaitingDeactivated() template function}
+ */
+ public ReturnCode_t onWaitingDeactivated(RTObjectStateMachine comp, long count);
+
+ /**
+ * {@.ja onWaitingReset() template function}
+ * {@.en onWaitingReset() template function}
+ */
+ public ReturnCode_t onWaitingReset(RTObjectStateMachine comp, long count);
+
}
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextProfile.java
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextProfile.java 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextProfile.java 2015-10-28 09:27:41 UTC (rev 737)
@@ -64,7 +64,7 @@
* {@.ja CORBA オブジェクトの設定}
* {@.en Sets the reference to the CORBA object}
* <p>
- * {@ja .ExecutioncontextService の CORBA オブジェクト参照をセットする。
+ * {@.ja ExecutioncontextService の CORBA オブジェクト参照をセットする。
* セットされると、それまでセットされていたオブジェクト参照は
* releaseされる。セットするオブジェクト参照は有効な参照でなければ
* ならない。}
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextWorker.java
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextWorker.java 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextWorker.java 2015-10-28 09:27:41 UTC (rev 737)
@@ -38,6 +38,8 @@
public ExecutionContextWorker() {
rtcout = new Logbuf("ec_worker");
m_running = false;
+ ticked_ = false ;
+ running_ = false ;
rtcout.println(Logbuf.TRACE, "ExecutionContextWorker()");
}
//============================================================
@@ -685,16 +687,21 @@
* true: running, false: stopped
*/
protected boolean m_running;
+ protected boolean ticked_;
+ protected boolean running_;
/**
* {@.ja コンポーネントの参加者リスト}
* {@.en List of the participating component}
*/
protected ArrayList<RTObjectStateMachine> m_comps;
- protected String m_mutex;
+// protected String m_mutex;
+ protected String m_mutex = new String();
protected ArrayList<RTObjectStateMachine> m_addedComps;
- protected String m_addedMutex;
+// protected String m_addedMutex;
+ protected String m_addedMutex = new String();
ArrayList<RTObjectStateMachine> m_removedComps;
- protected String m_removedMutex;
+// protected String m_removedMutex;
+ protected String m_removedMutex = new String();
};
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java 2015-10-28 09:27:41 UTC (rev 737)
@@ -6,6 +6,7 @@
import jp.go.aist.rtm.RTC.ObjectCreator;
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.StateAction;
import jp.go.aist.rtm.RTC.StateHolder;
import jp.go.aist.rtm.RTC.StateMachine;
@@ -41,6 +42,12 @@
extends ExtTrigExecutionContextServicePOA
implements Runnable, ObjectCreator<ExecutionContextBase>, ObjectDestructor, ExecutionContextBase{
+ TimeValue m_activationTimeout = new TimeValue(0.5);
+ TimeValue m_deactivationTimeout = new TimeValue(0.5);
+ TimeValue m_resetTimeout = new TimeValue(0.5);
+ boolean m_syncActivation = true;
+ boolean m_syncDeactivation = true;
+ boolean m_syncReset = true;
/**
* {@.ja コンストラクタ}
* {@.en Constructor}
@@ -48,9 +55,14 @@
public ExtTrigExecutionContext() {
super();
- rtcout = new Logbuf("Manager.ExtTrigExecutionContext");
+ rtcout = new Logbuf("ExtTrigExecutionContext");
+ m_svc = false;
m_profile.setObjRef((ExecutionContextService)this.__this());
+ m_profile.setKind(ExecutionKind.PERIODIC);
+ m_profile.setRate(1000);
+ rtcout.println(Logbuf.DEBUG, "Actual period: " + m_profile.getPeriod().sec() + " [sec], "
+ + m_profile.getPeriod().usec() + " [usec]");
}
/**
@@ -78,17 +90,18 @@
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);
- }
+ m_svc = false;
+ try {
+ m_thread.join();
+ }
+ catch (InterruptedException e) {
+ System.out.println(e);
+ }
- return true;
+ return true;
}
/**
@@ -105,7 +118,7 @@
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.tick()");
synchronized (m_worker) {
- m_worker._called = true;
+ m_worker.ticked_ = true;
m_worker.notifyAll();
}
}
@@ -128,40 +141,63 @@
* 全Componentの処理を呼び出した後、次のイベントが発生するまで休止します。</p>
*/
public int svc() {
-
+ int count = 0 ;
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.svc()");
do {
- TimeValue tv = new TimeValue(0, m_usec); // (s, us)
synchronized (m_worker) {
- while (!m_worker._called && m_running) {
+ rtcout.println(Logbuf.DEBUG, "Start of worker invocation. ticked = "+ (m_worker.ticked_ ? "true" : "false"));
+ while (!m_worker.ticked_) {
try {
m_worker.wait();
+ rtcout.println(Logbuf.DEBUG, "Thread was woken up.");
} catch (InterruptedException e) {
break;
}
}
- if (m_worker._called) {
- m_worker._called = false;
- for (int intIdx = 0; intIdx < m_comps.size(); ++intIdx) {
- m_comps.get(intIdx).invoke();
- }
-/*
- while (!m_running) {
- try {
- Thread.sleep(0, (int) tv.getUsec());
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- try {
- Thread.sleep(0, (int) tv.getUsec());
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-*/
+ if(!m_worker.ticked_){continue;}
+ }
+ TimeValue t0 = new TimeValue();
+ t0.convert(System.nanoTime()/1000);
+ 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 ;
+ }
+ TimeValue period = getPeriod();
+ TimeValue t2 = new TimeValue();
+ t2.convert(System.nanoTime()/1000);
+ if(true){
+ TimeValue t1_w = t1;
+ TimeValue period_w = period ;
+ rtcout.println(Logbuf.PARANOID, "Period: " + period + " [s]");
+ 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)
+ {
+ if(true)
+ {
+ rtcout.println(Logbuf.PARANOID, "sleeping...");
}
+ try {
+ Thread.sleep(period.getUsec());
+ } 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);
return 0;
@@ -196,13 +232,152 @@
*
*/
public boolean is_running() {
-
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.is_running()");
+ return m_worker.isRunning();
+ }
- return m_running;
+ public ReturnCode_t onStarting() { return ReturnCode_t.RTC_OK; }
+
+ //============================================================
+ // protected functions
+ //============================================================
+ /*!
+ * @brief onStarted() template function
+ */
+ public ReturnCode_t onStarted()
+ {
+ // change EC thread state
+ synchronized (m_worker) {
+ if (!m_svc)
+ { // If start() is called first time, start the worker thread.
+ m_svc = true;
+ this.open();
+ }
+ return ReturnCode_t.RTC_OK;
+ }
}
+ public ReturnCode_t onStopping()
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onStopped()
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public double onGetRate(double rate)
+ {
+ return rate;
+ }
+ public double onSettingRate(double rate)
+ {
+ return rate;
+ }
+ public ReturnCode_t onSetRate(double rate)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onAddingComponent(LightweightRTObject rtobj)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onAddedComponent(LightweightRTObject rtobj)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onRemovingComponent(LightweightRTObject rtobj)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onRemovedComponent(LightweightRTObject rtobj)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ // template virtual functions related to activation/deactivation/reset
+ public ReturnCode_t onActivating(LightweightRTObject comp)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onActivated(RTObjectStateMachine comp, long count)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onDeactivating(LightweightRTObject comp)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onDeactivated(RTObjectStateMachine comp, long count)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onResetting(LightweightRTObject comp)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onReset(RTObjectStateMachine comp, long count)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+
+ public LifeCycleState onGetComponentState(LifeCycleState state)
+ {
+ return state;
+ }
+ public ExecutionKind onGetKind(ExecutionKind kind)
+ {
+ return kind;
+ }
+ public ExecutionContextProfile onGetProfile(ExecutionContextProfile profile)
+ {
+ return profile;
+ }
+
/**
+ * {@.ja onWaitingActivated() template function}
+ * {@.en onWaitingActivated() template function}
+ */
+ public ReturnCode_t onWaitingActivated(RTObjectStateMachine comp, long count)
+ {
+ rtcout.println(Logbuf.TRACE,
+ "ExtTrigExecutionContext.onWaitingActivated(count = " + count +")");
+// rtcout.println(Logbuf.PARANOID,
+// "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();
+ return ReturnCode_t.RTC_OK;
+ }
+ }
+
+
+ /*!
+ * @brief onWaitingDeactivated() template function
+ */
+ public ReturnCode_t onWaitingDeactivated(RTObjectStateMachine comp, long count)
+ {
+ rtcout.println(Logbuf.TRACE,
+ "ExtTrigExecutionContext.onWaitingDeactivated(count = " + count +")");
+ synchronized (m_worker) {
+ m_worker.notifyAll();
+ return ReturnCode_t.RTC_OK;
+ }
+ }
+
+ /*!
+ * @brief onWaitingReset() template function
+ */
+ public ReturnCode_t onWaitingReset(RTObjectStateMachine comp, long count)
+ {
+ rtcout.println(Logbuf.TRACE,
+ "ExtTrigExecutionContext.onWaitingReset(count = " + count +")");
+ synchronized (m_worker) {
+ m_worker.notifyAll();
+ return ReturnCode_t.RTC_OK;
+ }
+ }
+
+ /**
* {@.ja ExecutionContext の実行を開始}
* {@.en Start the ExecutionContext}
* <p>
@@ -226,23 +401,27 @@
public ReturnCode_t start() {
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.start()");
-
- if( m_running ) return ReturnCode_t.PRECONDITION_NOT_MET;
-
- // invoke ComponentAction::on_startup for each comps.
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- m_comps.get(intIdx).invoke_on_startup();
+ ReturnCode_t ret = onStarting();
+ if( ret != ReturnCode_t.RTC_OK )
+ {
+ rtcout.println(Logbuf.ERROR, "onStarting() failed. Starting EC aborted.");
+ return ret;
}
- // change EC thread state
- m_running = true;
- synchronized (m_worker) {
- //m_worker.running_ = true;
- m_worker.notifyAll();
+ ret = m_worker.start();
+ if(ret!=ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "Invoking on_startup() for each RTC failed.");
+ return ret;
}
-
- this.open();
-
- return ReturnCode_t.RTC_OK;
+ ret = onStarted();
+ if(ret!=ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "Invoking on_startup() for each RTC failed.");
+ m_worker.stop();
+ rtcout.println(Logbuf.ERROR, "on_shutdown() was invoked, because of on_startup");
+ return ret;
+ }
+ return ret;
}
/**
@@ -269,20 +448,25 @@
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.stop()");
- if( !m_running ) return ReturnCode_t.PRECONDITION_NOT_MET;
-
- // change EC thread state
- m_running = false;
- synchronized (m_worker) {
- //m_worker.running_ = false;
- }
-
- // invoke on_shutdown for each comps.
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- m_comps.get(intIdx).invoke_on_shutdown();
+ ReturnCode_t ret = onStopping(); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "onStopping() failed. Stopping EC aborted.");
+ return ret;
}
-
- return ReturnCode_t.RTC_OK;
+ ret = m_worker.stop(); // Actual stop()
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "Invoking on_shutdown() for each RTC failed.");
+ return ret;
+ }
+ ret = onStopped(); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "Invoking on_shutdown() for each RTC failed.");
+ return ret;
+ }
+ return ret;
}
/**
@@ -299,12 +483,20 @@
* {@.en Execution cycle(Unit:Hz)}
*
*/
+
public double get_rate() {
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.get_rate()");
return m_profile.getRate();
}
+
+ public TimeValue getPeriod()
+ {
+ TimeValue period = m_profile.getPeriod();
+ return period;
+ }
+
/**
* <p>ExecutionContextの実行周期(Hz)を設定します。</p>
*
@@ -316,20 +508,20 @@
if( rate<=0.0 ) return ReturnCode_t.BAD_PARAMETER;
- m_profile.setRate(rate);
- this.m_usec = (long)(1000000/rate);
- if( m_usec == 0 ) {
- m_nowait = true;
+ ReturnCode_t ret = m_profile.setRate(onSettingRate(rate));
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "Setting execution rate failed. " + rate);
+ return ret;
}
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- m_comps.get(intIdx).invoke_on_rate_changed();
+ ret = onSetRate(rate);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "onSetRate("+ rate +") failed.");
+ return ret;
}
- rtcout.println(Logbuf.DEBUG, "Actual period: "
- + m_profile.getPeriod().sec()
- + " [sec], "
- + m_profile.getPeriod().usec()
- + " [usec]");
- return ReturnCode_t.RTC_OK;
+ rtcout.println(Logbuf.INFO, "onSetRate("+ rate +") done.");
+ return ret;
}
/**
@@ -342,22 +534,93 @@
public ReturnCode_t activate_component(LightweightRTObject comp) {
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.activate_component()");
+ return activateComponent(comp);
+ }
- // コンポーネントが参加者リストに無ければ BAD_PARAMETER を返す
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- find_comp find = new find_comp((LightweightRTObject)comp._duplicate());
- if (find.eqaulof(m_comps.get(intIdx)) ) {
- // the given component must be in Alive state.
- if(!(m_comps.get(intIdx)._sm.m_sm.isIn(LifeCycleState.INACTIVE_STATE))) {
- return ReturnCode_t.PRECONDITION_NOT_MET;
- }
- m_comps.get(intIdx)._sm.m_sm.goTo(LifeCycleState.ACTIVE_STATE);
- return ReturnCode_t.RTC_OK;
+ public ReturnCode_t activateComponent(LightweightRTObject comp) {
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.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_worker.activateComponent(comp, rtobj); // Actual activateComponent()
+ if (ret != ReturnCode_t.RTC_OK) { return ret; }
+ if (!m_syncActivation) // Asynchronous activation mode
+ {
+ ret = onActivated(rtobj, -1);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onActivated() failed.");
}
+ return ret;
}
- return ReturnCode_t.BAD_PARAMETER;
+ //------------------------------------------------------------
+ // Synchronized activation mode
+ rtcout.println(Logbuf.DEBUG,"Synchronous activation mode. "
+ +"Waiting for the RTC to be ACTIVE state. ");
+ return waitForActivated(rtobj);
}
+ public ReturnCode_t waitForActivated(RTObjectStateMachine rtobj)
+ {
+ long count =0 ;
+ ReturnCode_t ret = onWaitingActivated(rtobj, count);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingActivated failed.");
+ return ret;
+ }
+ 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
+ TimeValue starttime = new TimeValue();
+ starttime.convert(System.nanoTime()/1000);
+ while (rtobj.isCurrentState(LifeCycleState.INACTIVE_STATE))
+ {
+ ret = onWaitingActivated(rtobj, count); // Template method
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingActivated failed.");
+ return ret;
+ }
+ try
+ {
+ Thread.sleep(getPeriod().getUsec());
+ }catch(InterruptedException e){}
+ TimeValue delta= new TimeValue();
+ delta.convert(System.nanoTime()/1000);
+ 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)
+ {
+ rtcout.println(Logbuf.WARN,"The component is not responding.");
+ break;
+ }
+ }
+ // Now State must be ACTIVE or ERROR
+ if (rtobj.isCurrentState(LifeCycleState.INACTIVE_STATE))
+ {
+ rtcout.println(Logbuf.ERROR,"Unknown error: Invalid state transition.");
+ return ReturnCode_t.RTC_ERROR;
+ }
+ rtcout.println(Logbuf.DEBUG,"Current state is " + rtobj.getState());
+ ret = onActivated(rtobj, count); // Template method
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onActivated() failed.");
+ }
+ rtcout.println(Logbuf.DEBUG,"onActivated() done.");
+ return ret;
+ }
+
+
/**
* <p>コンポーネントを非アクティブ化します。</p>
*
@@ -368,20 +631,91 @@
public ReturnCode_t deactivate_component(LightweightRTObject comp) {
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.deactivate_component()");
+ return deactivateComponent(comp);
+ }
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- find_comp find = new find_comp((LightweightRTObject)comp._duplicate());
- if (find.eqaulof(m_comps.get(intIdx)) ) {
- // the given component must be in Alive state.
- if(!(m_comps.get(intIdx)._sm.m_sm.isIn(LifeCycleState.ACTIVE_STATE))) {
- return ReturnCode_t.PRECONDITION_NOT_MET;
- }
- m_comps.get(intIdx)._sm.m_sm.goTo(LifeCycleState.INACTIVE_STATE);
- return ReturnCode_t.RTC_OK;
+ public ReturnCode_t deactivateComponent(LightweightRTObject comp)
+ {
+ rtcout.println(Logbuf.TRACE,"ExtTrigExecutionContext.deactivateComponent()");
+ ReturnCode_t ret = onDeactivating(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onDeactivatingComponent() failed.");
+ return ret;
+ }
+ // Deactivate all the RTCs
+ RTObjectStateMachine rtobj = null;
+ ret = m_worker.deactivateComponent(comp, rtobj);
+ if (ret != ReturnCode_t.RTC_OK) { return ret; }
+ if (!m_syncDeactivation)
+ {
+ ret = onDeactivated(rtobj, -1);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onDeactivated() failed.");
}
+ return ret;
}
- return ReturnCode_t.BAD_PARAMETER;
+ //------------------------------------------------------------
+ // Waiting for synchronized deactivation
+ rtcout.println(Logbuf.DEBUG,"Synchronous deactivation mode. "
+ +"Waiting for the RTC to be INACTIVE state. ");
+ return waitForDeactivated(rtobj);
}
+ public ReturnCode_t waitForDeactivated(RTObjectStateMachine rtobj)
+ {
+ long count = 0;
+ ReturnCode_t ret = onWaitingDeactivated(rtobj, count);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingDeactivated failed.");
+ return ret;
+ }
+ long cycle =
+ (long )(m_deactivationTimeout.toDouble() / getPeriod().toDouble());
+ 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);
+ while (rtobj.isCurrentState(LifeCycleState.ACTIVE_STATE))
+ {
+ ret = onWaitingDeactivated(rtobj, count); // Template method
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingDeactivated failed.");
+ return ret;
+ }
+ try
+ {
+ Thread.sleep(getPeriod().getUsec());
+ }catch(InterruptedException e){}
+ TimeValue delta = new TimeValue();
+ delta.convert(System.nanoTime()/1000);
+ 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)
+ {
+ rtcout.println(Logbuf.WARN,"The component is not responding.");
+ break;
+ }
+ }
+ // Now State must be INACTIVE or ERROR
+ if (rtobj.isCurrentState(LifeCycleState.ACTIVE_STATE))
+ {
+ rtcout.println(Logbuf.ERROR,"Unknown error: Invalid state transition.");
+ return ReturnCode_t.RTC_ERROR;
+ }
+ rtcout.println(Logbuf.DEBUG,"Current state is "+ rtobj.getState());
+ ret = onDeactivated(rtobj, count);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onDeactivated() failed.");
+ }
+ rtcout.println(Logbuf.DEBUG,"onDeactivated() done.");
+ return ret;
+ }
+
/**
* <p>コンポーネントをリセットします。</p>
@@ -393,20 +727,89 @@
public ReturnCode_t reset_component(LightweightRTObject comp){
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.reset_component()");
+ return removeComponent(comp);
+ }
+ public ReturnCode_t resetCcomponent(LightweightRTObject comp){
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- find_comp find = new find_comp((LightweightRTObject)comp._duplicate());
- if (find.eqaulof(m_comps.get(intIdx)) ) {
- // the given component must be in Alive state.
- if(!(m_comps.get(intIdx)._sm.m_sm.isIn(LifeCycleState.ERROR_STATE))) {
- return ReturnCode_t.PRECONDITION_NOT_MET;
- }
- m_comps.get(intIdx)._sm.m_sm.goTo(LifeCycleState.INACTIVE_STATE);
- return ReturnCode_t.RTC_OK;
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.resetComponent()");
+
+ ReturnCode_t ret = onResetting(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onResetting() failed.");
+ return ret;
+ }
+ RTObjectStateMachine rtobj = null;
+ ret = m_worker.resetComponent(comp, rtobj); // Actual resetComponent()
+ if (ret != ReturnCode_t.RTC_OK) { return ret; }
+ if (!m_syncReset)
+ {
+ ret = onReset(rtobj, -1);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onReset() failed.");
}
+ return ret;
}
- return ReturnCode_t.BAD_PARAMETER;
+ //------------------------------------------------------------
+ // Waiting for synchronized reset
+ rtcout.println(Logbuf.DEBUG,"Synchronous reset mode. "
+ +"Waiting for the RTC to be INACTIVE state. ");
+ return waitForReset(rtobj);
}
+ public ReturnCode_t waitForReset(RTObjectStateMachine rtobj)
+ {
+ long count = 0;
+ ReturnCode_t ret = onWaitingReset(rtobj, count);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingReset() failed.");
+ return ret;
+ }
+ long cycle =
+ (long )(m_resetTimeout.toDouble() / getPeriod().toDouble());
+ 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);
+ while (rtobj.isCurrentState(LifeCycleState.ERROR_STATE))
+ {
+ ret = onWaitingReset(rtobj, count); // Template method
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingReset failed.");
+ return ret;
+ }
+ try
+ {
+ Thread.sleep(getPeriod().getUsec());
+ }catch(InterruptedException e){}
+ TimeValue delta = new TimeValue();
+ delta.convert(System.nanoTime()/1000);
+ 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)
+ {
+ rtcout.println(Logbuf.WARN,"The component is not responding.");
+ break;
+ }
+ }
+ // Now State must be INACTIVE
+ if (rtobj.isCurrentState(LifeCycleState.INACTIVE_STATE))
+ {
+ rtcout.println(Logbuf.ERROR,"Unknown error: Invalid state transition.");
+ return ReturnCode_t.RTC_ERROR;
+ }
+ rtcout.println(Logbuf.DEBUG,"Current state is "+ rtobj.getState());
+ ret = onReset(rtobj, count);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onReset() failed.");
+ }
+ rtcout.println(Logbuf.DEBUG,"onReset() done.");
+ return ret;
+ }
/**
* <p>コンポーネントの状態を取得します。</p>
@@ -418,14 +821,18 @@
public LifeCycleState get_component_state(LightweightRTObject comp) {
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.get_component_state()");
+ return getComponentState(comp);
+ }
+ public LifeCycleState getComponentState(LightweightRTObject comp) {
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- find_comp find = new find_comp((LightweightRTObject)comp._duplicate());
- if (find.eqaulof(m_comps.get(intIdx)) ) {
- return m_comps.get(intIdx)._sm.m_sm.getState();
- }
+ LifeCycleState state = m_worker.getComponentState(comp);
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.getComponentState() = " + state);
+ if (state == LifeCycleState.CREATED_STATE)
+ {
+ rtcout.println(Logbuf.ERROR,"CREATED state: not initialized "
+ +"RTC or unknwon RTC specified.");
}
- return LifeCycleState.CREATED_STATE;
+ return onGetComponentState(state);
}
/**
@@ -435,11 +842,18 @@
*/
public ExecutionKind get_kind() {
- rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.get_kind() ="
- + m_profile.getKindString());
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.get_kind()");
- return m_profile.getKind();
+ return getKind();
}
+ public ExecutionKind getKind()
+ {
+ ExecutionKind kind = m_profile.getKind();
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.getKind() = " + getKindString(kind));
+ kind = onGetKind(kind);
+ rtcout.println(Logbuf.DEBUG,"onGetKind() returns " + getKindString(kind));
+ return kind;
+ }
/**
* {@.ja RTコンポーネントを追加する}
@@ -472,26 +886,42 @@
rtcout.println(Logbuf.TRACE,
"ExtTrigExecutionContext.add_component()");
+ return addComponent(comp);
+ }
+ public ReturnCode_t addComponent(LightweightRTObject comp) {
- if( comp==null ) return ReturnCode_t.BAD_PARAMETER;
- //
- try {
- DataFlowComponent dfp = DataFlowComponentHelper.narrow(comp);
- if( dfp==null ) {
- // Because the ExecutionKind of this context is PERIODIC,
- // the RTC must be a data flow component.
- return ReturnCode_t.BAD_PARAMETER;
- }
- //
- int id = dfp.attach_context(m_ref);
- //
- m_comps.add(new Comp((LightweightRTObject)comp._duplicate(),
- (DataFlowComponent)dfp._duplicate(), id));
- m_profile.addComponent((LightweightRTObject)comp._duplicate());
- return ReturnCode_t.RTC_OK;
- } catch(Exception ex) {
- return ReturnCode_t.BAD_PARAMETER;
+ rtcout.println(Logbuf.TRACE,
+ "ExtTrigExecutionContext.addcomponent()");
+
+ ReturnCode_t ret = onAddingComponent(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: onAddingComponent(). RTC is not attached.");
+ return ret;
}
+ ret = m_worker.addComponent(comp); // Actual addComponent()
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: ECWorker addComponent() faild.");
+ return ret;
+ }
+ ret = m_profile.addComponent(comp); // Actual addComponent()
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: ECProfile addComponent() faild.");
+ return ret;
+ }
+ ret = onAddedComponent(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: onAddedComponent() faild.");
+ rtcout.println(Logbuf.INFO,"Removing attached RTC.");
+ m_worker.removeComponent(comp);
+ m_profile.removeComponent(comp);
+ return ret;
+ }
+ rtcout.println(Logbuf.INFO,"Component has been added to this EC.");
+ return ret;
}
/**
@@ -511,31 +941,8 @@
*
*/
public ReturnCode_t bindComponent(RTObject_impl rtc) {
-
- rtcout.println(Logbuf.TRACE,
- "ExtTrigExecutionContext.bindComponent()");
-
- if (rtc == null) return ReturnCode_t.BAD_PARAMETER;
-
- LightweightRTObject comp = rtc.getObjRef();
- DataFlowComponent dfp;
- dfp = DataFlowComponentHelper.narrow(comp);
-
- int id = rtc.bindContext(m_ref);
- if (id < 0 || id > RTObject_impl.ECOTHER_OFFSET) {
- rtcout.println(Logbuf.ERROR, "bindContext returns invalid id: "+id);
- return ReturnCode_t.RTC_ERROR;
- }
- rtcout.println(Logbuf.DEBUG, "bindComponent() returns id = "+id);
- m_comps.add(new Comp((LightweightRTObject)comp._duplicate(),
- (DataFlowComponent)dfp._duplicate(),
- id));
- m_profile.setOwner((LightweightRTObject)dfp._duplicate());
-
-
- return ReturnCode_t.RTC_OK;
+ return m_worker.bindComponent(rtc);
}
-
/**
* {@.ja RTコンポーネントを参加者リストから削除する}
* {@.en Remove the RT-Component from participant list}
@@ -561,29 +968,49 @@
* {@.en The return code of ReturnCode_t type}
*
*/
+
public ReturnCode_t remove_component(LightweightRTObject comp) {
rtcout.println(Logbuf.TRACE,
"ExtTrigExecutionContext.remove_component()");
+ return removeComponent(comp);
+ }
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- find_comp find
- = new find_comp((LightweightRTObject)comp._duplicate());
- if (find.eqaulof(m_comps.get(intIdx)) ) {
- m_comps.get(intIdx)._ref.detach_context(
- m_comps.get(intIdx)._sm.ec_id);
- m_comps.get(intIdx)._ref = null;
- m_comps.remove(m_comps.get(intIdx));
- rtcout.println(Logbuf.TRACE,
- "remove_component(): an RTC removed from this context.");
- m_profile.removeComponent(comp);
- return ReturnCode_t.RTC_OK;
- }
+ public ReturnCode_t removeComponent(LightweightRTObject comp) {
+
+ rtcout.println(Logbuf.TRACE,
+ "ExtTrigExecutionContext.removeComponent()");
+ ReturnCode_t ret = onRemovingComponent(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: onRemovingComponent(). "
+ +"RTC will not not attached.");
+ return ret;
}
- rtcout.println(Logbuf.TRACE, "remove_component(): no RTC found in this context.");
- return ReturnCode_t.BAD_PARAMETER;
+ ret = m_worker.removeComponent(comp); // Actual removeComponent()
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: ECWorker removeComponent() faild.");
+ return ret;
+ }
+ ret = m_profile.removeComponent(comp); // Actual removeComponent()
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: ECProfile removeComponent() faild.");
+ return ret;
+ }
+ ret = onRemovedComponent(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: onRemovedComponent() faild.");
+ rtcout.println(Logbuf.INFO,"Removing attached RTC.");
+ m_worker.removeComponent(comp);
+ m_profile.removeComponent(comp);
+ return ret;
+ }
+ rtcout.println(Logbuf.INFO,"Component has been removeed to this EC.");
+ return ret;
}
-
/**
* <p>ExecutionContextProfile を取得します。</p>
*
@@ -592,7 +1019,7 @@
public RTC.ExecutionContextProfile get_profile() {
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.get_profile()");
- return m_profile.getProfile();
+ return getProfile();
}
/**
@@ -976,7 +1403,9 @@
public boolean _called;
}
- private Worker m_worker = new Worker();
+// private Worker m_worker = new Worker();
+ private ExecutionContextWorker m_worker = new ExecutionContextWorker();
+
/**
* <p>ExecutionContextProfileです。</p>
*/
@@ -1060,6 +1489,42 @@
* {@.en Initialization function of ExecutionContext class}
*/
public void init(Properties props) {
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.init()");
+ rtcout.println(Logbuf.DEBUG, props.toString());
+ // getting rate
+ setExecutionRate(props);
+ // getting sync/async mode flag
+ boolean transitionMode=true;
+ if(setTransitionMode(props, "sync_transition", transitionMode))
+ {
+ m_syncActivation = transitionMode;
+ m_syncDeactivation = transitionMode;
+ m_syncReset = transitionMode;
+
+ }
+ setTransitionMode(props, "sync_activation", m_syncActivation);
+ setTransitionMode(props, "sync_deactivation", m_syncDeactivation);
+ setTransitionMode(props, "sync_reset", m_syncReset);
+ // getting transition timeout
+ TimeValue timeout = new TimeValue(0.0);
+ 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 ? "YES" : "NO" ) + " Timeout = " + m_activationTimeout.toString());
+ rtcout.println(Logbuf.DEBUG,"Deactivation: Sync = " + ( m_syncDeactivation ? "YES" : "NO" )+ " Timeout = "+ m_deactivationTimeout.toString());
+ rtcout.println(Logbuf.DEBUG,"Reset : Sync = " + ( m_syncReset ? "YES" : "NO" )+ " Timeout = "+ m_resetTimeout.toString());
+ // Setting given Properties to EC's profile::properties
+
+ setProperties(props);
}
/**
@@ -1071,7 +1536,7 @@
* {@.en Get the reference to the CORBA object as
* ExecutioncontextService of this object.}
*
- * @return
+ * @param ref
* {@.ja CORBA オブジェクト参照}
* {@.en The reference to CORBA object}
*
@@ -1281,5 +1746,61 @@
public RTC.ExecutionContextProfile getProfile(){
return m_profile.getProfile();
}
+ /*!
+ * @if jp
+ * @brief Propertiesから状態遷移Timeoutをセットする
+ * @else
+ * @brief Setting state transition timeout from given properties.
+ * @endif
+ */
+ public boolean setTimeout(Properties props, String key,TimeValue timevalue)
+ {
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.setTimeout(" + key +")");
+ if (props.findNode(key) != null)
+ {
+ timevalue.convert(Double.valueOf(props.getNode(key).getValue())) ;
+ rtcout.println(Logbuf.DEBUG, "Timeout (" + key +"): " + props.getNode(key).getValue() + " [s]");
+ return true;
+ }
+ rtcout.println(Logbuf.DEBUG, "Configuration " + key +" not found.");
+ return false;
+ }
+ /*!
+ * @if jp
+ * @brief Propertiesから実行コンテキストをセットする
+ * @else
+ * @brief Setting execution rate from given properties.
+ * @endif
+ */
+ public boolean setExecutionRate(Properties props)
+ {
+ if (props.findNode("rate") != null)
+ {
+ double rate;
+ rate = Double.valueOf(props.getNode("rate").getValue());
+ setRate(rate);
+ return true;
+ }
+ return false;
+ }
+ /*!
+ * @if jp
+ * @brief Propertiesから状態遷移Timeoutをセットする
+ * @else
+ * @brief Setting state transition timeout from given properties.
+ * @endif
+ */
+ public boolean setTransitionMode(Properties props, String key, boolean flag)
+ {
+ 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"));
+ return true;
+ }
+ rtcout.println(Logbuf.DEBUG, "Configuration " + key +" not found.");
+ return false;
+ }
}
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/OpenHRPExecutionContext.java
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/OpenHRPExecutionContext.java 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/OpenHRPExecutionContext.java 2015-10-28 09:27:41 UTC (rev 737)
@@ -3,9 +3,13 @@
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.log.Logbuf;
+import jp.go.aist.rtm.RTC.util.TimeValue;
import org.omg.CORBA.SystemException;
+import RTC.ReturnCode_t;
+
/**
* <p> OpenHRPExecutionContext </p>
*
@@ -19,60 +23,75 @@
*/
public OpenHRPExecutionContext() {
super();
+ m_count = 0;
}
/**
* <p> tick </p>
*/
public void tick() throws SystemException {
- synchronized (m_comps) {
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- m_comps.elementAt(intIdx).invoke();
+ if(m_workerthread.isRunning())
+ {
+ return ;
+ }
+ synchronized (m_tickmutex) {
+ m_workerthread.invokeWorkerPostDo();
+ TimeValue t0 = new TimeValue();
+ t0.convert(System.nanoTime()/1000);
+ m_workerthread.invokeWorkerDo();
+ TimeValue t1 = new TimeValue();
+ t1.convert(System.nanoTime()/1000);
+ m_workerthread.invokeWorkerPostDo();
+ TimeValue t2 = new TimeValue();
+ t2.convert(System.nanoTime()/1000);
+
+ TimeValue period = getPeriod();
+ if(m_count > 1000)
+ {
+ TimeValue t1_w = t1;
+ TimeValue t2_w = t2;
+ TimeValue t2_w2 = t2;
+ TimeValue period_w = period ;
+ rtcout.println(Logbuf.PARANOID, "Period: " + period_w + " [s]");
+ rtcout.println(Logbuf.PARANOID, "Exec-Do: " + t1_w.minus(t0) + " [s]");
+ rtcout.println(Logbuf.PARANOID, "Exec-PostDo:" + t2_w.minus(t1) + " [s]");
+ rtcout.println(Logbuf.PARANOID, "Sleep: " + period_w.minus(t2_w2.minus(t0)) + " [s]");
}
+ TimeValue t3 = new TimeValue();
+ t3.convert(System.nanoTime()/1000);
+ t2.minus(t0);
+ if( period.getUsec() > t2.getUsec() )
+ {
+ if( m_count > 1000)
+ {
+ rtcout.println(Logbuf.PARANOID, "sleeping...");
+ }
+ period.minus(t2);
+ try {
+ Thread.sleep(period.getUsec());
+ } catch (InterruptedException e){
+ e.printStackTrace();
+ }
+ }
+ if(m_count > 1000)
+ {
+ TimeValue t4 = new TimeValue();
+ t4.convert(System.nanoTime()/1000);
+ rtcout.println(Logbuf.PARANOID, "Slept: " + t4.minus(t3) + " [s]");
+ m_count = 0;
+ }
+ ++m_count ;
+ return ;
}
}
- /**
- * <p> svc </p>
- *
- * @return int
- *
- */
- public int svc() {
- return 0;
- }
-
- /**
- * <p> run </p>
- *
- *
- */
- public void run() {
- this.svc();
- }
-
- /**
- * <p> Worker </p>
- */
- private class Worker {
-
- /**
- * <p> constructor </p>
- */
- public Worker() {
- this._called = false;
- }
-
- /**
- *
- */
- public boolean _called;
- }
+ private int m_count ;
+ private String m_tickmutex = new String();
/**
*
*/
- private Worker m_worker = new Worker();
+ private ExecutionContextWorker m_workerthread = new ExecutionContextWorker();
/**
* {@.ja OpenHRPExecutionContext を生成する}
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java 2015-10-28 09:27:41 UTC (rev 737)
@@ -5,6 +5,7 @@
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.RTObject_impl;
import jp.go.aist.rtm.RTC.StateAction;
import jp.go.aist.rtm.RTC.StateHolder;
@@ -38,6 +39,12 @@
extends ExecutionContextServicePOA
implements Runnable, ObjectCreator<ExecutionContextBase>, ObjectDestructor, ExecutionContextBase {
+ TimeValue m_activationTimeout = new TimeValue(0.5);
+ TimeValue m_deactivationTimeout = new TimeValue(0.5);
+ TimeValue m_resetTimeout = new TimeValue(0.5);
+ boolean m_syncActivation = true;
+ boolean m_syncDeactivation = true;
+ boolean m_syncReset = true;
/**
* {@.ja デフォルトコンストラクタ}
@@ -56,115 +63,29 @@
public PeriodicExecutionContext() {
super();
rtcout = new Logbuf("PeriodicExecutionContext");
- m_running = false;
- m_svc = true;
+ m_svc = false;
m_nowait = false;
-
- double rate = (1.0/0.000001);//1000000Hz
-
- m_usec = (long)(1000000/rate);
-
- //m_ref = (ExecutionContextService)this.__this();
m_profile.setObjRef((ExecutionContextService)this.__this());
-
- m_profile.setPeriod(new TimeValue(1.0 / rate));
m_profile.setKind(ExecutionKind.PERIODIC);
- m_profile.setRate(1.0 / jp.go.aist.rtm.RTC.executionContext.ExecutionContextProfile.DEEFAULT_PERIOD);
-
-/*
- m_profile.kind = ExecutionKind.PERIODIC;
- m_profile.rate = 0.0;
- m_profile.owner = (RTC.RTObject)null;
- m_profile.participants = new RTC.RTObject[0];
- m_profile.properties = new _SDOPackage.NameValue[0];
-*/
+ m_profile.setRate(1000);
+ rtcout.println(Logbuf.DEBUG, "Actual period: " + m_profile.getPeriod().sec() + " [sec], "
+ + m_profile.getPeriod().usec() + " [usec]");
}
/**
- * {@.ja コンストラクタ}
- * {@.en Constructor}
- *
- * <p>
- * {@.ja 設定された値をプロファイルに設定する。}
- * {@.en Set the configuration value to profile.}
- *
- * @param owner
- * {@.ja 当該 Executioncontext の owner}
- * {@.en The owner of this Executioncontext}
- *
- */
- public PeriodicExecutionContext(DataFlowComponent owner) {
- this(owner, 1000);
- }
-
- /**
- * {@.ja コンストラクタ}
- * {@.en Constructor}
- *
- * <p>
- * {@.ja 設定された値をプロファイルに設定する。}
- * {@.en Set the configuration value to profile.}
- *
- * @param owner
- * {@.ja 当該 Executioncontext の owner}
- * {@.en The owner of this Executioncontext}
- * @param rate
- * {@.ja 動作周期(Hz)}
- * {@.en Execution cycle(Hz)}
- *
- */
- public PeriodicExecutionContext(DataFlowComponent owner, double rate) {
- super();
- rtcout = new Logbuf("PeriodicExecutionContext");
- rtcout.println(Logbuf.TRACE,
- "PeriodicExecutionContext(owner,rate="+rate+")");
- m_running = false;
- m_svc = true;
- m_nowait = true;
-
- if( rate==0 ) {
- rate = (1.0/0.000001);//1000000Hz
- }
- m_usec = (long)(1000000/rate);
- if( m_usec==0 ) {
- m_nowait = true;
- }
-
- //m_ref = (ExecutionContextService)this.__this();
- m_profile.setObjRef((ExecutionContextService)this.__this());
-
-
- m_profile.setPeriod(new TimeValue(1.0 / rate));
- m_profile.setKind(ExecutionKind.PERIODIC);
- m_profile.setRate(1.0 / jp.go.aist.rtm.RTC.executionContext.ExecutionContextProfile.DEEFAULT_PERIOD);
- m_profile.setOwner((LightweightRTObject)owner._duplicate());
-/*
- m_profile.kind = ExecutionKind.PERIODIC;
- m_profile.rate = rate;
- m_profile.owner = owner;
- m_profile.participants = new RTC.RTObject[0];
- m_profile.properties = new _SDOPackage.NameValue[0];
-*/
- }
-
- /**
* <p>終了処理用関数</p>
*/
public boolean finalizeExecutionContext() {
- synchronized (m_worker) {
- m_worker.running_ = true;
- m_worker.notifyAll();
+ synchronized (m_svcmutex) {
+ m_svc = false;
}
- m_svc = false;
- try {
- m_thread.join();
- }
- catch (InterruptedException e) {
- System.out.println(e);
- }
-
- return true;
+ synchronized (mutex_) {
+ m_workerthread.running_ = true;
+ mutex_.notifyAll();
+ }
+
+ return true;
}
/**
@@ -198,19 +119,7 @@
m_ref = ref;
}
- /**
- * <p> getObjRef </p>
- *
- * @return ExecutionContextService
- */
-/*
- public ExecutionContextService getObjRef() {
- rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.getObjRef()");
-
- return m_ref;
- }
-*/
/**
* <p>本オブジェクトのExecutionContextServiceとしてのCORBAオブジェクト参照を設定します。</p>
*
@@ -229,7 +138,6 @@
public int open() {
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.open()");
-
if(m_thread==null) {
m_thread = new Thread(this, "PeriodicExecutionContext");
m_thread.start();
@@ -242,37 +150,60 @@
* 登録されたコンポーネントの処理を呼び出します。</p>
*/
public int svc() {
-
+ int count = 0 ;
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.svc()");
do {
- synchronized (m_worker) {
- while (!m_worker.running_) {
+
+ m_workerthread.invokeWorkerPreDo();
+ synchronized (mutex_) {
+ while (!m_workerthread.running_) {
try {
- m_worker.wait();
+ mutex_.wait();
} catch (InterruptedException e) {
break;
}
- }
- if (m_worker.running_) {
- for (int intIdx=0; intIdx < m_comps.size(); ++intIdx) {
- m_comps.get(intIdx).invoke_work_pre();
- m_comps.get(intIdx).invoke_work_do();
- m_comps.get(intIdx).invoke_work_post();
- }
- }
- }
- if( !m_nowait ) {
- long millisec = m_usec / 1000;
- int nanosec = (int)((m_usec % 1000) * 1000);
+ }
+ }
+ TimeValue t0 = new TimeValue();
+ t0.convert(System.nanoTime()/1000);
+ m_workerthread.invokeWorkerDo();
+ m_workerthread.invokeWorkerPostDo();
+ TimeValue t1 = new TimeValue();
+ t1.convert(System.nanoTime()/1000);
+
+ 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]");
+ }
+ TimeValue t2 = new TimeValue();
+ t2.convert(System.nanoTime()/1000);
+ if( !m_nowait && period.getUsec() > 0)
+ {
+ if(count > 1000)
+ {
+ rtcout.println(Logbuf.PARANOID, "sleeping...");
+ }
try {
- Thread.sleep(millisec, nanosec);
- } catch (InterruptedException e) {
+ Thread.sleep(period.getUsec());
+ } catch (InterruptedException e){
e.printStackTrace();
}
}
- } while( m_svc );
- return 0;
+ 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);
+
+ return 0;
}
/**
@@ -310,10 +241,230 @@
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.is_running()");
- return m_running;
+ return m_workerthread.isRunning();
}
+ public ReturnCode_t onStarting() { return ReturnCode_t.RTC_OK; }
+ //============================================================
+ // protected functions
+ //============================================================
+ /*!
+ * @brief onStarted() template function
+ */
+ public ReturnCode_t onStarted()
+ {
+ // change EC thread state
+ synchronized (m_svcmutex){
+ if (!m_svc)
+ { // If start() is called first time, start the worker thread.
+ m_svc = true;
+ this.open();
+ }
+ }
+ if(m_workerthread.isAllNextState(LifeCycleState.INACTIVE_STATE))
+ {
+ synchronized(mutex_)
+ {
+ m_workerthread.running_ = false ;
+ }
+ }
+ else
+ {
+ synchronized (mutex_) {
+ m_workerthread.running_ = true ;
+ mutex_.notifyAll();
+ }
+ }
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onStopping()
+ {
+ synchronized (mutex_) {
+ m_workerthread.running_ = false ;
+ return ReturnCode_t.RTC_OK;
+ }
+ }
+ public ReturnCode_t onStopped()
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public double onGetRate(double rate)
+ {
+ return rate;
+ }
+ public double onSettingRate(double rate)
+ {
+ return rate;
+ }
+ public ReturnCode_t onSetRate(double rate)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onAddingComponent(LightweightRTObject rtobj)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onAddedComponent(LightweightRTObject rtobj)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onRemovingComponent(LightweightRTObject rtobj)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onRemovedComponent(LightweightRTObject rtobj)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+
+ // template virtual functions related to activation/deactivation/reset
+ public ReturnCode_t onActivating(LightweightRTObject comp)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onActivated(RTObjectStateMachine comp, long count)
+ {
+ rtcout.println(Logbuf.TRACE,
+ "PeriodicExecutionContext.onActivated(count = " + count +")");
+// rtcout.println(Logbuf.PARANOID,
+// "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_) {
+ if(m_workerthread.running_ == false)
+ {
+ m_workerthread.running_ = true ;
+ mutex_.notifyAll();
+ }
+ return ReturnCode_t.RTC_OK;
+ }
+ }
+ public ReturnCode_t onDeactivating(LightweightRTObject comp)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onDeactivated(RTObjectStateMachine comp, long count)
+ {
+ rtcout.println(Logbuf.TRACE,
+ "PeriodicExecutionContext.onDeactivated(count = " + count +")");
+// rtcout.println(Logbuf.PARANOID,
+// "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))
+ {
+ synchronized (mutex_) {
+ if(m_workerthread.running_ == true)
+ {
+ m_workerthread.running_ = false ;
+ rtcout.println(Logbuf.TRACE, "All RTCs are INACTIVE. Stopping worker thread.");
+ }
+ }
+ }
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onResetting(LightweightRTObject comp)
+ {
+ return ReturnCode_t.RTC_OK;
+ }
+ public ReturnCode_t onReset(RTObjectStateMachine comp, long count)
+ {
+ rtcout.println(Logbuf.TRACE,
+ "PeriodicExecutionContext.onReset(count = " + count +")");
+// rtcout.println(Logbuf.PARANOID,
+// "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))
+ {
+ synchronized (mutex_) {
+ if(m_workerthread.running_ == true)
+ {
+ m_workerthread.running_ = false ;
+ rtcout.println(Logbuf.TRACE, "All RTCs are INACTIVE. Stopping worker thread.");
+ }
+ }
+ }
+ return ReturnCode_t.RTC_OK;
+ }
+
+ public LifeCycleState onGetComponentState(LifeCycleState state)
+ {
+ return state;
+ }
+ public ExecutionKind onGetKind(ExecutionKind kind)
+ {
+ return kind;
+ }
+ public ExecutionContextProfile onGetProfile(ExecutionContextProfile profile)
+ {
+ return profile;
+ }
+
/**
+ * {@.ja onWaitingActivated() template function}
+ * {@.en onWaitingActivated() template function}
+ */
+ public ReturnCode_t onWaitingActivated(RTObjectStateMachine comp, long count)
+ {
+ rtcout.println(Logbuf.TRACE,
+ "PeriodicExecutionContext.onWaitingActivated(count = " + count +")");
+// rtcout.println(Logbuf.PARANOID,
+// "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_) {
+ if(m_workerthread.running_ == false)
+ {
+ m_workerthread.running_ = true ;
+ mutex_.notifyAll();
+ }
+ return ReturnCode_t.RTC_OK;
+ }
+ }
+
+
+ /*!
+ * @brief onWaitingDeactivated() template function
+ */
+ public ReturnCode_t onWaitingDeactivated(RTObjectStateMachine comp, long count)
+ {
+ rtcout.println(Logbuf.TRACE,
+ "PeriodicExecutionContext.onWaitingDeactivated(count = " + count +")");
+ if(m_workerthread.isAllNextState(LifeCycleState.INACTIVE_STATE))
+ {
+ synchronized (mutex_) {
+ if(m_workerthread.running_ == true)
+ {
+ m_workerthread.running_ = false ;
+ rtcout.println(Logbuf.TRACE, "All RTCs are INACTIVE. Stopping worker thread.");
+ }
+ }
+ }
+ return ReturnCode_t.RTC_OK;
+ }
+
+ /*!
+ * @brief onWaitingReset() template function
+ */
+ public ReturnCode_t onWaitingReset(RTObjectStateMachine comp, long count)
+ {
+ rtcout.println(Logbuf.TRACE,
+ "PeriodicExecutionContext.onWaitingReset(count = " + count +")");
+ if(m_workerthread.isAllNextState(LifeCycleState.INACTIVE_STATE))
+ {
+ synchronized (mutex_) {
+ if(m_workerthread.running_ == true)
+ {
+ m_workerthread.running_ = false ;
+ rtcout.println(Logbuf.TRACE, "All RTCs are INACTIVE. Stopping worker thread.");
+ }
+ }
+ }
+ return ReturnCode_t.RTC_OK;
+ }
+
+ /**
* <p>ExecutionContext をスタートします。</p>
*
* @return 実行結果
@@ -322,22 +473,27 @@
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.start()");
- if( m_running ) return ReturnCode_t.PRECONDITION_NOT_MET;
-
- // invoke ComponentAction::on_startup for each comps.
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- m_comps.elementAt(intIdx).invoke_on_startup();
+ ReturnCode_t ret = onStarting();
+ if( ret != ReturnCode_t.RTC_OK )
+ {
+ rtcout.println(Logbuf.ERROR, "onStarting() failed. Starting EC aborted.");
+ return ret;
}
- // change EC thread state
- m_running = true;
- synchronized (m_worker) {
- m_worker.running_ = true;
- m_worker.notifyAll();
+ ret = m_workerthread.start();
+ if(ret!=ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "Invoking on_startup() for each RTC failed.");
+ return ret;
}
-
- this.open();
-
- return ReturnCode_t.RTC_OK;
+ ret = onStarted();
+ if(ret!=ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "Invoking on_startup() for each RTC failed.");
+ m_workerthread.stop();
+ rtcout.println(Logbuf.ERROR, "on_shutdown() was invoked, because of on_startup");
+ return ret;
+ }
+ return ret;
}
/**
@@ -349,20 +505,25 @@
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.stop()");
- if( !m_running ) return ReturnCode_t.PRECONDITION_NOT_MET;
-
- // change EC thread state
- m_running = false;
- synchronized (m_worker) {
- m_worker.running_ = false;
- }
-
- // invoke on_shutdown for each comps.
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- m_comps.elementAt(intIdx).invoke_on_shutdown();
+ ReturnCode_t ret = onStopping(); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "onStopping() failed. Stopping EC aborted.");
+ return ret;
}
-
- return ReturnCode_t.RTC_OK;
+ ret = m_workerthread.stop(); // Actual stop()
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "Invoking on_shutdown() for each RTC failed.");
+ return ret;
+ }
+ ret = onStopped(); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "Invoking on_shutdown() for each RTC failed.");
+ return ret;
+ }
+ return ret;
}
/**
@@ -376,6 +537,11 @@
return m_profile.getRate();
}
+ public TimeValue getPeriod()
+ {
+ TimeValue period = m_profile.getPeriod();
+ return period;
+ }
/**
* <p>ExecutionContextの実行周期(Hz)を設定します。</p>
@@ -388,20 +554,20 @@
if( rate<=0.0 ) return ReturnCode_t.BAD_PARAMETER;
- m_profile.setRate(rate);
- this.m_usec = (long)(1000000/rate);
- if( m_usec == 0 ) {
- m_nowait = true;
+ ReturnCode_t ret = m_profile.setRate(onSettingRate(rate));
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "Setting execution rate failed. " + rate);
+ return ret;
}
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- m_comps.elementAt(intIdx).invoke_on_rate_changed();
+ ret = onSetRate(rate);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR, "onSetRate("+ rate +") failed.");
+ return ret;
}
- rtcout.println(Logbuf.DEBUG, "Actual period: "
- + m_profile.getPeriod().sec()
- + " [sec], "
- + m_profile.getPeriod().usec()
- + " [usec]");
- return ReturnCode_t.RTC_OK;
+ rtcout.println(Logbuf.INFO, "onSetRate("+ rate +") done.");
+ return ret;
}
/**
@@ -414,21 +580,89 @@
public ReturnCode_t activate_component(LightweightRTObject comp) {
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.activate_component()");
+ return activateComponent(comp);
+ }
+ public ReturnCode_t activateComponent(LightweightRTObject comp) {
- // コンポーネントが参加者リストに無ければ BAD_PARAMETER を返す
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- find_comp find = new find_comp((LightweightRTObject)comp._duplicate());
- if (find.eqaulof(m_comps.elementAt(intIdx)) ) {
- // the given component must be in Alive state.
- if(!(m_comps.elementAt(intIdx)._sm.m_sm.isIn(LifeCycleState.INACTIVE_STATE))) {
- return ReturnCode_t.PRECONDITION_NOT_MET;
- }
- m_comps.elementAt(intIdx)._sm.m_sm.goTo(LifeCycleState.ACTIVE_STATE);
- return ReturnCode_t.RTC_OK;
+ 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()
+ if (ret != ReturnCode_t.RTC_OK) { return ret; }
+ if (!m_syncActivation) // Asynchronous activation mode
+ {
+ ret = onActivated(rtobj, -1);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onActivated() failed.");
}
+ return ret;
}
- return ReturnCode_t.BAD_PARAMETER;
+ //------------------------------------------------------------
+ // Synchronized activation mode
+ rtcout.println(Logbuf.DEBUG,"Synchronous activation mode. "
+ +"Waiting for the RTC to be ACTIVE state. ");
+ return waitForActivated(rtobj);
}
+ public ReturnCode_t waitForActivated(RTObjectStateMachine rtobj)
+ {
+ long count =0 ;
+ ReturnCode_t ret = onWaitingActivated(rtobj, count);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingActivated failed.");
+ return ret;
+ }
+ 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
+ TimeValue starttime = new TimeValue();
+ starttime.convert(System.nanoTime()/1000);
+ while (rtobj.isCurrentState(LifeCycleState.INACTIVE_STATE))
+ {
+ ret = onWaitingActivated(rtobj, count); // Template method
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingActivated failed.");
+ return ret;
+ }
+ try
+ {
+ Thread.sleep(getPeriod().getUsec());
+ }catch(InterruptedException e){}
+ TimeValue delta= new TimeValue();
+ delta.convert(System.nanoTime()/1000);
+ 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)
+ {
+ rtcout.println(Logbuf.WARN,"The component is not responding.");
+ break;
+ }
+ }
+ // Now State must be ACTIVE or ERROR
+ if (rtobj.isCurrentState(LifeCycleState.INACTIVE_STATE))
+ {
+ rtcout.println(Logbuf.ERROR,"Unknown error: Invalid state transition.");
+ return ReturnCode_t.RTC_ERROR;
+ }
+ rtcout.println(Logbuf.DEBUG,"Current state is " + rtobj.getState());
+ ret = onActivated(rtobj, count); // Template method
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onActivated() failed.");
+ }
+ rtcout.println(Logbuf.DEBUG,"onActivated() done.");
+ return ret;
+ }
/**
* <p>コンポーネントを非アクティブ化します。</p>
@@ -440,20 +674,89 @@
public ReturnCode_t deactivate_component(LightweightRTObject comp) {
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.deactivate_component()");
-
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- find_comp find = new find_comp((LightweightRTObject)comp._duplicate());
- if (find.eqaulof(m_comps.elementAt(intIdx)) ) {
- // the given component must be in Alive state.
- if(!(m_comps.elementAt(intIdx)._sm.m_sm.isIn(LifeCycleState.ACTIVE_STATE))) {
- return ReturnCode_t.PRECONDITION_NOT_MET;
- }
- m_comps.elementAt(intIdx)._sm.m_sm.goTo(LifeCycleState.INACTIVE_STATE);
- return ReturnCode_t.RTC_OK;
+ return deactivateComponent(comp);
+ }
+ public ReturnCode_t deactivateComponent(LightweightRTObject comp)
+ {
+ rtcout.println(Logbuf.TRACE,"PeriodicExecutionContext.deactivateComponent()");
+ ReturnCode_t ret = onDeactivating(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onDeactivatingComponent() failed.");
+ return ret;
+ }
+ // Deactivate all the RTCs
+ RTObjectStateMachine rtobj = null;
+ ret = m_workerthread.deactivateComponent(comp, rtobj);
+ if (ret != ReturnCode_t.RTC_OK) { return ret; }
+ if (!m_syncDeactivation)
+ {
+ ret = onDeactivated(rtobj, -1);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onDeactivated() failed.");
}
+ return ret;
}
- return ReturnCode_t.BAD_PARAMETER;
+ //------------------------------------------------------------
+ // Waiting for synchronized deactivation
+ rtcout.println(Logbuf.DEBUG,"Synchronous deactivation mode. "
+ +"Waiting for the RTC to be INACTIVE state. ");
+ return waitForDeactivated(rtobj);
}
+ public ReturnCode_t waitForDeactivated(RTObjectStateMachine rtobj)
+ {
+ long count = 0;
+ ReturnCode_t ret = onWaitingDeactivated(rtobj, count);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingDeactivated failed.");
+ return ret;
+ }
+ long cycle =
+ (long )(m_deactivationTimeout.toDouble() / getPeriod().toDouble());
+ 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);
+ while (rtobj.isCurrentState(LifeCycleState.ACTIVE_STATE))
+ {
+ ret = onWaitingDeactivated(rtobj, count); // Template method
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingDeactivated failed.");
+ return ret;
+ }
+ try
+ {
+ Thread.sleep(getPeriod().getUsec());
+ }catch(InterruptedException e){}
+ TimeValue delta = new TimeValue();
+ delta.convert(System.nanoTime()/1000);
+ 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)
+ {
+ rtcout.println(Logbuf.WARN,"The component is not responding.");
+ break;
+ }
+ }
+ // Now State must be INACTIVE or ERROR
+ if (rtobj.isCurrentState(LifeCycleState.ACTIVE_STATE))
+ {
+ rtcout.println(Logbuf.ERROR,"Unknown error: Invalid state transition.");
+ return ReturnCode_t.RTC_ERROR;
+ }
+ rtcout.println(Logbuf.DEBUG,"Current state is "+ rtobj.getState());
+ ret = onDeactivated(rtobj, count);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onDeactivated() failed.");
+ }
+ rtcout.println(Logbuf.DEBUG,"onDeactivated() done.");
+ return ret;
+ }
/**
* <p>コンポーネントをリセットします。</p>
@@ -465,20 +768,89 @@
public ReturnCode_t reset_component(LightweightRTObject comp){
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.reset_component()");
+ return reset_component(comp);
+ }
+ public ReturnCode_t resetCcomponent(LightweightRTObject comp){
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- find_comp find = new find_comp((LightweightRTObject)comp._duplicate());
- if (find.eqaulof(m_comps.elementAt(intIdx)) ) {
- // the given component must be in Alive state.
- if(!(m_comps.elementAt(intIdx)._sm.m_sm.isIn(LifeCycleState.ERROR_STATE))) {
- return ReturnCode_t.PRECONDITION_NOT_MET;
- }
- m_comps.elementAt(intIdx)._sm.m_sm.goTo(LifeCycleState.INACTIVE_STATE);
- return ReturnCode_t.RTC_OK;
+ rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.resetComponent()");
+
+ ReturnCode_t ret = onResetting(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onResetting() failed.");
+ return ret;
+ }
+ RTObjectStateMachine rtobj = null;
+ ret = m_workerthread.resetComponent(comp, rtobj); // Actual resetComponent()
+ if (ret != ReturnCode_t.RTC_OK) { return ret; }
+ if (!m_syncReset)
+ {
+ ret = onReset(rtobj, -1);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onReset() failed.");
}
+ return ret;
}
- return ReturnCode_t.BAD_PARAMETER;
+ //------------------------------------------------------------
+ // Waiting for synchronized reset
+ rtcout.println(Logbuf.DEBUG,"Synchronous reset mode. "
+ +"Waiting for the RTC to be INACTIVE state. ");
+ return waitForReset(rtobj);
}
+ public ReturnCode_t waitForReset(RTObjectStateMachine rtobj)
+ {
+ long count = 0;
+ ReturnCode_t ret = onWaitingReset(rtobj, count);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingReset() failed.");
+ return ret;
+ }
+ long cycle =
+ (long )(m_resetTimeout.toDouble() / getPeriod().toDouble());
+ 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);
+ while (rtobj.isCurrentState(LifeCycleState.ERROR_STATE))
+ {
+ ret = onWaitingReset(rtobj, count); // Template method
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onWaitingReset failed.");
+ return ret;
+ }
+ try
+ {
+ Thread.sleep(getPeriod().getUsec());
+ }catch(InterruptedException e){}
+ TimeValue delta = new TimeValue();
+ delta.convert(System.nanoTime()/1000);
+ 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)
+ {
+ rtcout.println(Logbuf.WARN,"The component is not responding.");
+ break;
+ }
+ }
+ // Now State must be INACTIVE
+ if (rtobj.isCurrentState(LifeCycleState.INACTIVE_STATE))
+ {
+ rtcout.println(Logbuf.ERROR,"Unknown error: Invalid state transition.");
+ return ReturnCode_t.RTC_ERROR;
+ }
+ rtcout.println(Logbuf.DEBUG,"Current state is "+ rtobj.getState());
+ ret = onReset(rtobj, count);
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"onReset() failed.");
+ }
+ rtcout.println(Logbuf.DEBUG,"onReset() done.");
+ return ret;
+ }
/**
* <p>コンポーネントの状態を取得します。</p>
@@ -490,14 +862,18 @@
public LifeCycleState get_component_state(LightweightRTObject comp) {
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.get_component_state()");
+ return getComponentState(comp);
+ }
+ public LifeCycleState getComponentState(LightweightRTObject comp) {
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- find_comp find = new find_comp((LightweightRTObject)comp._duplicate());
- if (find.eqaulof(m_comps.elementAt(intIdx)) ) {
- return m_comps.elementAt(intIdx)._sm.m_sm.getState();
- }
+ LifeCycleState state = m_workerthread.getComponentState(comp);
+ rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.getComponentState() = " + state);
+ if (state == LifeCycleState.CREATED_STATE)
+ {
+ rtcout.println(Logbuf.ERROR,"CREATED state: not initialized "
+ +"RTC or unknwon RTC specified.");
}
- return LifeCycleState.CREATED_STATE;
+ return onGetComponentState(state);
}
/**
@@ -510,8 +886,16 @@
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.get_kind() ="
+ m_profile.getKindString());
- return m_profile.getKind();
+ return getKind();
}
+ public ExecutionKind getKind()
+ {
+ ExecutionKind kind = m_profile.getKind();
+ rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.getKind() = " + getKindString(kind));
+ kind = onGetKind(kind);
+ rtcout.println(Logbuf.DEBUG,"onGetKind() returns " + getKindString(kind));
+ return kind;
+ }
/**
* {@.ja RTコンポーネントを追加する}
@@ -544,35 +928,42 @@
rtcout.println(Logbuf.TRACE,
"PeriodicExecutionContext.add_component()");
+ return addComponent(comp);
+ }
+ public ReturnCode_t addComponent(LightweightRTObject comp) {
- if( comp==null ) return ReturnCode_t.BAD_PARAMETER;
- //
- try {
- DataFlowComponent dfp = DataFlowComponentHelper.narrow(comp);
- if( dfp==null ) {
- // Because the ExecutionKind of this context is PERIODIC,
- // the RTC must be a data flow component.
- return ReturnCode_t.BAD_PARAMETER;
- }
- //
- //int id = dfp.attach_context(m_ref);
- ExecutionContextService ec = m_profile.getObjRef();
- int id = dfp.attach_context(ec);
- //
- m_comps.add(new Comp((LightweightRTObject)comp._duplicate(),
- (DataFlowComponent)dfp._duplicate(), id));
- m_profile.addComponent((LightweightRTObject)comp._duplicate());
-/*
- RTC.RTCListHolder holder
- = new RTC.RTCListHolder(m_profile.participants);
- CORBA_SeqUtil.push_back(holder,
- RTC.RTObjectHelper.narrow(comp));
- m_profile.participants = holder.value;
-*/
- return ReturnCode_t.RTC_OK;
- } catch(Exception ex) {
- return ReturnCode_t.BAD_PARAMETER;
+ rtcout.println(Logbuf.TRACE,
+ "PeriodicExecutionContext.addcomponent()");
+
+ ReturnCode_t ret = onAddingComponent(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: onAddingComponent(). RTC is not attached.");
+ return ret;
}
+ ret = m_workerthread.addComponent(comp); // Actual addComponent()
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: ECWorker addComponent() faild.");
+ return ret;
+ }
+ ret = m_profile.addComponent(comp); // Actual addComponent()
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: ECProfile addComponent() faild.");
+ return ret;
+ }
+ ret = onAddedComponent(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: onAddedComponent() faild.");
+ rtcout.println(Logbuf.INFO,"Removing attached RTC.");
+ m_workerthread.removeComponent(comp);
+ m_profile.removeComponent(comp);
+ return ret;
+ }
+ rtcout.println(Logbuf.INFO,"Component has been added to this EC.");
+ return ret;
}
/**
@@ -595,28 +986,7 @@
rtcout.println(Logbuf.TRACE,
"PeriodicExecutionContext.bindComponent()");
-
- if (rtc == null) return ReturnCode_t.BAD_PARAMETER;
-
- LightweightRTObject comp = rtc.getObjRef();
- DataFlowComponent dfp;
- dfp = DataFlowComponentHelper.narrow(comp);
-
- ExecutionContextService ec = m_profile.getObjRef();
- int id = rtc.bindContext(ec);
- //int id = rtc.bindContext(m_ref);
- if (id < 0 || id > RTObject_impl.ECOTHER_OFFSET) {
- rtcout.println(Logbuf.ERROR, "bindContext returns invalid id: "+id);
- return ReturnCode_t.RTC_ERROR;
- }
- rtcout.println(Logbuf.DEBUG, "bindComponent() returns id = "+id);
- m_comps.add(new Comp((LightweightRTObject)comp._duplicate(),
- (DataFlowComponent)dfp._duplicate(),
- id));
- m_profile.setOwner((LightweightRTObject)dfp._duplicate());
-
-
- return ReturnCode_t.RTC_OK;
+ return m_workerthread.bindComponent(rtc);
}
/**
@@ -648,23 +1018,42 @@
rtcout.println(Logbuf.TRACE,
"PeriodicExecutionContext.remove_component()");
+ return removeComponent(comp);
+ }
+ public ReturnCode_t removeComponent(LightweightRTObject comp) {
- for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
- find_comp find
- = new find_comp((LightweightRTObject)comp._duplicate());
- if (find.eqaulof(m_comps.elementAt(intIdx)) ) {
- m_comps.elementAt(intIdx)._ref.detach_context(
- m_comps.elementAt(intIdx)._sm.ec_id);
- m_comps.elementAt(intIdx)._ref = null;
- m_comps.remove(m_comps.elementAt(intIdx));
- rtcout.println(Logbuf.TRACE,
- "remove_component(): an RTC removed from this context.");
- m_profile.removeComponent(comp);
- return ReturnCode_t.RTC_OK;
- }
+ rtcout.println(Logbuf.TRACE,
+ "PeriodicExecutionContext.removeComponent()");
+ ReturnCode_t ret = onRemovingComponent(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: onRemovingComponent(). "
+ +"RTC will not not attached.");
+ return ret;
}
- rtcout.println(Logbuf.TRACE, "remove_component(): no RTC found in this context.");
- return ReturnCode_t.BAD_PARAMETER;
+ ret = m_workerthread.removeComponent(comp); // Actual removeComponent()
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: ECWorker removeComponent() faild.");
+ return ret;
+ }
+ ret = m_profile.removeComponent(comp); // Actual removeComponent()
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: ECProfile removeComponent() faild.");
+ return ret;
+ }
+ ret = onRemovedComponent(comp); // Template
+ if (ret != ReturnCode_t.RTC_OK)
+ {
+ rtcout.println(Logbuf.ERROR,"Error: onRemovedComponent() faild.");
+ rtcout.println(Logbuf.INFO,"Removing attached RTC.");
+ m_workerthread.removeComponent(comp);
+ m_profile.removeComponent(comp);
+ return ret;
+ }
+ rtcout.println(Logbuf.INFO,"Component has been removeed to this EC.");
+ return ret;
}
//============================================================
@@ -1053,19 +1442,15 @@
* <p>ExecutionContext のスレッド実行フラグです。</p>
*/
private boolean m_svc;
+ private String m_svcmutex = new String();
- protected class Worker {
- public Worker() {
- this.running_ = false;
- }
-
private boolean running_;
+ private String mutex_ = new String() ;
- };
// A condition variable for external triggered worker
- private Worker m_worker = new Worker();
+ private ExecutionContextWorker m_workerthread = new ExecutionContextWorker();
/**
* <p>ExecutionContextProfileです。</p>
@@ -1081,6 +1466,7 @@
protected ExecutionContextService m_ref;
protected boolean m_nowait;
protected Thread m_thread = null;
+ protected boolean ticked_;
/**
* <p>このExecutionContextを生成するFactoryクラスを
@@ -1161,6 +1547,7 @@
public void init(Properties props) {
}
+
/**
* {@.ja CORBA オブジェクト参照の取得}
* {@.en Get the reference to the CORBA object}
@@ -1175,25 +1562,6 @@
* {@.en The reference to CORBA object}
*
*/
-/*
- public void setObjRef(final ExecutionContextService ref) {
- m_profile.setObjRef(ref);
- }
-*/
- /**
- * {@.ja CORBA オブジェクト参照の取得}
- * {@.en Get the reference to the CORBA object}
- * <p>
- * {@.ja 本オブジェクトの ExecutioncontextService としての CORBA オブジェ
- * クト参照を取得する。}
- * {@.en Get the reference to the CORBA object as
- * ExecutioncontextService of this object.}
- *
- * @return
- * {@.ja CORBA オブジェクト参照}
- * {@.en The reference to CORBA object}
- *
- */
public ExecutionContextService getObjRef() {
return m_profile.getObjRef();
}
@@ -1382,4 +1750,54 @@
public RTC.ExecutionContextProfile getProfile(){
return m_profile.getProfile();
}
+ public boolean setTimeout(Properties props, String key,TimeValue timevalue)
+ {
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.setTimeout(" + key +")");
+ if (props.findNode(key) != null)
+ {
+ timevalue.convert(Double.valueOf(props.getNode(key).getValue())) ;
+ rtcout.println(Logbuf.DEBUG, "Timeout (" + key +"): " + props.getNode(key).getValue() + " [s]");
+ return true;
+ }
+ rtcout.println(Logbuf.DEBUG, "Configuration " + key +" not found.");
+ return false;
+ }
+ /*!
+ * @if jp
+ * @brief Propertiesから実行コンテキストをセットする
+ * @else
+ * @brief Setting execution rate from given properties.
+ * @endif
+ */
+ public boolean setExecutionRate(Properties props)
+ {
+ if (props.findNode("rate") != null)
+ {
+ double rate;
+ rate = Double.valueOf(props.getNode("rate").getValue());
+ setRate(rate);
+ return true;
+ }
+ return false;
+ }
+ /*!
+ * @if jp
+ * @brief Propertiesから状態遷移Timeoutをセットする
+ * @else
+ * @brief Setting state transition timeout from given properties.
+ * @endif
+ */
+ public boolean setTransitionMode(Properties props, String key, boolean flag)
+ {
+ 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"));
+ return true;
+ }
+ rtcout.println(Logbuf.DEBUG, "Configuration " + key +" not found.");
+ return false;
+ }
+
}
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/AllTest110.java
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/AllTest110.java 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/AllTest110.java 2015-10-28 09:27:41 UTC (rev 737)
@@ -4,6 +4,8 @@
import jp.go.aist.rtm.RTC.log.LogbufTest;
import jp.go.aist.rtm.RTC.util.AdjustedClockTest;
import jp.go.aist.rtm.RTC.util.TimeValueTest;
+import jp.go.aist.rtm.RTC.buffer.RingBufferTest;
+import jp.go.aist.rtm.RTC.executionContext.*;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -17,6 +19,9 @@
suite.addTestSuite(AdjustedClockTest.class);
suite.addTestSuite(LogBufTimeTest.class);
+ suite.addTestSuite(RingBufferTest.class);
+ suite.addTestSuite(ExtTrigExecutionContextTests.class);
+ suite.addTestSuite(PeriodicExecutionContextTests.class);
return suite;
}
Modified: branches/RELENG_1_1/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/RTC/log/LogBufTimeTest.java
===================================================================
--- branches/RELENG_1_1/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/RTC/log/LogBufTimeTest.java 2015-10-28 09:02:58 UTC (rev 736)
+++ branches/RELENG_1_1/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/RTC/log/LogBufTimeTest.java 2015-10-28 09:27:41 UTC (rev 737)
@@ -29,7 +29,7 @@
// Junit出力ファイル*.xmlの <system-err>の欄に出力される
System.err.println("--- test_case0() adjusted ---");
rtcout.println(Logbuf.PARANOID, "PARANOID string to STDOUT 2");
- rtcout.setDateFormat("%b %d %H:%M:%S.%L %q");
+ rtcout.setDateFormat("%b %d %H:%M:%S.%Q %q");
rtcout.println(Logbuf.VERBOSE, "VERBOSE string to STDOUT 2");
rtcout.println(Logbuf.TRACE, "TRACE string to STDOUT 2");
rtcout.println(Logbuf.DEBUG, "DEBUG string to STDOUT 2");
@@ -43,9 +43,9 @@
System.err.println("--- test_case0() system ---");
rtcout.setClockType("system");
- rtcout.setDateFormat("%b %d %H:%M:%S.%L");
+ rtcout.setDateFormat("%b %d %H:%M:%S.%Q");
rtcout.println(Logbuf.PARANOID, "PARANOID string to STDOUT 2");
- rtcout.setDateFormat("%b %d %H:%M:%S.%L %q");
+ rtcout.setDateFormat("%b %d %H:%M:%S.%Q %q");
rtcout.println(Logbuf.VERBOSE, "VERBOSE string to STDOUT 2");
rtcout.println(Logbuf.TRACE, "TRACE string to STDOUT 2");
rtcout.println(Logbuf.DEBUG, "DEBUG string to STDOUT 2");
More information about the openrtm-commit
mailing list