#include <MainLoop.h>
Public Member Functions | |
MainLoop () | |
Constructor. | |
~MainLoop () | |
Destructor. | |
int | Run () |
This executes the main loop until Quit() is called. | |
void | Quit () |
Leaves the main loop. | |
void | SetExitCode (int code) |
Sets the exit code. | |
int | GetExitCode () const |
Returns the exit code. | |
virtual void | OnInitialize ()=0 |
(abstract) This method is called right before entering the main loop. | |
virtual void | OnTerminate ()=0 |
(abstract) This method is called right after leaving the main loop. | |
virtual void | OnBeforeProcessing () |
(abstract) This method is called before the events are processed (after waiting for events). | |
virtual void | OnAfterProcessing () |
(abstract) This method is called after the events are processed (before waiting for events). | |
IOInterfaceList * | GetIOInterfaceList () const |
Returns the IOInterfaceList. | |
EventInterfaceList * | GetEventInterfaceList () const |
Returns the EventInterfaceList. | |
void | Report (const std::string &name, std::ostream &out, int ccindent=0) const |
Writes a report of this object to the given stream. This is mainly useful for debugging. | |
Protected Attributes | |
bool | mQuit |
Set to true to leave the main loop. | |
int | mExitCode |
The exit code. | |
IOInterfaceList * | mIOInterfaceList |
The IOInterface list. | |
EventInterfaceList * | mEventInterfaceList |
The EventInterface list. |
This abstract class implements a main loop for a typical application. It listens to all handles of the attached IOInterfaceList and waits for all timeouts of the attached EventInterfaceList.
To use this class, derive your main application class from it and overwrite the methods OnInitialize() and OnTerminate(). Your application should first add all EventInterface to the EventInterfaceList and all IOInterfaces to the IOInterfaceList. It may then call Run() to execute the main loop. Immediately before entering the main loop, OnInitialize() is called. Then, the program waits until
Any such event may force the main loop to quit by calling Quit(). The main loop then calls OnTerminate() and returns the exit code (set by SetExitCode).