Refactor AskPluginLoad() to contain its own error state.
This commit is contained in:
parent
5eec2e7d6d
commit
5f19fc036d
@ -368,50 +368,40 @@ void CPlugin::Call_OnAllPluginsLoaded()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
APLRes CPlugin::Call_AskPluginLoad(char *error, size_t maxlength)
|
APLRes CPlugin::AskPluginLoad()
|
||||||
{
|
{
|
||||||
if (m_status != Plugin_Created)
|
assert(m_status == Plugin_Created);
|
||||||
{
|
|
||||||
return APLRes_Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_status = Plugin_Loaded;
|
m_status = Plugin_Loaded;
|
||||||
|
|
||||||
|
bool haveNewAPL = true;
|
||||||
|
IPluginFunction *pFunction = m_pRuntime->GetFunctionByName("AskPluginLoad2");
|
||||||
|
if (!pFunction) {
|
||||||
|
pFunction = m_pRuntime->GetFunctionByName("AskPluginLoad");
|
||||||
|
if (!pFunction)
|
||||||
|
return APLRes_Success;
|
||||||
|
haveNewAPL = false;
|
||||||
|
}
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
cell_t result;
|
cell_t result;
|
||||||
bool haveNewAPL = false;
|
|
||||||
IPluginFunction *pFunction = m_pRuntime->GetFunctionByName("AskPluginLoad2");
|
|
||||||
|
|
||||||
if (pFunction)
|
|
||||||
{
|
|
||||||
haveNewAPL = true;
|
|
||||||
}
|
|
||||||
else if (!(pFunction = m_pRuntime->GetFunctionByName("AskPluginLoad")))
|
|
||||||
{
|
|
||||||
return APLRes_Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
pFunction->PushCell(m_handle);
|
pFunction->PushCell(m_handle);
|
||||||
pFunction->PushCell(g_PluginSys.IsLateLoadTime() ? 1 : 0);
|
pFunction->PushCell(g_PluginSys.IsLateLoadTime() ? 1 : 0);
|
||||||
pFunction->PushStringEx(error, maxlength, 0, SM_PARAM_COPYBACK);
|
pFunction->PushStringEx(m_errormsg, sizeof(m_errormsg), 0, SM_PARAM_COPYBACK);
|
||||||
pFunction->PushCell(maxlength);
|
pFunction->PushCell(sizeof(m_errormsg));
|
||||||
if ((err=pFunction->Execute(&result)) != SP_ERROR_NONE)
|
if ((err = pFunction->Execute(&result)) != SP_ERROR_NONE) {
|
||||||
{
|
SetErrorState(Plugin_Failed, "unexpected error %d in AskPluginLoad callback", err);
|
||||||
return APLRes_Failure;
|
return APLRes_Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (haveNewAPL)
|
APLRes res = haveNewAPL
|
||||||
{
|
? (APLRes)result
|
||||||
return (APLRes)result;
|
: (result ? APLRes_Success : APLRes_Failure);
|
||||||
}
|
if (res != APLRes_Success) {
|
||||||
else if (result)
|
m_status = Plugin_Failed;
|
||||||
{
|
if (res == APLRes_SilentFailure)
|
||||||
return APLRes_Success;
|
m_SilentFailure = true;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return APLRes_Failure;
|
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPlugin::Call_OnLibraryAdded(const char *lib)
|
void CPlugin::Call_OnLibraryAdded(const char *lib)
|
||||||
@ -524,11 +514,6 @@ bool CPlugin::IsDebugging()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPlugin::SetSilentlyFailed()
|
|
||||||
{
|
|
||||||
m_SilentFailure = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPlugin::LibraryActions(LibraryAction action)
|
void CPlugin::LibraryActions(LibraryAction action)
|
||||||
{
|
{
|
||||||
List<String>::iterator iter;
|
List<String>::iterator iter;
|
||||||
@ -923,25 +908,11 @@ LoadRes CPluginManager::LoadPlugin(CPlugin **aResult, const char *path, bool deb
|
|||||||
if (plugin->GetStatus() != Plugin_Created)
|
if (plugin->GetStatus() != Plugin_Created)
|
||||||
return LoadRes_Failure;
|
return LoadRes_Failure;
|
||||||
|
|
||||||
APLRes result = plugin->Call_AskPluginLoad(error, maxlength);
|
if (plugin->AskPluginLoad() != APLRes_Success)
|
||||||
switch (result)
|
|
||||||
{
|
|
||||||
case APLRes_Success:
|
|
||||||
LoadExtensions(plugin);
|
|
||||||
return LoadRes_Successful;
|
|
||||||
|
|
||||||
case APLRes_Failure:
|
|
||||||
plugin->SetErrorState(Plugin_Failed, "%s", error);
|
|
||||||
return LoadRes_Failure;
|
return LoadRes_Failure;
|
||||||
|
|
||||||
case APLRes_SilentFailure:
|
LoadExtensions(plugin);
|
||||||
plugin->SetErrorState(Plugin_Failed, "%s", error);
|
return LoadRes_Successful;
|
||||||
plugin->SetSilentlyFailed();
|
|
||||||
return LoadRes_SilentFailure;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return LoadRes_Failure;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType type, char error[], size_t maxlength, bool *wasloaded)
|
IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType type, char error[], size_t maxlength, bool *wasloaded)
|
||||||
@ -1009,7 +980,7 @@ void CPluginManager::LoadAutoPlugin(const char *plugin)
|
|||||||
error);
|
error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == LoadRes_Successful || res == LoadRes_Failure || res == LoadRes_SilentFailure)
|
if (res == LoadRes_Successful || res == LoadRes_Failure)
|
||||||
{
|
{
|
||||||
AddPlugin(pl);
|
AddPlugin(pl);
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,6 @@ enum LoadRes
|
|||||||
LoadRes_Successful,
|
LoadRes_Successful,
|
||||||
LoadRes_AlreadyLoaded,
|
LoadRes_AlreadyLoaded,
|
||||||
LoadRes_Failure,
|
LoadRes_Failure,
|
||||||
LoadRes_SilentFailure,
|
|
||||||
LoadRes_NeverLoad
|
LoadRes_NeverLoad
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -143,7 +142,6 @@ public:
|
|||||||
bool IsDebugging();
|
bool IsDebugging();
|
||||||
PluginStatus GetStatus();
|
PluginStatus GetStatus();
|
||||||
bool IsSilentlyFailed();
|
bool IsSilentlyFailed();
|
||||||
void SetSilentlyFailed();
|
|
||||||
const sm_plugininfo_t *GetPublicInfo();
|
const sm_plugininfo_t *GetPublicInfo();
|
||||||
bool SetPauseState(bool paused);
|
bool SetPauseState(bool paused);
|
||||||
unsigned int GetSerial();
|
unsigned int GetSerial();
|
||||||
@ -194,12 +192,9 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls the OnPluginLoad function, and sets any failed states if necessary.
|
* Calls the OnPluginLoad function, and sets any failed states if necessary.
|
||||||
* NOTE: Valid pre-states are: Plugin_Created
|
* After invoking AskPluginLoad, its state is either Running or Failed.
|
||||||
* NOTE: If validated, plugin state is changed to Plugin_Loaded
|
|
||||||
*
|
|
||||||
* If the error buffer is NULL, the error message is cached locally.
|
|
||||||
*/
|
*/
|
||||||
APLRes Call_AskPluginLoad(char *error, size_t maxlength);
|
APLRes AskPluginLoad();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls the OnPluginStart function.
|
* Calls the OnPluginStart function.
|
||||||
|
Loading…
Reference in New Issue
Block a user