modulecomm.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #include "modulecomm.h"
  2. #include <iostream>
  3. #include "modulecomm_shm.h"
  4. #include "modulecomm_inter.h"
  5. #ifdef USE_FASTRTPS
  6. #include "modulecomm_fastrtps_shm.h"
  7. #include "modulecomm_fastrtps_tcp.h"
  8. #endif
  9. namespace iv {
  10. namespace modulecomm {
  11. struct ModeduleInfo
  12. {
  13. modulecomm_base * mphandle;
  14. ModuleComm_TYPE mmctype;
  15. };
  16. void * RegisterSend(const char *strcommname, const unsigned int nBufSize, const unsigned int nMsgBufCount)
  17. {
  18. return RegisterSend(strcommname,nBufSize,nMsgBufCount,ModuleComm_SHAREMEM);
  19. }
  20. void * RegisterSend(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount,
  21. ModuleComm_TYPE xmctype,const unsigned short nport)
  22. {
  23. iv::modulecomm::ModeduleInfo * pmi = new iv::modulecomm::ModeduleInfo;
  24. pmi->mmctype = xmctype;
  25. pmi->mphandle = 0;
  26. switch (xmctype) {
  27. case ModuleComm_SHAREMEM:
  28. {
  29. iv::modulecomm_shm * p = new iv::modulecomm_shm();
  30. p->RegisterSend(strcommname,nBufSize,nMsgBufCount);
  31. pmi->mphandle = (iv::modulecomm_base *)p;
  32. }
  33. break;
  34. case ModuleComm_INTERIOR:
  35. {
  36. iv::modulecomm_inter * p = new iv::modulecomm_inter();
  37. p->RegisterSend(strcommname,nBufSize,nMsgBufCount);
  38. pmi->mphandle = (iv::modulecomm_base *)p;
  39. }
  40. break;
  41. #ifdef USE_FASTRTPS
  42. case ModuleComm_FASTRTPS:
  43. {
  44. iv::modulecomm_fastrtps_shm * p = new iv::modulecomm_fastrtps_shm();
  45. p->RegisterSend(strcommname,nBufSize,nMsgBufCount);
  46. pmi->mphandle = (iv::modulecomm_base *)p;
  47. }
  48. break;
  49. case ModuleComm_FASTRTPS_TCP:
  50. {
  51. iv::modulecomm_fastrtps_tcp * p = new iv::modulecomm_fastrtps_tcp();
  52. p->RegisterSend(strcommname,nBufSize,nMsgBufCount,nport);
  53. pmi->mphandle = (iv::modulecomm_base *)p;
  54. }
  55. break;
  56. #endif
  57. default:
  58. break;
  59. }
  60. return pmi;
  61. }
  62. void * RegisterRecv(const char *strcommname, SMCallBack pCall)
  63. {
  64. return RegisterRecv(strcommname,pCall,ModuleComm_SHAREMEM);
  65. }
  66. void * RegisterRecv(const char * strcommname,SMCallBack pCall,ModuleComm_TYPE xmctype,const char * strip,
  67. const unsigned short nPort)
  68. {
  69. iv::modulecomm::ModeduleInfo * pmi = new iv::modulecomm::ModeduleInfo;
  70. pmi->mmctype = xmctype;
  71. pmi->mphandle = 0;
  72. switch (xmctype) {
  73. case ModuleComm_SHAREMEM:
  74. {
  75. iv::modulecomm_shm * p = new iv::modulecomm_shm();
  76. p->RegisterRecv(strcommname,pCall);
  77. pmi->mphandle = (iv::modulecomm_base *)p;
  78. }
  79. break;
  80. case ModuleComm_INTERIOR:
  81. {
  82. iv::modulecomm_inter * p = new iv::modulecomm_inter();
  83. p->RegisterRecv(strcommname,pCall);
  84. pmi->mphandle = (iv::modulecomm_base *)p;
  85. }
  86. break;
  87. #ifdef USE_FASTRTPS
  88. case ModuleComm_FASTRTPS:
  89. {
  90. iv::modulecomm_fastrtps_shm * p = new iv::modulecomm_fastrtps_shm();
  91. p->RegisterRecv(strcommname,pCall);
  92. pmi->mphandle = (iv::modulecomm_base *)p;
  93. }
  94. break;
  95. case ModuleComm_FASTRTPS_TCP:
  96. {
  97. iv::modulecomm_fastrtps_tcp * p = new iv::modulecomm_fastrtps_tcp();
  98. p->RegisterRecv(strcommname,pCall,strip,nPort);
  99. pmi->mphandle = (iv::modulecomm_base *)p;
  100. }
  101. break;
  102. #endif
  103. default:
  104. break;
  105. }
  106. return pmi;
  107. }
  108. void * RegisterRecvPlus(const char *strcommname, ModuleFun xFun)
  109. {
  110. return RegisterRecvPlus(strcommname,xFun,ModuleComm_SHAREMEM);
  111. }
  112. void * RegisterRecvPlus(const char * strcommname,ModuleFun xFun,
  113. ModuleComm_TYPE xmctype,const char * strip,
  114. const unsigned short nPort)
  115. {
  116. iv::modulecomm::ModeduleInfo * pmi = new iv::modulecomm::ModeduleInfo;
  117. pmi->mmctype = xmctype;
  118. pmi->mphandle = 0;
  119. switch (xmctype) {
  120. case ModuleComm_SHAREMEM:
  121. {
  122. iv::modulecomm_shm * p = new iv::modulecomm_shm();
  123. p->RegisterRecvPlus(strcommname,xFun);
  124. pmi->mphandle = (iv::modulecomm_base *)p;
  125. }
  126. break;
  127. case ModuleComm_INTERIOR:
  128. {
  129. iv::modulecomm_inter * p = new iv::modulecomm_inter();
  130. p->RegisterRecvPlus(strcommname,xFun);
  131. pmi->mphandle = (iv::modulecomm_base *)p;
  132. }
  133. break;
  134. #ifdef USE_FASTRTPS
  135. case ModuleComm_FASTRTPS:
  136. {
  137. iv::modulecomm_fastrtps_shm * p = new iv::modulecomm_fastrtps_shm();
  138. p->RegisterRecvPlus(strcommname,xFun);
  139. pmi->mphandle = (iv::modulecomm_base *)p;
  140. }
  141. break;
  142. case ModuleComm_FASTRTPS_TCP:
  143. {
  144. iv::modulecomm_fastrtps_tcp * p = new iv::modulecomm_fastrtps_tcp();
  145. p->RegisterRecvPlus(strcommname,xFun,strip,nPort);
  146. pmi->mphandle = (iv::modulecomm_base *)p;
  147. }
  148. break;
  149. #endif
  150. default:
  151. break;
  152. }
  153. return pmi;
  154. }
  155. void ModuleSendMsg(void * pHandle,const char * strdata,const unsigned int nDataLen)
  156. {
  157. iv::modulecomm::ModeduleInfo * pmi = (iv::modulecomm::ModeduleInfo * )pHandle;
  158. if(pmi->mphandle == 0)
  159. {
  160. qDebug("handler error. use fastrtps but not define.");
  161. return;
  162. }
  163. pmi->mphandle->ModuleSendMsg(strdata,nDataLen);
  164. }
  165. void Unregister(void * pHandle)
  166. {
  167. iv::modulecomm::ModeduleInfo * pmi = (iv::modulecomm::ModeduleInfo * )pHandle;
  168. if(pmi->mphandle == 0)
  169. {
  170. qDebug("handler error. use fastrtps but not define.");
  171. return;
  172. }
  173. pmi->mphandle->Unregister();
  174. }
  175. void PauseComm(void *pHandle)
  176. {
  177. iv::modulecomm::ModeduleInfo * pmi = (iv::modulecomm::ModeduleInfo * )pHandle;
  178. if(pmi->mphandle == 0)
  179. {
  180. qDebug("handler error. use fastrtps but not define.");
  181. return;
  182. }
  183. pmi->mphandle->PauseComm();
  184. }
  185. void ContintuComm(void *pHandle)
  186. {
  187. iv::modulecomm::ModeduleInfo * pmi = (iv::modulecomm::ModeduleInfo * )pHandle;
  188. if(pmi->mphandle == 0)
  189. {
  190. qDebug("handler error. use fastrtps but not define.");
  191. return;
  192. }
  193. pmi->mphandle->ContintuComm();
  194. }
  195. }
  196. }