123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- #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
- #include <QtXml>
- #include <QFile>
- namespace iv {
- namespace modulecomm {
- struct ModeduleInfo
- {
- modulecomm_base * mphandle;
- ModuleComm_TYPE mmctype;
- };
- static ModuleComm_TYPE getdefmodulecommtype()
- {
- #ifdef ANDROID
- return ModuleComm_INTERIOR;
- #endif
- ModuleComm_TYPE xrtn = ModuleComm_SHAREMEM;
- QDomDocument xdoc;
- QFile file("./modulecomm.xml");
- if (!file.open(QIODevice::ReadOnly))
- {
- return xrtn;
- }
- if (!xdoc.setContent(&file)) {
- file.close();
- return xrtn;
- }
- file.close();
- QDomElement docElem = xdoc.documentElement();
- QDomNode n = docElem.firstChild();
- while(!n.isNull())
- {
- QDomElement e = n.toElement();
- if(e.nodeName() == "commtype")
- {
- QString strvalue = e.attribute("value","0");
- if(strvalue == "0")
- {
- xrtn = ModuleComm_SHAREMEM;
- }
- if(strvalue == "1")
- {
- xrtn = ModuleComm_INTERIOR;
- }
- #ifdef USE_FASTRTPS
- if(strvalue == "2")
- {
- xrtn = ModuleComm_FASTRTPS;
- }
- #endif
- break;
- }
- n = n.nextSibling();
- }
- return xrtn;
- }
- void * RegisterSend(const char * strcommname)
- {
- return RegisterSend(strcommname,1000,1);
- }
- void * RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount,
- ModuleComm_TYPE xmctype,const unsigned short nport)
- {
- iv::modulecomm::ModeduleInfo * pmi = new iv::modulecomm::ModeduleInfo;
- pmi->mmctype = xmctype;
- pmi->mphandle = 0;
- ModuleComm_TYPE mctype = xmctype;
- if(mctype == ModuleComm_UNDEFINE)
- {
- mctype = getdefmodulecommtype();
- }
- switch (mctype) {
- case ModuleComm_SHAREMEM:
- {
- iv::modulecomm_shm * p = new iv::modulecomm_shm();
- p->RegisterSend(strcommname,nBufSize,nMsgBufCount);
- pmi->mphandle = (iv::modulecomm_base *)p;
- }
- break;
- case ModuleComm_INTERIOR:
- {
- 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:
- {
- 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;
- }
- return pmi;
- }
- 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;
- pmi->mphandle = 0;
- ModuleComm_TYPE mctype = xmctype;
- if(mctype == ModuleComm_UNDEFINE)
- {
- mctype = getdefmodulecommtype();
- }
- switch (mctype) {
- case ModuleComm_SHAREMEM:
- {
- iv::modulecomm_shm * p = new iv::modulecomm_shm();
- p->RegisterRecv(strcommname,pCall);
- pmi->mphandle = (iv::modulecomm_base *)p;
- }
- break;
- case ModuleComm_INTERIOR:
- {
- 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:
- {
- 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;
- }
- return pmi;
- }
- void * RegisterRecvPlus(const char * strcommname,ModuleFun xFun,
- ModuleComm_TYPE xmctype,const char * strip,
- const unsigned short nPort)
- {
- iv::modulecomm::ModeduleInfo * pmi = new iv::modulecomm::ModeduleInfo;
- pmi->mmctype = xmctype;
- pmi->mphandle = 0;
- ModuleComm_TYPE mctype = xmctype;
- if(mctype == ModuleComm_UNDEFINE)
- {
- mctype = getdefmodulecommtype();
- }
- switch (mctype) {
- case ModuleComm_SHAREMEM:
- {
- iv::modulecomm_shm * p = new iv::modulecomm_shm();
- p->RegisterRecvPlus(strcommname,xFun);
- pmi->mphandle = (iv::modulecomm_base *)p;
- }
- break;
- case ModuleComm_INTERIOR:
- {
- 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:
- {
- 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;
- }
- return pmi;
- }
- void ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen)
- {
- iv::modulecomm::ModeduleInfo * pmi = (iv::modulecomm::ModeduleInfo * )pHandle;
- 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;
- 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;
- 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;
- if(pmi->mphandle == 0)
- {
- qDebug("handler error. use fastrtps but not define.");
- return;
- }
- pmi->mphandle->ContintuComm();
- }
- }
- }
|