Update copyright dates
[src/app-framework-binder.git] / bindings / intrinsics / afb-dbus-binding.c
index 4eab2eb..04bbad0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 "IoT.bzh"
+ * Copyright (C) 2015-2020 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
 #include <systemd/sd-bus.h>
 #include <systemd/sd-bus-protocol.h>
 
+#define AFB_BINDING_VERSION 3
 #include <afb/afb-binding.h>
 
-/*
- * the interface to afb-daemon
- */
-const struct afb_binding_interface *afbitf;
-
 /*
  * union of possible dbus values
  */
@@ -370,7 +366,7 @@ static int packsingle(struct sd_bus_message *msg, const char *signature, struct
                        goto error;
                if (json_object_is_type(item, json_type_array)) {
                        /* Is an array! */
-                       count = json_object_array_length(item);
+                       count = (int)json_object_array_length(item);
                        index = 0;
                        while(index < count) {
                                rc = packsingle(msg, subsig, json_object_array_get_idx(item, index++));
@@ -465,7 +461,7 @@ static int packlist(struct sd_bus_message *msg, const char *signature, struct js
        }
 
        /* iterate over elements */
-       count = json_object_array_length(list);
+       count = (int)json_object_array_length(list);
        index = 0;
        for (;;) {
                /* check state */
@@ -496,7 +492,7 @@ error:
 /*
  * handle the reply
  */
-static int on_rawcall_reply(sd_bus_message *msg, struct afb_req *req, sd_bus_error *ret_error)
+static int on_rawcall_reply(sd_bus_message *msg, afb_req_t *req, sd_bus_error *ret_error)
 {
        struct json_object *obj = NULL;
        int rc;
@@ -531,7 +527,7 @@ static int on_rawcall_reply(sd_bus_message *msg, struct afb_req *req, sd_bus_err
  *     "arguments": "ARRAY of arguments"
  *   }
  */
-static void rawcall(struct afb_req req)
+static void rawcall(afb_req_t req)
 {
        struct json_object *obj;
        struct json_object *args;
@@ -568,9 +564,9 @@ static void rawcall(struct afb_req req)
        /* get bus */
        busname = strval(obj, "bus");
        if (busname != NULL && !strcmp(busname, "system"))
-               bus = afb_daemon_get_system_bus(afbitf->daemon);
+               bus = afb_api_get_system_bus(req->api);
        else
-               bus = afb_daemon_get_user_bus(afbitf->daemon);
+               bus = afb_api_get_user_bus(req->api);
 
        /* creates the message */
        rc = sd_bus_message_new_method_call(bus, &msg, destination, path, interface, member);
@@ -600,32 +596,19 @@ cleanup:
 /*
  * array of the verbs exported to afb-daemon
  */
-static const struct afb_verb_desc_v1 binding_verbs[] = {
+static const struct afb_verb_v3 binding_verbs[] = {
   /* VERB'S NAME       SESSION MANAGEMENT          FUNCTION TO CALL     SHORT DESCRIPTION */
-  { .name= "rawcall",  .session= AFB_SESSION_NONE, .callback= rawcall,  .info= "raw call to dbus method" },
-  { .name= NULL } /* marker for end of the array */
+  { .verb= "rawcall",  .session= AFB_SESSION_NONE, .callback= rawcall,  .info= "raw call to dbus method" },
+  { .verb= NULL } /* marker for end of the array */
 };
 
 /*
  * description of the binding for afb-daemon
  */
-static const struct afb_binding binding_description =
+const struct afb_binding_v3 afbBindingV3 =
 {
-  /* description conforms to VERSION 1 */
-  .type= AFB_BINDING_VERSION_1,
-  .v1= {                       /* fills the v1 field of the union when AFB_BINDING_VERSION_1 */
-    .prefix= "dbus",           /* the API name (or binding name or prefix) */
-    .info= "raw dbus binding", /* short description of of the binding */
+    .api   = "dbus",           /* the API name (or binding name or prefix) */
+    .info  = "raw dbus binding",       /* short description of of the binding */
     .verbs = binding_verbs     /* the array describing the verbs of the API */
-  }
 };
 
-/*
- * activation function for registering the binding called by afb-daemon
- */
-const struct afb_binding *afbBindingV1Register(const struct afb_binding_interface *itf)
-{
-       afbitf = itf;                   /* records the interface for accessing afb-daemon */
-       return &binding_description;    /* returns the description of the binding */
-}
-