[openrtm-commit:02070] r725 - in trunk/OpenRTM-aist-Python/OpenRTM_aist: . RTM_IDL test
openrtm @ openrtm.org
openrtm @ openrtm.org
2016年 10月 20日 (木) 14:42:02 JST
Author: miyamoto
Date: 2016-10-20 14:42:02 +0900 (Thu, 20 Oct 2016)
New Revision: 725
Modified:
trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortSHMConsumer.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortSHMProvider.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/RTM_IDL/SharedMemory.idl
trunk/OpenRTM-aist-Python/OpenRTM_aist/SharedMemory.py
trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_SharedMemory.py
Log:
[incompat,new_func,->RELENG_1_2] refs #3410
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortSHMConsumer.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortSHMConsumer.py 2016-10-17 06:16:28 UTC (rev 724)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/InPortSHMConsumer.py 2016-10-20 05:42:02 UTC (rev 725)
@@ -67,6 +67,7 @@
self._shmem = OpenRTM_aist.SharedMemory()
+
self._mutex = threading.RLock()
@@ -130,6 +131,22 @@
self._memory_size = self._shmem.string_to_MemorySize(ds)
+
+ if prop.hasKey("serializer"):
+ endian = prop.getProperty("serializer.cdr.endian")
+ if not endian:
+ self._rtcout.RTC_ERROR("init(): endian is not set.")
+ self._endian = None
+ endian = OpenRTM_aist.split(endian, ",")
+ endian = OpenRTM_aist.normalize(endian)
+ if endian == "little":
+ self._endian = True
+ elif endian == "big":
+ self._endian = False
+ else:
+ self._endian = None
+ else:
+ self._endian = True
return
@@ -180,7 +197,10 @@
inportcdr = ref_._narrow(OpenRTM__POA.PortSharedMemory)
guard = OpenRTM_aist.ScopedLock(self._mutex)
-
+ if not self._endian:
+ self._rtcout.RTC_ERROR("put(): endian is not set.")
+ return self.UNKNOWN_ERROR
+ self._shmem.setEndian(self._endian)
self._shmem.create_memory(self._memory_size, self._shm_address)
self._shmem.write(data)
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortSHMProvider.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortSHMProvider.py 2016-10-17 06:16:28 UTC (rev 724)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/OutPortSHMProvider.py 2016-10-20 05:42:02 UTC (rev 725)
@@ -108,7 +108,25 @@
ds = prop.getProperty("shem_default_size")
self._memory_size = self.string_to_MemorySize(ds)
+
+ if prop.hasKey("serializer"):
+ endian = prop.getProperty("serializer.cdr.endian")
+ if not endian:
+ self._rtcout.RTC_ERROR("init(): endian is not set.")
+ self._endian = None
+ endian = OpenRTM_aist.split(endian, ",")
+ endian = OpenRTM_aist.normalize(endian)
+ if endian == "little":
+ self._endian = True
+ elif endian == "big":
+ self._endian = False
+ else:
+ self._endian = None
+ else:
+ self._endian = True
+ return
+
def setBuffer(self, buffer):
self._buffer = buffer
return
@@ -164,6 +182,10 @@
self._rtcout.RTC_TRACE(OpenRTM_aist.Logger.print_exception())
return OpenRTM.UNKNOWN_ERROR
+ if not self._endian:
+ self._rtcout.RTC_ERROR("get(): endian is not set.")
+ return self.UNKNOWN_ERROR
+ self.setEndian(self._endian)
self.create_memory(self._memory_size, self._shm_address)
self.write(cdr[0])
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/RTM_IDL/SharedMemory.idl
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/RTM_IDL/SharedMemory.idl 2016-10-17 06:16:28 UTC (rev 724)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/RTM_IDL/SharedMemory.idl 2016-10-20 05:42:02 UTC (rev 725)
@@ -20,10 +20,11 @@
interface PortSharedMemory
{
- void open_memory(in unsigned long memory_size, in string shm_address);
- void create_memory(in unsigned long memory_size, in string shm_address);
+ void open_memory(in unsigned long long memory_size, in string shm_address);
+ void create_memory(in unsigned long long memory_size, in string shm_address);
void close_memory(in boolean unlink);
void setInterface(in PortSharedMemory sm);
+ void setEndian(in boolean endian);
PortStatus put();
PortStatus get();
};
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/SharedMemory.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/SharedMemory.py 2016-10-17 06:16:28 UTC (rev 724)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/SharedMemory.py 2016-10-20 05:42:02 UTC (rev 725)
@@ -43,9 +43,9 @@
#
class SharedMemory(OpenRTM__POA.PortSharedMemory):
default_size = 8
- default_memory_size = 2*1024*1024
+ default_memory_size = 2097152
+
-
##
# @if jp
# @brief コンストラクタ
@@ -69,6 +69,7 @@
self._smInterface = OpenRTM.PortSharedMemory._nil
self._shm_address = ""
self._memory_size = SharedMemory.default_memory_size
+ self._endian = None
if platform.system() == "Windows":
pass
else:
@@ -157,19 +158,20 @@
#
# @param self
# @param memory_size 共有メモリのサイズ
- # @parama shm_address 空間名
+ # @param shm_address 空間名
#
# @else
# @brief
#
# @param memory_size
- # @parama shm_address
+ # @param shm_address
#
# @endif
#
# void create_memory(int memory_size, string shm_address);
def create_memory(self, memory_size, shm_address):
+
if self._shmem is None:
self._rtcout.RTC_TRACE("create():memory_size="+str(memory_size)+",shm_address="+str(shm_address))
self._memory_size = memory_size
@@ -189,14 +191,14 @@
self.fd = self.rt.shm_open(self._shm_address,O_RDWR | O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH)
if self.fd < 0:
- return self.UNKNOWN_ERROR
+ return
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 )
if not CORBA.is_nil(self._smInterface):
- self._smInterface.open_memory(self._memory_size, self._shm_address)
+ self._smInterface.open_memory(self._memory_size, self._shm_address)
@@ -298,7 +300,7 @@
def write(self, data):
self._rtcout.RTC_TRACE("write()")
- if self._shmem:
+ if self._shmem and self._endian:
data_size = len(data)
@@ -314,7 +316,7 @@
- data_size_cdr = cdrMarshal(CORBA.TC_ulong, data_size)
+ data_size_cdr = cdrMarshal(CORBA.TC_ulonglong, data_size, self._endian)
self._shmem.seek(os.SEEK_SET)
self._shmem.write(data_size_cdr)
@@ -341,12 +343,12 @@
# void read(::OpenRTM::CdrData_out data);
def read(self):
self._rtcout.RTC_TRACE("read()")
- if self._shmem:
+ if self._shmem and self._endian:
self._shmem.seek(os.SEEK_SET)
data_size_cdr = self._shmem.read(SharedMemory.default_size)
- data_size = cdrUnmarshal(CORBA.TC_ulong, data_size_cdr)
+ data_size = cdrUnmarshal(CORBA.TC_ulonglong, data_size_cdr, self._endian)
@@ -376,10 +378,33 @@
# void close(int memory_size, string shm_address);
def setInterface(self, sm):
self._smInterface = sm
-
+
##
# @if jp
+ # @brief エンディアンを設定する
+ #
+ #
+ #
+ # @param self
+ # @param endian エンディアン
+ #
+ # @else
+ # @brief
+ #
+ # @param self
+ # @param endian endian
+ #
+ # @endif
+ #
+ # PortStatus setEndian();
+ def setEndian(self, endian):
+ self._endian = endian
+ if not CORBA.is_nil(self._smInterface):
+ self._smInterface.setEndian(self._endian)
+
+ ##
+ # @if jp
# @brief データの送信を知らせる
#
#
Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_SharedMemory.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_SharedMemory.py 2016-10-17 06:16:28 UTC (rev 724)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/test/test_SharedMemory.py 2016-10-20 05:42:02 UTC (rev 725)
@@ -38,6 +38,7 @@
def setUp(self):
sys.argv.extend(['-o', 'port.outport.out.shem_default_size:1k'])
+ #sys.argv.extend(['-o', 'port.dataport.serializer.cdr.endian:1k'])
#sys.argv.extend(['-o', 'port.inport.in.shem_default_size:1k'])
self.manager = OpenRTM_aist.Manager.init(sys.argv)
self.manager.activateManager()
@@ -77,10 +78,11 @@
self.assertEqual(memsize, 1024*1024)
sh_write.create_memory(1000,"test")
- data_cdr = cdrMarshal(CORBA.TC_ulong, 100)
+ sh_write.setEndian(True)
+ data_cdr = cdrMarshal(CORBA.TC_ulong, 100, True)
sh_write.write(data_cdr)
data_cdr = sh_read.read()
- data = cdrUnmarshal(CORBA.TC_ulong, data_cdr)
+ data = cdrUnmarshal(CORBA.TC_ulong, data_cdr, True)
self.assertEqual(data, 100)
if platform.system() == "Windows":
pass
More information about the openrtm-commit
mailing list