[openrtm-commit:01788] r781 - in trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC: src/RTMExamples/SimpleIO src/jp/go/aist/rtm/RTC/util tests/src/jp/go/aist/rtm/RTC/util
openrtm @ openrtm.org
openrtm @ openrtm.org
2016年 2月 29日 (月) 15:28:51 JST
Author: win-ei
Date: 2016-02-29 15:28:51 +0900 (Mon, 29 Feb 2016)
New Revision: 781
Modified:
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/SimpleIO/ConsoleInImpl.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/util/RTShellUtil.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/RTC/util/RTShellUtilTest.java
Log:
Added functions for component operation.
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/SimpleIO/ConsoleInImpl.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/SimpleIO/ConsoleInImpl.java 2016-02-28 11:59:00 UTC (rev 780)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/SimpleIO/ConsoleInImpl.java 2016-02-29 06:28:51 UTC (rev 781)
@@ -99,6 +99,9 @@
m_outOut.addConnectorListener(
ConnectorListenerType.ON_CONNECT,
new Listener("ON_CONNECT"));
+ m_outOut.addConnectorListener(
+ ConnectorListenerType.ON_DISCONNECT,
+ new Listener("ON_DISCONNECT"));
return super.onInitialize();
}
// The finalize action (on ALIVE->END transition)
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/util/RTShellUtil.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/util/RTShellUtil.java 2016-02-28 11:59:00 UTC (rev 780)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/util/RTShellUtil.java 2016-02-29 06:28:51 UTC (rev 781)
@@ -1180,6 +1180,15 @@
PortService port, PortServiceListHolder target_ports){
ReturnCode_t ret = ReturnCode_t.RTC_OK;
+ if(port == null){
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+ if(target_ports == null){
+ return ReturnCode_t.BAD_PARAMETER;
+ }
+ if(target_ports.value == null){
+ return ReturnCode_t.BAD_PARAMETER;
+ }
for (int ic=0; ic < target_ports.value.length; ++ic) {
if(target_ports.value[ic]._is_equivalent(port)){
continue;
@@ -1227,7 +1236,8 @@
*
* @return
* {@.ja RTC、ポートがnilの場合はBAD_PARAMETERを返す。
- * nilではない場合はport0.connect関数の戻り値を返す。RTC_OKの場合は接続が成功}
+ * nilではない場合はport0.connect関数の戻り値を返す。
+ * RTC_OKの場合は接続が成功}
* {@.en Return code}
*
*
@@ -1265,13 +1275,18 @@
* {@.en Conenctor Profile}
*
* @return
- * {@.ja コネクタプロファイルで保持しているポートのオブジェクトリファレンスがnilの場合はBAD_PARAMETERを返す
- * nilではない場合はports[0].disconnect関数の戻り値を返す。RTC_OKの場合は切断が成功}
+ * {@.ja コネクタプロファイルで保持しているポートの
+ * オブジェクトリファレンスがnilの場合はBAD_PARAMETERを返す
+ * nilではない場合はports[0].disconnect関数の戻り値を返す。
+ * RTC_OKの場合は切断が成功}
* {@.en Return code}
*
*
*/
public static ReturnCode_t disconnect(ConnectorProfile connector_prof){
+ if(connector_prof == null){
+ return ReturnCode_t.BAD_PARAMETER;
+ }
PortServiceListHolder ports = new PortServiceListHolder();
ports.value = connector_prof.ports;
return disconnect_by_connector_id(ports.value[0],
@@ -1346,7 +1361,8 @@
}
/**
*
- * {@.ja 対象ポートと接続しているポートで指定したポート名と一致した場合に切断}
+ * {@.ja 対象ポートと接続しているポートで指定したポート名と一致した場合に
+ * 切断}
* {@.en Disconnects a connection in specified by port.}
*
* @param localport
@@ -1358,8 +1374,11 @@
* {@.en port name}
*
* @return
- * {@.ja ポートがnilの場合、localportの名前とothernameが一致する場合、接続しているポートの名前でothernameと一致するものがない場合にBAD_PARAMETERを返す
- * 上記の条件に当てはまらない場合はdisconnect関数の戻り値を返す。RTC_OKの場合は切断が成功}
+ * {@.ja ポートがnilの場合、localportの名前とothernameが一致する場合、
+ * 接続しているポートの名前でothernameと一致するものがない場合に
+ * BAD_PARAMETERを返す
+ * 上記の条件に当てはまらない場合はdisconnect関数の戻り値を返す。
+ * RTC_OKの場合は切断が成功}
* {@.en Return code}
*
*
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/RTC/util/RTShellUtilTest.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/RTC/util/RTShellUtilTest.java 2016-02-28 11:59:00 UTC (rev 780)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/tests/src/jp/go/aist/rtm/RTC/util/RTShellUtilTest.java 2016-02-29 06:28:51 UTC (rev 781)
@@ -13,6 +13,7 @@
import RTMExamples.SimpleIO.ConsoleIn;
import RTMExamples.SimpleIO.ConsoleOut;
import RTMExamples.SimpleService.MyServiceConsumer;
+import RTMExamples.ConfigSample.ConfigSample;
import jp.go.aist.rtm.RTC.Manager;
import jp.go.aist.rtm.RTC.ModuleInitProc;
@@ -58,15 +59,24 @@
new CorbaConsumer<DataFlowComponent>(DataFlowComponent.class);
private CorbaConsumer<DataFlowComponent> m_conin =
new CorbaConsumer<DataFlowComponent>(DataFlowComponent.class);
+ private CorbaConsumer<DataFlowComponent> m_conin2 =
+ new CorbaConsumer<DataFlowComponent>(DataFlowComponent.class);
private CorbaConsumer<DataFlowComponent> m_sercon =
new CorbaConsumer<DataFlowComponent>(DataFlowComponent.class);
+ private CorbaConsumer<DataFlowComponent> m_config =
+ new CorbaConsumer<DataFlowComponent>(DataFlowComponent.class);
private RTObjectHolder m_conoutRef
= new RTObjectHolder();
private RTObjectHolder m_coninRef
= new RTObjectHolder();
+ private RTObjectHolder m_coninRef2
+ = new RTObjectHolder();
private RTObjectHolder m_serconRef
= new RTObjectHolder();
+ private RTObjectHolder m_configRef
+ = new RTObjectHolder();
+
//private RTObject m_conoutRef;
private ExecutionContextListHolder m_eclisto
= new ExecutionContextListHolder();
@@ -78,6 +88,7 @@
private RTObject_impl m_out_impl;
private RTObject_impl m_in_impl;
private RTObject_impl m_out_seq_impl;
+ private RTObject_impl m_config_impl;
public RTShellUtilTest(String name){
super(name);
@@ -88,11 +99,13 @@
m_conoutRef = new RTObjectHolder();
m_coninRef = new RTObjectHolder();
+ m_coninRef2 = new RTObjectHolder();
m_serconRef = new RTObjectHolder();
+ m_configRef = new RTObjectHolder();
String[] args = new String[0];
//Manager manager = Manager.init(null);
- Manager m_manager = Manager.init(null);
+ m_manager = Manager.init(null);
//
//
//
@@ -131,8 +144,20 @@
System.out.println("MyServiceConsumer is null.");
}
//
+ Properties prop_config
+ = new Properties(ConfigSample.component_conf);
+ m_manager.registerFactory(prop_config,
+ new ConfigSample(), new ConfigSample());
+ //RTObject_impl
+ m_config_impl
+ = m_manager.createComponent("ConfigSample");
+ if(m_config_impl==null)
+ {
+ System.out.println("ConfigSample is null.");
+ }
//
//
+ //
m_manager.runManager(true);
//
//
@@ -206,9 +231,21 @@
} catch (InvalidName e) {
e.printStackTrace();
}
-
//
+ //
m_coninRef.value = m_conin._ptr();
+ try {
+ m_conin2.setObject(naming.resolve(".host_cxt/ConsoleIn1.rtc"));
+ } catch (NotFound e) {
+ e.printStackTrace();
+ } catch (CannotProceed e) {
+ e.printStackTrace();
+ } catch (InvalidName e) {
+ e.printStackTrace();
+ }
+ //
+ //
+ m_coninRef2.value = m_conin2._ptr();
try {
@@ -223,6 +260,20 @@
//
m_serconRef.value = m_sercon._ptr();
+ //
+ //
+ try {
+ m_config.setObject(naming.resolve(".host_cxt/ConfigSample0.rtc"));
+ } catch (NotFound e) {
+ e.printStackTrace();
+ } catch (CannotProceed e) {
+ e.printStackTrace();
+ } catch (InvalidName e) {
+ e.printStackTrace();
+ }
+
+ //
+ m_configRef.value = m_config._ptr();
}
@@ -237,6 +288,7 @@
protected void tearDown() throws Exception {
super.tearDown();
+/*
for(int ic=0;ic<m_eclisto.value.length;++ic){
m_eclisto.value[ic].stop();
}
@@ -246,10 +298,13 @@
for(int ic=0;ic<m_eclistseq.value.length;++ic){
m_eclistseq.value[ic].stop();
}
+*/
+/*
if(m_manager!=null){
m_manager.shutdown();
m_manager = null;
}
+*/
Thread.sleep(300);
}
@@ -689,23 +744,295 @@
prop.setDefaults(conprop);
ReturnCode_t code;
- code = RTShellUtil.connect("kamo",prop,port1,port2);
- assertTrue("test:",code == ReturnCode_t.RTC_OK);
+ code = RTShellUtil.connect("kamo0",prop,port1,port2);
+ assertTrue("test:connect",code == ReturnCode_t.RTC_OK);
+/*
try{
Thread.sleep(10000);
}
catch(InterruptedException e){
}
+*/
//
//
//
code = RTShellUtil.connect("",prop,port1,port2);
- code = RTShellUtil.connect("kamo",null,port1,port2);
- code = RTShellUtil.connect("kamo",prop,null,port2);
+ assertTrue("test:disconnect",code == ReturnCode_t.RTC_OK);
+ code = RTShellUtil.connect("kamo1",null,port1,port2);
+ assertTrue("test:disconnect",code == ReturnCode_t.RTC_OK);
+ code = RTShellUtil.connect("kamo2",prop,null,port2);
assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
- code = RTShellUtil.connect("kamo",prop,port1,null);
+ code = RTShellUtil.connect("kamo3",prop,port1,null);
assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+
+ code = RTShellUtil.disconnect_by_connector_name(port1, "kamo0");
+ assertTrue("test:disconnect",code == ReturnCode_t.RTC_OK);
+/*
+ try{
+ Thread.sleep(10000);
+ }
+ catch(InterruptedException e){
+ }
+*/
+ code = RTShellUtil.disconnect_by_connector_name(null, "kamo0");
+ assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+ code = RTShellUtil.disconnect_by_connector_name(port1, "kamo5");
+ assertTrue("test:"+code.value(),code == ReturnCode_t.BAD_PARAMETER);
}
+ /**
+ *
+ * connect
+ *
+ */
+ public void test_connect_by_name(){
+
+ PortService port1 = RTShellUtil.get_port_by_name(m_conoutRef.value,
+ "ConsoleOut0.in");
+ PortService port2 = RTShellUtil.get_port_by_name(m_coninRef.value,
+ "ConsoleIn0.out");
+ Properties prop = new Properties();
+ String[] conprop = {
+ "dataport.interface_type","corba_cdr",
+ "dataport.dataflow_type", "push",
+ ""
+ };
+
+ prop.setDefaults(conprop);
+ ReturnCode_t code;
+ code = RTShellUtil.connect_by_name("kamo0",prop,
+ m_conoutRef.value,"ConsoleOut0.in",
+ m_coninRef.value,"ConsoleIn0.out");
+ assertTrue("test:connect",code == ReturnCode_t.RTC_OK);
+/*
+ try{
+ Thread.sleep(10000);
+ }
+ catch(InterruptedException e){
+ }
+*/
+ //
+ //
+ //
+ code = RTShellUtil.connect_by_name("",prop,
+ m_conoutRef.value,"ConsoleOut0.in",
+ m_coninRef.value,"ConsoleIn0.out");
+ assertTrue("test:disconnect",code == ReturnCode_t.RTC_OK);
+ code = RTShellUtil.connect_by_name("kamo1",null,
+ m_conoutRef.value,"ConsoleOut0.in",
+ m_coninRef.value,"ConsoleIn0.out");
+ assertTrue("test:disconnect",code == ReturnCode_t.RTC_OK);
+ code = RTShellUtil.connect_by_name("kamo2",prop,
+ null,"ConsoleOut0.in",
+ m_coninRef.value,"ConsoleIn0.out");
+ assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+ code = RTShellUtil.connect_by_name("kamo3",prop,
+ m_conoutRef.value,"ConsoleOut0.in",
+ m_coninRef.value,"");
+ assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+
+
+ ConnectorProfile[] cprofs = port1.get_connector_profiles();
+ for(int ic=0;ic<cprofs.length;++ic){
+ if(cprofs[ic].name.equals("kamo0")){
+ code = RTShellUtil.disconnect(cprofs[ic]);
+ break;
+ }
+ }
+
+ assertTrue("test:disconnect "+code.value(),code == ReturnCode_t.RTC_OK);
+/*
+ try{
+ Thread.sleep(10000);
+ }
+ catch(InterruptedException e){
+ }
+*/
+ code = RTShellUtil.disconnect(null);
+ assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+ }
+ /**
+ *
+ * disconnect
+ *
+ */
+ public void test_disconnect_by_id(){
+
+ PortService port1 = RTShellUtil.get_port_by_name(m_conoutRef.value,
+ "ConsoleOut0.in");
+ PortService port2 = RTShellUtil.get_port_by_name(m_coninRef.value,
+ "ConsoleIn0.out");
+ Properties prop = new Properties();
+ String[] conprop = {
+ "dataport.interface_type","corba_cdr",
+ "dataport.dataflow_type", "push",
+ ""
+ };
+
+ prop.setDefaults(conprop);
+ ReturnCode_t code;
+ code = RTShellUtil.connect("kamo0",prop,port1,port2);
+ assertTrue("test:connect",code == ReturnCode_t.RTC_OK);
+ //
+ //
+ //
+ String id = new String();
+ ConnectorProfile[] cprofs = port1.get_connector_profiles();
+ for(int ic=0;ic<cprofs.length;++ic){
+ if(cprofs[ic].name.equals("kamo0")){
+ id = cprofs[ic].connector_id;
+ break;
+ }
+ }
+ code = RTShellUtil.disconnect_by_connector_id(port1,id);
+ assertTrue("test:disconnect",code == ReturnCode_t.RTC_OK);
+
+
+
+ code = RTShellUtil.disconnect_by_connector_id(null,id);
+ assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+ code = RTShellUtil.disconnect_by_connector_id(port1,"");
+ assertTrue("test:"+code.value(),code == ReturnCode_t.BAD_PARAMETER);
+
+ }
+ /**
+ *
+ * disconnect
+ *
+ */
+ public void test_disconnect_by_port_name(){
+ PortService port1 = RTShellUtil.get_port_by_name(m_conoutRef.value,
+ "ConsoleOut0.in");
+ PortService port2 = RTShellUtil.get_port_by_name(m_coninRef.value,
+ "ConsoleIn0.out");
+ Properties prop = new Properties();
+ String[] conprop = {
+ "dataport.interface_type","corba_cdr",
+ "dataport.dataflow_type", "push",
+ ""
+ };
+
+ prop.setDefaults(conprop);
+ ReturnCode_t code;
+ code = RTShellUtil.connect("kamo0",prop,port1,port2);
+ assertTrue("test:connect",code == ReturnCode_t.RTC_OK);
+
+
+
+
+ code = RTShellUtil.disconnect_by_port_name(port1,"ConsoleIn0.out");
+ assertTrue("test:disconnect",code == ReturnCode_t.RTC_OK);
+
+ code = RTShellUtil.disconnect_by_port_name(port1,"");
+ assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+ code = RTShellUtil.disconnect_by_port_name(null,"ConsoleIn0.out");
+ assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+
+ }
+ /**
+ *
+ * get_parameter_by_key
+ * get_current_configuration_name
+ * get_active_configuration
+ * set_configuration
+ */
+ public void test_get_parameter_by_key(){
+ String str;
+ str = RTShellUtil.get_parameter_by_key(m_configRef.value,
+ "default","double_param0");
+ assertTrue("test:",str.equals("0.11"));
+
+ str = RTShellUtil.get_parameter_by_key(m_configRef.value,
+ "","double_param0");
+ assertTrue("test:",str.equals(""));
+ str = RTShellUtil.get_parameter_by_key(m_configRef.value,
+ "default","");
+ assertTrue("test:",str.equals(""));
+
+
+
+ str = RTShellUtil.get_current_configuration_name(m_configRef.value);
+ assertTrue("test:",str.equals("default"));
+ str = RTShellUtil.get_current_configuration_name(null);
+ assertTrue("test:",str.equals(""));
+
+
+
+ Properties prop
+ = RTShellUtil.get_active_configuration(m_configRef.value);
+ str = prop.getProperty("double_param0");
+ assertTrue("test:",str.equals("0.11"));
+ prop = RTShellUtil.get_active_configuration(null);
+ assertTrue("test:",prop==null);
+
+ boolean bool = RTShellUtil.set_configuration(m_configRef.value,
+ "default", "double_param0","305.8560");
+ assertTrue("test:",bool);
+ str = RTShellUtil.get_parameter_by_key(m_configRef.value,
+ "default","double_param0");
+ assertTrue("test:",str.equals("305.8560"));
+ //
+ bool = RTShellUtil.set_configuration(null,
+ "default", "double_param0","305.8560");
+ assertTrue("test:",!bool);
+ bool = RTShellUtil.set_configuration(m_configRef.value,
+ "", "double_param0","305.8560");
+ assertTrue("test:",!bool);
+ bool = RTShellUtil.set_configuration(m_configRef.value,
+ "default", "double_param2","123.456");
+ assertTrue("test:",bool);
+ str = RTShellUtil.get_parameter_by_key(m_configRef.value,
+ "default","double_param2");
+ assertTrue("test:",str.equals("123.456"));
+
+
+ }
+ /**
+ *
+ * connect
+ *
+ */
+ public void test_connect_multi(){
+
+ PortService port1 = RTShellUtil.get_port_by_name(m_conoutRef.value,
+ "ConsoleOut0.in");
+ PortService port2 = RTShellUtil.get_port_by_name(m_coninRef.value,
+ "ConsoleIn0.out");
+ PortService port3 = RTShellUtil.get_port_by_name(m_coninRef2.value,
+ "ConsoleIn1.out");
+ Properties prop = new Properties();
+ String[] conprop = {
+ "dataport.interface_type","corba_cdr",
+ "dataport.dataflow_type", "push",
+ ""
+ };
+ PortServiceListHolder target_ports = new PortServiceListHolder();
+ target_ports.value = new PortService[2];
+ target_ports.value[0] = port2;
+ target_ports.value[1] = port3;
+ prop.setDefaults(conprop);
+ ReturnCode_t code;
+ code = RTShellUtil.connect_multi("kamo10", prop,
+ port1, target_ports);
+ assertTrue("test:",code == ReturnCode_t.RTC_OK);
+/*
+ try{
+ Thread.sleep(30000);
+ }
+ catch(InterruptedException e){
+ }
+*/
+ code = RTShellUtil.connect_multi("kamo11", prop,
+ null, target_ports);
+ assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+ code = RTShellUtil.connect_multi("kamo11", prop,
+ port1, null);
+ assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+ PortServiceListHolder error_ports = new PortServiceListHolder();
+ code = RTShellUtil.connect_multi("kamo11", prop,
+ port1, error_ports );
+ assertTrue("test:",code == ReturnCode_t.BAD_PARAMETER);
+ }
}
+
More information about the openrtm-commit
mailing list