Browse Source

change src1/common/modulecomm, merge all commulication.

yuchuli 3 năm trước cách đây
mục cha
commit
8557655125

+ 30 - 7
include/modulecomm.h

@@ -1,11 +1,15 @@
-#ifndef MODULECOMM_H
+#ifndef MODULECOMM_H
 #define MODULECOMM_H
 
+
 #include <QtCore/qglobal.h>
 #include <QDateTime>
 
 #include <functional>
 
+
+
+
 #if defined(MODULECOMM_LIBRARY)
 #  define MODULECOMMSHARED_EXPORT Q_DECL_EXPORT
 #else
@@ -14,18 +18,39 @@
 
 
 
+
+
+
 //#include <iostream>
 //#include <thread>
 
 //using namespace std::placeholders;
+
+#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 {
-void * MODULECOMMSHARED_EXPORT RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount);
-void * MODULECOMMSHARED_EXPORT RegisterRecv(const char * strcommname,SMCallBack pCall);
-void * MODULECOMMSHARED_EXPORT RegisterRecvPlus(const char * strcommname,ModuleFun xFun);
+
+enum ModuleComm_TYPE
+{
+    ModuleComm_SHAREMEM = 0,
+    ModuleComm_INTERIOR = 1,
+    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,const unsigned short nport = 5100);
+void * MODULECOMMSHARED_EXPORT RegisterRecv(const char * strcommname,SMCallBack pCall,
+                                            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,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);
@@ -35,6 +60,4 @@ void MODULECOMMSHARED_EXPORT ContintuComm(void * pHandle);
 
 }
 
-
-
-#endif 
+#endif // MODULECOMM_H

+ 5 - 1
src1/common/modulecomm/fastrtps/Topics.cxx

@@ -19,11 +19,15 @@
  * This file was generated by the tool gen.
  */
 
+#ifdef USE_FASTRTPS
+
 #ifdef _WIN32
 // Remove linker warning LNK4221 on Visual Studio
 namespace { char dummy; }
 #endif
 
+
+
 #include "Topics.h"
 #include <fastcdr/Cdr.h>
 
@@ -320,4 +324,4 @@ void TopicSample::Message::serializeKey(eprosima::fastcdr::Cdr &scdr) const
      
      
 }
-
+#endif

+ 3 - 0
src1/common/modulecomm/fastrtps/TopicsPubSubTypes.cxx

@@ -19,6 +19,7 @@
  * This file was generated by the tool fastcdrgen.
  */
 
+#ifdef USE_FASTRTPS
 
 #include <fastcdr/FastBuffer.h>
 #include <fastcdr/Cdr.h>
@@ -136,3 +137,5 @@ namespace TopicSample
 
 
 } //End of namespace TopicSample
+
+#endif

+ 3 - 1
src1/common/modulecomm/fastrtps/TopicsPublisher.cxx

@@ -19,7 +19,7 @@
  * This file was generated by the tool fastcdrgen.
  */
 
-
+#ifdef USE_FASTRTPS
 #include <fastrtps/participant/Participant.h>
 #include <fastrtps/attributes/ParticipantAttributes.h>
 #include <fastrtps/publisher/Publisher.h>
@@ -213,3 +213,5 @@ void TopicsPublisher::senddata(const char *str, int nsize)
 
 }
 
+#endif
+

+ 4 - 0
src1/common/modulecomm/fastrtps/TopicsSubscriber.cxx

@@ -19,6 +19,8 @@
  * This file was generated by the tool fastcdrgen.
  */
 
+#ifdef USE_FASTRTPS
+
 #include <fastrtps/participant/Participant.h>
 #include <fastrtps/attributes/ParticipantAttributes.h>
 #include <fastrtps/subscriber/Subscriber.h>
@@ -226,3 +228,5 @@ void TopicsSubscriber::run()
     std::cout << "Shutting down the Subscriber." << std::endl;
 }
 
+#endif
+

+ 3 - 0
src1/common/modulecomm/fastrtps/modulecomm_fastrtps_shm.cpp

@@ -1,3 +1,4 @@
+#ifdef USE_FASTRTPS
 #include "modulecomm_fastrtps_shm.h"
 
 #include "modulecomm_impl_shm.h"
@@ -59,3 +60,5 @@ void modulecomm_fastrtps_shm::Unregister()
 }
 
 }
+
+#endif

+ 3 - 0
src1/common/modulecomm/fastrtps/modulecomm_fastrtps_tcp.cpp

