123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508 |
- #pragma once
- #define BUSUNITLOGIC_API
- #include <algorithm>
- #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<bool>
- {
- public:
- BaseJsonDataObject<string> m_TargetType;
- BaseJsonDataObject<string> m_MachineId;
- BaseJsonDataObject<UINT64> m_ProcId;
- BaseJsonDataObject<UINT64> 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<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;
- };
- };
- class DriverDescriptList : public BaseJsonDataObject<bool>
- {
- public:
- vector<string> m_DriverList;
- DriverDescriptList()
- {
- //SetKey("DeviceList");
- };
- ~DriverDescriptList()
- {
- };
- bool IsDriverExist(const char *pszDrvPath)
- {
- vector<string>::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<string>::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<string>::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<string> *m_pbusID;
- BaseJsonDataObject<string> *m_pMachineID;
- BaseJsonDataObject<UINT64> *m_pProcID;
- BaseJsonDataObject<int> *m_pState;
- BaseJsonDataObject<int> *m_pExitFlag;
- DeviceDescriptList *m_DevList; //此BusID上挂载的设备描述列表
- BaseJsonDataObject<int> *m_pEnableEthBus;
- BaseJsonDataObject<string> *m_pEthBusRouterIp;
- BaseJsonDataObject<bool> *m_pForTest;
- DriverDescriptList *m_pFullDriverList;
- DriverDescriptList *m_pConfigDriverList;
- map<string, vector<TargetDriverInfo>> *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();
- };
|