X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-monitor.c;h=8876f4c64e2d602728ada639eb4a0aa47954c2fc;hb=9e8fda2954d951ea819dbddfe5afe466b2306074;hp=9f01cc020379e51e6d5d957da9927220b2bf582e;hpb=d7936bbe45900b7bb315e0504672d242b7100af5;p=src%2Fapp-framework-binder.git diff --git a/src/afb-monitor.c b/src/afb-monitor.c index 9f01cc02..8876f4c6 100644 --- a/src/afb-monitor.c +++ b/src/afb-monitor.c @@ -16,21 +16,21 @@ */ #define _GNU_SOURCE -#define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO #include #include -#include +#define AFB_BINDING_VERSION 0 +#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 "afb-session.h" #include "verbose.h" #include "wrap-json.h" @@ -66,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; } } @@ -115,7 +115,7 @@ static void set_verbosity_to(const char *name, int level) if (!name || !name[0]) verbosity = level; else if (name[0] == '*' && !name[1]) - afb_apiset_enum(main_apiset, set_verbosity_to_all_cb, (void*)(intptr_t)level); + afb_apiset_enum(main_apiset, 1, set_verbosity_to_all_cb, (void*)(intptr_t)level); else afb_apiset_set_verbosity(main_apiset, name, level); } @@ -149,16 +149,17 @@ static void set_verbosity(struct json_object *spec) /** * Translate verbosity level to a protocol indication. - * @param level the verbosity + * @param level the verbosity * @return the encoded verbosity */ 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); } } @@ -188,7 +189,7 @@ static void get_verbosity_of(struct json_object *resu, const char *name) if (!name || !name[0]) json_object_object_add(resu, "", encode_verbosity(verbosity)); else if (name[0] == '*' && !name[1]) - afb_apiset_enum(main_apiset, get_verbosity_of_all_cb, resu); + afb_apiset_enum(main_apiset, 1, get_verbosity_of_all_cb, resu); else { l = afb_apiset_get_verbosity(main_apiset, name); if (l >= 0) @@ -242,7 +243,7 @@ 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_has(main_apiset, name)) + if (o || afb_apiset_lookup(main_apiset, name, 1)) json_object_object_add(resu, name, o); } @@ -284,7 +285,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, get_apis_of_all_cb, resu); + afb_apiset_enum(main_apiset, 1, get_apis_of_all_cb, resu); } return resu; } @@ -295,6 +296,7 @@ static struct json_object *get_apis(struct json_object *spec) 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) { @@ -325,7 +327,7 @@ static void f_set(struct afb_req req) static void *context_create() { - return afb_trace_create(&datav2.daemon, NULL); + return afb_trace_create(_afb_binding_v2_monitor.api, NULL); } static void context_destroy(void *pointer) @@ -359,3 +361,30 @@ end: afb_evt_update_hooks(); } +static void f_session(struct afb_req req) +{ + struct json_object *r = NULL; + int refresh = 0; + struct afb_xreq *xreq = xreq_from_request(req.closure); + + /* check right to call it */ + if (xreq->context.super) { + afb_req_fail(req, "invalid", "reserved to direct clients"); + return; + } + + /* renew the token if required */ + wrap_json_unpack(afb_req_json(req), "{s?:b}", _refresh_token_, &refresh); + if (refresh) + afb_context_refresh(&xreq->context); + + /* make the result */ + wrap_json_pack(&r, "{s:s,s:s,s:i,s:i}", + "uuid", afb_session_uuid(xreq->context.session), + "token", afb_session_token(xreq->context.session), + "timeout", afb_session_timeout(xreq->context.session), + "remain", afb_session_what_remains(xreq->context.session)); + afb_req_success(req, r, NULL); +} + +