1.1 --- a/core/systems/ExtensionSys.cpp Mon May 26 07:48:26 2008 +0000
1.2 +++ b/core/systems/ExtensionSys.cpp Mon May 26 07:51:11 2008 +0000
1.3 @@ -266,43 +266,12 @@
1.4 }
1.5 }
1.6
1.7 -void CExtension::AddPlugin(IPlugin *pPlugin)
1.8 +void CExtension::AddPlugin(CPlugin *pPlugin)
1.9 {
1.10 /* Unfortunately we have to do this :( */
1.11 - if (m_Plugins.find(pPlugin) != m_Plugins.end())
1.12 - {
1.13 - m_Plugins.push_back(pPlugin);
1.14 - }
1.15 -}
1.16 -
1.17 -void CExtension::RemovePlugin(IPlugin *pPlugin)
1.18 -{
1.19 - m_Plugins.remove(pPlugin);
1.20 -
1.21 - List<WeakNative>::iterator iter = m_WeakNatives.begin();
1.22 - while (iter != m_WeakNatives.end())
1.23 + if (m_Dependents.find(pPlugin) != m_Dependents.end())
1.24 {
1.25 - if ((*iter).pl == pPlugin)
1.26 - {
1.27 - iter = m_WeakNatives.erase(iter);
1.28 - }
1.29 - else
1.30 - {
1.31 - iter++;
1.32 - }
1.33 - }
1.34 -
1.35 - iter = m_ReplacedNatives.begin();
1.36 - while (iter != m_ReplacedNatives.end())
1.37 - {
1.38 - if ((*iter).pl == pPlugin)
1.39 - {
1.40 - iter = m_ReplacedNatives.erase(iter);
1.41 - }
1.42 - else
1.43 - {
1.44 - iter++;
1.45 - }
1.46 + m_Dependents.push_back(pPlugin);
1.47 }
1.48 }
1.49
1.50 @@ -671,7 +640,7 @@
1.51 pExt->AddInterface(pInterface);
1.52 }
1.53
1.54 -void CExtensionManager::BindChildPlugin(IExtension *pParent, IPlugin *pPlugin)
1.55 +void CExtensionManager::BindChildPlugin( IExtension *pParent, CPlugin *pPlugin )
1.56 {
1.57 CExtension *pExt = (CExtension *)pParent;
1.58
1.59 @@ -684,7 +653,7 @@
1.60
1.61 for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++)
1.62 {
1.63 - (*iter)->RemovePlugin(plugin);
1.64 + (*iter)->DropRefsTo((CPlugin *)plugin);
1.65 }
1.66 }
1.67
1.68 @@ -709,77 +678,6 @@
1.69 return NULL;
1.70 }
1.71
1.72 -void CExtensionManager::BindAllNativesToPlugin(IPlugin *pPlugin)
1.73 -{
1.74 - IPluginContext *pContext = pPlugin->GetBaseContext();
1.75 -
1.76 - List<CExtension *> exts;
1.77 -
1.78 - uint32_t natives = pContext->GetNativesNum();
1.79 - sp_native_t *native;
1.80 - sm_extnative_t *x_native;
1.81 - sm_repnative_t *r_native;
1.82 - for (uint32_t i=0; i<natives; i++)
1.83 - {
1.84 - /* Make sure the native is valid */
1.85 - if (pContext->GetNativeByIndex(i, &native) != SP_ERROR_NONE)
1.86 - {
1.87 - continue;
1.88 - }
1.89 -
1.90 - /* Make sure the native is not already bound */
1.91 - if (native->status == SP_NATIVE_BOUND)
1.92 - {
1.93 - /* If it is bound, see if there is a replacement. */
1.94 - if ((r_native = m_RepNatives.retrieve(native->name)) == NULL)
1.95 - {
1.96 - continue;
1.97 - }
1.98 -
1.99 - /* Rewrite the address. Whee! */
1.100 - native->pfn = r_native->info.func;
1.101 -
1.102 - /* Make sure this will unload safely */
1.103 - WeakNative wn((CPlugin *)pPlugin, i);
1.104 - r_native->owner->m_ReplacedNatives.push_back(wn);
1.105 -
1.106 - continue;
1.107 - }
1.108 -
1.109 - /* See if we've got this native in our cache */
1.110 - if ((x_native = m_ExtNatives.retrieve(native->name)) == NULL)
1.111 - {
1.112 - continue;
1.113 - }
1.114 - /* Try and bind it */
1.115 - if (pContext->BindNativeToIndex(i, x_native->info->func) != SP_ERROR_NONE)
1.116 - {
1.117 - continue;
1.118 - }
1.119 - /* See if it's optional */
1.120 - if (native->flags & SP_NTVFLAG_OPTIONAL)
1.121 - {
1.122 - WeakNative wkn = WeakNative((CPlugin *)pPlugin, i);
1.123 - x_native->owner->m_WeakNatives.push_back(wkn);
1.124 - }
1.125 - else if (exts.find(x_native->owner) == exts.end())
1.126 - {
1.127 - exts.push_back(x_native->owner);
1.128 - }
1.129 - }
1.130 -
1.131 - List<CExtension *>::iterator iter;
1.132 - for (iter = exts.begin(); iter != exts.end(); iter++)
1.133 - {
1.134 - CExtension *pExt = (*iter);
1.135 - if (pExt->m_Plugins.find(pPlugin) != pExt->m_Plugins.end())
1.136 - {
1.137 - continue;
1.138 - }
1.139 - pExt->m_Plugins.push_back(pPlugin);
1.140 - }
1.141 -}
1.142 -
1.143 bool CExtensionManager::UnloadExtension(IExtension *_pExt)
1.144 {
1.145 if (!_pExt)
1.146 @@ -804,12 +702,12 @@
1.147 if (pExt->IsLoaded())
1.148 {
1.149 /* Unload any dependent plugins */
1.150 - List<IPlugin *>::iterator p_iter = pExt->m_Plugins.begin();
1.151 - while (p_iter != pExt->m_Plugins.end())
1.152 + List<CPlugin *>::iterator p_iter = pExt->m_Dependents.begin();
1.153 + while (p_iter != pExt->m_Dependents.end())
1.154 {
1.155 /* We have to manually unlink ourselves here, since we're no longer being managed */
1.156 g_PluginSys.UnloadPlugin((*p_iter));
1.157 - p_iter = pExt->m_Plugins.erase(p_iter);
1.158 + p_iter = pExt->m_Dependents.erase(p_iter);
1.159 }
1.160
1.161 List<String>::iterator s_iter;
1.162 @@ -820,30 +718,6 @@
1.163 g_PluginSys.OnLibraryAction((*s_iter).c_str(), false, true);
1.164 }
1.165
1.166 - /* Unbind weak natives */
1.167 - List<WeakNative>::iterator wkn_iter;
1.168 - for (wkn_iter=pExt->m_WeakNatives.begin(); wkn_iter!=pExt->m_WeakNatives.end(); wkn_iter++)
1.169 - {
1.170 - WeakNative & wkn = (*wkn_iter);
1.171 - sp_context_t *ctx = wkn.pl->GetContext();
1.172 - ctx->natives[wkn.idx].status = SP_NATIVE_UNBOUND;
1.173 - }
1.174 -
1.175 - /* Unbind replacement natives, link them back to their originals */
1.176 - for (wkn_iter = pExt->m_ReplacedNatives.begin();
1.177 - wkn_iter != pExt->m_ReplacedNatives.end();
1.178 - wkn_iter++)
1.179 - {
1.180 - WeakNative & wkn = (*wkn_iter);
1.181 - sp_context_t *ctx = wkn.pl->GetContext();
1.182 - sm_repnative_t *r_native = m_RepNatives.retrieve(ctx->natives[wkn.idx].name);
1.183 - if (r_native == NULL || ctx->natives[wkn.idx].pfn != r_native->info.func)
1.184 - {
1.185 - continue;
1.186 - }
1.187 - ctx->natives[wkn.idx].pfn = r_native->original;
1.188 - }
1.189 -
1.190 /* Notify and/or unload all dependencies */
1.191 List<CExtension *>::iterator c_iter;
1.192 CExtension *pDep;
1.193 @@ -898,40 +772,7 @@
1.194 }
1.195
1.196 /* Unbind our natives from Core */
1.197 - List<const sp_nativeinfo_t *>::iterator native_iter;
1.198 - for (native_iter = pExt->m_Natives.begin();
1.199 - native_iter != pExt->m_Natives.end();
1.200 - native_iter++)
1.201 - {
1.202 - const sp_nativeinfo_t *natives = (*native_iter);
1.203 - sm_extnative_t *x_native;
1.204 - for (unsigned int n = 0;
1.205 - natives[n].name != NULL && natives[n].func != NULL;
1.206 - n++)
1.207 - {
1.208 - x_native = m_ExtNatives.retrieve(natives[n].name);
1.209 - if (x_native && x_native->owner == pExt)
1.210 - {
1.211 - m_ExtNatives.remove(natives[n].name);
1.212 - }
1.213 - }
1.214 - }
1.215 -
1.216 - /* Unbind our replacement natives */
1.217 - List<sm_repnative_t>::iterator rep_iter = m_RepNativeList.begin();
1.218 - while (rep_iter != m_RepNativeList.end())
1.219 - {
1.220 - sm_repnative_t & r_native = (*rep_iter);
1.221 - if (r_native.owner == pExt)
1.222 - {
1.223 - m_RepNatives.remove(r_native.info.name);
1.224 - rep_iter = m_RepNativeList.erase(rep_iter);
1.225 - }
1.226 - else
1.227 - {
1.228 - rep_iter++;
1.229 - }
1.230 - }
1.231 + pExt->DropEverything();
1.232
1.233 /* Tell it to unload */
1.234 pAPI = pExt->GetAPI();
1.235 @@ -962,44 +803,6 @@
1.236 return true;
1.237 }
1.238
1.239 -void CExtensionManager::AddNatives(IExtension *pOwner, const sp_nativeinfo_t *natives)
1.240 -{
1.241 - CExtension *pExt = (CExtension *)pOwner;
1.242 -
1.243 - pExt->m_Natives.push_back(natives);
1.244 -
1.245 - for (unsigned int i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
1.246 - {
1.247 - if (m_ExtNatives.retrieve(natives[i].name) != NULL)
1.248 - {
1.249 - continue;
1.250 - }
1.251 - sm_extnative_t x_native;
1.252 - x_native.info = &natives[i];
1.253 - x_native.owner = pExt;
1.254 - m_ExtNatives.insert(natives[i].name, x_native);
1.255 - }
1.256 -}
1.257 -
1.258 -void CExtensionManager::OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives)
1.259 -{
1.260 - SPVM_NATIVE_FUNC orig;
1.261 -
1.262 - for (unsigned int i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
1.263 - {
1.264 - if ((orig = g_PluginSys.FindCoreNative(natives[i].name)) == NULL)
1.265 - {
1.266 - continue;
1.267 - }
1.268 - sm_repnative_t rep;
1.269 - rep.info = natives[i];
1.270 - rep.owner = (CExtension *)myself;
1.271 - rep.original = orig;
1.272 - m_RepNativeList.push_back(rep);
1.273 - m_RepNatives.insert(natives[i].name, rep);
1.274 - }
1.275 -}
1.276 -
1.277 void CExtensionManager::MarkAllLoaded()
1.278 {
1.279 List<CExtension *>::iterator iter;
1.280 @@ -1206,7 +1009,7 @@
1.281 }
1.282
1.283 if (!pExt->IsLoaded()
1.284 - || (!pExt->m_ChildDeps.size() && !pExt->m_Plugins.size()))
1.285 + || (!pExt->m_ChildDeps.size() && !pExt->m_Dependents.size()))
1.286 {
1.287 char filename[PLATFORM_MAX_PATH];
1.288 snprintf(filename, PLATFORM_MAX_PATH, "%s", pExt->GetFilename());
1.289 @@ -1216,7 +1019,7 @@
1.290 }
1.291 else
1.292 {
1.293 - List<IPlugin *> plugins;
1.294 + List<CPlugin *> plugins;
1.295 if (pExt->m_ChildDeps.size())
1.296 {
1.297 g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename());
1.298 @@ -1246,9 +1049,9 @@
1.299 {
1.300 g_RootMenu.ConsolePrint(" -> %s", pExt->GetFilename());
1.301 /* Add to plugin unload list */
1.302 - List<IPlugin *>::iterator p_iter;
1.303 - for (p_iter=pOther->m_Plugins.begin();
1.304 - p_iter!=pOther->m_Plugins.end();
1.305 + List<CPlugin *>::iterator p_iter;
1.306 + for (p_iter=pOther->m_Dependents.begin();
1.307 + p_iter!=pOther->m_Dependents.end();
1.308 p_iter++)
1.309 {
1.310 if (plugins.find((*p_iter)) == plugins.end())
1.311 @@ -1260,12 +1063,12 @@
1.312 }
1.313 }
1.314 }
1.315 - if (pExt->m_Plugins.size())
1.316 + if (pExt->m_Dependents.size())
1.317 {
1.318 g_RootMenu.ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename());
1.319 - List<IPlugin *>::iterator iter;
1.320 - IPlugin *pPlugin;
1.321 - for (iter = pExt->m_Plugins.begin(); iter != pExt->m_Plugins.end(); iter++)
1.322 + List<CPlugin *>::iterator iter;
1.323 + CPlugin *pPlugin;
1.324 + for (iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++)
1.325 {
1.326 pPlugin = (*iter);
1.327 if (plugins.find(pPlugin) == plugins.end())