Browse Source

add src1/common/modulecomm_fastrtps_tcp for modulecomm use tcp commulication.

yuchuli 3 years ago
parent
commit
7423399c78

+ 26 - 3
src1/common/modulecomm/modulecomm.cpp

@@ -11,7 +11,7 @@ struct ModeduleInfo
 };
 
 void *  RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount,
-                     ModuleComm_TYPE xmctype)
+                     ModuleComm_TYPE xmctype,const unsigned short nport)
 {
 
     iv::modulecomm::ModeduleInfo * pmi = new iv::modulecomm::ModeduleInfo;
@@ -27,13 +27,17 @@ void *  RegisterSend(const char * strcommname,const unsigned int nBufSize,const
     case ModuleComm_INTERIOR:
         pmi->mphandle = iv::modulecomm_inter::RegisterSend(strcommname,nBufSize,nMsgBufCount);
         break;
+    case ModuleComm_FASTRTPS_TCP:
+        pmi->mphandle = iv::modulecomm_fastrtps_tcp::RegisterSend(strcommname,nBufSize,nMsgBufCount,nport);
+        break;
     default:
         break;
     }
     return pmi;
 }
 
-void  *  RegisterRecv(const char * strcommname,SMCallBack pCall,ModuleComm_TYPE xmctype)
+void  *  RegisterRecv(const char * strcommname,SMCallBack pCall,ModuleComm_TYPE xmctype,const char * strip,
+                      const unsigned short nPort)
 {
     iv::modulecomm::ModeduleInfo * pmi = new iv::modulecomm::ModeduleInfo;
     pmi->mmctype = xmctype;
@@ -48,6 +52,9 @@ void  *  RegisterRecv(const char * strcommname,SMCallBack pCall,ModuleComm_TYPE
     case ModuleComm_INTERIOR:
         pmi->mphandle = iv::modulecomm_inter::RegisterRecv(strcommname,pCall);
         break;
+    case ModuleComm_FASTRTPS_TCP:
+        pmi->mphandle = iv::modulecomm_fastrtps_tcp::RegisterRecv(strcommname,pCall,strip,nPort);
+        break;
     default:
         break;
     }
@@ -55,7 +62,8 @@ void  *  RegisterRecv(const char * strcommname,SMCallBack pCall,ModuleComm_TYPE
 }
 
 void *  RegisterRecvPlus(const char * strcommname,ModuleFun xFun,
-                                                ModuleComm_TYPE xmctype)
+                                                ModuleComm_TYPE xmctype,const char * strip,
+                         const unsigned short nPort)
 {
     iv::modulecomm::ModeduleInfo * pmi = new iv::modulecomm::ModeduleInfo;
     pmi->mmctype = xmctype;
@@ -70,6 +78,9 @@ void *  RegisterRecvPlus(const char * strcommname,ModuleFun xFun,
     case ModuleComm_INTERIOR:
         pmi->mphandle = iv::modulecomm_inter::RegisterRecvPlus(strcommname,xFun);
         break;
+    case ModuleComm_FASTRTPS_TCP:
+        pmi->mphandle = iv::modulecomm_fastrtps_tcp::RegisterRecvPlus(strcommname,xFun,strip,nPort);
+        break;
     default:
         break;
     }
@@ -89,6 +100,9 @@ void  ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nData
     case ModuleComm_INTERIOR:
         iv::modulecomm_inter::ModuleSendMsg(pmi->mphandle,strdata,nDataLen);
         break;
+    case ModuleComm_FASTRTPS_TCP:
+        iv::modulecomm_fastrtps_tcp::ModuleSendMsg(pmi->mphandle,strdata,nDataLen);
+        break;
     default:
         break;
     }
@@ -107,6 +121,9 @@ void  Unregister(void * pHandle)
     case ModuleComm_INTERIOR:
         iv::modulecomm_inter::Unregister(pmi->mphandle);
         break;
+    case ModuleComm_FASTRTPS_TCP:
+        iv::modulecomm_fastrtps_tcp::Unregister(pmi->mphandle);
+        break;
     default:
         break;
     }
@@ -125,6 +142,9 @@ void PauseComm(void *pHandle)
     case ModuleComm_INTERIOR:
         iv::modulecomm_inter::PauseComm(pmi->mphandle);
         break;
+    case ModuleComm_FASTRTPS_TCP:
+        iv::modulecomm_fastrtps_tcp::PauseComm(pmi->mphandle);
+        break;
     default:
         break;
     }
@@ -143,6 +163,9 @@ void ContintuComm(void *pHandle)
     case ModuleComm_INTERIOR:
         iv::modulecomm_inter::ContintuComm(pmi->mphandle);
         break;
+    case ModuleComm_FASTRTPS_TCP:
+        iv::modulecomm_fastrtps_tcp::ContintuComm(pmi->mphandle);
+        break;
     default:
         break;
     }

+ 6 - 4
src1/common/modulecomm/modulecomm.h

@@ -11,6 +11,7 @@
 #include "modulecomm_shm.h"
 #include "modulecomm_fastrtps.h"
 #include "modulecomm_inter.h"
+#include "modulecomm_fastrtps_tcp.h"
 
 #if defined(MODULECOMM_LIBRARY)
 #  define MODULECOMMSHARED_EXPORT Q_DECL_EXPORT
@@ -42,16 +43,17 @@ enum ModuleComm_TYPE
 {
     ModuleComm_SHAREMEM = 0,
     ModuleComm_INTERIOR = 1,
-    ModuleComm_FASTRTPS = 2
+    ModuleComm_FASTRTPS = 2,
+    ModuleComm_FASTRTPS_TCP = 3
 };
 
 
 void * MODULECOMMSHARED_EXPORT RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount
-                                            ,ModuleComm_TYPE xmctype = ModuleComm_SHAREMEM);
+                                            ,ModuleComm_TYPE xmctype = ModuleComm_SHAREMEM,const unsigned short nport = 5100);
 void * MODULECOMMSHARED_EXPORT RegisterRecv(const char * strcommname,SMCallBack pCall,
-                                            ModuleComm_TYPE xmctype = ModuleComm_SHAREMEM);
+                                            ModuleComm_TYPE xmctype = ModuleComm_SHAREMEM,const char * strip = 0,const unsigned short = 5100);
 void * MODULECOMMSHARED_EXPORT RegisterRecvPlus(const char * strcommname,ModuleFun xFun,
-                                                ModuleComm_TYPE xmctype = ModuleComm_SHAREMEM);
+                                                ModuleComm_TYPE xmctype = ModuleComm_SHAREMEM,const char * strip = 0,const unsigned short = 5100);
 void MODULECOMMSHARED_EXPORT ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen);
 void MODULECOMMSHARED_EXPORT Unregister(void * pHandle);
 void MODULECOMMSHARED_EXPORT PauseComm(void * pHandle);

+ 1 - 0
src1/common/modulecomm/modulecomm.pro

