[openrtm-commit:02044] r847 - trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port
openrtm @ openrtm.org
openrtm @ openrtm.org
2016年 10月 12日 (水) 23:21:26 JST
Author: win-ei
Date: 2016-10-12 23:21:26 +0900 (Wed, 12 Oct 2016)
New Revision: 847
Modified:
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/InPortSHMConsumer.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortSHMConsumer.java
trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/SharedMemory.java
Log:
Fixed bugs. refs #3395
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/InPortSHMConsumer.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/InPortSHMConsumer.java 2016-10-11 09:46:46 UTC (rev 846)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/InPortSHMConsumer.java 2016-10-12 14:21:26 UTC (rev 847)
@@ -11,14 +11,17 @@
import jp.go.aist.rtm.RTC.util.Properties;
import org.omg.CORBA.BAD_OPERATION;
+import org.omg.CORBA.Object;
import org.omg.CORBA.ORB;
import org.omg.CORBA.TCKind;
import org.omg.CORBA.portable.OutputStream;
import _SDOPackage.NVListHolder;
import OpenRTM.PortSharedMemory;
+import OpenRTM.CdrDataHolder;
+import OpenRTM.PortSharedMemory;
+import OpenRTM.PortSharedMemoryHelper;
-
/**
* {@.ja InPortSHMConsumer クラス}
* {@.en InPortSHMConsumer class}
@@ -42,8 +45,8 @@
super(OpenRTM.PortSharedMemory.class);
rtcout = new Logbuf("InPortSHMConsumer");
-// m_shm_address = UUID.randomUUID().toString();
-
+ m_shm_address = UUID.randomUUID().toString();
+
// rtcout.setLevel("PARANOID");
// m_orb = ORBUtil.getOrb();
}
@@ -71,7 +74,7 @@
rtcout.println(Logbuf.TRACE, "init()");
m_properties = prop;
String ds = prop.getProperty("shem_default_size");
- //m_memory_size = m_shmem.string_to_MemorySize(ds);
+ m_memory_size = (int)m_shmem.string_to_MemorySize(ds);
}
/**
@@ -112,6 +115,32 @@
public ReturnCode put(final OutputStream data) {
rtcout.println(Logbuf.PARANOID, "put");
+ try {
+ Object obj = getObject();
+ if(obj != null){
+ PortSharedMemory inportcdr = PortSharedMemoryHelper.narrow(obj);
+ OpenRTM.PortStatus ret;
+ synchronized(m_mutex) {
+ m_shmem.create_memory(m_memory_size, m_shm_address);
+ EncapsOutputStreamExt cdr;
+ cdr = (EncapsOutputStreamExt)data;
+ byte[] ch = cdr.getByteArray();
+ CdrDataHolder cdr_data = new CdrDataHolder();
+ cdr_data.value = ch;
+ m_shmem.write(cdr_data);
+
+ ret = inportcdr.put();
+ }
+ return convertReturn(ret);
+ }
+ return ReturnCode.CONNECTION_LOST;
+ }
+ catch (Exception ex) {
+ rtcout.println(Logbuf.WARN, "Exception caught: "+ex.toString());
+ return ReturnCode.CONNECTION_LOST;
+ }
+
+/*
EncapsOutputStreamExt cdr;
cdr = (EncapsOutputStreamExt)data;
byte[] ch = cdr.getByteArray();
@@ -127,6 +156,7 @@
catch (Exception e) {
return ReturnCode.CONNECTION_LOST;
}
+*/
}
/**
* {@.ja InterfaceProfile情報を公開する}
@@ -440,7 +470,7 @@
* {@.en The target instances for destruction}
*
*/
- public void destructor_(Object obj) {
+ public void destructor_(java.lang.Object obj) {
obj = null;
}
/**
@@ -477,8 +507,9 @@
private OutPortConnector m_connector;
private ORB m_orb;
private String m_shm_address = new String();
- //private SharedMemory m_shmem = new SharedMemory();
- private long m_memory_size;
+ private SharedMemory m_shmem = new SharedMemory();
+ private int m_memory_size;
+ private static String m_mutex = new String();
}
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortSHMConsumer.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortSHMConsumer.java 2016-10-11 09:46:46 UTC (rev 846)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/OutPortSHMConsumer.java 2016-10-12 14:21:26 UTC (rev 847)
@@ -16,7 +16,10 @@
import org.omg.CORBA.portable.OutputStream;
import _SDOPackage.NVListHolder;
+import OpenRTM.CdrDataHolder;
import OpenRTM.PortSharedMemory;
+import OpenRTM.PortSharedMemoryHelper;
+
/**
* {@.ja OutPortSHMConsumer クラス}
* {@.en OutPortSHMConsumer class}
@@ -162,32 +165,37 @@
rtcout.println(Logbuf.TRACE, "OutPortSHMConsumer.get()");
OpenRTM.CdrDataHolder cdr_data = new OpenRTM.CdrDataHolder();
try {
- OpenRTM.PortStatus ret = _ptr().get();
- //OpenRTM.PortStatus ret = _ptr().get(cdr_data);
- if (ret == OpenRTM.PortStatus.PORT_OK) {
- rtcout.println(Logbuf.DEBUG, "get() successful");
- data.write_octet_array(cdr_data.value, 0,
+ PortSharedMemory outportcdr = PortSharedMemoryHelper.narrow(getObject());
+ m_outportcdr = outportcdr;
+
+ synchronized(m_mutex) {
+ OpenRTM.PortStatus ret = outportcdr.get();
+ if (ret == OpenRTM.PortStatus.PORT_OK) {
+ rtcout.println(Logbuf.DEBUG, "get() successful");
+ data.write_octet_array(cdr_data.value, 0,
cdr_data.value.length);
- rtcout.println(Logbuf.PARANOID,
+ rtcout.println(Logbuf.PARANOID,
"CDR data length: "+cdr_data.value.length);
- onReceived(data);
- onBufferWrite(data);
-
- if (m_buffer.full()) {
- rtcout.println(Logbuf.INFO,
+ //CdrDataHolder cdr_data = new CdrDataHolder();
+ m_shmem.read(cdr_data);
+ onReceived(data);
+ onBufferWrite(data);
+ if (m_buffer.full()) {
+ rtcout.println(Logbuf.INFO,
"InPort buffer is full.");
- onBufferFull(data);
- onReceiverFull(data);
- }
+ onBufferFull(data);
+ onReceiverFull(data);
+ }
- m_buffer.put(data);
- m_buffer.advanceWptr();
- m_buffer.advanceRptr();
+ m_buffer.put(data);
+ m_buffer.advanceWptr();
+ m_buffer.advanceRptr();
- return ReturnCode.PORT_OK;
+ return ReturnCode.PORT_OK;
+ }
+ return convertReturn(ret);
}
- return convertReturn(ret);
}
catch (Exception e) {
rtcout.println(Logbuf.WARN,
@@ -530,5 +538,9 @@
private InPortConnector m_connector;
private ConnectorListeners m_listeners;
private ConnectorBase.ConnectorInfo m_profile;
+ private SharedMemory m_shmem = new SharedMemory();
+ private PortSharedMemory m_outportcdr;
+ private Properties m_properties = new Properties();
+ private static String m_mutex = new String();
}
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/SharedMemory.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/SharedMemory.java 2016-10-11 09:46:46 UTC (rev 846)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/SharedMemory.java 2016-10-12 14:21:26 UTC (rev 847)
@@ -28,7 +28,9 @@
*/
-public abstract class SharedMemory implements PortSharedMemory {
+//public abstract class SharedMemory implements PortSharedMemory {
+//public class SharedMemory implements OpenRTM.PortSharedMemory {
+public class SharedMemory extends OpenRTM.PortSharedMemoryPOA {
private static final int DEFAULT_SIZE = 8;
private static final int DEFAULT_MEMORY_SIZE = 2*1024*1024;
More information about the openrtm-commit
mailing list