@@ -1,3 +1,4 @@
+#ifdef USE_FASTRTPS
 #include "modulecomm_fastrtps_tcp.h"
 
 #include "modulecomm_impl_tcp.h"
@@ -59,3 +60,5 @@ void modulecomm_fastrtps_tcp::Unregister()
 
 }
 }
+
+#endif

+ 2 - 0
src1/common/modulecomm/fastrtps/modulecomm_impl_shm.cpp

@@ -1,3 +1,4 @@
+#ifdef USE_FASTRTPS
 #include "modulecomm_impl_shm.h"
 
 #include <thread>
@@ -138,3 +139,4 @@ void modulecomm_impl_shm::writemsg(const char *str, int nlen)
     mpPub->senddata(str,nlen);
 
 }
+#endif

+ 3 - 0
src1/common/modulecomm/fastrtps/modulecomm_impl_tcp.cpp

@@ -1,3 +1,4 @@
+#ifdef USE_FASTRTPS
 #include "modulecomm_impl_tcp.h"
 
 #include <thread>
@@ -138,3 +139,5 @@ void modulecomm_impl_tcp::writemsg(const char *str, int nlen)
     mpPub->senddata(str,nlen);
 
 }
+
+#endif

+ 13 - 0
src1/common/modulecomm/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

+ 106 - 79
src1/common/modulecomm/modulecomm.cpp

@@ -1,12 +1,20 @@
 #include "modulecomm.h"
 #include <iostream>
 
