[PATCH spice-common v2 2/3] agent-interface: add configuration functions

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

 



agent_interface_start: this function allows launching the agent
interface (ie, its listening socket) on a given port.

agent_interface_set_on_connect_cb: this function allows passing a
callback function that will be triggered when a client (a Local Agent)
connects to the Agent Interface socket.

agent_interface_set_forward_quality_cb: this function allows SPICE to
provide a function that will forward Quality messages received by the
Agent Interface towards SPICE server, for a centralized processing of
the messages.

Signed-off-by: Kevin Pouget <kpouget@xxxxxxxxxx>
---
v1->v2: unchanged
---
 common/agent_interface.c | 45 +++++++++++++++++++++++++++++++++++++++-
 common/agent_interface.h | 22 ++++++++++++++++++++
 common/recorder.h        | 27 ++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 1 deletion(-)

diff --git a/common/agent_interface.c b/common/agent_interface.c
index 768b6a9..eac071c 100644
--- a/common/agent_interface.c
+++ b/common/agent_interface.c
@@ -43,6 +43,12 @@ static FILE *communication_f = NULL;
 static recorder_info *recorders[NB_MAX_RECORDERS];
 static uint32_t nb_recorders = 0;

+static forward_quality_cb_t forward_quality_cb;
+static void *forward_quality_cb_data;
+
+static on_connect_cb_t on_connect_cb;
+static void *on_connect_cb_data;
+
 static uintptr_t recorder_tick(void);

 #ifndef RECORDER_HZ
@@ -98,6 +104,10 @@ static int agent_initialize_communication(int socket)
         g_info("Enable recorder '%s'", recorders[i]->name);
     }

+    if (on_connect_cb && on_connect_cb(on_connect_cb_data)) {
+        goto unlock;
+    }
+
     communication_f = socket_f;
     ret = 0;

@@ -124,6 +134,18 @@ static void agent_finalize_communication(int socket)
     g_mutex_unlock(&mutex_socket);
 }

+static void forward_quality(const char *quality)
+{
+    if (!forward_quality_cb) {
+        g_warning("Quality: No callback set, dropping the message (%s).", quality);
+        return;
+    }
+
+    g_info("Quality: Forwarding '%s'", quality);
+
+    forward_quality_cb(forward_quality_cb_data, quality);
+}
+
 static int agent_process_communication(int socket)
 {
     static char msg_in[128];
@@ -144,7 +166,8 @@ static int agent_process_communication(int socket)
     }

     if (msg_in[len] == '\0') {
-        // TODO: process quality indicator
+        // process quality indicator
+        forward_quality(msg_in);
         len = 0;
         return 0;
     }
@@ -396,6 +419,26 @@ static void recorder_trace_entry(recorder_info *info, recorder_entry *entry, ...
     g_mutex_unlock(&mutex_socket);
 }

+void agent_interface_start(unsigned int port)
+{
+    g_info("Launch on port %u", port);
+    recorder_initialization(port);
+}
+
+void agent_interface_set_forward_quality_cb(forward_quality_cb_t cb, void *data)
+{
+    g_debug("Received forward_quality callback");
+    forward_quality_cb = cb;
+    forward_quality_cb_data = data;
+}
+
+void agent_interface_set_on_connect_cb(on_connect_cb_t cb, void *data)
+{
+    g_debug("Received on_connect callback");
+    on_connect_cb = cb;
+    on_connect_cb_data = data;
+}
+
 void recorder_append(recorder_info *rec,
                      const char *where,
                      const char *format,
diff --git a/common/agent_interface.h b/common/agent_interface.h
index 042120e..ce5b8d9 100644
--- a/common/agent_interface.h
+++ b/common/agent_interface.h
@@ -540,3 +540,25 @@ static inline uintptr_t _recorder_double(double d)
         return u.i;
     }
 }
+
+// ============================================================================
+//   Agent-Interface specific definitions
+// ============================================================================
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// launch the Agent-Interface server socket
+extern void agent_interface_start(unsigned int port);
+
+//
+typedef void (*forward_quality_cb_t)(void *, const char *);
+extern void agent_interface_set_forward_quality_cb(forward_quality_cb_t cb, void *data);
+
+// set a callback function triggered when a new client connects to the socket
+typedef int (*on_connect_cb_t)(void *);
+extern void agent_interface_set_on_connect_cb(on_connect_cb_t cb, void *data);
+#ifdef __cplusplus
+}
+#endif // __cplusplus
diff --git a/common/recorder.h b/common/recorder.h
index 8448e02..7194ab5 100644
--- a/common/recorder.h
+++ b/common/recorder.h
@@ -73,3 +73,30 @@ recorder_dump_on_common_signals(unsigned add, unsigned remove)
 #else
 #include <common/recorder/recorder.h>
 #endif
+
+#if !defined(ENABLE_AGENT_INTERFACE)
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/* Stubs for Agent-Interface specific definitions */
+static inline void
+agent_interface_start(unsigned int port)
+{
+}
+
+typedef void (*forward_quality_cb_t)(void *, const char *);
+static inline void
+agent_interface_set_forward_quality_cb(forward_quality_cb_t cb, void *data)
+{
+}
+
+typedef int (*on_connect_cb_t)(void *);
+static inline void
+agent_interface_set_on_connect_cb(on_connect_cb_t cb, void *data)
+{
+}
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+#endif
--
2.21.0

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]