[openrtm-commit:02024] r838 - in trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples: . TopicTest
openrtm @ openrtm.org
openrtm @ openrtm.org
2016年 10月 7日 (金) 11:43:45 JST
Author: win-ei
Date: 2016-10-07 11:43:45 +0900 (Fri, 07 Oct 2016)
New Revision: 838
Added:
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConnectorComp.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleIn.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleInComp.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleInImpl.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOut.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOutComp.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOutImpl.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/component.conf
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/rtc.conf
Log:
Added components for tests of \"port connect function of a topic base\". refs #3391
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConnectorComp.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConnectorComp.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConnectorComp.java 2016-10-07 02:43:45 UTC (rev 838)
@@ -0,0 +1,227 @@
+package RTMExamples.TopicTest;
+
+import jp.go.aist.rtm.RTC.CorbaNaming;
+import jp.go.aist.rtm.RTC.port.CorbaConsumer;
+import jp.go.aist.rtm.RTC.util.CORBA_SeqUtil;
+import jp.go.aist.rtm.RTC.util.NVUtil;
+import jp.go.aist.rtm.RTC.util.ORBUtil;
+import jp.go.aist.rtm.RTC.util.StringUtil;
+import jp.go.aist.rtm.RTC.util.CORBA_RTCUtil;
+
+import org.omg.CORBA.ORB;
+import org.omg.CosNaming.NamingContextPackage.CannotProceed;
+import org.omg.CosNaming.NamingContextPackage.InvalidName;
+import org.omg.CosNaming.NamingContextPackage.NotFound;
+
+import RTC.ConnectorProfile;
+import RTC.ConnectorProfileHolder;
+import OpenRTM.DataFlowComponent;
+import RTC.ExecutionContext;
+import RTC.ExecutionContextListHolder;
+import RTC.PortService;
+import RTC.PortServiceListHolder;
+import RTC.RTObject;
+import RTC.ReturnCode_t;
+import _SDOPackage.NVListHolder;
+import _SDOPackage.NameValue;
+
+public class ConnectorComp {
+
+ public static void main(String[] args) {
+/*
+ String subs_type = "flush";
+ String period = "";
+ String endian = "little,big";
+ for( int intIdx=0;intIdx<args.length;++intIdx ) {
+ String arg = new String(args[intIdx]);
+ if( arg.equals("--flush") ) {
+ subs_type = "Flush";
+ } else if( arg.equals("--new") ) {
+ subs_type = "New";
+ } else if (arg.equals("--periodic") ) {
+ subs_type = "Periodic";
+ if( ++intIdx<args.length) {
+ period = args[intIdx];
+ } else {
+ period = "1.0";
+ }
+ } else if( arg.equals("--endian") ) {
+ if( ++intIdx<args.length) {
+ endian = args[intIdx];
+ }
+ endian = StringUtil.normalize(endian);
+ } else if( arg.equals("--help") ) {
+ usage();
+ } else {
+ subs_type = "Flush";
+ }
+ }
+
+ System.out.println( "Subscription Type: " + subs_type );
+ if( !period.equals("") ) {
+ System.out.println( "Period: " + period + " [Hz]" );
+ }
+
+ System.out.println( "Endian: "+endian);
+
+ ORB orb = ORBUtil.getOrb(args);
+ CorbaNaming naming = null;
+ try {
+ naming = new CorbaNaming(orb, "localhost:2809");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ CorbaConsumer<DataFlowComponent> conin =
+ new CorbaConsumer<DataFlowComponent>(DataFlowComponent.class);
+ CorbaConsumer<DataFlowComponent> conout =
+ new CorbaConsumer<DataFlowComponent>(DataFlowComponent.class);
+ PortServiceListHolder pin = new PortServiceListHolder();
+ pin.value = new PortService[0];
+ PortServiceListHolder pout = new PortServiceListHolder();
+ pout.value = new PortService[0];
+
+ // find ConsoleIn0 component
+ try {
+ conin.setObject(naming.resolve("ConsoleIn0.rtc"));
+ } catch (NotFound e) {
+ e.printStackTrace();
+ } catch (CannotProceed e) {
+ e.printStackTrace();
+ } catch (InvalidName e) {
+ e.printStackTrace();
+ }
+
+ // get ports
+ pin.value = conin._ptr().get_ports();
+ pin.value[0].disconnect_all();
+ assert(pin.value.length > 0);
+ // activate ConsoleIn0
+ ExecutionContextListHolder eclisti = new ExecutionContextListHolder();
+ eclisti.value = new ExecutionContext[0];
+ RTObject coninRef = conin._ptr();
+ eclisti.value = coninRef.get_owned_contexts();
+ eclisti.value[0].activate_component(coninRef);
+
+ // find ConsoleOut0 component
+ try {
+ conout.setObject(naming.resolve("ConsoleOut0.rtc"));
+ } catch (NotFound e) {
+ e.printStackTrace();
+ } catch (CannotProceed e) {
+ e.printStackTrace();
+ } catch (InvalidName e) {
+ e.printStackTrace();
+ }
+ // get ports
+ pout.value = conout._ptr().get_ports();
+ pout.value[0].disconnect_all();
+ assert(pout.value.length > 0);
+ // activate ConsoleOut0
+ ExecutionContextListHolder eclisto = new ExecutionContextListHolder();
+ eclisto.value = new ExecutionContext[0];
+ RTObject conoutRef = conout._ptr();
+ eclisto.value = conoutRef.get_owned_contexts();
+ eclisto.value[0].activate_component(conoutRef);
+
+ // connect ports
+ ConnectorProfile prof = new ConnectorProfile();
+ prof.connector_id = "";
+ prof.name = "connector0";
+ prof.ports = new PortService[2];
+ prof.ports[0] = pin.value[0];
+ prof.ports[1] = pout.value[0];
+ NVListHolder nvholder = new NVListHolder();
+ nvholder.value = prof.properties;
+ if( nvholder.value==null ) nvholder.value = new NameValue[0];
+ CORBA_SeqUtil.push_back(nvholder,
+ NVUtil.newNVString("dataport.interface_type","corba_cdr"));
+ CORBA_SeqUtil.push_back(nvholder,
+ NVUtil.newNVString("dataport.dataflow_type", "push"));
+ CORBA_SeqUtil.push_back(nvholder,
+ NVUtil.newNVString("dataport.subscription_type", subs_type));
+ CORBA_SeqUtil.push_back(nvholder,
+ NVUtil.newNVString("dataport.serializer.cdr.endian", endian));
+
+ if( !period.equals("") )
+ CORBA_SeqUtil.push_back(nvholder,
+ NVUtil.newNVString("dataport.push_interval", period));
+ prof.properties = nvholder.value;
+
+ ConnectorProfileHolder proflist = new ConnectorProfileHolder();
+ proflist.value = prof;
+
+ ReturnCode_t ret = pin.value[0].connect(proflist);
+ assert(ret == ReturnCode_t.RTC_OK);
+
+ System.out.println( "Connector ID: " + prof.connector_id );
+ NVUtil.dump(new NVListHolder(proflist.value.properties));
+*/
+ System.out.println("..");
+
+ ORB orb = ORBUtil.getOrb(args);
+ CorbaNaming naming = null;
+ try {
+ naming = new CorbaNaming(orb, "localhost:2809");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ CorbaConsumer<DataFlowComponent> conin =
+ new CorbaConsumer<DataFlowComponent>(DataFlowComponent.class);
+ try {
+ conin.setObject(naming.resolve("ConsoleIn0.rtc"));
+ } catch (NotFound e) {
+ e.printStackTrace();
+ } catch (CannotProceed e) {
+ e.printStackTrace();
+ } catch (InvalidName e) {
+ e.printStackTrace();
+ }
+ PortService port0_var =
+ CORBA_RTCUtil.get_port_by_name(conin._ptr(), "ConsoleIn0.topic_out");
+
+ CorbaConsumer<DataFlowComponent> conout =
+ new CorbaConsumer<DataFlowComponent>(DataFlowComponent.class);
+
+ try {
+ conout.setObject(naming.resolve("ConsoleOut0.rtc"));
+ } catch (NotFound e) {
+ e.printStackTrace();
+ } catch (CannotProceed e) {
+ e.printStackTrace();
+ } catch (InvalidName e) {
+ e.printStackTrace();
+ }
+
+
+ PortService port1_var =
+ CORBA_RTCUtil.get_port_by_name(conout._ptr(), "ConsoleOut0.topic_in");
+
+ if(CORBA_RTCUtil.already_connected(port0_var, port1_var)){
+ System.out.println( "OK");
+ }
+ else{
+ System.out.println( "Fail");
+ }
+
+
+
+ orb.destroy();
+ }
+
+ private static void usage() {
+ System.out.println("");
+ System.out.println( "usage: ConnectorComp [options]" );
+ System.out.println("");
+ System.out.println( " --flush " );
+ System.out.println( ": Set subscription type Flush" );
+ System.out.println( " --new " );
+ System.out.println( ": Set subscription type New" );
+ System.out.println( " --periodic [Hz] " );
+ System.out.println( ": Set subscription type Periodic" );
+ System.out.println("");
+ }
+
+}
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleIn.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleIn.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleIn.java 2016-10-07 02:43:45 UTC (rev 838)
@@ -0,0 +1,42 @@
+package RTMExamples.TopicTest;
+
+
+import jp.go.aist.rtm.RTC.Manager;
+import jp.go.aist.rtm.RTC.RTObject_impl;
+import jp.go.aist.rtm.RTC.RtcDeleteFunc;
+import jp.go.aist.rtm.RTC.RtcNewFunc;
+import jp.go.aist.rtm.RTC.RegisterModuleFunc;
+import jp.go.aist.rtm.RTC.util.Properties;
+
+public class ConsoleIn implements RtcNewFunc, RtcDeleteFunc, RegisterModuleFunc {
+
+// Module specification
+// <rtc-template block="module_spec">
+ public static String component_conf[] = {
+ "implementation_id", "ConsoleIn",
+ "type_name", "ConsoleIn",
+ "description", "Console input component",
+ "version", "1.0",
+ "vendor", "Noriaki Ando, AIST",
+ "category", "example",
+ "activity_type", "DataFlowComponent",
+ "max_instance", "10",
+ "language", "Java",
+ "lang_type", "compile",
+ ""
+ };
+// </rtc-template>
+
+ public RTObject_impl createRtc(Manager mgr) {
+ return new ConsoleInImpl(mgr);
+ }
+
+ public void deleteRtc(RTObject_impl rtcBase) {
+ rtcBase = null;
+ }
+ public void registerModule() {
+ Properties prop = new Properties(component_conf);
+ final Manager manager = Manager.instance();
+ manager.registerFactory(prop, new ConsoleIn(), new ConsoleIn());
+ }
+}
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleInComp.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleInComp.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleInComp.java 2016-10-07 02:43:45 UTC (rev 838)
@@ -0,0 +1,89 @@
+package RTMExamples.TopicTest;
+
+
+import jp.go.aist.rtm.RTC.Manager;
+import jp.go.aist.rtm.RTC.ModuleInitProc;
+import jp.go.aist.rtm.RTC.RTObject_impl;
+import jp.go.aist.rtm.RTC.util.NVUtil;
+import jp.go.aist.rtm.RTC.util.Properties;
+import RTC.ComponentProfile;
+import RTC.PortService;
+import RTC.PortInterfacePolarity;
+import RTC.PortInterfaceProfileListHolder;
+import RTC.PortServiceListHolder;
+import _SDOPackage.NVListHolder;
+
+public class ConsoleInComp implements ModuleInitProc {
+
+ public void myModuleInit(Manager mgr) {
+ Properties prop = new Properties(ConsoleIn.component_conf);
+ mgr.registerFactory(prop, new ConsoleIn(), new ConsoleIn());
+
+ // Create a component
+ System.out.println("Creating a component: \"ConsoleIn\"....");
+ RTObject_impl comp = mgr.createComponent("ConsoleIn");
+ System.out.println("succeed.");
+/*
+ ComponentProfile prof = comp.get_component_profile();
+ System.out.println( "=================================================" );
+ System.out.println( " Component Profile" );
+ System.out.println( "-------------------------------------------------" );
+ System.out.println( "InstanceID: " + prof.instance_name );
+ System.out.println( "Implementation: " + prof.type_name );
+ System.out.println( "Description: " + prof.description );
+ System.out.println( "Version: " + prof.version );
+ System.out.println( "Maker: " + prof.vendor );
+ System.out.println( "Category: " + prof.category );
+ System.out.println( " Other properties " );
+ NVUtil.dump(new NVListHolder(prof.properties));
+ System.out.println( "=================================================" );
+
+ PortServiceListHolder portlist = new PortServiceListHolder(comp.get_ports());
+
+ for( int intIdx=0;intIdx<portlist.value.length;++intIdx ) {
+ PortService port = portlist.value[intIdx];
+ System.out.println( "=================================================" );
+ System.out.println( "Port" + intIdx + " (name): ");
+ System.out.println( port.get_port_profile().name );
+ System.out.println( "-------------------------------------------------" );
+ PortInterfaceProfileListHolder iflist = new PortInterfaceProfileListHolder(port.get_port_profile().interfaces);
+
+ for( int intIdx2=0;intIdx2<iflist.value.length;++intIdx2 ) {
+ System.out.println( "I/F name: " );
+ System.out.println( iflist.value[intIdx2].instance_name );
+ System.out.println( "I/F type: ");
+ System.out.println( iflist.value[intIdx2].type_name );
+ if( iflist.value[intIdx2].polarity==PortInterfacePolarity.PROVIDED ) {
+ System.out.println( "Polarity: PROVIDED" );
+ } else {
+ System.out.println( "Polarity: REQUIRED" );
+ }
+ }
+ System.out.println( "- properties -" );
+ NVUtil.dump(new NVListHolder(port.get_port_profile().properties));
+ System.out.println( "-------------------------------------------------" );
+ }
+*/
+ }
+
+ public static void main(String[] args) {
+ // Initialize manager
+ final Manager manager = Manager.init(args);
+
+ // Set module initialization proceduer
+ // This procedure will be invoked in activateManager() function.
+ ConsoleInComp init = new ConsoleInComp();
+ manager.setModuleInitProc(init);
+
+ // Activate manager and register to naming service
+ manager.activateManager();
+
+ // run the manager in blocking mode
+ // runManager(false) is the default.
+ manager.runManager();
+
+ // If you want to run the manager in non-blocking mode, do like this
+ // manager.runManager(true);
+ }
+
+}
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleInImpl.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleInImpl.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleInImpl.java 2016-10-07 02:43:45 UTC (rev 838)
@@ -0,0 +1,280 @@
+package RTMExamples.TopicTest;
+
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Observer;
+import java.util.Observable;
+
+import jp.go.aist.rtm.RTC.DataFlowComponentBase;
+import jp.go.aist.rtm.RTC.Manager;
+import jp.go.aist.rtm.RTC.port.OutPort;
+import jp.go.aist.rtm.RTC.port.ConnectorBase;
+import jp.go.aist.rtm.RTC.port.ConnectorListener;
+import jp.go.aist.rtm.RTC.port.ConnectorDataListener;
+import jp.go.aist.rtm.RTC.port.ConnectorDataListenerT;
+import jp.go.aist.rtm.RTC.port.ConnectorDataListenerType;
+import jp.go.aist.rtm.RTC.port.ConnectorListenerType;
+import jp.go.aist.rtm.RTC.util.DataRef;
+import RTC.ReturnCode_t;
+import RTC.TimedLong;
+import RTC.PortService;
+import RTC.PortServiceListHolder;
+
+import org.omg.PortableServer.POAPackage.ObjectNotActive;
+import org.omg.PortableServer.POAPackage.ServantAlreadyActive;
+import org.omg.PortableServer.POAPackage.WrongPolicy;
+
+import org.omg.CORBA.portable.OutputStream;
+
+import jp.go.aist.rtm.RTC.port.CorbaPort;
+
+import RTMExamples.SimpleService.MyServiceSVC_impl;
+
+
+
+public class ConsoleInImpl extends DataFlowComponentBase {
+ private class TopicCorbaPort<DataType> extends CorbaPort {
+ public TopicCorbaPort(final String name) {
+ super(name);
+ appendProperty("publish_topic","test");
+ }
+ }
+ private class TopicOutPort<DataType> extends OutPort {
+ public TopicOutPort(final String name, DataRef<DataType> valueRef) {
+ super(name,valueRef);
+ appendProperty("publish_topic","test");
+ }
+ }
+
+ public ConsoleInImpl(Manager manager) {
+ super(manager);
+ // <rtc-template block="initializer">
+ m_out_val = new TimedLong(new RTC.Time(0,0),0);
+ m_out = new DataRef<TimedLong>(m_out_val);
+ m_outOut = new OutPort<TimedLong>("out", m_out);
+
+ m_topic_out_val = new TimedLong(new RTC.Time(0,0),0);
+ m_topic_out = new DataRef<TimedLong>(m_topic_out_val);
+ m_topic_outOut = new TopicOutPort<TimedLong>("topic_out", m_topic_out);
+
+ m_ServicePort = new TopicCorbaPort("topic_service");
+ // </rtc-template>
+
+ // Registration: InPort/OutPort/Service
+ // <rtc-template block="registration">
+ // Set InPort buffers
+
+ // Set OutPort buffer
+ // Set service provider to Ports
+
+ // Set service consumers to Ports
+
+ // Set CORBA Service Ports
+
+ // </rtc-template>
+ }
+
+ // The initialize action (on CREATED->ALIVE transition)
+ // formaer rtc_init_entry()
+// @Override
+ protected ReturnCode_t onInitialize() {
+/*
+ try {
+ addOutPort("out", m_outOut);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+*/
+ addOutPort("topic_out", m_topic_outOut);
+ try {
+ m_ServicePort.registerProvider("topic_service",
+ "TestService",
+ m_service);
+ } catch (ServantAlreadyActive e) {
+ e.printStackTrace();
+ } catch (WrongPolicy e) {
+ e.printStackTrace();
+ } catch (ObjectNotActive e) {
+ e.printStackTrace();
+ }
+ addPort(m_ServicePort);
+/*
+ PortServiceListHolder pslholder = new PortServiceListHolder();
+ pslholder.value = new PortService[0];
+ pslholder.value = get_ports();
+ PortProfile prof = ports[0].get_port_profile();
+ NVListHolder nvholder =
+ new NVListHolder(prof.properties);
+ CORBA_SeqUtil.push_back(nvholder,
+ NVUtil.newNVString("publish_topic","test"));
+ prof.properties = nvholder.value;
+ ports[0].setPortRef();
+*/
+ //m_topic_outOut.appendProperty("publish_topic","test");
+
+ return super.onInitialize();
+ }
+ // The finalize action (on ALIVE->END transition)
+ // formaer rtc_exiting_entry()
+// @Override
+// protected ReturnCode_t onFinalize() {
+// return super.onFinalize();
+// }
+ //
+ // The startup action when ExecutionContext startup
+ // former rtc_starting_entry()
+// @Override
+// protected ReturnCode_t onStartup(int ec_id) {
+// return super.onStartup(ec_id);
+// }
+ //
+ // The shutdown action when ExecutionContext stop
+ // former rtc_stopping_entry()
+// @Override
+// protected ReturnCode_t onShutdown(int ec_id) {
+// return super.onShutdown(ec_id);
+// }
+ //
+ // The activated action (Active state entry action)
+ // former rtc_active_entry()
+// @Override
+// protected ReturnCode_t onActivated(int ec_id) {
+// return super.onActivated(ec_id);
+// }
+ //
+ // The deactivated action (Active state exit action)
+ // former rtc_active_exit()
+// @Override
+// protected ReturnCode_t onDeactivated(int ec_id) {
+// return super.onDeactivated(ec_id);
+// }
+ //
+ // The execution action that is invoked periodically
+ // former rtc_active_do()
+ @Override
+ protected ReturnCode_t onExecute(int ec_id) {
+ System.out.println("Please input number: ");
+ BufferedReader buff = new BufferedReader(new InputStreamReader( System.in ));
+ try {
+ m_out_val.data = Integer.parseInt(buff.readLine());
+ } catch (NumberFormatException e) {
+ System.out.println("Input number Error!");
+// e.printStackTrace();
+ } catch (IOException e) {
+ System.out.println("Input number Error!");
+// e.printStackTrace();
+ }
+ System.out.println("Sending to subscriber: " + m_out_val.data);
+ m_outOut.write();
+
+ return super.onExecute(ec_id);
+ }
+ //
+ // The aborting action when main logic error occurred.
+ // former rtc_aborting_entry()
+// @Override
+// public ReturnCode_t onAborting(int ec_id) {
+// return super.onAborting(ec_id);
+// }
+ //
+ // The error action in ERROR state
+ // former rtc_error_do()
+// @Override
+// public ReturnCode_t onError(int ec_id) {
+// return super.onError(ec_id);
+// }
+ //
+ // The reset action that is invoked resetting
+ // This is same but different the former rtc_init_entry()
+// @Override
+// protected ReturnCode_t onReset(int ec_id) {
+// return super.onReset(ec_id);
+// }
+//
+ // The state update action that is invoked after onExecute() action
+ // no corresponding operation exists in OpenRTm-aist-0.2.0
+// @Override
+// protected ReturnCode_t onStateUpdate(int ec_id) {
+// return super.onStateUpdate(ec_id);
+// }
+ //
+ // The action that is invoked when execution context's rate is changed
+ // no corresponding operation exists in OpenRTm-aist-0.2.0
+// @Override
+// protected ReturnCode_t onRateChanged(int ec_id) {
+// return super.onRateChanged(ec_id);
+// }
+//
+ // DataInPort declaration
+ // <rtc-template block="inport_declare">
+
+ // </rtc-template>
+
+ // DataOutPort declaration
+ // <rtc-template block="outport_declare">
+ protected TimedLong m_out_val;
+ protected DataRef<TimedLong> m_out;
+ protected OutPort<TimedLong> m_outOut;
+
+ protected TimedLong m_topic_out_val;
+ protected DataRef<TimedLong> m_topic_out;
+ protected TopicOutPort<TimedLong> m_topic_outOut;
+ // </rtc-template>
+
+ // CORBA Port declaration
+ // <rtc-template block="corbaport_declare">
+ protected TopicCorbaPort m_ServicePort;
+
+ // </rtc-template>
+
+ // Service declaration
+ // <rtc-template block="service_declare">
+ protected MyServiceSVC_impl m_service = new MyServiceSVC_impl();
+
+ // </rtc-template>
+
+ // Consumer declaration
+ // <rtc-template block="consumer_declare">
+
+ // </rtc-template>
+
+ class DataListener extends ConnectorDataListenerT<TimedLong>{
+ public DataListener(final String name){
+ super(TimedLong.class);
+ m_name = name;
+ }
+
+ public void operator(final ConnectorBase.ConnectorInfo arg,
+ final TimedLong data) {
+ ConnectorBase.ConnectorInfo info =(ConnectorBase.ConnectorInfo)arg;
+ System.out.println("------------------------------");
+ System.out.println("Listener: "+m_name);
+ System.out.println("Profile::name: "+info.name);
+ System.out.println("Profile::id: "+info.id);
+// System.out.println("Profile::properties: ");
+// System.out.println(info.properties);
+ System.out.println("Data: "+data.data);
+ System.out.println("------------------------------");
+ }
+ public String m_name;
+ }
+ class Listener extends ConnectorListener{
+ public Listener(final String name){
+ m_name = name;
+ }
+
+ public void operator(final ConnectorBase.ConnectorInfo arg){
+ System.out.println("------------------------------");
+ System.out.println("Listener: "+m_name);
+ System.out.println("Profile::name: "+arg.name);
+ System.out.println("Profile::id: "+arg.id);
+ String str = new String();
+ System.out.println("Profile::data_type:"+arg.properties.getProperty("data_type"));
+ System.out.println("------------------------------");
+ }
+ public String m_name;
+ }
+}
+
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOut.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOut.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOut.java 2016-10-07 02:43:45 UTC (rev 838)
@@ -0,0 +1,42 @@
+package RTMExamples.TopicTest;
+
+
+import jp.go.aist.rtm.RTC.Manager;
+import jp.go.aist.rtm.RTC.RTObject_impl;
+import jp.go.aist.rtm.RTC.RtcDeleteFunc;
+import jp.go.aist.rtm.RTC.RtcNewFunc;
+import jp.go.aist.rtm.RTC.RegisterModuleFunc;
+import jp.go.aist.rtm.RTC.util.Properties;
+
+public class ConsoleOut implements RtcNewFunc, RtcDeleteFunc, RegisterModuleFunc {
+
+// Module specification
+// <rtc-template block="module_spec">
+ public static String component_conf[] = {
+ "implementation_id", "ConsoleOut",
+ "type_name", "ConsoleOut",
+ "description", "Console output component",
+ "version", "1.0",
+ "vendor", "Noriaki Ando, AIST",
+ "category", "example",
+ "activity_type", "DataFlowComponent",
+ "max_instance", "10",
+ "language", "Java",
+ "lang_type", "compile",
+ ""
+ };
+// </rtc-template>
+
+ public RTObject_impl createRtc(Manager mgr) {
+ return new ConsoleOutImpl(mgr);
+ }
+
+ public void deleteRtc(RTObject_impl rtcBase) {
+ rtcBase = null;
+ }
+ public void registerModule() {
+ Properties prop = new Properties(component_conf);
+ final Manager manager = Manager.instance();
+ manager.registerFactory(prop, new ConsoleOut(), new ConsoleOut());
+ }
+}
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOutComp.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOutComp.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOutComp.java 2016-10-07 02:43:45 UTC (rev 838)
@@ -0,0 +1,89 @@
+package RTMExamples.TopicTest;
+
+
+import jp.go.aist.rtm.RTC.Manager;
+import jp.go.aist.rtm.RTC.ModuleInitProc;
+import jp.go.aist.rtm.RTC.RTObject_impl;
+import jp.go.aist.rtm.RTC.util.NVUtil;
+import jp.go.aist.rtm.RTC.util.Properties;
+import RTC.ComponentProfile;
+import RTC.PortService;
+import RTC.PortInterfacePolarity;
+import RTC.PortInterfaceProfileListHolder;
+import RTC.PortServiceListHolder;
+import _SDOPackage.NVListHolder;
+
+public class ConsoleOutComp implements ModuleInitProc {
+
+ public void myModuleInit(Manager mgr) {
+ Properties prop = new Properties(ConsoleOut.component_conf);
+ mgr.registerFactory(prop, new ConsoleOut(), new ConsoleOut());
+
+ // Create a component
+ System.out.println("Creating a component: \"ConsoleOut\"....");
+ RTObject_impl comp = mgr.createComponent("ConsoleOut");
+ System.out.println("succeed.");
+/*
+ ComponentProfile prof = comp.get_component_profile();
+ System.out.println( "=================================================" );
+ System.out.println( " Component Profile" );
+ System.out.println( "-------------------------------------------------" );
+ System.out.println( "InstanceID: " + prof.instance_name );
+ System.out.println( "Implementation: " + prof.type_name );
+ System.out.println( "Description: " + prof.description );
+ System.out.println( "Version: " + prof.version );
+ System.out.println( "Maker: " + prof.vendor );
+ System.out.println( "Category: " + prof.category );
+ System.out.println( " Other properties " );
+ NVUtil.dump(new NVListHolder(prof.properties));
+ System.out.println( "=================================================" );
+
+ PortServiceListHolder portlist = new PortServiceListHolder(comp.get_ports());
+
+ for( int intIdx=0;intIdx<portlist.value.length;++intIdx ) {
+ PortService port = portlist.value[intIdx];
+ System.out.println( "=================================================" );
+ System.out.println( "Port" + intIdx + " (name): ");
+ System.out.println( port.get_port_profile().name );
+ System.out.println( "-------------------------------------------------" );
+ PortInterfaceProfileListHolder iflist = new PortInterfaceProfileListHolder(port.get_port_profile().interfaces);
+
+ for( int intIdx2=0;intIdx2<iflist.value.length;++intIdx2 ) {
+ System.out.println( "I/F name: " );
+ System.out.println( iflist.value[intIdx2].instance_name );
+ System.out.println( "I/F type: ");
+ System.out.println( iflist.value[intIdx2].type_name );
+ if( iflist.value[intIdx2].polarity==PortInterfacePolarity.PROVIDED ) {
+ System.out.println( "Polarity: PROVIDED" );
+ } else {
+ System.out.println( "Polarity: REQUIRED" );
+ }
+ }
+ System.out.println( "- properties -" );
+ NVUtil.dump(new NVListHolder(port.get_port_profile().properties));
+ System.out.println( "-------------------------------------------------" );
+ }
+*/
+ }
+
+ public static void main(String[] args) {
+ // Initialize manager
+ final Manager manager = Manager.init(args);
+
+ // Set module initialization proceduer
+ // This procedure will be invoked in activateManager() function.
+ ConsoleOutComp init = new ConsoleOutComp();
+ manager.setModuleInitProc(init);
+
+ // Activate manager and register to naming service
+ manager.activateManager();
+
+ // run the manager in blocking mode
+ // runManager(false) is the default.
+ manager.runManager();
+
+ // If you want to run the manager in non-blocking mode, do like this
+ // manager->runManager(true);
+ }
+
+}
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOutImpl.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOutImpl.java (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOutImpl.java 2016-10-07 02:43:45 UTC (rev 838)
@@ -0,0 +1,277 @@
+package RTMExamples.TopicTest;
+
+import java.util.Observer;
+import java.util.Observable;
+
+import RTC.ReturnCode_t;
+import RTC.TimedLong;
+import jp.go.aist.rtm.RTC.DataFlowComponentBase;
+import jp.go.aist.rtm.RTC.Manager;
+import jp.go.aist.rtm.RTC.port.InPort;
+import jp.go.aist.rtm.RTC.port.ConnectorBase;
+import jp.go.aist.rtm.RTC.port.ConnectorDataListener;
+import jp.go.aist.rtm.RTC.port.ConnectorDataListenerT;
+import jp.go.aist.rtm.RTC.port.ConnectorDataListenerType;
+import jp.go.aist.rtm.RTC.port.ConnectorListenerType;
+import jp.go.aist.rtm.RTC.util.DataRef;
+
+import org.omg.CORBA.portable.OutputStream;
+
+import jp.go.aist.rtm.RTC.port.CorbaPort;
+import jp.go.aist.rtm.RTC.port.CorbaConsumer;
+
+import RTMExamples.SimpleService.MyService;
+
+public class ConsoleOutImpl extends DataFlowComponentBase {
+ private class TopicCorbaPort<DataType> extends CorbaPort {
+ public TopicCorbaPort(final String name) {
+ super(name);
+ appendProperty("publish_topic","test");
+ }
+ }
+
+ private class TopicInPort<DataType> extends InPort {
+ public TopicInPort(final String name, DataRef<DataType> valueRef) {
+ super(name,valueRef);
+ appendProperty("publish_topic","test");
+ }
+ }
+
+ public ConsoleOutImpl(Manager manager) {
+ super(manager);
+ // <rtc-template block="initializer">
+ m_in_val = new TimedLong();
+ m_in = new DataRef<TimedLong>(m_in_val);
+ m_inIn = new InPort<TimedLong>("in", m_in);
+
+ m_topic_in_val = new TimedLong(new RTC.Time(0,0),0);
+ m_topic_in = new DataRef<TimedLong>(m_topic_in_val);
+ m_topic_inIn = new TopicInPort<TimedLong>("topic_in", m_topic_in);
+
+ m_ServicePort = new TopicCorbaPort("topic_service");
+ // </rtc-template>
+
+ // Registration: InPort/OutPort/Service
+ // <rtc-template block="registration">
+/*
+ // Set InPort buffers
+ try {
+// registerInPort(TimedLong.class, "in", m_inIn); //v042
+ registerInPort("in", m_inIn);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+*/
+
+ // Set OutPort buffer
+
+ // Set service provider to Ports
+
+ // Set service consumers to Ports
+
+ // Set CORBA Service Ports
+
+ // </rtc-template>
+ }
+
+ // The initialize action (on CREATED->ALIVE transition)
+ // formaer rtc_init_entry()
+// @Override
+ protected ReturnCode_t onInitialize() {
+/*
+ try {
+ addInPort("in", m_inIn);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+*/
+ addInPort("topic_in", m_topic_inIn);
+ m_ServicePort.registerConsumer("service",
+ "Service",
+ m_myservice0Base);
+ // Set CORBA Service Ports
+ addPort(m_ServicePort);
+/*
+ m_inIn.addConnectorDataListener(
+ ConnectorDataListenerType.ON_BUFFER_WRITE,
+ new DataListener("ON_BUFFER_WRITE"));
+ m_inIn.addConnectorDataListener(
+ ConnectorDataListenerType.ON_BUFFER_FULL,
+ new DataListener("ON_BUFFER_FULL"));
+ m_inIn.addConnectorDataListener(
+ ConnectorDataListenerType.ON_BUFFER_WRITE_TIMEOUT,
+ new DataListener("ON_BUFFER_WRITE_TIMEOUT"));
+ m_inIn.addConnectorDataListener(
+ ConnectorDataListenerType.ON_BUFFER_OVERWRITE,
+ new DataListener("ON_BUFFER_OVERWRITE"));
+ m_inIn.addConnectorDataListener(
+ ConnectorDataListenerType.ON_BUFFER_READ,
+ new DataListener("ON_BUFFER_READ"));
+ m_inIn.addConnectorDataListener(
+ ConnectorDataListenerType.ON_SEND,
+ new DataListener("ON_SEND"));
+ m_inIn.addConnectorDataListener(
+ ConnectorDataListenerType.ON_RECEIVED,
+ new DataListener("ON_RECEIVED"));
+ m_inIn.addConnectorDataListener(
+ ConnectorDataListenerType.ON_RECEIVER_FULL,
+ new DataListener("ON_RECEIVER_FULL"));
+ m_inIn.addConnectorDataListener(
+ ConnectorDataListenerType.ON_RECEIVER_TIMEOUT,
+ new DataListener("ON_RECEIVER_TIMEOUT"));
+ m_inIn.addConnectorDataListener(
+ ConnectorDataListenerType.ON_RECEIVER_ERROR,
+ new DataListener("ON_RECEIVER_ERROR"));
+*/
+
+ return super.onInitialize();
+ }
+ // The finalize action (on ALIVE->END transition)
+ // formaer rtc_exiting_entry()
+// @Override
+// protected ReturnCode_t onFinalize() {
+// return super.onFinalize();
+// }
+ //
+ // The startup action when ExecutionContext startup
+ // former rtc_starting_entry()
+// @Override
+// protected ReturnCode_t onStartup(int ec_id) {
+// return super.onStartup(ec_id);
+// }
+ //
+ // The shutdown action when ExecutionContext stop
+ // former rtc_stopping_entry()
+// @Override
+// protected ReturnCode_t onShutdown(int ec_id) {
+// return super.onShutdown(ec_id);
+// }
+ //
+ // The activated action (Active state entry action)
+ // former rtc_active_entry()
+// @Override
+// protected ReturnCode_t onActivated(int ec_id) {
+// return super.onActivated(ec_id);
+// }
+ //
+ // The deactivated action (Active state exit action)
+ // former rtc_active_exit()
+// @Override
+// protected ReturnCode_t onDeactivated(int ec_id) {
+// return super.onDeactivated(ec_id);
+// }
+ //
+ // The execution action that is invoked periodically
+ // former rtc_active_do()
+ @Override
+ protected ReturnCode_t onExecute(int ec_id) {
+ if( m_inIn.isNew() ) {
+ m_inIn.read();
+// if( m_inIn.read() ) {
+ System.out.print( "Received: " + m_in.v.data + " " );
+ System.out.print( "TimeStamp: " + m_in.v.tm.sec + "[s] " );
+ System.out.println( m_in.v.tm.nsec + "[ns]" );
+ }
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ return super.onExecute(ec_id);
+ }
+ //
+ // The aborting action when main logic error occurred.
+ // former rtc_aborting_entry()
+// @Override
+// public ReturnCode_t onAborting(int ec_id) {
+// return super.onAborting(ec_id);
+// }
+ //
+ // The error action in ERROR state
+ // former rtc_error_do()
+// @Override
+// public ReturnCode_t onError(int ec_id) {
+// return super.onError(ec_id);
+// }
+ //
+ // The reset action that is invoked resetting
+ // This is same but different the former rtc_init_entry()
+// @Override
+// protected ReturnCode_t onReset(int ec_id) {
+// return super.onReset(ec_id);
+// }
+//
+ // The state update action that is invoked after onExecute() action
+ // no corresponding operation exists in OpenRTm-aist-0.2.0
+// @Override
+// protected ReturnCode_t onStateUpdate(int ec_id) {
+// return super.onStateUpdate(ec_id);
+// }
+ //
+ // The action that is invoked when execution context's rate is changed
+ // no corresponding operation exists in OpenRTm-aist-0.2.0
+// @Override
+// protected ReturnCode_t onRateChanged(int ec_id) {
+// return super.onRateChanged(ec_id);
+// }
+//
+ // DataInPort declaration
+ // <rtc-template block="inport_declare">
+ protected TimedLong m_in_val;
+ protected DataRef<TimedLong> m_in;
+ protected InPort<TimedLong> m_inIn;
+
+ protected TimedLong m_topic_in_val;
+ protected DataRef<TimedLong> m_topic_in;
+ protected TopicInPort<TimedLong> m_topic_inIn;
+ // </rtc-template>
+
+ // DataOutPort declaration
+ // <rtc-template block="outport_declare">
+
+ // </rtc-template>
+
+ // CORBA Port declaration
+ // <rtc-template block="corbaport_declare">
+ protected TopicCorbaPort m_ServicePort;
+
+ // </rtc-template>
+
+ // Service declaration
+ // <rtc-template block="service_declare">
+ protected CorbaConsumer<MyService> m_myservice0Base =
+ new CorbaConsumer<MyService>(MyService.class);
+
+ protected MyService m_myservice0;
+
+ // </rtc-template>
+
+ // Consumer declaration
+ // <rtc-template block="consumer_declare">
+
+ // </rtc-template>
+
+ class DataListener extends ConnectorDataListenerT<TimedLong>{
+ public DataListener(final String name){
+ super(TimedLong.class);
+ m_name = name;
+ }
+
+ public void operator(final ConnectorBase.ConnectorInfo arg,
+ final TimedLong data) {
+ ConnectorBase.ConnectorInfo info =(ConnectorBase.ConnectorInfo)arg;
+ System.out.println("------------------------------");
+ System.out.println("Listener: "+m_name);
+ System.out.println("Profile::name: "+info.name);
+ System.out.println("Profile::id: "+info.id);
+// System.out.println("Profile::properties: ");
+// System.out.println(info.properties);
+ System.out.println("Data: "+data.data);
+ System.out.println("------------------------------");
+ }
+ public String m_name;
+ }
+
+
+}
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/component.conf
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/component.conf (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/component.conf 2016-10-07 02:43:45 UTC (rev 838)
@@ -0,0 +1,12 @@
+#============================================================
+# component profile
+#============================================================
+# data port configurations
+#
+# publisher property
+# port.[port_name].dataport.publisher.push_rate: freq.
+# port.outport.dataport.publisher.push_rate: 100
+# port.[port_name].dataport.publisher.push_policy: [all, new, skip, fifo]
+# port.outport.dataport.publisher.push_policy: skip
+# port.[port_name].dataport.publisher.skip_count: [skip count]
+# port.outport.dataport.publisher.skip_count: 4
Added: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/rtc.conf
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/rtc.conf (rev 0)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/rtc.conf 2016-10-07 02:43:45 UTC (rev 838)
@@ -0,0 +1,32 @@
+corba.nameservers:localhost
+naming.formats: %n.rtc
+logger.enable:YES
+logger.log_level:PARANOID
+#logger.file_name: stdout
+#manager.is_master: YES
+
+#manager.modules.load_path: ./Extension/LocalService/nameservice_file/
+#manager.local_service.modules: FileNameservice
+
+#manager.modules.load_path:./RTMExamples/SimpleIO
+#manager.modules.preload: ConsoleOut
+#manager.components.precreate: ConsoleOut
+
+#manager.components.preconnect: ConsoleIn0.out^ConsoleOut0.in(dataflow_type=push&interface_type=direct)
+#manager.components.preactivation: ConsoleIn0, ConsoleOut0
+
+#naming.type:corba,manager
+#manager.components.preconnect: ConsoleIn0.out^rtcloc://localhost:2810/ConsoleOut0.in(dataflow_type=push&interface_type=corba_cdr)
+#manager.components.preactivation:rtcloc://localhost:2810/ConsoleOut0, ConsoleIn0
+
+
+#manager.components.preconnect: ConsoleIn0.out^rtcname://localhost:2809/ConsoleOut0.in(dataflow_type=push&interface_type=corba_cdr)
+#manager.components.preactivation:rtcname://localhost:2809/ConsoleOut0, ConsoleIn0
+
+
+
+
+
+example.ConsoleIn.config_file: ./RTMExamples/SimpleIO/component.conf
+example.ConsoleOut.config_file: ./RTMExamples/SimpleIO/component.conf
+
More information about the openrtm-commit
mailing list