]> sourceware.org Git - lvm2.git/commitdiff
Also parse the config_tree on the client end (daemon-client.c).
authorPetr Rockai <prockai@redhat.com>
Mon, 27 Jun 2011 13:58:11 +0000 (13:58 +0000)
committerPetr Rockai <prockai@redhat.com>
Mon, 27 Jun 2011 13:58:11 +0000 (13:58 +0000)
daemons/common/daemon-client.c
daemons/common/daemon-client.h
daemons/common/daemon-server.c
daemons/common/daemon-server.h
daemons/lvmetad/lvmetad-core.c
daemons/lvmetad/testclient.c

index 50d22ae75291e5ef305f8d37c04ab2d2fa582e69..49d5eefd38a3f2e1cb90614bbb871183f88c168c 100644 (file)
@@ -44,13 +44,18 @@ daemon_reply daemon_send(daemon_handle h, daemon_request rq)
        write_buffer(h.socket_fd, rq.buffer, strlen(rq.buffer));
 
        if (read_buffer(h.socket_fd, &reply.buffer)) {
-               /* TODO: parse reply.buffer into reply.cft */
+               reply.cft = create_config_tree_from_string(reply.buffer);
        } else
                reply.error = 1;
 
        return reply;
 }
 
+void daemon_reply_destroy(daemon_reply r) {
+       if (r.cft)
+               destroy_config_tree(r.cft);
+}
+
 daemon_reply daemon_send_simple(daemon_handle h, char *id, ...)
 {
        va_list ap;
index d266ba75dfde1061ec734e18404cde1661c832bf..61dca5b5d4629234edc4007092c45c0e478066d8 100644 (file)
@@ -41,13 +41,13 @@ typedef struct {
         *        knobs = [ "twiddle", "tweak" ]
         *    }
         */
-       struct config_node *cft;
+       struct config_tree *cft;
 } daemon_request;
 
 typedef struct {
        int error; /* 0 for success */
        char *buffer; /* textual reply */
-       struct config_node *cft; /* parsed reply, if available */
+       struct config_tree *cft; /* parsed reply, if available */
 } daemon_reply;
 
 /*
@@ -79,6 +79,8 @@ daemon_reply daemon_send(daemon_handle h, daemon_request r);
  */
 daemon_reply daemon_send_simple(daemon_handle h, char *id, ...);
 
+void daemon_reply_destroy(daemon_reply r);
+
 /* Shut down the communication to the daemon. Compulsory. */
 void daemon_close(daemon_handle h);
 
index bdfe8735c43536e04458d77605fb77b87f702423..73a5c67804df2fad3a86c6df1cecc5366389df39 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <syslog.h>
 #include "daemon-server.h"
+#include "daemon-shared.h"
 #include "libdevmapper.h"
 
 #if 0
@@ -200,6 +201,18 @@ static void _daemonise(void)
        setsid();
 }
 
+response daemon_reply_simple(char *id, ...)
+{
+       va_list ap;
+       va_start(ap, id);
+       response res = { .buffer = format_buffer(id, ap), .cft = NULL };
+
+       if (!res.buffer)
+               res.error = ENOMEM;
+
+       return res;
+}
+
 struct thread_baton {
        daemon_state s;
        client_handle client;
index 2ac1554cb308edf7389eacf7f353d8135aa16328..93e1cc39d2df26c3b215c38acdf736e173adbb07 100644 (file)
@@ -38,6 +38,12 @@ typedef struct {
 
 struct daemon_state;
 
+/*
+ * Craft a simple reply, without the need to construct a config_tree. See
+ * daemon_send_simple in daemon-client.h for the description of the parameters.
+ */
+response daemon_reply_simple(char *id, ...);
+
 /*
  * The callback. Called once per request issued, in the respective client's
  * thread. It is presented by a parsed request (in the form of a config tree).
index d3e17ede53b7d17aed8b664233b49e6782321594..3e7bf89235f87862dcc235e21ca62de986dfa639 100644 (file)
@@ -6,11 +6,9 @@ typedef struct {
 
 static response handler(daemon_state s, client_handle h, request r)
 {
-       response res;
-       fprintf(stderr, "[D] REQUEST: %s\n", find_config_str(r.cft->root, "request", "NONE"));
-       res.error = 1;
-       res.buffer = strdup("hey hey.\n\n");
-       return res;
+       fprintf(stderr, "[D] REQUEST: %s, param = %d\n", find_config_str(r.cft->root, "request", "NONE"),
+                                                        find_config_int(r.cft->root, "param", -1));
+       return daemon_reply_simple("hey there", "param = %d", 42, NULL);
 }
 
 static int setup_post(daemon_state *s)
index 6ff4ded188fdcd57fe709413adf92bd0ab04737b..6608d19e856bc721415959da2c851c90d1cabd09 100644 (file)
@@ -5,7 +5,9 @@ int main() {
        int i;
        for (i = 0; i < 5; ++i ) {
                daemon_reply reply = daemon_send_simple(h, "hello world", "param = %d", 3, NULL);
-               fprintf(stderr, "[C] obtained: %s\n", reply.buffer);
+               fprintf(stderr, "[C] REPLY: %s, param = %d\n", find_config_str(reply.cft->root, "request", "NONE"),
+                                                              find_config_int(reply.cft->root, "param", -1));
+               daemon_reply_destroy(reply);
        }
        daemon_close(h);
        return 0;
This page took 0.037634 seconds and 5 git commands to generate.