Add additional PBD::string_to/to_string specializations for PBD::ID
[ardour.git] / libs / pbd / base_ui.cc
index 35ea6078ee71415ca6ba50f7fcf8a18f60c1c2ab..f22d83264ef08b1c5d4519bd06f16d3ea79c1e71 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000-2007 Paul Davis 
+    Copyright (C) 2000-2007 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
 
 #include <cstring>
 #include <stdint.h>
+#ifdef COMPILER_MSVC
+#include <io.h>      // Microsoft's nearest equivalent to <unistd.h>
+#else
 #include <unistd.h>
+#endif
 #include <fcntl.h>
 #include <cerrno>
 #include <cstring>
 #include "pbd/compose.h"
 #include "pbd/failed_constructor.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
+
+#include "pbd/debug.h"
 
 using namespace std;
 using namespace PBD;
 using namespace Glib;
-       
+
 uint64_t BaseUI::rt_bit = 1;
 BaseUI::RequestType BaseUI::CallSlot = BaseUI::new_request_type();
 BaseUI::RequestType BaseUI::Quit = BaseUI::new_request_type();
 
-BaseUI::BaseUI (const string& str)
-       : run_loop_thread (0)
-       , _name (str)
+BaseUI::BaseUI (const string& loop_name)
+       : EventLoop (loop_name)
+       , m_context(MainContext::get_default())
+       , run_loop_thread (0)
        , request_channel (true)
 {
        base_ui_instance = this;
-
-       request_channel.ios()->connect (sigc::mem_fun (*this, &BaseUI::request_handler));
+       request_channel.set_receive_handler (sigc::mem_fun (*this, &BaseUI::request_handler));
 
        /* derived class must set _ok */
 }
@@ -73,7 +79,7 @@ BaseUI::new_request_type ()
 void
 BaseUI::main_thread ()
 {
-       DEBUG_TRACE (DEBUG::EventLoop, string_compose ("%1: event loop running in thread %2\n", name(), pthread_name()));
+       DEBUG_TRACE (DEBUG::EventLoop, string_compose ("%1: event loop running in thread %2\n", event_loop_name(), pthread_name()));
        set_event_loop_for_thread (this);
        thread_init ();
        _main_loop->get_context()->signal_idle().connect (sigc::mem_fun (*this, &BaseUI::signal_running));
@@ -85,7 +91,7 @@ BaseUI::signal_running ()
 {
        Glib::Threads::Mutex::Lock lm (_run_lock);
        _running.signal ();
-       
+
        return false; // don't call it again
 }
 
@@ -95,11 +101,9 @@ BaseUI::run ()
        /* to be called by UI's that need/want their own distinct, self-created event loop thread.
        */
 
-       _main_loop = MainLoop::create (MainContext::create());
-       request_channel.ios()->attach (_main_loop->get_context());
-
-       /* glibmm hack - drop the refptr to the IOSource now before it can hurt */
-       request_channel.drop_ios ();
+       m_context = MainContext::create();
+       _main_loop = MainLoop::create (m_context);
+       attach_request_source ();
 
        Glib::Threads::Mutex::Lock lm (_run_lock);
        run_loop_thread = Glib::Threads::Thread::create (mem_fun (*this, &BaseUI::main_thread));
@@ -126,13 +130,14 @@ BaseUI::request_handler (Glib::IOCondition ioc)
 
        if (ioc & IO_IN) {
                request_channel.drain ();
-               
+
                /* there may been an error. we'd rather handle requests first,
                   and then get IO_HUP or IO_ERR on the next loop.
                */
 
                /* handle requests */
 
+               DEBUG_TRACE (DEBUG::EventLoop, string_compose ("%1: request handler\n", event_loop_name()));
                handle_ui_requests ();
        }
 
@@ -142,11 +147,16 @@ BaseUI::request_handler (Glib::IOCondition ioc)
 void
 BaseUI::signal_new_request ()
 {
+       DEBUG_TRACE (DEBUG::EventLoop, string_compose ("%1: signal_new_request\n", event_loop_name()));
        request_channel.wakeup ();
 }
 
+/**
+ * This method relies on the caller having already set m_context
+ */
 void
-BaseUI::attach_request_source (Glib::RefPtr<Glib::MainContext> context)
+BaseUI::attach_request_source ()
 {
-       request_channel.ios()->attach (context);
+       DEBUG_TRACE (DEBUG::EventLoop, string_compose ("%1: attach request source\n", event_loop_name()));
+       request_channel.attach (m_context);
 }