mod_CardReadAdapter.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. // mod_CardReadAdapter.cpp : Defines the exported functions for the DLL application.
  2. //
  3. #include "stdafx.h"
  4. #pragma once
  5. #include "SpBase.h"
  6. #include "mod_CardReadAdapter.h"
  7. void CardReadAdapterServerSession::Handle_Read(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx)
  8. {
  9. LOG_FUNCTION();
  10. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("Read")("Invoke Read");
  11. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("Module:%d,lightPos:%d,bus data size:%d",ctx->Req.module,ctx->Req.lightPos,ctx->Req.businessData.GetLength());
  12. if (ctx->Req.reserved1.GetCount() > 0)
  13. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("reserved1[0]:%d",ctx->Req.reserved1[0]);
  14. m_pEntity->Read(ctx);
  15. }
  16. void CardReadAdapterServerSession::Handle_Capture(SpReqAnsContext<CardReadAdapterService_Capture_Req, CardReadAdapterService_Capture_Ans>::Pointer ctx)
  17. {
  18. LOG_FUNCTION();
  19. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("Capture")("Invoke Capture");
  20. m_pEntity->Capture(ctx);
  21. }
  22. void CardReadAdapterServerSession::Handle_Eject(SpReqAnsContext<CardReadAdapterService_Eject_Req, CardReadAdapterService_Eject_Ans>::Pointer ctx)
  23. {
  24. LOG_FUNCTION();
  25. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("Eject")("Invoke Eject");
  26. m_pEntity->Eject(ctx);
  27. }
  28. void CardReadAdapterServerSession::Handle_CancelRead(SpOnewayCallContext<CardReadAdapterService_CancelRead_Info>::Pointer ctx)
  29. {
  30. LOG_FUNCTION();
  31. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("CancelRead")("Invoke CancelRead");
  32. m_pEntity->CancelRead(ctx);
  33. }
  34. void CardReadAdapterServerSession::Handle_ReadWaitMore(SpOnewayCallContext<CardReadAdapterService_ReadWaitMore_Info>::Pointer ctx)
  35. {
  36. LOG_FUNCTION();
  37. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("ReadWaitMore")("Invoke ReadWaitMore");
  38. m_pEntity->ReadWaitMore(ctx);
  39. }
  40. void CardReadAdapterServerSession::Handle_Issue(SpReqAnsContext<CardReadAdapterService_Issue_Req, CardReadAdapterService_Issue_Ans>::Pointer ctx)
  41. {
  42. LOG_FUNCTION();
  43. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("Issue")("Invoke Issue");
  44. m_pEntity->Issue(ctx);
  45. }
  46. void CardReadAdapterServerSession::Handle_PreOnline(SpReqAnsContext<CardReadAdapterService_PreOnline_Req, CardReadAdapterService_PreOnline_Ans>::Pointer ctx)
  47. {
  48. LOG_FUNCTION();
  49. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("PreOnline")("Invoke PreOnline");
  50. if (ctx->Req.reserved2.GetCount() > 0 && !ctx->Req.reserved2[0].IsNullOrEmpty() && _strnicmp("kaku#", (const char*)ctx->Req.reserved2[0], 5) == 0)
  51. m_pEntity->PreOnline(ctx);
  52. else
  53. {
  54. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("except for kaku,other can't use preonline directly.");
  55. ctx->Answer(Error_Unexpect);
  56. }
  57. }
  58. void CardReadAdapterServerSession::Handle_PostOnline(SpReqAnsContext<CardReadAdapterService_PostOnline_Req, CardReadAdapterService_PostOnline_Ans>::Pointer ctx)
  59. {
  60. LOG_FUNCTION();
  61. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("PostOnline")("Invoke PostOnline");
  62. m_pEntity->PostOnline(ctx);
  63. }
  64. void CardReadAdapterServerSession::Handle_Exit(SpOnewayCallContext<CardReadAdapterService_Exit_Info>::Pointer ctx)
  65. {
  66. LOG_FUNCTION();
  67. m_pEntity->Exit(ctx);
  68. }
  69. void CardReadAdapterServerSession::Handle_QueryCardInfo(SpReqAnsContext<CardReadAdapterService_QueryCardInfo_Req, CardReadAdapterService_QueryCardInfo_Ans>::Pointer ctx)
  70. {
  71. LOG_FUNCTION();
  72. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("QueryCardInfo")("Invoke QueryCardInfo");
  73. m_pEntity->QueryCardInfo(ctx);
  74. }
  75. void CardReadAdapterServerSession::Handle_WriteTrack(SpReqAnsContext<CardReadAdapterService_WriteTrack_Req, CardReadAdapterService_WriteTrack_Ans>::Pointer ctx)
  76. {
  77. LOG_FUNCTION();
  78. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("WriteTrack")("Invoke WriteTrack");
  79. //Dbg("oiltest %d,%d,t1[%S],t2[%S],t3[%S],[%S]",ctx->Req.co,ctx->Req.mode,(const wchar_t *)ctx->Req.track1,(const wchar_t *)ctx->Req.track2,(const wchar_t *)ctx->Req.track3,(const wchar_t *)ctx->Req.reserved);
  80. m_pEntity->WriteTrack(ctx);
  81. }
  82. void CardReadAdapterServerSession::Handle_SetSomeFlag(SpReqAnsContext<CardReadAdapterService_SetSomeFlag_Req, CardReadAdapterService_SetSomeFlag_Ans>::Pointer ctx)
  83. {
  84. LOG_FUNCTION();
  85. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("SetSomeFlag")("Invoke SetSomeFlag");
  86. m_pEntity->SetSomeFlag(ctx);
  87. }
  88. void CardReadAdapterServerSession::Handle_GetMaterialCount(SpReqAnsContext<CardReadAdapterService_GetMaterialCount_Req, CardReadAdapterService_GetMaterialCount_Ans>::Pointer ctx)
  89. {
  90. LOG_FUNCTION();
  91. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("GetMaterialCount")("Invoke GetMaterialCount");
  92. m_pEntity->GetMaterialCount(ctx);
  93. }
  94. void CardReadAdapterServerSession::Handle_SetMaterialCount(SpReqAnsContext<CardReadAdapterService_SetMaterialCount_Req, CardReadAdapterService_SetMaterialCount_Ans>::Pointer ctx)
  95. {
  96. LOG_FUNCTION();
  97. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("SetMaterialCount")("Invoke SetMaterialCount");
  98. m_pEntity->SetMaterialCount(ctx);
  99. }
  100. void CardReadAdapterServerSession::Handle_GetSCIInfo(SpReqAnsContext<CardReadAdapterService_GetSCIInfo_Req, CardReadAdapterService_GetSCIInfo_Ans>::Pointer ctx)
  101. {
  102. LOG_FUNCTION();
  103. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("GetSCIInfo")("Invoke GetSCIInfo");
  104. m_pEntity->GetSCIInfo(ctx);
  105. }
  106. void CardReadAdapterServerSession::Handle_OpenSafeLock(SpReqAnsContext<CardReadAdapterService_OpenSafeLock_Req, CardReadAdapterService_OpenSafeLock_Ans>::Pointer ctx)
  107. {
  108. LOG_FUNCTION();
  109. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("OpenSafeLock")("Invoke OpenSafeLock");
  110. m_pEntity->OpenSafeLock(ctx);
  111. }
  112. void CardReadAdapterServerSession::Handle_MagTransferInit(SpReqAnsContext<CardReadAdapterService_MagTransferInit_Req, CardReadAdapterService_MagTransferInit_Ans>::Pointer ctx)
  113. {
  114. LOG_FUNCTION();
  115. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("MagTransferInit")("Invoke MagTransferInit");
  116. m_pEntity->MagTransferInit(ctx);
  117. }
  118. void CardReadAdapterServerSession::Handle_QueryConnInfo(SpReqAnsContext<CardReadAdapterService_QueryConnInfo_Req, CardReadAdapterService_QueryConnInfo_Ans>::Pointer ctx)
  119. {
  120. LOG_FUNCTION();
  121. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("QueryConnInfo")("Invoke QueryConnInfo");
  122. m_pEntity->QueryConnInfo(ctx);
  123. }
  124. void CardReadAdapterServerSession::Handle_GetDevInfo(SpReqAnsContext<CardReadAdapterService_GetDevInfo_Req, CardReadAdapterService_GetDevInfo_Ans>::Pointer ctx)
  125. {
  126. LOG_FUNCTION();
  127. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("GetDevInfo")("Invoke GetDevInfo");
  128. m_pEntity->GetDevInfo(ctx);
  129. }
  130. void CardReadAdapterServerSession::Handle_SAMICCommand(SpReqAnsContext<CardReadAdapterService_SAMICCommand_Req, CardReadAdapterService_SAMICCommand_Ans>::Pointer ctx)
  131. {
  132. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("SAMICCommand")("Invoke SAMICCommand");
  133. m_pEntity->SAMICCommand(ctx);
  134. }
  135. void CardReadAdapterServerSession::Handle_QueryPrinterStatus(SpReqAnsContext<CardReadAdapterService_QueryPrinterStatus_Req, CardReadAdapterService_QueryPrinterStatus_Ans>::Pointer ctx)
  136. {
  137. LOG_FUNCTION();
  138. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("QueryPrinterStatus")("Invoke QueryPrinterStatus");
  139. m_pEntity->QueryPrinterStatus(ctx);
  140. }
  141. void CardReadAdapterServerSession::Handle_Print(SpReqAnsContext<CardReadAdapterService_Print_Req, CardReadAdapterService_Print_Ans>::Pointer ctx)
  142. {
  143. LOG_FUNCTION();
  144. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("Print")("Invoke Print");
  145. m_pEntity->Print(ctx);
  146. }
  147. void CardReadAdapterServerSession::Handle_QuerySCIList(SpReqAnsContext<CardReadAdapterService_QuerySCIList_Req, CardReadAdapterService_QuerySCIList_Ans>::Pointer ctx)
  148. {
  149. LOG_FUNCTION();
  150. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("QuerySCIList")("Invoke QuerySCIList");
  151. m_pEntity->QuerySCIList(ctx);
  152. }
  153. void CardReadAdapterServerSession::Handle_BindSCI(SpReqAnsContext<CardReadAdapterService_BindSCI_Req, CardReadAdapterService_BindSCI_Ans>::Pointer ctx)
  154. {
  155. LOG_FUNCTION();
  156. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("BindSCI")("Invoke BindSCI");
  157. m_pEntity->BindSCI(ctx);
  158. }
  159. void CardReadAdapterServerSession::Handle_PreOnlineOnStore(SpReqAnsContext<CardReadAdapterService_PreOnlineOnStore_Req, CardReadAdapterService_PreOnlineOnStore_Ans>::Pointer ctx)
  160. {
  161. LOG_FUNCTION();
  162. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("PreOnlineOnStore")("Invoke PreOnlineOnStore");
  163. m_pEntity->PreOnlineOnStore(ctx);
  164. }
  165. void CardReadAdapterServerSession::Handle_NotifyPreonline(SpReqAnsContext<CardReadAdapterService_NotifyPreonline_Req, CardReadAdapterService_NotifyPreonline_Ans>::Pointer ctx)
  166. {
  167. LOG_FUNCTION();
  168. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("NotifyPreonline")("Invoke NotifyPreonline");
  169. m_pEntity->NotifyPreonline(ctx);
  170. }
  171. void CardReadAdapterServerSession::Handle_QueryCardInfoOnStore(SpReqAnsContext<CardReadAdapterService_QueryCardInfoOnStore_Req, CardReadAdapterService_QueryCardInfoOnStore_Ans>::Pointer ctx)
  172. {
  173. LOG_FUNCTION();
  174. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("QueryCardInfoOnStore")("Invoke QueryCardInfoOnStore");
  175. m_pEntity->QueryCardInfoOnStore(ctx);
  176. }
  177. void CardReadAdapterServerSession::Handle_GetAddCardInfo(SpReqAnsContext<CardReadAdapterService_GetAddCardInfo_Req, CardReadAdapterService_GetAddCardInfo_Ans>::Pointer ctx)
  178. {
  179. LOG_FUNCTION();
  180. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("GetAddCardInfo")("Invoke GetAddCardInfo");
  181. m_pEntity->GetAddCardInfo(ctx);
  182. }
  183. void CardReadAdapterServerSession::Handle_Test1(SpReqAnsContext<CardReadAdapterService_Test1_Req, CardReadAdapterService_Test1_Ans>::Pointer ctx)
  184. {
  185. LOG_FUNCTION();
  186. //m_pEntity->Test1(ctx);
  187. }
  188. void CardReadAdapterServerSession::Handle_Test2(SpReqAnsContext<CardReadAdapterService_Test2_Req, CardReadAdapterService_Test2_Ans>::Pointer ctx)
  189. {
  190. LOG_FUNCTION();
  191. //m_pEntity->Test2(ctx);
  192. }
  193. void CardReadAdapterServerSession::Handle_CrossTermCall(SpReqAnsContext<CardReadAdapterService_CrossTermCall_Req, CardReadAdapterService_CrossTermCall_Ans>::Pointer ctx)
  194. {
  195. LOG_FUNCTION();
  196. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("CrossTermCall")("Invoke CrossTermCall");
  197. m_pEntity->CrossTermCall(ctx);
  198. }
  199. void CardReadAdapterServerSession::Handle_CrossTermInvokeInfo(SpOnewayCallContext<CardReadAdapterService_CrossTermInvokeInfo_Info>::Pointer ctx)
  200. {
  201. LOG_FUNCTION();
  202. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("CrossTermInvokeInfo")("Invoke CrossTermInvokeInfo");
  203. m_pEntity->CrossTermInvokeInfo(ctx);
  204. }
  205. void CardReadAdapterServerSession::Handle_PrintCardImmediately(SpReqAnsContext<CardReadAdapterService_PrintCardImmediately_Req, CardReadAdapterService_PrintCardImmediately_Ans>::Pointer ctx)
  206. {
  207. LOG_FUNCTION();
  208. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("PrintCardImmediately")("Invoke PrintCardImmediately");
  209. m_pEntity->PrintCardImmediately(ctx);
  210. }
  211. void CardReadAdapterServerSession::Handle_QueryCIStatus(SpReqAnsContext<CardReadAdapterService_QueryCIStatus_Req, CardReadAdapterService_QueryCIStatus_Ans>::Pointer ctx)
  212. {
  213. LOG_FUNCTION();
  214. DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI("QueryCIStatus")("Invoke QueryCIStatus");
  215. m_pEntity->QueryCIStatus(ctx);
  216. }
  217. void CCardReadAdapterEntity::OnBroadcastEvent(CUUID SubID, const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer)
  218. {
  219. if (dwMessageSignature != eMsgSig_FetchCard && dwMessageSignature != eMsgSig_SCIConnect && dwMessageSignature != eMsgSig_ConnectStatus)
  220. return;
  221. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("OnBroadcastEvent,msg:%s,%d,%d",pszEntityName,dwMessageId,dwMessageSignature);
  222. if (_strnicmp(pszEntityName, "CardIssuer", strlen("CardIssuer")) == 0)
  223. {
  224. if (dwMessageSignature == eMsgSig_FetchCard)
  225. {
  226. CardIssuer::FetchCard fc;
  227. SpBuffer2Object(Buffer, fc);
  228. CardIsserFetchCard evt;
  229. evt.status = fc.status;
  230. SpSendBroadcast(GetFunction(), SP_MSG_OF(CardIsserFetchCard), SP_MSG_SIG_OF(CardIsserFetchCard), evt);
  231. }
  232. else if (dwMessageSignature == eMsgSig_SCIConnect)
  233. {
  234. CardIssuer::SCIConnect scic;
  235. SpBuffer2Object(Buffer, scic);
  236. CardIssuerSCIConnect evt;
  237. evt.status = scic.status;
  238. SpSendBroadcast(GetFunction(), SP_MSG_OF(CardIssuerSCIConnect), SP_MSG_SIG_OF(CardIssuerSCIConnect), evt);
  239. }
  240. }
  241. else if (_strnicmp(pszEntityName, "ContactlessCard", strlen("ContactlessCard")) == 0)
  242. {
  243. if (dwMessageSignature == eMsgSig_FetchCard)
  244. {
  245. ContactlessCard::FetchCard fc;
  246. SpBuffer2Object(Buffer, fc);
  247. if (fc.status == 3){//oilyang@20181210 cancel read as have detect card in ContactlessCard
  248. if(m_fsm.GetMachineType() == MachineType_RVC_DESK2S)
  249. m_fsm.CancelReadForEntity(Module_CardSwiper);
  250. else{
  251. m_fsm.CancelReadForEntity(Module_CardIssuer);
  252. }
  253. }
  254. else
  255. {
  256. ContactlessCardFetchCard evt;
  257. evt.status = fc.status;
  258. SpSendBroadcast(GetFunction(), SP_MSG_OF(ContactlessCardFetchCard), SP_MSG_SIG_OF(ContactlessCardFetchCard), evt);
  259. }
  260. }
  261. }
  262. else if (_strnicmp(pszEntityName, "CardSwiper", strlen("CardSwiper")) == 0)
  263. {
  264. if (dwMessageSignature == eMsgSig_FetchCard)
  265. {
  266. CardSwiper::FetchCard fc;
  267. SpBuffer2Object(Buffer, fc);
  268. if (fc.status == 3)//oilyang@20190507 cancel read as have detect card in CardSwiper
  269. m_fsm.CancelReadForEntity(Module_ContactlessCard);
  270. else
  271. {
  272. CardSwiperFetchCard evt;
  273. evt.status = fc.status;
  274. SpSendBroadcast(GetFunction(), SP_MSG_OF(CardSwiperFetchCard), SP_MSG_SIG_OF(CardSwiperFetchCard), evt);
  275. }
  276. }
  277. else if (dwMessageSignature == eMsgSig_ConnectStatus)
  278. {
  279. CardSwiper::ConnectStatus cs;
  280. SpBuffer2Object(Buffer, cs);
  281. CardSwiperConnectStatus evt;
  282. evt.status = cs.status;
  283. SpSendBroadcast(GetFunction(), SP_MSG_OF(CardSwiperConnectStatus), SP_MSG_SIG_OF(CardSwiperConnectStatus), evt);
  284. }
  285. }
  286. }
  287. SP_BEGIN_ENTITY_MAP()
  288. SP_ENTITY(CCardReadAdapterEntity)
  289. SP_END_ENTITY_MAP()