X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-monitor.c;h=9f01cc020379e51e6d5d957da9927220b2bf582e;hb=d7936bbe45900b7bb315e0504672d242b7100af5;hp=a0618113039cdb640b54af4ab7ad2c90a99ce222;hpb=ae6f684d830871e81b0b4168424f6a4873eabbff;p=src%2Fapp-framework-binder.git diff --git a/src/afb-monitor.c b/src/afb-monitor.c index a0618113..9f01cc02 100644 --- a/src/afb-monitor.c +++ b/src/afb-monitor.c @@ -21,23 +21,28 @@ #include #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" #include "monitor-api.inc" extern struct afb_apiset *main_apiset; +static struct afb_binding_data_v2 datav2; + int afb_monitor_init() { - static int v; - return afb_api_so_v2_add_binding(&_afb_binding_v2_monitor, NULL, main_apiset, &v); + return afb_api_so_v2_add_binding(&_afb_binding_v2_monitor, NULL, main_apiset, &datav2); } /****************************************************************************** @@ -59,11 +64,10 @@ static int decode_verbosity(struct json_object *v) { const char *s; int level = -1; - if (json_object_is_type(v, json_type_int)) { - level = json_object_get_int(v); + + if (!wrap_json_unpack(v, "i", &level)) { level = level < 0 ? 0 : level > 3 ? 3 : level; - } else if (json_object_is_type(v, json_type_string)) { - s = json_object_get_string(v); + } else if (!wrap_json_unpack(v, "s", &s)) { switch(*s&~' ') { case 'D': if (!strcasecmp(s, _debug_)) @@ -197,11 +201,13 @@ static void get_verbosity_of(struct json_object *resu, const char *name) * @param resu the json object to build * @param spec specification of the verbosity to set */ -static void get_verbosity(struct json_object *resu, struct json_object *spec) +static struct json_object *get_verbosity(struct json_object *spec) { int i, n; + struct json_object *resu; struct json_object_iterator it, end; + resu = json_object_new_object(); if (json_object_is_type(spec, json_type_object)) { it = json_object_iter_begin(spec); end = json_object_iter_end(spec); @@ -213,10 +219,13 @@ static void get_verbosity(struct json_object *resu, struct json_object *spec) n = json_object_array_length(spec); for (i = 0 ; i < n ; i++) get_verbosity_of(resu, json_object_get_string(json_object_array_get_idx(spec, i))); + } else if (json_object_is_type(spec, json_type_string)) { + get_verbosity_of(resu, json_object_get_string(spec)); } else if (json_object_get_boolean(spec)) { get_verbosity_of(resu, ""); get_verbosity_of(resu, "*"); } + return resu; } /****************************************************************************** @@ -231,14 +240,10 @@ static void get_verbosity(struct json_object *resu, 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); - } } /** @@ -258,11 +263,13 @@ static void get_apis_of_all_cb(struct afb_apiset *set, const char *name, void *c * @param resu the json object to build * @param spec specification of the verbosity to set */ -static void get_apis(struct json_object *resu, struct json_object *spec) +static struct json_object *get_apis(struct json_object *spec) { int i, n; + struct json_object *resu; struct json_object_iterator it, end; + resu = json_object_new_object(); if (json_object_is_type(spec, json_type_object)) { it = json_object_iter_begin(spec); end = json_object_iter_end(spec); @@ -274,9 +281,12 @@ static void get_apis(struct json_object *resu, struct json_object *spec) n = json_object_array_length(spec); for (i = 0 ; i < n ; i++) get_one_api(resu, json_object_get_string(json_object_array_get_idx(spec, i)), NULL); + } else if (json_object_is_type(spec, json_type_string)) { + get_one_api(resu, json_object_get_string(spec), NULL); } else if (json_object_get_boolean(spec)) { afb_apiset_enum(main_apiset, get_apis_of_all_cb, resu); } + return resu; } /****************************************************************************** @@ -288,51 +298,64 @@ static const char _apis_[] = "apis"; static void f_get(struct afb_req req) { - struct json_object *o, *v, *r, *x; - - r = json_object_new_object(); - o = afb_req_json(req); - - if (json_object_object_get_ex(o, _verbosity_, &v)) { - x = json_object_new_object(); - json_object_object_add(r, _verbosity_, x); - get_verbosity(x, v); - } - - if (json_object_object_get_ex(o, _apis_, &v)) { - x = json_object_new_object(); - json_object_object_add(r, _apis_, x); - get_apis(x, v); - } - - afb_req_success(req, json_object_get(r), NULL); - json_object_put(r); + struct json_object *r; + struct json_object *apis = NULL; + struct json_object *verbosity = NULL; + + wrap_json_unpack(afb_req_json(req), "{s?:o,s?:o}", _verbosity_, &verbosity, _apis_, &apis); + if (verbosity) + verbosity = get_verbosity(verbosity); + if (apis) + apis = get_apis(apis); + + wrap_json_pack(&r, "{s:o*,s:o*}", _verbosity_, verbosity, _apis_, apis); + afb_req_success(req, r, NULL); } static void f_set(struct afb_req req) { - struct json_object *o, *v; + struct json_object *verbosity = NULL; - o = afb_req_json(req); - if (json_object_object_get_ex(o, _verbosity_, &v)) { - set_verbosity(v); - } + wrap_json_unpack(afb_req_json(req), "{s?:o}", _verbosity_, &verbosity); + if (verbosity) + set_verbosity(verbosity); 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