@@ -34,3 +34,4 @@ unix {
 INCLUDEPATH += $$PWD/../modulecomm_shm
 INCLUDEPATH += $$PWD/../modulecomm_fastrtps
 INCLUDEPATH += $$PWD/../modulecomm_inter
+INCLUDEPATH += $$PWD/../modulecomm_fastrtps_tcp

+ 323 - 0
src1/common/modulecomm_fastrtps_tcp/Topics.cxx

@@ -0,0 +1,323 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file Topics.cpp
+ * This source file contains the definition of the described types in the IDL file.
+ *
+ * This file was generated by the tool gen.
+ */
+
+#ifdef _WIN32
+// Remove linker warning LNK4221 on Visual Studio
+namespace { char dummy; }
+#endif
+
+#include "Topics.h"
+#include <fastcdr/Cdr.h>
+
+#include <fastcdr/exceptions/BadParamException.h>
+using namespace eprosima::fastcdr::exception;
+
+#include <utility>
+
+
+TopicSample::Message::Message()
+{
+    // m_msgname com.eprosima.idl.parser.typecode.StringTypeCode@76329302
+    m_msgname ="";
+    // m_counter com.eprosima.idl.parser.typecode.PrimitiveTypeCode@5e25a92e
+    m_counter = 0;
+    // m_sendtime com.eprosima.idl.parser.typecode.PrimitiveTypeCode@4df828d7
+    m_sendtime = 0;
+    // m_xdata com.eprosima.idl.parser.typecode.AliasTypeCode@b59d31
+
+    m_xdata.push_back(1);
+    m_xdata.push_back(2);
+
+
+}
+
+TopicSample::Message::~Message()
+{
+
+
+
+
+}
+
+TopicSample::Message::Message(const Message &x)
+{
+    m_msgname = x.m_msgname;
+    m_counter = x.m_counter;
+    m_sendtime = x.m_sendtime;
+    m_xdata = x.m_xdata;
+}
+
+TopicSample::Message::Message(Message &&x)
+{
+    m_msgname = std::move(x.m_msgname);
+    m_counter = x.m_counter;
+    m_sendtime = x.m_sendtime;
+    m_xdata = std::move(x.m_xdata);
+}
+
+TopicSample::Message& TopicSample::Message::operator=(const Message &x)
+{
+
+    m_msgname = x.m_msgname;
+    m_counter = x.m_counter;
+    m_sendtime = x.m_sendtime;
+    m_xdata = x.m_xdata;
+
+    return *this;
+}
+
+TopicSample::Message& TopicSample::Message::operator=(Message &&x)
+{
+
+    m_msgname = std::move(x.m_msgname);
+    m_counter = x.m_counter;
+    m_sendtime = x.m_sendtime;
+    m_xdata = std::move(x.m_xdata);
+
+    return *this;
+}
+
+size_t TopicSample::Message::getMaxCdrSerializedSize(size_t current_alignment)
+{
+    size_t initial_alignment = current_alignment;
+
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1;
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
+
+
+    current_alignment += 8 + eprosima::fastcdr::Cdr::alignment(current_alignment, 8);
+
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
+
+    current_alignment += (100 * 1) + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
+
+
+
+    return 10000000;
+//    return current_alignment - initial_alignment;
+}
+
+size_t TopicSample::Message::getCdrSerializedSize(const TopicSample::Message& data, size_t current_alignment)
+{
+    (void)data;
+    size_t initial_alignment = current_alignment;
+
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.msgname().size() + 1;
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
+
+
+    current_alignment += 8 + eprosima::fastcdr::Cdr::alignment(current_alignment, 8);
+
+
+    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
+
+    if (data.xdata().size() > 0)
+    {
+        current_alignment += (data.xdata().size() * 1) + eprosima::fastcdr::Cdr::alignment(current_alignment, 1);
+    }
+
+
+
+
+    return current_alignment - initial_alignment;
+}
+
+void TopicSample::Message::serialize(eprosima::fastcdr::Cdr &scdr) const
+{
+
+    scdr << m_msgname;
+    scdr << m_counter;
+    scdr << m_sendtime;
+    scdr << m_xdata;
+
+//    std::cout<<"serialize."<<std::endl;
+}
+
+void TopicSample::Message::deserialize(eprosima::fastcdr::Cdr &dcdr)
+{
+
+    dcdr >> m_msgname;
+    dcdr >> m_counter;
+    dcdr >> m_sendtime;
+    dcdr >> m_xdata;
+}
+
+/*!
+ * @brief This function copies the value in member msgname
+ * @param _msgname New value to be copied in member msgname
+ */
+void TopicSample::Message::msgname(const std::string &_msgname)
+{
+m_msgname = _msgname;
+}
+
+/*!
+ * @brief This function moves the value in member msgname
+ * @param _msgname New value to be moved in member msgname
+ */
+void TopicSample::Message::msgname(std::string &&_msgname)
+{
+m_msgname = std::move(_msgname);
+}
+
+/*!
+ * @brief This function returns a constant reference to member msgname
+ * @return Constant reference to member msgname
+ */
+const std::string& TopicSample::Message::msgname() const
+{
+    return m_msgname;
+}
+
+/*!
+ * @brief This function returns a reference to member msgname
+ * @return Reference to member msgname
+ */
+std::string& TopicSample::Message::msgname()
+{
+    return m_msgname;
+}
+/*!
+ * @brief This function sets a value in member counter
+ * @param _counter New value for member counter
+ */
+void TopicSample::Message::counter(int32_t _counter)
+{
+m_counter = _counter;
+}
+
+/*!
+ * @brief This function returns the value of member counter
+ * @return Value of member counter
+ */
+int32_t TopicSample::Message::counter() const
+{
+    return m_counter;
+}
+
+/*!
+ * @brief This function returns a reference to member counter
+ * @return Reference to member counter
+ */
+int32_t& TopicSample::Message::counter()
+{
+    return m_counter;
+}
+
+/*!
+ * @brief This function sets a value in member sendtime
+ * @param _sendtime New value for member sendtime
+ */
+void TopicSample::Message::sendtime(int64_t _sendtime)
+{
+m_sendtime = _sendtime;
+}
+
+/*!
+ * @brief This function returns the value of member sendtime
+ * @return Value of member sendtime
+ */
+int64_t TopicSample::Message::sendtime() const
+{
+    return m_sendtime;
+}
+
+/*!
+ * @brief This function returns a reference to member sendtime
+ * @return Reference to member sendtime
+ */
+int64_t& TopicSample::Message::sendtime()
+{
+    return m_sendtime;
+}
+
+/*!
+ * @brief This function copies the value in member xdata
+ * @param _xdata New value to be copied in member xdata
+ */
+void TopicSample::Message::xdata(const TopicSample::SomeBytes &_xdata)
+{
+ //   return;
+  m_xdata = _xdata;
+//int i;
+//for(i=0;i<300;i++)
+//    m_xdata.push_back(_xdata.at(i));
+}
+
+/*!
+ * @brief This function moves the value in member xdata
+ * @param _xdata New value to be moved in member xdata
+ */
+void TopicSample::Message::xdata(TopicSample::SomeBytes &&_xdata)
+{
+m_xdata = std::move(_xdata);
+}
+
+/*!
+ * @brief This function returns a constant reference to member xdata
+ * @return Constant reference to member xdata
+ */
+const TopicSample::SomeBytes& TopicSample::Message::xdata() const
+{
+    return m_xdata;
+}
+
+/*!
+ * @brief This function returns a reference to member xdata
+ * @return Reference to member xdata
+ */
+TopicSample::SomeBytes& TopicSample::Message::xdata()
+{
+    return m_xdata;
+}
+
+size_t TopicSample::Message::getKeyMaxCdrSerializedSize(size_t current_alignment)
+{
+    size_t current_align = current_alignment;
+
+
+
+
+
+
+
+    return current_align;
+}
+
+bool TopicSample::Message::isKeyDefined()
+{
+   return false;
+}
+
+void TopicSample::Message::serializeKey(eprosima::fastcdr::Cdr &scdr) const
+{
+    (void) scdr;
+     
+     
+     
+     
+}
+

+ 253 - 0
src1/common/modulecomm_fastrtps_tcp/Topics.h

@@ -0,0 +1,253 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file Topics.h
+ * This header file contains the declaration of the described types in the IDL file.
+ *
+ * This file was generated by the tool gen.
+ */
+
+#ifndef _TOPICSAMPLE_TOPICS_H_
+#define _TOPICSAMPLE_TOPICS_H_
+
+// TODO Poner en el contexto.
+
+#include <stdint.h>
+#include <array>
+#include <string>
+#include <vector>
+#include <map>
+#include <bitset>
+
+#if defined(_WIN32)
+#if defined(EPROSIMA_USER_DLL_EXPORT)
+#define eProsima_user_DllExport __declspec( dllexport )
+#else
+#define eProsima_user_DllExport
+#endif
+#else
+#define eProsima_user_DllExport
+#endif
+
+#if defined(_WIN32)
+#if defined(EPROSIMA_USER_DLL_EXPORT)
+#if defined(Topics_SOURCE)
+#define Topics_DllAPI __declspec( dllexport )
+#else
+#define Topics_DllAPI __declspec( dllimport )
+#endif // Topics_SOURCE
+#else
+#define Topics_DllAPI
+#endif
+#else
+#define Topics_DllAPI
+#endif // _WIN32
+
+namespace eprosima
+{
+    namespace fastcdr
+    {
+        class Cdr;
+    }
+}
+
+
+namespace TopicSample
+{
+    typedef std::vector<uint8_t> SomeBytes;
+    /*!
+     * @brief This class represents the structure Message defined by the user in the IDL file.
+     * @ingroup TOPICS
+     */
+    class Message
+    {
+    public:
+
+        /*!
+         * @brief Default constructor.
+         */
+        eProsima_user_DllExport Message();
+
+        /*!
+         * @brief Default destructor.
+         */
+        eProsima_user_DllExport ~Message();
+
+        /*!
+         * @brief Copy constructor.
+         * @param x Reference to the object TopicSample::Message that will be copied.
+         */
+        eProsima_user_DllExport Message(const Message &x);
+
+        /*!
+         * @brief Move constructor.
+         * @param x Reference to the object TopicSample::Message that will be copied.
+         */
+        eProsima_user_DllExport Message(Message &&x);
+
+        /*!
+         * @brief Copy assignment.
+         * @param x Reference to the object TopicSample::Message that will be copied.
+         */
+        eProsima_user_DllExport Message& operator=(const Message &x);
+
+        /*!
+         * @brief Move assignment.
+         * @param x Reference to the object TopicSample::Message that will be copied.
+         */
+        eProsima_user_DllExport Message& operator=(Message &&x);
+
+        /*!
+         * @brief This function copies the value in member msgname
+         * @param _msgname New value to be copied in member msgname
+         */
+        eProsima_user_DllExport void msgname(const std::string &_msgname);
+
+        /*!
+         * @brief This function moves the value in member msgname
+         * @param _msgname New value to be moved in member msgname
+         */
+        eProsima_user_DllExport void msgname(std::string &&_msgname);
+
+        /*!
+         * @brief This function returns a constant reference to member msgname
+         * @return Constant reference to member msgname
+         */
+        eProsima_user_DllExport const std::string& msgname() const;
+
+        /*!
+         * @brief This function returns a reference to member msgname
+         * @return Reference to member msgname
+         */
+        eProsima_user_DllExport std::string& msgname();
+        /*!
+         * @brief This function sets a value in member counter
+         * @param _counter New value for member counter
+         */
+        eProsima_user_DllExport void counter(int32_t _counter);
+
+        /*!
+         * @brief This function returns the value of member counter
+         * @return Value of member counter
+         */
+        eProsima_user_DllExport int32_t counter() const;
+
+        /*!
+         * @brief This function returns a reference to member counter
+         * @return Reference to member counter
+         */
+        eProsima_user_DllExport int32_t& counter();
+
+        /*!
+         * @brief This function sets a value in member sendtime
+         * @param _sendtime New value for member sendtime
+         */
+        eProsima_user_DllExport void sendtime(int64_t _sendtime);
+
+        /*!
+         * @brief This function returns the value of member sendtime
+         * @return Value of member sendtime
+         */
+        eProsima_user_DllExport int64_t sendtime() const;
+
+        /*!
+         * @brief This function returns a reference to member sendtime
+         * @return Reference to member sendtime
+         */
+        eProsima_user_DllExport int64_t& sendtime();
+
+        /*!
+         * @brief This function copies the value in member xdata
+         * @param _xdata New value to be copied in member xdata
+         */
+        eProsima_user_DllExport void xdata(const TopicSample::SomeBytes &_xdata);
+
+        /*!
+         * @brief This function moves the value in member xdata
+         * @param _xdata New value to be moved in member xdata
+         */
+        eProsima_user_DllExport void xdata(TopicSample::SomeBytes &&_xdata);
+
+        /*!
+         * @brief This function returns a constant reference to member xdata
+         * @return Constant reference to member xdata
+         */
+        eProsima_user_DllExport const TopicSample::SomeBytes& xdata() const;
+
+        /*!
+         * @brief This function returns a reference to member xdata
+         * @return Reference to member xdata
+         */
+        eProsima_user_DllExport TopicSample::SomeBytes& xdata();
+
+        /*!
+         * @brief This function returns the maximum serialized size of an object
+         * depending on the buffer alignment.
+         * @param current_alignment Buffer alignment.
+         * @return Maximum serialized size.
+         */
+        eProsima_user_DllExport static size_t getMaxCdrSerializedSize(size_t current_alignment = 0);
+
+        /*!
+         * @brief This function returns the serialized size of a data depending on the buffer alignment.
+         * @param data Data which is calculated its serialized size.
+         * @param current_alignment Buffer alignment.
+         * @return Serialized size.
+         */
+        eProsima_user_DllExport static size_t getCdrSerializedSize(const TopicSample::Message& data, size_t current_alignment = 0);
+
+
+        /*!
+         * @brief This function serializes an object using CDR serialization.
+         * @param cdr CDR serialization object.
+         */
+        eProsima_user_DllExport void serialize(eprosima::fastcdr::Cdr &cdr) const;
+
+        /*!
+         * @brief This function deserializes an object using CDR serialization.
+         * @param cdr CDR serialization object.
+         */
+        eProsima_user_DllExport void deserialize(eprosima::fastcdr::Cdr &cdr);
+
+
+
+        /*!
+         * @brief This function returns the maximum serialized size of the Key of an object
+         * depending on the buffer alignment.
+         * @param current_alignment Buffer alignment.
+         * @return Maximum serialized size.
+         */
+        eProsima_user_DllExport static size_t getKeyMaxCdrSerializedSize(size_t current_alignment = 0);
+
+        /*!
+         * @brief This function tells you if the Key has been defined for this type
+         */
+        eProsima_user_DllExport static bool isKeyDefined();
+
+        /*!
+         * @brief This function serializes the key members of an object using CDR serialization.
+         * @param cdr CDR serialization object.
+         */
+        eProsima_user_DllExport void serializeKey(eprosima::fastcdr::Cdr &cdr) const;
+
+    private:
+        std::string m_msgname;
+        int32_t m_counter;
+        int64_t m_sendtime;
+        TopicSample::SomeBytes m_xdata;
+    };
+}
+
+#endif // _TOPICSAMPLE_TOPICS_H_

+ 13 - 0
src1/common/modulecomm_fastrtps_tcp/Topics.idl

@@ -0,0 +1,13 @@
+module TopicSample {
+
+#pragma DCPS_DATA_TYPE "TopicSample::Message"
+
+typedef sequence<octet> SomeBytes;
+struct Message {
+  string msgname;
+  long counter;
+  long long sendtime;
+  SomeBytes   xdata;
+};
+
+};

+ 138 - 0
src1/common/modulecomm_fastrtps_tcp/TopicsPubSubTypes.cxx

@@ -0,0 +1,138 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsPubSubTypes.cpp
+ * This header file contains the implementation of the serialization functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+
+#include <fastcdr/FastBuffer.h>
+#include <fastcdr/Cdr.h>
+
+#include "TopicsPubSubTypes.h"
+
+using namespace eprosima::fastrtps;
+using namespace eprosima::fastrtps::rtps;
+
+namespace TopicSample
+{
+
+    MessagePubSubType::MessagePubSubType()
+    {
+        setName("TopicSample::Message");
+        m_typeSize = static_cast<uint32_t>(Message::getMaxCdrSerializedSize()) + 4 /*encapsulation*/;
+        m_isGetKeyDefined = Message::isKeyDefined();
+        size_t keyLength = Message::getKeyMaxCdrSerializedSize()>16 ? Message::getKeyMaxCdrSerializedSize() : 16;
+        m_keyBuffer = reinterpret_cast<unsigned char*>(malloc(keyLength));
+        memset(m_keyBuffer, 0, keyLength);
+    }
+
+    MessagePubSubType::~MessagePubSubType()
+    {
+        if(m_keyBuffer!=nullptr)
+            free(m_keyBuffer);
+    }
+
+    bool MessagePubSubType::serialize(void *data, SerializedPayload_t *payload)
+    {
+        Message *p_type = static_cast<Message*>(data);
+        eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->max_size); // Object that manages the raw buffer.
+        eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
+                eprosima::fastcdr::Cdr::DDS_CDR); // Object that serializes the data.
+        payload->encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
+        // Serialize encapsulation
+        ser.serialize_encapsulation();
+
+        try
+        {
+            p_type->serialize(ser); // Serialize the object:
+        }
+        catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/)
+        {
+            return false;
+        }
+
+        payload->length = static_cast<uint32_t>(ser.getSerializedDataLength()); //Get the serialized length
+        return true;
+    }
+
+    bool MessagePubSubType::deserialize(SerializedPayload_t* payload, void* data)
+    {
+        Message* p_type = static_cast<Message*>(data); //Convert DATA to pointer of your type
+        eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload->data), payload->length); // Object that manages the raw buffer.
+        eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
+                eprosima::fastcdr::Cdr::DDS_CDR); // Object that deserializes the data.
+        // Deserialize encapsulation.
+        deser.read_encapsulation();
+        payload->encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
+
+        try
+        {
+            p_type->deserialize(deser); //Deserialize the object:
+        }
+        catch(eprosima::fastcdr::exception::NotEnoughMemoryException& /*exception*/)
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    std::function<uint32_t()> MessagePubSubType::getSerializedSizeProvider(void* data)
+    {
+        return [data]() -> uint32_t
+        {
+            return static_cast<uint32_t>(type::getCdrSerializedSize(*static_cast<Message*>(data))) + 4 /*encapsulation*/;
+        };
+    }
+
+    void* MessagePubSubType::createData()
+    {
+        return reinterpret_cast<void*>(new Message());
+    }
+
+    void MessagePubSubType::deleteData(void* data)
+    {
+        delete(reinterpret_cast<Message*>(data));
+    }
+
+    bool MessagePubSubType::getKey(void *data, InstanceHandle_t* handle, bool force_md5)
+    {
+        if(!m_isGetKeyDefined)
+            return false;
+        Message* p_type = static_cast<Message*>(data);
+        eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(m_keyBuffer),Message::getKeyMaxCdrSerializedSize());     // Object that manages the raw buffer.
+        eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS);     // Object that serializes the data.
+        p_type->serializeKey(ser);
+        if(force_md5 || Message::getKeyMaxCdrSerializedSize()>16)    {
+            m_md5.init();
+            m_md5.update(m_keyBuffer, static_cast<unsigned int>(ser.getSerializedDataLength()));
+            m_md5.finalize();
+            for(uint8_t i = 0;i<16;++i)        {
+                handle->value[i] = m_md5.digest[i];
+            }
+        }
+        else    {
+            for(uint8_t i = 0;i<16;++i)        {
+                handle->value[i] = m_keyBuffer[i];
+            }
+        }
+        return true;
+    }
+
+
+} //End of namespace TopicSample

+ 61 - 0
src1/common/modulecomm_fastrtps_tcp/TopicsPubSubTypes.h

@@ -0,0 +1,61 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsPubSubTypes.h
+ * This header file contains the declaration of the serialization functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+
+#ifndef _TOPICSAMPLE_TOPICS_PUBSUBTYPES_H_
+#define _TOPICSAMPLE_TOPICS_PUBSUBTYPES_H_
+
+#include <fastrtps/config.h>
+#include <fastrtps/TopicDataType.h>
+
+#include "Topics.h"
+
+#if !defined(GEN_API_VER) || (GEN_API_VER != 1)
+#error Generated Topics is not compatible with current installed Fast-RTPS. Please, regenerate it with fastrtpsgen.
+#endif
+
+namespace TopicSample
+{
+    typedef std::vector<uint8_t> SomeBytes;
+    /*!
+     * @brief This class represents the TopicDataType of the type Message defined by the user in the IDL file.
+     * @ingroup TOPICS
+     */
+    class MessagePubSubType : public eprosima::fastrtps::TopicDataType {
+    public:
+        typedef Message type;
+
+        eProsima_user_DllExport MessagePubSubType();
+
+        eProsima_user_DllExport virtual ~MessagePubSubType();
+        eProsima_user_DllExport virtual bool serialize(void *data, eprosima::fastrtps::rtps::SerializedPayload_t *payload) override;
+        eProsima_user_DllExport virtual bool deserialize(eprosima::fastrtps::rtps::SerializedPayload_t *payload, void *data) override;
+        eProsima_user_DllExport virtual std::function<uint32_t()> getSerializedSizeProvider(void* data) override;
+        eProsima_user_DllExport virtual bool getKey(void *data, eprosima::fastrtps::rtps::InstanceHandle_t *ihandle,
+            bool force_md5 = false) override;
+        eProsima_user_DllExport virtual void* createData() override;
+        eProsima_user_DllExport virtual void deleteData(void * data) override;
+        MD5 m_md5;
+        unsigned char* m_keyBuffer;
+    };
+}
+
+#endif // _TOPICSAMPLE_TOPICS_PUBSUBTYPES_H_

