#include <GUILoadThread.h>

Definition at line 52 of file GUILoadThread.h.
Public Types | |
| enum | { ID_THREAD_EVENT } |
Public Member Functions | |
| const std::string & | getFileName () const |
| GUILoadThread (MFXInterThreadEventClient *mw, MFXEventQue &eq, FXEX::FXThreadEvent &ev) | |
| constructor | |
| void | load (const std::string &file, bool isNet) |
| begins the loading of the given file | |
| long | onThreadEvent (FXObject *, FXSelector, void *) |
| long | onThreadSignal (FXObject *, FXSelector, void *) |
| void | retrieveMessage (const MsgHandler::MsgType type, const std::string &msg) |
| Retrieves messages from the loading module. | |
| FXint | run () |
| void | signal (FXuint seltype) |
| void | signal () |
| virtual | ~GUILoadThread () |
| destructor | |
Static Public Member Functions | |
| static void | sleep (long ms) |
Protected Member Functions | |
| virtual bool | initOptions () |
| void | submitEndAndCleanup (GUINet *net, SUMOTime simStartTime, SUMOTime simEndTime) |
| Closes the loading process. | |
Protected Attributes | |
| OutputDevice * | myErrorRetriever |
| The instances of message retriever encapsulations Needed to be deleted from the handler later on. | |
| MFXEventQue & | myEventQue |
| FXEX::FXThreadEvent & | myEventThrow |
| std::string | myFile |
| the path to load the simulation from | |
| bool | myLoadNet |
| Information whether only the network shall be loaded. | |
| OutputDevice * | myMessageRetriever |
| MFXInterThreadEventClient * | myParent |
| the parent window to inform about the loading | |
| OutputDevice * | myWarningRetriever |
anonymous enum [inherited] |
| GUILoadThread::GUILoadThread | ( | MFXInterThreadEventClient * | mw, | |
| MFXEventQue & | eq, | |||
| FXEX::FXThreadEvent & | ev | |||
| ) |
constructor
Definition at line 69 of file GUILoadThread.cpp.
References MsgHandler::addRetriever(), MsgHandler::getErrorInstance(), MsgHandler::MT_ERROR, MsgHandler::MT_MESSAGE, MsgHandler::MT_WARNING, myErrorRetriever, myMessageRetriever, myWarningRetriever, and retrieveMessage().
00071 : FXSingleEventThread(gFXApp, mw), myParent(mw), myEventQue(eq), 00072 myEventThrow(ev) { 00073 myErrorRetriever = new MsgRetrievingFunction<GUILoadThread>(this, 00074 &GUILoadThread::retrieveMessage, MsgHandler::MT_ERROR); 00075 myMessageRetriever = new MsgRetrievingFunction<GUILoadThread>(this, 00076 &GUILoadThread::retrieveMessage, MsgHandler::MT_MESSAGE); 00077 myWarningRetriever = new MsgRetrievingFunction<GUILoadThread>(this, 00078 &GUILoadThread::retrieveMessage, MsgHandler::MT_WARNING); 00079 MsgHandler::getErrorInstance()->addRetriever(myErrorRetriever); 00080 }
| GUILoadThread::~GUILoadThread | ( | ) | [virtual] |
destructor
Definition at line 83 of file GUILoadThread.cpp.
References myErrorRetriever, myMessageRetriever, and myWarningRetriever.
00083 { 00084 delete myErrorRetriever; 00085 delete myMessageRetriever; 00086 delete myWarningRetriever; 00087 }
| const std::string & GUILoadThread::getFileName | ( | ) | const |
Definition at line 229 of file GUILoadThread.cpp.
References myFile.
Referenced by GUIApplicationWindow::onUpdReload().
00229 { 00230 return myFile; 00231 }
| bool GUILoadThread::initOptions | ( | ) | [protected, virtual] |
Definition at line 190 of file GUILoadThread.cpp.
References OptionsCont::clear(), MSFrame::fillOptions(), MsgHandler::getErrorInstance(), OptionsIO::getOptions(), OptionsCont::getOptions(), MsgHandler::inform(), myFile, myLoadNet, and OptionsCont::set().
Referenced by run().
00190 { 00191 try { 00192 OptionsCont &oc = OptionsCont::getOptions(); 00193 oc.clear(); 00194 MSFrame::fillOptions(); 00195 if (myLoadNet) { 00196 oc.set("net-file", myFile); 00197 } else { 00198 oc.set("configuration-file", myFile); 00199 } 00200 OptionsIO::getOptions(true, 1, 0); 00201 return true; 00202 } catch (ProcessError &e) { 00203 if (std::string(e.what())!=std::string("Process Error") && std::string(e.what())!=std::string("")) { 00204 MsgHandler::getErrorInstance()->inform(e.what()); 00205 } 00206 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 00207 } 00208 return false; 00209 }
| void GUILoadThread::load | ( | const std::string & | file, | |
| bool | isNet | |||
| ) |
begins the loading of the given file
Definition at line 213 of file GUILoadThread.cpp.
References myFile, and myLoadNet.
Referenced by GUIApplicationWindow::load().
| long FXSingleEventThread::onThreadEvent | ( | FXObject * | , | |
| FXSelector | , | |||
| void * | ||||
| ) | [inherited] |
Definition at line 106 of file FXSingleEventThread.cpp.
References MFXInterThreadEventClient::eventOccured(), and FXSingleEventThread::myClient.
00106 { 00107 myClient->eventOccured(); 00108 /* 00109 FXuint seltype1 = FXSELTYPE(SEL_THREAD); 00110 if(myTarget && myTarget->handle(this,FXSEL(seltype1,mySelector),NULL)) { 00111 } 00112 FXuint seltype = FXSELTYPE(sel); 00113 return myTarget && myTarget->handle(this,FXSEL(seltype,mySelector),NULL); 00114 */ 00115 return 1; 00116 }
| long FXSingleEventThread::onThreadSignal | ( | FXObject * | , | |
| FXSelector | , | |||
| void * | ||||
| ) | [inherited] |
Definition at line 92 of file FXSingleEventThread.cpp.
References PIPE_READ, and FXEX::SEL_THREAD.
00092 { 00093 FXuint seltype=SEL_THREAD; 00094 #ifndef WIN32 00095 ::read(event[PIPE_READ],&seltype,sizeof(seltype)); 00096 #else 00097 //FIXME need win32 support 00098 #endif 00099 FXSelector sel = FXSEL(SEL_THREAD,0); 00100 handle(this,sel,0); 00101 return 0; 00102 }
| void GUILoadThread::retrieveMessage | ( | const MsgHandler::MsgType | type, | |
| const std::string & | msg | |||
| ) |
Retrieves messages from the loading module.
Definition at line 221 of file GUILoadThread.cpp.
References MFXEventQue::add(), myEventQue, myEventThrow, and FXEX::FXThreadEvent::signal().
Referenced by GUILoadThread().
00221 { 00222 GUIEvent *e = new GUIEvent_Message(type, msg); 00223 myEventQue.add(e); 00224 myEventThrow.signal(); 00225 }
| FXint GUILoadThread::run | ( | ) | [virtual] |
starts the thread the thread ends after the net has been loaded
Reimplemented from FXSingleEventThread.
Definition at line 91 of file GUILoadThread.cpp.
References MsgHandler::addRetriever(), NLBuilder::build(), MSFrame::checkOptions(), MsgHandler::clear(), OptionsCont::clear(), MSNet::clearAll(), MsgHandler::getErrorInstance(), MsgHandler::getMessageInstance(), OptionsCont::getOptions(), OptionsCont::getString(), MsgHandler::getWarningInstance(), GUIGlObjectStorage::gIDStorage, MsgHandler::inform(), GUINet::initGUIStructures(), initOptions(), MsgHandler::initOutputOptions(), RandHelper::initRandGlobal(), myErrorRetriever, myMessageRetriever, myWarningRetriever, MsgHandler::report2cerr(), MsgHandler::report2cout(), NLTriggerBuilder::setHandler(), MSFrame::setMSGlobals(), string2time(), and submitEndAndCleanup().
00091 { 00092 GUINet *net = 0; 00093 int simStartTime = 0; 00094 int simEndTime = 0; 00095 00096 // remove old options 00097 OptionsCont &oc = OptionsCont::getOptions(); 00098 oc.clear(); 00099 // within gui-based applications, nothing is reported to the console 00100 MsgHandler::getErrorInstance()->report2cout(false); 00101 MsgHandler::getErrorInstance()->report2cerr(false); 00102 MsgHandler::getWarningInstance()->report2cout(false); 00103 MsgHandler::getWarningInstance()->report2cerr(false); 00104 MsgHandler::getMessageInstance()->report2cout(false); 00105 MsgHandler::getMessageInstance()->report2cerr(false); 00106 // register message callbacks 00107 MsgHandler::getMessageInstance()->addRetriever(myMessageRetriever); 00108 MsgHandler::getErrorInstance()->addRetriever(myErrorRetriever); 00109 MsgHandler::getWarningInstance()->addRetriever(myWarningRetriever); 00110 00111 // try to load the given configuration 00112 if (!initOptions()) { 00113 // the options are not valid 00114 submitEndAndCleanup(net, simStartTime, simEndTime); 00115 return 0; 00116 } 00117 MsgHandler::initOutputOptions(true); 00118 if (!MSFrame::checkOptions()) { 00119 // the options are not valid 00120 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 00121 submitEndAndCleanup(net, simStartTime, simEndTime); 00122 return 0; 00123 } 00124 00125 RandHelper::initRandGlobal(); 00126 // try to load 00127 MSFrame::setMSGlobals(oc); 00128 net = new GUINet(new GUIVehicleControl(), new GUIEventControl(), 00129 new GUIEventControl(), new GUIEventControl()); 00130 GUIEdgeControlBuilder *eb = new GUIEdgeControlBuilder(GUIGlObjectStorage::gIDStorage); 00131 NLJunctionControlBuilder jb(*net, oc); 00132 GUIDetectorBuilder db(*net); 00133 GUIGeomShapeBuilder sb(*net, GUIGlObjectStorage::gIDStorage); 00134 GUITriggerBuilder tb; 00135 NLHandler handler("", *net, db, tb, *eb, jb, sb); 00136 tb.setHandler(&handler); 00137 NLBuilder builder(oc, *net, *eb, jb, db, handler); 00138 try { 00139 MsgHandler::getErrorInstance()->clear(); 00140 MsgHandler::getWarningInstance()->clear(); 00141 MsgHandler::getMessageInstance()->clear(); 00142 if (!builder.build()) { 00143 throw ProcessError(); 00144 } else { 00145 net->initGUIStructures(); 00146 simStartTime = string2time(oc.getString("begin")); 00147 simEndTime = string2time(oc.getString("end")); 00148 } 00149 } catch (ProcessError &e) { 00150 if (std::string(e.what())!=std::string("Process Error") && std::string(e.what())!=std::string("")) { 00151 MsgHandler::getErrorInstance()->inform(e.what()); 00152 } 00153 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); 00154 delete net; 00155 net = 0; 00156 #ifndef _DEBUG 00157 } catch (std::exception &e) { 00158 MsgHandler::getErrorInstance()->inform(e.what()); 00159 delete net; 00160 net = 0; 00161 #endif 00162 } 00163 if (net==0) { 00164 MSNet::clearAll(); 00165 } 00166 delete eb; 00167 submitEndAndCleanup(net, simStartTime, simEndTime); 00168 return 0; 00169 }
| void FXSingleEventThread::signal | ( | FXuint | seltype | ) | [inherited] |
Definition at line 82 of file FXSingleEventThread.cpp.
References FXSingleEventThread::event, and PIPE_WRITE.
00082 { 00083 #ifndef WIN32 00084 ::write(event[PIPE_WRITE],&seltype,sizeof(seltype)); 00085 #else 00086 ::SetEvent(event); 00087 #endif 00088 }
| void FXSingleEventThread::signal | ( | ) | [inherited] |
Definition at line 71 of file FXSingleEventThread.cpp.
References FXSingleEventThread::event, PIPE_WRITE, and FXEX::SEL_THREAD.
00071 { 00072 FXuint seltype=SEL_THREAD; 00073 #ifndef WIN32 00074 ::write(event[PIPE_WRITE],&seltype,sizeof(seltype)); 00075 #else 00076 ::SetEvent(event); 00077 #endif 00078 }
| void FXSingleEventThread::sleep | ( | long | ms | ) | [static, inherited] |
Definition at line 120 of file FXSingleEventThread.cpp.
Referenced by GUIRunThread::run().
00120 { 00121 #ifdef WIN32 00122 Sleep(ms); 00123 #else 00124 long long us = ms * 1000; 00125 usleep(us); 00126 #endif 00127 }
| void GUILoadThread::submitEndAndCleanup | ( | GUINet * | net, | |
| SUMOTime | simStartTime, | |||
| SUMOTime | simEndTime | |||
| ) | [protected] |
Closes the loading process.
This method is called both on success and failure. All message callbacks to this instance are removed and the parent application is informed about the loading
Definition at line 174 of file GUILoadThread.cpp.
References MFXEventQue::add(), MsgHandler::getErrorInstance(), MsgHandler::getMessageInstance(), OptionsCont::getOptions(), MsgHandler::getWarningInstance(), myErrorRetriever, myEventQue, myEventThrow, myFile, myMessageRetriever, myWarningRetriever, MsgHandler::removeRetriever(), and FXEX::FXThreadEvent::signal().
Referenced by run().
00176 { 00177 // remove message callbacks 00178 MsgHandler::getErrorInstance()->removeRetriever(myErrorRetriever); 00179 MsgHandler::getWarningInstance()->removeRetriever(myWarningRetriever); 00180 MsgHandler::getMessageInstance()->removeRetriever(myMessageRetriever); 00181 // inform parent about the process 00182 GUIEvent *e = new GUIEvent_SimulationLoaded(net, simStartTime, simEndTime, myFile, 00183 OptionsCont::getOptions().getString("gui-settings-file")); 00184 myEventQue.add(e); 00185 myEventThrow.signal(); 00186 }
OutputDevice* GUILoadThread::myErrorRetriever [protected] |
The instances of message retriever encapsulations Needed to be deleted from the handler later on.
Definition at line 93 of file GUILoadThread.h.
Referenced by GUILoadThread(), run(), submitEndAndCleanup(), and ~GUILoadThread().
MFXEventQue& GUILoadThread::myEventQue [protected] |
Definition at line 95 of file GUILoadThread.h.
Referenced by retrieveMessage(), and submitEndAndCleanup().
FXEX::FXThreadEvent& GUILoadThread::myEventThrow [protected] |
Definition at line 97 of file GUILoadThread.h.
Referenced by retrieveMessage(), and submitEndAndCleanup().
std::string GUILoadThread::myFile [protected] |
the path to load the simulation from
Definition at line 89 of file GUILoadThread.h.
Referenced by getFileName(), initOptions(), load(), and submitEndAndCleanup().
bool GUILoadThread::myLoadNet [protected] |
Information whether only the network shall be loaded.
Definition at line 100 of file GUILoadThread.h.
Referenced by initOptions(), and load().
OutputDevice * GUILoadThread::myMessageRetriever [protected] |
Definition at line 93 of file GUILoadThread.h.
Referenced by GUILoadThread(), run(), submitEndAndCleanup(), and ~GUILoadThread().
MFXInterThreadEventClient* GUILoadThread::myParent [protected] |
OutputDevice * GUILoadThread::myWarningRetriever [protected] |
Definition at line 93 of file GUILoadThread.h.
Referenced by GUILoadThread(), run(), submitEndAndCleanup(), and ~GUILoadThread().
1.5.6