#include #include "tlmpdia.h" #include "tlmpdia.m" struct UITHREAD_PRIVATE{ PRIVATE_MESSAGE msg; bool endwait; UITHREAD_PRIVATE(){ endwait = false; } }; struct UITHREAD_INFO{ PRIVATE_MESSAGE *msg; int no; int &count; _F_uithread *c; UITHREAD_INFO( PRIVATE_MESSAGE &_msg, int &_count, int _no, _F_uithread &_c) : count(_count) { msg = &_msg; no = _no; c = &_c; } }; static void start_thread(void *data) { UITHREAD_INFO *info = (UITHREAD_INFO*)data; switch (info->no){ case 0: info->c->thread1(); break; case 1: info->c->thread2(); break; case 2: info->c->thread3(); break; case 3: info->c->thread4(); break; case 4: info->c->thread5(); break; } info->count++; dialog_sendmessage (*info->msg); delete info; } void _F_uithread::thread2() { } void _F_uithread::thread3() { } void _F_uithread::thread4() { } void _F_uithread::thread5() { } /* Tell the parent thread to continue. This is usually done when the child have copied all the information from the parent so they are independant. */ void _F_uithread::dontwait() { priv->endwait = true; dialog_sendmessage (priv->msg); } void uithread (_F_uithread &c, bool allmode) { UITHREAD_PRIVATE priv; c.priv = &priv; if (dialog_mode != DIALOG_GUI){ if (allmode){ // In none GUI mode, we simply execute the threads // one after the other. In general, only thread1 is defined // for dialog useful in non-gui mode, so we call thread1 // and wait and then thread2. c.thread1(); c.thread2(); c.thread3(); c.thread4(); c.thread5(); }else{ xconf_error (MSG_U(E_ONLYGUIMODE ,"TLMP component uithread only works in GUI mode.\n" "Maybe the GUI is not initialised yet.")); } }else{ int count = 0; uithread (start_thread,new UITHREAD_INFO(priv.msg,count,0,c)); uithread (start_thread,new UITHREAD_INFO(priv.msg,count,1,c)); uithread (start_thread,new UITHREAD_INFO(priv.msg,count,2,c)); uithread (start_thread,new UITHREAD_INFO(priv.msg,count,3,c)); uithread (start_thread,new UITHREAD_INFO(priv.msg,count,4,c)); while (count < 5 && !priv.endwait){ dialog_waitformessage (priv.msg); } } } void uithread (_F_uithread &c) { uithread (c,false); }