GUIUpdater Class Reference

Detailed Description
The class is responsible for maintaining a queue of actions to update GUI widgets.These actions are posted by triggers when scene objects containing data that is displayed in a GUI widget is modified. When this queue contains elements, and enough time has passed since the last GUI update, the server actuator thread will wake the main thread which will then proceed to process the actions and update the GUI elements.
The 'queue' used by the GUI updater is not actually a queue, but a map. This is because the order in wich widgets are updated is irrelevant, since all updates are absolute and do not depend on other widgets. Further, storing the updates in a map ensures that only the most recent update to a widget is actually carried out - updates that would have been overridden in the same update are skipped.
Finally, having a map container enables us to easily look up updates for widgets that have been deleted since the update was posted and remove them.
It uses scoped locks and mutexes to ensure thread consistency between the server actuator and the main thread.
Public Member Functions | |
| ~GUIUpdater () | |
| Deletes all the memory allocated for the actions currently in the queue. | |
| void | post_action (Fl_Widget *widget, UpdateAction *action) |
| Posts an update action on the queue. | |
| void | update_gui () |
| Process all pending GUI updates. | |
| bool | has_actions () |
Returns true if there are pending updates, false if not. | |
| void | remove_updates (Fl_Widget *widget) |
| Removes any updates for the specified widget. | |
Private Types | |
|
typedef std::multimap < Fl_Widget *, UpdateAction * > | UpdateMap |
Private Attributes | |
| UpdateMap | m_action_queue |
| Container implementing the 'queue'. | |
| boost::recursive_mutex | m_queue_mutex |
| Mutex ensuring the thread safety of the queue. | |
Member Function Documentation
| void post_action | ( | Fl_Widget * | widget, | |
| UpdateAction * | action | |||
| ) |
Posts an update action on the queue.
This method is intended to be called exclusively from the server actuator thread. It acquires a lock on the queue mutex, making sure the queue is not simultaneously polled by the main thread.
The first argument is the widget that the action affects. If this widget is deleted, the remove_widget() method should be called with a pointer to the widget passed to it to make sure any updates are deleted along with it.
| void update_gui | ( | ) |
Process all pending GUI updates.
This method is intended to be called from the main thread. It acquires a lock on the queue mutex and then copies the queue before processing it. The mutex is unlocked before processing starts, so that the server actuator thread can simultaneously post actions to the queue while the copy is being processed.
| bool has_actions | ( | ) |
Returns true if there are pending updates, false if not.
This method doesn't actually lock the mutex, as that would possibly be unnecessarily time-consuming and this is not a critical operation. The thread will be locked when the actual processing takes place instead.
| void remove_updates | ( | Fl_Widget * | widget | ) |
Removes any updates for the specified widget.
This method is called when a widget gets deleted. Makes sure the updater doesn't try to dereference a widget pointer that has been deallocated.
The documentation for this class was generated from the following files:
- src/gui/GUIUpdater.hh
- src/gui/GUIUpdater.cc