[jsonrpc-glib] client: allow detailed connections to handle-call



commit 4318f82685a710cf751d427aa4429629e6770d7b
Author: Christian Hergert <chergert redhat com>
Date:   Sun Dec 24 14:17:10 2017 -0800

    client: allow detailed connections to handle-call
    
    This allows connecting to handle-call::method-name to handle a
    specific method call.

 src/jsonrpc-client.c | 10 ++++++++--
 tests/test-client.c  |  3 ++-
 2 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/src/jsonrpc-client.c b/src/jsonrpc-client.c
index d84657b..636d429 100644
--- a/src/jsonrpc-client.c
+++ b/src/jsonrpc-client.c
@@ -428,12 +428,16 @@ jsonrpc_client_class_init (JsonrpcClientClass *klass)
    * in a timely manner using jsonrpc_client_reply() or
    * jsonrpc_client_reply_async().
    *
+   * Additionally, since 3.28 you may connect to the "detail" of this signal
+   * to handle a specific method call. Use the method name as the detail of
+   * the signal.
+   *
    * Since: 3.26
    */
   signals [HANDLE_CALL] =
     g_signal_new ("handle-call",
                   G_TYPE_FROM_CLASS (klass),
-                  G_SIGNAL_RUN_LAST,
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
                   G_STRUCT_OFFSET (JsonrpcClientClass, handle_call),
                   g_signal_accumulator_true_handled, NULL, NULL,
                   G_TYPE_BOOLEAN,
@@ -675,6 +679,7 @@ jsonrpc_client_call_read_cb (GObject      *object,
       g_autoptr(GVariant) params = NULL;
       const gchar *method_name = NULL;
       gboolean ret = FALSE;
+      GQuark detail;
 
       if (!g_variant_dict_lookup (&dict, "method", "&s", &method_name) ||
           NULL == (id = g_variant_dict_lookup_value (&dict, "id", NULL)))
@@ -691,7 +696,8 @@ jsonrpc_client_call_read_cb (GObject      *object,
       g_assert (method_name != NULL);
       g_assert (id != NULL);
 
-      g_signal_emit (self, signals [HANDLE_CALL], 0, method_name, id, params, &ret);
+      detail = g_quark_try_string (method_name);
+      g_signal_emit (self, signals [HANDLE_CALL], detail, method_name, id, params, &ret);
 
       if (ret == FALSE)
         {
diff --git a/tests/test-client.c b/tests/test-client.c
index 7673a1f..37e11f7 100644
--- a/tests/test-client.c
+++ b/tests/test-client.c
@@ -120,7 +120,8 @@ main (gint   argc,
   g_variant_dict_insert (&params, "rootPath", "s", path);
   g_variant_dict_insert_value (&params, "capabilities", g_variant_new ("a{sv}", NULL, NULL, NULL));
 
-  jsonrpc_client_call_async (gClient, "initialize", g_variant_dict_end (&params), NULL, call_cb, NULL);
+  /* Use a method name with / to ensure we test more complex paths */
+  jsonrpc_client_call_async (gClient, "initialize/foo", g_variant_dict_end (&params), NULL, call_cb, NULL);
 
   g_timeout_add_seconds (5, timeout_cb, NULL);
 


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