+#include "modulecomm_shm.h"
+
+#include "modulecomm_inter.h"
+#ifdef USE_FASTRTPS
+#include "modulecomm_fastrtps_shm.h"
+#include "modulecomm_fastrtps_tcp.h"
+#endif
+
 namespace iv {
 namespace modulecomm {
 
 struct ModeduleInfo
 {
-    void * mphandle;
+    modulecomm_base * mphandle;
     ModuleComm_TYPE mmctype;
 };
 
@@ -19,17 +27,37 @@ void *  RegisterSend(const char * strcommname,const unsigned int nBufSize,const
     pmi->mphandle = 0;
     switch (xmctype) {
     case ModuleComm_SHAREMEM:
-        pmi->mphandle = iv::modulecomm_shm::RegisterSend(strcommname,nBufSize,nMsgBufCount);
-        break;
-    case ModuleComm_FASTRTPS:
-        pmi->mphandle = iv::modulecomm_fastrtps::RegisterSend(strcommname,nBufSize,nMsgBufCount);
+    {
+        iv::modulecomm_shm * p = new iv::modulecomm_shm();
+        p->RegisterSend(strcommname,nBufSize,nMsgBufCount);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
         break;
     case ModuleComm_INTERIOR:
-        pmi->mphandle = iv::modulecomm_inter::RegisterSend(strcommname,nBufSize,nMsgBufCount);
+    {
+        iv::modulecomm_inter * p = new iv::modulecomm_inter();
+        p->RegisterSend(strcommname,nBufSize,nMsgBufCount);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
+        break;
+
+#ifdef USE_FASTRTPS
+    case ModuleComm_FASTRTPS:
+    {
+        iv::modulecomm_fastrtps_shm * p = new iv::modulecomm_fastrtps_shm();
+        p->RegisterSend(strcommname,nBufSize,nMsgBufCount);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
         break;
+
     case ModuleComm_FASTRTPS_TCP:
-        pmi->mphandle = iv::modulecomm_fastrtps_tcp::RegisterSend(strcommname,nBufSize,nMsgBufCount,nport);
+    {
+        iv::modulecomm_fastrtps_tcp * p = new iv::modulecomm_fastrtps_tcp();
+        p->RegisterSend(strcommname,nBufSize,nMsgBufCount,nport);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
         break;
+#endif
     default:
         break;
     }
@@ -44,17 +72,37 @@ void  *  RegisterRecv(const char * strcommname,SMCallBack pCall,ModuleComm_TYPE
     pmi->mphandle = 0;
     switch (xmctype) {
     case ModuleComm_SHAREMEM:
-        pmi->mphandle = iv::modulecomm_shm::RegisterRecv(strcommname,pCall);
-        break;
-    case ModuleComm_FASTRTPS:
-        pmi->mphandle = iv::modulecomm_fastrtps::RegisterRecv(strcommname,pCall);
+    {
+        iv::modulecomm_shm * p = new iv::modulecomm_shm();
+        p->RegisterRecv(strcommname,pCall);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
         break;
     case ModuleComm_INTERIOR:
-        pmi->mphandle = iv::modulecomm_inter::RegisterRecv(strcommname,pCall);
+    {
+        iv::modulecomm_inter * p = new iv::modulecomm_inter();
+        p->RegisterRecv(strcommname,pCall);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
+        break;
+
+#ifdef USE_FASTRTPS
+    case ModuleComm_FASTRTPS:
+    {
+        iv::modulecomm_fastrtps_shm * p = new iv::modulecomm_fastrtps_shm();
+        p->RegisterRecv(strcommname,pCall);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
         break;
+
     case ModuleComm_FASTRTPS_TCP:
-        pmi->mphandle = iv::modulecomm_fastrtps_tcp::RegisterRecv(strcommname,pCall,strip,nPort);
+    {
+        iv::modulecomm_fastrtps_tcp * p = new iv::modulecomm_fastrtps_tcp();
+        p->RegisterRecv(strcommname,pCall,strip,nPort);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
         break;
+#endif
     default:
         break;
     }
@@ -70,17 +118,36 @@ void *  RegisterRecvPlus(const char * strcommname,ModuleFun xFun,
     pmi->mphandle = 0;
     switch (xmctype) {
     case ModuleComm_SHAREMEM:
-        pmi->mphandle = iv::modulecomm_shm::RegisterRecvPlus(strcommname,xFun);
-        break;
-    case ModuleComm_FASTRTPS:
-        pmi->mphandle = iv::modulecomm_fastrtps::RegisterRecvPlus(strcommname,xFun);
+    {
+        iv::modulecomm_shm * p = new iv::modulecomm_shm();
+        p->RegisterRecvPlus(strcommname,xFun);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
         break;
     case ModuleComm_INTERIOR:
-        pmi->mphandle = iv::modulecomm_inter::RegisterRecvPlus(strcommname,xFun);
+    {
+        iv::modulecomm_inter * p = new iv::modulecomm_inter();
+        p->RegisterRecvPlus(strcommname,xFun);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
+        break;
+#ifdef USE_FASTRTPS
+    case ModuleComm_FASTRTPS:
+    {
+        iv::modulecomm_fastrtps_shm * p = new iv::modulecomm_fastrtps_shm();
+        p->RegisterRecvPlus(strcommname,xFun);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
         break;
+
     case ModuleComm_FASTRTPS_TCP:
-        pmi->mphandle = iv::modulecomm_fastrtps_tcp::RegisterRecvPlus(strcommname,xFun,strip,nPort);
+    {
+        iv::modulecomm_fastrtps_tcp * p = new iv::modulecomm_fastrtps_tcp();
+        p->RegisterRecvPlus(strcommname,xFun,strip,nPort);
+        pmi->mphandle = (iv::modulecomm_base *)p;
+    }
         break;
+#endif
     default:
         break;
     }
@@ -90,85 +157,45 @@ void *  RegisterRecvPlus(const char * strcommname,ModuleFun xFun,
 void  ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen)
 {
     iv::modulecomm::ModeduleInfo * pmi = (iv::modulecomm::ModeduleInfo  * )pHandle;
-    switch (pmi->mmctype) {
-    case ModuleComm_SHAREMEM:
-        iv::modulecomm_shm::ModuleSendMsg(pmi->mphandle,strdata,nDataLen);
-        break;
-    case ModuleComm_FASTRTPS:
-        iv::modulecomm_fastrtps::ModuleSendMsg(pmi->mphandle,strdata,nDataLen);
-        break;
-    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;
+    if(pmi->mphandle == 0)
+    {
+        qDebug("handler error. use fastrtps but not define.");
+        return;
     }
+    pmi->mphandle->ModuleSendMsg(strdata,nDataLen);
 }
 
 void  Unregister(void * pHandle)
 {
     iv::modulecomm::ModeduleInfo * pmi = (iv::modulecomm::ModeduleInfo  * )pHandle;
-    switch (pmi->mmctype) {
-    case ModuleComm_SHAREMEM:
-        iv::modulecomm_shm::Unregister(pmi->mphandle);
-        break;
-    case ModuleComm_FASTRTPS:
-        iv::modulecomm_fastrtps::Unregister(pmi->mphandle);
-        break;
-    case ModuleComm_INTERIOR:
-        iv::modulecomm_inter::Unregister(pmi->mphandle);
-        break;
-    case ModuleComm_FASTRTPS_TCP:
-        iv::modulecomm_fastrtps_tcp::Unregister(pmi->mphandle);
-        break;
-    default:
-        break;
+    if(pmi->mphandle == 0)
+    {
+        qDebug("handler error. use fastrtps but not define.");
+        return;
     }
+    pmi->mphandle->Unregister();
 }
 
 void PauseComm(void *pHandle)
 {
     iv::modulecomm::ModeduleInfo * pmi = (iv::modulecomm::ModeduleInfo  * )pHandle;
-    switch (pmi->mmctype) {
-    case ModuleComm_SHAREMEM:
-        iv::modulecomm_shm::PauseComm(pmi->mphandle);
-        break;
-    case ModuleComm_FASTRTPS:
-        iv::modulecomm_fastrtps::PauseComm(pmi->mphandle);
-        break;
-    case ModuleComm_INTERIOR:
-        iv::modulecomm_inter::PauseComm(pmi->mphandle);
-        break;
-    case ModuleComm_FASTRTPS_TCP:
-        iv::modulecomm_fastrtps_tcp::PauseComm(pmi->mphandle);
-        break;
-    default:
-        break;
+    if(pmi->mphandle == 0)
+    {
+        qDebug("handler error. use fastrtps but not define.");
+        return;
     }
+    pmi->mphandle->PauseComm();
 }
 
 void ContintuComm(void *pHandle)
 {
     iv::modulecomm::ModeduleInfo * pmi = (iv::modulecomm::ModeduleInfo  * )pHandle;
-    switch (pmi->mmctype) {
-    case ModuleComm_SHAREMEM:
-        iv::modulecomm_shm::ContintuComm(pmi->mphandle);
-        break;
-    case ModuleComm_FASTRTPS:
-        iv::modulecomm_fastrtps::ContintuComm(pmi->mphandle);
-        break;
-    case ModuleComm_INTERIOR:
-        iv::modulecomm_inter::ContintuComm(pmi->mphandle);
-        break;
-    case ModuleComm_FASTRTPS_TCP:
-        iv::modulecomm_fastrtps_tcp::ContintuComm(pmi->mphandle);
-        break;
-    default:
-        break;
+    if(pmi->mphandle == 0)
+    {
+        qDebug("handler error. use fastrtps but not define.");
+        return;
     }
+    pmi->mphandle->ContintuComm();
 }
 
 }

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

@@ -8,10 +8,7 @@
 #include <functional>
 
 
-#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

+ 17 - 4
src1/common/modulecomm/modulecomm.pro

@@ -1,8 +1,13 @@
 QT -= gui
 
+QT += dbus
+
 TEMPLATE = lib
 DEFINES += MODULECOMM_LIBRARY
 
+
+DEFINES += USEDBUS
+
 CONFIG += c++11
 
 # The following define makes your compiler emit warnings if you use
@@ -21,11 +26,13 @@ SOURCES += \
     modulecomm_base.cpp
 
 HEADERS += \
+    ivmodulemsg_type.h \
     modulecomm.h \
     modulecomm_base.h
 
 CONFIG += plugin
 
+
 # Default rules for deployment.
 unix {
     target.path = /usr/lib
@@ -46,7 +53,13 @@ unix {
     error( "Couldn't find the modulecomm_fastrtps.pri file!" )
 }
 
-INCLUDEPATH += $$PWD/../modulecomm_shm
-INCLUDEPATH += $$PWD/../modulecomm_fastrtps
-INCLUDEPATH += $$PWD/../modulecomm_inter
-INCLUDEPATH += $$PWD/../modulecomm_fastrtps_tcp
+
+INCLUDEPATH += $$PWD/shm
+INCLUDEPATH += $$PWD/fastrtps
+INCLUDEPATH += $$PWD/inter
+
+
+#DEFINES += USE_FASTRTPS
+#LIBS += -L$$PWD -lfastcdr -lfastrtps
+
+

+ 2 - 6
src1/driver/interface/ivlidar.pri

@@ -15,12 +15,8 @@ INCLUDEPATH += $$PWD/../../interface
 
 INCLUDEPATH += $$PWD/../../common/modulecomm
 
-INCLUDEPATH += $$PWD/../../common/modulecomm_shm
-INCLUDEPATH += $$PWD/../../common/modulecomm_fastrtps
-INCLUDEPATH += $$PWD/../../common/modulecomm_inter
+
 
 LIBS += -L$$PWD/../../common/build-modulecomm-Debug -lmodulecomm
-LIBS += -L$$PWD/../../common/build-modulecomm_fastrtps-Debug -lmodulecomm_fastrtps
-LIBS += -L$$PWD/../../common/build-modulecomm_shm-Debug -lmodulecomm_shm
-LIBS += -L$$PWD/../../common/build-modulecomm_inter-Debug -lmodulecomm_inter
+