[openrtm-commit:00695] r661 - in trunk: . 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
openrtm @ openrtm.org
openrtm @ openrtm.org
2012年 2月 10日 (金) 18:36:41 JST
Author: fsi-katami
Date: 2012-02-10 18:36:40 +0900 (Fri, 10 Feb 2012)
New Revision: 661
Added:
trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextFactory.java
trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextProfile.java
trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/IExecutionContextBase.java
Removed:
trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/CorbaObjectManager.java
Modified:
trunk/
trunk/jp.go.aist.rtm.RTC/
trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryGlobal.java
trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/Manager.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/ExtTrigExecutionContext.java
trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/OpenHRPExecutionContext.java
trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java
Log:
merge refs #2322
Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/RELENG_1_0_0:60-401
/branches/work/ConfigurationCallback:631-635
/branches/work/ForComponentActionListener:521-522
/branches/work/ForComponentObserverConsumer:534-543
/branches/work/ForConfigurationListener:524-526
/branches/work/ForFileNameservice:623-628
/branches/work/ForLogFormat:518-519
/branches/work/ForPortConnectListener:528-532
/branches/work/ForSDOServiceAdminClass:505-507
/branches/work/SourceSharing:591-603
/branches/work/ToGetProperties:545-548
/branches/work/ToIFR_ID:509-514
+ /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/ForFileNameservice:623-628
/branches/work/ForLogFormat:518-519
/branches/work/ForPortConnectListener:528-532
/branches/work/ForSDOServiceAdminClass:505-507
/branches/work/SourceSharing:591-603
/branches/work/ToGetProperties:545-548
/branches/work/ToIFR_ID:509-514
Property changes on: trunk/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/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/ForFileNameservice/jp.go.aist.rtm.RTC:623-628
/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/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
+ /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/ForFileNameservice/jp.go.aist.rtm.RTC:623-628
/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/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
Deleted: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/CorbaObjectManager.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/CorbaObjectManager.java 2012-02-10 08:03:08 UTC (rev 660)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/CorbaObjectManager.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -1,81 +0,0 @@
-package jp.go.aist.rtm.RTC;
-
-import jp.go.aist.rtm.RTC.executionContext.ExecutionContextBase;
-
-import org.omg.CORBA.ORB;
-import org.omg.PortableServer.POA;
-import org.omg.PortableServer.Servant;
-import org.omg.PortableServer.POAPackage.ObjectNotActive;
-import org.omg.PortableServer.POAPackage.ServantAlreadyActive;
-import org.omg.PortableServer.POAPackage.ServantNotActive;
-import org.omg.PortableServer.POAPackage.WrongPolicy;
-
-import RTC.ExecutionContextServiceHelper;
-import RTC.RTObjectHelper;
-
-
-/**
- * <p>CorbaObjectManagerクラスです。
- * CORBA オブジェクトをアクティブ化、非アクティブ化します。</p>
- */
-class CorbaObjectManager {
- /**
- * <p>コンストラクタです。</p>
- *
- * @param orb ORB
- * @param poa POA
- */
- public CorbaObjectManager(ORB orb, POA poa) {
- m_pPOA = poa;
- }
-
- /**
- * <p>CORBA オブジェクト(RTObjct)をアクティブ化します。</p>
- *
- * @param comp アクティブ化対象RTObject
- *
- * @exception ServantAlreadyActive 対象Servantがすでにactivate済み
- * @exception WrongPolicy POA でサポートされていないポリシーを使用
- * @exception ObjectNotActive 指定された oid を持つオブジェクトが Active Object Map にない場合
- */
- public void activate(RTObject_impl comp)
- throws ServantAlreadyActive, WrongPolicy, ObjectNotActive {
- if( comp.m_objref==null ) {
- byte[] id = m_pPOA.activate_object(comp);
- comp.setObjRef(RTObjectHelper.narrow(m_pPOA.id_to_reference(id)));
- }
- }
-
- /**
- * <p>CORBA オブジェクト(ExecutionContext)をアクティブ化します。</p>
- *
- * @param comp アクティブ化対象ExecutionContext
- *
- * @exception ServantAlreadyActive 対象Servantがすでにactivate済み
- * @exception WrongPolicy POA でサポートされていないポリシーを使用
- * @exception ObjectNotActive 指定された oid を持つオブジェクトが Active Object Map にない場合
- */
- public void activate(ExecutionContextBase comp) throws ServantAlreadyActive, WrongPolicy, ObjectNotActive {
- byte[] id = m_pPOA.activate_object(comp);
- comp.setObjRef(ExecutionContextServiceHelper.narrow(m_pPOA.id_to_reference(id)));
- }
- /**
- * <p>CORBA オブジェクトを非アクティブ化します。</p>
- *
- * @param comp 非アクティブ化対象オブジェクト
- *
- * @exception ServantAlreadyActive 対象Servantがactivate化されていない
- * @exception WrongPolicy POA でサポートされていないポリシーを使用
- * @exception ObjectNotActive 指定された oid を持つオブジェクトが Active Object Map にない場合
- *
- */
- public void deactivate(Servant comp) throws ServantNotActive, WrongPolicy, ObjectNotActive {
- byte[] id = m_pPOA.servant_to_id(comp);
- m_pPOA.deactivate_object(id);
- }
-
- /**
- * POA
- */
- private POA m_pPOA;
-}
Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryGlobal.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryGlobal.java 2012-02-10 08:03:08 UTC (rev 660)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/FactoryGlobal.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -2,6 +2,7 @@
import java.lang.reflect.Constructor;
+import java.util.ArrayList;
import java.util.Hashtable;
import java.util.HashMap;
import java.util.Iterator;
@@ -187,6 +188,7 @@
* {@.en Map of FactoryEntry}
*/
protected HashMap<IDENTIFIER, FactoryEntry> m_creators = new HashMap<IDENTIFIER, FactoryEntry>();
+ private HashMap<ABSTRACTCLASS, FactoryEntry> m_objects = new HashMap<ABSTRACTCLASS, FactoryEntry>();
/**
* {@.ja Identifierがマップに存在するかチェックする。}
@@ -233,7 +235,7 @@
if (m_creators.containsKey(id)){
return ReturnCode.ALREADY_EXISTS;
}
- FactoryEntry f = new FactoryEntry(creator, destructor);
+ FactoryEntry f = new FactoryEntry(id, creator, destructor);
m_creators.put(id,f);
return ReturnCode.FACTORY_OK;
}
@@ -278,7 +280,9 @@
if (!m_creators.containsKey(id)){
return null;
}
- return m_creators.get(id).creator_.creator_();
+ ABSTRACTCLASS obj = m_creators.get(id).creator_.creator_();
+ m_objects.put(obj, m_creators.get(id));
+ return obj;
}
/**
* {@.ja オブジェクト削除。}
@@ -296,11 +300,13 @@
* {@.en Deleteed object.}
*
*/
- public void deleteObject(final IDENTIFIER id, ABSTRACTCLASS obj) {
+ public ReturnCode deleteObject(final IDENTIFIER id, ABSTRACTCLASS obj) {
if (!m_creators.containsKey(id)){
- return ;
+ return deleteObject(obj);
}
m_creators.get(id).destructor_.destructor_(obj);
+ m_objects.remove(obj);
+ return ReturnCode.FACTORY_OK;
}
/**
* {@.ja オブジェクト削除。}
@@ -314,15 +320,127 @@
* {@.ja 削除するオブジェクト}
* {@.en Deleteed object.}
*/
- public void deleteObject(ABSTRACTCLASS obj) {
- Iterator it = m_creators.keySet().iterator();
+ public ReturnCode deleteObject(ABSTRACTCLASS obj) {
+ if(!m_objects.containsKey(obj)) {
+ return ReturnCode.NOT_FOUND;
+ }
+ m_objects.get(obj).destructor_.destructor_(obj);
+ m_objects.remove(obj);
+ return ReturnCode.FACTORY_OK;
+ }
+
+ /**
+ * {@.ja 生成済みオブジェクトリストの取得}
+ * {@.en Getting created objects}
+ * <p>
+ * {@.ja このファクトリで生成されたオブジェクトのリストを取得する。}
+ * {@.en This operation returns a list of created objects by the factory.}
+ *
+ * @return
+ * {@.ja 生成済みオブジェクトリスト}
+ * {@.en created object list}
+ *
+ */
+ public ArrayList<ABSTRACTCLASS> createdObjects() {
+ ArrayList<ABSTRACTCLASS> objects = new ArrayList<ABSTRACTCLASS>();
+ Iterator it = m_objects.keySet().iterator();
while (it.hasNext()) {
- m_creators.get(it.next()).destructor_.destructor_(obj);
+ objects.add((ABSTRACTCLASS)it.next());
}
+ return objects;
}
/**
+ * {@.ja オブジェクトがこのファクトリの生成物かどうか調べる}
+ * {@.en Whether a object is a product of this factory}
+ * <p>
+ * @param obj
+ * {@.ja 対象オブジェクト}
+ * {@.en A target object}
+ * @return
+ * {@.ja true: このファクトリの生成物
+ * false: このファクトリの生成物ではない}
+ * {@.en true: The object is a product of the factory
+ * false: The object is not a product of the factory}
+ *
+ */
+ public boolean isProducerOf(ABSTRACTCLASS obj) {
+ return m_objects.containsKey(obj);
+ }
+
+ /**
+ * {@.ja オブジェクトからクラス識別子(ID)を取得する}
+ * {@.en Getting class identifier (ID) from a object}
+ * <p>
+ * {@.ja 当該オブジェクトのクラス識別子(ID)を取得する。}
+ * {@.en This operation returns a class identifier (ID) from a object.}
+ *
+ * @param obj [in]
+ * {@.ja クラス識別子(ID)を取得したいオブジェクト}
+ * {@.en An object to investigate its class ID.}
+ * @param id [out]
+ * {@.ja クラス識別子(ID)}
+ * {@.en Class identifier (ID)}
+ * @return
+ * {@.ja リターンコード NOT_FOUND: 識別子が存在しない
+ * FACTORY_OK: 正常終了}
+ * {@.en Return code NOT_FOUND: ID not found
+ * FACTORY_OK: normal return}
+ */
+ public ReturnCode objectToIdentifier(ABSTRACTCLASS obj, IDENTIFIER id) {
+ if (!m_objects.containsKey(obj)) {
+ return ReturnCode.NOT_FOUND;
+ }
+ id = m_objects.get(obj).id_;
+ return ReturnCode.FACTORY_OK;
+ }
+
+ /**
+ * {@.ja オブジェクトのコンストラクタを取得する}
+ * {@.en Getting destructor of the object}
+ * <p>
+ * {@.ja このファクトリで生成されたオブジェクトのコンストラクタを取得する。
+ * obj はこのファクトリで生成されたものでなければならない。予め
+ * isProducerOf() 関数で当該オブジェクトがこのファクトリの生成物で
+ * あるかどうかをチェックしなければならない。}
+ * {@.en This operation returns a constructor of the object created by
+ * the factory. obj must be a product of the factory. User must
+ * check if the object is a product of the factory by using
+ * isProducerOf()-function, before using this function.}
+ *
+ * @return
+ * {@.ja オブジェクトのデストラクタ}
+ * {@.en destructor of the object}
+ *
+ */
+ public ObjectCreator objectToCreator(ABSTRACTCLASS obj) {
+ return m_objects.get(obj).creator_;
+ }
+
+ /**
+ * {@.ja オブジェクトのデストラクタを取得する}
+ * {@.en Getting destructor of the object}
+ * <p>
+ * {@.ja このファクトリで生成されたオブジェクトのデストラクタを取得する。
+ * obj はこのファクトリで生成されたものでなければならない。予め
+ * isProducerOf() 関数で当該オブジェクトがこのファクトリの生成物で
+ * あるかどうかをチェックしなければならない。}
+ * {@.en This operation returns a destructor of the object created by
+ * the factory. obj must be a product of the factory. User must
+ * check if the object is a product of the factory by using
+ * isProducerOf()-function, before using this function.}
+ *
+ * @return
+ * {@.ja オブジェクトのデストラクタ}
+ * {@.en destructor of the object}
+ *
+ */
+ public ObjectDestructor objectToDestructor(ABSTRACTCLASS obj) {
+ return m_objects.get(obj).destructor_;
+ }
+
+ /**
* {@.ja 生成/削除インターフェース管理用クラス}
* {@.en Class for creation/destruction interface management}
*/
@@ -343,8 +461,10 @@
* {@.ja 削除インターフェース}
* {@.en Destruction interface}
*/
- public FactoryEntry(ObjectCreator creator,
- ObjectDestructor destructor) {
+ public FactoryEntry(IDENTIFIER id,
+ ObjectCreator creator,
+ ObjectDestructor destructor) {
+ id_ = id;
creator_ = creator;
destructor_ = destructor;
}
@@ -358,6 +478,11 @@
* {@.en Destruction interface variable}
*/
public ObjectDestructor destructor_;
+ /**
+ * {@.ja }
+ * {@.en }
+ */
+ public IDENTIFIER id_;
};
/**
* {@.ja リターンコード}
Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/Manager.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/Manager.java 2012-02-10 08:03:08 UTC (rev 660)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/Manager.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -2133,7 +2133,7 @@
// Get the POAManager
m_pPOAManager = m_pPOA.the_POAManager();
- m_objManager = new CorbaObjectManager(m_pORB, m_pPOA);
+ //m_objManager = new CorbaObjectManager(m_pORB, m_pPOA);
} catch (Exception ex) {
rtcout.println(Logbuf.DEBUG,
@@ -2630,7 +2630,8 @@
for (int i=0, len=m_ecs.size(); i < len; ++i) {
try {
- m_pPOA.deactivate_object(m_pPOA.servant_to_id(m_ecs.elementAt(i)));
+ //m_pPOA.deactivate_object(m_pPOA.servant_to_id(m_ecs.elementAt(i).getObjRef()));
+ m_pPOA.deactivate_object(m_pPOA.servant_to_id((RTC.ExecutionContextServicePOA)m_ecs.get(i)));
} catch (Exception e) {
rtcout.println(Logbuf.DEBUG, "Exception: Caught unknown Exception in Manager.shutdownComponents().");
@@ -2755,7 +2756,7 @@
Properties temp = m_config.getNode(category + "." + type_name);
Vector<String> keys = temp.propertyNames();
int length = keys.size();
- if (!(length == 1 && keys.get(length).equals("config_file"))) {
+ if (!(length == 1 && keys.get(length-1).equals("config_file"))) {
type_prop.merge(m_config.getNode(category + "." + type_name));
rtcout.println(Logbuf.INFO,
"Component type conf exists in rtc.conf. Merged.");
@@ -3189,7 +3190,7 @@
* {@.ja CORBA Object Manager}
* {@.en CORBA Object Manager}
*/
- protected CorbaObjectManager m_objManager;
+ //protected CorbaObjectManager m_objManager;
/**
* {@.ja Timer Object}
* {@.en Timer Object}
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 2012-02-10 08:03:08 UTC (rev 660)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/RTObject_impl.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -1,10 +1,12 @@
package jp.go.aist.rtm.RTC;
import java.util.Vector;
+import java.util.Set;
import java.lang.reflect.Method;
import jp.go.aist.rtm.RTC.SDOPackage.Configuration_impl;
import jp.go.aist.rtm.RTC.executionContext.ExecutionContextBase;
+import jp.go.aist.rtm.RTC.executionContext.ExecutionContextFactory;
import jp.go.aist.rtm.RTC.port.CorbaPort;
import jp.go.aist.rtm.RTC.port.InPort;
import jp.go.aist.rtm.RTC.port.InPortBase;
@@ -657,22 +659,53 @@
String ec_args = new String();
+ String ec_type = m_properties.getProperty("exec_cxt.periodic.type");
ec_args += m_properties.getProperty("exec_cxt.periodic.type");
ec_args += "?";
ec_args += "rate=" + m_properties.getProperty("exec_cxt.periodic.rate");
+ ExecutionContextFactory<ExecutionContextBase,String> factory
+ = ExecutionContextFactory.instance();
ExecutionContextBase ec;
+ ec = factory.createObject(ec_type);
+ if (ec == null) {
+ rtcout.println(Logbuf.ERROR,"EC ("
+ + ec_type
+ + ") creation failed.");
+ Set ecs = ExecutionContextFactory.instance().getIdentifiers();
+ rtcout.println(Logbuf.DEBUG,"Available EC list: "
+ + ecs.toString() );
+ return ReturnCode_t.RTC_ERROR;
+/*
+ coil::vstring ecs;
+ ecs = RTC::ExecutionContextFactory::instance().getIdentifiers();
+ RTC_DEBUG(("Available EC list: %s",
+ coil::flatten(ecs).c_str()));
+ return RTC::RTC_ERROR;
+*/
+ }
+ rtcout.println(Logbuf.DEBUG,"EC (" + ec_type + ") created.");
+// RTC_DEBUG(("EC (%s) created.", ec_type.c_str()));
+/*
ec = Manager.instance().createContext(ec_args);
if (ec == null) {
return ReturnCode_t.RTC_ERROR;
}
- ec.set_rate(Double.valueOf(m_properties.getProperty("exec_cxt.periodic.rate")).doubleValue());
+*/
+ //ec.getObjRef().set_rate(Double.valueOf(m_properties.getProperty("exec_cxt.periodic.rate")).doubleValue());
m_eclist.add(ec);
ExecutionContextService ecv;
ecv = ec.getObjRef();
if (ecv == null) {
+ rtcout.println(Logbuf.ERROR,
+ "Getting object reference of ec failed.");
return ReturnCode_t.RTC_ERROR;
}
+ double ec_rate = Double.valueOf(m_properties.getProperty("exec_cxt.periodic.rate")).doubleValue();
+ ecv.set_rate(ec_rate);
+ rtcout.println(Logbuf.DEBUG,"Execution context rate is set to "
+ + ec_rate + ".");
+
ec.bindComponent(this);
ReturnCode_t ret;
@@ -685,6 +718,7 @@
// -- entering alive state --
// at least one EC must be attached
if (m_ecMine.value.length == 0) {
+ rtcout.println(Logbuf.ERROR, "No EC of this RTC.");
return ReturnCode_t.PRECONDITION_NOT_MET;
}
for(int intIdx=0; intIdx < m_ecMine.value.length; ++intIdx) {
@@ -3915,10 +3949,16 @@
rtcout.println(Logbuf.TRACE, "RTObject_impl.finalizeContexts()");
for(int i=0, len=m_eclist.size(); i < len; ++i) {
+ m_eclist.get(i).getObjRef().stop();
try {
- m_eclist.elementAt(i).stop();
- m_eclist.elementAt(i).finalizeExecutionContext();
- m_pPOA.deactivate_object(m_pPOA.servant_to_id(m_eclist.elementAt(i)));
+ RTC.ExecutionContextServicePOA servant;
+ servant = (RTC.ExecutionContextServicePOA)m_eclist.get(i);
+// m_eclist.elementAt(i).getObjRef().stop();
+// m_eclist.elementAt(i).finalizeExecutionContext();
+// m_pPOA.deactivate_object(m_pPOA.servant_to_id(m_eclist.elementAt(i).getObjRef()));
+ rtcout.println(Logbuf.DEBUG, "Deactivating Execution Context.");
+ m_pPOA.deactivate_object(m_pPOA.servant_to_id(servant));
+ rtcout.println(Logbuf.DEBUG, "Deactivating EC done.");
}
catch(Exception ex) {
}
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 2012-02-10 08:03:08 UTC (rev 660)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/StateMachine.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -527,7 +527,66 @@
}
}
}
+ //============================================================
+ // divided worker functions
+ // The following divided worker functions have to be used together.
+ // - worker_pre()
+ // - worker_do()
+ // - worker_post()
+ //
+ public void worker_pre() {
+ StateHolder state;
+
+ synchronized (m_states) {
+ state = new StateHolder(m_states);
+ }
+ if (state.curr == state.next) {
+ if( m_predo.get(state.curr) != null ) {
+ m_predo.get(state.curr).doAction(state);
+ }
+ return;
+ }
+ // State changed
+ if( m_exit.get(state.curr) != null ) {
+ m_exit.get(state.curr).doAction(state);
+ }
+
+ synchronized (m_states) {
+ state = new StateHolder(m_states);
+ }
+ if( state.curr != state.next ) {
+ state.curr = state.next;
+ if( m_entry.get(state.curr)!=null ) {
+ m_entry.get(state.curr).doAction(state);
+ }
+ update_curr((STATE)state.curr);
+ }
+ }
+
+ public void worker_do() {
+ StateHolder state;
+
+ synchronized (m_states) {
+ state = new StateHolder(m_states);
+ }
+ if( m_do.get(state.curr) != null ) {
+ m_do.get(state.curr).doAction(state);
+ }
+
+ }
+
+ public void worker_post() {
+ StateHolder state;
+
+ synchronized (m_states) {
+ state = new StateHolder(m_states);
+ }
+ if( m_postdo.get(state.curr) != null ) {
+ m_postdo.get(state.curr).doAction(state);
+ }
+ }
+
private boolean need_trans() {
synchronized (m_states) {
return m_states.curr != m_states.next;
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 2012-02-10 08:03:08 UTC (rev 660)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextBase.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -6,28 +6,47 @@
import OpenRTM.ExtTrigExecutionContextServicePOA;
import jp.go.aist.rtm.RTC.RTObject_impl;
+import jp.go.aist.rtm.RTC.util.Properties;
+import RTC.ExecutionKind;
import RTC.ReturnCode_t;
/**
* <p>Periodic Sampled Data Processing(周期実行用)ExecutionContextのベースとなる
* 抽象クラスです。</p>
*/
-public abstract class ExecutionContextBase extends
- ExtTrigExecutionContextServicePOA implements ECNewDeleteFunc {
+//public abstract class ExecutionContextBase
+// implements ECNewDeleteFunc {
+public interface ExecutionContextBase extends ECNewDeleteFunc {
/**
- * <p>ExecutionContextの処理を1周期分進めます。</p>
+ * {@.ja ExecutionContextクラスの初期化関数}
+ * {@.en Initialization function of ExecutionContext class}
*/
- public void tick() throws SystemException {
+ public void init(Properties props);
+/*
+ public void init(Properties props) {
}
-
+*/
/**
- * <p>本オブジェクトのExecutionContextServiceとしてのCORBAオブジェクト参照を設定します。</p>
- *
- * @param ref CORBAオブジェクト参照
+ * {@.ja CORBA オブジェクトの設定}
+ * {@.en Sets the reference to the CORBA object}
+ * <p>
+ * {@.ja 本オブジェクトの ExecutioncontextService としての CORBA オブジェ
+ * クトを設定する。}
+ * {@.en Sets the reference to the CORBA object as
+ * ExecutioncontextService of this object.}
+ *
+ * @param ref
+ * {@.ja オブジェクトリファレンス}
+ * {@.en The object reference}
+ *
*/
+ public void setObjRef(final ExecutionContextService ref);
+/*
public void setObjRef(final ExecutionContextService ref) {
+ m_profile.setObjRef(ref);
}
+*/
/**
* <p> bindComponent </p>
@@ -36,16 +55,114 @@
* @return ReturnCode_t
*
*/
- public abstract ReturnCode_t bindComponent(RTObject_impl rtc);
+ public ReturnCode_t bindComponent(RTObject_impl rtc);
+// public abstract ReturnCode_t bindComponent(RTObject_impl rtc);
/**
- * <p> getObjRef </p>
+ * {@.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 ExecutionContextService
- *
+ * @return
+ * {@.ja CORBA オブジェクト参照}
+ * {@.en The reference to CORBA object}
+ *
*/
- public abstract ExecutionContextService getObjRef();
+ public ExecutionContextService getObjRef();
+/*
+ public ExecutionContextService getObjRef() {
+ return m_profile.getObjRef();
+ }
+*/
+ /**
+ * {@.ja ExecutionContext の実行周期(Hz)を設定する}
+ * {@.en Set execution rate(Hz) of ExecutionContext}
+ * <p>
+ * {@.ja Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を設定す
+ * る。実行周期の変更は、DataFlowComponentAction の
+ * on_rate_changed によって各RTコンポーネントに伝達される。}
+ * {@.en This operation shall set the rate (in hertz) at which this
+ * context’s Active participating RTCs are being called. If the
+ * execution kind of the context is PERIODIC, a rate change shall
+ * result in the invocation of on_rate_changed on any RTCs
+ * realizing DataFlowComponentAction that are registered with any
+ * RTCs participating in the context.}
+ *
+ * @param rate
+ * {@.ja 処理周期(単位:Hz)}
+ * {@.en Execution cycle(Unit:Hz)}
+ *
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード
+ * RTC_OK: 正常終了
+ * BAD_PARAMETER: 設定値が負の値}
+ * {@.en The return code of ReturnCode_t type
+ * RTC_OK: Succeed
+ * BAD_PARAMETER: Invalid value. The value might be negative.}
+ *
+ */
+ 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}
+ * <p>
+ * {@.ja Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を取得す
+ * る。}
+ * {@.en This operation shall return the rate (in hertz) at which its
+ * Active participating RTCs are being invoked.}
+ *
+ * @return
+ * {@.ja 処理周期(単位:Hz)}
+ * {@.en Execution cycle(Unit:Hz)}
+ *
+ */
+ public double getRate();
+/*
+ public double getRate() {
+ return m_profile.getRate();
+ }
+*/
+ /**
+ * {@.ja ExecutionKind を文字列化する}
+ * {@.en Converting ExecutionKind enum to string}
+ * <p>
+ * {@.ja RTC::ExecutionKind で定義されている PERIODIC, EVENT_DRIVEN,
+ * OTHER を文字列化する。}
+ * {@.en This function converts enumeration (PERIODIC, EVENT_DRIVEN,
+ * OTHER) defined in RTC::ExecutionKind to string.}
+ *
+ * @param kind
+ * {@.ja ExecutionKind}
+ * {@.en ExecutionKind}
+ * @return
+ * {@.ja 文字列化されたExecutionKind}
+ * {@.en String of ExecutionKind}
+ *
+ */
+ public String getKindString(ExecutionKind kind);
+/*
+ public final String getKindString(ExecutionKind kind) {
+ return m_profile.getKindString(kind);
+ }
+*/
+ public boolean finalizeExecutionContext();
+// public abstract boolean finalizeExecutionContext();
+/*
+ public ExecutionContextProfile m_profile
+ = new ExecutionContextProfile();
+*/
+/*
+ protected ExecutionContextProfile m_profile
+ = new ExecutionContextProfile();
+*/
- public abstract boolean finalizeExecutionContext();
-
}
Copied: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextFactory.java (from rev 660, branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextFactory.java)
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextFactory.java (rev 0)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextFactory.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -0,0 +1,34 @@
+package jp.go.aist.rtm.RTC.executionContext;
+
+import jp.go.aist.rtm.RTC.FactoryGlobal;
+/**
+ * {@.ja ExecutionContext用ファクトリの実装}
+ * {@.en Implement of factory for ExecutionContext}
+ */
+
+public class ExecutionContextFactory<ABSTRACTCLASS,IDENTIFIER> extends FactoryGlobal<ABSTRACTCLASS,IDENTIFIER> {
+
+ /**
+ * {@.ja コンストラクタ。}
+ * {@.en Constructor}
+ */
+ private ExecutionContextFactory() {
+
+ }
+ /**
+ * {@.ja インスタンス生成。}
+ * {@.en Create instance}
+ *
+ * <p>
+ * {@.ja インスタンスを生成する。}
+ *
+ * @return
+ * {@.ja インスタンス}
+ * {@.en ExecutionContextFactory object}
+ *
+ */
+ public static ExecutionContextFactory instance() {
+ return (ExecutionContextFactory)instance("jp.go.aist.rtm.RTC.executionContext.ExecutionContextFactory");
+ }
+}
+
Copied: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextProfile.java (from rev 660, branches/work/DesignChangeOfEC/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextProfile.java)
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextProfile.java (rev 0)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExecutionContextProfile.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -0,0 +1,571 @@
+package jp.go.aist.rtm.RTC.executionContext;
+
+import jp.go.aist.rtm.RTC.log.Logbuf;
+import jp.go.aist.rtm.RTC.util.CORBA_SeqUtil;
+import jp.go.aist.rtm.RTC.util.equalFunctor;
+import jp.go.aist.rtm.RTC.util.NVUtil;
+import jp.go.aist.rtm.RTC.util.Properties;
+import jp.go.aist.rtm.RTC.util.TimeValue;
+import RTC.ExecutionContextService;
+//import RTC.ExecutionContextProfile;
+import RTC.ExecutionKind;
+import RTC.ExecutionKindHolder;
+import RTC.LightweightRTObject;
+import RTC.ReturnCode_t;
+import RTC.RTCListHolder;
+import RTC.RTObject;
+import RTC.RTObjectHelper;
+import _SDOPackage.NVListHolder;
+ /**
+ * {@.ja ExecutionContextProfile クラス}
+ * {@.en ExecutionContextProfile class}
+ * <p>
+ * {@.ja Periodic Sampled Data Processing(周期実行用)ExecutionContextクラス。}
+ * {@.en Periodic Sampled Data Processing (for the execution cycles)
+ * ExecutionContext class}
+ */
+public class ExecutionContextProfile {
+ public static final double DEEFAULT_PERIOD = 0.000001;
+
+ /**
+ * {@.ja デフォルトコンストラクタ}
+ * {@.en Default Constructor}
+ * <p>
+ * {@.ja デフォルトコンストラクタ
+ * プロファイルに以下の項目を設定する。
+ * - kind : PERIODIC
+ * - rate : 0.0}
+ * {@.en Default Constructor
+ * Set the following items to profile.
+ * - kind : PERIODIC
+ * - rate : 0.0}
+ */
+ public ExecutionContextProfile(ExecutionKind kind) {
+ rtcout = new Logbuf("periodic_ecprofile");
+ m_period = new TimeValue(DEEFAULT_PERIOD);
+ m_ref = null;
+ rtcout.println(Logbuf.TRACE, "ExecutionContextProfile()");
+ rtcout.println(Logbuf.DEBUG, "Actual rate: "
+ + m_period.sec()
+ + " [sec], "
+ + m_period.usec()
+ + " [usec]");
+ // profile initialization
+ m_profile.kind = kind;
+ m_profile.rate = 1.0 / m_period.toDouble();
+ m_profile.owner = null;
+ m_profile.participants = new RTObject[0];
+ m_profile.properties = new _SDOPackage.NameValue[0];
+ }
+ public ExecutionContextProfile(){
+ this(ExecutionKind.PERIODIC);
+ }
+ /**
+ * {@.ja CORBA オブジェクトの設定}
+ * {@.en Sets the reference to the CORBA object}
+ * <p>
+ * {@.ja 本オブジェクトの ExecutioncontextService としての CORBA オブジェ
+ * クトを設定する。}
+ * {@.en Sets the reference to the CORBA object as
+ * ExecutioncontextService of this object.}
+ *
+ * @param ec_ptr
+ * {@.ja オブジェクトリファレンス}
+ * {@.en The object reference}
+ */
+ public void setObjRef(ExecutionContextService ec_ptr){
+ rtcout.println(Logbuf.TRACE, "setObjRef()");
+ synchronized (m_profile){
+ m_ref = (ExecutionContextService)ec_ptr._duplicate();
+ }
+ }
+
+ /**
+ * {@.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(){
+ rtcout.println(Logbuf.TRACE, "getObjRef()");
+ synchronized (m_profile){
+ return (ExecutionContextService)m_ref._duplicate();
+ }
+ }
+
+ /**
+ * {@.ja ExecutionContext の実行周期(Hz)を設定する}
+ * {@.en Set execution rate(Hz) of ExecutionContext}
+ * <p>
+ * {@.ja Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を設定す
+ * る。実行周期の変更は、DataFlowComponentAction の
+ * on_rate_changed によって各RTコンポーネントに伝達される。}
+ * {@.en This operation shall set the rate (in hertz) at which this
+ * context’s Active participating RTCs are being called. If the
+ * execution kind of the context is PERIODIC, a rate change shall
+ * result in the invocation of on_rate_changed on any RTCs
+ * realizing DataFlowComponentAction that are registered with any
+ * RTCs participating in the context.}
+ *
+ * @param rate
+ * {@.ja 処理周期(単位:Hz)}
+ * {@.en Execution cycle(Unit:Hz)}
+ *
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード
+ * RTC_OK: 正常終了
+ * BAD_PARAMETER: 設定値が負の値}
+ * {@.en The return code of ReturnCode_t type
+ * RTC_OK: Succeed
+ * BAD_PARAMETER: Invalid value. The value might be negative.}
+ *
+ */
+ public ReturnCode_t setRate(double rate) {
+ rtcout.println(Logbuf.TRACE, "set_rate("+rate+")");
+ if (rate < 0.0) {
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+
+ synchronized (m_profile){
+ m_profile.rate = rate;
+ m_period = new TimeValue(1.0/rate);
+ return ReturnCode_t.RTC_OK;
+ }
+ }
+ public ReturnCode_t setPeriod(double period) {
+ rtcout.println(Logbuf.TRACE, "setPeriod("+period+" [sec])");
+ if (period < 0.0) {
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+
+ synchronized (m_profile){
+ m_profile.rate = 1.0 / period;
+ m_period = new TimeValue(period);
+ return ReturnCode_t.RTC_OK;
+ }
+ }
+ public ReturnCode_t setPeriod(TimeValue period) {
+ rtcout.println(Logbuf.TRACE, "setPeriod("+period.toDouble()+" [sec])");
+ if (period.toDouble() < 0.0) {
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+
+ synchronized (m_profile){
+ m_profile.rate = 1.0 / period.toDouble();
+ m_period = period;
+ return ReturnCode_t.RTC_OK;
+ }
+ }
+
+ /**
+ * {@.ja ExecutionContext の実行周期(Hz)を取得する}
+ * {@.en Get execution rate(Hz) of ExecutionContext}
+ * <p>
+ * {@.ja Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を取得す
+ * る。}
+ * {@.en This operation shall return the rate (in hertz) at which its
+ * Active participating RTCs are being invoked.}
+ *
+ * @return
+ * {@.ja 処理周期(単位:Hz)}
+ * {@.en Execution cycle(Unit:Hz)}
+ *
+ */
+ public double getRate() {
+ rtcout.println(Logbuf.TRACE, "get_rate()");
+ synchronized (m_profile){
+ return m_profile.rate;
+ }
+ }
+ public TimeValue getPeriod(){
+ rtcout.println(Logbuf.TRACE, "getPeriod()");
+ synchronized (m_profile){
+ return m_period;
+ }
+ }
+
+ /**
+ * {@.ja ExecutionKind を文字列化する}
+ * {@.en Converting ExecutionKind enum to string }
+ * <p>
+ * {@.ja ExecutionKind で定義されている PERIODIC, EVENT_DRIVEN,
+ * OTHER を文字列化する。}
+ * {@.en This function converts enumeration (PERIODIC, EVENT_DRIVEN,
+ * OTHER) defined in RTC::ExecutionKind to string.}
+ *
+ * @param kind
+ * {@.ja ExecutionKind}
+ * {@.en ExecutionKind}
+ * @return
+ * {@.en 文字列化されたExecutionKind}
+ * {@.en String of ExecutionKind}
+ *
+ */
+ public final String getKindString(ExecutionKind kind){
+ ExecutionKindHolder ekh = new ExecutionKindHolder(kind);
+ try {
+ return ekh._type().name();
+ }
+ catch(Exception ex) {
+ return "";
+ }
+ }
+ public final String getKindString() {
+ return getKindString(m_profile.kind);
+ }
+
+ /**
+ * {@.ja ExecutionKind を設定する}
+ * {@.en Set the ExecutionKind}
+ * <p>
+ * {@.ja この ExecutionContext の ExecutionKind を設定する}
+ * {@.en This operation sets the kind of the execution context.}
+ *
+ * @param kind
+ * {@.ja ExecutionKind}
+ * {@.en ExecutionKind}
+ *
+ */
+ public ReturnCode_t setKind(ExecutionKind kind) {
+ rtcout.println(Logbuf.TRACE, "setKind("+getKindString(kind)+")");
+ synchronized (m_profile){
+ m_profile.kind = kind;
+ return ReturnCode_t.RTC_OK;
+ }
+ }
+
+ /**
+ * {@.ja ExecutionKind を取得する}
+ * {@.en Get the ExecutionKind}
+ * <p>
+ * {@.ja 本 ExecutionContext の ExecutionKind を取得する}
+ * {@.en This operation shall report the execution kind of the execution
+ * context.}
+ *
+ * @return
+ * {@.ja ExecutionKind}
+ * {@.en ExecutionKind}
+ */
+ public ExecutionKind getKind() {
+ rtcout.println(Logbuf.TRACE, getKindString(m_profile.kind)
+ + " = getKind()");
+ return m_profile.kind;
+ }
+
+ /**
+ * {@.ja Ownerコンポーネントをセットする。}
+ * {@.en Setting owner component of the execution context}
+ * <p>
+ * {@.ja このECのOwnerとなるRTCをセットする。}
+ * {@.en This function sets an RT-Component to be owner of the
+ * execution context.}
+ *
+ * @param comp
+ * {@.ja OwnerとなるRTコンポーネント}
+ * {@.en an owner RT-Component of this execution context}
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード}
+ * {@.en The return code of ReturnCode_t type}
+ */
+ public ReturnCode_t setOwner(LightweightRTObject comp) {
+ rtcout.println(Logbuf.TRACE, "setOwner()");
+ if (comp==null) {
+ rtcout.println(Logbuf.ERROR,"nil reference is given.");
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+ RTObject rtobj;
+ rtobj = RTObjectHelper.narrow(comp);
+ if (rtobj==null) {
+ rtcout.println(Logbuf.ERROR,"Narrowing failed.");
+ return ReturnCode_t.RTC_ERROR;
+ }
+ m_profile.owner = (RTObject)rtobj._duplicate();
+ return ReturnCode_t.RTC_OK;
+ }
+
+ /**
+ * {@.ja Ownerコンポーネントの参照を取得する}
+ * {@.en Getting a reference of the owner component}
+ * <p>
+ * {@.ja このECのOwnerであるRTCの参照を取得する。}
+ * {@.en This function returns a reference of the owner RT-Component of
+ * this execution context}
+ *
+ * @return
+ * {@.ja OwnerRTコンポーネントの参照}
+ * {@.en a reference of the owner RT-Component}
+ */
+ public final RTObject getOwner() {
+ rtcout.println(Logbuf.TRACE, "getOwner()");
+ return (RTObject)m_profile.owner._duplicate();
+ }
+
+ /**
+ * {@.ja RTコンポーネントを追加する}
+ * {@.en Add an RT-component}
+ * <p>
+ * {@.ja 指定したRTコンポーネントを参加者リストに追加する。追加されたRTコ
+ * ンポーネントは attach_context が呼ばれ、Inactive 状態に遷移する。
+ * 指定されたRTコンポーネントがnullの場合は、BAD_PARAMETER が返され
+ * る。指定されたRTコンポーネントが DataFlowComponent 以外の場合は、
+ * BAD_PARAMETER が返される。}
+ * {@.en The operation causes the given RTC to begin participating in
+ * the execution context. The newly added RTC will receive a call
+ * to LightweightRTComponent::attach_context and then enter the
+ * Inactive state. BAD_PARAMETER will be invoked, if the given
+ * RT-Component is null or if the given RT-Component is other than
+ * DataFlowComponent.}
+ *
+ * @param comp
+ * {@.ja 追加対象RTコンポーネント}
+ * {@.en The target RT-Component for add}
+ *
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード}
+ * {@.en The return code of ReturnCode_t type}
+ */
+ public ReturnCode_t addComponent(LightweightRTObject comp) {
+ rtcout.println(Logbuf.TRACE,"addComponent()");
+ if (comp==null) {
+ rtcout.println(Logbuf.ERROR,"A nil reference was given.");
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+ RTObject rtobj = RTObjectHelper.narrow(comp);
+ if (rtobj==null) {
+ rtcout.println(Logbuf.ERROR,"Narrowing was failed.");
+ return ReturnCode_t.RTC_ERROR;
+ }
+ RTCListHolder holder = new RTCListHolder(m_profile.participants);
+ CORBA_SeqUtil.push_back(holder, rtobj);
+ m_profile.participants = holder.value;
+ return ReturnCode_t.RTC_OK;
+ }
+
+ /**
+ * {@.ja RTコンポーネントを参加者リストから削除する}
+ * {@.en Remove the RT-Component from participant list}
+ * <p>
+ * {@.ja 指定したRTコンポーネントを参加者リストから削除する。削除された
+ * RTコンポーネントは detach_context が呼ばれる。指定されたRTコンポー
+ * ネントが参加者リストに登録されていない場合は、BAD_PARAMETER が返
+ * される。}
+ * {@.en This operation causes a participant RTC to stop participating
+ * in the execution context.
+ * The removed RTC will receive a call to
+ * LightweightRTComponent::detach_context.
+ * BAD_PARAMETER will be returned, if the given RT-Component is not
+ * participating in the participant list.}
+ *
+ * @param comp
+ * {@.ja 削除対象RTコンポーネント}
+ * {@.en The target RT-Component for delete}
+ *
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード}
+ * {@.en The return code of ReturnCode_t type}
+ *
+ */
+ public ReturnCode_t removeComponent(LightweightRTObject comp) {
+ rtcout.println(Logbuf.TRACE,"removeComponent()");
+ if (comp==null) {
+ rtcout.println(Logbuf.ERROR,"A nil reference was given.");
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+ RTObject rtobj = RTObjectHelper.narrow(comp);
+ if (rtobj==null) {
+ rtcout.println(Logbuf.ERROR,"Narrowing was failed.");
+ return ReturnCode_t.RTC_ERROR;
+ }
+ synchronized (m_profile) {
+ RTCListHolder holder = new RTCListHolder(m_profile.participants);
+ int index;
+ index = CORBA_SeqUtil.find(holder,
+ new find_participant(rtobj));
+ if (index < 0) {
+ rtcout.println(Logbuf.ERROR,
+ "The given RTObject does not exist in the EC.");
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+ CORBA_SeqUtil.erase(holder, index);
+ m_profile.participants = holder.value;
+ }
+ return ReturnCode_t.RTC_OK;
+ }
+
+ /**
+ * {@.ja RTコンポーネントの参加者リストを取得する}
+ * {@.en Getting participant RTC list}
+ * <p>
+ * {@.ja 現在登録されている参加者RTCのリストを取得する。}
+ * {@.en This function returns a list of participant RTC of the
+ * execution context.}
+ *
+ * @return
+ * {@.ja 参加者RTCのリスト}
+ * {@.en Participants RTC list}
+ *
+ */
+ public final RTObject[] getComponentList() {
+ rtcout.println(Logbuf.TRACE,"getComponentList("
+ + m_profile.participants.length
+ +")");
+ return m_profile.participants;
+ }
+
+ /**
+ * {@.ja Propertiesをセットする}
+ * {@.en Setting Properties}
+ * <p>
+ * {@.ja ExecutionContextProfile::properties をセットする。}
+ * {@.en This function sets ExecutionContextProfile::properties by
+ * Properties.}
+ *
+ * @param props
+ * {@.ja ExecutionContextProfile::properties にセットするプロパティー}
+ * {@.en Properties to be set to ExecutionContextProfile::properties.}
+ */
+ public void setProperties(Properties props) {
+ rtcout.println(Logbuf.TRACE,"setProperties()");
+ String str = new String();
+ str = props._dump(str,props,0);
+ rtcout.println(Logbuf.TRACE,str);
+ synchronized (m_profile) {
+ NVListHolder holder = new NVListHolder(m_profile.properties);
+ NVUtil.copyFromProperties(holder, props);
+ m_profile.properties = holder.value;
+ }
+ }
+
+ /**
+ * {@.ja Propertiesを取得する}
+ * {@.en Setting Properties}
+ * <p>
+ * {@.ja ExecutionContextProfile::properties を取得する。}
+ *
+ * @return
+ * {@.ja Propertiesに変換されたExecutionContextProfile::properties}
+ * {@.en This function sets ExecutionContextProfile::properties by
+ * Properties.}
+ *
+ */
+ public final Properties getProperties() {
+ rtcout.println(Logbuf.TRACE,"getProperties()");
+ Properties props = new Properties();
+ synchronized (m_profile) {
+ NVListHolder holder = new NVListHolder(m_profile.properties);
+ NVUtil.copyToProperties(props, holder);
+ String str = new String();
+ str = props._dump(str,props,0);
+ rtcout.println(Logbuf.TRACE,str);
+ }
+ return props;
+ }
+
+ /**
+ * {@.ja Profileを取得する}
+ * {@.en Getting Profile}
+ * <p>
+ * {@.ja RTC::ExecutionContextProfile を取得する。取得した
+ * ExecutionContextProfile の所有権は呼び出し側にある。取得されたオ
+ * ブジェクトが不要になった場合、呼び出し側が開放する責任を負う。}
+ * {@.en This function gets RTC::ExecutionContextProfile. The ownership
+ * of the obtained ExecutionContextProfile is given to caller. The
+ * caller should release obtained object when it is unneccessary
+ * anymore.}
+ *
+ * @return
+ * {@.ja RTC::ExecutionContextProfile}
+ * {@.en RTC::ExecutionContextProfile}
+ *
+ */
+ public RTC.ExecutionContextProfile getProfile() {
+ rtcout.println(Logbuf.TRACE,"getProfile()");
+ RTC.ExecutionContextProfile p;
+ synchronized (m_profile){
+ p = new RTC.ExecutionContextProfile(m_profile.kind,
+ m_profile.rate,
+ m_profile.owner,
+ m_profile.participants,
+ m_profile.properties);
+ }
+ return p;
+
+ }
+
+
+ /**
+ * {@.ja ExecutionContextProfileをロックする}
+ * {@.en Getting a lock of RTC::ExecutionContextProfile}
+ * <p>
+ * {@.ja このオブジェクトが管理する RTC::ExecutionContextProfile をロックする。
+ * ロックが不要になった際にはunlock()でロックを解除しなければならない。}
+ * {@.en This function locks RTC::ExecutionContextProfile in the object.
+ * The lock should be released when the lock is unneccessary.}
+ *
+ */
+ public void lock() {
+ //m_profileMutex.lock();
+ }
+
+ /**
+ * {@.ja ExecutionContextProfileをアンロックする}
+ * {@.en Release a lock of the RTC::ExecutionContextProfile}
+ * <p>
+ * {@.ja このオブジェクトが管理する RTC::ExecutionContextProfile をアンロッ
+ * クする。}
+ * {@.en This function release the lock of RTC::ExecutionContextProfile
+ * in the object.}
+ *
+ */
+ public void unlock() {
+ //m_profileMutex.unlock();
+ }
+
+ /**
+ * {@.ja Logger}
+ * {@.en Logger}
+ */
+ private Logbuf rtcout;
+ /**
+ * {@.ja ECProfile}
+ * {@.en ECProfile}
+ */
+ private RTC.ExecutionContextProfile m_profile
+ = new RTC.ExecutionContextProfile();
+
+ /**
+ * {@.ja mutex of ExecutionContextProfile}
+ * {@.en mutex ExecutionContextProfile}
+ */
+ //private String m_profileMutex = new String();
+
+ /**
+ * {@.ja ExecutionContext の実行周期}
+ * {@.en Execution cycle of ExecutionContext}
+ */
+ private TimeValue m_period;
+
+ /**
+ * {@.ja ExecutionContextService オブジェクトへの参照}
+ * {@.en Reference to ExecutionContextService object}
+ */
+ private ExecutionContextService m_ref;
+
+ private class find_participant implements equalFunctor {
+ private RTObject m_comp;
+ public find_participant(RTObject comp) {
+ m_comp = (RTObject)comp._duplicate();
+ }
+ public boolean equalof(final java.lang.Object comp) {
+ return m_comp._is_equivalent((RTObject)comp);
+ }
+ };
+}; // class ExecutionContextProfile
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 2012-02-10 08:03:08 UTC (rev 660)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/ExtTrigExecutionContext.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -1,10 +1,31 @@
package jp.go.aist.rtm.RTC.executionContext;
+import java.util.ArrayList;
+
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.RTObject_impl;
+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.log.Logbuf;
+import jp.go.aist.rtm.RTC.util.POAUtil;
+import jp.go.aist.rtm.RTC.util.Properties;
import jp.go.aist.rtm.RTC.util.TimeValue;
import org.omg.CORBA.SystemException;
+
+import OpenRTM.ExtTrigExecutionContextServicePOA;
+import OpenRTM.ExtTrigExecutionContextServiceHelper;
+import OpenRTM.DataFlowComponent;
+import OpenRTM.DataFlowComponentHelper;
+import RTC.ExecutionContextService;
+import RTC.ExecutionContextServiceHelper;
+import RTC.ExecutionKind;
+import RTC.LifeCycleState;
+import RTC.LightweightRTObject;
+import RTC.ReturnCode_t;
/**
* {@.ja ステップ実行が可能な ExecutionContext クラス}
* {@.en ExecutionContext class that enables one step execution}
@@ -17,7 +38,8 @@
* Time(Tick) advances one cycle by invoking method externally.}
*/
public class ExtTrigExecutionContext
- extends PeriodicExecutionContext implements Runnable {
+extends ExtTrigExecutionContextServicePOA
+implements Runnable, ObjectCreator<ExecutionContextBase>, ObjectDestructor, ExecutionContextBase{
/**
* {@.ja コンストラクタ}
@@ -27,12 +49,57 @@
super();
rtcout = new Logbuf("Manager.ExtTrigExecutionContext");
+ m_profile.setObjRef((ExecutionContextService)this.__this());
}
/**
- * <p>ExecutionContextの処理を1周期分進めます。</p>
+ * <p> __this() </p>
+ *
+ * @return ExecutionContextService
*/
+
+ public ExecutionContextService __this() {
+
+ if (this.m_ref == null) {
+ try {
+ this.m_ref = ExtTrigExecutionContextServiceHelper.narrow(POAUtil.getRef(this));
+
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ return this.m_ref;
+ }
+ /**
+ * <p>終了処理用関数</p>
+ */
+ public boolean finalizeExecutionContext() {
+ synchronized (m_worker) {
+ //m_worker.running_ = true;
+ m_worker.notifyAll();
+ }
+ m_svc = false;
+ try {
+ m_thread.join();
+ }
+ catch (InterruptedException e) {
+ System.out.println(e);
+ }
+
+ return true;
+ }
+
+ /**
+ * {@.ja ExecutionContextの処理を進める}
+ * {@.en Proceed with tick of ExecutionContext}
+ *
+ * <p>
+ * {@.ja ExecutionContextの処理を1周期分進めます。}
+ * {@.en Proceed with tick of ExecutionContext for one period.}
+ *
+ */
public void tick() throws SystemException {
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.tick()");
@@ -44,13 +111,25 @@
}
/**
+ * <p>ExecutionContext用のスレッドを生成します。</p>
+ */
+ public int open() {
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.open()");
+
+ if(m_thread==null) {
+ m_thread = new Thread(this, "ExtTrigExecutionContext");
+ m_thread.start();
+ }
+ return 0;
+ }
+ /**
* <p>ExecutionContextにattachされている各Componentの処理を呼び出します。
* 全Componentの処理を呼び出した後、次のイベントが発生するまで休止します。</p>
*/
public int svc() {
rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.svc()");
-
do {
TimeValue tv = new TimeValue(0, m_usec); // (s, us)
@@ -65,8 +144,9 @@
if (m_worker._called) {
m_worker._called = false;
for (int intIdx = 0; intIdx < m_comps.size(); ++intIdx) {
- m_comps.elementAt(intIdx).invoke();
+ m_comps.get(intIdx).invoke();
}
+/*
while (!m_running) {
try {
Thread.sleep(0, (int) tv.getUsec());
@@ -79,6 +159,7 @@
} catch (InterruptedException e) {
e.printStackTrace();
}
+*/
}
}
} while (m_running);
@@ -93,6 +174,799 @@
this.svc();
}
+ //============================================================
+ // ExecutionContext
+ //============================================================
+ /**
+ * {@.ja ExecutionContext 実行状態確認関数}
+ * {@.en heck for ExecutionContext running state}
+ * <p>
+ * {@.ja この操作は ExecutionContext が Runnning 状態の場合に true を返す。
+ * Executioncontext が Running の間、当該 Executioncontext に参加し
+ * ている全てのアクティブRTコンポーネントが、ExecutionContext の実
+ * 行種類に応じて実行される。}
+ * {@.en This operation shall return true if the context is in the
+ * Running state. While the context is Running, all Active RTCs
+ * participating in the context shall be executed according to the
+ * context’s execution kind.}
+ *
+ * @return
+ * {@.ja 状態確認関数(動作中:true、停止中:false)}
+ * {@.en Check state function (Running:true、Stopping:false)}
+ *
+ */
+ public boolean is_running() {
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.is_running()");
+
+ return m_running;
+ }
+
+ /**
+ * {@.ja ExecutionContext の実行を開始}
+ * {@.en Start the ExecutionContext}
+ * <p>
+ * {@.ja ExecutionContext の実行状態を Runnning とするためのリクエストを
+ * 発行する。ExecutionContext の状態が遷移すると
+ * ComponentAction::on_startup が呼び出される。参加しているRTコンポー
+ * ネントが、初期化されるまで ExecutionContext を開始することはでき
+ * ない。ExecutionContext は複数回開始/停止を繰り返すことができる。}
+ * {@.en Request that the context enter the Running state. Once the
+ * state transition occurs, the ComponentAction::on_startup
+ * operation will be invoked. An execution context may not be
+ * started until the RT-Components that participate in it have
+ * been initialized. An execution context may be started and
+ * stopped multiple times.}
+ *
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード}
+ * {@.en The return code of ReturnCode_t type}
+ *
+ */
+ 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();
+ }
+ // change EC thread state
+ m_running = true;
+ synchronized (m_worker) {
+ //m_worker.running_ = true;
+ m_worker.notifyAll();
+ }
+
+ this.open();
+
+ return ReturnCode_t.RTC_OK;
+ }
+
+ /**
+ * {@.ja ExecutionContext の実行を停止}
+ * {@.en Stop the ExecutionContext}
+ * <p>
+ * {@.ja ExecutionContext の状態を Stopped とするためのリクエストを発行す
+ * る。遷移が発生した場合は、ComponentAction::on_shutdown が呼び出
+ * される。参加しているRTコンポーネントが終了する前に
+ * ExecutionContext を停止する必要がある。ExecutionContext は複数回
+ * 開始/停止を繰り返すことができる。}
+ * {@.en Request that the context enter the Stopped state. Once the
+ * transition occurs, the ComponentAction::on_shutdown operation
+ * will be invoked. An execution context must be stopped before
+ * the RT components that participate in it are finalized. An
+ * execution context may be started and stopped multiple times.}
+ *
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード}
+ * {@.en The return code of ReturnCode_t type}
+ *
+ */
+ public ReturnCode_t stop(){
+
+ 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();
+ }
+
+ return ReturnCode_t.RTC_OK;
+ }
+
+ /**
+ * {@.ja ExecutionContext の実行周期(Hz)を取得する}
+ * {@.en Get execution rate(Hz) of ExecutionContext}
+ * <p>
+ * {@.ja Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を取得す
+ * る。}
+ * {@.en This operation shall return the rate (in hertz) at which its
+ * Active participating RTCs are being invoked.}
+ *
+ * @return
+ * {@.ja 処理周期(単位:Hz)}
+ * {@.en Execution cycle(Unit:Hz)}
+ *
+ */
+ public double get_rate() {
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.get_rate()");
+
+ return m_profile.getRate();
+ }
+ /**
+ * <p>ExecutionContextの実行周期(Hz)を設定します。</p>
+ *
+ * @param rate 実行周期(Hz)
+ */
+ public ReturnCode_t set_rate(double rate) {
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.set_rate("+rate+")");
+
+ 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;
+ }
+ for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
+ m_comps.get(intIdx).invoke_on_rate_changed();
+ }
+ rtcout.println(Logbuf.DEBUG, "Actual period: "
+ + m_profile.getPeriod().sec()
+ + " [sec], "
+ + m_profile.getPeriod().usec()
+ + " [usec]");
+ return ReturnCode_t.RTC_OK;
+ }
+
+ /**
+ * <p>コンポーネントをアクティブ化します。</p>
+ *
+ * @param comp アクティブ化対象コンポーネント
+ *
+ * @return 実行結果
+ */
+ public ReturnCode_t activate_component(LightweightRTObject comp) {
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.activate_component()");
+
+ // コンポーネントが参加者リストに無ければ 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;
+ }
+ }
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+
+ /**
+ * <p>コンポーネントを非アクティブ化します。</p>
+ *
+ * @param comp 非アクティブ化対象コンポーネント
+ *
+ * @return 実行結果
+ */
+ public ReturnCode_t deactivate_component(LightweightRTObject comp) {
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.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.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;
+ }
+ }
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+
+ /**
+ * <p>コンポーネントをリセットします。</p>
+ *
+ * @param comp リセット対象コンポーネント
+ *
+ * @return 実行結果
+ */
+ public ReturnCode_t reset_component(LightweightRTObject comp){
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.reset_component()");
+
+ 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;
+ }
+ }
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+
+ /**
+ * <p>コンポーネントの状態を取得します。</p>
+ *
+ * @param comp 状態取得対象コンポーネント
+ *
+ * @return コンポーネント状態
+ */
+ public LifeCycleState get_component_state(LightweightRTObject comp) {
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.get_component_state()");
+
+ 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();
+ }
+ }
+ return LifeCycleState.CREATED_STATE;
+ }
+
+ /**
+ * <p>ExecutionKindを取得します。</p>
+ *
+ * @return ExecutionKind
+ */
+ public ExecutionKind get_kind() {
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.get_kind() ="
+ + m_profile.getKindString());
+
+ return m_profile.getKind();
+ }
+
+ /**
+ * {@.ja RTコンポーネントを追加する}
+ * {@.en Add an RT-component}
+ *
+ * <p>
+ * {@.ja 指定したRTコンポーネントを参加者リストに追加する。追加されたRTコ
+ * ンポーネントは attach_context が呼ばれ、Inactive 状態に遷移する。
+ * 指定されたRTコンポーネントがnullの場合は、BAD_PARAMETER が返され
+ * る。指定されたRTコンポーネントが DataFlowComponent 以外の場合は、
+ * BAD_PARAMETER が返される。}
+ * {@.en The operation causes the given RTC to begin participating in
+ * the execution context. The newly added RTC will receive a call
+ * to LightweightRTComponent::attach_context and then enter the
+ * Inactive state. BAD_PARAMETER will be invoked, if the given
+ * RT-Component is null or if the given RT-Component is other than
+ * DataFlowComponent.}
+ *
+ * @param comp
+ * {@.ja 追加対象RTコンポーネント}
+ * {@.en The target RT-Component for add}
+ *
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード}
+ * {@.en The return code of ReturnCode_t type}
+ *
+ *
+ */
+ public ReturnCode_t add_component(LightweightRTObject comp) {
+
+ rtcout.println(Logbuf.TRACE,
+ "ExtTrigExecutionContext.add_component()");
+
+ 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;
+ }
+ }
+
+ /**
+ * {@.ja コンポーネントをバインドする。}
+ * {@.en Bind the component.}
+ *
+ * <p>
+ * {@.ja コンポーネントをバインドする。}
+ * {@.en Bind the component.}
+ *
+ * @param rtc
+ * {@.ja RTコンポーネント}
+ * {@.en RT-Component's instances}
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード}
+ * {@.en The return code of ReturnCode_t type}
+ *
+ */
+ 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;
+ }
+
+ /**
+ * {@.ja RTコンポーネントを参加者リストから削除する}
+ * {@.en Remove the RT-Component from participant list}
+ *
+ * <p>
+ * {@.ja 指定したRTコンポーネントを参加者リストから削除する。削除された
+ * RTコンポーネントは detach_context が呼ばれる。指定されたRTコンポー
+ * ネントが参加者リストに登録されていない場合は、BAD_PARAMETER が返
+ * される。}
+ * {@.en This operation causes a participant RTC to stop participating in
+ * the execution context.
+ * The removed RTC will receive a call to
+ * LightweightRTComponent::detach_context.
+ * BAD_PARAMETER will be returned, if the given RT-Component is not
+ * participating in the participant list.}
+ *
+ * @param comp
+ * {@.ja 削除対象RTコンポーネント}
+ * {@.en The target RT-Component for delete}
+ *
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード}
+ * {@.en The return code of ReturnCode_t type}
+ *
+ */
+ public ReturnCode_t remove_component(LightweightRTObject comp) {
+
+ rtcout.println(Logbuf.TRACE,
+ "ExtTrigExecutionContext.remove_component()");
+
+ 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;
+ }
+ }
+ rtcout.println(Logbuf.TRACE, "remove_component(): no RTC found in this context.");
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+
+ /**
+ * <p>ExecutionContextProfile を取得します。</p>
+ *
+ * @return ExecutionContextProfile
+ */
+ public RTC.ExecutionContextProfile get_profile() {
+
+ rtcout.println(Logbuf.TRACE, "ExtTrigExecutionContext.get_profile()");
+ return m_profile.getProfile();
+ }
+
+ /**
+ * <p>DataFlowComponentのAction定義用抽象クラスです。</p>
+ */
+ protected abstract class DFPBase {
+ /**
+ * <p>コンストラクタです。</p>
+ *
+ * @param id ExecutionContextのID
+ */
+ public DFPBase(int id) {
+ ec_id = id;
+ m_sm = new StateMachine(3);
+ m_sm.setListener(this);
+ StateHolder st = new StateHolder();
+ m_sm.setEntryAction(LifeCycleState.ACTIVE_STATE, new onActivated());
+ m_sm.setDoAction(LifeCycleState.ACTIVE_STATE, new onExecute());
+ m_sm.setPostDoAction(LifeCycleState.ACTIVE_STATE, new onStateUpdate());
+ m_sm.setExitAction(LifeCycleState.ACTIVE_STATE, new onDeactivated());
+ m_sm.setEntryAction(LifeCycleState.ERROR_STATE, new onAborting());
+ m_sm.setDoAction(LifeCycleState.ERROR_STATE, new onError());
+ m_sm.setExitAction(LifeCycleState.ERROR_STATE, new onReset());
+
+ st.prev = LifeCycleState.INACTIVE_STATE;
+ st.curr = LifeCycleState.INACTIVE_STATE;
+ st.next = LifeCycleState.INACTIVE_STATE;
+ m_sm.setStartState(st);
+ m_sm.goTo(LifeCycleState.INACTIVE_STATE);
+ }
+ /**
+ * <p>onActivatedアクション定義用抽象クラスです。</p>
+ */
+ private class onActivated implements StateAction {
+ public void doAction(StateHolder state) {
+ on_activated(state);
+ }
+ }
+ /**
+ * <p>onExecuteアクション定義用抽象クラスです。</p>
+ */
+ private class onExecute implements StateAction {
+ public void doAction(StateHolder state) {
+ on_execute(state);
+ }
+ }
+ /**
+ * <p>onStateUpdateアクション定義用抽象クラスです。</p>
+ */
+ private class onStateUpdate implements StateAction {
+ public void doAction(StateHolder state) {
+ on_state_update(state);
+ }
+ }
+ /**
+ * <p>onDeactivatedアクション定義用抽象クラスです。</p>
+ */
+ private class onDeactivated implements StateAction {
+ public void doAction(StateHolder state) {
+ on_deactivated(state);
+ }
+ }
+ /**
+ * <p>onAbortingアクション定義用抽象クラスです。</p>
+ */
+ private class onAborting implements StateAction {
+ public void doAction(StateHolder state) {
+ on_aborting(state);
+ }
+ }
+ /**
+ * <p>onErrorアクション定義用抽象クラスです。</p>
+ */
+ private class onError implements StateAction {
+ public void doAction(StateHolder state) {
+ on_error(state);
+ }
+ }
+ /**
+ * <p>onResetアクション定義用抽象クラスです。</p>
+ */
+ private class onReset implements StateAction {
+ public void doAction(StateHolder state) {
+ on_reset(state);
+ }
+ }
+
+ /**
+ * <p>ExecutionContextのstart時に呼ばれる抽象メソッドです。</p>
+ */
+ public abstract void on_startup();
+ /**
+ * <p>ExecutionContextのstop時に呼ばれる抽象メソッドです。</p>
+ */
+ public abstract void on_shutdown();
+
+ /**
+ * <p>コンポーネントのactivate時に呼ばれる抽象メソッドです。</p>
+ */
+ public abstract void on_activated(final StateHolder st);
+ /**
+ * <p>コンポーネントのdeactivate時に呼ばれる抽象メソッドです。</p>
+ */
+ public abstract void on_deactivated(final StateHolder st);
+ /**
+ * <p>コンポーネントのabort時に呼ばれる抽象メソッドです。</p>
+ */
+ public abstract void on_aborting(final StateHolder st);
+ /**
+ * <p>コンポーネントがerror状態の時に呼ばれる抽象メソッドです。</p>
+ */
+ public abstract void on_error(final StateHolder st);
+ /**
+ * <p>コンポーネントreset時に呼ばれる抽象メソッドです。</p>
+ */
+ public abstract void on_reset(final StateHolder st);
+ /**
+ * <p>コンポーネント実行時に呼ばれる抽象メソッドです。</p>
+ */
+ public abstract void on_execute(final StateHolder st);
+ /**
+ * <p>コンポーネントの実行時に呼ばれる抽象メソッドです。</p>
+ */
+ public abstract void on_state_update(final StateHolder st);
+
+ /**
+ * <p>ExecutionContextの実行周期変更時に呼ばれる抽象メソッドです。</p>
+ */
+ public abstract void on_rate_changed();
+ /**
+ * <p>ExecutionContextの状態遷移用ワーカーです。</p>
+ */
+ public void worker() {
+ m_sm.worker();
+ }
+ public void worker_pre() {
+ m_sm.worker_pre();
+ }
+ public void worker_do() {
+ m_sm.worker_do();
+ }
+ public void worker_post() {
+ m_sm.worker_post();
+ }
+
+ /**
+ * <p>現在の状態を取得します。</p>
+ *
+ * @return 現在の状態
+ */
+ public LifeCycleState get_state(){
+ return m_sm.getState();
+ }
+
+ /**
+ * <p>ExecutionContextのID</p>
+ */
+ public int ec_id;
+ /**
+ * <p>ExecutionContextのStateMachine</p>
+ */
+ public StateMachine<LifeCycleState, DFPBase> m_sm;
+
+ }
+
+ /**
+ * <p>DataFlowComponentのAction定義用抽象クラスです。</p>
+ */
+ protected class DFP extends DFPBase {
+ /**
+ * <p>コンストラクタです。</p>
+ *
+ * @param obj 対象コンポーネント
+ * @param id ExecutionContextのID
+ */
+ public DFP(DataFlowComponent obj, int id) {
+ super(id);
+ m_obj = obj;
+ }
+ /**
+ * <p>onStartupアクション定義用メソッドです。</p>
+ */
+ public void on_startup() {
+ m_obj.on_startup(ec_id);
+ }
+ /**
+ * <p>onShutdownアクション定義用メソッドです。</p>
+ */
+ public void on_shutdown() {
+ m_obj.on_shutdown(ec_id);
+ }
+ /**
+ * <p>onActivatedアクション定義用メソッドです。</p>
+ */
+ public void on_activated(final StateHolder st) {
+ if( m_obj.on_activated(ec_id) != ReturnCode_t.RTC_OK ) {
+ m_sm.goTo(LifeCycleState.ERROR_STATE);
+ return;
+ }
+ return;
+ }
+ /**
+ * <p>onDeactivatedアクション定義用メソッドです。</p>
+ */
+ public void on_deactivated(final StateHolder st) {
+ if( m_obj.on_deactivated(ec_id) != ReturnCode_t.RTC_OK ) {
+ m_sm.goTo(LifeCycleState.ERROR_STATE);
+ return;
+ }
+ return;
+ }
+ /**
+ * <p>onAbortingアクション定義用メソッドです。</p>
+ */
+ public void on_aborting(final StateHolder st) {
+ m_obj.on_aborting(ec_id);
+ }
+ /**
+ * <p>onErrorアクション定義用メソッドです。</p>
+ */
+ public void on_error(final StateHolder st) {
+ m_obj.on_error(ec_id);
+ }
+ /**
+ * <p>onResetアクション定義用メソッドです。</p>
+ */
+ public void on_reset(final StateHolder st) {
+ if( m_obj.on_reset(ec_id) != ReturnCode_t.RTC_OK) {
+ m_sm.goTo(LifeCycleState.ERROR_STATE);
+ return;
+ }
+ return;
+ }
+ /**
+ * <p>onExecuteアクション定義用メソッドです。</p>
+ */
+ public void on_execute(final StateHolder st) {
+ if( m_obj.on_execute(ec_id) != ReturnCode_t.RTC_OK) {
+ m_sm.goTo(LifeCycleState.ERROR_STATE);
+ return;
+ }
+ return;
+ }
+ /**
+ * <p>onStateUpdateアクション定義用メソッドです。</p>
+ */
+ public void on_state_update(final StateHolder st) {
+ if( m_obj.on_state_update(ec_id) != ReturnCode_t.RTC_OK) {
+ m_sm.goTo(LifeCycleState.ERROR_STATE);
+ return;
+ }
+ return;
+ }
+ /**
+ * <p>onRateChangedアクション定義用メソッドです。</p>
+ */
+ public void on_rate_changed() {
+ m_obj.on_rate_changed(ec_id);
+ }
+ private DataFlowComponent m_obj;
+ }
+
+ /**
+ * <p>ExecutionContextにattachされたコンポーネントのメソッド呼出用クラスです。</p>
+ */
+ protected class Comp {
+ /**
+ * <p>コンストラクタです。</p>
+ *
+ * @param ref 対象コンポーネント
+ * @param dfp ExecutionContextの対象StateMachine
+ * @param id ExecutionContextのID
+ */
+ public Comp(LightweightRTObject ref, DataFlowComponent dfp, int id) {
+ this._ref = ref;
+ this._sm = new DFP(dfp, id);
+ }
+ /**
+ * <p>コンストラクタです。</p>
+ *
+ * @param comp 対象コンポーネント
+ */
+ public Comp(final Comp comp) {
+ this._ref = comp._ref;
+ this._sm = new DFP(comp._sm.m_obj, comp._sm.ec_id);
+ }
+ /**
+ * <p>コンポーネントをコピーします。</p>
+ *
+ * @param comp 対象コンポーネント
+ */
+ public Comp substitute(final Comp comp) {
+ this._ref = comp._ref;
+ this._sm.m_obj = comp._sm.m_obj;
+ this._sm.ec_id = comp._sm.ec_id;
+ return this;
+ }
+ /**
+ * <p>ExecutionContextから呼び出されるメソッドです。</p>
+ */
+ public void invoke(){
+ this._sm.worker();
+ }
+ /**
+ * <p>ExecutionContextから呼び出されるメソッドです。</p>
+ */
+ public void invoke_work_pre(){
+ this._sm.worker_pre();
+ }
+ /**
+ * <p>ExecutionContextから呼び出されるメソッドです。</p>
+ */
+ public void invoke_work_do(){
+ this._sm.worker_do();
+ }
+ /**
+ * <p>ExecutionContextから呼び出されるメソッドです。</p>
+ */
+ public void invoke_work_post(){
+ this._sm.worker_post();
+ }
+ /**
+ * <p>StartUp時に呼び出されるメソッドです。</p>
+ */
+ public void invoke_on_startup(){
+ this._sm.on_startup();
+ }
+ /**
+ * <p>ShutDown時に呼び出されるメソッドです。</p>
+ */
+ public void invoke_on_shutdown(){
+ this._sm.on_shutdown();
+ }
+ /**
+ * <p>RateChanged時に呼び出されるメソッドです。</p>
+ */
+ public void invoke_on_rate_changed(){
+ this._sm.on_rate_changed();
+ }
+ /**
+ * <p>StateMachine管理対象コンポーネントです。</p>
+ */
+ public LightweightRTObject _ref;
+ /**
+ * <p>対象コンポーネントのStateMachineです。</p>
+ */
+ public DFP _sm;
+ }
+ /**
+ * <p>管理対象コンポーネント検索用ヘルパークラスです。</p>
+ */
+ protected class find_comp {
+ private LightweightRTObject m_comp;
+ public find_comp(LightweightRTObject comp) {
+ m_comp = comp;
+ }
+ public boolean eqaulof(Comp comp) {
+ return comp._ref._is_equivalent(m_comp);
+ }
+ };
+
+ /**
+ * <p>ExecutionContextにatttachされているコンポーネントのリストです。</p>
+ */
+ protected ArrayList<Comp> m_comps = new ArrayList<Comp>();
+ /**
+ * <p>ExecutionContextの実行状態です。</p>
+ */
+ protected boolean m_running;
+ /**
+ * <p>ExecutionContext のスレッド実行フラグです。</p>
+ */
+ private boolean m_svc;
+
private class Worker {
public Worker() {
@@ -103,15 +977,60 @@
}
private Worker m_worker = new Worker();
+ /**
+ * <p>ExecutionContextProfileです。</p>
+ */
+ protected ExecutionContextProfile m_profile = new ExecutionContextProfile();
+ /**
+ * <p>ExecutionContextの動作周期です。</p>
+ */
+ protected long m_usec;
+ /**
+ * <p>ExecutionContextServiceとしてのCORBAオブジェクト参照です。</p>
+ */
+ protected ExecutionContextService m_ref;
+ protected boolean m_nowait;
+ protected Thread m_thread = null;
+
/**
+ * {@.ja OpenHRPExecutionContext を生成する}
+ * {@.en Creats OpenHRPExecutionContext}
+ *
+ * @return
+ * {@.ja 生成されたExtTrigExecutionContext}
+ * {@.en Object Created instances}
+ *
+ *
+ */
+ public ExecutionContextBase creator_() {
+ return new ExtTrigExecutionContext();
+ }
+ /**
+ * {@.ja Object を破棄する}
+ * {@.en Destructs Object}
+ *
+ * @param obj
+ * {@.ja 破棄するインタスタンス}
+ * {@.en The target instances for destruction}
+ *
+ */
+ public void destructor_(Object obj) {
+ obj = null;
+ }
+ /**
* <p>このExecutionContextを生成するFactoryクラスを
* ExecutionContext用ObjectManagerに登録します。</p>
*
* @param manager Managerオブジェクト
*/
public static void ExtTrigExecutionContextInit(Manager manager) {
- manager.registerECFactory("jp.go.aist.rtm.RTC.executionContext.ExtTrigExecutionContext");
+
+ ExecutionContextFactory<ExecutionContextBase,String> factory
+ = ExecutionContextFactory.instance();
+ factory.addFactory("jp.go.aist.rtm.RTC.executionContext.ExtTrigExecutionContext",
+ new ExtTrigExecutionContext(),
+ new ExtTrigExecutionContext());
}
/**
@@ -136,4 +1055,113 @@
* <p>Logging用フォーマットオブジェクト</p>
*/
protected Logbuf rtcout;
+ /**
+ * {@.ja ExecutionContextクラスの初期化関数}
+ * {@.en Initialization function of ExecutionContext class}
+ */
+ public void init(Properties props) {
+ }
+
+ /**
+ * {@.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 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();
+ }
+ /**
+ * {@.ja ExecutionContext の実行周期(Hz)を設定する}
+ * {@.en Set execution rate(Hz) of ExecutionContext}
+ * <p>
+ * {@.ja Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を設定す
+ * る。実行周期の変更は、DataFlowComponentAction の
+ * on_rate_changed によって各RTコンポーネントに伝達される。}
+ * {@.en This operation shall set the rate (in hertz) at which this
+ * context’s Active participating RTCs are being called. If the
+ * execution kind of the context is PERIODIC, a rate change shall
+ * result in the invocation of on_rate_changed on any RTCs
+ * realizing DataFlowComponentAction that are registered with any
+ * RTCs participating in the context.}
+ *
+ * @param rate
+ * {@.ja 処理周期(単位:Hz)}
+ * {@.en Execution cycle(Unit:Hz)}
+ *
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード
+ * RTC_OK: 正常終了
+ * BAD_PARAMETER: 設定値が負の値}
+ * {@.en The return code of ReturnCode_t type
+ * RTC_OK: Succeed
+ * BAD_PARAMETER: Invalid value. The value might be negative.}
+ *
+ */
+ public ReturnCode_t setRate(double rate) {
+ return m_profile.setRate(rate);
+ }
+ /**
+ * {@.ja ExecutionContext の実行周期(Hz)を取得する}
+ * {@.en Get execution rate(Hz) of ExecutionContext}
+ * <p>
+ * {@.ja Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を取得す
+ * る。}
+ * {@.en This operation shall return the rate (in hertz) at which its
+ * Active participating RTCs are being invoked.}
+ *
+ * @return
+ * {@.ja 処理周期(単位:Hz)}
+ * {@.en Execution cycle(Unit:Hz)}
+ *
+ */
+ public double getRate() {
+ return m_profile.getRate();
+ }
+ /**
+ * {@.ja ExecutionKind を文字列化する}
+ * {@.en Converting ExecutionKind enum to string}
+ * <p>
+ * {@.ja RTC::ExecutionKind で定義されている PERIODIC, EVENT_DRIVEN,
+ * OTHER を文字列化する。}
+ * {@.en This function converts enumeration (PERIODIC, EVENT_DRIVEN,
+ * OTHER) defined in RTC::ExecutionKind to string.}
+ *
+ * @param kind
+ * {@.ja ExecutionKind}
+ * {@.en ExecutionKind}
+ * @return
+ * {@.ja 文字列化されたExecutionKind}
+ * {@.en String of ExecutionKind}
+ *
+ */
+ public final String getKindString(ExecutionKind kind) {
+ return m_profile.getKindString(kind);
+ }
+
}
Copied: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/IExecutionContextBase.java (from rev 660, branches/work/DesignChangeOfEC/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 (rev 0)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/IExecutionContextBase.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -0,0 +1,46 @@
+package jp.go.aist.rtm.RTC.executionContext;
+
+import org.omg.CORBA.SystemException;
+
+import RTC.ExecutionContextService;
+import OpenRTM.ExtTrigExecutionContextServicePOA;
+
+import jp.go.aist.rtm.RTC.RTObject_impl;
+import jp.go.aist.rtm.RTC.util.Properties;
+import RTC.ExecutionKind;
+import RTC.ReturnCode_t;
+
+/**
+ * <p>Periodic Sampled Data Processing(周期実行用)ExecutionContextのベースとなる
+ * 抽象クラスです。</p>
+ */
+//public abstract class ExecutionContextBase
+// implements ECNewDeleteFunc {
+public interface IExecutionContextBase extends ECNewDeleteFunc {
+
+ /**
+ * {@.ja ExecutionContextクラスの初期化関数}
+ * {@.en Initialization function of ExecutionContext class}
+ */
+ public void init(Properties props);
+
+ /**
+ * <p> bindComponent </p>
+ *
+ * @param rtc RTObject
+ * @return ReturnCode_t
+ *
+ */
+ public ReturnCode_t bindComponent(RTObject_impl rtc);
+
+ public boolean finalizeExecutionContext();
+/*
+ public ExecutionContextProfile m_profile
+ = new jp.go.aist.rtm.RTC.executionContext.ExecutionContextProfile();
+*/
+/*
+ protected ExecutionContextProfile m_profile
+ = new ExecutionContextProfile();
+*/
+
+}
Modified: trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/OpenHRPExecutionContext.java
===================================================================
--- trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/OpenHRPExecutionContext.java 2012-02-10 08:03:08 UTC (rev 660)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/OpenHRPExecutionContext.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -1,6 +1,8 @@
package jp.go.aist.rtm.RTC.executionContext;
import jp.go.aist.rtm.RTC.Manager;
+import jp.go.aist.rtm.RTC.ObjectCreator;
+import jp.go.aist.rtm.RTC.ObjectDestructor;
import org.omg.CORBA.SystemException;
@@ -9,8 +11,9 @@
*
*/
public class OpenHRPExecutionContext
- extends PeriodicExecutionContext implements Runnable{
-
+// extends PeriodicExecutionContext implements Runnable{
+extends PeriodicExecutionContext
+implements Runnable, ObjectCreator<ExecutionContextBase>, ObjectDestructor, ExecutionContextBase{
/**
* <p> Constructor </p>
*/
@@ -72,12 +75,42 @@
private Worker m_worker = new Worker();
/**
+ * {@.ja OpenHRPExecutionContext を生成する}
+ * {@.en Creats OpenHRPExecutionContext}
+ *
+ * @return
+ * {@.ja 生成されたOpenHRPExecutionContext}
+ * {@.en Object Created instances}
+ *
+ *
+ */
+ public OpenHRPExecutionContext creator_() {
+ return new OpenHRPExecutionContext();
+ }
+ /**
+ * {@.ja Object を破棄する}
+ * {@.en Destructs Object}
+ *
+ * @param obj
+ * {@.ja 破棄するインタスタンス}
+ * {@.en The target instances for destruction}
+ *
+ */
+ public void destructor_(Object obj) {
+ obj = null;
+ }
+ /**
* <p> OpenHRPExecutionContextInit </p>
*
* @param manager Manager
*/
public static void OpenHRPExecutionContextInit(Manager manager) {
- manager.registerECFactory("jp.go.aist.rtm.RTC.executionContext.OpenHRPExecutionContext");
+// manager.registerECFactory("jp.go.aist.rtm.RTC.executionContext.OpenHRPExecutionContext");
+ ExecutionContextFactory<ExecutionContextBase,String> factory
+ = ExecutionContextFactory.instance();
+ factory.addFactory("jp.go.aist.rtm.RTC.executionContext.OpenHRPExecutionContext",
+ new OpenHRPExecutionContext(),
+ new OpenHRPExecutionContext());
}
/**
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 2012-02-10 08:03:08 UTC (rev 660)
+++ trunk/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/executionContext/PeriodicExecutionContext.java 2012-02-10 09:36:40 UTC (rev 661)
@@ -3,6 +3,8 @@
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.RTObject_impl;
import jp.go.aist.rtm.RTC.StateAction;
import jp.go.aist.rtm.RTC.StateHolder;
@@ -11,13 +13,16 @@
import jp.go.aist.rtm.RTC.util.CORBA_SeqUtil;
import jp.go.aist.rtm.RTC.util.NVUtil;
import jp.go.aist.rtm.RTC.util.POAUtil;
+import jp.go.aist.rtm.RTC.util.Properties;
+import jp.go.aist.rtm.RTC.util.TimeValue;
import jp.go.aist.rtm.RTC.util.equalFunctor;
+//import RTC.ExecutionContextProfile;
import OpenRTM.DataFlowComponent;
import OpenRTM.DataFlowComponentHelper;
-import RTC.ExecutionContextProfile;
import RTC.ExecutionContextProfileHolder;
import RTC.ExecutionContextService;
import RTC.ExecutionContextServiceHelper;
+import RTC.ExecutionContextServicePOA;
import RTC.ExecutionKind;
import RTC.LifeCycleState;
import RTC.LightweightRTObject;
@@ -28,8 +33,12 @@
* <p>Periodic Sampled Data Processing(周期実行用)ExecutionContextクラスです。</p>
*/
-public class PeriodicExecutionContext extends ExecutionContextBase implements Runnable {
+//public class PeriodicExecutionContext extends ExtTrigExecutionContextServicePOA implements Runnable, ExecutionContextBase {
+public class PeriodicExecutionContext
+extends ExecutionContextServicePOA
+implements Runnable, ObjectCreator<ExecutionContextBase>, ObjectDestructor, ExecutionContextBase {
+
/**
* {@.ja デフォルトコンストラクタ}
* {@.en Default Constructor}
@@ -55,14 +64,21 @@
m_usec = (long)(1000000/rate);
- m_ref = (ExecutionContextService)this.__this();
+ //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];
+*/
}
/**
@@ -107,19 +123,29 @@
m_svc = true;
m_nowait = true;
- if( rate==0 ) rate = (1.0/0.000001);//1000000Hz
-
+ if( rate==0 ) {
+ rate = (1.0/0.000001);//1000000Hz
+ }
m_usec = (long)(1000000/rate);
- if( m_usec==0 ) m_nowait = true;
+ if( m_usec==0 ) {
+ m_nowait = true;
+ }
- m_ref = (ExecutionContextService)this.__this();
+ //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];
+*/
}
/**
@@ -177,12 +203,14 @@
*
* @return ExecutionContextService
*/
+/*
public ExecutionContextService getObjRef() {
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.getObjRef()");
return m_ref;
}
+*/
/**
* <p>本オブジェクトのExecutionContextServiceとしてのCORBAオブジェクト参照を設定します。</p>
*
@@ -228,7 +256,9 @@
}
if (m_worker.running_) {
for (int intIdx=0; intIdx < m_comps.size(); ++intIdx) {
- m_comps.elementAt(intIdx).invoke();
+ m_comps.get(intIdx).invoke_work_pre();
+ m_comps.get(intIdx).invoke_work_do();
+ m_comps.get(intIdx).invoke_work_post();
}
}
}
@@ -344,9 +374,12 @@
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.get_rate()");
+ return m_profile.getRate();
+/*
synchronized (m_profile) {
return m_profile.rate;
}
+*/
}
/**
@@ -360,14 +393,24 @@
if( rate<=0.0 ) return ReturnCode_t.BAD_PARAMETER;
+ m_profile.setRate(rate);
+/*
synchronized (m_profile) {
m_profile.rate = rate;
}
+*/
this.m_usec = (long)(1000000/rate);
- if( m_usec == 0 ) m_nowait = true;
+ if( m_usec == 0 ) {
+ m_nowait = true;
+ }
for(int intIdx=0;intIdx<m_comps.size();intIdx++ ) {
m_comps.elementAt(intIdx).invoke_on_rate_changed();
}
+ rtcout.println(Logbuf.DEBUG, "Actual period: "
+ + m_profile.getPeriod().sec()
+ + " [sec], "
+ + m_profile.getPeriod().usec()
+ + " [usec]");
return ReturnCode_t.RTC_OK;
}
@@ -474,9 +517,11 @@
*/
public ExecutionKind get_kind() {
- rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.get_kind()");
+ rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.get_kind() ="
+ + m_profile.getKindString());
- return m_profile.kind;
+ return m_profile.getKind();
+ //return m_profile.kind;
}
/**
@@ -525,11 +570,14 @@
//
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;
@@ -572,7 +620,8 @@
m_comps.add(new Comp((LightweightRTObject)comp._duplicate(),
(DataFlowComponent)dfp._duplicate(),
id));
- m_profile.owner = (DataFlowComponent)dfp._duplicate();
+ m_profile.setOwner((LightweightRTObject)dfp._duplicate());
+ //m_profile.owner = (DataFlowComponent)dfp._duplicate();
return ReturnCode_t.RTC_OK;
@@ -616,7 +665,10 @@
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.");
+ rtcout.println(Logbuf.TRACE,
+ "remove_component(): an RTC removed from this context.");
+ m_profile.removeComponent(comp);
+/*
RTC.RTObject rtcomp = RTC.RTObjectHelper.narrow(comp);
if(rtcomp == null){
rtcout.println(Logbuf.ERROR,"Invalid object reference.");
@@ -636,6 +688,7 @@
CORBA_SeqUtil.erase(holder, (int)index);
m_profile.participants = holder.value;
}
+*/
return ReturnCode_t.RTC_OK;
}
}
@@ -651,15 +704,17 @@
*
* @return ExecutionContextProfile
*/
- public ExecutionContextProfile get_profile() {
+ public RTC.ExecutionContextProfile get_profile() {
rtcout.println(Logbuf.TRACE, "PeriodicExecutionContext.get_profile()");
-
+ return m_profile.getProfile();
+/*
ExecutionContextProfileHolder p;
synchronized (m_profile) {
p = new ExecutionContextProfileHolder(m_profile);
}
return p.value;
+*/
}
/**
@@ -795,6 +850,15 @@
public void worker() {
m_sm.worker();
}
+ public void worker_pre() {
+ m_sm.worker_pre();
+ }
+ public void worker_do() {
+ m_sm.worker_do();
+ }
+ public void worker_post() {
+ m_sm.worker_post();
+ }
/**
* <p>現在の状態を取得します。</p>
@@ -955,6 +1019,24 @@
this._sm.worker();
}
/**
+ * <p>ExecutionContextから呼び出されるメソッドです。</p>
+ */
+ public void invoke_work_pre(){
+ this._sm.worker_pre();
+ }
+ /**
+ * <p>ExecutionContextから呼び出されるメソッドです。</p>
+ */
+ public void invoke_work_do(){
+ this._sm.worker_do();
+ }
+ /**
+ * <p>ExecutionContextから呼び出されるメソッドです。</p>
+ */
+ public void invoke_work_post(){
+ this._sm.worker_post();
+ }
+ /**
* <p>StartUp時に呼び出されるメソッドです。</p>
*/
public void invoke_on_startup(){
@@ -1043,10 +1125,40 @@
* @param manager Managerオブジェクト
*/
public static void PeriodicExecutionContextInit(Manager manager) {
- manager.registerECFactory("jp.go.aist.rtm.RTC.executionContext.PeriodicExecutionContext");
+ //manager.registerECFactory("jp.go.aist.rtm.RTC.executionContext.PeriodicExecutionContext");
+ ExecutionContextFactory<ExecutionContextBase,String> factory
+ = ExecutionContextFactory.instance();
+ factory.addFactory("jp.go.aist.rtm.RTC.executionContext.PeriodicExecutionContext",
+ new PeriodicExecutionContext(),
+ new PeriodicExecutionContext());
}
/**
+ * {@.ja PeriodicExecutionContext を生成する}
+ * {@.en Creats PeriodicExecutionContext}
+ *
+ * @return
+ * {@.ja 生成されたinstance}
+ * {@.en Object Created instances}
+ *
+ *
+ */
+ public ExecutionContextBase creator_() {
+ return new PeriodicExecutionContext();
+ }
+ /**
+ * {@.ja Object を破棄する}
+ * {@.en Destructs Object}
+ *
+ * @param obj
+ * {@.ja 破棄するインタスタンス}
+ * {@.en The target instances for destruction}
+ *
+ */
+ public void destructor_(Object obj) {
+ obj = null;
+ }
+ /**
* <p>ExecutionContextのインスタンスを取得します。</p>
*
* @return ExecutionContextインスタンス
@@ -1077,4 +1189,115 @@
return m_obj._is_equivalent((RTC.RTObject)object);
}
}
+
+ /**
+ * {@.ja ExecutionContextクラスの初期化関数}
+ * {@.en Initialization function of ExecutionContext class}
+ */
+ public void init(Properties props) {
+ }
+
+ /**
+ * {@.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 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();
+ }
+ /**
+ * {@.ja ExecutionContext の実行周期(Hz)を設定する}
+ * {@.en Set execution rate(Hz) of ExecutionContext}
+ * <p>
+ * {@.ja Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を設定す
+ * る。実行周期の変更は、DataFlowComponentAction の
+ * on_rate_changed によって各RTコンポーネントに伝達される。}
+ * {@.en This operation shall set the rate (in hertz) at which this
+ * context’s Active participating RTCs are being called. If the
+ * execution kind of the context is PERIODIC, a rate change shall
+ * result in the invocation of on_rate_changed on any RTCs
+ * realizing DataFlowComponentAction that are registered with any
+ * RTCs participating in the context.}
+ *
+ * @param rate
+ * {@.ja 処理周期(単位:Hz)}
+ * {@.en Execution cycle(Unit:Hz)}
+ *
+ * @return
+ * {@.ja ReturnCode_t 型のリターンコード
+ * RTC_OK: 正常終了
+ * BAD_PARAMETER: 設定値が負の値}
+ * {@.en The return code of ReturnCode_t type
+ * RTC_OK: Succeed
+ * BAD_PARAMETER: Invalid value. The value might be negative.}
+ *
+ */
+ public ReturnCode_t setRate(double rate) {
+ return m_profile.setRate(rate);
+ }
+ /**
+ * {@.ja ExecutionContext の実行周期(Hz)を取得する}
+ * {@.en Get execution rate(Hz) of ExecutionContext}
+ * <p>
+ * {@.ja Active 状態にてRTコンポーネントが実行される周期(単位:Hz)を取得す
+ * る。}
+ * {@.en This operation shall return the rate (in hertz) at which its
+ * Active participating RTCs are being invoked.}
+ *
+ * @return
+ * {@.ja 処理周期(単位:Hz)}
+ * {@.en Execution cycle(Unit:Hz)}
+ *
+ */
+ public double getRate() {
+ return m_profile.getRate();
+ }
+ /**
+ * {@.ja ExecutionKind を文字列化する}
+ * {@.en Converting ExecutionKind enum to string}
+ * <p>
+ * {@.ja RTC::ExecutionKind で定義されている PERIODIC, EVENT_DRIVEN,
+ * OTHER を文字列化する。}
+ * {@.en This function converts enumeration (PERIODIC, EVENT_DRIVEN,
+ * OTHER) defined in RTC::ExecutionKind to string.}
+ *
+ * @param kind
+ * {@.ja ExecutionKind}
+ * {@.en ExecutionKind}
+ * @return
+ * {@.ja 文字列化されたExecutionKind}
+ * {@.en String of ExecutionKind}
+ *
+ */
+ public final String getKindString(ExecutionKind kind) {
+ return m_profile.getKindString(kind);
+ }
}
openrtm-commit メーリングリストの案内