#define NO_PLUGIN_VERBOSE_MACRO
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <systemd/sd-bus.h>
#include <json-c/json.h>
-#include <afb/afb-req-itf.h>
+#include <afb/afb-event.h>
#include "afb-common.h"
#include "afb-session.h"
#include "afb-msg-json.h"
-#include "afb-apis.h"
-#include "afb-api-so.h"
+#include "afb-api.h"
+#include "afb-apiset.h"
+#include "afb-api-dbus.h"
#include "afb-context.h"
#include "afb-cred.h"
#include "afb-evt.h"
struct sd_bus_slot *slot_call;
struct afb_evt_listener *listener; /* listener for broadcasted events */
struct origin *origins;
+ struct afb_apiset *apiset;
} server;
};
};
goto error2;
}
api->api++;
- if (!afb_apis_is_valid_api_name(api->api)) {
+ if (!afb_api_is_valid_name(api->api)) {
errno = EINVAL;
goto error2;
}
memo = malloc(sizeof *memo);
if (memo != NULL) {
- afb_xreq_addref(xreq);
+ afb_xreq_unhooked_addref(xreq);
memo->xreq = xreq;
memo->msgid = 0;
memo->api = api;
prv = &(*prv)->next;
}
- afb_xreq_unref(memo->xreq);
+ afb_xreq_unhooked_unref(memo->xreq);
free(memo);
}
sd_bus_message_unref(msg);
}
-static int api_dbus_service_start(void *closure, int share_session, int onneed)
-{
- struct api_dbus *api = closure;
-
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* already started: it is an error */
- ERROR("The Dbus binding %s is not a startable service", api->name);
- return -1;
-}
-
/* receives broadcasted events */
static int api_dbus_client_on_broadcast_event(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
{
struct dbus_event *ev;
ev = api->client.events;
- while (ev != NULL && (ev->id != id || 0 != strcmp(afb_evt_event_name(ev->event), name)))
+ while (ev != NULL && (ev->id != id || 0 != strcmp(afb_evt_event_fullname(ev->event), name)))
ev = ev->next;
return ev;
*prv = ev->next;
/* destroys the event */
- afb_event_drop(ev->event);
+ afb_event_unref(ev->event);
free(ev);
}
}
static struct afb_api_itf dbus_api_itf = {
- .call = api_dbus_client_call,
- .service_start = api_dbus_service_start
+ .call = api_dbus_client_call
};
/* adds a afb-dbus-service client api */
-int afb_api_dbus_add_client(const char *path)
+int afb_api_dbus_add_client(const char *path, struct afb_apiset *apiset)
{
int rc;
struct api_dbus *api;
/* record it as an API */
afb_api.closure = api;
afb_api.itf = &dbus_api_itf;
- if (afb_apis_add(api->api, afb_api) < 0)
+ afb_api.group = NULL;
+ if (afb_apiset_add(apiset, api->api, afb_api) < 0)
goto error2;
return 0;
rc = afb_evt_add_watch(dreq->listener->listener, event);
sd_bus_message_get_cookie(dreq->message, &msgid);
- afb_api_dbus_server_event_send(dreq->listener->origin, 'S', afb_evt_event_name(event), afb_evt_event_id(event), "", msgid);
+ afb_api_dbus_server_event_send(dreq->listener->origin, 'S', afb_evt_event_fullname(event), afb_evt_event_id(event), "", msgid);
return rc;
}
int rc;
sd_bus_message_get_cookie(dreq->message, &msgid);
- afb_api_dbus_server_event_send(dreq->listener->origin, 'U', afb_evt_event_name(event), afb_evt_event_id(event), "", msgid);
+ afb_api_dbus_server_event_send(dreq->listener->origin, 'U', afb_evt_event_fullname(event), afb_evt_event_id(event), "", msgid);
rc = afb_evt_remove_watch(dreq->listener->listener, event);
return rc;
}
dreq->listener = listener;
dreq->xreq.api = api->api;
dreq->xreq.verb = method;
- afb_apis_call(&dreq->xreq);
- afb_xreq_unref(&dreq->xreq);
+ afb_xreq_process(&dreq->xreq, api->server.apiset);
return 1;
out_of_memory:
}
/* create the service */
-int afb_api_dbus_add_server(const char *path)
+int afb_api_dbus_add_server(const char *path, struct afb_apiset *apiset)
{
int rc;
struct api_dbus *api;
INFO("afb service over dbus installed, name %s, path %s", api->name, api->path);
api->server.listener = afb_evt_listener_create(&evt_broadcast_itf, api);
+ api->server.apiset = afb_apiset_addref(apiset);
return 0;
error3:
sd_bus_release_name(api->sdbus, api->name);