123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- // BusUnitClient.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include "PacketAnalizer.h"
- #include "BusUnitClient.h"
- // 这是已导出类的构造函数。
- // 有关类定义的信息,请参阅 BusUnitClient.h
- BusUnitClient::BusUnitClient()
- {
- pLogicDeivce = (LogicDevice*)this;
- //m_pSysIF->SetLogicDevice(pLogicDeivce);
- }
- BusUnitClient::~BusUnitClient()
- {
- return;
- }
- BusUnitClient& BusUnitClient::operator = (const BusUnitClient &tValue)
- {
- //strongly recommended do not assign a client to another one
- if (this != &tValue)
- {
- m_FileFlags = tValue.m_FileFlags;
- (*m_pFilePath) = (*(tValue.m_pFilePath));
- //do open
- if (tValue.m_ClosedFlag == false)
- {
- if (Open((tValue.m_pFilePath)->c_str(), (CCOS_FILE_FLAGS)tValue.m_FileFlags) <= 0)
- {
- //failed here
- //put some log
- printf("Thread:%d,Open Failed\n", GetCurrentThreadId());
- }
- }
- }
- return (*this);
- }
- PACKET_CMD BusUnitClient::ReadCmd(ResDataObject &CmdObject)
- {
- PACKET_CMD ret = PACKET_CMD_NONE;
- if (IsDataArrived())
- {
- ret = LogicClient::ReadCmd(CmdObject);
- ResDataObject Context;
- string key = PacketAnalizer::GetPacketKey(&CmdObject);
- if (PacketAnalizer::GetPacketContext(&CmdObject, Context) == false)
- {
- //log here
- return PACKET_CMD_NONE;
- }
- if (ret == PACKET_CMD_ADD)
- {
- try {
- string reqkey = PacketAnalizer::GetPacketKey(&CmdObject);
- if (reqkey == "DeviceList")
- {
- DeviceDescript dd;
- dd.SetResDataObject(Context);
- BusUnitLogic::AddDeviceDescrpt(dd.GetKey(), dd.m_TargetType.GetVal(), dd.m_MachineId.GetVal(), dd.m_ProcId, dd.m_Address);
- }
- }
- catch (...)
- {
- //log here
- ret = PACKET_CMD_NONE;
- }
- return ret;
- }
- else if (ret == PACKET_CMD_DEL)
- {
- try {
- string reqkey = PacketAnalizer::GetPacketKey(&CmdObject);
- if (reqkey == "DeviceList")
- {
- BusUnitLogic::DelDeviceDescrpt((const char *)Context[0]);
- }
- }
- catch (...)
- {
- //log here
- ret = PACKET_CMD_NONE;
- }
- return ret;
- }
- else if (ret == PACKET_CMD_UPDATE)
- {
- try {
- string key = PacketAnalizer::GetPacketKey(&CmdObject);
- ResDataObject Context;
- if (PacketAnalizer::GetPacketContext(&CmdObject, Context))
- {
- if (key == "Status")
- {
- if (BusUnitLogic::GetDeviceStatus() != (int)Context)
- {
- BusUnitLogic::SetDeviceStatus((int)Context);
- }
- else
- {
- ret = PACKET_CMD_NONE;
- }
-
- }
- else if (key == "ExitFlag")
- {
- if (BusUnitLogic::GetExitFlag() != (int)Context)
- {
- BusUnitLogic::SetExitFlag((int)Context);
- }
- else
- {
- ret = PACKET_CMD_NONE;
- }
- }
- else if (key == "EnableEthBus")
- {
- if (BusUnitLogic::GetEthBusSwitch() != (int)Context)
- {
- BusUnitLogic::SetEthBusSwitch((int)Context);
- }
- else
- {
- ret = PACKET_CMD_NONE;
- }
- }
- else if (key == "EthBusRouterIp")
- {
- string IpStr;
- ResDataObject Ip;
- BusUnitLogic::GetEthBusRouterIp(Ip);
- IpStr = (const char*)Ip;
- if (IpStr != (const char*)Context)
- {
- BusUnitLogic::SetEthBusRouterIp((const char*)Context);
- }
- else
- {
- ret = PACKET_CMD_NONE;
- }
- }
- }
- }
- catch (...)
- {
- //log here
- ret = PACKET_CMD_NONE;
- }
- return ret;
- }
- else if (ret != PACKET_CMD_NONE)
- {
- return ret;
- }
- }
- return ret;
- }
- int BusUnitClient::Open(const char *pPath, int flags, DWORD timeout)
- {
- RET_STATUS ret = (RET_STATUS)LogicClient::Open(pPath, flags, timeout);
- if (ret >= RET_SUCCEED)
- {
- //need update local data!!!!
- bool sRet = true;
- ResDataObject Attribute;
- ResDataObject Temp;
- sRet &= TryGetValue(m_DeviceResource, "Attribute", Attribute);
- if (sRet)
- {
- sRet &= TryGetValue(Attribute, "MachineId", Temp);
- BusUnitLogic::SetMachineId(Temp);
- }
- if (sRet)
- {
- Temp.clear();
- sRet &= TryGetValue(Attribute, "BusId", Temp);
- BusUnitLogic::SetbusId(Temp);
- }
- if (sRet)
- {
- Temp.clear();
- sRet &= TryGetValue(Attribute, "ProcId", Temp);
- BusUnitLogic::SetProcId((UINT64)Temp);
- }
- if (sRet)
- {
- Temp.clear();
- sRet &= TryGetValue(Attribute, "DeviceList", Temp);
- if (sRet)
- {
- size_t Size = Temp.size();
- for (size_t i = 0; i < Size; i++)
- {
- try {
- BusUnitLogic::AddDeviceDescrpt(Temp.GetKey(i),
- (const char*)Temp[i]["TargetType"],
- (const char*)Temp[i]["MachineId"],
- (UINT64)Temp[i]["ProcId"],
- (UINT64)Temp[i]["Addr"]);
- }
- catch (...)
- {
- ret = RET_FAILED;
- }
- }
- }
- }
- if (sRet)
- {
- Temp.clear();
- sRet &= TryGetValue(Attribute, "Status", Temp);
- BusUnitLogic::SetDeviceStatus((int)Temp);
- }
- if (sRet)
- {
- Temp.clear();
- sRet &= TryGetValue(Attribute, "EnableEthBus", Temp);
- BusUnitLogic::SetEthBusSwitch((int)Temp);
- }
- if (sRet)
- {
- Temp.clear();
- sRet &= TryGetValue(Attribute, "EthBusRouterIp", Temp);
- BusUnitLogic::SetEthBusRouterIp((const char*)Temp);
- }
- if (sRet)
- {
- Temp.clear();
- sRet &= TryGetValue(Attribute, "ExitFlag", Temp);
- BusUnitLogic::SetExitFlag((int)Temp);
- }
- //last check
- if (ret < RET_SUCCEED)
- {
- LogicClient::Close();
- }
- }
- return ret;
- }
- //get device resource
- RET_STATUS SYSTEM_CALL BusUnitClient::GetDeviceResource(ResDataObject PARAM_OUT *pDeviceResource)
- {
- if (IsClosed())
- {
- return RET_FAILED;
- }
- return ((LogicClient*)this)->GetDeviceResource(pDeviceResource);
- }
- //ResourceCommand Request In and Response Out
- RET_STATUS SYSTEM_CALL BusUnitClient::Request(ResDataObject PARAM_IN *pRequest, ResDataObject PARAM_OUT *pResponse)
- {
- //do nothing
- return RET_NOSUPPORT;
- }
- //notify to lower layer
- //notify&response from real logic device
- RET_STATUS SYSTEM_CALL BusUnitClient::CmdToLogicDev(ResDataObject PARAM_IN *pCmd)
- {
- //response and notify comes here
- PacketArrived(pCmd);
- return RET_SUCCEED;
- }
- //Data Access
- int BusUnitClient::AddDeviceDescrpt(const char PARAM_IN *pDevPath, const char PARAM_IN *pTargetType, const char PARAM_IN *pMachineId, UINT64 ProcId, UINT64 Addr, bool forceAdd)
- {
- //pack get status
- ResDataObject req, res,obj;
- //make params
- req.add("P0", pDevPath);
- req.add("P1", pTargetType);
- req.add("P2", pMachineId);
- req.add("P3", ProcId);
- req.add("P4", Addr);
- req.add("P5", forceAdd);
- printf("\r\n BusUnitClient::AddDeviceDescrpt add to Root %s \r\n\r\n", pDevPath);
- return Action("AddDeviceDescrpt", req, res);
- }
- int BusUnitClient::DelDeviceDescrpt(const char PARAM_IN *pDevPath)
- {
- ResDataObject req, res, obj;
- //make params
- req.add("P0", pDevPath);
- return Action("DelDeviceDescrpt", req, res,50);
- }
- int BusUnitClient::SetDeviceStatus(int PARAM_IN DevStatus)
- {
- ResDataObject req, res, obj;
- //make params
- req.add("P0", DevStatus);
- return Action("SetDeviceStatus", req, res);
- }
- int BusUnitClient::SetEthBusSwitch(int Switch)
- {
- ResDataObject req, res;
- //make params
- req.add("P0", Switch);
- return Action("SetEthBusSwitch", req, res);
- }
- int BusUnitClient::SetEthBusRouterIp(const char PARAM_IN *pRouterIp)
- {
- ResDataObject req, res;
- //make params
- req.add("P0", pRouterIp);
- return Action("SetEthBusRouterIp", req, res);
- }
- int BusUnitClient::ExitDriverProc()
- {
- ResDataObject req, res;
- return Action_Req("ExitDriverProc", req, res);
- }
- bool BusUnitClient::GetDeviceUsage()
- {
- if (IsClosed() == false && GetDeviceStatus() == 1 && GetExitFlag() == 0)
- {
- return true;
- }
- return false;
- }
- int BusUnitClient::ForTest(bool Flag)
- {
- ResDataObject req, res;
- //make params
- req.add("P0", Flag);
- return Action_Req("ForTest", req, res);
- }
|