123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- #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<bool>
- {
- public:
- BaseJsonDataObject<string> m_MachineId;
- BaseJsonDataObject<UINT64> m_ProcId;
- BaseJsonDataObject<UINT64> 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<bool>
- {
- public:
- vector<DeviceDescript> 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<DeviceDescript>::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<DeviceDescript>::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<DeviceDescript>::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<string> *m_pbusID;
- BaseJsonDataObject<string> *m_pMachineID;
- BaseJsonDataObject<UINT64> *m_pProcID;
- BaseJsonDataObject<int> *m_pState;
- BaseJsonDataObject<int> *m_pExitFlag;
- DeviceDescriptList *m_DevList;
- BaseJsonDataObject<int> *m_pEnableEthBus;
- BaseJsonDataObject<string> *m_pEthBusRouterIp;
- BaseJsonDataObject<bool> *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
- };
|