void MPluginList::retry_all(PLUG_LOADTIME now) { int i; MPlugin *iplug; for(i=0; i < endlist; i++) { iplug=&plist[i]; if(iplug->action != PA_NONE) iplug->retry(now, PNL_DELAYED); } }
void MPluginList::unpause_all(void) { int i; MPlugin *iplug; for(i=0; i < endlist; i++) { iplug=&plist[i]; if(iplug->status==PL_PAUSED) iplug->unpause(); } }
MPlugin* MEngine::loadPlugin(const char* name) { M_PROFILE_SCOPE(MEngine::loadPlugin); MPlugin* plugin = new MPlugin; plugin->load(name); if(plugin->isLoaded()) { m_Plugins.push_back(plugin); return plugin; } delete plugin; return 0; }
void MaratisPlayer::loadGamePlugin(void) { char gameFile[256]; MWindow * window = MWindow::getInstance(); #ifdef WIN32 getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.dll"); #elif __APPLE__ getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.dylib"); #elif linux getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.so"); #endif // try to load any other plugins in the game directory first // as the game may expect these to be loaded vector<string> files; readDirectory(window->getWorkingDirectory(), &files); for(vector<string>::iterator iFile = files.begin(); iFile != files.end(); iFile++) { if(*iFile == gameFile) continue; #ifdef WIN32 if(iFile->find(".dll") != string::npos) #elif __APPLE__ if(iFile->find(".dylib") != string::npos) #elif linux if(iFile->find(".so") != string::npos) #endif { char pluginPath[256]; getGlobalFilename(pluginPath, window->getWorkingDirectory(), iFile->c_str()); MPlugin* plugin = new MPlugin(); plugin->load(pluginPath); if(plugin->getFilename()) m_plugins.push_back(plugin); else SAFE_DELETE(plugin); } } // After all other plugins are loaded, we can load the game // as we assume all prerequisites are loaded SAFE_DELETE(m_gamePlugin); m_gamePlugin = new MPlugin(); m_gamePlugin->load(gameFile); }
void MPluginList::show(int source_index) { int i, n=0, r=0; MPlugin *pl; char desc[15+1], file[16+1], vers[7+1]; // plus 1 for term null if (source_index <= 0) META_CONS("Currently loaded plugins:"); else META_CONS("Child plugins:"); META_CONS(" %*s %-*s %-4s %-4s %-*s v%-*s %-3s %-5s %-5s", WIDTH_MAX_PLUGINS, "", sizeof(desc)-1, "description", "stat", "pend", sizeof(file)-1, "file", sizeof(vers)-1, "ers", "src", "load ", "unlod"); for(i=0; i < endlist; i++) { pl=&plist[i]; if(pl->status < PL_VALID) continue; if ((source_index > 0) && (pl->source_plugin_index != source_index)) continue; STRNCPY(desc, pl->desc, sizeof(desc)); STRNCPY(file, pl->file, sizeof(file)); if(pl->info && pl->info->version) STRNCPY(vers, pl->info->version, sizeof(vers)); else STRNCPY(vers, " -", sizeof(vers)); META_CONS(" [%*d] %-*s %-4s %-4s %-*s v%-*s %-3s %-5s %-5s", WIDTH_MAX_PLUGINS, pl->index, sizeof(desc)-1, desc, pl->str_status(ST_SHOW), pl->str_action(SA_SHOW), sizeof(file)-1, file, sizeof(vers)-1, vers, pl->str_source(SO_SHOW), pl->str_loadable(SL_SHOW), pl->str_unloadable(SL_SHOW)); if(pl->status == PL_RUNNING) r++; n++; } META_CONS("%d plugins, %d running", n, r); }
mBOOL MPluginList::refresh(PLUG_LOADTIME now) { int i, ndone=0, nkept=0, nloaded=0, nunloaded=0, nreloaded=0, ndelayed=0; MPlugin *iplug; if (!ini_refresh()) { META_ERROR("dll: Problem reloading plugins.ini: %s", inifile); // meta_errno should be already set in ini_refresh() return(mFALSE); } META_LOG("dll: Updating plugins..."); for(i=0; i < endlist; i++) { iplug=&plist[i]; if(iplug->status < PL_VALID) continue; switch(iplug->action) { case PA_KEEP: META_DEBUG(1, ("Keeping plugin '%s'", iplug->desc)); iplug->action=PA_NONE; nkept++; break; case PA_LOAD: META_DEBUG(1, ("Loading plugin '%s'", iplug->desc)); if(iplug->load(now)) nloaded++; else if(meta_errno==ME_DELAYED) ndelayed++; break; case PA_RELOAD: META_DEBUG(1, ("Reloading plugin '%s'", iplug->desc)); if(iplug->reload(now, PNL_FILE_NEWER)) nreloaded++; else if(meta_errno==ME_DELAYED) ndelayed++; break; case PA_NONE: // If previously loaded from ini, but apparently removed from new ini. if(iplug->source==PS_INI && iplug->status >= PL_RUNNING) { META_DEBUG(1, ("Unloading plugin '%s'", iplug->desc)); iplug->action=PA_UNLOAD; if(iplug->unload(now, PNL_INI_DELETED, PNL_INI_DELETED)) nunloaded++; else if(meta_errno==ME_DELAYED) ndelayed++; } break; case PA_ATTACH: // Previously requested attach, but was delayed? META_DEBUG(1, ("Retrying attach plugin '%s'", iplug->desc)); if(iplug->retry(now, PNL_DELAYED)) nloaded++; else if(meta_errno==ME_DELAYED) ndelayed++; break; case PA_UNLOAD: // Previously requested unload, but was delayed? META_DEBUG(1, ("Retrying unload plugin '%s'", iplug->desc)); if(iplug->retry(now, PNL_DELAYED)) nunloaded++; else if(meta_errno==ME_DELAYED) ndelayed++; break; case PA_NULL: META_ERROR("dll: Unexpected action for plugin '%s': '%s'", iplug->desc, iplug->str_action()); break; default: META_ERROR("dll: Unrecognized action for plugin '%s': '%s'", iplug->desc, iplug->str_action()); break; } ndone++; } META_LOG("dll: Finished updating %d plugins; kept %d, loaded %d, unloaded %d, reloaded %d, delayed %d", ndone, nkept, nloaded, nunloaded, nreloaded, ndelayed); return(mTRUE); }