struct HGenStuff: public std::unary_function<const std::pair<wxString,int>&, void>{ std::map<wxString, DevDesc*>& mapDevs; std::map<wxString, LogDesc*>& mapLogs; HandlerLibData & hData; HGenStuff(std::map<wxString, DevDesc*>&_mapDevs, std::map<wxString, LogDesc*>&_mapLogs,HandlerLibData&_hData): mapDevs(_mapDevs), mapLogs(_mapLogs), hData(_hData) {}; inline void operator()(const std::pair<wxString,TypeFlag>&paInp){ if(paInp.second.isSet(HandlerLibData::DEVICE)){ std::map<std::string,DevInterface*>::iterator itDev; if((itDev = hData.HLI.mapDevs.find(std::string(paInp.first.mb_str())))!=hData.HLI.mapDevs.end()){ mapDevs.insert(std::make_pair(paInp.first, new DevDesc(itDev->second, &hData))); } } if(paInp.second.isSet(HandlerLibData::LOGGER)){ std::map<std::string,Logger *>::iterator itLog; if((itLog = hData.HLI.mapLogs.find(std::string(paInp.first.mb_str())))!=hData.HLI.mapLogs.end()){ mapLogs.insert(std::make_pair(paInp.first, new LogDesc(itLog->second, &hData))); } } } }; struct HandlerActivator: public std::unary_function<HandlerLibData&, void>{ HandlerBroker *pHB; std::map<wxString, DevDesc*>mapDevs; std::map<wxString, LogDesc*>mapLogs; std::map<wxString,std::map<wxString,TypeFlag> > &toUse; bool &bSuccess; HandlerActivator(HandlerBroker *_pHB, std::map<wxString,std::map<wxString,TypeFlag> > &_toUse, bool &_bSuccess):pHB(_pHB), toUse(_toUse), bSuccess(_bSuccess){ }; inline void operator()(HandlerLibData&inp){ std::map<wxString,std::map<wxString,TypeFlag> >::iterator it(toUse.find(inp.md5)); if(it != toUse.end()) std::for_each(it->second.begin(),it->second.end(),HGenStuff(mapDevs,mapLogs , inp)); } ~HandlerActivator(){ if (!pHB->checkLock(mapDevs)) bSuccess = wxYES == wxMessageBox(wxT("Some locks seam to be incompatible. Shall we use new device handlers selection?\n"),wxT("Confirm"), wxYES_NO | wxICON_EXCLAMATION ); if(bSuccess ) pHB->setAvailHandlers(mapDevs, mapLogs); }; }; bool MyFrame::pocessHandlers(std::map<wxString, std::map<wxString,TypeFlag> > &mapHandlersToUse){ std::set<HandlerLibData>::iterator it = strIntConf.setHandlerLibs.begin(); std::set<HandlerLibData>::iterator itEnd = strIntConf.setHandlerLibs.end(); bool bSuccess = true; HandlerActivator hGen(fGetHBroker(),mapHandlersToUse, bSuccess); while(it != itEnd) hGen(*const_cast<HandlerLibData*>(&(*it++))); return bSuccess; } void MyFrame::loadHandlers(){ wxDynamicLibrary dllDev; wxDir dirHandlers(strIntConf.sHandlersDir); wxString sLibName; if (!dirHandlers.GetFirst( &sLibName, wxEmptyString, wxDIR_FILES)) return; do { MD5 md5Op; wxString sFullPath = strIntConf.sHandlersDir + wxFileName::GetPathSeparator() +sLibName; wxString md5 = wxString(md5Op.digestFile((sFullPath).mb_str(wxConvLibc)),wxConvUTF8 ); if (strIntConf.setHandlerLibs.find(HandlerLibData(md5))!=strIntConf.setHandlerLibs.end()) continue; if(!dllDev.Load( sFullPath )) wxLogError(wxString::Format(wxT("Error Loading ")) + sLibName); else{ void (*dynLoad)(HandlerLibInterface *) = reinterpret_cast<void (*)(HandlerLibInterface* )>(dllDev.GetSymbol(wxT("dynLoad"))); if(dynLoad) { HandlerLibInterface HLI; dynLoad(&HLI); strIntConf.setHandlerLibs.insert( HandlerLibData( md5, sLibName, strIntConf.sHandlersDir, HLI,dllDev.Detach())); }else dllDev.Unload(); } }while(dirHandlers.GetNext( &sLibName)); }