Fixed OnLibraryAdded/Removed not being called in all plugins (bug 5431, r=psychonic).
Fixed OnLibraryAdded/Removed not being called in all plugins (
bug 5431, r=psychonic).
1.1 --- a/core/ExtensionSys.cpp Fri Dec 14 15:12:22 2012 -0500
1.2 +++ b/core/ExtensionSys.cpp Fri Dec 14 15:15:12 2012 -0500
1.3 @@ -828,7 +828,7 @@
1.4 s_iter != pExt->m_Libraries.end();
1.5 s_iter++)
1.6 {
1.7 - g_PluginSys.OnLibraryAction((*s_iter).c_str(), false, true);
1.8 + g_PluginSys.OnLibraryAction((*s_iter).c_str(), LibraryAction_Removed);
1.9 }
1.10
1.11 /* Notify and/or unload all dependencies */
1.12 @@ -1401,7 +1401,7 @@
1.13 {
1.14 CExtension *pExt = (CExtension *)pSource;
1.15 pExt->AddLibrary(library);
1.16 - g_PluginSys.OnLibraryAction(library, false, false);
1.17 + g_PluginSys.OnLibraryAction(library, LibraryAction_Added);
1.18 }
1.19
1.20 bool CExtensionManager::LibraryExists(const char *library)
2.1 --- a/core/PluginSys.cpp Fri Dec 14 15:12:22 2012 -0500
2.2 +++ b/core/PluginSys.cpp Fri Dec 14 15:15:12 2012 -0500
2.3 @@ -501,14 +501,14 @@
2.4 m_bSilentlyFailed = sf;
2.5 }
2.6
2.7 -void CPlugin::LibraryActions(bool dropping)
2.8 +void CPlugin::LibraryActions(LibraryAction action)
2.9 {
2.10 List<String>::iterator iter;
2.11 for (iter = m_Libraries.begin();
2.12 iter != m_Libraries.end();
2.13 iter++)
2.14 {
2.15 - g_PluginSys.OnLibraryAction((*iter).c_str(), true, dropping);
2.16 + g_PluginSys.OnLibraryAction((*iter).c_str(), action);
2.17 }
2.18 }
2.19
2.20 @@ -523,7 +523,7 @@
2.21
2.22 if (paused)
2.23 {
2.24 - LibraryActions(true);
2.25 + LibraryActions(LibraryAction_Removed);
2.26 }
2.27
2.28 IPluginFunction *pFunction = m_pRuntime->GetFunctionByName("OnPluginPauseChange");
2.29 @@ -547,7 +547,7 @@
2.30
2.31 if (!paused)
2.32 {
2.33 - LibraryActions(false);
2.34 + LibraryActions(LibraryAction_Added);
2.35 }
2.36
2.37 return true;
2.38 @@ -1495,7 +1495,7 @@
2.39 s_iter != pPlugin->m_Libraries.end();
2.40 s_iter++)
2.41 {
2.42 - OnLibraryAction((*s_iter).c_str(), true, false);
2.43 + OnLibraryAction((*s_iter).c_str(), LibraryAction_Added);
2.44 }
2.45
2.46 /* :TODO: optimize? does this even matter? */
2.47 @@ -1597,7 +1597,7 @@
2.48 s_iter != pPlugin->m_Libraries.end();
2.49 s_iter++)
2.50 {
2.51 - OnLibraryAction((*s_iter).c_str(), true, true);
2.52 + OnLibraryAction((*s_iter).c_str(), LibraryAction_Removed);
2.53 }
2.54
2.55 List<IPluginsListener *>::iterator iter;
2.56 @@ -1914,6 +1914,9 @@
2.57 g_RootMenu.AddRootConsoleCommand("plugins", "Manage Plugins", this);
2.58
2.59 g_ShareSys.AddInterface(NULL, this);
2.60 +
2.61 + m_pOnLibraryAdded = g_Forwards.CreateForward("OnLibraryAdded", ET_Ignore, 1, NULL, Param_String);
2.62 + m_pOnLibraryRemoved = g_Forwards.CreateForward("OnLibraryRemoved", ET_Ignore, 1, NULL, Param_String);
2.63 }
2.64
2.65 void CPluginManager::OnSourceModShutdown()
2.66 @@ -1925,6 +1928,9 @@
2.67 g_HandleSys.RemoveType(g_PluginType, m_MyIdent);
2.68 g_ShareSys.DestroyIdentType(g_PluginIdent);
2.69 g_ShareSys.DestroyIdentity(m_MyIdent);
2.70 +
2.71 + g_Forwards.ReleaseForward(m_pOnLibraryAdded);
2.72 + g_Forwards.ReleaseForward(m_pOnLibraryRemoved);
2.73 }
2.74
2.75 ConfigResult CPluginManager::OnSourceModConfigChanged(const char *key,
2.76 @@ -2551,83 +2557,18 @@
2.77 return (CPlugin *)(pToken->ptr);
2.78 }
2.79
2.80 -void CPluginManager::OnLibraryAction(const char *lib, bool is_a_plugin, bool drop)
2.81 +void CPluginManager::OnLibraryAction(const char *lib, LibraryAction action)
2.82 {
2.83 - List<CPlugin *>::iterator iter;
2.84 -
2.85 - struct _pl
2.86 - {
2.87 - cell_t name;
2.88 - cell_t file;
2.89 - cell_t required;
2.90 - } *plc;
2.91 -
2.92 - struct _ext
2.93 - {
2.94 - cell_t name;
2.95 - cell_t file;
2.96 - cell_t autoload;
2.97 - cell_t required;
2.98 - } *ext;
2.99 -
2.100 - const char *name = drop ? "OnLibraryRemoved" : "OnLibraryAdded";
2.101 -
2.102 - for (iter=m_plugins.begin();
2.103 - iter!=m_plugins.end();
2.104 - iter++)
2.105 + switch (action)
2.106 {
2.107 - CPlugin *pl = (*iter);
2.108 - if (pl->GetStatus() != Plugin_Running)
2.109 - {
2.110 - continue;
2.111 - }
2.112 - IPluginContext *pContext = pl->GetBaseContext();
2.113 - IPluginFunction *pf = pContext->GetFunctionByName(name);
2.114 - if (!pf)
2.115 - {
2.116 - continue;
2.117 - }
2.118 - uint32_t num_vars = pContext->GetPubVarsNum();
2.119 - for (uint32_t i=0; i<num_vars; i++)
2.120 - {
2.121 - sp_pubvar_t *pubvar;
2.122 - if (pContext->GetPubvarByIndex(i, &pubvar) != SP_ERROR_NONE)
2.123 - {
2.124 - continue;
2.125 - }
2.126 - if (is_a_plugin && strncmp(pubvar->name, "__pl_", 5) == 0)
2.127 - {
2.128 - plc = (_pl *)pubvar->offs;
2.129 - if (plc->required)
2.130 - {
2.131 - continue;
2.132 - }
2.133 - char *str;
2.134 - pContext->LocalToString(plc->name, &str);
2.135 - if (strcmp(str, lib) != 0)
2.136 - {
2.137 - continue;
2.138 - }
2.139 - pf->PushString(lib);
2.140 - pf->Execute(NULL);
2.141 - }
2.142 - else if (!is_a_plugin && strncmp(pubvar->name, "__ext_", 6) == 0)
2.143 - {
2.144 - ext = (_ext *)pubvar->offs;
2.145 - if (ext->required)
2.146 - {
2.147 - continue;
2.148 - }
2.149 - char *str;
2.150 - pContext->LocalToString(ext->name, &str);
2.151 - if (strcmp(str, lib) != 0)
2.152 - {
2.153 - continue;
2.154 - }
2.155 - pf->PushString(lib);
2.156 - pf->Execute(NULL);
2.157 - }
2.158 - }
2.159 + case LibraryAction_Removed:
2.160 + m_pOnLibraryRemoved->PushString(lib);
2.161 + m_pOnLibraryRemoved->Execute(NULL);
2.162 + break;
2.163 + case LibraryAction_Added:
2.164 + m_pOnLibraryAdded->PushString(lib);
2.165 + m_pOnLibraryAdded->Execute(NULL);
2.166 + break;
2.167 }
2.168 }
2.169
3.1 --- a/core/PluginSys.h Fri Dec 14 15:12:22 2012 -0500
3.2 +++ b/core/PluginSys.h Fri Dec 14 15:15:12 2012 -0500
3.3 @@ -131,6 +131,12 @@
3.4 APLRes_SilentFailure
3.5 };
3.6
3.7 +enum LibraryAction
3.8 +{
3.9 + LibraryAction_Removed,
3.10 + LibraryAction_Added
3.11 +};
3.12 +
3.13 struct AutoConfig
3.14 {
3.15 String autocfg;
3.16 @@ -250,7 +256,7 @@
3.17 {
3.18 m_Libraries.push_back(name);
3.19 }
3.20 - void LibraryActions(bool dropping);
3.21 + void LibraryActions(LibraryAction action);
3.22 void SyncMaxClients(int max_clients);
3.23 protected:
3.24 bool UpdateInfo();
3.25 @@ -403,7 +409,7 @@
3.26
3.27 void Shutdown();
3.28
3.29 - void OnLibraryAction(const char *lib, bool is_a_plugin, bool drop);
3.30 + void OnLibraryAction(const char *lib, LibraryAction action);
3.31
3.32 bool LibraryExists(const char *lib);
3.33
3.34 @@ -475,6 +481,10 @@
3.35
3.36 // Config
3.37 bool m_bBlockBadPlugins;
3.38 +
3.39 + // Forwards
3.40 + IForward *m_pOnLibraryAdded;
3.41 + IForward *m_pOnLibraryRemoved;
3.42 };
3.43
3.44 extern CPluginManager g_PluginSys;