123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #ifndef _MOD_DEVICECONTROL_H
- #define _MOD_DEVICECONTROL_H
- #pragma once
- #include "modVer.h"
- #include "SpTest.h"
- #include "DeviceControlFSM.h"
- #include "DevEntityCommBase.hpp"
- // to get mac address
- #include <string>
- #include <vector>
- #ifdef RVC_OS_WIN
- #include <Winsock2.h>
- #include <WS2tcpip.h>
- #include <Iphlpapi.h>
- #endif // RVC_OS_WIN
- #pragma warning( disable : 4996 )
- #define MACSESION 6
- using namespace DeviceControl;
- class CDeviceControlEntity;
- class CDeviceControlServerSession : public DeviceControlService_ServerSessionBase
- {
- public:
- CDeviceControlServerSession(CDeviceControlEntity* pEntity) :m_pEntity(pEntity) {}
- virtual ~CDeviceControlServerSession() {}
- virtual void Handle_USB(SpReqAnsContext<DeviceControlService_USB_Req, DeviceControlService_USB_Ans>::Pointer ctx);
- virtual void Handle_GetUkeyID(SpReqAnsContext<DeviceControlService_GetUkeyID_Req, DeviceControlService_GetUkeyID_Ans>::Pointer ctx);
- virtual void Handle_InitToken(SpReqAnsContext<DeviceControlService_InitToken_Req, DeviceControlService_InitToken_Ans>::Pointer ctx);
- virtual void Handle_QueryUSBStatus(SpReqAnsContext<DeviceControlService_QueryUSBStatus_Req, DeviceControlService_QueryUSBStatus_Ans>::Pointer ctx);
- virtual void Handle_QueryHardwareInfo(SpReqAnsContext<DeviceControlService_QueryHardwareInfo_Req, DeviceControlService_QueryHardwareInfo_Ans>::Pointer ctx);
- virtual void Handle_ReadCenterConfigStr(SpReqAnsContext<DeviceControlService_ReadCenterConfigStr_Req, DeviceControlService_ReadCenterConfigStr_Ans>::Pointer ctx);
- virtual void Handle_ReadConfigValue(SpReqAnsContext<DeviceControlService_ReadConfigValue_Req, DeviceControlService_ReadConfigValue_Ans>::Pointer ctx);
- virtual void Handle_GetDevInfo(SpReqAnsContext<DeviceControlService_GetDevInfo_Req, DeviceControlService_GetDevInfo_Ans>::Pointer ctx);
- virtual void Handle_TestConnectivity(SpReqAnsContext<DeviceControlService_TestConnectivity_Req, DeviceControlService_TestConnectivity_Ans>::Pointer ctx);
- virtual void Handle_GetVendorFileList(SpReqAnsContext<DeviceControlService_GetVendorFileList_Req, DeviceControlService_GetVendorFileList_Ans>::Pointer ctx);
- virtual void Handle_TestAdapterFileAvailable(SpReqAnsContext<DeviceControlService_TestAdapterFileAvailable_Req, DeviceControlService_TestAdapterFileAvailable_Ans>::Pointer ctx);
- private:
- CDeviceControlEntity* m_pEntity;
- };
- class CDeviceControlEntity : public CDevAdptEntityBase
- {
- public:
- CDeviceControlEntity(){}
- virtual ~CDeviceControlEntity()
- {
- }
- virtual const char* GetEntityName() const { return "DeviceControl"; }
- const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
- ON_ENTITYT_TEST()
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- ErrorCodeEnum rt = m_fsm.Init(this);
- pTransactionContext->SendAnswer(rt);
- }
- virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_fsm.OnExit();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual CServerSessionBase* OnNewSession(const char*, const char*)
- {
- return new CDeviceControlServerSession(this);
- }
- void USB(SpReqAnsContext<DeviceControlService_USB_Req, DeviceControlService_USB_Ans>::Pointer ctx)
- {
- USBEvent* pEvt = new USBEvent();
- pEvt->ctx = ctx;
- m_fsm.PostEventFIFO(pEvt);
- }
- void GetUkeyID(SpReqAnsContext<DeviceControlService_GetUkeyID_Req, DeviceControlService_GetUkeyID_Ans>::Pointer ctx)
- {
- GetUkeyIDEvent* pEvt = new GetUkeyIDEvent();
- pEvt->ctx = ctx;
- m_fsm.PostEventFIFO(pEvt);
- }
- void InitToken(SpReqAnsContext<DeviceControlService_InitToken_Req, DeviceControlService_InitToken_Ans>::Pointer ctx)
- {
- InitTokenEvent* pEvt = new InitTokenEvent();
- pEvt->ctx = ctx;
- m_fsm.PostEventFIFO(pEvt);
- }
- void QueryUSBStatus(SpReqAnsContext<DeviceControlService_QueryUSBStatus_Req, DeviceControlService_QueryUSBStatus_Ans>::Pointer ctx)
- {
- QueryUSBEvent* pEvt = new QueryUSBEvent();
- pEvt->ctx = ctx;
- m_fsm.PostEventFIFO(pEvt);
- }
- void QueryHardwareInfo(SpReqAnsContext<DeviceControlService_QueryHardwareInfo_Req, DeviceControlService_QueryHardwareInfo_Ans>::Pointer ctx);
- void ReadCenterConfigStr(SpReqAnsContext<DeviceControlService_ReadCenterConfigStr_Req, DeviceControlService_ReadCenterConfigStr_Ans>::Pointer ctx);
- void ReadConfigValue(SpReqAnsContext<DeviceControlService_ReadConfigValue_Req, DeviceControlService_ReadConfigValue_Ans>::Pointer ctx);
- void GetDevInfo(SpReqAnsContext<DeviceControlService_GetDevInfo_Req, DeviceControlService_GetDevInfo_Ans>::Pointer ctx)
- {
- ctx->Answer(Error_NotImpl);
- }
- void TestConnectivity(SpReqAnsContext<DeviceControlService_TestConnectivity_Req, DeviceControlService_TestConnectivity_Ans>::Pointer ctx);
- void GetVendorFileList(SpReqAnsContext<DeviceControlService_GetVendorFileList_Req, DeviceControlService_GetVendorFileList_Ans>::Pointer ctx);
- void TestAdapterFileAvailable(SpReqAnsContext<DeviceControlService_TestAdapterFileAvailable_Req, DeviceControlService_TestAdapterFileAvailable_Ans>::Pointer ctx);
- void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_fsm.SelfTest(eTestType, pTransactionContext);
- }
- virtual bool IsService()const { return true; }
- virtual bool IsMultiThread()const { return true; }
- private:
- std::pair<ErrorCodeEnum, CSimpleStringA> __ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName);
- void BroadcastAdapterTestResult(const CSimpleStringA& adapterName, ErrorCodeEnum result, const CSimpleStringA& strErrMsg);
- private:
- CDeviceControlFSM m_fsm;
- };
- #endif //_MOD_DEVICECONTROL_H
|