X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fpbd%2Fbase_ui.h;h=186a3c55a659e346c7e723d5a2ba4f457adf5623;hb=99bf5d9eeda1e5e1811d660c0c22bb5a2d4984c0;hp=ccd4878cd9d103b4ab64d3fe90f0093bcb179c76;hpb=14b0ca31bcb62e5b7e9e77634ef9cd2e8cf65800;p=ardour.git diff --git a/libs/pbd/pbd/base_ui.h b/libs/pbd/pbd/base_ui.h index ccd4878cd9..186a3c55a6 100644 --- a/libs/pbd/pbd/base_ui.h +++ b/libs/pbd/pbd/base_ui.h @@ -26,13 +26,22 @@ #include #include -#include +#include #include #include "pbd/crossthread.h" #include "pbd/event_loop.h" -class BaseUI : virtual public sigc::trackable, public PBD::EventLoop +/** A BaseUI is an abstraction designed to be used with any "user + * interface" (not necessarily graphical) that needs to wait on + * events/requests and dispatch/process them as they arrive. + * + * This implementation starts up a thread that runs a Glib main loop + * to wait on events/requests etc. + */ + + +class BaseUI : public sigc::trackable, public PBD::EventLoop { public: BaseUI (const std::string& name); @@ -41,8 +50,8 @@ class BaseUI : virtual public sigc::trackable, public PBD::EventLoop BaseUI* base_instance() { return base_ui_instance; } Glib::RefPtr main_loop() const { return _main_loop; } - Glib::Thread* event_loop_thread() const { return run_loop_thread; } - bool caller_is_self () const { return Glib::Thread::self() == run_loop_thread; } + Glib::Threads::Thread* event_loop_thread() const { return run_loop_thread; } + bool caller_is_self () const { return Glib::Threads::Thread::self() == run_loop_thread; } std::string name() const { return _name; } @@ -52,7 +61,13 @@ class BaseUI : virtual public sigc::trackable, public PBD::EventLoop static RequestType CallSlot; static RequestType Quit; + /** start up a thread to run the main loop + */ void run (); + + /** stop the thread running the main loop (and block + * until it exits) + */ void quit (); protected: @@ -60,11 +75,31 @@ class BaseUI : virtual public sigc::trackable, public PBD::EventLoop bool _ok; Glib::RefPtr _main_loop; - Glib::Thread* run_loop_thread; + Glib::Threads::Thread* run_loop_thread; + Glib::Threads::Mutex _run_lock; + Glib::Threads::Cond _running; + + /* this signals _running from within the event loop, + from an idle callback + */ + + bool signal_running (); + + /** Derived UI objects can implement thread_init() + * which will be called by the event loop thread + * immediately before it enters the event loop. + */ virtual void thread_init () {}; + + /** Called when there input ready on the request_channel + */ bool request_handler (Glib::IOCondition); + /** Derived UI objects must implement this method, + * which will be called whenever there are requests + * to be dealt with. + */ virtual void handle_ui_requests () = 0; private: