Merge pull request #93 from peace-maker/failstate_dependencies

Pause dependent plugins on SetFailState. (bug 6120, r=dvander)
This commit is contained in:
David Anderson 2015-01-03 10:55:52 -08:00
commit bf3ff460b3
2 changed files with 26 additions and 19 deletions

View File

@ -195,15 +195,20 @@ IPluginRuntime *CPlugin::GetRuntime()
void CPlugin::SetErrorState(PluginStatus status, const char *error_fmt, ...)
{
PluginStatus old_status = m_status;
m_status = status;
if (old_status == Plugin_Running)
if (m_status == Plugin_Running)
{
/* Tell everyone we're now paused */
g_PluginSys._SetPauseState(this, true);
SetPauseState(true);
/* If we won't recover from this error, drop everything and pause dependent plugins too! */
if (status == Plugin_Failed)
{
DropEverything();
}
}
/* SetPauseState sets the status to Plugin_Paused, but we might want to see some other status set. */
m_status = status;
va_list ap;
va_start(ap, error_fmt);
smcore.FormatArgs(m_errormsg, sizeof(m_errormsg), error_fmt, ap);
@ -531,7 +536,8 @@ bool CPlugin::SetPauseState(bool paused)
if (paused && GetStatus() != Plugin_Running)
{
return false;
} else if (!paused && GetStatus() != Plugin_Paused) {
}
else if (!paused && GetStatus() != Plugin_Paused && GetStatus() != Plugin_Error) {
return false;
}
@ -539,6 +545,12 @@ bool CPlugin::SetPauseState(bool paused)
{
LibraryActions(LibraryAction_Removed);
}
else
{
// Set to running again BEFORE trying to call OnPluginPauseChange ;)
m_status = Plugin_Running;
m_pRuntime->SetPauseState(false);
}
IPluginFunction *pFunction = m_pRuntime->GetFunctionByName("OnPluginPauseChange");
if (pFunction)
@ -552,9 +564,6 @@ bool CPlugin::SetPauseState(bool paused)
{
m_status = Plugin_Paused;
m_pRuntime->SetPauseState(true);
} else {
m_status = Plugin_Running;
m_pRuntime->SetPauseState(false);
}
g_PluginSys._SetPauseState(this, paused);
@ -1138,7 +1147,7 @@ void CPluginManager::LoadAll_SecondPass()
if (!RunSecondPass(pPlugin, error, sizeof(error)))
{
g_Logger.LogError("[SM] Unable to load plugin \"%s\": %s", pPlugin->GetFilename(), error);
pPlugin->SetErrorState(Plugin_Failed, "%s", error);
pPlugin->SetErrorState(Plugin_BadLoad, "%s", error);
}
}
}
@ -1496,11 +1505,9 @@ void CPluginManager::TryRefreshDependencies(CPlugin *pPlugin)
if (pPlugin->GetStatus() == Plugin_Error)
{
/* If we got here, all natives are okay again! */
pPlugin->m_status = Plugin_Running;
if (pPlugin->m_pRuntime->IsPaused())
{
pPlugin->m_pRuntime->SetPauseState(false);
_SetPauseState(pPlugin, false);
pPlugin->SetPauseState(false);
}
}
}
@ -2217,7 +2224,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
const sm_plugininfo_t *info = pl->GetPublicInfo();
rootmenu->ConsolePrint(" Filename: %s", pl->GetFilename());
if (pl->GetStatus() <= Plugin_Error)
if (pl->GetStatus() <= Plugin_Error || pl->GetStatus() == Plugin_Failed)
{
if (IS_STR_FILLED(info->name))
{
@ -2240,7 +2247,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
{
rootmenu->ConsolePrint(" URL: %s", info->url);
}
if (pl->GetStatus() == Plugin_Error)
if (pl->GetStatus() == Plugin_Error || pl->GetStatus() == Plugin_Failed)
{
rootmenu->ConsolePrint(" Error: %s", pl->m_errormsg);
}

View File

@ -380,7 +380,7 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params)
if (params[0] == 1)
{
pPlugin->SetErrorState(Plugin_Error, "%s", str);
pPlugin->SetErrorState(Plugin_Failed, "%s", str);
return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "%s", str);
}
@ -391,12 +391,12 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params)
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 1);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
pPlugin->SetErrorState(Plugin_Error, "%s", str);
pPlugin->SetErrorState(Plugin_Failed, "%s", str);
return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "Formatting error (%s)", str);
}
else
{
pPlugin->SetErrorState(Plugin_Error, "%s", buffer);
pPlugin->SetErrorState(Plugin_Failed, "%s", buffer);
return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "%s", buffer);
}
}
@ -774,4 +774,4 @@ REGISTER_NATIVES(coreNatives)
{"LoadFromAddress", LoadFromAddress},
{"StoreToAddress", StoreToAddress},
{NULL, NULL},
};
};