mod_DeviceControl.h 5.8 KB

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