Added public method to pause a script.

git-svn-id: http://yate.null.ro/svn/yate/trunk@5139 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2012-06-20 15:48:03 +00:00
parent 128acd4367
commit 8be6ed4c46
3 changed files with 38 additions and 7 deletions

View File

@ -229,6 +229,7 @@ public:
m_paused(false), m_opcode(0), m_index(0)
{ }
virtual Status reset();
virtual bool pause();
virtual Status call(const String& name, ObjList& args, ExpOperation* thisObj = 0, ExpOperation* scopeObj = 0);
virtual bool callable(const String& name);
protected:
@ -1763,13 +1764,15 @@ bool JsCode::runOperation(ObjList& stack, const ExpOperation& oper, GenObject* c
break;
case OpcNext:
{
ExpOperation* op = popValue(stack,context);
if (!op)
return gotError("Stack underflow",oper.lineNumber());
JsIterator* iter = YOBJECT(JsIterator,op);
if (!iter) {
TelEngine::destruct(op);
return gotError("Expecting runtime iterator",oper.lineNumber());
JsIterator* iter = 0;
ExpOperation* op;
while (!iter) {
op = popValue(stack,context);
if (!op)
return gotError("Stack underflow",oper.lineNumber());
iter = YOBJECT(JsIterator,op);
if (!iter)
TelEngine::destruct(op);
}
bool ok = false;
String* n = iter->get();
@ -2089,6 +2092,22 @@ ScriptRun::Status JsRunner::resume()
return m_paused ? Incomplete : Succeeded;
}
bool JsRunner::pause()
{
Lock mylock(this);
if (m_paused)
return true;
switch (state()) {
case Running:
case Incomplete:
DDebug(DebugAll,"Pausing Javascript runner [%p]",this);
m_paused = true;
return true;
default:
return false;
}
}
ScriptRun::Status JsRunner::call(const String& name, ObjList& args,
ExpOperation* thisObj, ExpOperation* scopeObj)
{

View File

@ -301,6 +301,12 @@ ScriptRun::Status ScriptRun::run()
return s;
}
// Pause the script - not implemented here
bool ScriptRun::pause()
{
return false;
}
// Execute a function or method call
ScriptRun::Status ScriptRun::call(const String& name, ObjList& args,
ExpOperation* thisObj, ExpOperation* scopeObj)

View File

@ -1434,6 +1434,12 @@ public:
*/
virtual Status run();
/**
* Pause the script, make it return Incomplete state
* @return True if pausing the script succeeded or was already paused
*/
virtual bool pause();
/**
* Call a script function or method
* @param name Name of the function to call