Update date of copyright notices
[src/app-framework-binder.git] / src / afb-api-dbus.c
index 806d743..98c2693 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015, 2016, 2017 "IoT.bzh"
+ * Copyright (C) 2015-2018 "IoT.bzh"
  * Author José Bollo <jose.bollo@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,7 +29,7 @@
 
 #include <afb/afb-event.h>
 
-#include "afb-common.h"
+#include "afb-systemd.h"
 
 #include "afb-session.h"
 #include "afb-msg-json.h"
@@ -113,7 +113,7 @@ static struct api_dbus *make_api_dbus_3(int system, const char *path, size_t pat
                goto error2;
        }
        api->api++;
-       if (!afb_api_is_valid_name(api->api)) {
+       if (!afb_api_is_valid_name(api->api, 1)) {
                errno = EINVAL;
                goto error2;
        }
@@ -128,7 +128,7 @@ static struct api_dbus *make_api_dbus_3(int system, const char *path, size_t pat
        }
 
        /* choose the bus */
-       sdbus = (system ? afb_common_get_system_bus : afb_common_get_user_bus)();
+       sdbus = (system ? afb_systemd_get_system_bus : afb_systemd_get_user_bus)();
        if (sdbus == NULL)
                goto error2;
 
@@ -382,7 +382,7 @@ static struct dbus_event *api_dbus_client_event_search(struct api_dbus *api, int
        struct dbus_event *ev;
 
        ev = api->client.events;
-       while (ev != NULL && (ev->id != id || 0 != strcmp(afb_evt_event_fullname(ev->eventid), name)))
+       while (ev != NULL && (ev->id != id || 0 != strcmp(afb_evt_eventid_fullname(ev->eventid), name)))
                ev = ev->next;
 
        return ev;
@@ -403,7 +403,7 @@ static void api_dbus_client_event_create(struct api_dbus *api, int id, const cha
        /* no conflict, try to add it */
        ev = malloc(sizeof *ev);
        if (ev != NULL) {
-               ev->eventid = afb_evt_create_event(name);
+               ev->eventid = afb_evt_eventid_create(name);
                if (ev->eventid == NULL)
                        free(ev);
                else {
@@ -440,7 +440,7 @@ static void api_dbus_client_event_drop(struct api_dbus *api, int id, const char
        *prv = ev->next;
 
        /* destroys the event */
-       afb_evt_event_unref(ev->eventid);
+       afb_evt_eventid_unref(ev->eventid);
        free(ev);
 }
 
@@ -459,7 +459,7 @@ static void api_dbus_client_event_push(struct api_dbus *api, int id, const char
 
        /* destroys the event */
        object = json_tokener_parse(data);
-       afb_evt_push(ev->eventid, object);
+       afb_evt_eventid_push(ev->eventid, object);
 }
 
 /* subscribes an event */
@@ -848,9 +848,9 @@ static int dbus_req_subscribe(struct afb_xreq *xreq, struct afb_eventid *eventid
        uint64_t msgid;
        int rc;
 
-       rc = afb_evt_add_watch(dreq->listener->listener, eventid);
+       rc = afb_evt_eventid_add_watch(dreq->listener->listener, eventid);
        sd_bus_message_get_cookie(dreq->message, &msgid);
-       afb_api_dbus_server_event_send(dreq->listener->origin, 'S', afb_evt_event_fullname(eventid), afb_evt_event_id(eventid), "", msgid);
+       afb_api_dbus_server_event_send(dreq->listener->origin, 'S', afb_evt_eventid_fullname(eventid), afb_evt_eventid_id(eventid), "", msgid);
        return rc;
 }
 
@@ -861,18 +861,32 @@ static int dbus_req_unsubscribe(struct afb_xreq *xreq, struct afb_eventid *event
        int rc;
 
        sd_bus_message_get_cookie(dreq->message, &msgid);
-       afb_api_dbus_server_event_send(dreq->listener->origin, 'U', afb_evt_event_fullname(eventid), afb_evt_event_id(eventid), "", msgid);
-       rc = afb_evt_remove_watch(dreq->listener->listener, eventid);
+       afb_api_dbus_server_event_send(dreq->listener->origin, 'U', afb_evt_eventid_fullname(eventid), afb_evt_eventid_id(eventid), "", msgid);
+       rc = afb_evt_eventid_remove_watch(dreq->listener->listener, eventid);
        return rc;
 }
 
+static void dbus_req_subcall(
+       struct afb_xreq *xreq,
+       const char *api,
+       const char *verb,
+       struct json_object *args,
+       void (*callback)(void*, int, struct json_object*),
+       void *cb_closure)
+{
+       ERROR("DBUS API doesn't support subcalls, info: %s/%s(%s)", api, verb, json_object_to_json_string(args));
+       callback(cb_closure, 1, afb_msg_json_reply_error("error", "subcall isn't supported", NULL, NULL));
+       json_object_put(args);
+}
+
 const struct afb_xreq_query_itf afb_api_dbus_xreq_itf = {
        .json = dbus_req_json,
        .success = dbus_req_success,
        .fail = dbus_req_fail,
        .unref = dbus_req_destroy,
        .subscribe = dbus_req_subscribe,
-       .unsubscribe = dbus_req_unsubscribe
+       .unsubscribe = dbus_req_unsubscribe,
+       .subcall = dbus_req_subcall
 };
 
 /******************* server part **********************************/