+ 202 - 0
src1/common/modulecomm_fastrtps_tcp/TopicsPublisher.cxx

@@ -0,0 +1,202 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsPublisher.cpp
+ * This file contains the implementation of the publisher functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+
+#include <fastrtps/participant/Participant.h>
+#include <fastrtps/attributes/ParticipantAttributes.h>
+#include <fastrtps/publisher/Publisher.h>
+#include <fastrtps/attributes/PublisherAttributes.h>
+
+#include <fastrtps/Domain.h>
+
+#include <fastrtps/participant/Participant.h>
+#include <fastrtps/attributes/ParticipantAttributes.h>
+#include <fastrtps/attributes/PublisherAttributes.h>
+#include <fastrtps/publisher/Publisher.h>
+#include <fastrtps/Domain.h>
+#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
+#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>
+#include <fastdds/rtps/transport/TCPv4TransportDescriptor.h>
+
+#include <thread>
+#include <chrono>
+
+#include "TopicsPublisher.h"
+
+using namespace eprosima::fastrtps;
+using namespace eprosima::fastrtps::rtps;
+
+using namespace eprosima::fastdds::rtps;
+
+TopicsPublisher::TopicsPublisher() : mp_participant(nullptr), mp_publisher(nullptr) {}
+
+TopicsPublisher::~TopicsPublisher() {	Domain::removeParticipant(mp_participant);}
+
+bool TopicsPublisher::init(const char * strtopic,const unsigned short nListenPort)
+{
+    strncpy(mstrtopic,strtopic,255);
+    mnListenPort = nListenPort;
+    // Create RTPSParticipant
+
+    ParticipantAttributes PParam;
+    PParam.rtps.sendSocketBufferSize = 100000000;
+    PParam.rtps.setName("Participant_publisher");  //You can put here the name you want
+
+    PParam.rtps.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol_t::SIMPLE;
+    PParam.rtps.builtin.discovery_config.use_SIMPLE_EndpointDiscoveryProtocol = true;
+    PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter = true;
+    PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationWriterANDSubscriptionReader = true;
+    PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
+
+    // SharedMem transport configuration
+    PParam.rtps.useBuiltinTransports = false;
+
+    //Create a descriptor for the new transport.
+    auto tcp_transport = std::make_shared<TCPv4TransportDescriptor>();
+    tcp_transport->add_listener_port(nListenPort);
+    tcp_transport->set_WAN_address("0.0.0.0");
+
+    tcp_transport->wait_for_tcp_negotiation = false;
+    tcp_transport->sendBufferSize = 0;
+    tcp_transport->receiveBufferSize = 0;
+
+    PParam.rtps.userTransports.push_back(tcp_transport);
+
+
+    mp_participant = Domain::createParticipant(PParam);
+    if(mp_participant == nullptr)
+    {
+        return false;
+    }
+
+    //Register the type
+
+    Domain::registerType(mp_participant, static_cast<TopicDataType*>(&myType));
+
+    // Create Publisher
+
+    PublisherAttributes Wparam;
+    Wparam.topic.topicKind = NO_KEY;
+    Wparam.topic.topicDataType = myType.getName();  //This type MUST be registered
+    Wparam.topic.topicName = strtopic;//"TopicsPubSubTopic";
+
+    Wparam.topic.historyQos.depth = 30;
+    Wparam.topic.resourceLimitsQos.max_samples = 50;
+    Wparam.topic.resourceLimitsQos.allocated_samples = 20;
+    Wparam.times.heartbeatPeriod.seconds = 2;
+    Wparam.times.heartbeatPeriod.nanosec = 200 * 1000 * 1000;
+    Wparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
+    Wparam.qos.m_publishMode.kind = ASYNCHRONOUS_PUBLISH_MODE;
+
+    mp_publisher = Domain::createPublisher(mp_participant,Wparam,static_cast<PublisherListener*>(&m_listener));
+
+    if(mp_publisher == nullptr)
+    {
+        return false;
+    }
+
+    std::cout << "Publisher created, waiting for Subscribers." << std::endl;
+    return true;
+}
+
+void TopicsPublisher::PubListener::onPublicationMatched(Publisher* pub,MatchingInfo& info)
+{
+    (void)pub;
+
+    if (info.status == MATCHED_MATCHING)
+    {
+        n_matched++;
+        std::cout << "Publisher matched" << std::endl;
+    }
+    else
+    {
+        n_matched--;
+        std::cout << "Publisher unmatched" << std::endl;
+    }
+}
+
+void TopicsPublisher::run()
+{
+    while(m_listener.n_matched == 0)
+    {
+        std::this_thread::sleep_for(std::chrono::milliseconds(250)); // Sleep 250 ms
+    }
+
+    // Publication code
+
+    TopicSample::Message st;
+
+    /* Initialize your structure here */
+
+    int msgsent = 0;
+    char ch = 'y';
+    do
+    {
+        if(ch == 'y')
+        {
+            mp_publisher->write(&st);  ++msgsent;
+            std::cout << "Sending sample, count=" << msgsent << ", send another sample?(y-yes,n-stop): ";
+        }
+        else if(ch == 'n')
+        {
+            std::cout << "Stopping execution " << std::endl;
+            break;
+        }
+        else
+        {
+            std::cout << "Command " << ch << " not recognized, please enter \"y/n\":";
+        }
+    } while(std::cin >> ch);
+}
+
+#include <QDateTime>
+
+void TopicsPublisher::senddata(const char *str, int nsize)
+{
+
+
+    static int ncount = 1;
+    std::cout<<"send data."<<std::endl;
+//    while(m_listener.n_matched == 0)
+    TopicSample::SomeBytes x;
+    x.resize(nsize);
+    memcpy(x.data(),str,nsize);
+
+    TopicSample::Message st;
+
+    st.msgname(mstrtopic);
+//    st.msgname("topictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopictopic");
+    st.counter(ncount);ncount++;
+    st.sendtime(QDateTime::currentMSecsSinceEpoch());
+    TopicSample::SomeBytes & px = x;
+    st.xdata(x);
+
+    int ndatasize = TopicSample::Message::getCdrSerializedSize(st);
+
+    std::cout<<"size is "<<ndatasize<<std::endl;
+
+
+    mp_publisher->write(&st);
+
+
+
+}
+

