Skip to content

Commit

Permalink
Merge pull request xbmc#6308 from Montellese/generic_language_invocat…
Browse files Browse the repository at this point in the history
…ion_cleanup

python: extend ILanguageInvocationHandler to not have to call g_pythonParser directly in CPythonInvoker
  • Loading branch information
Montellese committed Feb 10, 2015
2 parents b07ab06 + 7cce49d commit 48a6862
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 140 deletions.
4 changes: 4 additions & 0 deletions xbmc/interfaces/generic/ILanguageInvocationHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ class ILanguageInvocationHandler

virtual bool Initialize() { return true; }
virtual void Process() { }
virtual void PulseGlobalEvent() { }
virtual void Uninitialize() { }

virtual bool OnScriptInitialized(ILanguageInvoker *invoker) { return true; }
virtual void OnScriptStarted(ILanguageInvoker *invoker) { }
virtual void OnScriptAbortRequested(ILanguageInvoker *invoker) { }
virtual void OnScriptEnded(ILanguageInvoker *invoker) { }
virtual void OnScriptFinalized(ILanguageInvoker *invoker) { }

virtual ILanguageInvoker* CreateInvoker() = 0;
};
28 changes: 28 additions & 0 deletions xbmc/interfaces/generic/ILanguageInvoker.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ILanguageInvoker

void SetId(int id) { m_id = id; }
int GetId() const { return m_id; }
const ADDON::AddonPtr& GetAddon() const { return m_addon; }
void SetAddon(const ADDON::AddonPtr &addon) { m_addon = addon; }
InvokerState GetState() const { return m_state; }
bool IsActive() const { return GetState() > InvokerStateUninitialized && GetState() < InvokerStateDone; }
Expand All @@ -68,17 +69,44 @@ class ILanguageInvoker
virtual bool execute(const std::string &script, const std::vector<std::string> &arguments) = 0;
virtual bool stop(bool abort) = 0;

virtual void pulseGlobalEvent()
{
if (m_invocationHandler)
m_invocationHandler->PulseGlobalEvent();
}

virtual bool onExecutionInitialized()
{
if (m_invocationHandler == NULL)
return false;

return m_invocationHandler->OnScriptInitialized(this);
}

virtual void onAbortRequested()
{
if (m_invocationHandler)
m_invocationHandler->OnScriptAbortRequested(this);
}

virtual void onExecutionFailed()
{
if (m_invocationHandler)
m_invocationHandler->OnScriptEnded(this);
}

virtual void onExecutionDone()
{
if (m_invocationHandler)
m_invocationHandler->OnScriptEnded(this);
}

virtual void onExecutionFinalized()
{
if (m_invocationHandler)
m_invocationHandler->OnScriptFinalized(this);
}

void setState(InvokerState state)
{
if (state <= m_state)
Expand Down
10 changes: 5 additions & 5 deletions xbmc/interfaces/python/PythonInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ CPythonInvoker::~CPythonInvoker()
CLog::Log(LOGDEBUG, "CPythonInvoker(%d): waiting for python thread \"%s\" to stop",
GetId(), (!m_sourceFile.empty() ? m_sourceFile.c_str() : "unknown script"));
Stop(true);
g_pythonParser.PulseGlobalEvent();
pulseGlobalEvent();

if (m_argv != NULL)
{
for (unsigned int i = 0; i < m_argc; i++)
delete [] m_argv[i];
delete [] m_argv;
}
g_pythonParser.FinalizeScript();
onExecutionFinalized();
}

bool CPythonInvoker::Execute(const std::string &script, const std::vector<std::string> &arguments /* = std::vector<std::string>() */)
Expand All @@ -135,7 +135,7 @@ bool CPythonInvoker::Execute(const std::string &script, const std::vector<std::s
return false;
}

if (!g_pythonParser.InitializeEngine())
if (!onExecutionInitialized())
return false;

return ILanguageInvoker::Execute(script, arguments);
Expand Down Expand Up @@ -436,7 +436,7 @@ bool CPythonInvoker::stop(bool abort)

//tell xbmc.Monitor to call onAbortRequested()
if (m_addon != NULL)
g_pythonParser.OnAbortRequested(m_addon->ID());
onAbortRequested();

PyObject *m;
m = PyImport_AddModule((char*)"xbmc");
Expand Down Expand Up @@ -491,7 +491,7 @@ bool CPythonInvoker::stop(bool abort)
}

// If a dialog entered its doModal(), we need to wake it to see the exception
g_pythonParser.PulseGlobalEvent();
pulseGlobalEvent();
}

if (old != NULL)
Expand Down
Loading

0 comments on commit 48a6862

Please sign in to comment.