mod_DeviceControl.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. private:
  34. CDeviceControlEntity *m_pEntity;
  35. };
  36. class CDeviceControlEntity : public CDevAdptEntityBase
  37. {
  38. public:
  39. CDeviceControlEntity(){}
  40. virtual ~CDeviceControlEntity(){}
  41. virtual const char *GetEntityName() const { return "DeviceControl"; }
  42. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  43. ON_ENTITYT_TEST()
  44. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  45. {
  46. LOG_FUNCTION();
  47. ErrorCodeEnum rt = m_fsm.Init(this);
  48. pTransactionContext->SendAnswer(rt);
  49. }
  50. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  51. {
  52. QueryHardwareInfo(NULL);
  53. pTransactionContext->SendAnswer(Error_Succeed);
  54. }
  55. virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
  56. {
  57. pTransactionContext->SendAnswer(Error_Succeed);
  58. }
  59. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  60. {
  61. m_fsm.OnExit();
  62. pTransactionContext->SendAnswer(Error_Succeed);
  63. }
  64. virtual CServerSessionBase* OnNewSession(const char*,const char*)
  65. {
  66. return new CDeviceControlServerSession(this);
  67. }
  68. void USB(SpReqAnsContext<DeviceControlService_USB_Req, DeviceControlService_USB_Ans>::Pointer ctx)
  69. {
  70. USBEvent *pEvt = new USBEvent();
  71. pEvt->ctx = ctx;
  72. m_fsm.PostEventFIFO(pEvt);
  73. }
  74. void GetUkeyID(SpReqAnsContext<DeviceControlService_GetUkeyID_Req, DeviceControlService_GetUkeyID_Ans>::Pointer ctx)
  75. {
  76. GetUkeyIDEvent *pEvt = new GetUkeyIDEvent();
  77. pEvt->ctx = ctx;
  78. m_fsm.PostEventFIFO(pEvt);
  79. }
  80. void InitToken(SpReqAnsContext<DeviceControlService_InitToken_Req, DeviceControlService_InitToken_Ans>::Pointer ctx)
  81. {
  82. InitTokenEvent *pEvt = new InitTokenEvent();
  83. pEvt->ctx = ctx;
  84. m_fsm.PostEventFIFO(pEvt);
  85. }
  86. void QueryUSBStatus(SpReqAnsContext<DeviceControlService_QueryUSBStatus_Req, DeviceControlService_QueryUSBStatus_Ans>::Pointer ctx)
  87. {
  88. QueryUSBEvent *pEvt = new QueryUSBEvent();
  89. pEvt->ctx = ctx;
  90. m_fsm.PostEventFIFO(pEvt);
  91. }
  92. void QueryHardwareInfo(SpReqAnsContext<DeviceControlService_QueryHardwareInfo_Req, DeviceControlService_QueryHardwareInfo_Ans>::Pointer ctx);
  93. void ReadCenterConfigStr(SpReqAnsContext<DeviceControlService_ReadCenterConfigStr_Req, DeviceControlService_ReadCenterConfigStr_Ans>::Pointer ctx);
  94. void ReadConfigValue(SpReqAnsContext<DeviceControlService_ReadConfigValue_Req, DeviceControlService_ReadConfigValue_Ans>::Pointer ctx);
  95. void GetDevInfo(SpReqAnsContext<DeviceControlService_GetDevInfo_Req, DeviceControlService_GetDevInfo_Ans>::Pointer ctx)
  96. {
  97. ctx->Answer(Error_NotImpl);
  98. }
  99. void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  100. {
  101. m_fsm.SelfTest(eTestType,pTransactionContext);
  102. }
  103. virtual bool IsService()const{return true;}
  104. virtual bool IsMultiThread()const{return true;}
  105. private:
  106. std::pair<ErrorCodeEnum, CSimpleStringA> __ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName);
  107. private:
  108. CDeviceControlFSM m_fsm;
  109. };
  110. #endif //_MOD_DEVICECONTROL_H