diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-10-25 22:37:33 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-10-25 22:37:33 +0100 |
| commit | 1df722e04cce91d7f410e7355a1c0bcf0db4d1c9 (patch) | |
| tree | 4376107d981e02ced7f851843931adbaf6887d95 /src/lib | |
| parent | 42d72484cbf06a4bd8e2e9fe2a59fcae25628a3f (diff) | |
Add some comments.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/ui_signaller.cc | 1 | ||||
| -rw-r--r-- | src/lib/ui_signaller.h | 17 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/lib/ui_signaller.cc b/src/lib/ui_signaller.cc index 4f39a6187..4cb34da51 100644 --- a/src/lib/ui_signaller.cc +++ b/src/lib/ui_signaller.cc @@ -19,5 +19,6 @@ #include "ui_signaller.h" +/** Global UISignaller instance */ UISignaller* ui_signaller = 0; diff --git a/src/lib/ui_signaller.h b/src/lib/ui_signaller.h index 9de1b736d..221bcbe95 100644 --- a/src/lib/ui_signaller.h +++ b/src/lib/ui_signaller.h @@ -24,6 +24,9 @@ #include <boost/asio.hpp> #include <boost/thread.hpp> +/** A class to allow signals to be emitted from non-UI threads and handled + * by a UI thread. + */ class UISignaller { public: @@ -33,26 +36,38 @@ public: { _ui_thread = boost::this_thread::get_id (); } - + + /** Emit a signal from any thread whose handlers will be called in the UI + * thread. Use something like: + * + * ui_signaller->emit (boost::bind (boost::ref (SomeSignal), parameter)); + */ template <typename T> void emit (T f) { if (boost::this_thread::get_id() == _ui_thread) { + /* already in the UI thread */ f (); } else { + /* non-UI thread; post to the service and wake up the UI */ _service.post (f); wake_ui (); } } + /** Call this in the UI when it is idle */ void ui_idle () { _service.poll (); } + /** This should wake the UI and make it call ui_idle() */ virtual void wake_ui () = 0; private: + /** A io_service which is used as the conduit for messages */ boost::asio::io_service _service; + /** Object required to keep io_service from stopping when it has nothing to do */ boost::asio::io_service::work _work; + /** The UI thread's ID */ boost::thread::id _ui_thread; }; |
