Remove CPluginManager direct use of CPlugin::m_RequiredLibs.

This commit is contained in:
David Anderson 2015-09-19 17:39:36 -07:00
parent 717ad38d06
commit f27dbaf716
2 changed files with 27 additions and 10 deletions

View File

@ -1045,10 +1045,7 @@ bool CPluginManager::FindOrRequirePluginDeps(CPlugin *pPlugin, char *error, size
}
} else {
/* Check that we aren't registering the same library twice */
if (pPlugin->m_RequiredLibs.find(name) != pPlugin->m_RequiredLibs.end())
continue;
pPlugin->m_RequiredLibs.push_back(name);
pPlugin->AddRequiredLib(name);
CPlugin *found;
for (auto iter=m_plugins.begin(); iter!=m_plugins.end(); iter++) {
@ -1114,6 +1111,21 @@ void CPlugin::ForEachLibrary(ke::Lambda<void(const char *)> callback)
callback((*iter).c_str());
}
void CPlugin::AddRequiredLib(const char *name)
{
if (m_RequiredLibs.find(name) == m_RequiredLibs.end())
m_RequiredLibs.push_back(name);
}
bool CPlugin::ForEachRequiredLib(ke::Lambda<bool(const char *)> callback)
{
for (auto iter = m_RequiredLibs.begin(); iter != m_RequiredLibs.end(); iter++) {
if (!callback((*iter).c_str()))
return false;
}
return true;
}
void CPluginManager::LoadExtensions(CPlugin *pPlugin)
{
auto callback = [pPlugin] (const sp_pubvar_t *pubvar, const CPlugin::ExtVar& ext) -> bool
@ -1317,22 +1329,24 @@ void CPluginManager::TryRefreshDependencies(CPlugin *pPlugin)
g_ShareSys.BindNativesToPlugin(pPlugin, false);
for (auto req_iter=pPlugin->m_RequiredLibs.begin(); req_iter!=pPlugin->m_RequiredLibs.end(); req_iter++) {
bool all_found = pPlugin->ForEachRequiredLib([this, pPlugin] (const char *lib) -> bool {
CPlugin *found = nullptr;
for (auto pl_iter=m_plugins.begin(); pl_iter!=m_plugins.end(); pl_iter++) {
CPlugin *search = (*pl_iter);
if (search->HasLibrary((*req_iter).c_str())) {
if (search->HasLibrary(lib)) {
found = search;
break;
}
}
if (!found) {
pPlugin->SetErrorState(Plugin_Error, "Library not found: %s", (*req_iter).c_str());
return;
pPlugin->SetErrorState(Plugin_Error, "Library not found: %s", lib);
return false;
}
found->AddDependent(pPlugin);
}
return true;
});
if (!all_found)
return;
/* Find any unbound natives
* Right now, these are not allowed

View File

@ -270,6 +270,9 @@ public:
return m_errormsg;
}
void AddRequiredLib(const char *name);
bool ForEachRequiredLib(ke::Lambda<bool(const char *)> callback);
protected:
bool ReadInfo();
void DependencyDropped(CPlugin *pOwner);