#include "DevTree.h" #include "LocalConfig.h" #include "common_api.h" #include "OemBusUnit.h" #include "OemBusUnitDevice.h" //OEMBUSUNIT_API DPC* GetDPC() //{ // return (DPC*)(new BusUnitDPC()); //} // //OEMBUSUNIT_API void ReleaseDPC(DPC *p) //{ // BusUnitDPC *org = (BusUnitDPC*)p; // delete org; //} //Log4CPP::Logger* mLog::gLogger = nullptr; OEMBUSUNIT_C_API DriverDPC* GetDriverDPC() { return (DriverDPC*)(new BusUnitDPC()); } OEMBUSUNIT_C_API void ReleaseDriverDPC(DriverDPC *p) { BusUnitDPC *org = (BusUnitDPC*)p; delete org; } BusUnitDPC::BusUnitDPC(void) { m_pWorkpath = new std::string(); m_pRootDevice = 0; m_FirstLoad = true; m_ExitFlag = LinuxEvent::CreateEvent(LinuxEvent::MANUAL_RESET,false); //if (//mLog::gLogger == nullptr) //{ // string strLogPath = GetProcessDirectory() + R"(\Conf\Log4CPP.Config.xml)"; // string LogHost = ((string)getLogRootpath()).c_str(); // if (LogHost.length() <= 1) // { // char szName[256]; // sprintf(szName, "/LogicDevice_%08d", GetCurrentProcessId()); // LogHost = szName; // } // Log4CPP::ThreadContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "Platform"); // //Log4CPP::GlobalContext::Map::Set("LogHost", LogHost.c_str()); // Log4CPP::ThreadContext::Map::Set(ECOM::Utility::Hash("LogHost"), LogHost.c_str() + 1); // auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str()); // //mLog::gLogger = Log4CPP::LogManager::GetLogger("Platform"); // //mLog::FINFO("Code Build datetime [{$} {$}]", __DATE__, __TIME__); //} } BusUnitDPC::~BusUnitDPC(void) { delete m_pWorkpath; } void BusUnitDPC::SetExitFlag() { m_ExitFlag->SetEvent(); } bool BusUnitDPC::DriverEntry(ResDataObject &Configuration) { return LogicDriver::DriverEntry(Configuration); } bool SYSTEM_CALL BusUnitDPC::Driver_Probe(ResDataObject& PARAM_OUT HardwareInfo) { ResDataObject Config; GetConfiguration(&Config); HardwareInfo.add("MajorID", (const char*)Config["MajorID"]); HardwareInfo.add("MinorID", (const char*)Config["MinorID"]); HardwareInfo.add("VendorID", (const char*)Config["VendorID"]); HardwareInfo.add("ProductID", (const char*)Config["ProductID"]); HardwareInfo.add("SerialID", (const char*)Config["SerialID"]); //HardwareInfo.add("MajorID", "root"); //HardwareInfo.add("MinorID", "drv"); //HardwareInfo.add("VendorID", "Ecom"); //HardwareInfo.add("ProductID", "bus"); //HardwareInfo.add("SerialID", "425"); return true; } RET_STATUS SYSTEM_CALL BusUnitDPC::GetDriverDictionary(ResDataObject& PARAM_OUT DriverInfo) { DriverInfo.add("DriverType", "root"); DriverInfo.add("DeviceName", "root"); DriverInfo.add("DateOfManufacture", "2017.10.20"); DriverInfo.add("SoftwareVersion", "Alpha1.0"); DriverInfo.add("HardwareVersion", "Alpha1.0"); DriverInfo.add("Description", "Root Drver"); DriverInfo.add("Properties", "None"); return RET_SUCCEED; } bool BusUnitDPC::SetDriverWorkPath(const char *pWorkPath) { (*m_pWorkpath) = pWorkPath; //要把读取单一硬件属性的过程放到此处 return true; } bool BusUnitDPC::SetDeviceWorkPath(const char *pWorkPath) { return true; } void BusUnitDPC::OnSetClientID() { if (m_pRootDevice != nullptr) { //mLog::FINFO("reset root SetClientRootID ? [{$}] ", m_strCCOSDevicePath); std::cout << "BusUnitDPC::OnSetClientID [ 0 reset root SetClientRootID ?" << m_strCCOSDevicePath << "]" << std::endl; if (m_strCCOSDevicePath.find('/') == string::npos) { std::cout << "BusUnitDPC::OnSetClientID [ reset root SetClientRootID ?" << m_strCCOSDevicePath << "]" << std::endl; m_strCCOSDevicePath = "CCOS/HOST/" + m_strCCOSDevicePath; } m_pRootDevice->SetClientRootID(m_strEBusRoot.c_str(), m_strCCOSDevicePath.c_str()); } } void BusUnitDPC::SubscribeSelf() { //这里订阅主题 //if (m_pRootDevice != nullptr) { // m_pRootDevice->SubscribeSelf(); //} //SubscribeTopic(m_pMqttConntion, m_strEBusRoot.c_str()); } /* RET_STATUS BusUnitDPC::ProcessRequest(ResDataObject* pCmd, PACKET_CMD cmd) { if (cmd == PACKET_CMD_OPEN || PACKET_CMD_CLOSE) { ResDataObject resRes, resResponse; GetDeviceResource(&resRes); PacketAnalizer::MakeOpenResponse(*pCmd, resResponse, resRes); ResDataObject resTopic; PacketAnalizer::GetContextTopic(pCmd, resTopic); //std::cout << "publis " << (const char*)resTopic << "msg body" << resResponse.encode() << endl; PublishAction(&resResponse, (const char*)resTopic, m_pMqttConntion); return RET_SUCCEED; } return LogicDevice::ProcessRequest(pCmd, cmd); }*/ PVOID SYSTEM_CALL BusUnitDPC::LoadDriver() { std::cout << "enter BusUnitDPC::LoadDriver() "<< endl; OemBusUnitDevice *p = new OemBusUnitDevice(); p->SetDrvDPC(this); m_pRootDevice = p; LogicDevice *pret = (LogicDevice *)p; DevTree* pTree = (DevTree*)GetDriverTree(); pTree->Add((PVOID)pret, TYPE_DEVICE); CCOS_PROC_TYPE Mode = GetConfigMode(); if (Mode == CCOS_PROC_CHANNEL) { p->LoadAllConfigDrivers(); } LogicDriver::Connect();//make sure it's connected return (PVOID)pTree; } void SYSTEM_CALL BusUnitDPC::UnloadAllRegistedDrivers() { Thread_Lock(); ((OemBusUnitDevice*)m_pRootDevice)->UnloadAllRegistedDrivers(); Thread_UnLock(); } void SYSTEM_CALL BusUnitDPC::UnloadDriver() { //kill all drivers before me //UnloadAllRegistedDrivers(); DevTree* pTree = (DevTree*)GetDriverTree(); size_t Size = pTree->size(); for (size_t i = 0; i < Size; i++) { DevTreeNode node = (*pTree)[i]; if (node.m_NodeType == TYPE_DEVICE) { OemBusUnitDevice *pdev = (OemBusUnitDevice*)node.m_pObject; delete pdev; } else if (node.m_NodeType == TYPE_DRIVER) { //... } } pTree->clear(); Thread_Lock(); m_pRootDevice = 0; Thread_UnLock(); } bool BusUnitDPC::Connect() { return true; } void BusUnitDPC::DisConnect() { return; } bool SYSTEM_CALL BusUnitDPC::Device_Probe(ResDataObject& PARAM_OUT HardwareInfo) { //不支持情况直接反馈失败 return false; } PVOID BusUnitDPC::LoadLogicDevices() { //不支持情况直接反馈失败 return NULL; } void BusUnitDPC::UnloadLogicDevices() { //do nothing return; } DWORD SYSTEM_CALL BusUnitDPC::OnNotify(std::vector > evtList, DWORD count) { std::vector > pWaitList = evtList; pWaitList.push_back( m_ExitFlag); while (1) { ////mLog::FINFO("OnNotify Loop Entry-----------"); //进程崩溃后,可以做到秒起,但是基于目前的SM模块启动需要5秒时间,意义不是很大... DWORD dwResult = LinuxEvent::WaitForMultipleEvents(pWaitList, 2000); if ((dwResult >= WAIT_OBJECT_0) && (dwResult <= WAIT_OBJECT_0 + count - 1)) { //mLog::FINFO( "OnNotify Platform. it might be exit the process...."); pWaitList.clear(); return dwResult - WAIT_OBJECT_0; } if (dwResult == WAIT_OBJECT_0 + count) { pWaitList.clear(); return 0;//exit flag } //timeout CCOS_PROC_TYPE Mode = GetConfigMode(); if (Mode == CCOS_PROC_CHANNEL) { //timeout Thread_Lock(); if (m_pRootDevice) { //first load if (m_FirstLoad) { ((OemBusUnitDevice*)m_pRootDevice)->LoadAllConfigDriver(); m_FirstLoad = false; } else { //watch dog ((OemBusUnitDevice*)m_pRootDevice)->CheckAllLiveDriver(); } } Thread_UnLock(); } } return 0; }