+ 57 - 0
src1/common/modulecomm_fastrtps_tcp/TopicsPublisher.h

@@ -0,0 +1,57 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsPublisher.h
+ * This header file contains the declaration of the publisher functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+
+#ifndef _TOPICSAMPLE_TOPICS_PUBLISHER_H_
+#define _TOPICSAMPLE_TOPICS_PUBLISHER_H_
+
+#include <fastrtps/fastrtps_fwd.h>
+#include <fastrtps/publisher/PublisherListener.h>
+
+#include "TopicsPubSubTypes.h"
+
+class TopicsPublisher
+{
+public:
+	TopicsPublisher();
+	virtual ~TopicsPublisher();
+    bool init(const char * strtopic,const unsigned short nListenPort);
+	void run();
+    void senddata(const char *str, int nsize);
+private:
+	eprosima::fastrtps::Participant *mp_participant;
+	eprosima::fastrtps::Publisher *mp_publisher;
+
+    char mstrtopic[256];
+    unsigned short mnListenPort;
+
+	class PubListener : public eprosima::fastrtps::PublisherListener
+	{
+	public:
+		PubListener() : n_matched(0){};
+		~PubListener(){};
+		void onPublicationMatched(eprosima::fastrtps::Publisher* pub,eprosima::fastrtps::rtps::MatchingInfo& info);
+		int n_matched;
+	} m_listener;
+	TopicSample::MessagePubSubType myType;
+};
+
+#endif // _TOPICSAMPLE_TOPICS_PUBLISHER_H_

+ 216 - 0
src1/common/modulecomm_fastrtps_tcp/TopicsSubscriber.cxx

