From 968533cc23e99955426c78ace9364bf7e29a3d77 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 16 May 2022 15:23:42 -0600 Subject: [PATCH] (re)add mechanism for a callback in any glib event loop executed before the loop "executes" This is based on code from earlier commits that were later reversed, but we need some mechanism to ensure that threads have a thread local tempo map ptr set. The big difference is that this time we do not implement this for all instances of an AbstractUI - implementation is left to each thread/event loop --- libs/pbd/base_ui.cc | 1 + libs/pbd/glib_event_source.cc | 19 ++++++++++++++++++ libs/pbd/pbd/base_ui.h | 2 ++ libs/pbd/pbd/glib_event_source.h | 34 ++++++++++++++++++++++++++++++++ libs/pbd/wscript | 1 + 5 files changed, 57 insertions(+) create mode 100644 libs/pbd/glib_event_source.cc create mode 100644 libs/pbd/pbd/glib_event_source.h diff --git a/libs/pbd/base_ui.cc b/libs/pbd/base_ui.cc index 83df2b76b5..d41d6aac44 100644 --- a/libs/pbd/base_ui.cc +++ b/libs/pbd/base_ui.cc @@ -175,5 +175,6 @@ BaseUI::attach_request_source () { DEBUG_TRACE (DEBUG::EventLoop, string_compose ("%1: attach request source\n", event_loop_name())); request_channel.attach (m_context); + maybe_install_precall_handler (m_context); } diff --git a/libs/pbd/glib_event_source.cc b/libs/pbd/glib_event_source.cc new file mode 100644 index 0000000000..59ae3d7c86 --- /dev/null +++ b/libs/pbd/glib_event_source.cc @@ -0,0 +1,19 @@ +#include "pbd/glib_event_source.h" + +bool +GlibEventLoopSource::prepare (int& timeout) +{ + return false; +} + +bool +GlibEventLoopSource::check () +{ + return false; +} + +bool +GlibEventLoopSource::dispatch (sigc::slot_base*) +{ + return false; +} diff --git a/libs/pbd/pbd/base_ui.h b/libs/pbd/pbd/base_ui.h index fff6f5da84..fe412f2537 100644 --- a/libs/pbd/pbd/base_ui.h +++ b/libs/pbd/pbd/base_ui.h @@ -105,6 +105,8 @@ class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop void signal_new_request (); void attach_request_source (); + virtual void maybe_install_precall_handler (Glib::RefPtr) {} + /** Derived UI objects must implement this method, * which will be called whenever there are requests * to be dealt with. diff --git a/libs/pbd/pbd/glib_event_source.h b/libs/pbd/pbd/glib_event_source.h new file mode 100644 index 0000000000..22400f0c53 --- /dev/null +++ b/libs/pbd/pbd/glib_event_source.h @@ -0,0 +1,34 @@ +#ifndef __libpbd_glib_event_source_h__ +#define __libpbd_glib_event_source_h__ + +#include + +#include +#include "pbd/libpbd_visibility.h" + +class LIBPBD_API GlibEventLoopSource : public Glib::Source +{ + public: + GlibEventLoopSource () {}; + + bool prepare (int& timeout); + bool check(); + bool dispatch (sigc::slot_base*); +}; + + +class LIBPBD_API GlibEventLoopCallback : public GlibEventLoopSource +{ + public: + GlibEventLoopCallback (boost::function callback) : _callback (callback) {} + + bool check() { + _callback(); + return false; + } + + private: + boost::function _callback; +}; + +#endif /* __libpbd_glib_event_source_h__ */ diff --git a/libs/pbd/wscript b/libs/pbd/wscript index 2dda798a45..82960539a2 100644 --- a/libs/pbd/wscript +++ b/libs/pbd/wscript @@ -51,6 +51,7 @@ libpbd_sources = [ 'file_archive.cc', 'file_utils.cc', 'fpu.cc', + 'glib_event_source.cc', 'id.cc', 'locale_guard.cc', 'localtime_r.cc',