summaryrefslogtreecommitdiffstats
path: root/src/afb-monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/afb-monitor.c')
-rw-r--r--src/afb-monitor.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/src/afb-monitor.c b/src/afb-monitor.c
index 18ea606b..a50e2c65 100644
--- a/src/afb-monitor.c
+++ b/src/afb-monitor.c
@@ -21,12 +21,12 @@
#include <json-c/json.h>
-#define AFB_BINDING_VERSION 0
+#define AFB_BINDING_VERSION 3
#include <afb/afb-binding.h>
#include "afb-api.h"
#include "afb-apiset.h"
-#include "afb-api-so-v2.h"
+#include "afb-api-v3.h"
#include "afb-evt.h"
#include "afb-xreq.h"
#include "afb-trace.h"
@@ -36,13 +36,12 @@
#include "monitor-api.inc"
-extern struct afb_apiset *main_apiset;
+static struct afb_apiset *target_set;
-static struct afb_binding_data_v2 datav2;
-
-int afb_monitor_init()
+int afb_monitor_init(struct afb_apiset *declare_set, struct afb_apiset *call_set)
{
- return afb_api_so_v2_add_binding(&_afb_binding_v2_monitor, NULL, main_apiset, &datav2);
+ target_set = call_set;
+ return -!afb_api_v3_from_binding(&_afb_binding_monitor, declare_set, call_set);
}
/******************************************************************************
@@ -66,28 +65,28 @@ static int decode_verbosity(struct json_object *v)
int level = -1;
if (!wrap_json_unpack(v, "i", &level)) {
- level = level < Verbosity_Level_Error ? Verbosity_Level_Error : level > Verbosity_Level_Debug ? Verbosity_Level_Debug : level;
+ level = level < _VERBOSITY_(Log_Level_Error) ? _VERBOSITY_(Log_Level_Error) : level > _VERBOSITY_(Log_Level_Debug) ? _VERBOSITY_(Log_Level_Debug) : level;
} else if (!wrap_json_unpack(v, "s", &s)) {
switch(*s&~' ') {
case 'D':
if (!strcasecmp(s, _debug_))
- level = Verbosity_Level_Debug;
+ level = _VERBOSITY_(Log_Level_Debug);
break;
case 'I':
if (!strcasecmp(s, _info_))
- level = Verbosity_Level_Info;
+ level = _VERBOSITY_(Log_Level_Info);
break;
case 'N':
if (!strcasecmp(s, _notice_))
- level = Verbosity_Level_Notice;
+ level = _VERBOSITY_(Log_Level_Notice);
break;
case 'W':
if (!strcasecmp(s, _warning_))
- level = Verbosity_Level_Warning;
+ level = _VERBOSITY_(Log_Level_Warning);
break;
case 'E':
if (!strcasecmp(s, _error_))
- level = Verbosity_Level_Error;
+ level = _VERBOSITY_(Log_Level_Error);
break;
}
}
@@ -100,9 +99,10 @@ static int decode_verbosity(struct json_object *v)
* @param the name of the api to set
* @param closure the verbosity to set as an integer casted to a pointer
*/
-static void set_verbosity_to_all_cb(struct afb_apiset *set, const char *name, void *closure)
+static void set_verbosity_to_all_cb(void *closure, struct afb_apiset *set, const char *name, int isalias)
{
- afb_apiset_set_verbosity(set, name, (int)(intptr_t)closure);
+ if (!isalias)
+ afb_apiset_set_logmask(set, name, (int)(intptr_t)closure);
}
/**
@@ -112,12 +112,13 @@ static void set_verbosity_to_all_cb(struct afb_apiset *set, const char *name, vo
*/
static void set_verbosity_to(const char *name, int level)
{
+ int mask = verbosity_to_mask(level);
if (!name || !name[0])
- verbosity = level;
+ verbosity_set(level);
else if (name[0] == '*' && !name[1])
- afb_apiset_enum(main_apiset, 1, set_verbosity_to_all_cb, (void*)(intptr_t)level);
+ afb_apiset_enum(target_set, 1, set_verbosity_to_all_cb, (void*)(intptr_t)mask);
else
- afb_apiset_set_verbosity(main_apiset, name, level);
+ afb_apiset_set_logmask(target_set, name, mask);
}
/**
@@ -154,12 +155,12 @@ static void set_verbosity(struct json_object *spec)
*/
static struct json_object *encode_verbosity(int level)
{
- switch(level) {
- 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_);
+ switch(_DEVERBOSITY_(level)) {
+ case Log_Level_Error: return json_object_new_string(_error_);
+ case Log_Level_Warning: return json_object_new_string(_warning_);
+ case Log_Level_Notice: return json_object_new_string(_notice_);
+ case Log_Level_Info: return json_object_new_string(_info_);
+ case Log_Level_Debug: return json_object_new_string(_debug_);
default: return json_object_new_int(level);
}
}
@@ -170,12 +171,12 @@ static struct json_object *encode_verbosity(int level)
* @param the name of the api to set
* @param closure the json object to build
*/
-static void get_verbosity_of_all_cb(struct afb_apiset *set, const char *name, void *closure)
+static void get_verbosity_of_all_cb(void *closure, struct afb_apiset *set, const char *name, int isalias)
{
struct json_object *resu = closure;
- int l = afb_apiset_get_verbosity(set, name);
- if (l >= 0)
- json_object_object_add(resu, name, encode_verbosity(l));
+ int m = afb_apiset_get_logmask(set, name);
+ if (m >= 0)
+ json_object_object_add(resu, name, encode_verbosity(verbosity_from_mask(m)));
}
/**
@@ -185,15 +186,15 @@ static void get_verbosity_of_all_cb(struct afb_apiset *set, const char *name, vo
*/
static void get_verbosity_of(struct json_object *resu, const char *name)
{
- int l;
+ int m;
if (!name || !name[0])
- json_object_object_add(resu, "", encode_verbosity(verbosity));
+ json_object_object_add(resu, "", encode_verbosity(verbosity_get()));
else if (name[0] == '*' && !name[1])
- afb_apiset_enum(main_apiset, 1, get_verbosity_of_all_cb, resu);
+ afb_apiset_enum(target_set, 1, get_verbosity_of_all_cb, resu);
else {
- l = afb_apiset_get_verbosity(main_apiset, name);
- if (l >= 0)
- json_object_object_add(resu, name, encode_verbosity(l));
+ m = afb_apiset_get_logmask(target_set, name);
+ if (m >= 0)
+ json_object_object_add(resu, name, encode_verbosity(verbosity_from_mask(m)));
}
}
@@ -242,8 +243,8 @@ static void get_one_api(struct json_object *resu, const char *name, struct json_
{
struct json_object *o;
- o = afb_apiset_describe(main_apiset, name);
- if (o || afb_apiset_lookup(main_apiset, name, 1))
+ o = afb_apiset_describe(target_set, name);
+ if (o || afb_apiset_lookup(target_set, name, 1))
json_object_object_add(resu, name, o);
}
@@ -253,7 +254,7 @@ static void get_one_api(struct json_object *resu, const char *name, struct json_
* @param the name of the api to set
* @param closure the json object to build
*/
-static void get_apis_of_all_cb(struct afb_apiset *set, const char *name, void *closure)
+static void get_apis_of_all_cb(void *closure, struct afb_apiset *set, const char *name, int isalias)
{
struct json_object *resu = closure;
get_one_api(resu, name, NULL);
@@ -285,7 +286,7 @@ static struct json_object *get_apis(struct json_object *spec)
} 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, 1, get_apis_of_all_cb, resu);
+ afb_apiset_enum(target_set, 1, get_apis_of_all_cb, resu);
}
return resu;
}
@@ -298,7 +299,7 @@ static const char _verbosity_[] = "verbosity";
static const char _apis_[] = "apis";
static const char _refresh_token_[] = "refresh-token";
-static void f_get(struct afb_req req)
+static void f_get(afb_req_t req)
{
struct json_object *r;
struct json_object *apis = NULL;
@@ -314,7 +315,7 @@ static void f_get(struct afb_req req)
afb_req_success(req, r, NULL);
}
-static void f_set(struct afb_req req)
+static void f_set(afb_req_t req)
{
struct json_object *verbosity = NULL;
@@ -325,9 +326,9 @@ static void f_set(struct afb_req req)
afb_req_success(req, NULL, NULL);
}
-static void *context_create()
+static void *context_create(void *closure)
{
- return afb_trace_create(_afb_binding_v2_monitor.api, NULL);
+ return afb_trace_create(_afb_binding_monitor.api, NULL);
}
static void context_destroy(void *pointer)
@@ -336,14 +337,14 @@ static void context_destroy(void *pointer)
afb_trace_unref(trace);
}
-static void f_trace(struct afb_req req)
+static void f_trace(afb_req_t 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);
+ trace = afb_req_context(req, 0, context_create, context_destroy, NULL);
wrap_json_unpack(afb_req_json(req), "{s?o s?o}", "add", &add, "drop", &drop);
if (add) {
rc = afb_trace_add(req, add, trace);
@@ -357,15 +358,15 @@ static void f_trace(struct afb_req req)
}
afb_req_success(req, NULL, NULL);
end:
- afb_apiset_update_hooks(main_apiset, NULL);
+ afb_apiset_update_hooks(target_set, NULL);
afb_evt_update_hooks();
}
-static void f_session(struct afb_req req)
+static void f_session(afb_req_t req)
{
struct json_object *r = NULL;
int refresh = 0;
- struct afb_xreq *xreq = xreq_from_request(req.closure);
+ struct afb_xreq *xreq = xreq_from_req_x2(req);
/* check right to call it */
if (xreq->context.super) {
@@ -387,4 +388,3 @@ static void f_session(struct afb_req req)
afb_req_success(req, r, NULL);
}
-