apiset: improvements
[src/app-framework-binder.git] / src / afb-api-so-v2.c
index 12b83ac..6038d96 100644 (file)
@@ -24,7 +24,8 @@
 
 #include <afb/afb-binding.h>
 
-#include "afb-apis.h"
+#include "afb-api.h"
+#include "afb-apiset.h"
 #include "afb-svc.h"
 #include "afb-ditf.h"
 #include "afb-evt.h"
@@ -66,12 +67,13 @@ static void call_cb(void *closure, struct afb_xreq *xreq)
 
        verb = search(desc, xreq->verb);
        if (!verb)
-               afb_xreq_fail_f(xreq, "unknown-verb", "verb %s unknown within api %s", xreq->verb, desc->binding->api);
+               afb_xreq_fail_unknown_verb(xreq);
        else
-               afb_xreq_call(xreq, verb->session, verb->callback);
+               if (!xreq_session_check_apply(xreq, verb->session))
+                       afb_xreq_call(xreq, verb->callback);
 }
 
-static int service_start_cb(void *closure, int share_session, int onneed)
+static int service_start_cb(void *closure, int share_session, int onneed, struct afb_apiset *apiset)
 {
        int (*start)(const struct afb_binding_interface *interface, struct afb_service service);
        void (*onevent)(const char *event, struct json_object *object);
@@ -103,7 +105,7 @@ static int service_start_cb(void *closure, int share_session, int onneed)
 
        /* get the event handler if any */
        onevent = desc->binding->onevent;
-       desc->service = afb_svc_create_v2(share_session, onevent, start, &desc->ditf.interface);
+       desc->service = afb_svc_create_v2(apiset, share_session, onevent, start, &desc->ditf.interface);
        if (desc->service == NULL) {
                /* starting error */
                ERROR("Starting service %s failed", desc->binding->api);
@@ -119,7 +121,27 @@ static void update_hooks_cb(void *closure)
        afb_ditf_update_hook(&desc->ditf);
 }
 
-int afb_api_so_v2_add(const char *path, void *handle)
+static int get_verbosity_cb(void *closure)
+{
+       struct api_so_v2 *desc = closure;
+       return desc->ditf.interface.verbosity;
+}
+
+static void set_verbosity_cb(void *closure, int level)
+{
+       struct api_so_v2 *desc = closure;
+       desc->ditf.interface.verbosity = level;
+}
+
+static struct afb_api_itf so_v2_api_itf = {
+       .call = call_cb,
+       .service_start = service_start_cb,
+       .update_hooks = update_hooks_cb,
+       .get_verbosity = get_verbosity_cb,
+       .set_verbosity = set_verbosity_cb
+};
+
+int afb_api_so_v2_add(const char *path, void *handle, struct afb_apiset *apiset)
 {
        int rc;
        struct api_so_v2 *desc;
@@ -138,7 +160,7 @@ int afb_api_so_v2_add(const char *path, void *handle)
                ERROR("binding [%s] bad api name...", path);
                goto error;
        }
-       if (!afb_apis_is_valid_api_name(binding->api)) {
+       if (!afb_api_is_valid_name(binding->api)) {
                ERROR("binding [%s] invalid api name...", path);
                goto error;
        }
@@ -177,10 +199,8 @@ int afb_api_so_v2_add(const char *path, void *handle)
 
        /* records the binding */
        afb_api.closure = desc;
-       afb_api.call = call_cb;
-       afb_api.service_start = service_start_cb;
-       afb_api.update_hooks = update_hooks_cb;
-       if (afb_apis_add(binding->api, afb_api) < 0) {
+       afb_api.itf = &so_v2_api_itf;
+       if (afb_apiset_add(apiset, binding->api, afb_api) < 0) {
                ERROR("binding [%s] can't be registered...", path);
                goto error2;
        }