[openrtm-commit:02003] r824 - in trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC: port util
openrtm @ openrtm.org
openrtm @ openrtm.org
2016年 10月 3日 (月) 18:08:16 JST
Author: win-ei
Date: 2016-10-03 18:08:16 +0900 (Mon, 03 Oct 2016)
New Revision: 824
Modified:
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPort.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/util/NVUtil.java
Log:
Now data value is stored to PortProfile.properties.
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPort.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPort.java 2016-05-20 12:18:21 UTC (rev 823)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPort.java 2016-10-03 09:08:16 UTC (rev 824)
@@ -2,6 +2,8 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Vector;
@@ -10,11 +12,14 @@
import jp.go.aist.rtm.RTC.log.Logbuf;
import jp.go.aist.rtm.RTC.port.publisher.PublisherBase;
import jp.go.aist.rtm.RTC.util.DataRef;
+import jp.go.aist.rtm.RTC.util.NVUtil;
import jp.go.aist.rtm.RTC.util.ORBUtil;
+import jp.go.aist.rtm.RTC.util.CORBA_SeqUtil;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.Streamable;
+import _SDOPackage.NVListHolder;
/**
* {@.ja 出力ポートの実装。}
* {@.en Implementation of OutPort}
@@ -30,6 +35,42 @@
public class OutPort<DataType> extends OutPortBase {
/**
+ * {@.ja }
+ * {@.en }
+ */
+/*
+ private class getInfo{
+ private HashMap<String, Class> types
+ = new HashMap<String, Class>();
+
+ private HashMap<String, Integer> nums = new HashMap<String, Integer>();
+
+ public getInfo() {
+ types.put("byte",byte.class);
+ types.put("char",char.class);
+ types.put("short",short.class);
+ types.put("int",int.class);
+ types.put("long",long.class);
+ types.put("float",float.class);
+ types.put("double",double.class);
+
+ nums.put("byte",0);
+ nums.put("char",1);
+ nums.put("short",2);
+ nums.put("int",3);
+ nums.put("long",4);
+ nums.put("float",5);
+ nums.put("double",6);
+ }
+ public Class getType(String className) {
+ return (Class) types.get(className);
+ }
+ public int getNumber(String className) {
+ return nums.get(className);
+ }
+ }
+*/
+ /**
* <p> toTypeCode </p>
* <p> This function gets TypeCode of data. </p>
*
@@ -266,6 +307,16 @@
rtcout.println(Logbuf.WARN,
"Exception caught."+e.toString());
}
+
+
+
+ addProperty("dataport.data_value", valueRef.v, cl);
+
+ synchronized (m_profile.properties) {
+ NVListHolder nvholder = new NVListHolder(m_profile.properties);
+ m_propValueIndex = NVUtil.find_index(nvholder,
+ "dataport.data_value");
+ }
}
/**
@@ -313,6 +364,24 @@
rtcout.println(Logbuf.TRACE, "OnWrite called");
}
+ synchronized (m_profile.properties) {
+ NVListHolder nvholder =
+ new NVListHolder(m_profile.properties);
+ try{
+ CORBA_SeqUtil.erase(nvholder, m_propValueIndex);
+ } catch (Exception ex) {
+ throw new InternalError("remove_organization_property()");
+ }
+
+ m_profile.properties = nvholder.value;
+ Class cl = value.getClass();
+ addProperty("dataport.data_value", value, cl);
+ nvholder.value = m_profile.properties;
+ m_propValueIndex = NVUtil.find_index(nvholder, "dataport.data_value");
+
+ }
+
+
// 1) direct connection
synchronized (m_directNewDataMutex){
rtcout.println(Logbuf.DEBUG, "Direct data transfer");
@@ -729,4 +798,6 @@
private static String m_directNewDataMutex = new String();
+ private int m_propValueIndex;
+
}
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/util/NVUtil.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/util/NVUtil.java 2016-05-20 12:18:21 UTC (rev 823)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/util/NVUtil.java 2016-10-03 09:08:16 UTC (rev 824)
@@ -1,6 +1,7 @@
package jp.go.aist.rtm.RTC.util;
import java.util.Vector;
+import java.lang.reflect.Method;
import org.omg.CORBA.Any;
import org.omg.CORBA.TCKind;
@@ -173,7 +174,7 @@
* {@.en NVList of copy source}
*/
public static void copyToProperties(Properties prop, final NVListHolder nvlist) {
-
+
for (int intIdx = 0; intIdx < nvlist.value.length; ++intIdx) {
try {
Any anyVal = nvlist.value[intIdx].value;
@@ -203,7 +204,78 @@
value = Long.toString(anyVal.extract_longlong());
} else if( anyVal.type().kind() == TCKind.tk_octet ) {
value = Byte.toString(anyVal.extract_octet());
+ } else if( anyVal.type().kind() == TCKind.tk_struct ) {
+
+ if(anyVal.type().name().equals("TimedLong")) {
+ value = RTC.TimedLongHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedBoolean")) {
+ value = RTC.TimedBooleanHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedChar")) {
+ value = RTC.TimedCharHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedDouble")) {
+ value = RTC.TimedDoubleHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedFloat")) {
+ value = RTC.TimedFloatHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedOctet")) {
+ value = RTC.TimedOctetHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedShort")) {
+ value = RTC.TimedShortHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedBooleanSeq")) {
+ value = RTC.TimedBooleanSeqHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedCharSeq")) {
+ value = RTC.TimedCharSeqHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedDoubleSeq")) {
+ value = RTC.TimedDoubleSeqHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedFloatSeq")) {
+ value = RTC.TimedFloatSeqHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedLongSeq")) {
+ value = RTC.TimedLongSeqHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedOctetSeq")) {
+ value = RTC.TimedOctetSeqHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedShortSeq")) {
+ value = RTC.TimedShortSeqHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedStringSeq")) {
+ value = RTC.TimedStringSeqHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedULongSeq")) {
+ value = RTC.TimedULongSeqHelper.extract(anyVal).toString();
+ }
+ else if(anyVal.type().name().equals("TimedUShortSeq")) {
+ value = RTC.TimedUShortSeqHelper.extract(anyVal).toString();
+ }
+ else {
+ try {
+ String className = anyVal.type().name();
+ Class helper = Class.forName(className + "Helper",
+ true,
+ anyVal.getClass().getClassLoader());
+ Method method = helper.getMethod("extract",
+ org.omg.CORBA.Any.class);
+ Object targetObject = method.invoke(
+ null, // invoke static method.
+ anyVal);
+ value = targetObject.toString();
+ } catch ( Exception ex) {
+ throw new ClassCastException("Unknown data type.");
+ }
+ }
} else {
+ Class cl = anyVal.getClass();
+ String str = cl.getName();
value = anyVal.extract_Value().toString();
}
final String name = nvlist.value[intIdx].name;
More information about the openrtm-commit
mailing list