@@ -0,0 +1,216 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsSubscriber.cpp
+ * This file contains the implementation of the subscriber functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+#include <fastrtps/participant/Participant.h>
+#include <fastrtps/attributes/ParticipantAttributes.h>
+#include <fastrtps/subscriber/Subscriber.h>
+#include <fastrtps/attributes/SubscriberAttributes.h>
+
+#include <fastrtps/Domain.h>
+
+#include <fastcdr/FastBuffer.h>
+#include <fastcdr/FastCdr.h>
+#include <fastcdr/Cdr.h>
+
+#include <fastrtps/participant/Participant.h>
+#include <fastrtps/attributes/ParticipantAttributes.h>
+#include <fastrtps/attributes/PublisherAttributes.h>
+#include <fastrtps/publisher/Publisher.h>
+#include <fastrtps/Domain.h>
+#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
+#include <fastdds/rtps/transport/UDPv4TransportDescriptor.h>
+#include <fastdds/rtps/transport/TCPv4TransportDescriptor.h>
+
+#include "TopicsSubscriber.h"
+
+using namespace eprosima::fastrtps;
+using namespace eprosima::fastrtps::rtps;
+
+using namespace eprosima::fastdds::rtps;
+
+
+
+
+#include <QDateTime>
+
+TopicsSubscriber::TopicsSubscriber() : mp_participant(nullptr), mp_subscriber(nullptr) {}
+
+TopicsSubscriber::~TopicsSubscriber() {	Domain::removeParticipant(mp_participant);}
+
+bool TopicsSubscriber::init(const char * strtopic,const char * strpubip,const unsigned short nPort)
+{
+
+    strncpy(mstrtopic,strtopic,255);
+    mnPort = nPort;
+    // Create RTPSParticipant
+
+    ParticipantAttributes PParam;
+    PParam.rtps.setName("Participant_subscriber"); //You can put the name you want
+
+    PParam.rtps.builtin.discovery_config.discoveryProtocol = DiscoveryProtocol_t::SIMPLE;
+    PParam.rtps.builtin.discovery_config.use_SIMPLE_EndpointDiscoveryProtocol = true;
+    PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationReaderANDSubscriptionWriter = true;
+    PParam.rtps.builtin.discovery_config.m_simpleEDP.use_PublicationWriterANDSubscriptionReader = true;
+    PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
+
+    // SharedMem transport configuration
+    PParam.rtps.useBuiltinTransports = false;
+
+    auto tcp2_transport = std::make_shared<TCPv4TransportDescriptor>();
+
+    //Set initial peers.
+    Locator_t initial_peer_locator;
+    initial_peer_locator.kind = LOCATOR_KIND_TCPv4;
+    IPLocator::setIPv4(initial_peer_locator, strpubip);
+    initial_peer_locator.port = mnPort;
+    PParam.rtps.builtin.initialPeersList.push_back(initial_peer_locator);
+
+//    PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
+//    PParam.rtps.builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(5, 0);
+//    PParam.rtps.setName("Participant_sub");
+
+    tcp2_transport->wait_for_tcp_negotiation = false;
+    //Link the Transport Layer to the Participant.
+    PParam.rtps.userTransports.push_back(tcp2_transport);
+
+
+
+    mp_participant = Domain::createParticipant(PParam);
+    if(mp_participant == nullptr)
+    {
+        return false;
+    }
+
+    //Register the type
+
+    Domain::registerType(mp_participant, static_cast<TopicDataType*>(&myType));
+
+    // Create Subscriber
+
+    SubscriberAttributes Rparam;
+    Rparam.topic.topicKind = NO_KEY;
+    Rparam.topic.topicDataType = myType.getName(); //Must be registered before the creation of the subscriber
+    Rparam.topic.topicName = strtopic;//"TopicsPubSubTopic";
+
+    Rparam.topic.historyQos.depth = 30;
+    Rparam.topic.resourceLimitsQos.max_samples = 50;
+    Rparam.topic.resourceLimitsQos.allocated_samples = 20;
+
+    Rparam.qos.m_reliability.kind = RELIABLE_RELIABILITY_QOS;
+
+
+    mp_subscriber = Domain::createSubscriber(mp_participant,Rparam, static_cast<SubscriberListener*>(&m_listener));
+    if(mp_subscriber == nullptr)
+    {
+        return false;
+    }
+    return true;
+}
+
+void TopicsSubscriber::SubListener::onSubscriptionMatched(Subscriber* sub,MatchingInfo& info)
+{
+    (void)sub;
+
+    if (info.status == MATCHED_MATCHING)
+    {
+        n_matched++;
+        std::cout << "Subscriber matched" << std::endl;
+    }
+    else
+    {
+        n_matched--;
+        std::cout << "Subscriber unmatched" << std::endl;
+    }
+}
+
+
+void TopicsSubscriber::SubListener::setReceivedTopicFunction(ModuleFun xFun)
+{
+    mFun = xFun;
+    mbSetFun = true;
+}
+void TopicsSubscriber::SubListener::onNewDataMessage(Subscriber* sub)
+{
+    // Take data
+    TopicSample::Message st;
+    static int ncount = 0;
+
+    static int nmaxlatancy = 0;
+
+    std::cout<<"new msg"<<std::endl;
+
+
+//    char * strbuf = new char[1000000];
+//    eprosima::fastcdr::FastBuffer pbuf(strbuf,1000000);
+//    eprosima::fastcdr::Cdr * pxcdr;//
+//    pxcdr = new eprosima::fastcdr::Cdr(pbuf);
+
+//    if(sub->takeNextData(pxcdr, &m_info))
+//    {
+//        if(m_info.sampleKind == ALIVE)
+//        {
+//            // Print your structure data here.
+//            ++n_msg;
+//            std::cout << "Sample received, count=" << n_msg<<std::endl;
+//            st.deserialize(*pxcdr);
+
+//            std::cout<<" size is "<<TopicSample::Message::getCdrSerializedSize(st)<<std::endl;
+//        }
+//    }
+
+//    return;
+
+//    sub->get_first_untaken_info(&m_info);
+    std::cout<<"count is "<<sub->getUnreadCount()<<std::endl;
+
+    if(sub->takeNextData(&st, &m_info))
+    {
+        if(m_info.sampleKind == ALIVE)
+        {
+            // Print your structure data here.
+            ++n_msg;
+            ncount++;
+            std::cout << "Sample received, count=" << st.counter() <<" total: "<<ncount<<std::endl;
+            qint64 timex = QDateTime::currentMSecsSinceEpoch();
+            int nlatancy = (timex - st.sendtime());
+            if(nlatancy>nmaxlatancy)nmaxlatancy = nlatancy;
+            std::cout<<"  latency is "<<nlatancy<<" max: "<<nmaxlatancy<<std::endl;
+            std::cout<<" size is "<<st.xdata().size()<<std::endl;
+            QDateTime dt = QDateTime::fromMSecsSinceEpoch(st.sendtime());
+            if(mbSetFun) mFun((char *)(st.xdata().data()),st.xdata().size(),st.counter(),&dt,st.msgname().data());
+
+
+        }
+    }
+}
+
+void TopicsSubscriber::setReceivedTopicFunction(ModuleFun xFun)
+{
+    m_listener.setReceivedTopicFunction(xFun);
+}
+
+void TopicsSubscriber::run()
+{
+    std::cout << "Waiting for Data, press Enter to stop the Subscriber. "<<std::endl;
+    std::cin.ignore();
+    std::cout << "Shutting down the Subscriber." << std::endl;
+}
+

