X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fpbd%2Fpbd%2Fbase_ui.h;h=ea1afbbb5a3428e84fd4cc9b4fe0a02db45d2597;hb=59076a7e4c66db12bbbfbf01f012ca2f6ba4bf56;hp=e8de355b03224625d8269a1bce275325109bcd20;hpb=b8b55ef0036bbef9a2961f03f44387ea8c89456a;p=ardour.git diff --git a/libs/pbd/pbd/base_ui.h b/libs/pbd/pbd/base_ui.h index e8de355b03..ea1afbbb5a 100644 --- a/libs/pbd/pbd/base_ui.h +++ b/libs/pbd/pbd/base_ui.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2007 Paul Davis + Copyright (C) 2000-2009 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,12 +26,24 @@ #include #include -#include +#include #include +#include "pbd/libpbd_visibility.h" #include "pbd/crossthread.h" +#include "pbd/event_loop.h" -class BaseUI : virtual public sigc::trackable { +/** 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 LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop +{ public: BaseUI (const std::string& name); virtual ~BaseUI(); @@ -39,46 +51,73 @@ class BaseUI : virtual public sigc::trackable { 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; } bool ok() const { return _ok; } - - enum RequestType { - range_guarantee = ~0 - }; - - struct BaseRequestObject { - RequestType type; - sigc::slot the_slot; - }; - + static RequestType new_request_type(); static RequestType CallSlot; static RequestType Quit; + /** start up a thread to run the main loop + */ void run (); - void quit (); - virtual void call_slot (sigc::slot theSlot) = 0; + /** stop the thread running the main loop (and block + * until it exits) + */ + void quit (); protected: - CrossThreadChannel request_channel; bool _ok; Glib::RefPtr _main_loop; - Glib::Thread* run_loop_thread; + Glib::RefPtr m_context; + 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 () {}; + +#ifdef PLATFORM_WINDOWS + static gboolean _request_handler (gpointer); + bool request_handler (); +#else + /** Called when there input ready on the request_channel + */ bool request_handler (Glib::IOCondition); +#endif + + void signal_new_request (); + void attach_request_source (); + /** 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: std::string _name; BaseUI* base_ui_instance; + +#ifndef PLATFORM_WINDOWS + CrossThreadChannel request_channel; +#endif static uint64_t rt_bit;