[beast/devel: 11/17] BSE: add AidaGlibSource to attach an Aida::BaseConnection to a Glib main loop
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast/devel: 11/17] BSE: add AidaGlibSource to attach an Aida::BaseConnection to a Glib main loop
- Date: Wed, 1 May 2013 12:30:53 +0000 (UTC)
commit d7266a6b44c6bd721a01edc2fe689aa8d3f12150
Author: Tim Janik <timj gnu org>
Date: Thu Mar 28 16:05:17 2013 +0000
BSE: add AidaGlibSource to attach an Aida::BaseConnection to a Glib main loop
bse/bsecore.cc | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
bse/bsecore.hh | 6 ++++++
2 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/bse/bsecore.cc b/bse/bsecore.cc
index 8c5948e..eed2ce5 100644
--- a/bse/bsecore.cc
+++ b/bse/bsecore.cc
@@ -68,4 +68,57 @@ TaskRegistry::list ()
return task_registry_tasks_;
}
+class AidaGlibSourceImpl : public AidaGlibSource {
+ static AidaGlibSourceImpl* self_ (GSource *src) { return (AidaGlibSourceImpl*)
src; }
+ static int glib_prepare (GSource *src, int *timeoutp) { return self_ (src)->prepare
(timeoutp); }
+ static int glib_check (GSource *src) { return self_ (src)->check();
}
+ static int glib_dispatch (GSource *src, GSourceFunc, void*) { return self_
(src)->dispatch(); }
+ static void glib_finalize (GSource *src) { self_
(src)->~AidaGlibSourceImpl(); }
+ Rapicorn::Aida::BaseConnection *connection_;
+ GPollFD pfd_;
+ AidaGlibSourceImpl (Rapicorn::Aida::BaseConnection *connection) :
+ connection_ (connection), pfd_ { -1, 0, 0 }
+ {
+ pfd_.fd = connection_->notify_fd();
+ pfd_.events = G_IO_IN;
+ g_source_add_poll (this, &pfd_);
+ }
+ ~AidaGlibSourceImpl ()
+ {
+ g_source_remove_poll (this, &pfd_);
+ }
+ bool
+ prepare (int *timeoutp)
+ {
+ return pfd_.revents || connection_->pending();
+ }
+ bool
+ check ()
+ {
+ return pfd_.revents || connection_->pending();
+ }
+ bool
+ dispatch ()
+ {
+ pfd_.revents = 0;
+ connection_->dispatch();
+ return true;
+ }
+public:
+ static AidaGlibSourceImpl*
+ create (Rapicorn::Aida::BaseConnection *connection)
+ {
+ AIDA_ASSERT (connection != NULL);
+ static GSourceFuncs glib_source_funcs = { glib_prepare, glib_check, glib_dispatch, glib_finalize, NULL,
NULL };
+ GSource *src = g_source_new (&glib_source_funcs, sizeof (AidaGlibSourceImpl));
+ return new (src) AidaGlibSourceImpl (connection);
+ }
+};
+
+AidaGlibSource*
+AidaGlibSource::create (Rapicorn::Aida::BaseConnection *connection)
+{
+ return AidaGlibSourceImpl::create (connection);
+}
+
} // Bse
diff --git a/bse/bsecore.hh b/bse/bsecore.hh
index 7997f55..2d09a5c 100644
--- a/bse/bsecore.hh
+++ b/bse/bsecore.hh
@@ -3,6 +3,7 @@
#define __BSE_CORE_HH__
#include <bse/bse.hh>
+#include <bse/bseclientapi.hh>
/// The Bse namespace contains all functions of the synthesis engine.
namespace Bse {
@@ -24,6 +25,11 @@ public:
SfiGlueContext* init_glue_context (const gchar *client, const std::function<void()> &caller_wakeup);
void init_async (int *argc, char ***argv, const char *app_name, SfiInitValue values[]);
+/// A GSource implementation to attach an Aida::BaseConnection to a Glib main loop.
+class AidaGlibSource : public GSource {
+public:
+ static AidaGlibSource* create (Rapicorn::Aida::BaseConnection *connection);
+};
} // Bse
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]