mod_DeviceControl.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #ifndef _MOD_DEVICECONTROL_H
  2. #define _MOD_DEVICECONTROL_H
  3. #pragma once
  4. #include "modVer.h"
  5. #include "SpTest.h"
  6. #include "DeviceControlFSM.h"
  7. #include "DevEntityCommBase.hpp"
  8. // to get mac address
  9. #include <string>
  10. #include <vector>
  11. #ifdef RVC_OS_WIN
  12. #include <Winsock2.h>
  13. #include <WS2tcpip.h>
  14. #include <Iphlpapi.h>
  15. #endif // RVC_OS_WIN
  16. #pragma warning( disable : 4996 )
  17. #define MACSESION 6
  18. using namespace DeviceControl;
  19. class CDeviceControlEntity;
  20. class CDeviceControlServerSession : public DeviceControlService_ServerSessionBase
  21. {
  22. public:
  23. CDeviceControlServerSession(CDeviceControlEntity* pEntity) :m_pEntity(pEntity) {}
  24. virtual ~CDeviceControlServerSession() {}
  25. virtual void Handle_USB(SpReqAnsContext<DeviceControlService_USB_Req, DeviceControlService_USB_Ans>::Pointer ctx);
  26. virtual void Handle_GetUkeyID(SpReqAnsContext<DeviceControlService_GetUkeyID_Req, DeviceControlService_GetUkeyID_Ans>::Pointer ctx);
  27. virtual void Handle_InitToken(SpReqAnsContext<DeviceControlService_InitToken_Req, DeviceControlService_InitToken_Ans>::Pointer ctx);
  28. virtual void Handle_QueryUSBStatus(SpReqAnsContext<DeviceControlService_QueryUSBStatus_Req, DeviceControlService_QueryUSBStatus_Ans>::Pointer ctx);
  29. virtual void Handle_QueryHardwareInfo(SpReqAnsContext<DeviceControlService_QueryHardwareInfo_Req, DeviceControlService_QueryHardwareInfo_Ans>::Pointer ctx);
  30. virtual void Handle_ReadCenterConfigStr(SpReqAnsContext<DeviceControlService_ReadCenterConfigStr_Req, DeviceControlService_ReadCenterConfigStr_Ans>::Pointer ctx);
  31. virtual void Handle_ReadConfigValue(SpReqAnsContext<DeviceControlService_ReadConfigValue_Req, DeviceControlService_ReadConfigValue_Ans>::Pointer ctx);
  32. virtual void Handle_GetDevInfo(SpReqAnsContext<DeviceControlService_GetDevInfo_Req, DeviceControlService_GetDevInfo_Ans>::Pointer ctx);
  33. virtual void Handle_TestConnectivity(SpReqAnsContext<DeviceControlService_TestConnectivity_Req, DeviceControlService_TestConnectivity_Ans>::Pointer ctx);
  34. virtual void Handle_GetVendorFileList(SpReqAnsContext<DeviceControlService_GetVendorFileList_Req, DeviceControlService_GetVendorFileList_Ans>::Pointer ctx);
  35. virtual void Handle_TestAdapterFileAvailable(SpReqAnsContext<DeviceControlService_TestAdapterFileAvailable_Req, DeviceControlService_TestAdapterFileAvailable_Ans>::Pointer ctx);
  36. private:
  37. CDeviceControlEntity* m_pEntity;
  38. };
  39. class CDeviceControlEntity : public CDevAdptEntityBase
  40. {
  41. public:
  42. CDeviceControlEntity(){}
  43. virtual ~CDeviceControlEntity()
  44. {
  45. }
  46. virtual const char* GetEntityName() const { return "DeviceControl"; }
  47. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  48. ON_ENTITYT_TEST()
  49. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
  50. {
  51. LOG_FUNCTION();
  52. ErrorCodeEnum rt = m_fsm.Init(this);
  53. pTransactionContext->SendAnswer(rt);
  54. }
  55. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  56. {
  57. pTransactionContext->SendAnswer(Error_Succeed);
  58. }
  59. virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
  60. {
  61. pTransactionContext->SendAnswer(Error_Succeed);
  62. }
  63. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
  64. {
  65. m_fsm.OnExit();
  66. pTransactionContext->SendAnswer(Error_Succeed);
  67. }
  68. virtual CServerSessionBase* OnNewSession(const char*, const char*)
  69. {
  70. return new CDeviceControlServerSession(this);
  71. }
  72. void USB(SpReqAnsContext<DeviceControlService_USB_Req, DeviceControlService_USB_Ans>::Pointer ctx)
  73. {
  74. USBEvent* pEvt = new USBEvent();
  75. pEvt->ctx = ctx;
  76. m_fsm.PostEventFIFO(pEvt);
  77. }
  78. void GetUkeyID(SpReqAnsContext<DeviceControlService_GetUkeyID_Req, DeviceControlService_GetUkeyID_Ans>::Pointer ctx)
  79. {
  80. GetUkeyIDEvent* pEvt = new GetUkeyIDEvent();
  81. pEvt->ctx = ctx;
  82. m_fsm.PostEventFIFO(pEvt);
  83. }
  84. void InitToken(SpReqAnsContext<DeviceControlService_InitToken_Req, DeviceControlService_InitToken_Ans>::Pointer ctx)
  85. {
  86. InitTokenEvent* pEvt = new InitTokenEvent();
  87. pEvt->ctx = ctx;
  88. m_fsm.PostEventFIFO(pEvt);
  89. }
  90. void QueryUSBStatus(SpReqAnsContext<DeviceControlService_QueryUSBStatus_Req, DeviceControlService_QueryUSBStatus_Ans>::Pointer ctx)
  91. {
  92. QueryUSBEvent* pEvt = new QueryUSBEvent();
  93. pEvt->ctx = ctx;
  94. m_fsm.PostEventFIFO(pEvt);
  95. }
  96. void QueryHardwareInfo(SpReqAnsContext<DeviceControlService_QueryHardwareInfo_Req, DeviceControlService_QueryHardwareInfo_Ans>::Pointer ctx);
  97. void ReadCenterConfigStr(SpReqAnsContext<DeviceControlService_ReadCenterConfigStr_Req, DeviceControlService_ReadCenterConfigStr_Ans>::Pointer ctx);
  98. void ReadConfigValue(SpReqAnsContext<DeviceControlService_ReadConfigValue_Req, DeviceControlService_ReadConfigValue_Ans>::Pointer ctx);
  99. void GetDevInfo(SpReqAnsContext<DeviceControlService_GetDevInfo_Req, DeviceControlService_GetDevInfo_Ans>::Pointer ctx)
  100. {
  101. ctx->Answer(Error_NotImpl);
  102. }
  103. void TestConnectivity(SpReqAnsContext<DeviceControlService_TestConnectivity_Req, DeviceControlService_TestConnectivity_Ans>::Pointer ctx);
  104. void GetVendorFileList(SpReqAnsContext<DeviceControlService_GetVendorFileList_Req, DeviceControlService_GetVendorFileList_Ans>::Pointer ctx);
  105. void TestAdapterFileAvailable(SpReqAnsContext<DeviceControlService_TestAdapterFileAvailable_Req, DeviceControlService_TestAdapterFileAvailable_Ans>::Pointer ctx);
  106. void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
  107. {
  108. m_fsm.SelfTest(eTestType, pTransactionContext);
  109. }
  110. virtual bool IsService()const { return true; }
  111. virtual bool IsMultiThread()const { return true; }
  112. private:
  113. std::pair<ErrorCodeEnum, CSimpleStringA> __ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName);
  114. void BroadcastAdapterTestResult(const CSimpleStringA& adapterName, ErrorCodeEnum result, const CSimpleStringA& strErrMsg);
  115. private:
  116. CDeviceControlFSM m_fsm;
  117. };
  118. #endif //_MOD_DEVICECONTROL_H