summaryrefslogtreecommitdiffstats
path: root/src/persistence-binding.c
diff options
context:
space:
mode:
authorGaykawadpk <Puja.Kumari@kpit.com>2019-09-21 17:37:08 +0530
committerGaykawadpk <Puja.Kumari@kpit.com>2019-10-09 10:51:49 +0530
commitfb31aa674d3e006b7a7327c068f048ab9cee1964 (patch)
tree5e878ee4d8558fec6c580e5025501cda0c6bee0d /src/persistence-binding.c
parent298b2fe4914c63bd7aec2fc6a979d152599e3c46 (diff)
binding: data-persistence: Modified the response of verb_read
Added key and value both in response so that user can know which key the value corresponds to. The current persistence implementation responds with only the value when queried. Since this is async call and multiple keys can be queried at the same time, the key and value should be given as response to any persistence query done. This will improve the readability of the Read verb response for user application. Also made the same changes for failed case of Read verb so that if read verb fails, user can know for which key it failed. Bug-AGL: SPEC-2828 Signed-off-by: Gaykawadpk <Puja.Kumari@kpit.com> Change-Id: I565cd78ca2c1e7c5d5f63ab49479b495044772ce
Diffstat (limited to 'src/persistence-binding.c')
-rw-r--r--src/persistence-binding.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/persistence-binding.c b/src/persistence-binding.c
index 3efb1f0..d1327a5 100644
--- a/src/persistence-binding.c
+++ b/src/persistence-binding.c
@@ -236,24 +236,40 @@ static void xdb_delete(afb_req_t req, datum *key)
static void xdb_get(afb_req_t req, datum *key)
{
struct json_object* obj;
+ struct json_object* args;
+ struct json_object* item = NULL;
datum result;
+ /* get the key */
+ args = afb_req_json(req);
+
+ obj = json_object_new_object();
+
+ if (json_object_object_get_ex(args, "key", &item))
+ {
+ json_object_object_add(obj, "key", json_object_get(item));
+ }
+
result = gdbm_fetch(database, *key);
if (result.dptr)
{
- obj = json_object_new_object();
+
json_object_object_add(obj, "value", json_tokener_parse(result.dptr));
+
afb_req_reply(req, obj, NULL, NULL);
+
free(result.dptr);
+
}
else
{
+ json_object_object_add(obj, "value", NULL);
AFB_API_ERROR(afbBindingRoot, "can't get key %s: %s%s%s",
DATA_STR(*key),
gdbm_strerror(gdbm_errno),
IFSYS(", ", ""),
IFSYS(strerror(errno), ""));
- afb_req_reply_f(req, NULL, "failed", "%s", gdbm_strerror(gdbm_errno));
+ afb_req_reply_f(req, obj, "failed", "%s", gdbm_strerror(gdbm_errno));
}
}
#endif