2
0
mirror of https://github.com/rehlds/metamod-r.git synced 2025-03-03 17:15:26 +03:00

Make correct messages for delayed load/unload

This commit is contained in:
asmodai 2017-05-09 19:59:13 +03:00
parent 06d78fe775
commit 895dea5eba
4 changed files with 37 additions and 25 deletions

View File

@ -364,11 +364,12 @@ void cmd_doplug(PLUG_CMD pcmd)
case PC_UNLOAD:
{
findp->set_action(PA_UNLOAD);
if (findp->unload(PT_ANYTIME, PNL_COMMAND)) {
bool delayed;
if (findp->unload(PT_ANYTIME, PNL_COMMAND, delayed)) {
META_CONS("Unloaded plugin '%s'", findp->description());
g_plugins->show();
}
else if (false /*meta_errno == ME_DELAYED*/) // TODO
else if (delayed)
META_CONS("Unload delayed for plugin '%s'", findp->description());
else
META_CONS("Unload failed for plugin '%s'", findp->description());
@ -377,7 +378,8 @@ void cmd_doplug(PLUG_CMD pcmd)
case PC_FORCE_UNLOAD:
{
findp->set_action(PA_UNLOAD);
if (findp->unload(PT_ANYTIME, PNL_CMD_FORCED)) {
bool delayed;
if (findp->unload(PT_ANYTIME, PNL_CMD_FORCED, delayed)) {
META_CONS("Forced unload plugin '%s'", findp->description());
g_plugins->show();
}
@ -388,12 +390,11 @@ void cmd_doplug(PLUG_CMD pcmd)
case PC_RELOAD:
{
findp->set_action(PA_RELOAD);
if (findp->reload(PT_ANYTIME, PNL_COMMAND))
bool delayed;
if (findp->reload(PT_ANYTIME, PNL_COMMAND, delayed))
META_CONS("Reloaded plugin '%s'", findp->description());
else if (0/*meta_errno == ME_DELAYED*/) // TODO
else if (delayed)
META_CONS("Reload delayed for plugin '%s'", findp->description());
else if (0/*meta_errno == ME_NOTALLOWED*/)
META_CONS("Reload not allowed for plugin '%s' now, only allowed %s", findp->description(), findp->str_loadable(SL_ALLOWED));
else
META_CONS("Reload failed for plugin '%s'", findp->description());
break;

View File

@ -191,7 +191,8 @@ MPlugin* MPluginList::plugin_addload(plid_t plid, const char* fname, PLUG_LOADTI
}
pl_added->m_action = PA_LOAD;
if (!pl_added->load(now)) {
bool delayed;
if (!pl_added->load(now, delayed)) {
if (pl_added->m_status == PL_OPENED) {
META_DEBUG(1, "Opened plugin '%s', but failed to attach; see log", pl_added->m_desc);
}
@ -448,7 +449,8 @@ bool MPluginList::cmd_addload(const char* args)
// try to load new plugin
pl_added->m_action = PA_LOAD;
if (!pl_added->load(PT_ANYTIME)) {
bool delayed;
if (!pl_added->load(PT_ANYTIME, delayed)) {
// load failed
if (pl_added->m_status == PL_OPENED)
META_CONS("Opened plugin '%s', but failed to attach; see log", pl_added->m_desc);
@ -479,7 +481,8 @@ bool MPluginList::load()
if (m_plist[i].m_status < PL_VALID)
continue;
if (m_plist[i].load(PT_STARTUP))
bool delayed;
if (m_plist[i].load(PT_STARTUP, delayed))
n++;
else
// all plugins should be loadable at startup...
@ -502,6 +505,7 @@ bool MPluginList::refresh(PLUG_LOADTIME now)
}
META_LOG("dll: Updating plugins...");
bool delayed;
for (int i = 0; i < m_max_loaded_count; i++) {
auto iplug = &m_plist[i];
if (iplug->m_status < PL_VALID)
@ -515,14 +519,14 @@ bool MPluginList::refresh(PLUG_LOADTIME now)
break;
case PA_LOAD:
META_DEBUG(1, "Loading plugin '%s'", iplug->m_desc);
if (iplug->load(now))
if (iplug->load(now, delayed))
nloaded++;
/*else if (meta_errno == ME_DELAYED) TODO
ndelayed++;*/
break;
case PA_RELOAD:
META_DEBUG(1, "Reloading plugin '%s'", iplug->m_desc);
if (iplug->reload(now, PNL_FILE_NEWER))
if (iplug->reload(now, PNL_FILE_NEWER, delayed))
nreloaded++;
/*else if (meta_errno == ME_DELAYED) TODO
ndelayed++;*/
@ -532,7 +536,7 @@ bool MPluginList::refresh(PLUG_LOADTIME now)
if (iplug->m_source == PS_INI && iplug->m_status >= PL_RUNNING) {
META_DEBUG(1, "Unloading plugin '%s'", iplug->m_desc);
iplug->m_action = PA_UNLOAD;
if (iplug->unload(now, PNL_INI_DELETED))
if (iplug->unload(now, PNL_INI_DELETED, delayed))
nunloaded++;
/*else if (meta_errno == ME_DELAYED) TODO
ndelayed++;*/

View File

@ -372,8 +372,9 @@ bool MPlugin::platform_match(MPlugin *other) const
}
// Load a plugin; query, check allowed time, attach.
bool MPlugin::load(PLUG_LOADTIME now)
bool MPlugin::load(PLUG_LOADTIME now, bool& delayed)
{
delayed = false;
if (!check_input()) {
return false;
}
@ -405,6 +406,7 @@ bool MPlugin::load(PLUG_LOADTIME now)
if (m_info->loadable > PT_STARTUP) {
// will try to attach again at next opportunity
META_DEBUG(2, "dll: Delaying load plugin '%s'; can't attach now: allowed=%s; now=%s", m_desc, str_loadable(), str_loadtime(now, SL_SIMPLE));
delayed = true;
return false;
}
@ -445,8 +447,9 @@ bool MPlugin::load(PLUG_LOADTIME now)
}
// Unload a plugin. Check time, detach.
bool MPlugin::unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
bool MPlugin::unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason, bool& delayed)
{
delayed = false;
if (!check_input()) {
return false;
}
@ -472,6 +475,7 @@ bool MPlugin::unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
META_DEBUG(2, "dll: Delaying unload plugin '%s'; can't detach now: allowed=%s; now=%s", m_desc, str_unloadable(), str_loadtime(now, SL_SIMPLE));
// caller should give message to user
// try to unload again at next opportunity
delayed = true;
return false;
}
@ -534,8 +538,9 @@ bool MPlugin::unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
}
// Reload a plugin; unload and load again.
bool MPlugin::reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
bool MPlugin::reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason, bool& delayed)
{
delayed = false;
if (!check_input()) {
return false;
}
@ -560,12 +565,12 @@ bool MPlugin::reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
reason = PNL_RELOAD;
}
if (!unload(now, reason)) {
if (!unload(now, reason, delayed)) {
META_WARNING("dll: Failed to unload plugin '%s' for reloading", m_desc);
return false;
}
if (!load(now)) {
if (!load(now, delayed)) {
META_WARNING("dll: Failed to reload plugin '%s' after unloading", m_desc);
return false;
}
@ -613,12 +618,13 @@ bool MPlugin::unpause()
// Retry pending action, presumably from a previous failure.
bool MPlugin::retry(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
{
bool delayed;
if (m_action == PA_LOAD || m_action == PA_ATTACH)
return load(now);
return load(now, delayed);
if (m_action == PA_UNLOAD)
return unload(now, reason);
return unload(now, reason, delayed);
if (m_action == PA_RELOAD)
return reload(now, reason);
return reload(now, reason, delayed);
META_ERROR("No pending action to retry for plugin '%s'; (status=%s, action=%s)", m_desc, str_status(), str_action());
return false;
@ -703,8 +709,9 @@ bool MPlugin::plugin_unload(plid_t plid, PLUG_LOADTIME now, PL_UNLOAD_REASON rea
//try unload
PLUG_ACTION old_action = m_action;
m_action = PA_UNLOAD;
bool delayed;
if (unload(now, reason)) {
if (unload(now, reason, delayed)) {
META_DEBUG(1, "Unloaded plugin '%s'", m_desc);
pl_unloader->m_is_unloader = false;
return true;

View File

@ -89,9 +89,9 @@ public:
bool platform_match(MPlugin* plugin) const; // check if a given plugin is the same but possibly for a different platform
bool load(PLUG_LOADTIME now); // load parsed plugin
bool unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
bool reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason);
bool load(PLUG_LOADTIME now, bool& delayed); // load parsed plugin
bool unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason, bool& delayed);
bool reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason, bool& delayed);
bool pause();
bool unpause();
bool retry(PLUG_LOADTIME now, PL_UNLOAD_REASON reason); // if previously failed