aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-api-dbus.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-06-09 07:54:31 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-06-09 08:39:02 +0200
commit7e0abe76db7b90369429bf387d7aad0fb5a42328 (patch)
treeeedf5609a588f0d9d743fb941bc8727ff1356b21 /src/afb-api-dbus.c
parentc37c8e6291c36665dd23601a8ce1449afd43e6df (diff)
Events: refactoring
This new version allows to subscribe a client for an event. The event should first be created for the API (the API's prefix is added) using 'afb_daemon_make_event'. After that, plugins can subscribe or unsubscribe their clients (identified through requests) to the events that it generates. See 'afb_req_subscribe' and 'afb_req_unsubscribe'. Events created by 'afb_daemon_make_event' can be widely broadcasted using 'afb_event_broadcast' or pushed only to suscribers using 'afb_event_push'. Events can be destroyed using 'afb_event_drop'. Change-Id: I7c0bed5e625c2052dcd81c6bfe960def1fa032f3 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-api-dbus.c')
-rw-r--r--src/afb-api-dbus.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/afb-api-dbus.c b/src/afb-api-dbus.c
index c0bc57a8..eda7985f 100644
--- a/src/afb-api-dbus.c
+++ b/src/afb-api-dbus.c
@@ -35,6 +35,7 @@
#include "afb-apis.h"
#include "afb-api-so.h"
#include "afb-context.h"
+#include "afb-evt.h"
#include "verbose.h"
static const char DEFAULT_PATH_PREFIX[] = "/org/agl/afb/api/";
@@ -52,6 +53,7 @@ struct api_dbus
char *path; /* path of the object for the API */
char *name; /* name/interface of the object */
char *api; /* api name of the interface */
+ struct afb_evt_listener *listener;
};
#define RETOK 1
@@ -302,7 +304,7 @@ static int api_dbus_client_on_event(sd_bus_message *m, void *userdata, sd_bus_er
ERROR("unreadable event");
else {
object = json_tokener_parse(data);
- ctxClientEventSend(NULL, event, object);
+ afb_evt_broadcast(event, object);
json_object_put(object);
}
return 1;
@@ -444,7 +446,7 @@ static void dbus_req_send(struct dbus_req *dreq, const char *buffer, size_t size
dbus_req_reply(dreq, RETRAW, buffer, "");
}
-struct afb_req_itf dbus_req_itf = {
+const struct afb_req_itf afb_api_dbus_req_itf = {
.json = (void*)dbus_req_json,
.get = (void*)dbus_req_get,
.success = (void*)dbus_req_success,
@@ -504,7 +506,7 @@ static int api_dbus_server_on_object_called(sd_bus_message *message, void *userd
dreq->message = sd_bus_message_ref(message);
dreq->json = NULL;
dreq->refcount = 1;
- areq.itf = &dbus_req_itf;
+ areq.itf = &afb_api_dbus_req_itf;
areq.closure = dreq;
afb_apis_call_(areq, &dreq->context, api->api, method);
dbus_req_unref(dreq);
@@ -522,19 +524,6 @@ static void afb_api_dbus_server_send_event(struct api_dbus *api, const char *eve
json_object_put(object);
}
-static int afb_api_dbus_server_expects_event(struct api_dbus *api, const char *event)
-{
- size_t len = strlen(api->api);
- if (strncasecmp(event, api->api, len) != 0)
- return 0;
- return event[len] == '.';
-}
-
-static struct afb_event_listener_itf evitf = {
- .send = (void*)afb_api_dbus_server_send_event,
- .expects = (void*)afb_api_dbus_server_expects_event
-};
-
/* create the service */
int afb_api_dbus_add_server(const char *path)
{
@@ -563,7 +552,7 @@ int afb_api_dbus_add_server(const char *path)
}
INFO("afb service over dbus installed, name %s, path %s", api->name, api->path);
- ctxClientEventListenerAdd(NULL, (struct afb_event_listener){ .itf = &evitf, .closure = api });
+ api->listener = afb_evt_listener_create((void*)afb_api_dbus_server_send_event, api);
return 0;
error3: