bool NFCPluginManager::LoadPluginLibrary(const std::string& strPluginDLLName) { PluginLibMap::iterator it = mPluginLibMap.find(strPluginDLLName); if (it == mPluginLibMap.end()) { NFCDynLib* pLib = new NFCDynLib(strPluginDLLName); bool bLoad = pLib->Load(); if (bLoad) { mPluginLibMap.insert(PluginLibMap::value_type(strPluginDLLName, pLib)); DLL_START_PLUGIN_FUNC pFunc = (DLL_START_PLUGIN_FUNC)pLib->GetSymbol("DllStartPlugin"); if (!pFunc) { std::cout << "Find function DllStartPlugin Failed in [" << pLib->GetName() << "]" << std::endl; assert(0); return false; } pFunc(this); return true; } else { #if NF_PLATFORM == NF_PLATFORM_LINUX char* error = dlerror(); if (error) { std::cout << stderr << " Load shared lib[" << pLib->GetName() << "] failed, ErrorNo. = [" << error << "]" << std::endl; std::cout << "Load [" << pLib->GetName() << "] failed" << std::endl; assert(0); return false; } #elif NF_PLATFORM == NF_PLATFORM_WIN std::cout << stderr << " Load DLL[" << pLib->GetName() << "] failed, ErrorNo. = [" << GetLastError() << "]" << std::endl; std::cout << "Load [" << pLib->GetName() << "] failed" << std::endl; assert(0); return false; #endif // NF_PLATFORM } } return false; }
bool NFCPluginManager::ReLoadPlugin(const std::string & strPluginDLLName) { //1.shut all module of this plugin //2.unload this plugin //3.load new plugin //4.init new module //5.tell others who has been reloaded PluginInstanceMap::iterator itInstance = mPluginInstanceMap.find(strPluginDLLName); if (itInstance == mPluginInstanceMap.end()) { return false; } //1 NFIPlugin* pPlugin = itInstance->second; NFIModule* pModule = pPlugin->First(); while (pModule) { pModule->BeforeShut(); pModule->Shut(); pModule->Finalize(); pModule = pPlugin->Next(); } //2 PluginLibMap::iterator it = mPluginLibMap.find(strPluginDLLName); if (it != mPluginLibMap.end()) { NFCDynLib* pLib = it->second; DLL_STOP_PLUGIN_FUNC pFunc = (DLL_STOP_PLUGIN_FUNC)pLib->GetSymbol("DllStopPlugin"); if (pFunc) { pFunc(this); } pLib->UnLoad(); delete pLib; pLib = NULL; mPluginLibMap.erase(it); } //3 NFCDynLib* pLib = new NFCDynLib(strPluginDLLName); bool bLoad = pLib->Load(); if (bLoad) { mPluginLibMap.insert(PluginLibMap::value_type(strPluginDLLName, pLib)); DLL_START_PLUGIN_FUNC pFunc = (DLL_START_PLUGIN_FUNC)pLib->GetSymbol("DllStartPlugin"); if (!pFunc) { std::cout << "Reload Find function DllStartPlugin Failed in [" << pLib->GetName() << "]" << std::endl; assert(0); return false; } pFunc(this); } else { #if NF_PLATFORM == NF_PLATFORM_LINUX char* error = dlerror(); if (error) { std::cout << stderr << " Reload shared lib[" << pLib->GetName() << "] failed, ErrorNo. = [" << error << "]" << std::endl; std::cout << "Reload [" << pLib->GetName() << "] failed" << std::endl; assert(0); return false; } #elif NF_PLATFORM == NF_PLATFORM_WIN std::cout << stderr << " Reload DLL[" << pLib->GetName() << "] failed, ErrorNo. = [" << GetLastError() << "]" << std::endl; std::cout << "Reload [" << pLib->GetName() << "] failed" << std::endl; assert(0); return false; #endif // NF_PLATFORM } //4 PluginInstanceMap::iterator itReloadInstance = mPluginInstanceMap.begin(); for (itReloadInstance; itReloadInstance != mPluginInstanceMap.end(); itReloadInstance++) { if (strPluginDLLName != itReloadInstance->first) { itReloadInstance->second->OnReloadPlugin(); } } return true; }