Merge branch 'master' into cairocanvas
[ardour.git] / libs / pbd / pbd / base_ui.h
index 414c9970d979e5c3cc038988f86d3fe74ed00b0f..ea1afbbb5a3428e84fd4cc9b4fe0a02db45d2597 100644 (file)
 #include <sigc++/slot.h>
 #include <sigc++/trackable.h>
 
-#include <glibmm/thread.h>
+#include <glibmm/threads.h>
 #include <glibmm/main.h>
 
+#include "pbd/libpbd_visibility.h"
 #include "pbd/crossthread.h"
 #include "pbd/event_loop.h"
 
@@ -41,7 +42,7 @@
  */
 
 
-class BaseUI : virtual public sigc::trackable, public PBD::EventLoop
+class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop
 {
   public:
        BaseUI (const std::string& name);
@@ -50,8 +51,8 @@ class BaseUI : virtual public sigc::trackable, public PBD::EventLoop
        BaseUI* base_instance() { return base_ui_instance; }
 
        Glib::RefPtr<Glib::MainLoop> 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; }
 
@@ -71,11 +72,19 @@ class BaseUI : virtual public sigc::trackable, public PBD::EventLoop
        void quit ();
 
   protected:
-       CrossThreadChannel request_channel;
        bool _ok; 
 
        Glib::RefPtr<Glib::MainLoop> _main_loop;
-       Glib::Thread*                 run_loop_thread;
+       Glib::RefPtr<Glib::MainContext> 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
@@ -84,9 +93,17 @@ class BaseUI : virtual public sigc::trackable, public PBD::EventLoop
 
        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
@@ -97,6 +114,10 @@ class BaseUI : virtual public sigc::trackable, public PBD::EventLoop
   private:
        std::string _name; 
        BaseUI* base_ui_instance;
+
+#ifndef PLATFORM_WINDOWS
+       CrossThreadChannel request_channel;
+#endif
        
        static uint64_t rt_bit;