|
luna-sysmgr-common
|
#include <TaskBase.h>
Public Member Functions | |
| TaskBase () | |
| virtual | ~TaskBase () |
| virtual void | run ()=0 |
| virtual void | quit ()=0 |
| void | postEvent (sptr< Event > event, bool highPriority=false) |
| GMainLoop * | mainLoop () const |
| SingletonTimer * | masterTimer () const |
Public Member Functions inherited from RefCounted | |
| RefCounted () | |
| virtual | ~RefCounted () |
| void | ref () |
| void | deref () |
Protected Member Functions | |
| virtual void | handleEvent (sptr< Event > event)=0 |
Protected Attributes | |
| GMainContext * | m_mainCtxt |
| GMainLoop * | m_mainLoop |
| Mutex | m_mutex |
| Mutex | m_eventsMutex |
| std::list< sptr< Event > > | m_eventsList |
| AsyncCaller< TaskBase > * | m_asyncCaller |
| SingletonTimer * | m_masterTimer |
Abstract base class for runnable tasks
Manages an event queue and feeds each event (in order) to an event handler method to be defined by derived classes.
This class cannot be instantiated by itself but must be derived from.
| TaskBase::TaskBase | ( | ) |
Constructs a new TaskBase
Since this class is designed to be built upon, it mainly just sets the internal members to null.
|
virtual |
|
inline |
Gets a pointer to this task's GLib main event loop
Main GLib functions require a pointer to the main GLib event loop, which (from what I can tell) is specific to each process or fork. This allows access to it, thereby allowing central storage of the main event loop pointer without having to use a global variable.
|
inline |
Gets a pointer to the master timer for this task
The master timer is a class which simplified access to the system clock. It is specific to a GLib main event loop, so it is returned here so construction of it can be abstracted away from the caller, removing a few explicit GLib dependencies.
Note: This pointer is set to 0 by default by TaskBase::TaskBase() and cannot be used until a derived class sets it up.
Posts an event to this task's event queue
Normally events in the queue are fed to the derived class's event handler in order from first to last. This method is how you add add events to the queue. If highPriority is set to true, the new event is added to the beginning of the queue so it is processed as soon as possible. Normally you would post events with highPriority set to false so they're posted to the end of the queue and processed in the order received.
| event | Smart pointer to an Event object to post |
| highPriority | Whether or not this event is urgent and should be posted to the start of the queue |
|
pure virtual |
Terminates this task
At this point, it doesn't appear this is used by any deriving classes. Ideally this would do cleanup from TaskBase::run().
|
pure virtual |
Runs this task
The bulk of derived classes' funcionality should reside within this method. This method should not return until the task is complete. For example, WebAppManager runs a QCoreApplication within this method, and when it terminates, this function returns.
|
protected |
Asynchronous caller to handle all events in the event queue
Allows the internal event handler loop callback method to be called without stalling out the caller.
Event queue
This standard library list object stores a list of smart pointers to events that are in the event processing queue (see sptr for more information on smart pointers). Events are stored in this list in order they should be processed - first list item is the first event that the event handling loop should feed to the derived class's event handler method.
|
protected |
Mutex for the event queue
Prevents other threads using the same event queue from modifying the queue while it's being actively processed. When one thread is about ready to process the queue and handle events, it will lock this mutex until it's done modifying the queue at which point it will unlock it so other threads know it's safe for them to modify it.
Note: Mutex stands for "mutually exclusive".
|
protected |
Main GLib context
|
protected |
Pointer to main GLib event loop structure
|
protected |
Master timer for this task
|
protected |