// ContainerDPC.cpp : 定义 DLL 应用程序的导出函数。 // #include "ContainerDPC.h" #include "DevTree.h" #include "ContainerDevice.h" #include "common_api.h" #include #include #include // Linux 动态加载库头文件 #include // 用于 strlen 等操作 #include "LocalConfig.h" //Log4CPP::Logger* mLog::gLogger = nullptr; //CONTAINERDPC_C_API DriverDPC* GetDriverDPC() //{ // return (DriverDPC*)(new ContainerDPC()); //} // //CONTAINERDPC_C_API void ReleaseDriverDPC(DriverDPC *p) //{ // ContainerDPC *org = (ContainerDPC*)p; // delete org; //} //typedef nsDEV::IODriver* (*GetDriverMgrAPI)(); ContainerDPC::ContainerDPC(void) { m_pWorkpath = new std::string(); //m_pMidObject = 0; //m_pMidObject.reset(new eDEV::Mediator()); memset(&m_ContainerManager, 0, sizeof(m_ContainerManager)); } ContainerDPC::~ContainerDPC(void) { delete m_pWorkpath; } bool ContainerDPC::InitDeviceMgr(const char *pDriverpath) { m_DriverFunctions = GetDllFunctionInfo(pDriverpath); for (const auto& function : m_DriverFunctions) { std::cout << "Function Name: " << std::get<0>(function) << std::endl; std::cout << "Function Address: " << std::get<1>(function) << std::endl; std::cout << "Function Ordinal: " << std::get<2>(function) << std::endl; std::cout << std::endl; } // 加载动态库:RTLD_NOW 表示立即解析符号 m_Module = dlopen(pDriverpath, RTLD_NOW); if (m_Module) { /*---------------------------------------------------------- 加载驱动管理器核心函数 ----------------------------------------------------------*/ //枚举所有的导出函数 m_ContainerManager.DRV_DriverEntry = (BoolCallString)dlsym(m_Module, "DRV_DriverEntry"); m_ContainerManager.DRV_Prepare = (VoidCall)dlsym(m_Module, "DRV_Prepare"); //m_ContainerManager.DRV_DriverProbe = (StringCall)dlsym(m_Module, "DRV_DriverProbe"); //m_ContainerManager.DRV_GetGUID = (StringCall)dlsym(m_Module, "DRV_GetGUID"); //m_ContainerManager.DRV_GetResource = (StringCall)dlsym(m_Module, "DRV_GetResource"); //m_ContainerManager.DRV_DeviceProbe = (StringCall)dlsym(m_Module, "DRV_DeviceProbe"); m_ContainerManager.DRV_OnHeartBeat = (BoolCall)dlsym(m_Module, "DRV_OnHeartBeat"); m_ContainerManager.DRV_ReLoadConfig = (BoolCall)dlsym(m_Module, "DRV_ReLoadConfig"); //m_ContainerManager.DRV_Connect = (BoolCall)dlsym(m_Module, "DRV_Connect"); //m_ContainerManager.DRV_Disconnect = (VoidCall)dlsym(m_Module, "DRV_Disconnect"); m_ContainerManager.DRV_CreateDevice = (VoindPointerCallInt)dlsym(m_Module, "DRV_CreateDevice"); //m_ContainerManager.DRV_FreeDevice = (HandleCall)dlsym(m_Module, "DRV_FreeDevice"); //m_ContainerManager.DRV_GetDeviceConfig = (BoolCallString)dlsym(m_Module, "DRV_GetDeviceConfig"); //m_ContainerManager.DRV_SetDeviceConfig = (BoolCallStringRef)dlsym(m_Module, "DRV_SetDeviceConfig"); m_ContainerManager.DRV_Get = (StdGetCall)dlsym(m_Module, "DRV_Get"); //m_ContainerManager. = ()dlsym(m_Module, ""); m_ContainerManager.GetCallTmplMap.clear(); /* */ m_ContainerDeviceManager.DEV_GetGUID = (GetDevCall)dlsym(m_Module, "DEV_GetGUID"); m_ContainerDeviceManager.DEV_GetResource = (GetDevCall)dlsym(m_Module, "DEV_GetResource"); m_ContainerDeviceManager.DEV_CompleteInit = (VoidDevCall)dlsym(m_Module, "DEV_CompleteInit"); m_ContainerDeviceManager.DEV_Prepare = (BoolDevCall)dlsym(m_Module, "DEV_Prepare"); m_ContainerDeviceManager.DEV_CompleteUnInit = (VoidDevCall)dlsym(m_Module, "DEV_CompleteUnInit"); //m_ContainerDeviceManager.DEV_SubscribeSelf = (VoidDevCall)dlsym(m_Module, "DEV_SubscribeSelf"); m_ContainerDeviceManager.DEV_Add = (DevAddCall)dlsym(m_Module, "DEV_Add"); m_ContainerDeviceManager.Dev_Delete = (DevDeleteCall)dlsym(m_Module, "Dev_Delete"); m_ContainerDeviceManager.Dev_Update = (DevUpdateCall)dlsym(m_Module, "Dev_Update"); m_ContainerDeviceManager.Dev_Action = (DevActionCall)dlsym(m_Module, "Dev_Action"); m_ContainerDeviceManager.Dev_Get = (DevGetCall)dlsym(m_Module, "Dev_Get"); m_ContainerDeviceManager.Dev_Set = (DevSetCall)dlsym(m_Module, "Dev_Set"); m_ContainerDeviceManager.DevPath_Add = (DevPathAddCall)dlsym(m_Module, "DevPath_Add"); m_ContainerDeviceManager.DevPath_Delete = (DevPathDeleteCall)dlsym(m_Module, "DevPath_Delete"); m_ContainerDeviceManager.DevPath_Update = (DevPathUpdateCall)dlsym(m_Module, "DevPath_Update"); m_ContainerDeviceManager.DevPath_Action = (DevPathActionCall)dlsym(m_Module, "DevPath_Action"); m_ContainerDeviceManager.DevPath_Get = (DevPathGetCall)dlsym(m_Module, "DevPath_Get"); m_ContainerDeviceManager.DevPath_Set = (DevPathSetCall)dlsym(m_Module, "DevPath_Set"); for (const auto& function : m_DriverFunctions) { string funcName = std::get<0>(function); std::cout << "Function Name: " << funcName << std::endl; const size_t DRV_GET_STRLEN = strlen("DRV_GET_"); if (funcName.substr(0, DRV_GET_STRLEN) == "DRV_GET_") { m_ContainerManager.GetCallTmplMap[funcName.substr(DRV_GET_STRLEN)] = (TmplGetCall)dlsym(m_Module, funcName.c_str()); } /* */ const size_t DEV_Add_STRLEN = strlen("DEV_Add_"); string keys = funcName.substr(0, DEV_Add_STRLEN); if (keys == "DEV_Add_") { m_ContainerDeviceManager.DevAddTmplMap[funcName.substr(DEV_Add_STRLEN)] = (DevActionTmplCall)dlsym(m_Module, funcName.c_str()); } else if (keys == "DEV_Dele") { const size_t DEV_Delete_STRLEN = strlen("DEV_Delete_"); m_ContainerDeviceManager.DevDeleteTmplMap[funcName.substr(DEV_Delete_STRLEN)] = (DevActionTmplCall)dlsym(m_Module, funcName.c_str()); } else if (keys == "DEV_Upda") { const size_t DEV_Update_STRLEN = strlen("DEV_Update_"); m_ContainerDeviceManager.DevUpdateTmplMap[funcName.substr(DEV_Update_STRLEN)] = (DevActionTmplCall)dlsym(m_Module, funcName.c_str()); } else if (keys == "DEV_Acti") { const size_t DEV_Action_STRLEN = strlen("DEV_Action_"); m_ContainerDeviceManager.DevActionTmplMap[funcName.substr(DEV_Action_STRLEN)] = (DevActionTmplCall)dlsym(m_Module, funcName.c_str()); } else if (keys == "DEV_Get_") { m_ContainerDeviceManager.DevGetTmplMap[funcName.substr(DEV_Add_STRLEN)] = (DevGetTmplCall)dlsym(m_Module, funcName.c_str()); } else if (keys == "DEV_Set_") { m_ContainerDeviceManager.DevSetTmplMap[funcName.substr(DEV_Add_STRLEN)] = (DevSetTmplCall)dlsym(m_Module, funcName.c_str()); } else if (keys == "DEVPath_") { //与patch有关的,需要进一步判断 /* */ const size_t DEVPATH_Add_STRLEN = strlen("DEVPath_Add_"); string pathkeys = funcName.substr(0, DEVPATH_Add_STRLEN); size_t funcNameLen = funcName.length(); if (pathkeys == "DEVPath_Add_") { if (funcName[funcNameLen - 1] == '_') { //根设备的模型方法 DEVPath_Add_ XXX_ m_ContainerDeviceManager.LogicDevAddTmpMap[funcName.substr(DEVPATH_Add_STRLEN)] = (DevTemplPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } else { size_t findNamePos = funcName.substr(DEVPATH_Add_STRLEN).find_first_of('_'); if (findNamePos == string::npos) { //DEVPath_Add_XXX ,入口参数第一个是设备路径 m_ContainerDeviceManager.DevPathAddTmplMap[funcName.substr(DEVPATH_Add_STRLEN)] = (DevPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } else { //DEVPath_Add_ XXX_Dev01_SubDev m_ContainerDeviceManager.LogicDevAddTmpMap[funcName.substr(DEVPATH_Add_STRLEN)] = (DevTemplPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } } } else if (pathkeys == "DEVPath_Dele") { const size_t DEV_Delete_STRLEN = strlen("DEVPath_Delete_"); if (funcName[funcNameLen - 1] == '_') { //根设备的模型方法 DEVPath_Delete_ XXX_ m_ContainerDeviceManager.LogicDevDeleteTmpMap[funcName.substr(DEV_Delete_STRLEN)] = (DevTemplPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } else { size_t findNamePos = funcName.substr(DEV_Delete_STRLEN).find_first_of('_'); if (findNamePos == string::npos) { //DEVPath_Delete_XXX ,入口参数第一个是设备路径 m_ContainerDeviceManager.DevPathDeleteTmplMap[funcName.substr(DEV_Delete_STRLEN)] = (DevPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } else { //DEVPath_Delete_ XXX_Dev01_SubDev m_ContainerDeviceManager.LogicDevDeleteTmpMap[funcName.substr(DEV_Delete_STRLEN)] = (DevTemplPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } } } else if (pathkeys == "DEVPath_Upda") { const size_t DEV_Update_STRLEN = strlen("DEVPath_Update_"); if (funcName[funcNameLen - 1] == '_') { //根设备的模型方法 DEVPath_Update_ XXX_ m_ContainerDeviceManager.LogicDevUpdateTmpMap[funcName.substr(DEV_Update_STRLEN)] = (DevTemplPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } else { size_t findNamePos = funcName.substr(DEV_Update_STRLEN).find_first_of('_'); if (findNamePos == string::npos) { //DEVPath_Update_XXX ,入口参数第一个是设备路径 m_ContainerDeviceManager.DevPathUpdateTmplMap[funcName.substr(DEV_Update_STRLEN)] = (DevPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } else { //DEVPath_Update_ XXX_Dev01_SubDev m_ContainerDeviceManager.LogicDevUpdateTmpMap[funcName.substr(DEV_Update_STRLEN)] = (DevTemplPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } } } else if (pathkeys == "DEVPath_Acti") { const size_t DEV_Action_STRLEN = strlen("DEVPath_Action_"); if (funcName[funcNameLen - 1] == '_') { //根设备的模型方法 DEVPath_Action_ XXX_ m_ContainerDeviceManager.LogicDevActionTmpMap[funcName.substr(DEV_Action_STRLEN)] = (DevTemplPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } else { size_t findNamePos = funcName.substr(DEV_Action_STRLEN).find_first_of('_'); if (findNamePos == string::npos) { //DEVPath_Update_XXX ,入口参数第一个是设备路径 m_ContainerDeviceManager.DevPathActionTmplMap[funcName.substr(DEV_Action_STRLEN)] = (DevPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } else { //DEVPath_Update_ XXX_Dev01_SubDev m_ContainerDeviceManager.LogicDevActionTmpMap[funcName.substr(DEV_Action_STRLEN)] = (DevTemplPathActionTmplCall)dlsym(m_Module, funcName.c_str()); } } } else if (pathkeys == "DEVPath_Get_") { if (funcName[funcNameLen - 1] == '_') { //根设备的模型方法 DEVPath_Get_ XXX_ m_ContainerDeviceManager.LogicDevGetTmpMap[funcName.substr(DEVPATH_Add_STRLEN)] = (DevTemplPathGetTmplCall)dlsym(m_Module, funcName.c_str()); } else { size_t findNamePos = funcName.substr(DEVPATH_Add_STRLEN).find_first_of('_'); if (findNamePos == string::npos) { //DEVPath_Get_XXX ,入口参数第一个是设备路径 m_ContainerDeviceManager.DevPathGetTmplMap[funcName.substr(DEVPATH_Add_STRLEN)] = (DevPathGetTmplCall)dlsym(m_Module, funcName.c_str()); } else { //DEVPath_Get_ XXX_Dev01_SubDev m_ContainerDeviceManager.LogicDevGetTmpMap[funcName.substr(DEVPATH_Add_STRLEN)] = (DevTemplPathGetTmplCall)dlsym(m_Module, funcName.c_str()); } } } else if (pathkeys == "DEVPath_Set_") { if (funcName[funcNameLen - 1] == '_') { //根设备的模型方法 DEVPath_Set_ XXX_ m_ContainerDeviceManager.LogicDevSetTmpMap[funcName.substr(DEVPATH_Add_STRLEN)] = (DevTemplPathSetTmplCall)dlsym(m_Module, funcName.c_str()); } else { size_t findNamePos = funcName.substr(DEVPATH_Add_STRLEN).find_first_of('_'); if (findNamePos == string::npos) { //DEVPath_Set_XXX ,入口参数第一个是设备路径 m_ContainerDeviceManager.DevPathSetTmplMap[funcName.substr(DEVPATH_Add_STRLEN)] = (DevPathSetTmplCall)dlsym(m_Module, funcName.c_str()); } else { //DEVPath_Set_ XXX_Dev01_SubDev m_ContainerDeviceManager.LogicDevSetTmpMap[funcName.substr(DEVPATH_Add_STRLEN)] = (DevTemplPathSetTmplCall)dlsym(m_Module, funcName.c_str()); } } } } } //GetDriverMgrAPI callfunc = (GetDriverMgrAPI)dlsym(m_Module, "CreateIODriver"); //if (callfunc) //{ // auto pDriver = reinterpret_cast (callfunc()); // if (pDriver) // { // m_NewDevManager.reset(pDriver); // //succeed // return true; // } // else // { // DWORD errNo = GetLastError(); // //mLog::FINFO(("lib:%s no Object returned.ErrNo:%d\n", pDriverpath, errNo); // } //} //else //{ // DWORD errNo = GetLastError(); // //mLog::FINFO(("lib:%s no CreateIODriver entry.ErrNo:%d\n", pDriverpath, errNo); //} return CheckDriver(); } else { // Linux 错误处理:使用 dlerror() 获取错误信息 const char* errMsg = dlerror(); std::cerr << "Load lib:" << pDriverpath << " failed. Error: " << (errMsg ? errMsg : "Unknown error") << std::endl; return false; } return false; } bool ContainerDPC::CheckDriver() { bool bOK = true; bOK &= m_ContainerManager.DRV_DriverEntry != NULL; bOK &= m_ContainerManager.DRV_Prepare != NULL; //bOK &= m_ContainerManager.DRV_DriverProbe != NULL; //bOK &= m_ContainerManager.DRV_GetGUID != NULL; //bOK &= m_ContainerManager.DRV_GetResource != NULL; //bOK &= m_ContainerManager.DRV_DeviceProbe != NULL; bOK &= m_ContainerManager.DRV_OnHeartBeat != NULL; bOK &= m_ContainerManager.DRV_ReLoadConfig != NULL; //bOK &= m_ContainerManager.DRV_Connect != NULL; //bOK &= m_ContainerManager.DRV_Disconnect != NULL; bOK &= m_ContainerManager.DRV_CreateDevice != NULL; bOK &= m_ContainerManager.DRV_FreeDevice != NULL; //bOK &= m_ContainerManager.DRV_GetDeviceConfig != NULL; //bOK &= m_ContainerManager.DRV_SetDeviceConfig != NULL; bOK &= m_ContainerManager.DRV_Get != NULL; return bOK; } bool ContainerDPC::DriverEntry(ResDataObject &Configuration) { m_Config = Configuration; const char *pDriverpath = Configuration["oemdriver"]; if (pDriverpath == 0 || strlen(pDriverpath) == 0) { //mLog::FINFO("context of oemdriver is empty"); return false; } if (InitDeviceMgr(pDriverpath) == false) { //mLog::FINFO("CreateIODriver Failed.{$}",pDriverpath); return false; } bool ret = LogicDriver::DriverEntry(Configuration); string filepath = GetDriverConfigFilePath(); m_strConfigFilePath = filepath; if (ret) { ret = m_ContainerManager.DRV_DriverEntry(filepath); //ret = m_NewDevManager->DriverEntry(filepath); m_ContainerManager.DRV_Prepare(); //m_NewDevManager->Prepare(); } else { //mLog::FINFO("LogicDriver::DriverEntry Failed.{$}", filepath.c_str()); } return ret; } bool ContainerDPC::GetDeviceType(GUID &DevType) { string DriverType = ""; try { DriverType = (string)m_Config["GUID"];//m_ContainerManager.DRV_GetGUID(); // m_NewDevManager->GetGUID(); } catch (...) { } if (DriverType.size() == 0) { //mLog::FINFO("GetDeviceType Failed"); return false; } //if (m_pNewDevManager->GetDriverType(DriverType) == false) //{ // return false; //} return string_2_guid(DriverType.c_str(), DevType); } string DEVICE_ID = ""; string TOPIC_PREFIX = ""; bool SYSTEM_CALL ContainerDPC::Driver_Probe(ResDataObject& PARAM_OUT HardwareInfo) { //string DriverInfo = "";// m_NewDevManager->DriverProbe(); //if (m_pNewDevManager->Driver_Probe(DriverInfo)) { ResDataObject Config = m_Config; //if (Config.decode(DriverInfo.c_str())) { 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"]); ostringstream os,os2; os << (const char*)Config["VendorID"] << "_" << (const char*)Config["ProductID"] << "_" << (const char*)Config["SerialID"]; DEVICE_ID = os.str(); os2 << "" << (const char*)Config["MajorID"] ;//<< "/" << (const char*)Config["VendorID"] << "/" << (const char*)Config["ProductID"]; os2 << "/" << (const char*)Config["SerialID"] << "/"; TOPIC_PREFIX = os2.str(); return true; } } return false; } /// /// 读取配置项的所有key:value /// /// ResDataObject GetDriverConfigration(CCOS_DRIVER_OBJ* pDriver); RET_STATUS ContainerDPC::GetDeviceResource(ResDataObject *pDeviceResource) { RET_STATUS ret = RET_FAILED; string ResInfo = "";// m_NewDevManager->GetResource(); //if (m_pNewDevManager->GetDriverResource(ResInfo)) { //low layerInfo ResDataObject LowLayerConfig; if (LowLayerConfig.decode(ResInfo.c_str()) == false) { //mLog::FINFO("GetDriverResource Failed"); return ret; } //base LogicDriverinfo ResDataObject BaseLayerConfig; ret = LogicDriver::GetDeviceResource(&BaseLayerConfig); if (ret < RET_SUCCEED) { return ret; } //配置文件属性,WEBconfig可以读/写,只读属性属于初始配置值,不能修改 BaseLayerConfig["Configrations"] = GetDriverConfigration(&m_ContainerManager); //驱动属性,GET //BaseLayerConfig.update("Attribute", GetDriverAttribute()); ////驱动可写属性 SET //BaseLayerConfig.update("Set", GetDriverWritableAttribute()); ////update //BaseLayerConfig.update("Update", GetDriverUpdateItems()); ////add //BaseLayerConfig.update("Add", GetDriverAddItems()); ////delete //BaseLayerConfig.update("Delete", GetDriverDeleteItems()); ////action //BaseLayerConfig.update("Action", GetDriverActionItems()); if (LowLayerConfig.GetFirstOf("Attribute") >= 0) { //loop Low Layer Attribute for (size_t i = 0; i < LowLayerConfig["Attribute"].size(); i++) { const char *pKey = LowLayerConfig["Attribute"].GetKey(i); if (pKey) { int BaseIdx = BaseLayerConfig["Attribute"].GetFirstOf(pKey); if (BaseIdx >= 0) { //exist then overwrite BaseLayerConfig["Attribute"][BaseIdx] = LowLayerConfig["Attribute"][i]; } else { //not exist then add BaseLayerConfig["Attribute"].add(pKey, LowLayerConfig["Attribute"][i]); } } } } if (LowLayerConfig.GetFirstOf("Action") >= 0) { //loop Low Layer Action for (size_t i = 0; i < LowLayerConfig["Action"].size(); i++) { const char *pKey = LowLayerConfig["Action"].GetKey(i); if (pKey) { int BaseIdx = BaseLayerConfig["Action"].GetFirstOf(pKey); if (BaseIdx >= 0) { //exist then overwrite BaseLayerConfig["Action"][BaseIdx] = LowLayerConfig["Action"][i]; } else { //not exist then add BaseLayerConfig["Action"].add(pKey, LowLayerConfig["Action"][i]); } } } } (*pDeviceResource) = BaseLayerConfig; return RET_SUCCEED; } return ret; } /* void ContainerDPC::SubscribeSelf() { //这里订阅topic }*/ bool ContainerDPC::Device_Probe(ResDataObject &HardwareInfo) { string DeviceInfo = ""; // m_NewDevManager->DeviceProbe(); //if (m_pNewDevManager->Device_Probe(DeviceInfo)) { ResDataObject Config = m_Config; //if (Config.decode(DeviceInfo.c_str())) { 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"]); return true; } } return false; } bool ContainerDPC::SetDeviceWorkPath(const char *pWorkPath) { return true; } bool ContainerDPC::SetDriverWorkPath(const char *pWorkPath) { (*m_pWorkpath) = pWorkPath; //要把读取单一硬件属性的过程放到此处 return true; } bool ContainerDPC::Connect() { bool bret = true;// m_ContainerManager.DRV_Connect(); // m_NewDevManager->Connect(); if (bret) { LogicDriver::Connect();//make sure it's connected //mLog::FINFO("Connect Succeed"); return true; } else { //mLog::FINFO("Connect Failed"); } return false; } bool SYSTEM_CALL ContainerDPC::GetConnectionStatus() { return false; // m_NewDevManager->isConnected(); } void ContainerDPC::DisConnect() { //m_NewDevManager->Disconnect(); //m_ContainerManager.DRV_Disconnect(); LogicDriver::DisConnect();//make sure it's Disconnected //mLog::FINFO("DisConnect Succeed"); } bool SYSTEM_CALL ContainerDPC::OnHeartBeat() { return m_ContainerManager.DRV_OnHeartBeat(); // m_NewDevManager->OnHeartBeat(); } PVOID ContainerDPC::LoadLogicDevices() { std::cout << "**************** ContainerDPC :: LoadLogicDevices" << std::endl; //mLog::FINFO( "Load Logic Devices"); int nDeviceNumber = 1; string filepath = GetDriverConfigFilePath(); ResDataObject Config; std::cout << "**************** ContainerDPC Load Config " << filepath << std::endl; if (Config.loadFile(filepath.c_str())) { int nHaveDeviceNumber = (int)Config["CONFIGURATION"].GetKeyCount("DeviceNumber"); if (nHaveDeviceNumber > 0) { nDeviceNumber = Config["CONFIGURATION"]["DeviceNumber"]; //mLog::FINFO("Have %d Devices", nDeviceNumber); } else { //mLog::FINFO("Have no DeviceNumber Attribute"); } } else { //mLog::FINFO("Load config file failed %d",filepath.c_str()); } DevTree *pTree = (DevTree *)GetDeviceTree(); for (int i = 0; i < nDeviceNumber; i++) { ContainerDevice *p = new ContainerDevice(); std::cout << " ****************ContainerDPC Try new Device " << i << " of " << nDeviceNumber << std::endl; //auto pIoDevice = m_NewDevManager->CreateDevice(i); DEVICE_HANDLE pContainerDevice = m_ContainerManager.DRV_CreateDevice(i); if (pContainerDevice) { GUID guid2; string guidname; //((LogicDevice*)pChild)->GetDeviceType(guid); //bool bget = pIoDevice->GetDeviceType(guid2); guidname = m_ContainerDeviceManager.DEV_GetGUID(pContainerDevice);// pIoDevice->GetGUID(); //guid_2_string(guid2, guidname); ResDataObject subpath; subpath = (guidname).c_str(); ResDataObject probe,conn_usless; Device_Probe(probe); string fullpath = MakeDevicePath(probe, conn_usless, subpath).encode(); string ccospath = MakeCcosPath(probe, conn_usless, subpath).encode(); //pDevice->SetEbusRoot(fullpath.c_str()); p->SetClientRootID(fullpath.c_str(), ccospath.c_str()); //p->SetClientRootID(); //mLog::FINFO("Get IoDevice Succeed"); std::shared_ptr DisconnectEvt = GetPassiveDisConnectEvtHandle(); //p->ConnectMQTTServer(); p->Init(&m_ContainerDeviceManager, pContainerDevice, DisconnectEvt); //p->SubscribeAction(); //mLog::FINFO("Create IoDevice Succeed"); } else { // //mLog::FERROR("Create IoDevice Failed"); // delete p; // return NULL; } LogicDevice *pret = (LogicDevice *)p; pTree->Add((PVOID)pret, TYPE_DEVICE); LogicDevice::AddEbusChildren(p, ""); } return (PVOID)pTree; } void ContainerDPC::UnloadLogicDevices() { //mLog::FINFO( "UnLoad Logic Devices"); DevTree *pTree = (DevTree *)GetDeviceTree(); size_t Size = pTree->size(); for (size_t i = 0; i < Size; i++) { DevTreeNode node = (*pTree)[i]; if (node.m_NodeType == TYPE_DEVICE) { ContainerDevice *pdev = (ContainerDevice*)node.m_pObject; delete pdev; } else { //tree dev //do not copy this!!!! //UnloadLogicDevices(node.m_pObject); } } pTree->clear(); //mLog::FINFO( "UnLoad Over"); } ResDataObject GetDriverConfigration(CCOS_DRIVER_OBJ* pDriver) { ResDataObject res; return res; } //std::string FPDDemoDriver::GetResource() //{ // ResDataObject r_config, temp; // if (!temp.loadFile(m_ConfigFileName.c_str())) // { // //mLog::FINFO("FPDDemoDriver::GetResource loadFile failed :{$} \n", m_ConfigFileName); // return ""; // } // // m_ConfigAll = temp; // // r_config = temp["CONFIGURATION"]; // m_Configurations = r_config; // // ResDataObject DescriptionTemp; // ResDataObject ListTemp; // string strTemp = ""; //用于读取字符串配置信息 // string strIndex = ""; //用于读取配置信息中的List项 // int nTemp = -1; //用于读取整型配置信息 // char sstream[10] = { 0 }; //用于转换值 // string strValue = ""; //用于存储配置的值 // string strType = ""; //用于存储配置的类型 int/float/string... // // /*** // * 1. 通过循环,将所有配置项写到pDeviceConfig // * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值 // ***/ // try // { // int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo"); // m_pAttribute->clear(); // m_pDescription->clear(); // for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++) // { // DescriptionTemp.clear(); // ListTemp.clear(); // //AttributeType // strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"]; // DescriptionTemp.add(AttributeType, strTemp.c_str()); // ////mLog::FINFO(g_pFPDCtrlLog, "--> {$}: {$}", AttributeType, strTemp.c_str()); // strType = strTemp; //记录配置项的类型 // // //AttributeKey // //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值 // strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"]; // nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"]; // GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); // //2. 赋值 // strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"]; // if ("int" == strType) // { // (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str())); // ////mLog::FINFO(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atoi(strValue.c_str())); // } // else if ("float" == strType) // { // (*m_pAttribute).add(strTemp.c_str(), atof(strValue.c_str())); // ////mLog::FINFO(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atof(strValue.c_str())); // } // else //其它先按string类型处理 // { // (*m_pAttribute).add(strTemp.c_str(), strValue.c_str()); // ////mLog::FINFO(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), strValue.c_str()); // } // // //AttributeAccess // strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"]; // DescriptionTemp.add(AttributeAccess, strTemp.c_str()); // ////mLog::FINFO(g_pFPDCtrlLog, "{$}: {$}", AttributeAccess, strTemp.c_str()); // // //AttributeRangeMin // strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"]; // if (strTemp != "") //不需要的配置项为空 // { // DescriptionTemp.add(AttributeRangeMin, strTemp.c_str()); // ////mLog::FINFO(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMin, strTemp.c_str()); // } // // //AttributeRangeMax // strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"]; // if (strTemp != "") //不需要的配置项为空 // { // DescriptionTemp.add(AttributeRangeMax, strTemp.c_str()); // ////mLog::FINFO(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMax, strTemp.c_str()); // } // // //AttributeList // nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"]; // if (nTemp > 0) //ListNum不大于0时说明不需要list配置 // { // for (int nListIndex = 0; nListIndex < nTemp; nListIndex++) // { // strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex]; // auto temKey = std::to_string(nListIndex); // ListTemp.add(temKey.c_str(), strTemp.c_str()); // ////mLog::FINFO(g_pFPDCtrlLog, "list {$}: {$}", nListIndex, strTemp.c_str()); // } // DescriptionTemp.add(AttributeList, ListTemp); // } // // //AttributeRequired // strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"]; // DescriptionTemp.add(AttributeRequired, strTemp.c_str()); // ////mLog::FINFO(g_pFPDCtrlLog, "{$}: {$}", AttributeRequired, strTemp.c_str()); // // //AttributeDefaultValue // strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"]; // if (strTemp != "") //不需要的配置项为空 // { // DescriptionTemp.add(AttributeDefaultValue, strTemp.c_str()); // ////mLog::FINFO(g_pFPDCtrlLog, "{$}: {$}", AttributeDefaultValue, strTemp.c_str()); // } // // strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"]; // (*m_pDescription).add(strTemp.c_str(), DescriptionTemp); // } // } // catch (exception e) // { // //mLog::FERROR("Get config error: {$}", e.what()); // return ""; // } // // ResDataObject resDeviceResource; // resDeviceResource.add(ConfKey::CcosDetectorAttribute, (*m_pAttribute)); // resDeviceResource.add(ConfKey::CcosDetectorDescription, (*m_pDescription)); // // ResDataObject DescriptionTempEx; // DescriptionTempEx.add(ConfKey::CcosDetectorConfig, resDeviceResource); // // m_DeviceConfig = DescriptionTempEx; // // string res = DescriptionTempEx.encode(); // // //mLog::FINFO("resDeviceResource :{$} \n", DescriptionTempEx.encode()); // return res; //} RET_STATUS DATA_ACTION ContainerDPC::GetDeviceConfig(ResDataObject PARAM_OUT* pDeviceConfig) { //mLog::FINFO( "GetDeviceConfig start"); std::string strDeviceConfig; //if (m_NewDevManager->GetDeviceConfig(strDeviceConfig)) //{ // pDeviceConfig->decode(strDeviceConfig.c_str()); //} //else //{ // return RET_FAILED; //} //mLog::FINFO( "GetDeviceConfig Over"); return RET_SUCCEED; } RET_STATUS DATA_ACTION ContainerDPC::SetDeviceConfig(ResDataObject PARAM_IN* DeviceConfig) { //mLog::FINFO( "SetDeviceConfig start"); std::string strDeviceConfig = DeviceConfig->encode(); //if (m_NewDevManager->SetDeviceConfig(strDeviceConfig)) //{ //} //else //{ // return RET_FAILED; //} //mLog::FINFO( "SetDeviceConfig Over"); return RET_SUCCEED; }