X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-monitor.c;h=a0618113039cdb640b54af4ab7ad2c90a99ce222;hb=ae6f684d830871e81b0b4168424f6a4873eabbff;hp=5d5c12d1f1d7ace74d9a5c322e5cd867f3540117;hpb=1164734afd826ca8cef0a624aa4f4c59ecb1e228;p=src%2Fapp-framework-binder.git diff --git a/src/afb-monitor.c b/src/afb-monitor.c index 5d5c12d1..a0618113 100644 --- a/src/afb-monitor.c +++ b/src/afb-monitor.c @@ -16,90 +16,28 @@ */ #define _GNU_SOURCE +#define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO #include #include +#include #include "afb-api.h" #include "afb-apiset.h" +#include "afb-api-so-v2.h" #include "afb-ditf.h" #include "afb-xreq.h" #include "verbose.h" -extern struct afb_apiset *main_apiset; - -/* CAUTION! KEEP VERBS SORTED */ -#define VERBS \ - V(get) \ - V(hook) \ - V(set) - -/** - * Declare functions of verbs - */ -#define F(x) static void f_##x(struct afb_xreq *xreq) -#define V(x) F(x); - VERBS -#undef V - -/** - * Name of the known verbs - */ -static const struct { - const char *name; - void (*function)(struct afb_xreq*); -} verbs[] = { -#define V(x) { .name = #x, .function = f_##x }, - VERBS -#undef V -}; - -/** - * get the function of a verb - * @param verb the name of the verb - * @return the function for the verb or NULL when no verb of name exists - */ -static void (*lookfun(const char *verb))(struct afb_xreq*) -{ - int l, u, i, c; - - l = 0; - u = (int)(sizeof verbs / sizeof *verbs); - while (l < u) { - i = (l + u) >> 1; - c = strcmp(verb, verbs[i].name); - if (c == 0) - return verbs[i].function; - if (c < 0) - u = i; - else - l = i + 1; - } - return NULL; -} - -static void call_cb(void *closure, struct afb_xreq *xreq) -{ - void (*fun)(struct afb_xreq*); +#include "monitor-api.inc" - fun = lookfun(xreq->verb); - if (!fun) - afb_xreq_fail_unknown_verb(xreq); - else - fun(xreq); -} - -static struct afb_api_itf monitor_api_itf = { - .call = call_cb -}; +extern struct afb_apiset *main_apiset; int afb_monitor_init() { - struct afb_api api; - api.closure = NULL; - api.itf = &monitor_api_itf; - return afb_apiset_add(main_apiset, "monitor", api); + static int v; + return afb_api_so_v2_add_binding(&_afb_binding_v2_monitor, NULL, main_apiset, &v); } /****************************************************************************** @@ -348,12 +286,12 @@ static void get_apis(struct json_object *resu, struct json_object *spec) static const char _verbosity_[] = "verbosity"; static const char _apis_[] = "apis"; -static void f_get(struct afb_xreq *xreq) +static void f_get(struct afb_req req) { struct json_object *o, *v, *r, *x; r = json_object_new_object(); - o = afb_xreq_json(xreq); + o = afb_req_json(req); if (json_object_object_get_ex(o, _verbosity_, &v)) { x = json_object_new_object(); @@ -367,24 +305,23 @@ static void f_get(struct afb_xreq *xreq) get_apis(x, v); } - if (!xreq->replied) - afb_xreq_success(xreq, json_object_get(r), NULL); + afb_req_success(req, json_object_get(r), NULL); json_object_put(r); } -static void f_set(struct afb_xreq *xreq) +static void f_set(struct afb_req req) { struct json_object *o, *v; - o = afb_xreq_json(xreq); + o = afb_req_json(req); if (json_object_object_get_ex(o, _verbosity_, &v)) { set_verbosity(v); } - if (!xreq->replied) - afb_xreq_success(xreq, NULL, NULL); + afb_req_success(req, NULL, NULL); } +#if 0 static void f_hook(struct afb_xreq *xreq) { struct json_object *o, *v; @@ -397,4 +334,5 @@ static void f_hook(struct afb_xreq *xreq) if (!xreq->replied) afb_xreq_success(xreq, NULL, NULL); } +#endif