modulecomm.cpp 5.4 KB

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