Added Engine.alarm() method in Javascript.

git-svn-id: http://yate.null.ro/svn/yate/trunk@5564 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2013-07-05 12:50:18 +00:00
parent 863247ff31
commit 2d7d0489d5
1 changed files with 41 additions and 0 deletions

View File

@ -211,6 +211,7 @@ public:
: JsObject("Engine",mtx,true),
m_worker(0), m_debugName("javascript")
{
debugName(m_debugName);
debugChain(&__plugin);
MKDEBUG(Fail);
MKDEBUG(Test);
@ -225,6 +226,7 @@ public:
MKDEBUG(All);
params().addParam(new ExpFunction("output"));
params().addParam(new ExpFunction("debug"));
params().addParam(new ExpFunction("alarm"));
params().addParam(new ExpFunction("sleep"));
params().addParam(new ExpFunction("usleep"));
params().addParam(new ExpFunction("yield"));
@ -606,6 +608,45 @@ bool JsEngine::runNative(ObjList& stack, const ExpOperation& oper, GenObject* co
Debug(this,level,"%s",str.c_str());
}
}
else if (oper.name() == YSTRING("alarm")) {
if (oper.number() < 2)
return false;
int level = -1;
String info;
String str;
for (long int i = oper.number(); i; i--) {
ExpOperation* op = popValue(stack,context);
if (!op)
continue;
if (i == 1) {
if (level < 0) {
if (op->isInteger())
level = op->number();
else
return false;
}
else
info = *op;
}
else if ((i == 2) && oper.number() > 2 && op->isInteger())
level = op->number();
else if (*op) {
if (str)
str = *op + " " + str;
else
str = *op;
}
TelEngine::destruct(op);
}
if (str && level >= 0) {
int limit = s_allowAbort ? DebugFail : DebugGoOn;
if (level > DebugAll)
level = DebugAll;
else if (level < limit)
level = limit;
Alarm(this,info,level,"%s",str.c_str());
}
}
else if (oper.name() == YSTRING("sleep")) {
if (oper.number() != 1)
return false;