From 94bb67ab37aabf69e7617e8695bf364493c1bfa6 Mon Sep 17 00:00:00 2001 From: Petr Rockai Date: Mon, 27 Jun 2011 14:03:58 +0000 Subject: [PATCH] Add int/str lookup routines specific to the reply (in client) and request (in server) for nicer-looking code (thin wrapping around find_config_{int,str}). --- daemons/common/daemon-client.h | 9 +++++++++ daemons/common/daemon-server.h | 8 ++++++++ daemons/lvmetad/lvmetad-core.c | 4 ++-- daemons/lvmetad/testclient.c | 4 ++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/daemons/common/daemon-client.h b/daemons/common/daemon-client.h index 61dca5b5d..124892d60 100644 --- a/daemons/common/daemon-client.h +++ b/daemons/common/daemon-client.h @@ -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); diff --git a/daemons/common/daemon-server.h b/daemons/common/daemon-server.h index 93e1cc39d..92f354b02 100644 --- a/daemons/common/daemon-server.h +++ b/daemons/common/daemon-server.h @@ -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). diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c index 3e7bf8923..bda99b77f 100644 --- a/daemons/lvmetad/lvmetad-core.c +++ b/daemons/lvmetad/lvmetad-core.c @@ -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); } diff --git a/daemons/lvmetad/testclient.c b/daemons/lvmetad/testclient.c index 6608d19e8..26f748c4f 100644 --- a/daemons/lvmetad/testclient.c +++ b/daemons/lvmetad/testclient.c @@ -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); -- 2.43.5