#pragma once #define BUSUNITLOGIC_API #include #include "LogicDevice.h" #define ONE_ACTION_TIMEOUT (5000) class TargetDriverInfo { public: PROCESS_INFORMATION m_info; ResDataObject m_RootBusId; ResDataObject m_DriverBusId; ResDataObject m_CcosProcInfo; public: TargetDriverInfo() { memset(&m_info, 0, sizeof(PROCESS_INFORMATION)); }; ~TargetDriverInfo() { }; }; class DeviceDescript : public BaseJsonDataObject { public: BaseJsonDataObject m_TargetType; BaseJsonDataObject m_MachineId; BaseJsonDataObject m_ProcId; BaseJsonDataObject m_Address; DeviceDescript() { SetKey(""); m_TargetType.SetKey("TargetType"); m_TargetType = ""; m_MachineId.SetKey("MachineId"); m_MachineId = ""; m_ProcId.SetKey("ProcId"); m_ProcId = 0; m_Address.SetKey("Addr"); m_Address = 0; }; ~DeviceDescript() { }; virtual void GetResDataObject(ResDataObject &obj) { ResDataObject Temp; Temp.add(m_TargetType.GetKey(), m_TargetType.GetVal()); Temp.add(m_MachineId.GetKey(), m_MachineId.GetVal()); Temp.add(m_ProcId.GetKey(), m_ProcId.GetVal()); Temp.add(m_Address.GetKey(), m_Address.GetVal()); obj.add(GetKey(), Temp); }; virtual bool SetResDataObject(ResDataObject &obj) { bool ret = true; try { const char *pKey = obj.GetKey(0); SetKey(pKey); m_ProcId = obj[0][m_ProcId.GetKey()]; m_TargetType = (const char*)obj[0][m_TargetType.GetKey()]; m_MachineId = (const char*)obj[0][m_MachineId.GetKey()]; m_Address = obj[0][m_Address.GetKey()]; } catch (...) { ret = false; } return ret; }; virtual const char *GetVal() { ResDataObject obj; obj.add(m_ProcId.GetKey(), m_ProcId.GetVal()); obj.add(m_MachineId.GetKey(), m_MachineId.GetVal()); obj.add(m_TargetType.GetKey(), m_TargetType.GetVal()); obj.add(m_Address.GetKey(), m_Address.GetVal()); (m_ValString) = obj.encode(); return m_ValString.c_str(); }; virtual bool SetVal(const char* pValString) { bool ret = true; ResDataObject obj; if (obj.decode(pValString)) { int idx; idx = obj.GetFirstOf(m_TargetType.GetKey()); if (idx >= 0) { m_TargetType.SetVal(obj[idx]); } else { ret = false; } idx = obj.GetFirstOf(m_MachineId.GetKey()); if (idx >= 0) { m_MachineId.SetVal(obj[idx]); } else { ret = false; } idx = obj.GetFirstOf(m_ProcId.GetKey()); if (idx >= 0) { m_ProcId.SetVal(obj[idx]); } else { ret = false; } idx = obj.GetFirstOf(m_Address.GetKey()); if (idx >= 0) { m_Address.SetVal(obj[idx]); } else { ret = false; } } else { ret = false; } return ret; }; }; class DeviceDescriptList : public BaseJsonDataObject { public: vector m_DeviceList; DeviceDescriptList() { SetKey("DeviceList"); }; ~DeviceDescriptList() { }; void GetResDataObject(ResDataObject &obj) { for (size_t i = 0; i < m_DeviceList.size(); i++) { ResDataObject unit; //NOT FINISHED YET //it needs get object method and needs get object context method m_DeviceList[i].GetResDataObject(unit);//the whole shit obj.add(m_DeviceList[i].GetKey(), (ResDataObject &)unit[0]);//get unit[keystring]... } }; bool SetResDataObject(ResDataObject &obj) { bool ret = true; try { m_DeviceList.clear(); size_t total = obj.size(); for (size_t i = 0; i < total; i++) { DeviceDescript descript; if (descript.SetResDataObject(obj[i]) == false) { ret = false; break; } } } catch (...) { ret = false; } return ret; }; virtual const char *GetVal() { ResDataObject obj; for (DWORD i = 0; i < m_DeviceList.size(); i++) { obj.add(m_DeviceList[i].GetKey(), m_DeviceList[i].GetVal()); } (m_ValString) = obj.encode(); return m_ValString.c_str(); }; virtual bool SetVal(const char* pValString) { bool ret = true; ResDataObject obj; m_DeviceList.clear(); try { obj.decode(pValString); for (size_t i = 0; i < obj.size(); i++) { DeviceDescript dd; dd.SetVal(obj[i].encode()); m_DeviceList.push_back(dd); } } catch (...) { ret = false; } return ret; }; virtual bool AddVal(const char* pValString) { try { DeviceDescript dd; if (dd.SetVal(pValString)) { m_DeviceList.push_back(dd); return true; } } catch (...) { } return true; }; virtual bool DelVal(const char* pValString) { //key is the path vector::iterator iter = m_DeviceList.begin(); while (iter != m_DeviceList.end()) { if (string(iter->GetKey()) == string(pValString)) { iter = m_DeviceList.erase(iter); continue; } ++iter; } return true; }; bool DelValEx(const char* pValString, DeviceDescript &ddd) { //key is the path vector::iterator iter = m_DeviceList.begin(); while (iter != m_DeviceList.end()) { if (string(iter->GetKey()) == string(pValString)) { ddd = (*iter); iter = m_DeviceList.erase(iter); return true; } ++iter; } return false; }; bool AddDriver(DeviceDescript &dd) { bool ret = true; try { for (size_t i = 0; i < m_DeviceList.size(); i++) { if (string((m_DeviceList[i].GetKey())) == string(dd.GetKey())) { return false; } } m_DeviceList.push_back(dd); } catch (...) { ret = false; } return ret; }; bool DelDriver(const char* pPath) { //key is the path vector::iterator iter = m_DeviceList.begin(); while (iter != m_DeviceList.end()) { std::string existfileLow = (iter->GetKey()); std::string filenameLow = pPath; transform(filenameLow.begin(), filenameLow.end(), filenameLow.begin(), tolower); transform(existfileLow.begin(), existfileLow.end(), existfileLow.begin(), tolower); if (existfileLow == filenameLow) { iter = m_DeviceList.erase(iter); continue; } ++iter; } return true; }; }; class DriverDescriptList : public BaseJsonDataObject { public: vector m_DriverList; DriverDescriptList() { //SetKey("DeviceList"); }; ~DriverDescriptList() { }; bool IsDriverExist(const char *pszDrvPath) { vector::iterator it = find(m_DriverList.begin(), m_DriverList.end(), pszDrvPath); if (it != m_DriverList.end()) { //already exist return true; } return false; }; bool AddDriver(const char *pszDrvPath) { vector::iterator it = find(m_DriverList.begin(), m_DriverList.end(), pszDrvPath); if (it != m_DriverList.end()) { //already exist return false; } m_DriverList.push_back(pszDrvPath); return true; }; bool DelDriver(const char* pPath) { vector::iterator it = find(m_DriverList.begin(), m_DriverList.end(), pPath); if (it != m_DriverList.end()) { m_DriverList.erase(it); return true; } return false; }; void GetResDataObject(ResDataObject &obj) { for (size_t i = 0; i < m_DriverList.size(); i++) { obj.add(m_DriverList[i].c_str(), ""); } }; }; // 此类是从 BusUnitLogic.dll 导出的 class BUSUNITLOGIC_API BusUnitLogic : public LogicDevice { bool m_bConfigRemoveDriver; protected://for internal use BaseJsonDataObject *m_pbusID; BaseJsonDataObject *m_pMachineID; BaseJsonDataObject *m_pProcID; BaseJsonDataObject *m_pState; BaseJsonDataObject *m_pExitFlag; DeviceDescriptList *m_DevList; //此BusID上挂载的设备描述列表 BaseJsonDataObject *m_pEnableEthBus; BaseJsonDataObject *m_pEthBusRouterIp; BaseJsonDataObject *m_pForTest; DriverDescriptList *m_pFullDriverList; DriverDescriptList *m_pConfigDriverList; map> *m_pProcessInfo; bool SYSTEM_CALL CheckAndKillLiveDriver(const char *pszDriverpath); void SYSTEM_CALL UnloadDriver(const char *pszBusId); public: BusUnitLogic(void); virtual ~BusUnitLogic(void); //get device type virtual bool SYSTEM_CALL GetDeviceType(GUID &DevType); //get device resource virtual RET_STATUS SYSTEM_CALL GetDeviceResource(ResDataObject PARAM_OUT *pDeviceResource); //ResourceCommand Request In and Response Out virtual RET_STATUS SYSTEM_CALL Request(ResDataObject PARAM_IN *pRequest, ResDataObject PARAM_OUT *pResponse); //notify to lower layer virtual RET_STATUS SYSTEM_CALL CmdToLogicDev(ResDataObject PARAM_IN *pCmd); //errors,warnings void SetErrorInfo(int errCode, char *pErrInfo); void SetWarningInfo(int warningCode, char *pWarningInfo); //Data Access virtual int DATA_ACTION Get(const char PARAM_IN *pKey, ResDataObject &Res); virtual int DATA_ACTION AddDeviceDescrpt(const char PARAM_IN *pDevPath,const char PARAM_IN *pTargetType, const char PARAM_IN *pMachineId, UINT64 ProcId, UINT64 Addr,bool forceAdd = false); virtual int DATA_ACTION DelDeviceDescrpt(const char PARAM_IN *pDevPath); virtual int DATA_ACTION ExitDriverProc(); int SYSTEM_CALL GetExitFlag(); int SYSTEM_CALL SetExitFlag(int ExitFlag); virtual int DATA_ACTION SetDeviceStatus(int Status);//设置设备状态 int SYSTEM_CALL GetDeviceStatus(); virtual int DATA_ACTION SetEthBusSwitch(int Switch);//设置网络EBUS开关 int SYSTEM_CALL GetEthBusSwitch(); virtual int DATA_ACTION SetEthBusRouterIp(const char PARAM_IN *pRouterIp);//设置网络EBUS的RouterIp int SYSTEM_CALL GetEthBusRouterIp(ResDataObject &obj); virtual int DATA_ACTION ForTest(bool Flag); virtual int DATA_ACTION ConfigLoadDriver(const char *pszDriverpath,char *pszFixDriverpath,DWORD FixDrvLen); virtual int DATA_ACTION ConfigRemoveDriver(const char *pszDriverpath); bool SYSTEM_CALL CheckBusIdsExistance(const char *pszBusId); bool SYSTEM_CALL LoadAllConfigDrivers(); int DATA_ACTION MakeDriverNotify(const char *pszDriverpath, bool Add); //Data Access of internal int SYSTEM_CALL GetbusId(ResDataObject &obj);// int SYSTEM_CALL GetMachineId(ResDataObject &obj);// int SYSTEM_CALL GetProcId(UINT64 &obj);// int SYSTEM_CALL SetbusId(ResDataObject &obj);// int SYSTEM_CALL SetMachineId(ResDataObject &obj);// int SYSTEM_CALL SetProcId(UINT64 obj);// DWORD SYSTEM_CALL GetDeviceCount();// bool SYSTEM_CALL GetDeviceDescript(DWORD Idx, ResDataObject &DevPath, ResDataObject &DevType, ResDataObject &MachineId, UINT64 &ProcId, UINT64 &Addr);// //Actions int LoadAllConfigDriver(bool ForReload = false); void UnloadAllRegistedDrivers(); void CheckAllLiveDriver(); };