[openrtm-commit:02060] r851 - trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port
openrtm @ openrtm.org
openrtm @ openrtm.org
2016年 10月 14日 (金) 14:11:15 JST
Author: win-ei
Date: 2016-10-14 14:11:15 +0900 (Fri, 14 Oct 2016)
New Revision: 851
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/InPortSHMProvider.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-13 03:40:03 UTC (rev 850)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/InPortSHMConsumer.java 2016-10-14 05:11:15 UTC (rev 851)
@@ -46,6 +46,7 @@
rtcout = new Logbuf("InPortSHMConsumer");
m_shm_address = UUID.randomUUID().toString();
+
// rtcout.setLevel("PARANOID");
// m_orb = ORBUtil.getOrb();
@@ -132,7 +133,6 @@
*/
public ReturnCode put(final OutputStream data) {
rtcout.println(Logbuf.PARANOID, "put");
-
try {
Object obj = getObject();
if(obj != null){
@@ -305,7 +305,8 @@
return false;
}
- if (!super.setObject(obj)) {
+ //if (!super.setObject(obj)) {
+ if (!setObject(obj)) {
rtcout.println(Logbuf.WARN, "Setting object to consumer failed.");
return false;
}
@@ -347,7 +348,8 @@
return false;
}
- if (!super.setObject(obj)) {
+ //if (!super.setObject(obj)) {
+ if (!setObject(obj)) {
rtcout.println(Logbuf.ERROR, "Setting object to consumer failed.");
return false;
}
Modified: trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/InPortSHMProvider.java
===================================================================
--- trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/InPortSHMProvider.java 2016-10-13 03:40:03 UTC (rev 850)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/InPortSHMProvider.java 2016-10-14 05:11:15 UTC (rev 851)
@@ -152,42 +152,8 @@
*/
public OpenRTM.PortStatus put(byte[] data)
throws SystemException {
+ return OpenRTM.PortStatus.UNKNOWN_ERROR;
- rtcout.println(Logbuf.PARANOID, "InPortSHMProvider.put()");
-
- CdrDataHolder cdr_data = new CdrDataHolder();
- read(cdr_data);
-// for(int ic=0;ic<cdr_data.value.length;++ic){
-// data[ic] = cdr_data.value[ic];
-// }
-
- if (m_buffer == null) {
- EncapsOutputStreamExt cdr
- = new EncapsOutputStreamExt(m_orb,m_connector.isLittleEndian());
- cdr.write_octet_array(cdr_data.value, 0, data.length);
- onReceiverError(cdr);
- return OpenRTM.PortStatus.PORT_ERROR;
- }
-
-
- rtcout.println(Logbuf.PARANOID, "received data size: "+cdr_data.value.length);
-
-
- EncapsOutputStreamExt cdr
- = new EncapsOutputStreamExt(m_orb,m_connector.isLittleEndian());
- cdr.write_octet_array(cdr_data.value, 0, cdr_data.value.length);
-
- int len = cdr.getByteArray().length;
- rtcout.println(Logbuf.PARANOID, "converted CDR data size: "+len);
- onReceived(cdr);
-
- if(m_connector==null){
- return OpenRTM.PortStatus.PORT_ERROR;
- }
-
- jp.go.aist.rtm.RTC.buffer.ReturnCode ret = m_buffer.write(cdr);
- //jp.go.aist.rtm.RTC.buffer.ReturnCode ret = m_connector.write(cdr);
- return convertReturn(ret,cdr);
}
/**
@@ -621,50 +587,6 @@
/**
*
- * {@.ja 共有メモリのマッピングを行う}
- * {@.en Open a shared memory.}
- *
- * @param memory_size
- * {@.ja 共有メモリのサイズ}
- * {@.en size of shared momoery}
- * @param shm_address
- * {@.ja 空間名}
- * {@.en name of memory}
- # void open_memory(int memory_size, string shm_address);
- */
- public void open_memory (int memory_size, String shm_address){
- rtcout.println(Logbuf.TRACE,
- "open():memory_size="
- + memory_size +",shm_address=" + shm_address);
- m_memory_size = memory_size;
- m_shm_address = shm_address;
- try{
- RandomAccessFile file = new RandomAccessFile(m_shm_address, "rw");
- file.setLength(m_memory_size);
- }
- catch(Exception ex) {
- rtcout.println(Logbuf.ERROR,"Open error "+ex.toString() );
- }
-/*
- self._rtcout.RTC_TRACE("open():memory_size="+str(memory_size)+",shm_address="+str(shm_address))
- self._memory_size = memory_size
- self._shm_address = shm_address
- if self._shmem is None:
- if platform.system() == "Windows":
- self._shmem = mmap.mmap(0, self._memory_size, self._shm_address, mmap.ACCESS_READ)
- else:
- O_RDWR = 2
- self.fd = self.rt.shm_open(self._shm_address,O_RDWR,0)
- if self.fd < 0:
- return self.UNKNOWN_ERROR
- self.rt.ftruncate(self.fd, self._memory_size)
- self._shmem = mmap.mmap(self.fd, self._memory_size, mmap.MAP_SHARED)
- self.rt.close( self.fd )
-
-*/
- }
- /**
- *
* {@.ja 共有メモリの初期化}
* {@.en Initializes a shared memory.}
*
@@ -752,7 +674,38 @@
* {@.en Put data.}
*/
public OpenRTM.PortStatus put(){
- return OpenRTM.PortStatus.UNKNOWN_ERROR;
+ rtcout.println(Logbuf.PARANOID, "InPortSHMProvider.put()");
+
+ CdrDataHolder cdr_data = new CdrDataHolder();
+ cdr_data.value = new byte[0];
+ read(cdr_data);
+ if (m_buffer == null) {
+ EncapsOutputStreamExt cdr
+ = new EncapsOutputStreamExt(m_orb,m_connector.isLittleEndian());
+ cdr.write_octet_array(cdr_data.value, 0, cdr_data.value.length);
+ onReceiverError(cdr);
+ return OpenRTM.PortStatus.PORT_ERROR;
+ }
+
+
+ rtcout.println(Logbuf.PARANOID, "received data size: "+cdr_data.value.length);
+
+
+ EncapsOutputStreamExt cdr
+ = new EncapsOutputStreamExt(m_orb,m_connector.isLittleEndian());
+ cdr.write_octet_array(cdr_data.value, 0, cdr_data.value.length);
+
+ int len = cdr.getByteArray().length;
+ rtcout.println(Logbuf.PARANOID, "converted CDR data size: "+len);
+ onReceived(cdr);
+
+ if(m_connector==null){
+ return OpenRTM.PortStatus.PORT_ERROR;
+ }
+
+ jp.go.aist.rtm.RTC.buffer.ReturnCode ret = m_buffer.write(cdr);
+ //jp.go.aist.rtm.RTC.buffer.ReturnCode ret = m_connector.write(cdr);
+ return convertReturn(ret,cdr);
}
/**
* <p>インタフェース情報を保持するオブジェクトです。</p>
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-13 03:40:03 UTC (rev 850)
+++ trunk/OpenRTM-aist-Java/jp.go.aist.rtm.RTC/src/jp/go/aist/rtm/RTC/port/SharedMemory.java 2016-10-14 05:11:15 UTC (rev 851)
@@ -13,7 +13,12 @@
import OpenRTM.PortSharedMemory;
import jp.go.aist.rtm.RTC.log.Logbuf;
+import jp.go.aist.rtm.RTC.util.LongHolder;
+import jp.go.aist.rtm.RTC.util.ORBUtil;
+import org.omg.CORBA.portable.OutputStream;
+import org.omg.CORBA.portable.InputStream;
+
/**
* {@.ja SharedMemory クラス}
* {@.en SharedMemory class}
@@ -102,6 +107,10 @@
+ memory_size +",shm_address=" + shm_address);
m_memory_size = memory_size;
m_shm_address = shm_address;
+
+ if(m_smInterface!=null){
+ m_smInterface.open_memory(m_memory_size, m_shm_address);
+ }
}
@@ -146,6 +155,9 @@
public void close_memory(boolean unlink){
File file = new File(m_shm_address);
file.delete();
+ if(m_smInterface!=null){
+ m_smInterface.close_memory(false);
+ }
}
public void close_memory(){
@@ -178,16 +190,20 @@
MappedByteBuffer buffer
= channel.map(FileChannel.MapMode.READ_WRITE, 0, length);
buffer.order(ByteOrder.LITTLE_ENDIAN);
-/*
- OutPort out = (OutPort)m_outport;
- OutputStream cdr
- = new EncapsOutputStreamExt(m_orb,m_isLittleEndian);
- out.write_stream(data,cdr);
-*/
-// buffer.putInt((offset * 4/* size of int */), value);
+ LongHolder len = new LongHolder(data.value.length);
+ //OutputStream cdr
+ EncapsOutputStreamExt cdr
+ = new EncapsOutputStreamExt(ORBUtil.getOrb(),true);
+ len._write(cdr);
+ byte[] ch = cdr.getByteArray();
+ buffer.put(ch, 0, ch.length);
+// buffer.put(data.value, 8, data.value.length);
+ buffer.put(data.value);
+
+
channel.close();
file.close();
}
@@ -215,7 +231,18 @@
MappedByteBuffer buffer
= channel.map(FileChannel.MapMode.READ_WRITE, 0, length);
buffer.order(ByteOrder.LITTLE_ENDIAN);
- //int value = buffer.getInt(offset * 4/* size of int */);
+ byte[] len_data = new byte[8];
+ buffer.get(len_data,0,len_data.length);
+
+ EncapsOutputStreamExt cdr
+ = new EncapsOutputStreamExt(ORBUtil.getOrb(),true);
+ cdr.write_octet_array(len_data, 0, len_data.length);
+ InputStream instream = cdr.create_input_stream();
+ LongHolder len = new LongHolder();
+ len._read(instream);
+ data.value = new byte[(int)len.value.intValue()];
+ buffer.get(data.value);
+ //buffer.get(data.value,8,data.value.length);
channel.close();
file.close();
}
@@ -239,7 +266,7 @@
# void close(int memory_size, string shm_address);
*/
public void setInterface (OpenRTM.PortSharedMemory sm){
- //self._smInterface = sm
+ m_smInterface = sm;
}
@@ -267,6 +294,7 @@
private Logbuf rtcout;
private String m_shm_address = new String();
private int m_memory_size;
+ private OpenRTM.PortSharedMemory m_smInterface;
}
More information about the openrtm-commit
mailing list