[Spice-devel] [spice-xpi 09/12] Add SpiceController::SetupControllerPipe

Christophe Fergeau cfergeau at redhat.com
Tue Mar 12 04:23:04 PDT 2013


Communication with the client is done differently on Windows and
Linux (named pipe VS unix socket), so move this platform-specific
setup to a distinct method.
---
 SpiceXPI/src/plugin/controller-unix.cpp | 15 +++++++++++----
 SpiceXPI/src/plugin/controller.h        |  2 ++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/SpiceXPI/src/plugin/controller-unix.cpp b/SpiceXPI/src/plugin/controller-unix.cpp
index 7b4bc1c..504a8ef 100644
--- a/SpiceXPI/src/plugin/controller-unix.cpp
+++ b/SpiceXPI/src/plugin/controller-unix.cpp
@@ -139,6 +139,16 @@ int SpiceController::Connect(const int nRetries)
     return rc;
 }
 
+void SpiceController::SetupControllerPipe(GStrv &env)
+{
+    std::string socket_file(this->m_tmp_dir);
+    socket_file += "/spice-xpi";
+
+    this->SetFilename(socket_file);
+
+    env = g_environ_setenv(env, "SPICE_XPI_SOCKET", socket_file.c_str(), TRUE);
+}
+
 void SpiceController::Disconnect()
 {
     // close the socket
@@ -206,12 +216,9 @@ gpointer SpiceController::ClientThread(gpointer data)
     gboolean spawned;
     GError *error = NULL;
 
-    std::string socket_file(fake_this->m_tmp_dir);
-    socket_file += "/spice-xpi";
 
-    fake_this->SetFilename(socket_file);
+    fake_this->SetupControllerPipe(env);
 
-    env = g_environ_setenv(env, "SPICE_XPI_SOCKET", socket_file.c_str(), TRUE);
     if (!fake_this->m_proxy.empty())
         env = g_environ_setenv(env, "SPICE_PROXY", fake_this->m_proxy.c_str(), TRUE);
 
diff --git a/SpiceXPI/src/plugin/controller.h b/SpiceXPI/src/plugin/controller.h
index 268994b..f47a921 100644
--- a/SpiceXPI/src/plugin/controller.h
+++ b/SpiceXPI/src/plugin/controller.h
@@ -59,6 +59,7 @@
 */
 
 #include <glib.h>
+#include <glib-object.h> /* for GStrv */
 #include <string>
 extern "C" {
 #  include <stdint.h>
@@ -88,6 +89,7 @@ public:
 private:
     int Connect();
     void WaitForPid(GPid pid);
+    void SetupControllerPipe(GStrv &env);
     static void ChildExited(GPid pid, gint status, gpointer user_data);
     static gpointer ClientThread(gpointer data);
 
-- 
1.8.1.4



More information about the Spice-devel mailing list