Added support to run the client on the main thread. Run the Qt4 Client on the main thread.

git-svn-id: http://voip.null.ro/svn/yate@4990 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
oana 2012-04-04 12:31:32 +00:00
parent 145dbcb688
commit 3d323905a0
3 changed files with 68 additions and 4 deletions

View File

@ -25,13 +25,67 @@
#include <yatephone.h> #include <yatephone.h>
#include "qt4/qt4client.h" #include "qt4/qt4client.h"
#define WAIT_ENGINE 10000 //wait 10 seconds for engine to halt
using namespace TelEngine; using namespace TelEngine;
static QtDriver qtdriver; class EngineThread;
static QtDriver qtdriver(false);
static EngineThread* s_engineThread = 0;
class EngineThread : public Thread
{
public:
inline EngineThread()
: Thread("Engine")
{ }
virtual void run();
virtual void cleanup();
};
void EngineThread::run()
{
Engine::engineRun();
Debug(DebugAll,"Engine stopped running");
}
void EngineThread::cleanup()
{
Debug(DebugAll,"EngineThread::cleanup() [%p]",this);
s_engineThread = 0;
}
extern "C" int main(int argc, const char** argv, const char** envp) extern "C" int main(int argc, const char** argv, const char** envp)
{ {
TelEngine::Engine::extraPath("qt4"); TelEngine::Engine::extraPath("qt4");
return TelEngine::Engine::main(argc,argv,envp,TelEngine::Engine::Client); // parse arguments
int retcode = TelEngine::Engine::main(argc,argv,envp,TelEngine::Engine::ClientMainThread);
if (retcode)
return retcode;
// create engine from this thread
Engine::self();
s_engineThread = new EngineThread;
if (!s_engineThread->startup())
return EINVAL;
// build client if the driver didn't
if (!QtClient::self())
new QtClient();
// run the client
QtClient::self()->run();
// the client finished running, do cleanup
QtClient::self()->cleanup();
// wait for the engine to halt
Engine::halt(0);
unsigned long count = WAIT_ENGINE / Thread::idleMsec();
while (s_engineThread && count--)
Thread::idle();
Thread::killall();
return retcode;
} }
/* vi: set ts=8 sw=4 sts=4 noet: */ /* vi: set ts=8 sw=4 sts=4 noet: */

View File

@ -735,7 +735,7 @@ static bool logFileOpen()
return false; return false;
} }
static int engineRun() int Engine::engineRun()
{ {
time_t t = ::time(0); time_t t = ::time(0);
s_startMsg << "Yate (" << ::getpid() << ") is starting " << ::ctime(&t); s_startMsg << "Yate (" << ::getpid() << ") is starting " << ::ctime(&t);
@ -1837,6 +1837,9 @@ int Engine::main(int argc, const char** argv, const char** env, RunMode mode, bo
bool daemonic = false; bool daemonic = false;
bool supervised = false; bool supervised = false;
#endif #endif
bool noStart = (mode == ClientMainThread);
if (noStart)
mode = Client;
bool client = (mode == Client); bool client = (mode == Client);
Debugger::Formatting tstamp = Debugger::None; Debugger::Formatting tstamp = Debugger::None;
bool colorize = false; bool colorize = false;
@ -2287,7 +2290,7 @@ int Engine::main(int argc, const char** argv, const char** env, RunMode mode, bo
} }
else else
#endif #endif
retcode = engineRun(); retcode = noStart ? 0 : engineRun();
return retcode; return retcode;
} }

View File

@ -821,6 +821,7 @@ public:
Server = 2, Server = 2,
Client = 3, Client = 3,
ClientProxy = 4, ClientProxy = 4,
ClientMainThread = 5,
}; };
enum CallAccept { enum CallAccept {
@ -1152,6 +1153,12 @@ public:
*/ */
static void clearEvents(const String& type); static void clearEvents(const String& type);
/**
* Start running the engine
* @return The code with which the engine has stopped
*/
static int engineRun();
protected: protected:
/** /**
* Destroys the engine and everything. You must not call it directly, * Destroys the engine and everything. You must not call it directly,