X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-monitor.c;h=fd334cf9f43aa5c0950554f0d8ca86c0aed16422;hb=859aa04ec2ee66709261a62d7f002d6a01c97a81;hp=b361be79aac2b1b5fd0bc46b2f6deeec76ccb5dd;hpb=2c0d6171441fc3612c3cf60fda70a1d90b18be64;p=src%2Fapp-framework-binder.git diff --git a/src/afb-monitor.c b/src/afb-monitor.c index b361be79..fd334cf9 100644 --- a/src/afb-monitor.c +++ b/src/afb-monitor.c @@ -21,13 +21,16 @@ #include #include + #include #include "afb-api.h" #include "afb-apiset.h" #include "afb-api-so-v2.h" #include "afb-ditf.h" +#include "afb-evt.h" #include "afb-xreq.h" +#include "afb-trace.h" #include "verbose.h" #include "wrap-json.h" @@ -63,28 +66,28 @@ static int decode_verbosity(struct json_object *v) int level = -1; if (!wrap_json_unpack(v, "i", &level)) { - level = level < 0 ? 0 : level > 3 ? 3 : level; + level = level < Verbosity_Level_Error ? Verbosity_Level_Error : level > Verbosity_Level_Debug ? Verbosity_Level_Debug : level; } else if (!wrap_json_unpack(v, "s", &s)) { switch(*s&~' ') { case 'D': if (!strcasecmp(s, _debug_)) - level = 3; + level = Verbosity_Level_Debug; break; case 'I': if (!strcasecmp(s, _info_)) - level = 2; + level = Verbosity_Level_Info; break; case 'N': if (!strcasecmp(s, _notice_)) - level = 1; + level = Verbosity_Level_Notice; break; case 'W': if (!strcasecmp(s, _warning_)) - level = 1; + level = Verbosity_Level_Warning; break; case 'E': if (!strcasecmp(s, _error_)) - level = 0; + level = Verbosity_Level_Error; break; } } @@ -152,10 +155,11 @@ static void set_verbosity(struct json_object *spec) static struct json_object *encode_verbosity(int level) { switch(level) { - case 0: return json_object_new_string(_error_); - case 1: return json_object_new_string(_notice_); - case 2: return json_object_new_string(_info_); - case 3: return json_object_new_string(_debug_); + case Verbosity_Level_Error: return json_object_new_string(_error_); + case Verbosity_Level_Warning: return json_object_new_string(_warning_); + case Verbosity_Level_Notice: return json_object_new_string(_notice_); + case Verbosity_Level_Info: return json_object_new_string(_info_); + case Verbosity_Level_Debug: return json_object_new_string(_debug_); default: return json_object_new_int(level); } } @@ -237,14 +241,10 @@ static struct json_object *get_verbosity(struct json_object *spec) static void get_one_api(struct json_object *resu, const char *name, struct json_object *spec) { struct json_object *o; - struct afb_api api; - int rc; - rc = afb_apiset_lookup(main_apiset, name, &api); - if (!rc) { - o = api.itf->describe ? api.itf->describe(api.closure) : NULL; + o = afb_apiset_describe(main_apiset, name); + if (o || afb_apiset_has(main_apiset, name)) json_object_object_add(resu, name, o); - } } /** @@ -324,18 +324,39 @@ 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) + goto end; + } + if (drop) { + rc = afb_trace_drop(req, drop, trace); + if (rc) + goto end; + } + afb_req_success(req, NULL, NULL); +end: + afb_apiset_update_hooks(main_apiset, NULL); + afb_evt_update_hooks(); } -#endif