*/
#define _GNU_SOURCE
+#define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO
#include <string.h>
#include <json-c/json.h>
+#include <afb/afb-binding-v2.h>
#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)
+#include "monitor-api.inc"
-/**
- * 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*);
-
- fun = lookfun(xreq->verb);
- if (!fun)
- afb_xreq_fail_unknown_verb(xreq);
- else
- fun(xreq);
-}
+extern struct afb_apiset *main_apiset;
-static struct afb_api_itf monitor_api_itf = {
- .call = call_cb
-};
+static struct afb_binding_data_v2 datav2;
int afb_monitor_init()
{
- struct afb_api api;
- api.closure = NULL;
- api.itf = &monitor_api_itf;
- return afb_apiset_add(main_apiset, "monitor", api);
+ return afb_api_so_v2_add_binding(&_afb_binding_v2_monitor, NULL, main_apiset, &datav2);
}
/******************************************************************************
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, "*");
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);
}
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();
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;
if (!xreq->replied)
afb_xreq_success(xreq, NULL, NULL);
}
+#endif