[openrtm-commit:02972] r3108 - in branches/RELENG_1_2/OpenRTM-aist: . examples/Throughput src/ext/ec/rtpreempt src/ext/logger/fluentbit_stream src/lib/coil/posix/coil src/lib/coil/win32/coil src/lib/rtm win32/OpenRTM-aist win32/OpenRTM-aist/examples
openrtm @ openrtm.org
openrtm @ openrtm.org
2017年 12月 10日 (日) 15:19:38 JST
Author: n-ando
Date: 2017-12-10 15:19:38 +0900 (Sun, 10 Dec 2017)
New Revision: 3108
Added:
branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/SharedMemory.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/SharedMemory.h
branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/SharedMemory.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/SharedMemory.h
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMConsumer.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMConsumer.h
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMProvider.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMProvider.h
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMConsumer.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMConsumer.h
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMProvider.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMProvider.h
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/SharedMemoryPort.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/SharedMemoryPort.h
branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/examples/Throughput/
Modified:
branches/RELENG_1_2/OpenRTM-aist/configure.ac
branches/RELENG_1_2/OpenRTM-aist/examples/Throughput/Makefile.am
branches/RELENG_1_2/OpenRTM-aist/src/ext/ec/rtpreempt/RTPreemptEC.cpp
branches/RELENG_1_2/OpenRTM-aist/src/ext/logger/fluentbit_stream/Makefile.am
branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/Makefile.am
branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/FactoryInit.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/Makefile.am
branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/OpenRTM-aist.sln.dep
branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/examples/Makefile.am
branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/examples/example.yaml
Log:
trunk/OpenRTM-aist{U+304B}{U+3089}{U+30EA}{U+30D2}{U+30B7}{U+30E7}{U+30F3}3051-3053, 3056{U+3092}{U+30DE}{U+30FC}{U+30B7}:
[compat,bugfix,->RELENG_1_2] #4199
[build,->RELENG_1_2] Changed to use tag source of fluent-bit. refs #4219
[compat,->RELENG_1_2] Throughput sample has been added in windows source package. refs #4222
[incompat,->RELENG_1_2] Shared memory data port implementation. #3269
Modified: branches/RELENG_1_2/OpenRTM-aist/configure.ac
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/configure.ac 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/configure.ac 2017-12-10 06:19:38 UTC (rev 3108)
@@ -1709,6 +1709,7 @@
win32/OpenRTM-aist/examples/SimpleIO/Makefile
win32/OpenRTM-aist/examples/SeqIO/Makefile
win32/OpenRTM-aist/examples/SimpleService/Makefile
+ win32/OpenRTM-aist/examples/Throughput/Makefile
win32/OpenRTM-aist/examples/USBCamera/Makefile
win32/OpenRTM-aist/ext/Makefile
win32/OpenRTM-aist/ext/ec/Makefile
Modified: branches/RELENG_1_2/OpenRTM-aist/examples/Throughput/Makefile.am
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/examples/Throughput/Makefile.am 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/examples/Throughput/Makefile.am 2017-12-10 06:19:38 UTC (rev 3108)
@@ -68,7 +68,7 @@
#------------------------------------------------------------
# Visual Studio Project
#------------------------------------------------------------
-win32_builddir=$(top_builddir)/win32/OpenRTM-aist/examples/SimpleIO
+win32_builddir=$(top_builddir)/win32/OpenRTM-aist/examples/Throughput
vcproj: vc9proj vcxproj
Modified: branches/RELENG_1_2/OpenRTM-aist/src/ext/ec/rtpreempt/RTPreemptEC.cpp
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/ext/ec/rtpreempt/RTPreemptEC.cpp 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/src/ext/ec/rtpreempt/RTPreemptEC.cpp 2017-12-10 06:19:38 UTC (rev 3108)
@@ -596,9 +596,9 @@
void RTPreemptEC::
setPolicy(coil::Properties& prop)
{
- RTC_TRACE(("setPriority()"));
+ RTC_TRACE(("setPolicy()"));
std::string policy;
- getProperty(prop, "priority", policy);
+ getProperty(prop, "policy", policy);
if (!policy.empty())
{
coil::normalize(policy);
Modified: branches/RELENG_1_2/OpenRTM-aist/src/ext/logger/fluentbit_stream/Makefile.am
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/ext/logger/fluentbit_stream/Makefile.am 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/src/ext/logger/fluentbit_stream/Makefile.am 2017-12-10 06:19:38 UTC (rev 3108)
@@ -34,7 +34,7 @@
else \
rm -rf fluent-bit; \
echo "fluent-bit cloneing"; \
- git clone --depth 1 https://github.com/fluent/fluent-bit.git; \
+ git clone --depth 1 -b v0.12.5 https://github.com/fluent/fluent-bit.git; \
fi;
fluent-bit-build: fluent-bit-clone
Modified: branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/Makefile.am
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/Makefile.am 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/Makefile.am 2017-12-10 06:19:38 UTC (rev 3108)
@@ -19,7 +19,8 @@
Signal.cpp \
Task.cpp \
Time.cpp \
- UUID.cpp
+ UUID.cpp \
+ SharedMemory.cpp
# posix API dependent headers
COIL_PLATFORM_H = \
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/SharedMemory.cpp (from rev 3056, trunk/OpenRTM-aist/src/lib/coil/posix/coil/SharedMemory.cpp)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/SharedMemory.cpp (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/SharedMemory.cpp 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,417 @@
+// -*- C++ -*-
+/*!
+ * @file SharedMemory_posix.cpp
+ * @brief SharedMemory class
+ * @date $Date$
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+
+#include <coil/SharedMemory.h>
+//#include "SharedMemory.h"
+#include <string.h>
+
+
+namespace coil
+{
+ /*!
+ * @if jp
+ * @brief ¥³¥ó¥¹¥È¥é¥¯¥¿
+ * @else
+ * @brief Constructor
+ * @endif
+ */
+ SharedMemory::SharedMemory()
+ : m_memory_size(0),
+ m_shm(NULL),
+ m_file_create(false),
+ m_fd(-1)
+ {
+ }
+
+
+ /*!
+ * @if jp
+ * @brief ¥Ç¥¹¥È¥é¥¯¥¿
+ * @else
+ * @brief Destructor
+ * @endif
+ */
+ SharedMemory::~SharedMemory()
+ {
+ close();
+ }
+
+ /*!
+ * @if jp
+ * @brief ¥³¥Ô¡¼¥³¥ó¥¹¥È¥é¥¯¥¿
+ * @else
+ * @brief Copy Constructor
+ * @endif
+ */
+ SharedMemory::SharedMemory(const SharedMemory& rhs)
+ {
+ m_memory_size = rhs.m_memory_size;
+ m_shm_address = rhs.m_shm_address;
+ m_shm = rhs.m_shm;
+ m_fd = rhs.m_fd;
+
+
+ }
+
+ /*!
+ * @if jp
+ * @brief ÂåÆþ±é»»»Ò
+ * @else
+ * @brief Assignment operator
+ * @endif
+ */
+ SharedMemory& SharedMemory::operator=(const SharedMemory& rhs)
+ {
+ SharedMemory tmp(rhs);
+ std::swap(this->m_memory_size, tmp.m_memory_size);
+ std::swap(this->m_shm_address, tmp.m_shm_address);
+ std::swap(this->m_shm, tmp.m_shm);
+ std::swap(this->m_fd, tmp.m_fd);
+
+ return *this;
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤ÎÀ¸À®
+ *¡£
+ *
+ * @param shm_address ¶¦Í¥á¥â¥ê¤Î¼±ÊÌ»Ò
+ * @param memory_size ¶¦Í¥á¥â¥ê¤Î¥µ¥¤¥º
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief Create Shared Memory
+ *
+ *
+ * @param shm_address
+ * @param memory_size
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::create(std::string shm_address,
+ int memory_size)
+ {
+
+ m_shm_address = shm_address;
+ m_memory_size = memory_size;
+
+
+ m_fd = shm_open(m_shm_address.c_str(), O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
+ if(m_fd < 0)
+ {
+ return -1;
+ }
+ ftruncate(m_fd, m_memory_size);
+ m_shm = (char*)mmap(NULL,
+ m_memory_size,
+ PROT_READ|PROT_WRITE,
+ MAP_SHARED,
+ m_fd,
+ 0);
+
+ m_file_create = true;
+ return 0;
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤Ø¤Î¥¢¥¯¥»¥¹
+ *¡£
+ *
+ * @param shm_address ¶¦Í¥á¥â¥ê¤Î¼±ÊÌ»Ò
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief Open Shared Memory
+ *
+ *
+ * @param shm_address
+ * @param memory_size
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::open(std::string shm_address, int memory_size)
+ {
+ m_shm_address = shm_address;
+ m_memory_size = memory_size;
+
+
+ m_fd = shm_open(m_shm_address.c_str(), O_RDWR|O_CREAT, 0);
+ if(m_fd < 0)
+ {
+ return -1;
+ }
+ ftruncate(m_fd, m_memory_size);
+ m_shm = (char*)mmap(NULL,
+ m_memory_size,
+ PROT_READ|PROT_WRITE,
+ MAP_SHARED,
+ m_fd,
+ 0);
+
+ return 0;
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤Ø¤Î½ñ¤¹þ¤ß
+ *¡£
+ *
+ * @param data ½ñ¤¹þ¤à¥Ç¡¼¥¿
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief Write Shared Memory
+ *
+ *
+ * @param data
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::write(const char *data, const int pos, const int size)
+ {
+ if (!created())
+ {
+ return -1;
+ }
+
+ memcpy(&m_shm[pos],&data[0],size);
+
+ return 0;
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤«¤é¤ÎÆɤ߹þ¤ß
+ *¡£
+ *
+ * @param data Æɤ߹þ¤à¥Ç¡¼¥¿
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief Read Shared Memory
+ *
+ *
+ * @param data
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::read(char* data, const int pos, const int size)
+ {
+ if (!created())
+ {
+ return -1;
+ }
+
+ memcpy(&data[0],&m_shm[pos],size);
+
+ return 0;
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤Îºï½ü
+ *¡£
+ *
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief Close Shared Memory
+ *
+ *
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::close()
+ {
+
+ if (created())
+ {
+ ::close(m_fd);
+ }
+ else
+ {
+ return -1;
+ }
+ if(m_file_create)
+ {
+ //shm_unlink(m_shm_address);
+ }
+ return 0;
+
+ }
+ /*!
+ * @if jp
+ *
+ * @brief ¥á¥â¥ê¤Î¥µ¥¤¥º¼èÆÀ
+ *¡£
+ *
+ *
+ * @return ¥µ¥¤¥º
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return size
+ *
+ * @endif
+ */
+ unsigned int SharedMemory::get_size()
+ {
+ return m_memory_size;
+ }
+ /*!
+ * @if jp
+ *
+ * @brief ¥á¥â¥ê¤Î¥¢¥É¥ì¥¹¼èÆÀ
+ *¡£
+ *
+ *
+ * @return ¥¢¥É¥ì¥¹
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return address
+ *
+ * @endif
+ */
+ std::string SharedMemory::get_addresss()
+ {
+ return m_shm_address;
+ };
+ /*!
+ * @if jp
+ *
+ * @brief ¥á¥â¥ê¤Î¼èÆÀ
+ *
+ *
+ *
+ * @return ¥á¥â¥ê
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return memory
+ *
+ * @endif
+ */
+ char *SharedMemory::get_data()
+ {
+ return m_shm;
+ }
+
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¥Õ¥¡¥¤¥ëºï½ü(Windows¤Î¾ì¹ç¤Ï²¿¤â¤·¤Ê¤¤)
+ *
+ *
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::unlink()
+ {
+ shm_unlink(m_shm_address.c_str());
+ return 0;
+ }
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤ËÀ¸À®ºÑ¤ß¤«¤Î³Îǧ
+ *
+ *
+ *
+ * @return true: ºîÀ®ºÑ¤ß, false: ̤ºîÀ®
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return
+ *
+ * @endif
+ */
+ bool SharedMemory::created()
+ {
+ if(m_fd < 0)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+
+
+
+}
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/SharedMemory.h (from rev 3056, trunk/OpenRTM-aist/src/lib/coil/posix/coil/SharedMemory.h)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/SharedMemory.h (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/posix/coil/SharedMemory.h 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,373 @@
+// -*- C++ -*-
+/*!
+ * @file SharedMemory_vxworks.h
+ * @brief SharedMemory class
+ * @date $Date$
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef COIL_SHAREDMEMORY_H
+#define COIL_SHAREDMEMORY_H
+
+
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <string>
+
+#include <coil/config_coil.h>
+
+#define DEFAULT_MEMORY_SIZE 2097152
+
+
+
+namespace coil
+{
+ /*!
+ * @if jp
+ *
+ * @class SharedMemory
+ * @brief SharedMemory ¥¯¥é¥¹
+ *
+ * @else
+ *
+ * @class SharedMemory
+ * @brief SharedMemory class
+ *
+ * @endif
+ */
+ class SharedMemory
+ {
+ public:
+
+ /*!
+ * @if jp
+ *
+ * @brief ¥³¥ó¥¹¥È¥é¥¯¥¿
+ *
+ * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£
+ *
+ *
+ * @else
+ *
+ * @brief Constructor
+ *
+ * Constructor
+ *
+ *
+ * @endif
+ */
+ SharedMemory();
+
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¥Ç¥¹¥È¥é¥¯¥¿
+ *
+ * ¥Ç¥¹¥È¥é¥¯¥¿¡£
+ *
+ * @else
+ *
+ * @brief Destructor
+ *
+ * Destructor
+ *
+ * @endif
+ */
+ virtual ~SharedMemory();
+
+ /*!
+ * @if jp
+ *
+ * @brief ¥³¥Ô¡¼¥³¥ó¥¹¥È¥é¥¯¥¿
+ *
+ * ¥³¥Ô¡¼¥³¥ó¥¹¥È¥é¥¯¥¿¡£
+ *
+ * @param rhs ¥³¥Ô¡¼¸µ¶¦Í¥á¥â¥ê¥ª¥Ö¥¸¥§¥¯¥È
+ *
+ * @else
+ *
+ * @brief Copy Constructor
+ *
+ * Copy Constructor
+ *
+ * @param rhs shared memory object of copy source.
+ *
+ * @endif
+ */
+ SharedMemory(const SharedMemory& rhs);
+
+ /*!
+ * @if jp
+ *
+ * @brief ÂåÆþ±é»»»Ò
+ *
+ * ¶¦Í¥á¥â¥ê¥ª¥Ö¥¸¥§¥¯¥È¤ò¥³¥Ô¡¼¤¹¤ë¡£
+ *
+ * @param rhs ÂåÆþ¸µÆ°Åª¶¦Í¥á¥â¥ê¥ª¥Ö¥¸¥§¥¯¥È
+ *
+ * @return ÂåÆþ·ë²Ì
+ *
+ * @else
+ *
+ * @brief Assignment operator
+ *
+ * Copy a shared memory object.
+ *
+ * @param rhs shared memory object of assignment source.
+ *
+ * @return Assignment result.
+ *
+ * @endif
+ */
+ SharedMemory& operator=(const SharedMemory& rhs);
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤ÎÀ¸À®
+ *¡£
+ *
+ * @param shm_address ¶¦Í¥á¥â¥ê¤Î¼±ÊÌ»Ò
+ * @param memory_size ¶¦Í¥á¥â¥ê¤Î¥µ¥¤¥º
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief Create Shared Memory
+ *
+ *
+ * @param shm_address
+ * @param memory_size
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int create(std::string shm_address,
+ int memory_size = DEFAULT_MEMORY_SIZE);
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤Ø¤Î¥¢¥¯¥»¥¹
+ *¡£
+ *
+ * @param shm_address ¶¦Í¥á¥â¥ê¤Î¼±ÊÌ»Ò
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief Open Shared Memory
+ *
+ *
+ * @param shm_address
+ * @param memory_size
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int open(std::string shm_address,
+ int memory_size = DEFAULT_MEMORY_SIZE);
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤Ø¤Î½ñ¤¹þ¤ß
+ *¡£
+ *
+ * @param data ½ñ¤¹þ¤à¥Ç¡¼¥¿
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief Write Shared Memory
+ *
+ *
+ * @param data
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int write(const char *data, const int pos, const int size);
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤«¤é¤ÎÆɤ߹þ¤ß
+ *¡£
+ *
+ * @param data Æɤ߹þ¤à¥Ç¡¼¥¿
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief Read Shared Memory
+ *
+ *
+ * @param data
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int read(char* data, const int pos, const int size);
+
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤Îºï½ü
+ *¡£
+ *
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief Close Shared Memory
+ *
+ *
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int close();
+ /*!
+ * @if jp
+ *
+ * @brief ¥á¥â¥ê¤Î¥µ¥¤¥º¼èÆÀ
+ *¡£
+ *
+ *
+ * @return ¥µ¥¤¥º
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return size
+ *
+ * @endif
+ */
+ virtual unsigned int get_size();
+ /*!
+ * @if jp
+ *
+ * @brief ¥á¥â¥ê¤Î¥¢¥É¥ì¥¹¼èÆÀ
+ *¡£
+ *
+ *
+ * @return ¥¢¥É¥ì¥¹
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return address
+ *
+ * @endif
+ */
+ virtual std::string get_addresss();
+ /*!
+ * @if jp
+ *
+ * @brief ¥á¥â¥ê¤Î¼èÆÀ
+ *
+ *
+ *
+ * @return ¥á¥â¥ê
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return memory
+ *
+ * @endif
+ */
+ virtual char *get_data();
+ /*!
+ * @if jp
+ *
+ * @brief ¥Õ¥¡¥¤¥ëºï½ü(Windows¤Î¾ì¹ç¤Ï²¿¤â¤·¤Ê¤¤)
+ *
+ *
+ *
+ * @return 0: À®¸ù, -1: ¼ºÇÔ
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int unlink();
+ /*!
+ * @if jp
+ *
+ * @brief ¶¦Í¥á¥â¥ê¤ËÀ¸À®ºÑ¤ß¤«¤Î³Îǧ
+ *
+ *
+ *
+ * @return true: ºîÀ®ºÑ¤ß,false: ̤ºîÀ®
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return
+ *
+ * @endif
+ */
+ virtual bool created();
+
+ private:
+ int m_memory_size;
+ std::string m_shm_address;
+ char *m_shm;
+ bool m_file_create;
+ int m_fd;
+ }; // class SharedMemory
+
+}; // namespace coil
+
+#endif // SharedMemory_h
Modified: branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/Makefile.am 2017-12-10 06:19:38 UTC (rev 3108)
@@ -15,7 +15,8 @@
Signal.cpp \
Task.cpp \
Time.cpp \
- UUID.cpp
+ UUID.cpp \
+ SharedMemory.cpp
# Win32 API dependent headers
COIL_PLATFORM_H = \
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/SharedMemory.cpp (from rev 3056, trunk/OpenRTM-aist/src/lib/coil/win32/coil/SharedMemory.cpp)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/SharedMemory.cpp (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/SharedMemory.cpp 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,408 @@
+// -*- C++ -*-
+/*!
+ * @file SharedMemory_win32.cpp
+ * @brief SharedMemory class
+ * @date $Date$
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+
+#include <coil/SharedMemory.h>
+//#include "SharedMemory.h"
+#include <string.h>
+
+
+namespace coil
+{
+ /*!
+ * @if jp
+ * @brief RXgN^
+ * @else
+ * @brief Constructor
+ * @endif
+ */
+ SharedMemory::SharedMemory()
+ : m_memory_size(0),
+ m_shm(NULL),
+ m_file_create(false),
+ m_handle(NULL)
+ {
+ }
+
+
+ /*!
+ * @if jp
+ * @brief fXgN^
+ * @else
+ * @brief Destructor
+ * @endif
+ */
+ SharedMemory::~SharedMemory()
+ {
+ close();
+ }
+
+ /*!
+ * @if jp
+ * @brief Rs[RXgN^
+ * @else
+ * @brief Copy Constructor
+ * @endif
+ */
+ SharedMemory::SharedMemory(const SharedMemory& rhs)
+ {
+ m_memory_size = rhs.m_memory_size;
+ m_shm_address = rhs.m_shm_address;
+ m_shm = rhs.m_shm;
+ m_handle = rhs.m_handle;
+ }
+
+ /*!
+ * @if jp
+ * @brief ãüZq
+ * @else
+ * @brief Assignment operator
+ * @endif
+ */
+ SharedMemory& SharedMemory::operator=(const SharedMemory& rhs)
+ {
+ SharedMemory tmp(rhs);
+ std::swap(this->m_memory_size, tmp.m_memory_size);
+ std::swap(this->m_shm_address, tmp.m_shm_address);
+ std::swap(this->m_shm, tmp.m_shm);
+ std::swap(this->m_handle, tmp.m_handle);
+ return *this;
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤L̶¬
+ *B
+ *
+ * @param shm_address ¤L̯Êq
+ * @param memory_size ¤LÌTCY
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief Create Shared Memory
+ *
+ *
+ * @param shm_address
+ * @param memory_size
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::create(std::string shm_address,
+ int memory_size)
+ {
+
+ m_shm_address = shm_address;
+ m_memory_size = memory_size;
+ m_handle = CreateFileMapping(
+ (HANDLE)-1,
+ NULL,
+ PAGE_READWRITE | SEC_COMMIT,
+ 0, m_memory_size,
+ shm_address.c_str());
+ /*
+ if(GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ }
+ else
+ {
+
+ }
+ */
+
+ m_shm = (char *)MapViewOfFile(m_handle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
+ m_file_create = true;
+ return 0;
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤LÖÌANZX
+ *B
+ *
+ * @param shm_address ¤L̯Êq
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief Open Shared Memory
+ *
+ *
+ * @param shm_address
+ * @param memory_size
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::open(std::string shm_address, int memory_size)
+ {
+ m_shm_address = shm_address;
+ m_memory_size = memory_size;
+ m_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, m_shm_address.c_str());
+ m_shm = (char *)MapViewOfFile(m_handle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
+ return 0;
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤LÖÌ«Ý
+ *B
+ *
+ * @param data «Þf[^
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief Write Shared Memory
+ *
+ *
+ * @param data
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::write(const char *data, const int pos, const int size)
+ {
+ if (!created())
+ {
+ return -1;
+ }
+
+ memcpy(&m_shm[pos],&data[0],size);
+
+ return 0;
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤L©çÌÇÝÝ
+ *B
+ *
+ * @param data ÇÝÞf[^
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief Read Shared Memory
+ *
+ *
+ * @param data
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::read(char* data, const int pos, const int size)
+ {
+ if (!created())
+ {
+ return -1;
+ }
+
+ memcpy(&data[0],&m_shm[pos],size);
+ return 0;
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤LÌí
+ *B
+ *
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief Close Shared Memory
+ *
+ *
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::close()
+ {
+
+ if (created())
+ {
+ UnmapViewOfFile(m_shm);
+ }
+ else
+ {
+ return -1;
+ }
+ if(m_file_create)
+ {
+ if (CloseHandle(m_handle) == 0)
+ {
+ return -1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ return 0;
+
+ }
+ /*!
+ * @if jp
+ *
+ * @brief ÌTCYæ¾
+ *B
+ *
+ *
+ * @return TCY
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return size
+ *
+ * @endif
+ */
+ unsigned int SharedMemory::get_size()
+ {
+ return m_memory_size;
+ }
+ /*!
+ * @if jp
+ *
+ * @brief ÌAhXæ¾
+ *B
+ *
+ *
+ * @return AhX
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return address
+ *
+ * @endif
+ */
+ std::string SharedMemory::get_addresss()
+ {
+ return m_shm_address;
+ };
+ /*!
+ * @if jp
+ *
+ * @brief Ìæ¾
+ *
+ *
+ *
+ * @return
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return memory
+ *
+ * @endif
+ */
+ char *SharedMemory::get_data()
+ {
+ return m_shm;
+ }
+
+
+
+ /*!
+ * @if jp
+ *
+ * @brief t@Cí(WindowsÌêͽàµÈ¢)
+ *
+ *
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ int SharedMemory::unlink()
+ {
+ return -1;
+ }
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤Lɶ¬ÏÝ©ÌmF
+ *
+ *
+ *
+ * @return true: ì¬ÏÝ, false: ¢ì¬
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return
+ *
+ * @endif
+ */
+ bool SharedMemory::created()
+ {
+ if (m_handle == NULL)
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+
+
+
+}
\ No newline at end of file
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/SharedMemory.h (from rev 3056, trunk/OpenRTM-aist/src/lib/coil/win32/coil/SharedMemory.h)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/SharedMemory.h (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/coil/win32/coil/SharedMemory.h 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,366 @@
+// -*- C++ -*-
+/*!
+ * @file SharedMemory_win32.h
+ * @brief SharedMemory class
+ * @date $Date$
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef COIL_SHAREDMEMORY_H
+#define COIL_SHAREDMEMORY_H
+
+#include <windows.h>
+
+#include <string>
+#include <coil/config_coil.h>
+
+#define DEFAULT_MEMORY_SIZE 2097152
+
+
+
+namespace coil
+{
+ /*!
+ * @if jp
+ *
+ * @class SharedMemory
+ * @brief SharedMemory NX
+ *
+ * @else
+ *
+ * @class SharedMemory
+ * @brief SharedMemory class
+ *
+ * @endif
+ */
+ class SharedMemory
+ {
+ public:
+
+ /*!
+ * @if jp
+ *
+ * @brief RXgN^
+ *
+ * RXgN^B
+ *
+ *
+ * @else
+ *
+ * @brief Constructor
+ *
+ * Constructor
+ *
+ *
+ * @endif
+ */
+ SharedMemory();
+
+
+
+ /*!
+ * @if jp
+ *
+ * @brief fXgN^
+ *
+ * fXgN^B
+ *
+ * @else
+ *
+ * @brief Destructor
+ *
+ * Destructor
+ *
+ * @endif
+ */
+ virtual ~SharedMemory();
+
+ /*!
+ * @if jp
+ *
+ * @brief Rs[RXgN^
+ *
+ * Rs[RXgN^B
+ *
+ * @param rhs Rs[³¤LIuWFNg
+ *
+ * @else
+ *
+ * @brief Copy Constructor
+ *
+ * Copy Constructor
+ *
+ * @param rhs shared memory object of copy source.
+ *
+ * @endif
+ */
+ SharedMemory(const SharedMemory& rhs);
+
+ /*!
+ * @if jp
+ *
+ * @brief ãüZq
+ *
+ * ¤LIuWFNgðRs[·éB
+ *
+ * @param rhs ãü³®I¤LIuWFNg
+ *
+ * @return ãüÊ
+ *
+ * @else
+ *
+ * @brief Assignment operator
+ *
+ * Copy a shared memory object.
+ *
+ * @param rhs shared memory object of assignment source.
+ *
+ * @return Assignment result.
+ *
+ * @endif
+ */
+ SharedMemory& operator=(const SharedMemory& rhs);
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤L̶¬
+ *B
+ *
+ * @param shm_address ¤L̯Êq
+ * @param memory_size ¤LÌTCY
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief Create Shared Memory
+ *
+ *
+ * @param shm_address
+ * @param memory_size
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int create(std::string shm_address,
+ int memory_size = DEFAULT_MEMORY_SIZE);
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤LÖÌANZX
+ *B
+ *
+ * @param shm_address ¤L̯Êq
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief Open Shared Memory
+ *
+ *
+ * @param shm_address
+ * @param memory_size
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int open(std::string shm_address,
+ int memory_size = DEFAULT_MEMORY_SIZE);
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤LÖÌ«Ý
+ *B
+ *
+ * @param data «Þf[^
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief Write Shared Memory
+ *
+ *
+ * @param data
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int write(const char *data, const int pos, const int size);
+
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤L©çÌÇÝÝ
+ *B
+ *
+ * @param data ÇÝÞf[^
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief Read Shared Memory
+ *
+ *
+ * @param data
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int read(char* data, const int pos, const int size);
+
+ /*!
+ * @if jp
+ *
+ * @brief ¤LÌí
+ *B
+ *
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief Close Shared Memory
+ *
+ *
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int close();
+ /*!
+ * @if jp
+ *
+ * @brief ÌTCYæ¾
+ *B
+ *
+ *
+ * @return TCY
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return size
+ *
+ * @endif
+ */
+ virtual unsigned int get_size();
+ /*!
+ * @if jp
+ *
+ * @brief ÌAhXæ¾
+ *B
+ *
+ *
+ * @return AhX
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return address
+ *
+ * @endif
+ */
+ virtual std::string get_addresss();
+ /*!
+ * @if jp
+ *
+ * @brief Ìæ¾
+ *
+ *
+ *
+ * @return
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return memory
+ *
+ * @endif
+ */
+ virtual char *get_data();
+ /*!
+ * @if jp
+ *
+ * @brief t@Cí(WindowsÌêͽàµÈ¢)
+ *
+ *
+ *
+ * @return 0: ¬÷, -1: ¸s
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return 0: successful, -1: failed
+ *
+ * @endif
+ */
+ virtual int unlink();
+ /*!
+ * @if jp
+ *
+ * @brief ¤Lɶ¬ÏÝ©ÌmF
+ *
+ *
+ *
+ * @return true: ì¬ÏÝ, false: ¢ì¬
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ *
+ * @return
+ *
+ * @endif
+ */
+ virtual bool created();
+
+ private:
+ int m_memory_size;
+ std::string m_shm_address;
+ char *m_shm;
+ HANDLE m_handle;
+ bool m_file_create;
+ }; // class SharedMemory
+
+}; // namespace coil
+
+#endif // SharedMemory_h
Modified: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/FactoryInit.cpp
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/FactoryInit.cpp 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/FactoryInit.cpp 2017-12-10 06:19:38 UTC (rev 3108)
@@ -37,6 +37,10 @@
#include <rtm/OutPortCorbaCdrProvider.h>
#include <rtm/InPortDirectProvider.h>
#include <rtm/InPortDirectConsumer.h>
+#include <rtm/InPortSHMProvider.h>
+#include <rtm/InPortSHMConsumer.h>
+#include <rtm/OutPortSHMProvider.h>
+#include <rtm/OutPortSHMConsumer.h>
// RTC name numbering policy
#include <rtm/NumberingPolicy.h>
@@ -64,6 +68,10 @@
OutPortCorbaCdrProviderInit();
InPortDirectProviderInit();
InPortDirectConsumerInit();
+ InPortSHMProviderInit();
+ InPortSHMConsumerInit();
+ OutPortSHMProviderInit();
+ OutPortSHMConsumerInit();
// Naming Policy
ProcessUniquePolicyInit();
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMConsumer.cpp (from rev 3056, trunk/OpenRTM-aist/src/lib/rtm/InPortSHMConsumer.cpp)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMConsumer.cpp (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMConsumer.cpp 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,350 @@
+// -*- C++ -*-
+/*!
+ * @file InPortSHMConsumer.h
+ * @brief InPortSHMConsumer class
+ *
+ * @date $Date: 2017-10-30 07:49:59 $
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ */
+
+
+#include <rtm/NVUtil.h>
+#include <rtm/InPortSHMConsumer.h>
+#include <coil/UUID.h>
+#include <coil/Guard.h>
+#include <memory>
+
+
+namespace RTC
+{
+ /*!
+ * @if jp
+ * @brief コンストラクタ
+ * @else
+ * @brief Constructor
+ * @param buffer The buffer object that is attached to this Consumer
+ * @endif
+ */
+ InPortSHMConsumer::InPortSHMConsumer()
+ : m_memory_size(0),
+ m_endian(true),
+ rtclog("InPortSHMConsumer")
+ {
+ coil::UUID_Generator uugen;
+ uugen.init();
+ std::auto_ptr<coil::UUID> uuid(uugen.generateUUID(2, 0x01));
+ m_shm_address = uuid->to_string();
+ }
+
+ /*!
+ * @if jp
+ * @brief デストラクタ
+ * @else
+ * @brief Destructor
+ * @endif
+ */
+ InPortSHMConsumer::~InPortSHMConsumer()
+ {
+ RTC_PARANOID(("~InPortSHMConsumer()"));
+ m_shmem.close_memory(true);
+
+ }
+
+ /*!
+ * @if jp
+ * @brief 設定初期化
+ * @else
+ * @brief Initializing configuration
+ * @endif
+ */
+ void InPortSHMConsumer::init(coil::Properties& prop)
+ {
+ m_properties = prop;
+ std::string ds = m_properties["shem_default_size"];
+ m_memory_size = m_shmem.string_to_MemorySize(ds);
+
+ if (m_properties.hasKey("serializer") == NULL)
+ {
+ m_endian = true;
+ return;
+ }
+
+
+ std::string endian_type(m_properties.getProperty("serializer.cdr.endian", ""));
+ coil::normalize(endian_type);
+ std::vector<std::string> endian(coil::split(endian_type, ","));
+ if (endian.empty()) { return; }
+ if (endian[0] == "little")
+ {
+ m_endian = true;
+ }
+ else if (endian[0] == "big")
+ {
+ m_endian = false;
+ return;
+ }
+
+ }
+
+
+ bool InPortSHMConsumer::setObject(CORBA::Object_ptr obj)
+ {
+ RTC_PARANOID(("setObject()"));
+ if (CorbaConsumer< ::OpenRTM::PortSharedMemory >::setObject(obj))
+ {
+ m_shmem.setInterface(_ptr());
+ return true;
+ }
+
+
+ return false;
+ }
+
+
+ /*!
+ * @if jp
+ * @brief バッファへのデータ書込
+ * @else
+ * @brief Write data into the buffer
+ * @endif
+ */
+ InPortConsumer::ReturnCode InPortSHMConsumer::put(const cdrMemoryStream& data)
+ {
+ RTC_PARANOID(("put()"));
+
+
+ try
+ {
+
+ Guard guard(m_mutex);
+ m_shmem.setEndian(m_endian);
+
+ m_shmem.create_memory(m_memory_size, m_shm_address.c_str());
+
+ m_shmem.write(data);
+
+ return convertReturnCode(_ptr()->put());
+ }
+ catch (...)
+ {
+ return CONNECTION_LOST;
+ }
+ return UNKNOWN_ERROR;
+ }
+
+
+ void InPortSHMConsumer::
+ publishInterfaceProfile(SDOPackage::NVList& properties)
+ {
+ return;
+ }
+ bool InPortSHMConsumer::
+ subscribeInterface(const SDOPackage::NVList& properties)
+ {
+ RTC_TRACE(("subscribeInterface()"));
+ RTC_DEBUG_STR((NVUtil::toString(properties)));
+
+ // getting InPort's ref from IOR string
+ if (subscribeFromIor(properties)) { return true; }
+
+ // getting InPort's ref from Object reference
+ if (subscribeFromRef(properties)) { return true; }
+
+ return false;;
+ }
+ void InPortSHMConsumer::
+ unsubscribeInterface(const SDOPackage::NVList& properties)
+ {
+ RTC_TRACE(("unsubscribeInterface()"));
+ RTC_DEBUG_STR((NVUtil::toString(properties)));
+
+ if (unsubscribeFromIor(properties)) { return; }
+ unsubscribeFromRef(properties);
+ }
+ bool InPortSHMConsumer::
+ subscribeFromIor(const SDOPackage::NVList& properties)
+ {
+ RTC_TRACE(("subscribeFromIor()"));
+
+ CORBA::Long index;
+ index = NVUtil::find_index(properties,
+ "dataport.corba_cdr.inport_ior");
+ if (index < 0)
+ {
+ RTC_ERROR(("inport_ior not found"));
+ return false;
+ }
+
+ const char* ior(0);
+ if (!(properties[index].value >>= ior))
+ {
+ RTC_ERROR(("inport_ior has no string"));
+ return false;
+ }
+
+ CORBA::ORB_var orb = ::RTC::Manager::instance().getORB();
+ CORBA::Object_var obj = orb->string_to_object(ior);
+
+ if (CORBA::is_nil(obj))
+ {
+ RTC_ERROR(("invalid IOR string has been passed"));
+ return false;
+ }
+
+ if (!setObject(obj.in()))
+ {
+ RTC_WARN(("Setting object to consumer failed."));
+ return false;
+ }
+ return true;
+ }
+ bool InPortSHMConsumer::
+ subscribeFromRef(const SDOPackage::NVList& properties)
+ {
+ RTC_TRACE(("subscribeFromRef()"));
+ CORBA::Long index;
+ index = NVUtil::find_index(properties,
+ "dataport.corba_cdr.inport_ref");
+ if (index < 0)
+ {
+ RTC_ERROR(("inport_ref not found"));
+ return false;
+ }
+
+ CORBA::Object_var obj;
+#ifdef ORB_IS_ORBEXPRESS
+ if (!(properties[index].value >>= obj))
+#else
+ if (!(properties[index].value >>= CORBA::Any::to_object(obj.out())))
+#endif
+ {
+ RTC_ERROR(("prop[inport_ref] is not objref"));
+ return true;
+ }
+
+ if (CORBA::is_nil(obj))
+ {
+ RTC_ERROR(("prop[inport_ref] is not objref"));
+ return false;
+ }
+
+ if (!setObject(obj.in()))
+ {
+ RTC_ERROR(("Setting object to consumer failed."));
+ return false;
+ }
+ return true;
+ }
+ bool InPortSHMConsumer::
+ unsubscribeFromIor(const SDOPackage::NVList& properties)
+ {
+ RTC_TRACE(("unsubscribeFromIor()"));
+ CORBA::Long index;
+ index = NVUtil::find_index(properties,
+ "dataport.corba_cdr.inport_ior");
+ if (index < 0)
+ {
+ RTC_ERROR(("inport_ior not found"));
+ return false;
+ }
+
+ const char* ior;
+ if (!(properties[index].value >>= ior))
+ {
+ RTC_ERROR(("prop[inport_ior] is not string"));
+ return false;
+ }
+
+ CORBA::ORB_var orb = ::RTC::Manager::instance().getORB();
+ CORBA::Object_var var = orb->string_to_object(ior);
+ if (!(_ptr()->_is_equivalent(var)))
+ {
+ RTC_ERROR(("connector property inconsistency"));
+ return false;
+ }
+
+ releaseObject();
+ return true;
+ }
+ bool InPortSHMConsumer::
+ unsubscribeFromRef(const SDOPackage::NVList& properties)
+ {
+ RTC_TRACE(("unsubscribeFromRef()"));
+ CORBA::Long index;
+ index = NVUtil::find_index(properties,
+ "dataport.corba_cdr.inport_ref");
+ if (index < 0) { return false; }
+
+ CORBA::Object_var obj;
+#ifdef ORB_IS_ORBEXPRESS
+ if (!(properties[index].value >>= obj))
+#else
+ if (!(properties[index].value >>= CORBA::Any::to_object(obj.out())))
+#endif
+ {
+ return false;
+ }
+
+ if (!(_ptr()->_is_equivalent(obj.in()))) { return false; }
+
+ releaseObject();
+ return true;
+ }
+ InPortConsumer::ReturnCode
+ InPortSHMConsumer::convertReturnCode(OpenRTM::PortStatus ret)
+ {
+ switch (ret)
+ {
+ case OpenRTM::PORT_OK:
+ return InPortConsumer::PORT_OK;
+ break;
+ case OpenRTM::PORT_ERROR:
+ return InPortConsumer::PORT_ERROR;
+ break;
+ case OpenRTM::BUFFER_FULL:
+ return InPortConsumer::SEND_FULL;
+ break;
+ case OpenRTM::BUFFER_TIMEOUT:
+ return InPortConsumer::SEND_TIMEOUT;
+ break;
+ case OpenRTM::UNKNOWN_ERROR:
+ return InPortConsumer::UNKNOWN_ERROR;
+ break;
+ default:
+ return InPortConsumer::UNKNOWN_ERROR;
+ break;
+ }
+ return InPortConsumer::UNKNOWN_ERROR;
+ }
+
+
+
+}; // namespace RTC
+
+extern "C"
+{
+ /*!
+ * @if jp
+ * @brief モジュール初期化関数
+ * @else
+ * @brief Module initialization
+ * @endif
+ */
+ void InPortSHMConsumerInit(void)
+ {
+ RTC::InPortConsumerFactory& factory(RTC::InPortConsumerFactory::instance());
+ factory.addFactory("shared_memory",
+ ::coil::Creator< ::RTC::InPortConsumer,
+ ::RTC::InPortSHMConsumer>,
+ ::coil::Destructor< ::RTC::InPortConsumer,
+ ::RTC::InPortSHMConsumer>);
+ }
+};
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMConsumer.h (from rev 3056, trunk/OpenRTM-aist/src/lib/rtm/InPortSHMConsumer.h)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMConsumer.h (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMConsumer.h 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,193 @@
+// -*- C++ -*-
+/*!
+ * @file InPortSHMConsumer.h
+ * @brief InPortSHMConsumer class
+ * @date $Date: 2007-12-31 03:08:03 $
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * @date $Date: 2017-10-30 07:49:59 $
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ */
+
+#ifndef RTC_INPORTSHMCONSUMER_H
+#define RTC_INPORTSHMCONSUMER_H
+
+
+//#include <rtm/BufferBase.h>
+
+#include <rtm/SharedMemoryPort.h>
+#include <rtm/CorbaConsumer.h>
+#include <rtm/InPortConsumer.h>
+#include <rtm/Manager.h>
+#include <rtm/InPortCorbaCdrConsumer.h>
+
+namespace RTC
+{
+ /*!
+ * @if jp
+ * @class InPortSHMConsumer
+ * @brief InPortSHMConsumer クラス
+ *
+ * InPortConsumer
+ *
+ * 通信手段に 共有メモリ を利用した入力ポートコンシューマの実装クラス。
+ *
+ * @since 1.2.0
+ *
+ * @else
+ * @class InPortSHMConsumer
+ * @brief InPortSHMConsumer class
+ *
+ *
+ *
+ * @since 1.2.0
+ *
+ * @endif
+ */
+ class InPortSHMConsumer
+ : public InPortConsumer,
+ public CorbaConsumer< ::OpenRTM::PortSharedMemory >
+ {
+ typedef coil::Guard<coil::Mutex> Guard;
+ public:
+ DATAPORTSTATUS_ENUM
+ /*!
+ * @if jp
+ * @brief コンストラクタ
+ *
+ * コンストラクタ
+ *
+ * @param buffer 当該コンシューマに割り当てるバッファオブジェクト
+ *
+ * @else
+ * @brief Constructor
+ *
+ * Constructor
+ *
+ * @param buffer The buffer object that is attached to this Consumer
+ *
+ * @endif
+ */
+ InPortSHMConsumer();
+
+ /*!
+ * @if jp
+ * @brief デストラクタ
+ *
+ * デストラクタ
+ *
+ * @else
+ * @brief Destructor
+ *
+ * Destructor
+ *
+ * @endif
+ */
+ virtual ~InPortSHMConsumer();
+
+ /*!
+ * @if jp
+ * @brief 設定初期化
+ *
+ *
+ *
+ * @param prop 設定情報
+ *
+ * @else
+ *
+ * @brief Initializing configuration
+ *
+ *
+ *
+ * @param prop Configuration information
+ *
+ * @endif
+ */
+ virtual void init(coil::Properties& prop);
+ /*!
+ * @if jp
+ * @brief 接続先へのデータ送信
+ *
+ * 接続先のポートへデータを送信するための純粋仮想関数。
+ *
+ *
+ *
+ * @param data 送信するデータ
+ * @return リターンコード
+ *
+ * @else
+ * @brief Send data to the destination port
+ *
+ *
+ *
+ * @endif
+ */
+ virtual InPortConsumer::ReturnCode put(const cdrMemoryStream& data);
+ /*!
+ * @if jp
+ * @brief
+ *
+ *
+ *
+ * @param obj
+ * @return
+ *
+ * @else
+ * @brief
+ *
+ *
+ *
+ * @endif
+ */
+ virtual bool setObject(CORBA::Object_ptr obj);
+ virtual void publishInterfaceProfile(SDOPackage::NVList& properties);
+ virtual bool subscribeInterface(const SDOPackage::NVList& properties);
+ virtual void unsubscribeInterface(const SDOPackage::NVList& properties);
+
+private:
+ bool subscribeFromIor(const SDOPackage::NVList& properties);
+ bool subscribeFromRef(const SDOPackage::NVList& properties);
+ bool unsubscribeFromIor(const SDOPackage::NVList& properties);
+ bool unsubscribeFromRef(const SDOPackage::NVList& properties);
+
+protected:
+ InPortConsumer::ReturnCode convertReturnCode(OpenRTM::PortStatus ret);
+
+ mutable Logger rtclog;
+ coil::Properties m_properties;
+ coil::Mutex m_mutex;
+ std::string m_shm_address;
+ SharedMemoryPort m_shmem;
+ int m_memory_size;
+ bool m_endian;
+ };
+}; // namespace RTC
+
+extern "C"
+{
+ /*!
+ * @if jp
+ * @brief モジュール初期化関数
+ *
+ * InPortSHMConsumer のファクトリを登録する初期化関数。
+ *
+ * @else
+ * @brief Module initialization
+ *
+ * This initialization function registers InPortSHMConsumer's factory.
+ *
+ * @endif
+ */
+ void InPortSHMConsumerInit(void);
+};
+
+#endif // RTC_INPORTCORBACDRCONSUMER_H
+
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMProvider.cpp (from rev 3056, trunk/OpenRTM-aist/src/lib/rtm/InPortSHMProvider.cpp)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMProvider.cpp (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMProvider.cpp 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,233 @@
+// -*- C++ -*-
+/*!
+ * @file InPortCorbaCdrProvider.cpp
+ * @brief InPortCorbaCdrProvider class
+ * @date $Date: 2008-01-14 07:49:59 $
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2009-2010
+ * Noriaki Ando
+ * Task-intelligence Research Group,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id: InPortCorbaCdrProvider.cpp 1244 2009-03-13 07:25:42Z n-ando $
+ *
+ */
+
+#include <rtm/InPortSHMProvider.h>
+
+#ifdef WIN32
+#pragma warning( disable : 4290 )
+#endif
+
+namespace RTC
+{
+ /*!
+ * @if jp
+ * @brief コンストラクタ
+ * @else
+ * @brief Constructor
+ * @endif
+ */
+ InPortSHMProvider::InPortSHMProvider(void)
+ : m_buffer(0)
+ {
+ // PortProfile setting
+ setInterfaceType("shared_memory");
+
+ // ConnectorProfile setting
+
+#ifdef ORB_IS_OMNIORB
+ ::RTC::Manager::instance().theShortCutPOA()->activate_object(this);
+#endif
+
+ m_objref = this->_this();
+
+ // set InPort's reference
+ CORBA::ORB_var orb = ::RTC::Manager::instance().getORB();
+ CORBA::String_var ior = orb->object_to_string(m_objref.in());
+ CORBA_SeqUtil::
+ push_back(m_properties,
+ NVUtil::newNV("dataport.corba_cdr.inport_ior", ior.in()));
+
+ CORBA_SeqUtil::
+ push_back(m_properties,
+ NVUtil::newNV("dataport.corba_cdr.inport_ref", m_objref));
+
+ }
+
+ /*!
+ * @if jp
+ * @brief デストラクタ
+ * @else
+ * @brief Destructor
+ * @endif
+ */
+ InPortSHMProvider::~InPortSHMProvider(void)
+ {
+
+ }
+
+ void InPortSHMProvider::init(coil::Properties& prop)
+ {
+ }
+
+ /*!
+ * @if jp
+ * @brief バッファをセットする
+ * @else
+ * @brief Setting outside buffer's pointer
+ * @endif
+ */
+ void InPortSHMProvider::
+ setBuffer(BufferBase<cdrMemoryStream>* buffer)
+ {
+ m_buffer = buffer;
+ }
+
+ /*!
+ * @if jp
+ * @brief リスナを設定する
+ * @else
+ * @brief Set the listener
+ * @endif
+ */
+ void InPortSHMProvider::setListener(ConnectorInfo& info,
+ ConnectorListeners* listeners)
+ {
+ m_profile = info;
+ m_listeners = listeners;
+ }
+
+
+ void InPortSHMProvider::setConnector(InPortConnector* connector)
+ {
+ m_connector = connector;
+ }
+
+
+
+ /*!
+ * @if jp
+ * @brief バッファにデータを書き込む
+ * @else
+ * @brief Write data into the buffer
+ * @endif
+ */
+ ::OpenRTM::PortStatus
+ InPortSHMProvider::put()
+ throw (CORBA::SystemException)
+ {
+ RTC_PARANOID(("InPortSHMProvider::put()"));
+ if (m_buffer == 0)
+ {
+ return ::OpenRTM::PORT_ERROR;
+ }
+
+ cdrMemoryStream cdr;
+ bool endian_type = m_connector->isLittleEndian();
+
+ try
+ {
+ setEndian(endian_type);
+ read(cdr);
+
+#ifdef ORB_IS_ORBEXPRESS
+ RTC_PARANOID(("received data size: %d", cdr.cdr.size_written()));
+#elif defined(ORB_IS_TAO)
+ RTC_PARANOID(("received data size: %d", cdr.cdr.length()));
+#else
+ RTC_PARANOID(("received data size: %d", cdr.bufSize()));
+#endif
+
+ }
+ catch (...)
+ {
+
+ }
+
+ onReceived(cdr);
+
+ BufferStatus::Enum ret = m_buffer->write(cdr);
+
+ return convertReturn(ret, cdr);
+ }
+
+ /*!
+ * @if jp
+ * @brief リターンコード変換
+ * @else
+ * @brief Return codes conversion
+ * @endif
+ */
+ ::OpenRTM::PortStatus
+ InPortSHMProvider::convertReturn(BufferStatus::Enum status,
+ const cdrMemoryStream& data)
+ {
+ switch(status)
+ {
+ case BufferStatus::BUFFER_OK:
+ onBufferWrite(data);
+ return ::OpenRTM::PORT_OK;
+ break;
+
+ case BufferStatus::BUFFER_ERROR:
+ onReceiverError(data);
+ return ::OpenRTM::PORT_ERROR;
+ break;
+
+ case BufferStatus::BUFFER_FULL:
+ onBufferFull(data);
+ onReceiverFull(data);
+ return ::OpenRTM::BUFFER_FULL;
+ break;
+
+ case BufferStatus::BUFFER_EMPTY:
+ // never come here
+ return ::OpenRTM::BUFFER_EMPTY;
+ break;
+
+ case BufferStatus::PRECONDITION_NOT_MET:
+ onReceiverError(data);
+ return ::OpenRTM::PORT_ERROR;
+ break;
+
+ case BufferStatus::TIMEOUT:
+ onBufferWriteTimeout(data);
+ onReceiverTimeout(data);
+ return ::OpenRTM::BUFFER_TIMEOUT;
+ break;
+
+ default:
+ return ::OpenRTM::UNKNOWN_ERROR;
+ }
+
+ onReceiverError(data);
+ return ::OpenRTM::UNKNOWN_ERROR;
+ }
+
+}; // namespace RTC
+
+
+extern "C"
+{
+ /*!
+ * @if jp
+ * @brief モジュール初期化関数
+ * @else
+ * @brief Module initialization
+ * @endif
+ */
+ void InPortSHMProviderInit(void)
+ {
+ RTC::InPortProviderFactory& factory(RTC::InPortProviderFactory::instance());
+ factory.addFactory("shared_memory",
+ ::coil::Creator< ::RTC::InPortProvider,
+ ::RTC::InPortSHMProvider>,
+ ::coil::Destructor< ::RTC::InPortProvider,
+ ::RTC::InPortSHMProvider>);
+ }
+};
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMProvider.h (from rev 3056, trunk/OpenRTM-aist/src/lib/rtm/InPortSHMProvider.h)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMProvider.h (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/InPortSHMProvider.h 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,275 @@
+// -*- C++ -*-
+/*!
+ * @file InPortSHMProvider.h
+ * @brief InPortSHMProvider class
+ * @date $Date: 2017-10-30 07:49:59 $
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ *
+ */
+
+#ifndef RTC_INPORTSHMPROVIDER_H
+#define RTC_INPORTSHMPROVIDER_H
+
+#include <rtm/SharedMemoryPort.h>
+#include <rtm/BufferBase.h>
+#include <rtm/InPortProvider.h>
+#include <rtm/CORBA_SeqUtil.h>
+#include <rtm/Manager.h>
+#include <rtm/ConnectorListener.h>
+#include <rtm/ConnectorBase.h>
+
+#ifdef WIN32
+#pragma warning( disable : 4290 )
+#endif
+
+namespace RTC
+{
+ /*!
+ * @if jp
+ * @class InPortSHMProvider
+ * @brief InPortSHMProvider クラス
+ *
+ * InPortProvider
+ *
+ * 通信手段に 共有メモリ を利用した入力ポートプロバイダーの実装クラス。
+ *
+ * @since 1.2.0
+ *
+ * @else
+ * @class InPortSHMProvider
+ * @brief InPortSHMProvider class
+ *
+ *
+ *
+ * @since 1.2.0
+ *
+ * @endif
+ */
+ class InPortSHMProvider
+ : public InPortProvider,
+ public virtual SharedMemoryPort
+ {
+ public:
+ /*!
+ * @if jp
+ * @brief コンストラクタ
+ *
+ * コンストラクタ
+ *
+ * @else
+ * @brief Constructor
+ *
+ * Constructor
+ *
+ * @endif
+ */
+ InPortSHMProvider();
+
+ /*!
+ * @if jp
+ * @brief デストラクタ
+ *
+ * デストラクタ
+ *
+ * @else
+ * @brief Destructor
+ *
+ * Destructor
+ *
+ * @endif
+ */
+ virtual ~InPortSHMProvider();
+
+ /*!
+ * @if jp
+ * @brief 設定初期化
+ *
+ *
+ *
+ * @param prop 設定情報
+ *
+ * @else
+ *
+ * @brief Initializing configuration
+ *
+ *
+ *
+ * @endif
+ */
+ virtual void init(coil::Properties& prop);
+
+ /*!
+ * @if jp
+ * @brief バッファをセットする
+ *
+ *
+ *
+ * @param buffer OutPortProviderがデータを取り出すバッファへのポインタ
+ *
+ * @else
+ * @brief Setting outside buffer's pointer
+ *
+ *
+ *
+ * @endif
+ */
+ virtual void setBuffer(BufferBase<cdrMemoryStream>* buffer);
+
+ /*!
+ * @if jp
+ * @brief リスナを設定する。
+ *
+ *
+ *
+ * @param info 接続情報
+ * @param listeners リスナオブジェクト
+ *
+ * @else
+ * @brief Set the listener.
+ *
+ *
+ *
+ *
+ * @param info Connector information
+ * @param listeners Listener objects
+ *
+ * @endif
+ */
+ virtual void setListener(ConnectorInfo& info,
+ ConnectorListeners* listeners);
+ /*!
+ * @if jp
+ * @brief Connectorを設定する。
+ *
+ *
+ *
+ * @param connector OutPortConnector
+ *
+ * @else
+ * @brief set Connector
+ *
+ *
+ *
+ * @param connector OutPortConnector
+ *
+ * @endif
+ */
+ virtual void setConnector(InPortConnector* connector);
+
+ /*!
+ * @if jp
+ * @brief [CORBA interface] バッファにデータを書き込む
+ *
+ * 設定されたバッファにデータを書き込む。
+ *
+ * @param data 書込対象データ
+ *
+ * @else
+ * @brief [CORBA interface] Write data into the buffer
+ *
+ * Write data into the specified buffer.
+ *
+ * @param data The target data for writing
+ *
+ * @endif
+ */
+ virtual ::OpenRTM::PortStatus put()
+ throw (CORBA::SystemException);
+
+ private:
+
+ ::OpenRTM::PortStatus
+ convertReturn(BufferStatus::Enum status,
+ const cdrMemoryStream& data);
+
+
+ inline void onBufferWrite(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_BUFFER_WRITE].notify(m_profile, data);
+ }
+
+ inline void onBufferFull(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_BUFFER_FULL].notify(m_profile, data);
+ }
+
+ inline void onBufferWriteTimeout(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_BUFFER_WRITE_TIMEOUT].notify(m_profile, data);
+ }
+
+ inline void onBufferWriteOverwrite(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_BUFFER_OVERWRITE].notify(m_profile, data);
+ }
+
+ inline void onReceived(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_RECEIVED].notify(m_profile, data);
+ }
+
+ inline void onReceiverFull(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_RECEIVER_FULL].notify(m_profile, data);
+ }
+
+ inline void onReceiverTimeout(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_RECEIVER_TIMEOUT].notify(m_profile, data);
+ }
+
+ inline void onReceiverError(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_RECEIVER_ERROR].notify(m_profile, data);
+ }
+
+ private:
+ CdrBufferBase* m_buffer;
+ ::OpenRTM::PortSharedMemory_var m_objref;
+ ConnectorListeners* m_listeners;
+ ConnectorInfo m_profile;
+ InPortConnector* m_connector;
+
+ }; // class InPortCorCdrbaProvider
+}; // namespace RTC
+
+extern "C"
+{
+ /*!
+ * @if jp
+ * @brief モジュール初期化関数
+ *
+ * InPortSHMProvider のファクトリを登録する初期化関数。
+ *
+ * @else
+ * @brief Module initialization
+ *
+ * This initialization function registers InPortSHMProvider's factory.
+ *
+ * @endif
+ */
+ void InPortSHMProviderInit();
+};
+
+#ifdef WIN32
+#pragma warning( default : 4290 )
+#endif
+
+#endif // RTC_INPORTCORBACDRPROVIDER_H
+
Modified: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/Makefile.am
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/Makefile.am 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/Makefile.am 2017-12-10 06:19:38 UTC (rev 3108)
@@ -116,7 +116,12 @@
OutPortCorbaCdrProvider.cpp \
InPortCorbaCdrConsumer.cpp \
InPortDirectProvider.cpp \
- InPortDirectConsumer.cpp
+ InPortDirectConsumer.cpp \
+ InPortSHMConsumer.cpp \
+ InPortSHMProvider.cpp \
+ OutPortSHMConsumer.cpp \
+ OutPortSHMProvider.cpp \
+ SharedMemoryPort.cpp
RTC_SRC = \
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMConsumer.cpp (from rev 3056, trunk/OpenRTM-aist/src/lib/rtm/OutPortSHMConsumer.cpp)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMConsumer.cpp (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMConsumer.cpp 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,319 @@
+// -*- C++ -*-
+/*!
+ * @file OutPortSHMConsumer.h
+ * @brief OutPortSHMConsumer class
+ * @date $Date: 2017-10-30 07:49:59 $
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ */
+
+#include <rtm/Manager.h>
+#include <rtm/OutPortSHMConsumer.h>
+#include <rtm/NVUtil.h>
+#include <coil/UUID.h>
+#include <coil/Guard.h>
+
+namespace RTC
+{
+ /*!
+ * @if jp
+ * @brief コンストラクタ
+ * @else
+ * @brief Constructor
+ * @endif
+ */
+ OutPortSHMConsumer::OutPortSHMConsumer()
+ {
+ rtclog.setName("OutPortSHMConsumer");
+
+ }
+
+ /*!
+ * @if jp
+ * @brief デストラクタ
+ * @else
+ * @brief Destructor
+ * @endif
+ */
+ OutPortSHMConsumer::~OutPortSHMConsumer()
+ {
+ try
+ {
+ _ptr()->close_memory(true);
+ }
+ catch(...)
+ {
+ }
+ }
+
+ /*!
+ * @if jp
+ * @brief 設定初期化
+ * @else
+ * @brief Initializing configuration
+ * @endif
+ */
+ void OutPortSHMConsumer::init(coil::Properties& prop)
+ {
+ RTC_TRACE(("OutPortSHMConsumer::init()"));
+
+ }
+
+ /*!
+ * @if jp
+ * @brief バッファをセットする
+ * @else
+ * @brief Setting outside buffer's pointer
+ * @endif
+ */
+ void OutPortSHMConsumer::setBuffer(CdrBufferBase* buffer)
+ {
+ RTC_TRACE(("OutPortSHMConsumer::setBuffer()"));
+ m_buffer = buffer;
+ }
+
+ /*!
+ * @if jp
+ * @brief リスナを設定する。
+ * @else
+ * @brief Set the listener.
+ * @endif
+ */
+ void OutPortSHMConsumer::setListener(ConnectorInfo& info,
+ ConnectorListeners* listeners)
+ {
+ RTC_TRACE(("OutPortSHMConsumer::setListener()"));
+ m_listeners = listeners;
+ m_profile = info;
+ }
+
+ bool OutPortSHMConsumer::setObject(CORBA::Object_ptr obj)
+ {
+ RTC_PARANOID(("setObject()"));
+ if (CorbaConsumer< ::OpenRTM::PortSharedMemory >::setObject(obj))
+ {
+ //::OpenRTM::PortSharedMemory_var sm = m_shmem.getObjRef();
+ _ptr()->setInterface(m_shmem._this());
+ return true;
+ }
+
+
+ return false;
+ }
+
+ /*!
+ * @if jp
+ * @brief データを読み出す
+ * @else
+ * @brief Read data
+ * @endif
+ */
+ OutPortConsumer::ReturnCode
+ OutPortSHMConsumer::get(cdrMemoryStream& data)
+ {
+ RTC_TRACE(("OutPortSHMConsumer::get()"));
+
+ try
+ {
+
+ Guard guard(m_mutex);
+
+
+ ::OpenRTM::PortStatus ret(_ptr()->get());
+ if (ret == ::OpenRTM::PORT_OK)
+ {
+ m_shmem.read(data);
+
+ RTC_DEBUG(("get() successful"));
+
+ RTC_PARANOID(("CDR data length: %d", data.bufSize()));
+
+ onReceived(data);
+ onBufferWrite(data);
+
+ if (m_buffer->full())
+ {
+ RTC_INFO(("InPort buffer is full."));
+ onBufferFull(data);
+ onReceiverFull(data);
+ }
+ m_buffer->put(data);
+ m_buffer->advanceWptr();
+ m_buffer->advanceRptr();
+
+ return PORT_OK;
+ }
+
+ return convertReturn(ret, data);
+ }
+ catch (...)
+ {
+ RTC_WARN(("Exception caought from OutPort::get()."));
+ return CONNECTION_LOST;
+ }
+ RTC_ERROR(("OutPortSHMConsumer::get(): Never comes here."));
+ return UNKNOWN_ERROR;
+ }
+
+ /*!
+ * @if jp
+ * @brief データ受信通知への登録
+ * @else
+ * @brief Subscribe the data receive notification
+ * @endif
+ */
+ bool OutPortSHMConsumer::
+ subscribeInterface(const SDOPackage::NVList& properties)
+ {
+ RTC_TRACE(("OutPortSHMConsumer::subscribeInterface()"));
+ CORBA::Long index;
+ index = NVUtil::find_index(properties,
+ "dataport.corba_cdr.outport_ior");
+ if (index < 0)
+ {
+ RTC_DEBUG(("dataport.corba_cdr.outport_ior not found."));
+ return false;
+ }
+
+ if (NVUtil::isString(properties,
+ "dataport.corba_cdr.outport_ior"))
+ {
+ RTC_DEBUG(("dataport.corba_cdr.outport_ior found."));
+ const char* ior;
+ properties[index].value >>= ior;
+
+ CORBA::ORB_var orb = ::RTC::Manager::instance().getORB();
+ CORBA::Object_var var = orb->string_to_object(ior);
+ bool ret(setObject(var.in()));
+ if (ret)
+ {
+ RTC_DEBUG(("CorbaConsumer was set successfully."));
+ }
+ else
+ {
+ RTC_ERROR(("Invalid object reference."))
+ }
+ return ret;
+ }
+
+ return false;
+ }
+
+ /*!
+ * @if jp
+ * @brief データ受信通知からの登録解除
+ * @else
+ * @brief Unsubscribe the data receive notification
+ * @endif
+ */
+ void OutPortSHMConsumer::
+ unsubscribeInterface(const SDOPackage::NVList& properties)
+ {
+ RTC_TRACE(("OutPortSHMConsumer::unsubscribeInterface()"));
+ CORBA::Long index;
+ index = NVUtil::find_index(properties,
+ "dataport.corba_cdr.outport_ior");
+ if (index < 0)
+ {
+ RTC_DEBUG(("dataport.corba_cdr.outport_ior not found."));
+ return;
+ }
+
+ const char* ior;
+ if (properties[index].value >>= ior)
+ {
+ RTC_DEBUG(("dataport.corba_cdr.outport_ior found."));
+ CORBA::ORB_var orb = ::RTC::Manager::instance().getORB();
+ CORBA::Object_var var = orb->string_to_object(ior);
+ if (_ptr()->_is_equivalent(var))
+ {
+ releaseObject();
+ RTC_DEBUG(("CorbaConsumer's reference was released."));
+ return;
+ }
+ RTC_ERROR(("hmm. Inconsistent object reference."));
+ }
+ }
+
+ /*!
+ * @if jp
+ * @brief リターンコード変換 (DataPortStatus -> BufferStatus)
+ * @else
+ * @brief Return codes conversion
+ * @endif
+ */
+ OutPortConsumer::ReturnCode
+ OutPortSHMConsumer::convertReturn(::OpenRTM::PortStatus status,
+ const cdrMemoryStream& data)
+ {
+ switch(status)
+ {
+ case ::OpenRTM::PORT_OK:
+ // never comes here
+ return PORT_OK;
+ break;
+
+ case ::OpenRTM::PORT_ERROR:
+ onSenderError();
+ return PORT_ERROR;
+ break;
+
+ case ::OpenRTM::BUFFER_FULL:
+ // never comes here
+ return BUFFER_FULL;
+ break;
+
+ case ::OpenRTM::BUFFER_EMPTY:
+ onSenderEmpty();
+ return BUFFER_EMPTY;
+ break;
+
+ case ::OpenRTM::BUFFER_TIMEOUT:
+ onSenderTimeout();
+ return BUFFER_TIMEOUT;
+ break;
+
+ case ::OpenRTM::UNKNOWN_ERROR:
+ onSenderError();
+ return UNKNOWN_ERROR;
+ break;
+
+ default:
+ onSenderError();
+ return UNKNOWN_ERROR;
+ }
+
+ onSenderError();
+ return UNKNOWN_ERROR;
+ }
+
+
+}; // namespace RTC
+
+extern "C"
+{
+ /*!
+ * @if jp
+ * @brief モジュール初期化関数
+ * @else
+ * @brief Module initialization
+ * @endif
+ */
+ void OutPortSHMConsumerInit(void)
+ {
+ RTC::OutPortConsumerFactory&
+ factory(RTC::OutPortConsumerFactory::instance());
+ factory.addFactory("shared_memory",
+ ::coil::Creator< ::RTC::OutPortConsumer,
+ ::RTC::OutPortSHMConsumer>,
+ ::coil::Destructor< ::RTC::OutPortConsumer,
+ ::RTC::OutPortSHMConsumer>);
+ }
+};
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMConsumer.h (from rev 3056, trunk/OpenRTM-aist/src/lib/rtm/OutPortSHMConsumer.h)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMConsumer.h (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMConsumer.h 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,360 @@
+// -*- C++ -*-
+/*!
+ * @file OutPortSHMConsumer.h
+ * @brief OutPortSHMConsumer class
+ * @date $Date: 2017-10-30 07:49:59 $
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef RTC_OUTPORTSHMCONSUMER_H
+#define RTC_OUTPORTSHMCONSUMER_H
+
+#include <rtm/SharedMemoryPort.h>
+#include <rtm/CorbaConsumer.h>
+#include <rtm/OutPortConsumer.h>
+#include <rtm/ConnectorListener.h>
+#include <rtm/ConnectorBase.h>
+
+namespace RTC
+{
+ /*!
+ * @if jp
+ * @class OutPortSHMConsumer
+ * @brief OutPortSHMConsumer クラス
+ *
+ * OutPortConsumer
+ *
+ * 通信手段に 共有メモリ を利用した出力ポートプロバイダーの実装クラス。
+ *
+ * @since 0.4.0
+ *
+ * @else
+ * @class OutPortSHMConsumer
+ * @brief OutPortSHMConsumer class
+ *
+ *
+ *
+ * @since 0.4.0
+ *
+ * @endif
+ */
+ class OutPortSHMConsumer
+ : public OutPortConsumer,
+ public CorbaConsumer< ::OpenRTM::PortSharedMemory >
+ {
+ typedef coil::Guard<coil::Mutex> Guard;
+ public:
+ DATAPORTSTATUS_ENUM
+
+ /*!
+ * @if jp
+ * @brief コンストラクタ
+ *
+ * コンストラクタ
+ *
+ * @else
+ * @brief Constructor
+ *
+ * Constructor
+ *
+ * @endif
+ */
+ OutPortSHMConsumer();
+
+ /*!
+ * @if jp
+ * @brief デストラクタ
+ *
+ * デストラクタ
+ *
+ * @else
+ * @brief Destructor
+ *
+ * Destructor
+ *
+ * @endif
+ */
+ virtual ~OutPortSHMConsumer();
+
+ /*!
+ * @if jp
+ * @brief 設定初期化
+ *
+ *
+ *
+ * @param prop 設定情報
+ *
+ * @else
+ *
+ * @brief Initializing configuration
+ *
+ *
+ *
+ * @param prop Configuration information
+ *
+ * @endif
+ */
+ virtual void init(coil::Properties& prop);
+
+ /*!
+ * @if jp
+ * @brief バッファをセットする
+ *
+ *
+ *
+ * @param buffer OutPortProviderがデータを取り出すバッファへのポインタ
+ *
+ * @else
+ * @brief Setting outside buffer's pointer
+ *
+ *
+ *
+ * @param buffer A pointer to a data buffer to be used by OutPortProvider
+ *
+ * @endif
+ */
+ virtual void setBuffer(CdrBufferBase* buffer);
+
+ /*!
+ * @if jp
+ * @brief リスナを設定する。
+ *
+ *
+ *
+ * @param info 接続情報
+ * @param listeners リスナオブジェクト
+ *
+ * @else
+ * @brief Set the listener.
+ *
+ *
+ *
+ * @param info Connector information
+ * @param listeners Listener objects
+ *
+ * @endif
+ */
+ virtual void setListener(ConnectorInfo& info,
+ ConnectorListeners* listeners);
+
+ /*!
+ * @if jp
+ * @brief データを読み出す
+ *
+ * 設定されたデータを読み出す。
+ *
+ * @param data 読み出したデータを受け取るオブジェクト
+ *
+ * @return データ読み出し処理結果(読み出し成功:true、読み出し失敗:false)
+ *
+ * @else
+ * @brief Read data
+ *
+ * Read set data
+ *
+ * @param data Object to receive the read data
+ *
+ * @return Read result (Successful:true, Failed:false)
+ *
+ * @endif
+ */
+ virtual ReturnCode get(cdrMemoryStream& data);
+
+ /*!
+ * @if jp
+ * @brief データ受信通知への登録
+ *
+ * 指定されたプロパティに基づいて、データ受信通知の受け取りに登録する。
+ *
+ * @param properties 登録情報
+ *
+ * @return 登録処理結果(登録成功:true、登録失敗:false)
+ *
+ * @else
+ * @brief Subscribe the data receive notification
+ *
+ * Subscribe the data receive notification based on specified property
+ * information
+ *
+ * @param properties Subscription information
+ *
+ * @return Subscription result (Successful:true, Failed:false)
+ *
+ * @endif
+ */
+ virtual bool subscribeInterface(const SDOPackage::NVList& properties);
+
+ /*!
+ * @if jp
+ * @brief データ受信通知からの登録解除
+ *
+ * データ受信通知の受け取りから登録を解除する。
+ *
+ * @param properties 登録解除情報
+ *
+ * @else
+ * @brief Unsubscribe the data receive notification
+ *
+ * Unsubscribe the data receive notification.
+ *
+ * @param properties Unsubscription information
+ *
+ * @endif
+ */
+ virtual void unsubscribeInterface(const SDOPackage::NVList& properties);
+ virtual bool setObject(CORBA::Object_ptr obj);
+
+ private:
+ /*!
+ * @if jp
+ * @brief リターンコード変換 (DataPortStatus -> BufferStatus)
+ * @else
+ * @brief Return codes conversion
+ * @endif
+ */
+ OutPortConsumer::ReturnCode convertReturn(::OpenRTM::PortStatus status,
+ const cdrMemoryStream& data);
+
+ /*!
+ * @if jp
+ * @brief ON_BUFFER_WRITE のリスナへ通知する。
+ * @param data cdrMemoryStream
+ * @else
+ * @brief Notify an ON_BUFFER_WRITE event to listeners
+ * @param data cdrMemoryStream
+ * @endif
+ */
+ inline void onBufferWrite(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_BUFFER_WRITE].notify(m_profile, data);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_BUFFER_FULL のリスナへ通知する。
+ * @param data cdrMemoryStream
+ * @else
+ * @brief Notify an ON_BUFFER_FULL event to listeners
+ * @param data cdrMemoryStream
+ * @endif
+ */
+ inline void onBufferFull(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_BUFFER_FULL].notify(m_profile, data);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_RECEIVED のリスナへ通知する。
+ * @param data cdrMemoryStream
+ * @else
+ * @brief Notify an ON_RECEIVED event to listeners
+ * @param data cdrMemoryStream
+ * @endif
+ */
+ inline void onReceived(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_RECEIVED].notify(m_profile, data);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_RECEIVER_FULL のリスナへ通知する。
+ * @param data cdrMemoryStream
+ * @else
+ * @brief Notify an ON_RECEIVER_FULL event to listeners
+ * @param data cdrMemoryStream
+ * @endif
+ */
+ inline void onReceiverFull(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_RECEIVER_FULL].notify(m_profile, data);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_SENDER_EMPTYのリスナへ通知する。
+ * @else
+ * @brief Notify an ON_SENDER_EMPTY event to listeners
+ * @endif
+ */
+ inline void onSenderEmpty()
+ {
+ m_listeners->
+ connector_[ON_SENDER_EMPTY].notify(m_profile);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_SENDER_TIMEOUT のリスナへ通知する。
+ * @else
+ * @brief Notify an ON_SENDER_TIMEOUT event to listeners
+ * @endif
+ */
+ inline void onSenderTimeout()
+ {
+ m_listeners->
+ connector_[ON_SENDER_TIMEOUT].notify(m_profile);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_SENDER_ERRORのリスナへ通知する。
+ * @else
+ * @Brief Notify an ON_SENDER_ERROR event to listeners
+ * @endif
+ */
+ inline void onSenderError()
+ {
+ m_listeners->
+ connector_[ON_SENDER_ERROR].notify(m_profile);
+ }
+protected:
+ // RTC::OutPortCdr_var m_outport;
+ mutable Logger rtclog;
+ coil::Properties m_properties;
+ coil::Mutex m_mutex;
+ std::string m_shm_address;
+ SharedMemoryPort m_shmem;
+ int m_memory_size;
+ bool m_endian;
+
+ CdrBufferBase* m_buffer;
+ ConnectorListeners* m_listeners;
+ ConnectorInfo m_profile;
+ };
+}; // namespace RTC
+
+extern "C"
+{
+ /*!
+ * @if jp
+ * @brief モジュール初期化関数
+ *
+ * OutPortSHMConsumer のファクトリを登録する初期化関数。
+ *
+ * @else
+ * @brief Module initialization
+ *
+ * This initialization function registers OutPortSHMConsumer's factory.
+ *
+ * @endif
+ */
+ void OutPortSHMConsumerInit(void);
+};
+
+#endif // RTC_OUTPORTSHMCONSUMER_H
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMProvider.cpp (from rev 3056, trunk/OpenRTM-aist/src/lib/rtm/OutPortSHMProvider.cpp)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMProvider.cpp (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMProvider.cpp 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,273 @@
+// -*- C++ -*-
+/*!
+ * @file OutPortSHMProvider.cpp
+ * @brief OutPortSHMProvider class
+ * @date $Date: 2017-10-30 07:49:59 $
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ */
+
+#include <rtm/OutPortSHMProvider.h>
+#include <coil/UUID.h>
+#include <memory>
+
+#ifdef WIN32
+#pragma warning( disable : 4290 )
+#endif
+
+namespace RTC
+{
+ /*!
+ * @if jp
+ * @brief コンストラクタ
+ * @else
+ * @brief Constructor
+ * @endif
+ */
+ OutPortSHMProvider::OutPortSHMProvider(void)
+ : m_buffer(0)
+ {
+ // PortProfile setting
+ setInterfaceType("shared_memory");
+
+ // ConnectorProfile setting
+#ifdef ORB_IS_OMNIORB
+ ::RTC::Manager::instance().theShortCutPOA()->activate_object(this);
+#endif
+ m_objref = this->_this();
+
+ // set outPort's reference
+ CORBA::ORB_var orb = ::RTC::Manager::instance().getORB();
+ CORBA::String_var ior = orb->object_to_string(m_objref.in());
+#ifndef ORB_IS_RTORB
+ CORBA_SeqUtil::
+ push_back(m_properties,
+ NVUtil::newNV("dataport.corba_cdr.outport_ior", ior));
+#else // ORB_IS_RTORB
+ CORBA_SeqUtil::
+ push_back(m_properties,
+ NVUtil::newNV("dataport.corba_cdr.outport_ior", ior.in()));
+#endif // ORB_IS_RTORB
+ CORBA_SeqUtil::
+ push_back(m_properties,
+ NVUtil::newNV("dataport.corba_cdr.outport_ref", m_objref));
+
+ coil::UUID_Generator uugen;
+ uugen.init();
+ std::auto_ptr<coil::UUID> uuid(uugen.generateUUID(2, 0x01));
+ m_shm_address = uuid->to_string();
+ }
+
+ /*!
+ * @if jp
+ * @brief デストラクタ
+ * @else
+ * @brief Destructor
+ * @endif
+ */
+ OutPortSHMProvider::~OutPortSHMProvider(void)
+ {
+
+ }
+
+ /*!
+ * @if jp
+ * @brief 設定初期化
+ * @else
+ * @brief Initializing configuration
+ * @endif
+ */
+ void OutPortSHMProvider::init(coil::Properties& prop)
+ {
+ std::string ds = prop["shem_default_size"];
+ m_memory_size = string_to_MemorySize(ds);
+
+ if (prop.hasKey("serializer") == NULL)
+ {
+ m_endian = true;
+ return;
+ }
+
+
+ std::string endian_type(prop.getProperty("serializer.cdr.endian", ""));
+ coil::normalize(endian_type);
+ std::vector<std::string> endian(coil::split(endian_type, ","));
+ if (endian.empty()) { return; }
+ if (endian[0] == "little")
+ {
+ m_endian = true;
+ }
+ else if (endian[0] == "big")
+ {
+ m_endian = false;
+ return;
+ }
+ }
+
+ /*!
+ * @if jp
+ * @brief バッファをセットする
+ * @else
+ * @brief Setting outside buffer's pointer
+ * @endif
+ */
+ void OutPortSHMProvider::setBuffer(CdrBufferBase* buffer)
+ {
+ m_buffer = buffer;
+ }
+
+ /*!
+ * @if jp
+ * @brief リスナを設定する。
+ * @else
+ * @brief Set the listener.
+ * @endif
+ */
+ void OutPortSHMProvider::setListener(ConnectorInfo& info,
+ ConnectorListeners* listeners)
+ {
+ m_profile = info;
+ m_listeners = listeners;
+ }
+
+ /*!
+ * @if jp
+ * @brief コネクタをセットする
+ * @else
+ * @brief Setting outside connector's pointer
+ * @endif
+ */
+ void OutPortSHMProvider::setConnector(OutPortConnector* connector)
+ {
+ m_connector = connector;
+ }
+
+ /*!
+ * @if jp
+ * @brief [CORBA interface] バッファからデータを取得する
+ * @else
+ * @brief [CORBA interface] Get data from the buffer
+ * @endif
+ */
+ ::OpenRTM::PortStatus
+ OutPortSHMProvider::get()
+ throw (CORBA::SystemException)
+ {
+ RTC_PARANOID(("OutPortSHMProvider::get()"));
+ // at least the output "data" area should be allocated
+
+
+ if (m_buffer == 0)
+ {
+ onSenderError();
+ return ::OpenRTM::UNKNOWN_ERROR;
+ }
+
+ cdrMemoryStream cdr;
+ CdrBufferBase::ReturnCode ret(m_buffer->read(cdr));
+ if (ret == CdrBufferBase::BUFFER_OK)
+ {
+#ifdef ORB_IS_ORBEXPRESS
+ CORBA::ULong len((CORBA::ULong)cdr.cdr.size_written());
+#elif defined(ORB_IS_TAO)
+ CORBA::ULong len((CORBA::ULong)cdr.cdr.length());
+#else
+ CORBA::ULong len((CORBA::ULong)cdr.bufSize());
+#endif
+ RTC_PARANOID(("converted CDR data size: %d", len));
+ if (len == (CORBA::ULong)0) {
+ RTC_ERROR(("buffer is empty."));
+ return ::OpenRTM::BUFFER_EMPTY;
+ }
+ bool endian_type = m_connector->isLittleEndian();
+ setEndian(endian_type);
+ create_memory(m_memory_size, m_shm_address.c_str());
+ write(cdr);
+ }
+
+ return convertReturn(ret, cdr);
+ }
+
+ /*!
+ * @if jp
+ * @brief リターンコード変換
+ * @else
+ * @brief Return codes conversion
+ * @endif
+ */
+ ::OpenRTM::PortStatus
+ OutPortSHMProvider::convertReturn(BufferStatus::Enum status,
+ const cdrMemoryStream& data)
+ {
+ switch(status)
+ {
+ case BufferStatus::BUFFER_OK:
+ onBufferRead(data);
+ onSend(data);
+ return ::OpenRTM::PORT_OK;
+ break;
+
+ case BufferStatus::BUFFER_ERROR:
+ onSenderError();
+ return ::OpenRTM::PORT_ERROR;
+ break;
+
+ case BufferStatus::BUFFER_FULL:
+ // never come here
+ return ::OpenRTM::BUFFER_FULL;
+ break;
+
+ case BufferStatus::BUFFER_EMPTY:
+ onBufferEmpty();
+ onSenderEmpty();
+ return ::OpenRTM::BUFFER_EMPTY;
+ break;
+
+ case BufferStatus::PRECONDITION_NOT_MET:
+ onSenderError();
+ return ::OpenRTM::PORT_ERROR;
+ break;
+
+ case BufferStatus::TIMEOUT:
+ onBufferReadTimeout();
+ onSenderTimeout();
+ return ::OpenRTM::BUFFER_TIMEOUT;
+ break;
+
+ default:
+ return ::OpenRTM::UNKNOWN_ERROR;
+ }
+
+ onSenderError();
+ return ::OpenRTM::UNKNOWN_ERROR;
+ }
+
+}; // namespace RTC
+
+extern "C"
+{
+ /*!
+ * @if jp
+ * @brief モジュール初期化関数
+ * @else
+ * @brief Module initialization
+ * @endif
+ */
+ void OutPortSHMProviderInit(void)
+ {
+ RTC::OutPortProviderFactory&
+ factory(RTC::OutPortProviderFactory::instance());
+ factory.addFactory("shared_memory",
+ ::coil::Creator< ::RTC::OutPortProvider,
+ ::RTC::OutPortSHMProvider>,
+ ::coil::Destructor< ::RTC::OutPortProvider,
+ ::RTC::OutPortSHMProvider>);
+ }
+};
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMProvider.h (from rev 3056, trunk/OpenRTM-aist/src/lib/rtm/OutPortSHMProvider.h)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMProvider.h (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/OutPortSHMProvider.h 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,331 @@
+// -*- C++ -*-
+/*!
+ * @file OutPortSHMProvider.h
+ * @brief OutPortSHMProvider class
+ * @date $Date: 2017-10-30 07:49:59 $
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2017 Nobuhiko Miyamoto
+ * Robot Innovation Research Center,
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ */
+
+#ifndef RTC_OUTPORTSHMPROVIDER_H
+#define RTC_OUTPORTSHMPROVIDER_H
+
+#include <rtm/SharedMemoryPort.h>
+#include <rtm/BufferBase.h>
+#include <rtm/OutPortProvider.h>
+#include <rtm/CORBA_SeqUtil.h>
+#include <rtm/Manager.h>
+#include <rtm/ConnectorListener.h>
+#include <rtm/ConnectorBase.h>
+
+#ifdef WIN32
+#pragma warning( disable : 4290 )
+#endif
+
+namespace RTC
+{
+ /*!
+ * @if jp
+ * @class OutPortSHMProvider
+ * @brief OutPortSHMProvider クラス
+ *
+ * OutPortProvider
+ *
+ * 通信手段に 共有メモリ を利用した出力ポートプロバイダの実装クラス。
+ *
+ * @since 1.2.0
+ *
+ * @else
+ * @class OutPortSHMProvider
+ * @brief OutPortSHMProvider class
+ *
+ *
+ *
+ * @since 1.2.0
+ *
+ * @endif
+ */
+ class OutPortSHMProvider
+ : public OutPortProvider,
+ public virtual SharedMemoryPort
+ {
+ public:
+ /*!
+ * @if jp
+ * @brief コンストラクタ
+ *
+ * コンストラクタ
+ *
+ * @else
+ * @brief Constructor
+ *
+ * Constructor
+ *
+ * @endif
+ */
+ OutPortSHMProvider();
+
+ /*!
+ * @if jp
+ * @brief デストラクタ
+ *
+ * デストラクタ
+ *
+ * @else
+ * @brief Destructor
+ *
+ * Destructor
+ *
+ * @endif
+ */
+ virtual ~OutPortSHMProvider();
+
+ /*!
+ * @if jp
+ * @brief 設定初期化
+ *
+ *
+ *
+ * @param prop 設定情報
+ *
+ * @else
+ *
+ * @brief Initializing configuration
+ *
+ *
+ *
+ * @param prop Configuration information
+ *
+ * @endif
+ */
+ virtual void init(coil::Properties& prop);
+
+ /*!
+ * @if jp
+ * @brief バッファをセットする
+ *
+ *
+ *
+ * @param buffer OutPortProviderがデータを取り出すバッファへのポインタ
+ *
+ * @else
+ * @brief Setting outside buffer's pointer
+ *
+ *
+ *
+ * @param buffer A pointer to a data buffer to be used by OutPortProvider
+ *
+ * @endif
+ */
+ virtual void setBuffer(CdrBufferBase* buffer);
+
+ /*!
+ * @if jp
+ * @brief リスナを設定する。
+ *
+ *
+ *
+ * @param info 接続情報
+ * @param listeners リスナオブジェクト
+ *
+ * @else
+ * @brief Set the listener.
+ *
+ *
+ *
+ * @param info Connector information
+ * @param listeners Listener objects
+ *
+ * @endif
+ */
+ virtual void setListener(ConnectorInfo& info,
+ ConnectorListeners* listeners);
+
+ /*!
+ * @if jp
+ * @brief Connectorを設定する。
+ *
+ *
+ *
+ * @param connector OutPortConnector
+ *
+ * @else
+ * @brief set Connector
+ *
+ *
+ *
+ * @param connector OutPortConnector
+ *
+ * @endif
+ */
+ virtual void setConnector(OutPortConnector* connector);
+
+ /*!
+ * @if jp
+ * @brief [CORBA interface] バッファからデータを取得する
+ *
+ * 設定された内部バッファからデータを取得する。
+ *
+ * @return 取得データ
+ *
+ * @else
+ * @brief [CORBA interface] Get data from the buffer
+ *
+ * Get data from the internal buffer.
+ *
+ * @return Data got from the buffer.
+ *
+ * @endif
+ */
+ virtual ::OpenRTM::PortStatus get()
+ throw (CORBA::SystemException);
+
+
+ private:
+ /*!
+ * @if jp
+ * @brief リターンコード変換
+ * @else
+ * @brief Return codes conversion
+ * @endif
+ */
+ ::OpenRTM::PortStatus convertReturn(BufferStatus::Enum status,
+ const cdrMemoryStream& data);
+
+
+ /*!
+ * @if jp
+ * @brief ON_BUFFER_READ のリスナへ通知する。
+ * @param data cdrMemoryStream
+ * @else
+ * @brief Notify an ON_BUFFER_READ event to listeners
+ * @param data cdrMemoryStream
+ * @endif
+ */
+ inline void onBufferRead(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_BUFFER_READ].notify(m_profile, data);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_SEND のリスナへ通知する。
+ * @param data cdrMemoryStream
+ * @else
+ * @brief Notify an ON_SEND event to listeners
+ * @param data cdrMemoryStream
+ * @endif
+ */
+ inline void onSend(const cdrMemoryStream& data)
+ {
+ m_listeners->
+ connectorData_[ON_SEND].notify(m_profile, data);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_BUFFER_EMPTYのリスナへ通知する。
+ * @else
+ * @brief Notify an ON_BUFFER_EMPTY event to listeners
+ * @endif
+ */
+ inline void onBufferEmpty()
+ {
+ m_listeners->
+ connector_[ON_BUFFER_EMPTY].notify(m_profile);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_BUFFER_READ_TIMEOUT のリスナへ通知する。
+ * @else
+ * @brief Notify an ON_BUFFER_READ_TIMEOUT event to listeners
+ * @endif
+ */
+ inline void onBufferReadTimeout()
+ {
+ m_listeners->
+ connector_[ON_BUFFER_READ_TIMEOUT].notify(m_profile);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_SENDER_EMPTYのリスナへ通知する。
+ * @else
+ * @brief Notify an ON_SENDER_EMPTY event to listeners
+ * @endif
+ */
+ inline void onSenderEmpty()
+ {
+ m_listeners->
+ connector_[ON_SENDER_EMPTY].notify(m_profile);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_SENDER_TIMEOUT のリスナへ通知する。
+ * @else
+ * @brief Notify an ON_SENDER_TIMEOUT event to listeners
+ * @endif
+ */
+ inline void onSenderTimeout()
+ {
+ m_listeners->
+ connector_[ON_SENDER_TIMEOUT].notify(m_profile);
+ }
+
+ /*!
+ * @if jp
+ * @brief ON_SENDER_ERRORのリスナへ通知する。
+ * @else
+ * @brief Notify an ON_SENDER_ERROR event to listeners
+ * @endif
+ */
+ inline void onSenderError()
+ {
+ m_listeners->
+ connector_[ON_SENDER_ERROR].notify(m_profile);
+ }
+
+ private:
+ CdrBufferBase* m_buffer;
+ ::OpenRTM::PortSharedMemory_var m_objref;
+ ConnectorListeners* m_listeners;
+ ConnectorInfo m_profile;
+ OutPortConnector* m_connector;
+ std::string m_shm_address;
+ int m_memory_size;
+ }; // class OutPortCorbaCdrProvider
+}; // namespace RTC
+
+extern "C"
+{
+ /*!
+ * @if jp
+ * @brief モジュール初期化関数
+ *
+ * OutPortSHMProvider のファクトリを登録する初期化関数。
+ *
+ * @else
+ * @brief Module initialization
+ *
+ * This initialization function registers OutPortSHMProvider's factory.
+ *
+ * @endif
+ */
+ void OutPortSHMProviderInit(void);
+};
+
+#ifdef WIN32
+#pragma warning( default : 4290 )
+#endif
+
+#endif // RTC_OUTPORTSHMPROVIDER_H
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/SharedMemoryPort.cpp (from rev 3056, trunk/OpenRTM-aist/src/lib/rtm/SharedMemoryPort.cpp)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/SharedMemoryPort.cpp (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/SharedMemoryPort.cpp 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,449 @@
+// -*- C++ -*-
+/*!
+ * @file SharedMemoryPort.cpp
+ * @brief SharedMemoryPort class
+ * @date $Date: 2017-10-29 07:57:18 $
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2009-2010
+ * Noriaki Ando
+ * Robot Innovation Research Center,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ *
+ */
+
+#include <rtm/SharedMemoryPort.h>
+#include <rtm/Manager.h>
+
+#ifdef WIN32
+#pragma warning( disable : 4290 )
+#endif
+
+namespace RTC
+{
+ /*!
+ * @if jp
+ * @brief コンストラクタ
+ * @else
+ * @brief Constructor
+ * @endif
+ */
+ SharedMemoryPort::SharedMemoryPort()
+ : m_smInterface(OpenRTM::PortSharedMemory::_nil()),
+ m_endian(true)//,
+ //rtclog("SharedMemoryPort")
+ {
+
+ }
+
+ /*!
+ * @if jp
+ * @brief デストラクタ
+ * @else
+ * @brief Destructor
+ * @endif
+ */
+ SharedMemoryPort::~SharedMemoryPort()
+ {
+ //RTC_PARANOID(("~SharedMemoryPort()"));
+ try
+ {
+ PortableServer::ObjectId_var oid;
+#ifdef ORB_IS_OMNIORB
+ oid = ::RTC::Manager::instance().theShortCutPOA()->servant_to_id(this);
+ ::RTC::Manager::instance().theShortCutPOA()->deactivate_object(oid);
+#else
+ oid = _default_POA()->servant_to_id(this);
+ _default_POA()->deactivate_object(oid);
+#endif
+ }
+ catch (PortableServer::POA::ServantNotActive &e)
+ {
+#ifdef ORB_IS_ORBEXPRESS
+ oe_out << e << oe_endl << oe_flush;
+#else
+ //RTC_ERROR(("%s", e._name()));
+#endif
+ }
+ catch (PortableServer::POA::WrongPolicy &e)
+ {
+#ifdef ORB_IS_ORBEXPRESS
+ oe_out << e << oe_endl << oe_flush;
+#else
+ //RTC_ERROR(("%s", e._name()));
+#endif
+ }
+ catch (...)
+ {
+ // never throws exception
+ //RTC_ERROR(("Unknown exception caught."));
+ }
+ }
+
+
+
+ /*!
+ * @if jp
+ * @brief 文字列で指定したデータサイズを数値に変換する
+ * 1M → 1048576
+ * 1k → 1024
+ * 100 → 100
+ *
+ * @param size_str データサイズ(文字列)
+ * @return データサイズ(数値)
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param
+ * @return
+ *
+ * @endif
+ */
+ int SharedMemoryPort::string_to_MemorySize(std::string size_str)
+ {
+ int memory_size = DEFAULT_MEMORY_SIZE;
+ std::string size_str_n = coil::normalize(size_str);
+ if (size_str.size() > 0)
+ {
+ std::string unit_str_M = "M";
+ unit_str_M = coil::normalize(unit_str_M);
+ std::string unit_str_k = "k";
+ unit_str_k = coil::normalize(unit_str_k);
+
+ std::string value_str = size_str_n.substr(0, size_str_n.size() - 1);
+ int value = 0;
+ coil::stringTo(value, value_str.c_str());
+
+ if (size_str_n.substr(size_str_n.size() - 1, 1) == unit_str_M)
+ {
+ memory_size = 1048576 * value;
+ }
+ else if (size_str_n.substr(size_str_n.size() - 1, 1) == unit_str_k)
+ {
+
+ memory_size = 1024 * value;
+ }
+ else
+ {
+ memory_size = value;
+ }
+
+ }
+
+ return memory_size;
+ }
+ /*!
+ * @if jp
+ * @brief 共有メモリの初期化
+ * windowsではページングファイル上に領域を確保する
+ * Linuxでは/dev/shm以下にファイルを作成する
+ * 作成したファイルの内容を仮想アドレスにマッピングする
+ *
+ * @param memory_size 共有メモリのサイズ
+ * @param shm_address 空間名
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param memory_size
+ * @param shm_address
+ *
+ * @endif
+ */
+ void SharedMemoryPort::create_memory(::CORBA::ULongLong memory_size, const char *shm_address)
+ throw (CORBA::SystemException)
+ {
+ if (!m_shmem.created())
+ {
+
+ m_shmem.create(shm_address, memory_size);
+ try
+ {
+ m_smInterface->open_memory(memory_size, CORBA::string_dup(shm_address));
+ }
+ catch (...)
+ {
+ }
+ }
+ }
+ /*!
+ * @if jp
+ * @brief 共有メモリのマッピングを行う
+ *
+ * @param memory_size 共有メモリのサイズ
+ * @param shm_address 空間名
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param memory_size
+ * @param shm_address
+ *
+ * @endif
+ */
+ void SharedMemoryPort::open_memory(::CORBA::ULongLong memory_size, const char * shm_address)
+ throw (CORBA::SystemException)
+ {
+
+ m_shmem.open(shm_address, memory_size);
+ }
+ /*!
+ * @if jp
+ * @brief マッピングした共有メモリをアンマップする
+ *
+ * @param unlink Linuxで/dev/shm以下に作成したファイルを削除する場合にTrueにする
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param unlink
+ *
+ * @endif
+ */
+ void SharedMemoryPort::close_memory(::CORBA::Boolean unlink)
+ throw (CORBA::SystemException)
+ {
+ if (!m_shmem.created())
+ {
+ m_shmem.close();
+ if (unlink)
+ {
+ m_shmem.unlink();
+ }
+ try
+ {
+ m_smInterface->close_memory(false);
+ }
+ catch (...)
+ {
+ }
+ }
+ }
+ /*!
+ * @if jp
+ * @brief データを書き込む
+ * 先頭8byteにデータサイズを書き込み、その後ろにデータを書き込む
+ * 設定したデータサイズが共有メモリのサイズを上回った場合、共有メモリの初期化を行う
+ *
+ * @param data
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param data 書き込むデータ
+ *
+ * @endif
+ */
+ void SharedMemoryPort::write(const cdrMemoryStream& data)
+ {
+ CORBA::ULongLong data_size = (CORBA::ULongLong)data.bufSize();
+ if (data_size + sizeof(CORBA::ULongLong) > m_shmem.get_size())
+ {
+ int memory_size = (int)data_size + (int)sizeof(CORBA::ULongLong);
+ if (!CORBA::is_nil(m_smInterface))
+ {
+ try
+ {
+ m_smInterface->close_memory(false);
+ }
+ catch (...)
+ {
+ }
+ }
+ close_memory(true);
+ create_memory(memory_size, m_shmem.get_addresss().c_str());
+ }
+ cdrMemoryStream data_size_cdr;
+
+#ifdef ORB_IS_ORBEXPRESS
+ data_size_cdr.is_little_endian(m_endian);
+ data_size_cdr.cdr << data_size;
+ int ret = m_shmem.write(const_cast<char*>(data_size_cdr.cdr.get_buffer()), 0, sizeof(CORBA::ULongLong));
+#elif defined(ORB_IS_TAO)
+ data_size_cdr.cdr << data_size;
+ int ret = m_shmem.write((char*)data_size_cdr.cdr.buffer(), 0, sizeof(CORBA::ULongLong));
+#else
+ data_size_cdr.setByteSwapFlag(m_endian);
+ data_size >>= data_size_cdr;
+ int ret = m_shmem.write((char*)data_size_cdr.bufPtr(), 0, sizeof(CORBA::ULongLong));
+#endif
+ if (ret == 0)
+ {
+#ifdef ORB_IS_ORBEXPRESS
+ m_shmem.write(const_cast<char*>(data.get_buffer()), sizeof(CORBA::ULongLong), data.cdr.size_written());
+#elif defined(ORB_IS_TAO)
+ m_shmem.write((char*)data.buffer(), sizeof(CORBA::ULongLong), data.cdr.length());
+#else
+
+ m_shmem.write((char*)data.bufPtr(), sizeof(CORBA::ULongLong), data.bufSize());
+#endif
+ }
+
+ }
+ /*!
+ * @if jp
+ * @brief データを読み込む
+ *
+ * @return データ
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @return
+ *
+ * @endif
+ */
+ void SharedMemoryPort::read(cdrMemoryStream& data)
+ {
+ //CORBA::Octet data_size_str[sizeof(CORBA::ULongLong)];
+ //int ret = m_shmem.read((char*)data_size_str, 0, sizeof(CORBA::ULongLong));
+ //if (ret == 0)
+ if (m_shmem.created())
+ {
+ cdrMemoryStream data_size_cdr;
+ CORBA::ULongLong data_size;
+#ifdef ORB_IS_ORBEXPRESS
+ data.is_little_endian(m_endian);
+ data_size_cdr.is_little_endian(m_endian);
+ data_size_cdr.write_array_1(data_size_str[0], sizeof(CORBA::ULongLong));
+ data_size_cdr.cdr >> data_size;
+#elif defined(ORB_IS_TAO)
+ data_size_cdr.write_octet_array(data_size_str[0], sizeof(CORBA::ULongLong));
+ TAO_InputCDR(data_size_cdr.cdr) >> data_size;
+#else
+ data.setByteSwapFlag(m_endian);
+ data_size_cdr.setByteSwapFlag(m_endian);
+ //data_size_cdr.put_octet_array(&(data_size_str[0]), sizeof(CORBA::ULongLong));
+ data_size_cdr.put_octet_array((CORBA::Octet *)&(m_shmem.get_data()[0]), sizeof(CORBA::ULongLong));
+ data_size <<= data_size_cdr;
+
+
+#endif
+ //CORBA::Octet *shm_data = new CORBA::Octet[data_size];
+ //ret = m_shmem.read((char*)shm_data, sizeof(CORBA::ULongLong), (int)data_size);
+
+ /*if (ret == 0)
+ {
+
+ data.put_octet_array(&(shm_data[0]), (int)data_size);
+ }*/
+ data.put_octet_array((CORBA::Octet *)&(m_shmem.get_data()[sizeof(CORBA::ULongLong)]), (int)data_size);
+ //delete shm_data;
+ }
+
+ }
+ /*!
+ * @if jp
+ * @brief データを読み込む
+ *
+ * @return データ
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @return
+ *
+ * @endif
+ */
+ void SharedMemoryPort::setInterface(::OpenRTM::PortSharedMemory_ptr sm)
+ throw (CORBA::SystemException)
+ {
+ m_smInterface = ::OpenRTM::PortSharedMemory::_narrow(sm);
+ }
+ /*!
+ * @if jp
+ * @brief エンディアンを設定する
+ *
+ * @param endian エンディアン
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param
+ *
+ * @endif
+ */
+ void SharedMemoryPort::setEndian(::CORBA::Boolean endian)
+ throw (CORBA::SystemException)
+ {
+ m_endian = endian;
+ if (!CORBA::is_nil(m_smInterface))
+ {
+ try
+ {
+ m_smInterface->setEndian(endian);
+ }
+ catch (...)
+ {
+
+ }
+ }
+ }
+ /*!
+ * @if jp
+ * @brief データの送信を知らせる
+ *
+ * @return
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @return
+ *
+ * @endif
+ */
+ ::OpenRTM::PortStatus SharedMemoryPort::put()
+ throw (CORBA::SystemException)
+ {
+ return ::OpenRTM::PORT_OK;
+ }
+ /*!
+ * @if jp
+ * @brief データの送信を要求する
+ *
+ * @return
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @return
+ *
+ * @endif
+ */
+ ::OpenRTM::PortStatus SharedMemoryPort::get()
+ throw (CORBA::SystemException)
+ {
+ return ::OpenRTM::PORT_OK;
+ }
+
+ ::OpenRTM::PortSharedMemory_ptr SharedMemoryPort::getObjRef()
+ {
+ //m_objref = this->_this();
+ //return ::OpenRTM::PortSharedMemory::_duplicate(m_objref);
+ return this->_this();
+ }
+};
Copied: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/SharedMemoryPort.h (from rev 3056, trunk/OpenRTM-aist/src/lib/rtm/SharedMemoryPort.h)
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/SharedMemoryPort.h (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/SharedMemoryPort.h 2017-12-10 06:19:38 UTC (rev 3108)
@@ -0,0 +1,283 @@
+// -*- C++ -*-
+/*!
+ * @file SharedMemoryPort.h
+ * @brief Shared Memory Port class
+ * @date $Date: 2017-10-29 07:57:18 $
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2006-2017
+ * Robot Innovation Research Center,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ *
+ */
+
+#ifndef SHAREDMEMORYPORT_H
+#define SHAREDMEMORYPORT_H
+
+
+#include <rtm/Manager.h>
+#include <rtm/idl/SharedMemorySkel.h>
+#include <coil/SharedMemory.h>
+
+#define DEFAULT_DATA_SIZE 8
+#define DEFAULT_SHARED_MEMORY_SIZE 2097152
+
+namespace RTC
+{
+ /*!
+ * @if jp
+ * @class SharedMemoryPort
+ * @brief SharedMemory NX
+ *
+ * SharedMemoryPort
+ *
+ * ¤LìNX
+ * CORBAÉæéÊMÉæèAmmapÌú»AI¹ÈǪ[gÉìÅ«é
+ *
+ * @since 1.2.0
+ *
+ * @else
+ * @class
+ * @brief
+ *
+ *
+ *
+ * @since 1.2.0
+ *
+ * @endif
+ */
+ class SharedMemoryPort
+ : public virtual POA_OpenRTM::PortSharedMemory,
+ public virtual PortableServer::RefCountServantBase
+ {
+ public:
+ /*!
+ * @if jp
+ * @brief RXgN^
+ *
+ * RXgN^
+ *
+ *
+ * @else
+ *
+ * @brief Constructor
+ *
+ * Constructor
+ *
+ * @param manager Manager object
+ *
+ * @endif
+ */
+ SharedMemoryPort();
+ /*!
+ * @if jp
+ * @brief fXgN^
+ *
+ * fXgN^
+ *
+ * @else
+ * @brief Destructor
+ *
+ * Destructor
+ *
+ * @endif
+ */
+ virtual ~SharedMemoryPort();
+ /*!
+ * @if jp
+ * @brief ¶ñÅwèµ½f[^TCYðlÉÏ··é
+ * 1M ¨ 1048576
+ * 1k ¨ 1024
+ * 100 ¨ 100
+ *
+ * @param size_str f[^TCY(¶ñ)
+ * @return f[^TCY(l)
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param
+ * @return
+ *
+ * @endif
+ */
+ virtual int string_to_MemorySize(std::string size_str);
+ /*!
+ * @if jp
+ * @brief ¤LÌú»
+ * windowsÅÍy[WOt@CãÉÌæðmÛ·é
+ * LinuxÅÍ/dev/shmȺÉt@Cð쬷é
+ * 쬵½t@CÌàeð¼zAhXÉ}bsO·é
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param memory_size
+ * @param shm_address
+ *
+ * @endif
+ */
+ virtual void create_memory(::CORBA::ULongLong memory_size, const char *shm_address)
+ throw (CORBA::SystemException);
+ /*!
+ * @if jp
+ * @brief ¤LÌ}bsOðs¤
+ *
+ * @param memory_size ¤LÌTCY
+ * @param shm_address óÔ¼
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param memory_size
+ * @param shm_address
+ *
+ * @endif
+ */
+ virtual void open_memory(::CORBA::ULongLong memory_size, const char *shm_address)
+ throw (CORBA::SystemException);
+ /*!
+ * @if jp
+ * @brief }bsOµ½¤LðA}bv·é
+ * @param unlink LinuxÅ/dev/shmȺÉ쬵½t@Cðí·éêÉTrueÉ·é
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param unlink
+ *
+ * @endif
+ */
+ virtual void close_memory(::CORBA::Boolean unlink = false)
+ throw (CORBA::SystemException);
+ /*!
+ * @if jp
+ * @brief f[^ð«Þ
+ * æª8byteÉf[^TCYð«ÝA»ÌãëÉf[^ð«Þ
+ * Ýèµ½f[^TCYª¤LÌTCYðãñÁ½êA¤LÌú»ðs¤
+ *
+ * @param data «Þf[^
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param data
+ *
+ * @endif
+ */
+ virtual void write(const cdrMemoryStream& data);
+ /*!
+ * @if jp
+ * @brief f[^ðÇÝÞ
+ * @return f[^
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @return
+ *
+ * @endif
+ */
+ virtual void read(cdrMemoryStream& data);
+ /*!
+ * @if jp
+ * @brief ÊMæÌCORBAC^[tF[Xðo^·é
+ * o^·éÉæè¤LÌú»µ½Æ«ÉAÊMæÅà}bsOðâè¼·±ÆªÅ«é
+ *
+ * @param sm SharedMemoryÌIuWFNgt@X
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @return
+ *
+ * @endif
+ */
+ virtual void setInterface(::OpenRTM::PortSharedMemory_ptr sm)
+ throw (CORBA::SystemException);
+ /*!
+ * @if jp
+ * @brief GfBAðÝè·é
+ *
+ * @param endian GfBA
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @param
+ *
+ * @endif
+ */
+ virtual void setEndian(::CORBA::Boolean endian)
+ throw (CORBA::SystemException);
+ /*!
+ * @if jp
+ * @brief f[^ÌMðmç¹é
+ *
+ * @return
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @return
+ *
+ * @endif
+ */
+ virtual ::OpenRTM::PortStatus put()
+ throw (CORBA::SystemException);
+ /*!
+ * @if jp
+ * @brief f[^ÌMðv·é
+ *
+ * @return
+ *
+ *
+ *
+ * @else
+ * @brief
+ *
+ * @return
+ *
+ * @endif
+ */
+ virtual ::OpenRTM::PortStatus get()
+ throw (CORBA::SystemException);
+
+ virtual ::OpenRTM::PortSharedMemory_ptr getObjRef();
+
+ protected:
+ //mutable Logger rtclog;
+ ::OpenRTM::PortSharedMemory_var m_smInterface;
+ bool m_endian;
+ coil::SharedMemory m_shmem;
+ //::OpenRTM::PortSharedMemory_var m_objref;
+
+
+ }; // class SharedMemoryPort
+}; // namespace RTC
+
+#ifdef WIN32
+#pragma warning( default : 4290 )
+#endif
+
+#endif // RTC_RTOBJECT
Modified: branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/OpenRTM-aist.sln.dep
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/OpenRTM-aist.sln.dep 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/OpenRTM-aist.sln.dep 2017-12-10 06:19:38 UTC (rev 3108)
@@ -40,3 +40,5 @@
AnalyzerComp: libcoil libRTCSkel libRTC
Analyzer_test: libcoil libRTCSkel libRTC
Analyzer_testComp: libcoil libRTCSkel libRTC
+Throughput: libcoil libRTCSkel libRTC
+ThroughputComp: libcoil libRTCSkel libRTC
Modified: branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/examples/Makefile.am
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/examples/Makefile.am 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/examples/Makefile.am 2017-12-10 06:19:38 UTC (rev 3108)
@@ -4,7 +4,7 @@
##
## $Id$
##---------------------------------------------------------------------------
-SUBDIRS = Analyzer Composite ConfigSample ExtTrigger LTTSample SimpleIO SeqIO SimpleService USBCamera .
+SUBDIRS = Analyzer Composite ConfigSample ExtTrigger LTTSample SimpleIO SeqIO SimpleService Throughput USBCamera .
clean-local:
rm -f *~
Modified: branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/examples/example.yaml
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/examples/example.yaml 2017-12-10 06:15:08 UTC (rev 3107)
+++ branches/RELENG_1_2/OpenRTM-aist/win32/OpenRTM-aist/examples/example.yaml 2017-12-10 06:19:38 UTC (rev 3108)
@@ -143,4 +143,14 @@
ShortName: Anlytest.dll
Name: Analyzer_test.dll
Source: ..\\examples\\Analyzer\\Analyzer_test\\Release\\Analyzer_test.dll
+ - Id: ThroughputComp.exe
+ ShortName: Through.exe
+ Name: ThroughputComp.exe
+ Source: ..\\examples\\Throughput\\ThroughputComp\\Release\\ThroughputComp.exe
+ Shortcut: true
+ - Id: Throughputdll
+ ShortName: Through .dll
+ Name: Throughput.dll
+ Source: ..\\examples\\Throughput\\Throughput\\Release\\Throughput.dll
+ Source: ..\\examples\\Analyzer\\Analyzer\\Release\\Throughput.dll
More information about the openrtm-commit
mailing list