Unload script on end execution and error
A ScriptEngineAgent is added to monitor the execution of a script. If it ends it stops the script to free resources. The same is done in case of an exception, just that in this case the script takes care of unloading itself. REVIEW: 104871
This commit is contained in:
parent
c66c78f1d2
commit
c3fce865ee
2 changed files with 30 additions and 0 deletions
|
@ -157,6 +157,7 @@ KWin::Script::Script(int id, QString scriptName, QString pluginName, QObject* pa
|
|||
: AbstractScript(id, scriptName, pluginName, parent)
|
||||
, m_engine(new QScriptEngine(this))
|
||||
, m_starting(false)
|
||||
, m_agent(new ScriptUnloaderAgent(this))
|
||||
{
|
||||
QDBusConnection::sessionBus().registerObject('/' + QString::number(scriptId()), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportScriptableInvokables);
|
||||
}
|
||||
|
@ -235,6 +236,19 @@ void KWin::Script::sigException(const QScriptValue& exception)
|
|||
}
|
||||
}
|
||||
emit printError(exception.toString());
|
||||
stop();
|
||||
}
|
||||
|
||||
KWin::ScriptUnloaderAgent::ScriptUnloaderAgent(KWin::Script *script)
|
||||
: QScriptEngineAgent(script->engine())
|
||||
, m_script(script)
|
||||
{
|
||||
script->engine()->setAgent(this);
|
||||
}
|
||||
|
||||
void KWin::ScriptUnloaderAgent::scriptUnload(qint64 id)
|
||||
{
|
||||
m_script->stop();
|
||||
}
|
||||
|
||||
KWin::DeclarativeScript::DeclarativeScript(int id, QString scriptName, QString pluginName, QObject* parent)
|
||||
|
|
|
@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <QtCore/QFile>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtScript/QScriptEngineAgent>
|
||||
|
||||
class QAction;
|
||||
class QDeclarativeView;
|
||||
|
@ -38,6 +39,7 @@ typedef QList< QPair<bool, QPair<QString, QString > > > LoadScriptList;
|
|||
|
||||
namespace KWin
|
||||
{
|
||||
class ScriptUnloaderAgent;
|
||||
class WorkspaceWrapper;
|
||||
|
||||
class AbstractScript : public QObject
|
||||
|
@ -108,6 +110,9 @@ public:
|
|||
|
||||
Script(int id, QString scriptName, QString pluginName, QObject *parent = NULL);
|
||||
virtual ~Script();
|
||||
QScriptEngine *engine() {
|
||||
return m_engine;
|
||||
}
|
||||
|
||||
public Q_SLOTS:
|
||||
Q_SCRIPTABLE void run();
|
||||
|
@ -134,6 +139,17 @@ private:
|
|||
QByteArray loadScriptFromFile();
|
||||
QScriptEngine *m_engine;
|
||||
bool m_starting;
|
||||
QScopedPointer<ScriptUnloaderAgent> m_agent;
|
||||
};
|
||||
|
||||
class ScriptUnloaderAgent : public QScriptEngineAgent
|
||||
{
|
||||
public:
|
||||
ScriptUnloaderAgent(Script *script);
|
||||
virtual void scriptUnload(qint64 id);
|
||||
|
||||
private:
|
||||
Script *m_script;
|
||||
};
|
||||
|
||||
class DeclarativeScript : public AbstractScript
|
||||
|
|
Loading…
Reference in a new issue