mod_DeviceControl.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #else
  16. #include "SpTest.h"
  17. #endif // RVC_OS_WIN
  18. #pragma warning( disable : 4996 )
  19. #define MACSESION 6
  20. using namespace DeviceControl;
  21. class CDeviceControlEntity;
  22. class CDeviceControlServerSession : public DeviceControlService_ServerSessionBase
  23. {
  24. public:
  25. CDeviceControlServerSession(CDeviceControlEntity* pEntity) :m_pEntity(pEntity) {}
  26. virtual ~CDeviceControlServerSession() {}
  27. virtual void Handle_USB(SpReqAnsContext<DeviceControlService_USB_Req, DeviceControlService_USB_Ans>::Pointer ctx);
  28. virtual void Handle_GetUkeyID(SpReqAnsContext<DeviceControlService_GetUkeyID_Req, DeviceControlService_GetUkeyID_Ans>::Pointer ctx);
  29. virtual void Handle_InitToken(SpReqAnsContext<DeviceControlService_InitToken_Req, DeviceControlService_InitToken_Ans>::Pointer ctx);
  30. virtual void Handle_QueryUSBStatus(SpReqAnsContext<DeviceControlService_QueryUSBStatus_Req, DeviceControlService_QueryUSBStatus_Ans>::Pointer ctx);
  31. virtual void Handle_QueryHardwareInfo(SpReqAnsContext<DeviceControlService_QueryHardwareInfo_Req, DeviceControlService_QueryHardwareInfo_Ans>::Pointer ctx);
  32. virtual void Handle_ReadCenterConfigStr(SpReqAnsContext<DeviceControlService_ReadCenterConfigStr_Req, DeviceControlService_ReadCenterConfigStr_Ans>::Pointer ctx);
  33. virtual void Handle_ReadConfigValue(SpReqAnsContext<DeviceControlService_ReadConfigValue_Req, DeviceControlService_ReadConfigValue_Ans>::Pointer ctx);
  34. virtual void Handle_GetDevInfo(SpReqAnsContext<DeviceControlService_GetDevInfo_Req, DeviceControlService_GetDevInfo_Ans>::Pointer ctx);
  35. virtual void Handle_TestConnectivity(SpReqAnsContext<DeviceControlService_TestConnectivity_Req, DeviceControlService_TestConnectivity_Ans>::Pointer ctx);
  36. virtual void Handle_GetVendorFileList(SpReqAnsContext<DeviceControlService_GetVendorFileList_Req, DeviceControlService_GetVendorFileList_Ans>::Pointer ctx);
  37. virtual void Handle_TestAdapterFileAvailable(SpReqAnsContext<DeviceControlService_TestAdapterFileAvailable_Req, DeviceControlService_TestAdapterFileAvailable_Ans>::Pointer ctx);
  38. private:
  39. CDeviceControlEntity* m_pEntity;
  40. };
  41. class CDeviceControlEntity : public CDevAdptEntityBase
  42. {
  43. public:
  44. CDeviceControlEntity(){}
  45. virtual ~CDeviceControlEntity()
  46. {
  47. }
  48. virtual const char* GetEntityName() const { return "DeviceControl"; }
  49. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  50. #if defined(RVC_OS_LINUX)
  51. ON_ENTITYT_TEST()
  52. #endif //RVC_OS_LINUX
  53. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext);
  54. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  55. {
  56. pTransactionContext->SendAnswer(Error_Succeed);
  57. }
  58. virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
  59. {
  60. pTransactionContext->SendAnswer(Error_Succeed);
  61. }
  62. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
  63. {
  64. m_fsm.OnExit();
  65. pTransactionContext->SendAnswer(Error_Succeed);
  66. }
  67. virtual CServerSessionBase* OnNewSession(const char*, const char*)
  68. {
  69. return new CDeviceControlServerSession(this);
  70. }
  71. void USB(SpReqAnsContext<DeviceControlService_USB_Req, DeviceControlService_USB_Ans>::Pointer ctx)
  72. {
  73. ctx->Answer(Error_NotSupport);
  74. }
  75. void GetUkeyID(SpReqAnsContext<DeviceControlService_GetUkeyID_Req, DeviceControlService_GetUkeyID_Ans>::Pointer ctx)
  76. {
  77. ctx->Answer(Error_NotSupport);
  78. }
  79. void InitToken(SpReqAnsContext<DeviceControlService_InitToken_Req, DeviceControlService_InitToken_Ans>::Pointer ctx)
  80. {
  81. ctx->Answer(Error_NotSupport);
  82. }
  83. void QueryUSBStatus(SpReqAnsContext<DeviceControlService_QueryUSBStatus_Req, DeviceControlService_QueryUSBStatus_Ans>::Pointer ctx)
  84. {
  85. ctx->Answer(Error_NotSupport);
  86. }
  87. void QueryHardwareInfo(SpReqAnsContext<DeviceControlService_QueryHardwareInfo_Req, DeviceControlService_QueryHardwareInfo_Ans>::Pointer ctx);
  88. void ReadCenterConfigStr(SpReqAnsContext<DeviceControlService_ReadCenterConfigStr_Req, DeviceControlService_ReadCenterConfigStr_Ans>::Pointer ctx);
  89. void ReadConfigValue(SpReqAnsContext<DeviceControlService_ReadConfigValue_Req, DeviceControlService_ReadConfigValue_Ans>::Pointer ctx);
  90. void GetDevInfo(SpReqAnsContext<DeviceControlService_GetDevInfo_Req, DeviceControlService_GetDevInfo_Ans>::Pointer ctx)
  91. {
  92. ctx->Answer(Error_NotImpl);
  93. }
  94. void TestConnectivity(SpReqAnsContext<DeviceControlService_TestConnectivity_Req, DeviceControlService_TestConnectivity_Ans>::Pointer ctx);
  95. void GetVendorFileList(SpReqAnsContext<DeviceControlService_GetVendorFileList_Req, DeviceControlService_GetVendorFileList_Ans>::Pointer ctx);
  96. void TestAdapterFileAvailable(SpReqAnsContext<DeviceControlService_TestAdapterFileAvailable_Req, DeviceControlService_TestAdapterFileAvailable_Ans>::Pointer ctx);
  97. void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
  98. {
  99. m_fsm.SelfTest(eTestType, pTransactionContext);
  100. }
  101. virtual bool IsService()const { return true; }
  102. virtual bool IsMultiThread()const { return true; }
  103. private:
  104. std::pair<ErrorCodeEnum, CSimpleStringA> __ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName);
  105. void BroadcastAdapterTestResult(const CSimpleStringA& adapterName, ErrorCodeEnum result, const CSimpleStringA& strErrMsg);
  106. private:
  107. CDeviceControlFSM m_fsm;
  108. };
  109. #endif //_MOD_DEVICECONTROL_H