#pragma once // 下列 ifdef 块是创建使从 DLL 导出更简单的 // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 BUSUNITLOGIC_EXPORTS // 符号编译的。在使用此 DLL 的 // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将 // BUSUNITLOGIC_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的 // 符号视为是被导出的。 #ifndef BUSUNITLOGIC_EXPORTS #ifdef _WIN64 #ifdef _DEBUG #pragma comment(lib, "BusUnitLogicX64D.lib") #else #pragma comment(lib, "BusUnitLogicX64.lib") #endif #else #ifdef _DEBUG #pragma comment(lib, "BusUnitLogicD.lib") #else #pragma comment(lib, "BusUnitLogic.lib") #endif #endif #endif #ifdef BUSUNITLOGIC_EXPORTS #define BUSUNITLOGIC_API __declspec(dllexport) #else #define BUSUNITLOGIC_API __declspec(dllimport) #endif #include "LogicDevice.h" class DeviceDescript : public BaseJsonDataObject { public: BaseJsonDataObject m_MachineId; BaseJsonDataObject m_ProcId; BaseJsonDataObject m_Address; DeviceDescript() { SetKey(""); 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_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_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_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_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; }; }; // 此类是从 BusUnitLogic.dll 导出的 class BUSUNITLOGIC_API BusUnitLogic : public LogicDevice { protected://for internal use BaseJsonDataObject *m_pbusID; BaseJsonDataObject *m_pMachineID; BaseJsonDataObject *m_pProcID; BaseJsonDataObject *m_pState; BaseJsonDataObject *m_pExitFlag; DeviceDescriptList *m_DevList; BaseJsonDataObject *m_pEnableEthBus; BaseJsonDataObject *m_pEthBusRouterIp; BaseJsonDataObject *m_pForTest; 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 *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); //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 &MachineId, UINT64 &ProcId, UINT64 &Addr);// //Actions };