[beast: 2/10] BSE: provide init_server_instance() and init_server_connection() to ease startup



commit eae5ac15419b0747625c4572ff7f4f1c3544a9a5
Author: Tim Janik <timj gnu org>
Date:   Tue Jan 19 23:15:43 2016 +0100

    BSE: provide init_server_instance() and init_server_connection() to ease startup
    
    Signed-off-by: Tim Janik <timj gnu org>

 bse/bse.hh        |    5 +++++
 bse/bsestartup.cc |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/bse/bse.hh b/bse/bse.hh
index dd1a28f..661080e 100644
--- a/bse/bse.hh
+++ b/bse/bse.hh
@@ -5,4 +5,9 @@
 #include <bse/bsestartup.hh>
 #include <bse/bseclientapi.hh>
 
+namespace Bse { // clientapi glue code, see bsestartup.cc
+ServerHandle                      init_server_instance   ();
+Rapicorn::Aida::ClientConnectionP init_server_connection ();
+} // Bse
+
 #endif /* __BSE_H__ */
diff --git a/bse/bsestartup.cc b/bse/bsestartup.cc
index d4c1ead..54c566e 100644
--- a/bse/bsestartup.cc
+++ b/bse/bsestartup.cc
@@ -2,6 +2,8 @@
 #include "bsestartup.hh"
 #include "bsemain.hh"
 #include <bse/bseclientapi.hh>
+#include <bse/bse.hh>           // init_server_connection
+#include "../configure.h"       // BST_VERSION
 
 namespace Bse {
 
@@ -122,6 +124,41 @@ AidaGlibSource::create (Rapicorn::Aida::BaseConnection *connection)
   return AidaGlibSourceImpl::create (connection);
 }
 
+static Rapicorn::Aida::ClientConnectionP *client_connection = NULL;
+
+/// Retrieve a handle for the Bse::Server instance managing the Bse thread.
+ServerHandle
+init_server_instance () // bse.hh
+{
+  ServerH server;
+  Rapicorn::Aida::ClientConnectionP connection = init_server_connection();
+  if (connection)
+    server = connection->remote_origin<ServerH>();
+  return server;
+}
+
+/// Retrieve the ClientConnection used for RPC communication with the Bse thread.
+Rapicorn::Aida::ClientConnectionP
+init_server_connection () // bse.hh
+{
+  if (!client_connection)
+    {
+      using namespace Rapicorn::Aida;
+      ClientConnectionP connection = ClientConnection::connect ("inproc://BSE-" BST_VERSION);
+      ServerH server;
+      if (connection)
+        server = connection->remote_origin<ServerH>();
+      if (!server) // shouldn't happen
+        sfi_error ("%s: failed to establish BSE connection: %s", __func__, g_strerror (errno));
+      constexpr SfiProxy BSE_SERVER = 1;
+      assert (server.proxy_id() == BSE_SERVER);
+      assert (server.from_proxy (BSE_SERVER) == server);
+      assert (client_connection == NULL);
+      client_connection = new Rapicorn::Aida::ClientConnectionP (connection);
+    }
+  return *client_connection;
+}
+
 } // Bse
 
 #include "bseclientapi.cc"      // build IDL client interface


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