]> sourceware.org Git - lvm2.git/commitdiff
Add int/str lookup routines specific to the reply (in client) and request (in
authorPetr Rockai <prockai@redhat.com>
Mon, 27 Jun 2011 14:03:58 +0000 (14:03 +0000)
committerPetr Rockai <prockai@redhat.com>
Mon, 27 Jun 2011 14:03:58 +0000 (14:03 +0000)
server) for nicer-looking code (thin wrapping around find_config_{int,str}).

daemons/common/daemon-client.h
daemons/common/daemon-server.h
daemons/lvmetad/lvmetad-core.c
daemons/lvmetad/testclient.c

index 61dca5b5d4629234edc4007092c45c0e478066d8..124892d60fe540f23d8424b4791824a6714dc91f 100644 (file)
@@ -81,6 +81,15 @@ daemon_reply daemon_send_simple(daemon_handle h, char *id, ...);
 
 void daemon_reply_destroy(daemon_reply r);
 
+static inline int daemon_reply_int(daemon_reply r, const char *path, int def) {
+       return find_config_int(r.cft->root, path, def);
+}
+
+static inline const char *daemon_reply_str(daemon_reply r, const char *path, const char *def) {
+       return find_config_str(r.cft->root, path, def);
+}
+
+
 /* Shut down the communication to the daemon. Compulsory. */
 void daemon_close(daemon_handle h);
 
index 93e1cc39d2df26c3b215c38acdf736e173adbb07..92f354b02f24b7aeb8cda321ddc35fae4a0c7abe 100644 (file)
@@ -44,6 +44,14 @@ struct daemon_state;
  */
 response daemon_reply_simple(char *id, ...);
 
+static inline int daemon_request_int(request r, const char *path, int def) {
+       return find_config_int(r.cft->root, path, def);
+}
+
+static inline const char *daemon_request_str(request r, const char *path, const char *def) {
+       return find_config_str(r.cft->root, path, def);
+}
+
 /*
  * 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 3e7bf89235f87862dcc235e21ca62de986dfa639..bda99b77ff9cecd8ef1e38115a18fdefcb5ee760 100644 (file)
@@ -6,8 +6,8 @@ typedef struct {
 
 static response handler(daemon_state s, client_handle h, request r)
 {
-       fprintf(stderr, "[D] REQUEST: %s, param = %d\n", find_config_str(r.cft->root, "request", "NONE"),
-                                                        find_config_int(r.cft->root, "param", -1));
+       fprintf(stderr, "[D] REQUEST: %s, param = %d\n", daemon_request_str(r, "request", "NONE"),
+                                                        daemon_request_int(r, "param", -1));
        return daemon_reply_simple("hey there", "param = %d", 42, NULL);
 }
 
index 6608d19e856bc721415959da2c851c90d1cabd09..26f748c4f2886c9177f1b5a4c54f45e2f35cdf5f 100644 (file)
@@ -5,8 +5,8 @@ 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] REPLY: %s, param = %d\n", find_config_str(reply.cft->root, "request", "NONE"),
-                                                              find_config_int(reply.cft->root, "param", -1));
+               fprintf(stderr, "[C] REPLY: %s, param = %d\n", daemon_reply_str(reply, "request", "NONE"),
+                                                              daemon_reply_int(reply, "param", -1));
                daemon_reply_destroy(reply);
        }
        daemon_close(h);
This page took 0.037428 seconds and 5 git commands to generate.