+ 73 - 0
src1/common/modulecomm_fastrtps_tcp/TopicsSubscriber.h

@@ -0,0 +1,73 @@
+// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * @file TopicsSubscriber.h
+ * This header file contains the declaration of the subscriber functions.
+ *
+ * This file was generated by the tool fastcdrgen.
+ */
+
+
+#ifndef _TOPICSAMPLE_TOPICS_SUBSCRIBER_H_
+#define _TOPICSAMPLE_TOPICS_SUBSCRIBER_H_
+
+#include <fastrtps/fastrtps_fwd.h>
+#include <fastrtps/subscriber/SubscriberListener.h>
+#include <fastrtps/subscriber/SampleInfo.h>
+#include "TopicsPubSubTypes.h"
+
+
+#include <QDateTime>
+
+typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
+
+class TopicsSubscriber
+{
+public:
+	TopicsSubscriber();
+	virtual ~TopicsSubscriber();
+    bool init(const char * strtopic,const char * strpubip,const unsigned short nPort);
+	void run();
+
+    void setReceivedTopicFunction(ModuleFun xFun);
+private:
+	eprosima::fastrtps::Participant *mp_participant;
+	eprosima::fastrtps::Subscriber *mp_subscriber;
+
+
+    char mstrtopic[256];
+    unsigned short mnPort;
+
+	class SubListener : public eprosima::fastrtps::SubscriberListener
+	{
+	public:
+		SubListener() : n_matched(0),n_msg(0){};
+		~SubListener(){};
+		void onSubscriptionMatched(eprosima::fastrtps::Subscriber* sub,eprosima::fastrtps::rtps::MatchingInfo& info);
+		void onNewDataMessage(eprosima::fastrtps::Subscriber* sub);
+		eprosima::fastrtps::SampleInfo_t m_info;
+		int n_matched;
+		int n_msg;
+
+        void setReceivedTopicFunction(ModuleFun xFun);
+
+    private:
+        bool mbSetFun = false;
+        ModuleFun mFun;
+	} m_listener;
+	TopicSample::MessagePubSubType myType;
+};
+
+#endif // _TOPICSAMPLE_TOPICS_SUBSCRIBER_H_

+ 13 - 0
src1/common/modulecomm_fastrtps_tcp/ivmodulemsg_type.h

@@ -0,0 +1,13 @@
+#ifndef IVMODULEMSG_TYPE_H
+#define IVMODULEMSG_TYPE_H
+
+namespace iv {
+struct modulemsg_type
+{
+    char mstrmsgname[256];
+    int mnBufSize;
+    int mnMsgBufCount;
+};
+
+}
+#endif // IVMODULEMSG_TYPE_H

+ 63 - 0
src1/common/modulecomm_fastrtps_tcp/modulecomm_fastrtps_tcp.cpp

@@ -0,0 +1,63 @@
+#include "modulecomm_fastrtps_tcp.h"
+//#include "procsm_if.h"
+//#include "procsm.h"
+
+#include "modulecomm_impl.h"
+
+namespace iv {
+namespace modulecomm_fastrtps_tcp {
+
+
+void *  RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount,unsigned int nListenPort)
+{
+
+
+    modulecomm_impl * pif = new modulecomm_impl(strcommname,modulecomm_impl::type_send,nListenPort);
+
+//    procsm_if * pif = new procsm_if(strcommname,nBufSize,nMsgBufCount,procsm::ModeWrite);
+    return (void *)pif;
+}
+
+void  *  RegisterRecv(const char * strcommname,SMCallBack pCall,const char * strpubip,unsigned int nListenPort)
+{
+    modulecomm_impl * pif = new modulecomm_impl(strcommname,modulecomm_impl::type_recv,nListenPort,strpubip);
+ //   procsm_if * pif = new procsm_if(strcommname,0,0,procsm::ModeRead);
+    pif->listenmsg(pCall);
+    return (void *)pif;
+}
+
+void * MODULECOMMFASTRTPSTCPSHARED_EXPORT RegisterRecvPlus(const char * strcommname,ModuleFun xFun,const char * strpubip,unsigned int nListenPort)
+{
+    modulecomm_impl * pif = new modulecomm_impl(strcommname,modulecomm_impl::type_recv,nListenPort,strpubip);
+ //   procsm_if * pif = new procsm_if(strcommname,0,0,procsm::ModeRead);
+    pif->listenmsg(xFun);
+    return (void *)pif;
+}
+void  ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen)
+{
+    modulecomm_impl * pif= (modulecomm_impl *)pHandle;
+ //   procsm_if * pif = (procsm_if *)pHandle;
+    pif->writemsg(strdata,nDataLen);
+}
+
+void  Unregister(void * pHandle)
+{
+    modulecomm_impl * pif= (modulecomm_impl *)pHandle;
+//    procsm_if * pif = (procsm_if *)pHandle;
+    delete pif;
+}
+
+void PauseComm(void *pHandle)
+{
+//    procsm_if * pif = (procsm_if *)pHandle;
+//    pif->pausecomm();
+}
+
+void ContintuComm(void *pHandle)
+{
+ //   procsm_if * pif = (procsm_if *)pHandle;
+ //   pif->continuecomm();
+}
+
+}
+}

+ 44 - 0
src1/common/modulecomm_fastrtps_tcp/modulecomm_fastrtps_tcp.h

@@ -0,0 +1,44 @@
+#ifndef MODULECOMM_FASTRTPS_TCP_H
+#define MODULECOMM_FASTRTPS_TCP_H
+
+#include <QtCore/qglobal.h>
+#include <QDateTime>
+
+#include <functional>
+
+#if defined(MODULECOMM_FASTRTPS_TCP_LIBRARY)
+#  define MODULECOMMFASTRTPSTCPSHARED_EXPORT Q_DECL_EXPORT
+#else
+#  define MODULECOMMFASTRTPSTCPSHARED_EXPORT Q_DECL_IMPORT
+#endif
+
+
+
+//#include <iostream>
+//#include <thread>
+
+#ifndef IV_MODULE_FUN
+
+typedef std::function<void(const char * ,const unsigned int , const unsigned int , QDateTime * ,const char *)> ModuleFun;
+typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+#define IV_MODULE_FUN
+#endif
+
+
+namespace iv {
+namespace modulecomm_fastrtps_tcp {
+void * MODULECOMMFASTRTPSTCPSHARED_EXPORT RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount,unsigned int nListenPort);
+void * MODULECOMMFASTRTPSTCPSHARED_EXPORT RegisterRecv(const char * strcommname,SMCallBack pCall,const char * strpubip,unsigned int nListenPort);
+void * MODULECOMMFASTRTPSTCPSHARED_EXPORT RegisterRecvPlus(const char * strcommname,ModuleFun xFun,const char * strpubip,unsigned int nListenPort);
+void MODULECOMMFASTRTPSTCPSHARED_EXPORT ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen);
+void MODULECOMMFASTRTPSTCPSHARED_EXPORT Unregister(void * pHandle);
+void MODULECOMMFASTRTPSTCPSHARED_EXPORT PauseComm(void * pHandle);
+void MODULECOMMFASTRTPSTCPSHARED_EXPORT ContintuComm(void * pHandle);
+
+}
+
+}
+
+
+
+#endif 

+ 45 - 0
src1/common/modulecomm_fastrtps_tcp/modulecomm_fastrtps_tcp.pro

