From a6a00f96609ab6521cf68341802403f896d29eab Mon Sep 17 00:00:00 2001 From: paulc Date: Wed, 16 Jun 2010 09:05:08 +0000 Subject: [PATCH] Added an engine.stop message that modules can use to keep engine running while cleaning up. The engine emits engine.stop every second (but at most 5 times) and shuts down only if the message returned false. git-svn-id: http://yate.null.ro/svn/yate/trunk@3381 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/Engine.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/engine/Engine.cpp b/engine/Engine.cpp index 077a8673..f172cc5e 100644 --- a/engine/Engine.cpp +++ b/engine/Engine.cpp @@ -118,6 +118,10 @@ using namespace TelEngine; #define CFG_SUFFIX ".conf" #endif +// Maximum number of engine.stop messages we allow +#ifndef MAX_STOP +#define MAX_STOP 5 +#endif // Supervisor control constants @@ -1066,7 +1070,8 @@ int Engine::run() #endif Output("Yate%s engine is initialized and starting up%s%s", clientMode() ? " client" : "",s_node.null() ? "" : " on " ,s_node.safe()); - while (s_haltcode == -1) { + int stops = MAX_STOP; + while (s_haltcode == -1 || ((--stops >= 0) && dispatch("engine.stop"))) { if (s_cmds) { Output("Executing initial commands"); for (ObjList* c = s_cmds->skipNull(); c; c=c->skipNext()) { @@ -1136,13 +1141,15 @@ int Engine::run() m->addParam("time",String((int)m->msgTime().sec())); if (nodeName()) m->addParam("nodename",nodeName()); - // Try to fine tune the ticker - t = (long)(m->msgTime().usec() % 1000000); - if (t > 500000) - corr -= (1000000-t)/10; - else - corr += t/10; - XDebug(DebugAll,"Adjustment at %ld, corr %ld",t,corr); + if (s_haltcode == -1) { + // Try to fine tune the ticker unless exiting + t = (long)(m->msgTime().usec() % 1000000); + if (t > 500000) + corr -= (1000000-t)/10; + else + corr += t/10; + XDebug(DebugAll,"Adjustment at %ld, corr %ld",t,corr); + } enqueue(m); Thread::yield(); }