aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-monitor.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-07-31 17:50:13 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-08-08 11:55:36 +0200
commit4ecf37c1899349e6ef7ac08813ebb52fc80b2677 (patch)
tree88d6b940fc8e6f296ac2a93dfab32bba1711418d /src/afb-monitor.c
parent330edf6a1ec91fa5a9829d6450fa4fff0b91c693 (diff)
afb-trace: Add tracing features to API monitor
This api allows to receive events when particular actions are reached. At the moment, tracing is bound to the API monitor and can trace anything. In the future, this will not be the case and the API monitor will only allow to trace requests of its session. The tracing of all will be available for supervision only. Change-Id: I880852612c2f77ff5329496b16c75fe602db4090 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-monitor.c')
-rw-r--r--src/afb-monitor.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/afb-monitor.c b/src/afb-monitor.c
index b361be79..7524d24e 100644
--- a/src/afb-monitor.c
+++ b/src/afb-monitor.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <json-c/json.h>
+
#include <afb/afb-binding-v2.h>
#include "afb-api.h"
@@ -28,6 +29,7 @@
#include "afb-api-so-v2.h"
#include "afb-ditf.h"
#include "afb-xreq.h"
+#include "afb-trace.h"
#include "verbose.h"
#include "wrap-json.h"
@@ -324,18 +326,36 @@ static void f_set(struct afb_req req)
afb_req_success(req, NULL, NULL);
}
-#if 0
-static void f_hook(struct afb_xreq *xreq)
+static void *context_create()
{
- struct json_object *o, *v;
+ return afb_trace_create(&datav2.daemon, NULL);
+}
- o = afb_xreq_json(xreq);
- if (json_object_object_get_ex(o, _verbosity_, &v)) {
- set_verbosity(v);
- }
+static void context_destroy(void *pointer)
+{
+ struct afb_trace *trace = pointer;
+ afb_trace_unref(trace);
+}
- if (!xreq->replied)
- afb_xreq_success(xreq, NULL, NULL);
+static void f_trace(struct afb_req req)
+{
+ int rc;
+ struct json_object *add = NULL;
+ struct json_object *drop = NULL;
+ struct afb_trace *trace;
+
+ trace = afb_req_context(req, context_create, context_destroy);
+ wrap_json_unpack(afb_req_json(req), "{s?o s?o}", "add", &add, "drop", &drop);
+ if (add) {
+ rc = afb_trace_add(req, add, trace);
+ if (rc)
+ return;
+ }
+ if (drop) {
+ rc = afb_trace_drop(req, drop, trace);
+ if (rc)
+ return;
+ }
+ afb_req_success(req, NULL, NULL);
}
-#endif