@@ -0,0 +1,45 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2018-07-10T05:46:48
+#
+#-------------------------------------------------
+
+QT       -= gui
+
+
+#DEFINES += dds_use_shm
+
+TARGET = modulecomm_fastrtps_tcp
+TEMPLATE = lib
+
+DEFINES += MODULECOMM_FASTRTPS_TCP_LIBRARY
+
+VERSION = 1.0.1
+CONFIG += plugin
+
+
+SOURCES += modulecomm_fastrtps_tcp.cpp \
+    Topics.cxx \
+    TopicsPubSubTypes.cxx \
+    TopicsPublisher.cxx \
+    TopicsSubscriber.cxx \
+    modulecomm_impl.cpp
+
+HEADERS += modulecomm_fastrtps_tcp.h \
+    Topics.h \
+    TopicsPubSubTypes.h \
+    TopicsPublisher.h \
+    TopicsSubscriber.h \
+    modulecomm_impl.h \
+    ivmodulemsg_type.h
+
+unix {
+    target.path = /usr/lib
+    INSTALLS += target
+}
+
+#INCLUDEPATH += $$PWD/../../../include/
+
+
+LIBS += -L$$PWD -lfastcdr -lfastrtps
+

+ 140 - 0
src1/common/modulecomm_fastrtps_tcp/modulecomm_impl.cpp

@@ -0,0 +1,140 @@
+#include "modulecomm_impl.h"
+
+#include <thread>
+#include <iostream>
+#include <QDateTime>
+
+#include <QMutex>
+#include <QFile>
+
+namespace iv {
+namespace modulecomm {
+QMutex gmodulecomm_dds_Mutex;
+int createcount = 0;
+}
+
+}
+
+
+void modulecomm_impl::callbackTopic(const char * strdata,const unsigned int nSize,const unsigned int index, QDateTime * dt,const char * strmemname) {
+
+  if(mbFunPlus)
+  {
+      mFun(strdata,nSize,index,dt,strmemname);
+  }
+  else
+  {
+     (*mpCall)(strdata,nSize,index,dt,strmemname);
+  }
+}
+
+
+int modulecomm_impl::GetTempConfPath(char *strpath)
+{
+    char strtmppath[256];
+    QDateTime dt = QDateTime::currentDateTime();
+    snprintf(strtmppath,256,"/tmp/adc_modulecomm_conf_%04d%02d%02d%02d%02d.ini",dt.date().year(),
+             dt.date().month(),dt.date().day(),dt.time().hour(),dt.time().minute());
+    QFile xFile;
+    xFile.setFileName(strtmppath);
+    char strtem[256];
+    char strdata[10000];
+    snprintf(strdata,10000,"");
+    if(!xFile.exists())
+    {
+        if(xFile.open(QIODevice::ReadWrite))
+        {
+            snprintf(strtem,256,"[common]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"DCPSDefaultDiscovery=TheRTPSConfig\n");strncat(strdata,strtem,10000);
+#ifdef dds_use_shm
+            snprintf(strtem,256,"DCPSGlobalTransportConfig=myconfig\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"[config/myconfig]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"transports=share\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"[transport/share]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"transport_type=shmem\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"pool_size=100000000\n");strncat(strdata,strtem,10000);
+#endif
+            snprintf(strtem,256,"[rtps_discovery/TheRTPSConfig]\n");strncat(strdata,strtem,10000);
+            snprintf(strtem,256,"ResendPeriod=5\n");strncat(strdata,strtem,10000);
+            xFile.write(strdata,strnlen(strdata,10000));
+            xFile.close();
+        }
+    }
+    strncpy(strpath,strtmppath,255);
+    return 0;
+}
+
+modulecomm_impl::modulecomm_impl(const char * strcommname,int ntype,const unsigned short nport ,const char * strip )
+{
+
+    strncpy(mstrtopic,strcommname,255);
+
+    iv::modulecomm::gmodulecomm_dds_Mutex.lock();
+    if(ntype == type_recv)
+    {
+        mpSub = new TopicsSubscriber();
+        mpSub->init(strcommname,strip,nport);
+//        std::this_thread::sleep_for(std::chrono::milliseconds(10));
+
+        mnType = type_recv;
+    }
+    else
+    {
+        mpPub = new TopicsPublisher();
+        mpPub->init(strcommname,nport);
+ //       std::this_thread::sleep_for(std::chrono::milliseconds(10));
+        mnType = type_send;
+    }
+    iv::modulecomm::createcount++;
+    std::cout<<"count is "<<iv::modulecomm::createcount<<std::endl;
+    iv::modulecomm::gmodulecomm_dds_Mutex.unlock();
+
+}
+
+int modulecomm_impl::listenmsg(ModuleFun xFun)
+{
+    if(mnType == type_send)
+    {
+        std::cout<<"send not listen."<<std::endl;;
+        return -1;
+    }
+    mbFunPlus = true;
+    mFun = xFun;
+    ModuleFun topicFunction = std::bind(&modulecomm_impl::callbackTopic,this,std::placeholders::_1,
+                                                                                std::placeholders::_2,
+                                                                                std::placeholders::_3,
+                                                                                std::placeholders::_4,
+                                                                                std::placeholders::_5);
+    mpSub->setReceivedTopicFunction(topicFunction);
+    return 0;
+}
+
+int modulecomm_impl::listenmsg(SMCallBack pCall)
+{
+    if(mnType == type_send)
+    {
+        std::cout<<"send not listen."<<std::endl;
+        return -1;
+    }
+    mbFunPlus = false;
+    mpCall = pCall;
+    ModuleFun topicFunction = std::bind(&modulecomm_impl::callbackTopic,this,std::placeholders::_1,
+                                                                                std::placeholders::_2,
+                                                                                std::placeholders::_3,
+                                                                                std::placeholders::_4,
+                                                                                std::placeholders::_5);
+    mpSub->setReceivedTopicFunction(topicFunction);
+    return 0;
+}
+
+void modulecomm_impl::writemsg(const char *str, int nlen)
+{
+    if(mnType == type_recv)
+    {
+        std::cout<<"recv not send."<<std::endl;
+        return ;
+    }
+
+    mpPub->senddata(str,nlen);
+
+}

+ 41 - 0
src1/common/modulecomm_fastrtps_tcp/modulecomm_impl.h

@@ -0,0 +1,41 @@
+#ifndef MODULECOMM_IMPL_H
+#define MODULECOMM_IMPL_H
+
+#include <QDateTime>
+
+#include "TopicsPublisher.h"
+#include "TopicsSubscriber.h"
+
+
+typedef void (* SMCallBack)(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
+
+
+class modulecomm_impl
+{
+public:
+    const static int type_send = 1;
+    const static int type_recv = 2;
+public:
+    modulecomm_impl(const char * strcommname,int ntype = 2,const unsigned short nport =1,const char * strip = 0);
+    int listenmsg(SMCallBack pCall);
+    int listenmsg(ModuleFun xFun);
+    void writemsg(const char * str,int nlen);
+
+private:
+    char mstrtopic[256];
+    int mnType = type_recv;
+    TopicsPublisher * mpPub;
+    TopicsSubscriber * mpSub;
+    SMCallBack  mpCall;
+    ModuleFun mFun;
+    void callbackTopic(const char * strdata,const unsigned int nSize,const unsigned int index,QDateTime * dt,const char * strmemname);
+
+    int GetTempConfPath(char * strpath);
+
+
+
+    bool mbFunPlus = false;
+
+};
+
+#endif // MODULECOMM_IMPL_H