[openrtm-commit:02790] r1032 - trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest

openrtm @ openrtm.org openrtm @ openrtm.org
2017年 8月 31日 (木) 14:33:37 JST


Author: t-katami
Date: 2017-08-31 14:33:37 +0900 (Thu, 31 Aug 2017)
New Revision: 1032

Modified:
   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/ConsoleOutImpl.java
Log:
[compat,bugfix,->releng_1_2] Fixed components for test. refs #3391

Modified: 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	2017-08-30 06:00:06 UTC (rev 1031)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleInImpl.java	2017-08-31 05:33:37 UTC (rev 1032)
@@ -23,15 +23,12 @@
 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 jp.go.aist.rtm.RTC.port.CorbaConsumer;
 
-import RTMExamples.SimpleService.MyServiceSVC_impl;
+import RTMExamples.SimpleService.MyService;
 
 
 
@@ -52,10 +49,6 @@
     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);
@@ -79,42 +72,14 @@
 
     // The initialize action (on CREATED->ALIVE transition)
     // formaer rtc_init_entry() 
-//    @Override
+    @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();
-        }
+        m_ServicePort.registerConsumer("topic_service", 
+                                            "Service", 
+                                            m_myservice0Base);
+        // Set CORBA Service Ports
         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)
@@ -156,22 +121,65 @@
     // former rtc_active_do()
     @Override
     protected ReturnCode_t onExecute(int ec_id) {
-        System.out.println("Please input number: ");
+        System.out.print("Please input : ");
         BufferedReader buff = new BufferedReader(new InputStreamReader( System.in ));
+        String str = null;
         try {
-            String str = buff.readLine();
+            str = buff.readLine();
             if(str != null){
-                m_out_val.data = Integer.parseInt(str);
+                m_topic_out_val.data = Integer.parseInt(str);
             }
-        } 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_topic_out_val.data);
+            m_topic_outOut.write();
+        } catch (Exception e) {
+            if(str != null){
+                String[] argv = str.split(" ");
+                m_myservice0 = m_myservice0Base._ptr();
+                if( argv[0].equals("echo") && argv.length>1 ) {
+                    String retmsg = m_myservice0.echo(argv[1]);
+                    System.out.println( "echo return: " + retmsg );
+                }
+                else if( argv[0].equals("set_value") && argv.length>1 ) {
+                    Float val = Float.valueOf(argv[1]);
+                    m_myservice0.set_value(val.floatValue());
+                    System.out.println( "Set remote value: " + val );
+                }
+          
+                else if( argv[0].equals("get_value") ) {
+                    System.out.println( "Current remote value: " 
+                                        + m_myservice0.get_value() );
+                }
+          
+                else if( argv[0].equals("get_echo_history") ) {
+                    String[] echo_history = m_myservice0.get_echo_history();
+                    for( int intIdx=0;intIdx<echo_history.length;intIdx++ ) {
+                        System.out.println( intIdx+": "+echo_history[intIdx]);
+                    }
+                }
+                else if( argv[0].equals("get_value_history") ) {
+                    float[] value_history = m_myservice0.get_value_history();
+                    for( int intIdx=0;intIdx<value_history.length;intIdx++ ) {
+                        System.out.println( intIdx+": "+value_history[intIdx]);
+                    }
+                }
+                else{
+                    System.out.println("");
+                    System.out.println("Command list: ");
+                    System.out.println(" echo [msg]       : echo message.");
+                    System.out.println(" set_value [value]: set value." );
+                    System.out.println(" get_value        : "
+                                       +"get current value.");
+                    System.out.println(" get_echo_history : "
+                                       +"get input messsage history." );
+                    System.out.println(" get_value_history: "
+                                       +"get input value history." );
+                }
+            }
+            else{
+                System.out.println("Input Error!");
+            }
         }
-        System.out.println("Sending to subscriber: "  + m_out_val.data);
-        m_outOut.write();
 
         return super.onExecute(ec_id);
     }
@@ -218,10 +226,6 @@
 
     // 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;
@@ -235,8 +239,12 @@
 
     // Service declaration
     // <rtc-template block="service_declare">
-    protected MyServiceSVC_impl m_service = new MyServiceSVC_impl();
+    protected CorbaConsumer<MyService> m_myservice0Base =
+        new CorbaConsumer<MyService>(MyService.class);
     
+    protected MyService m_myservice0;
+    //protected MyServiceSVC_impl m_service = new MyServiceSVC_impl();
+    
     // </rtc-template>
 
     // Consumer declaration
@@ -257,8 +265,6 @@
             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("------------------------------");
             return ReturnCode.NO_CHANGE;

Modified: 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	2017-08-30 06:00:06 UTC (rev 1031)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/RTMExamples/TopicTest/ConsoleOutImpl.java	2017-08-31 05:33:37 UTC (rev 1032)
@@ -16,12 +16,15 @@
 import jp.go.aist.rtm.RTC.port.ConnectorListenerType;
 import jp.go.aist.rtm.RTC.util.DataRef;
 
+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 jp.go.aist.rtm.RTC.port.CorbaConsumer;
 
-import RTMExamples.SimpleService.MyService;
+import RTMExamples.SimpleService.MyServiceSVC_impl;
 
 public class ConsoleOutImpl  extends DataFlowComponentBase {
     private class TopicCorbaPort<DataType> extends CorbaPort {
@@ -41,10 +44,6 @@
     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);
@@ -54,15 +53,6 @@
 
         // 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
         
@@ -77,54 +67,21 @@
 
     // The initialize action (on CREATED->ALIVE transition)
     // formaer rtc_init_entry() 
-//    @Override
+    @Override
     protected ReturnCode_t onInitialize() {
-/*
+        addInPort("topic_in", m_topic_inIn);
         try {
-            addInPort("in", m_inIn);
-        } catch (Exception e) {
+            m_ServicePort.registerProvider("topic_service", 
+                                                "Service", 
+                                                m_service);
+        } catch (ServantAlreadyActive e) {
             e.printStackTrace();
+        } catch (WrongPolicy e) {
+            e.printStackTrace();
+        } catch (ObjectNotActive 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)
@@ -166,12 +123,11 @@
     // 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]" );
+        if( m_topic_inIn.isNew() ) {
+            m_topic_inIn.read();
+            System.out.print( "Received: " + m_topic_in.v.data + " " );
+            System.out.print( "TimeStamp: " + m_topic_in.v.tm.sec + "[s] " );
+            System.out.println( m_topic_in.v.tm.nsec + "[ns]" );
           }
         try {
             Thread.sleep(1);
@@ -219,10 +175,6 @@
 //
     // 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;
@@ -241,11 +193,7 @@
 
     // Service declaration
     // <rtc-template block="service_declare">
-    protected CorbaConsumer<MyService> m_myservice0Base =
-        new CorbaConsumer<MyService>(MyService.class);
-    
-    protected MyService m_myservice0;
-    
+    protected MyServiceSVC_impl m_service = new MyServiceSVC_impl();
     // </rtc-template>
 
     // Consumer declaration
@@ -266,8 +214,6 @@
             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("------------------------------");
             return ReturnCode.NO_CHANGE;



More information about the openrtm-commit mailing list