[beast: 7/8] BSE: hook up bse_glue to the main loop at initialization



commit 97c569937d9c759adfe98b0d98c231d6afb5b9a4
Author: Tim Janik <timj gnu org>
Date:   Tue Oct 3 02:11:09 2017 +0200

    BSE: hook up bse_glue to the main loop at initialization
    
    Signed-off-by: Tim Janik <timj gnu org>

 bse/bseglue.cc |   44 +++++++++++++++++++++++++++++++++++++++++++-
 bse/bseglue.hh |    3 ++-
 bse/bsemain.cc |    2 ++
 3 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/bse/bseglue.cc b/bse/bseglue.cc
index 8c5a0f3..0e160a1 100644
--- a/bse/bseglue.cc
+++ b/bse/bseglue.cc
@@ -98,8 +98,50 @@ static GQuark quark_original_enum = 0;
 static GQuark quark_property_notify = 0;
 static GQuark quark_notify = 0;
 
+// == bse_glue_setup_dispatcher ==
+struct GlueGSource : GSource {
+  SfiComPort     *port;
+  SfiGlueContext *context;
+  SfiGlueDecoder *decoder;
+};
+
+GSource*
+bse_glue_setup_dispatcher (SfiComPort *port)
+{
+  assert_return (port != NULL, NULL);
+  assert_return (bse_main_context != NULL, NULL);
+  auto prepare = [] (GSource *source, int *timeout_p) -> gboolean {
+    return sfi_glue_decoder_pending (static_cast<GlueGSource*> (source)->decoder);
+  };
+  auto check = [] (GSource *source) -> gboolean {
+    return sfi_glue_decoder_pending (static_cast<GlueGSource*> (source)->decoder);
+  };
+  auto dispatch = [] (GSource *source, GSourceFunc callback, void *user_data) -> gboolean {
+    GlueGSource *gsource = static_cast<GlueGSource*> (source);
+    if (gsource->port)
+      sfi_glue_decoder_dispatch (gsource->decoder);
+    return true;        /* keep source alive */
+  };
+  static GSourceFuncs gsource_funcs = { prepare, check, dispatch };
+  GlueGSource *gsource = (GlueGSource*) g_source_new (&gsource_funcs, sizeof (GlueGSource));
+  gsource->port = sfi_com_port_ref (port);
+  gsource->context = bse_glue_context_intern (port->ident);
+  gsource->decoder = sfi_glue_context_decoder (port, gsource->context);
+  SfiRing *ring;
+  GPollFD *pfd;
+  g_source_set_priority (gsource, BSE_PRIORITY_GLUE);
+  ring = sfi_glue_decoder_list_poll_fds (gsource->decoder);
+  pfd = (GPollFD*) sfi_ring_pop_head (&ring);
+  while (pfd)
+    {
+      g_source_add_poll (gsource, pfd);
+      pfd = (GPollFD*) sfi_ring_pop_head (&ring);
+    }
+  g_source_attach (gsource, bse_main_context);
+  return gsource;
+}
 
-/* --- functions --- */
+// == bse_glue_context =
 SfiGlueContext*
 bse_glue_context_intern (const char *user)
 {
diff --git a/bse/bseglue.hh b/bse/bseglue.hh
index 64dbf2e..18ee9f1 100644
--- a/bse/bseglue.hh
+++ b/bse/bseglue.hh
@@ -4,7 +4,8 @@
 
 #include <bse/bsetype.hh>
 
-SfiGlueContext*        bse_glue_context_intern  (const gchar   *user);
+SfiGlueContext*        bse_glue_context_intern   (const gchar  *user);
+GSource*        bse_glue_setup_dispatcher (SfiComPort   *port);
 
 /* Construct a new #SfiRec from a boxed value. */
 typedef SfiRec*        (*BseGlueBoxedToRec)     (gpointer          boxed);
diff --git a/bse/bsemain.cc b/bse/bsemain.cc
index 1081c53..8df0e49 100644
--- a/bse/bsemain.cc
+++ b/bse/bsemain.cc
@@ -12,6 +12,7 @@
 #include "bsemididevice.hh"
 #include "bseengine.hh"
 #include "bseblockutils.hh" /* bse_block_impl_name() */
+#include "bseglue.hh"
 #include <string.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -263,6 +264,7 @@ async_create_context (gpointer data)
   sfi_com_port_create_linked ("Client", adata->caller_wakeup, &port1,
                              "Server", bse_main_wakeup, &port2);
   SfiGlueContext *context = sfi_glue_encoder_context (port1);
+  bse_glue_setup_dispatcher (port2);
   adata->result_queue.push (context);
   return false; // run-once
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]