luna-sysmgr-common
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TaskBase Class Referenceabstract

#include <TaskBase.h>

Inheritance diagram for TaskBase:
[legend]
Collaboration diagram for TaskBase:
[legend]

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
 
SingletonTimermasterTimer () 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
 
SingletonTimerm_masterTimer
 

Detailed Description

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.

Constructor & Destructor Documentation

TaskBase::TaskBase ( )

Constructs a new TaskBase

Since this class is designed to be built upon, it mainly just sets the internal members to null.

TaskBase::~TaskBase ( )
virtual

Cleans up the current TaskBase instance

Since this class is designed to be built upon, this is here to define it as virtual so TaskBase pointers can correctly call their derived class's destructor.

Member Function Documentation

virtual void TaskBase::handleEvent ( sptr< Event event)
protectedpure virtual

Event handler

Called by the event loop to handle each event, in order, from the event queue

See Also
sptr
Parameters
eventSmart pointer to an Event with info about the event to handle

Implemented in HostBase.

GMainLoop* TaskBase::mainLoop ( ) const
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.

Returns
Pointer to GLib main event loop
SingletonTimer* TaskBase::masterTimer ( ) const
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.

Returns
Pointer to the master timer for this task
void TaskBase::postEvent ( sptr< Event event,
bool  highPriority = false 
)

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.

See Also
sptr
Parameters
eventSmart pointer to an Event object to post
highPriorityWhether or not this event is urgent and should be posted to the start of the queue
virtual void TaskBase::quit ( )
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().

Implemented in HostBase, and SyncTask.

virtual void 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.

Implemented in HostBase, and SyncTask.

Member Data Documentation

AsyncCaller<TaskBase>* TaskBase::m_asyncCaller
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.

Todo:
Check this description for accuracy once AsyncCaller is documented.
std::list<sptr<Event> > TaskBase::m_eventsList
protected

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.

Mutex TaskBase::m_eventsMutex
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".

GMainContext* TaskBase::m_mainCtxt
protected

Main GLib context

Todo:
Figure out what this points to.
GMainLoop* TaskBase::m_mainLoop
protected

Pointer to main GLib event loop structure

Todo:
Commonly used throughout the code - needs to be filled in as to what it's for.
SingletonTimer* TaskBase::m_masterTimer
protected

Master timer for this task

Todo:
Document this further as derived classes are documented and we figure out what this is used for.
Mutex TaskBase::m_mutex
protected

Mutex for derived classes to use

Todo:
Fill this in after documenting some derived classes.

The documentation for this class was generated from the following files: