#include "StdAfx.h" #include "PacketAnalizer.h" #include "WheelClient.h" WheelUnitLogicClient::WheelUnitLogicClient(void) { pLogicDeivce = (LogicDevice*)this; } WheelUnitLogicClient::~WheelUnitLogicClient(void) { } WheelUnitLogicClient& WheelUnitLogicClient::operator = (WheelUnitLogicClient &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.IsClosed() == 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); } RET_STATUS SYSTEM_CALL WheelUnitLogicClient::GetDeviceResource(ResDataObject PARAM_OUT *pDeviceResource) { if (IsClosed()) { return RET_FAILED; } return ((LogicClient*)this)->GetDeviceResource(pDeviceResource); } int WheelUnitLogicClient::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, "WHELLSTATUS", Temp); if (sRet) { ret = (RET_STATUS)WheelUnitLogic::SetStatus((bool)Temp); } else { ret = RET_FAILED; } if (ret != RET_SUCCEED) { LogicClient::Close(); } } sRet &= TryGetValue(m_DeviceResource, "Action", Attribute); } return ret; } //ResourceCommand Request In and Response Out RET_STATUS SYSTEM_CALL WheelUnitLogicClient::Request(ResDataObject PARAM_IN *pRequest, ResDataObject PARAM_OUT *pResponse) { //do nothing return RET_NOSUPPORT; } //notify to lower layer RET_STATUS SYSTEM_CALL WheelUnitLogicClient::CmdToLogicDev(ResDataObject PARAM_IN *pCmd) { //response and notify comes here PacketArrived(pCmd); return RET_SUCCEED; } PACKET_CMD WheelUnitLogicClient::ReadCmd(ResDataObject &CmdObject) { PACKET_CMD ret = PACKET_CMD_NONE; while (IsDataArrived()) { ret = LogicClient::ReadCmd(CmdObject); if (ret == PACKET_CMD_UPDATE) { //only one update string key = PacketAnalizer::GetPacketKey(&CmdObject); assert(key == "WHELLSTATUS"); ResDataObject Context; if (PacketAnalizer::GetPacketContext(&CmdObject, Context)) { WheelUnitLogic::SetStatus((bool)Context); } return ret; } else if (ret != PACKET_CMD_NONE) { return ret; } } return ret; } //resource // DeviceType:GUID // attribute:{WHELLSTATUS:0} // action:StartRoll // action:StopRoll //Data Access int DATA_ACTION WheelUnitLogicClient::GetStatus(bool PARAM_OUT &status) { //use the request if (Support_GetStatus()) { //pack get status ResDataObject req, res; RET_STATUS ret = (RET_STATUS)Action("GetStatus", req, res); if (ret == RET_SUCCEED && GetRequestSyncMode() == ACTION_SYNC) { try { status = res["P0"]; } //catch (ResDataObjectExption &exp) //{ // //exp.what(); //} catch (...) { //exp } } return ret; } return RET_NOSUPPORT; } int DATA_ACTION WheelUnitLogicClient::SetStatus(bool PARAM_IN status) { //use the request if (Support_SetStatus()) { //pack set status ResDataObject req, res; //put params here req.add("P0", status); //exec action here return (RET_STATUS)Action("SetStatus", req, res); } return RET_NOSUPPORT; } //Actions int DEVICE_ACTION WheelUnitLogicClient::StartRoll() { //use the request if (Support_StartRoll()) { //pack set status ResDataObject req, res; //put params here //exec action here return Action("StartRoll", req, res); } return RET_NOSUPPORT; } int DEVICE_ACTION WheelUnitLogicClient::StopRoll() { //use the request if (Support_StopRoll()) { //pack set status ResDataObject req, res; //put params here //exec action here return Action("StopRoll", req, res); } return RET_NOSUPPORT; } bool DEVICE_SUPPORT WheelUnitLogicClient::Support_GetStatus() { //use the resource of LogicDevice try{ int idx = m_DeviceResource.GetFirstOf("Action"); if (idx >= 0) { idx = m_DeviceResource[idx].GetFirstOf("GetStatus"); return (idx >= 0); } } //catch (ResDataObjectExption &exp) //{ // //log here // //exp.what(); //} catch (...) { //log here } return false; } bool DEVICE_SUPPORT WheelUnitLogicClient::Support_SetStatus() { //use the resource of LogicDevice try{ int idx = m_DeviceResource.GetFirstOf("Action"); if (idx >= 0) { idx = m_DeviceResource[idx].GetFirstOf("SetStatus"); return (idx >= 0); } } //catch (ResDataObjectExption &exp) //{ // //log here // //exp.what(); //} catch (...) { //log here } return false; } bool DEVICE_SUPPORT WheelUnitLogicClient::Support_StartRoll() { //use the resource of LogicDevice try{ int idx = m_DeviceResource.GetFirstOf("Action"); if (idx >= 0) { idx = m_DeviceResource[idx].GetFirstOf("StartRoll"); return (idx >= 0); } } //catch (ResDataObjectExption &exp) //{ // //log here // //exp.what(); //} catch (...) { //log here } return false; } bool DEVICE_SUPPORT WheelUnitLogicClient::Support_StopRoll() { //use the resource of LogicDevice try{ int idx = m_DeviceResource.GetFirstOf("Action"); if (idx >= 0) { idx = m_DeviceResource[idx].GetFirstOf("StopRoll"); return (idx >= 0); } } //catch (ResDataObjectExption &exp) //{ // //log here // //exp.what(); //} catch (...) { //log here } return false; } int SYSTEM_CALL WheelUnitLogicClient::GetLocalStatus(bool PARAM_OUT &status) { return WheelUnitLogic::GetStatus(status); }