123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- #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 <std::shared_ptr<LinuxEvent>> evtList, DWORD count)
- {
- std::vector <std::shared_ptr<LinuxEvent>> 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;
- }
|