From 09c84d1de87e19cc7d8b8985ca79794b99c59cb8 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 19 Nov 2020 19:19:51 -0700 Subject: [PATCH] add new GSource-derived object that can be attached to a Glib::MainContext to execute code before other sources have their dispatch() method invoked --- libs/pbd/glib_event_source.cc | 19 ++++++++++++++++++ libs/pbd/pbd/glib_event_source.h | 33 ++++++++++++++++++++++++++++++++ libs/pbd/wscript | 1 + 3 files changed, 53 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/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/glib_event_source.h b/libs/pbd/pbd/glib_event_source.h new file mode 100644 index 0000000000..65752fbd53 --- /dev/null +++ b/libs/pbd/pbd/glib_event_source.h @@ -0,0 +1,33 @@ +#ifndef __libpbd_glib_event_source_h__ +#define __libpbd_glib_event_source_h__ + +#include + +#include + +class GlibEventLoopSource : public Glib::Source +{ + public: + GlibEventLoopSource () {}; + + bool prepare (int& timeout); + bool check(); + bool dispatch (sigc::slot_base*); +}; + + +class 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 77b41d6d10..d0393b6275 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',