X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-monitor.c;h=18ea606b32a2ee74f7b31c7b32d0f31492d08950;hb=428dd77c7ef528dd1769d7c9bb95cd0fb2eaf2a8;hp=44233109ec5a26453009755824dfa9c3d10ad415;hpb=8f3368daeca3d5c184321e96cba60886bb7fc82f;p=src%2Fapp-framework-binder.git diff --git a/src/afb-monitor.c b/src/afb-monitor.c index 44233109..18ea606b 100644 --- a/src/afb-monitor.c +++ b/src/afb-monitor.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 "IoT.bzh" + * Copyright (C) 2016, 2017, 2018 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -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" @@ -149,7 +149,7 @@ 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) @@ -296,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) { @@ -326,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) @@ -360,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); +} + +