summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-05-31 11:32:46 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-05-31 11:32:46 +0200
commit524ce4c40da3b25630dffdd80c5aca99364a3569 (patch)
tree9d6e256f9b818c73d99d56c69da0149b052f2a83 /bindings
parent06c7e1c7e9aec77a1a22ccb14dd0e540cf08f5d9 (diff)
Add logging by request
Change-Id: I6dda714bcb8c36392c14a1981cfb8960f3db45b8 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'bindings')
-rw-r--r--bindings/samples/HelloWorld.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/bindings/samples/HelloWorld.c b/bindings/samples/HelloWorld.c
index 09c7d3e7..68af5fc6 100644
--- a/bindings/samples/HelloWorld.c
+++ b/bindings/samples/HelloWorld.c
@@ -325,9 +325,39 @@ static void callsync (struct afb_req request)
}
}
+static void verbose (struct afb_req request)
+{
+ int level = 5;
+ json_object *query = afb_req_json(request), *l;
+
+ if (json_object_is_type(query,json_type_int))
+ level = json_object_get_int(query);
+ else if (json_object_object_get_ex(query, "level", &l) && json_object_is_type(l, json_type_int))
+ level = json_object_get_int(l);
+
+ if (!json_object_object_get_ex(query,"message",&l))
+ l = query;
+
+ AFB_REQ_VERBOSE(request, level, "verbose called for %s", json_object_get_string(l));
+ afb_req_success(request, NULL, NULL);
+}
+
static void exitnow (struct afb_req request)
{
- exit(0);
+ int code = 0;
+ json_object *query = afb_req_json(request), *l;
+
+ if (json_object_is_type(query,json_type_int))
+ code = json_object_get_int(query);
+ else if (json_object_object_get_ex(query, "code", &l) && json_object_is_type(l, json_type_int))
+ code = json_object_get_int(l);
+
+ if (!json_object_object_get_ex(query,"reason",&l))
+ l = NULL;
+
+ REQ_NOTICE(request, "in phase of exiting with code %d, reason: %s", code, l ? json_object_get_string(l) : "unknown");
+ afb_req_success(request, NULL, NULL);
+ exit(code);
}
static int preinit()
@@ -365,6 +395,7 @@ static const struct afb_verb_v2 verbs[]= {
{ "eventpush", eventpush , NULL, AFB_SESSION_NONE },
{ "call", call , NULL, AFB_SESSION_NONE },
{ "callsync", callsync , NULL, AFB_SESSION_NONE },
+ { "verbose", verbose , NULL, AFB_SESSION_NONE },
{ "exit", exitnow , NULL, AFB_SESSION_NONE },
{ NULL}
};