summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-09-21 21:25:07 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-10-09 14:08:32 +0200
commit5928e8fc14c2edabc0bc104fff7542819e06d45a (patch)
tree5a03f7b05c6cfb4cf9f9b5c70415a547d841780d
parentae5d707f9348b50d44724ec2b091f4528ff0a72b (diff)
Deprecate internal use of afb_event
The deprecation is made in favor of afb_eventid but this can change later in favor of afb_evt_evtid. Change-Id: Ic16cb25dbd97cb1e8d26b3c54b159d46bbf82671 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-api-dbus.c34
-rw-r--r--src/afb-evt.c56
-rw-r--r--src/afb-evt.h21
-rw-r--r--src/afb-export.c8
-rw-r--r--src/afb-hook.c20
-rw-r--r--src/afb-hook.h14
-rw-r--r--src/afb-stub-ws.c26
-rw-r--r--src/afb-trace.c18
-rw-r--r--src/afb-xreq.c40
-rw-r--r--src/afb-xreq.h10
10 files changed, 139 insertions, 108 deletions
diff --git a/src/afb-api-dbus.c b/src/afb-api-dbus.c
index 33435a96..1aad8635 100644
--- a/src/afb-api-dbus.c
+++ b/src/afb-api-dbus.c
@@ -226,7 +226,7 @@ struct dbus_memo {
struct dbus_event
{
struct dbus_event *next;
- struct afb_event event;
+ struct afb_eventid *eventid;
int id;
int refcount;
};
@@ -376,19 +376,19 @@ static int api_dbus_client_on_broadcast_event(sd_bus_message *m, void *userdata,
return 1;
}
-/* search the event */
+/* search the eventid */
static struct dbus_event *api_dbus_client_event_search(struct api_dbus *api, int id, const char *name)
{
struct dbus_event *ev;
ev = api->client.events;
- while (ev != NULL && (ev->id != id || 0 != strcmp(afb_evt_event_fullname(ev->event), name)))
+ while (ev != NULL && (ev->id != id || 0 != strcmp(afb_evt_event_fullname(ev->eventid), name)))
ev = ev->next;
return ev;
}
-/* adds an event */
+/* adds an eventid */
static void api_dbus_client_event_create(struct api_dbus *api, int id, const char *name)
{
struct dbus_event *ev;
@@ -403,8 +403,8 @@ 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->event = afb_evt_create_event(name);
- if (ev->event.closure == NULL)
+ ev->eventid = afb_evt_create_event(name);
+ if (ev->eventid == NULL)
free(ev);
else {
ev->refcount = 1;
@@ -417,7 +417,7 @@ static void api_dbus_client_event_create(struct api_dbus *api, int id, const cha
ERROR("can't create event %s, out of memory", name);
}
-/* removes an event */
+/* removes an eventid */
static void api_dbus_client_event_drop(struct api_dbus *api, int id, const char *name)
{
struct dbus_event *ev, **prv;
@@ -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_event_unref(ev->event);
+ afb_evt_event_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_event_push(ev->event, object);
+ afb_evt_push(ev->eventid, object);
}
/* subscribes an event */
@@ -484,7 +484,7 @@ static void api_dbus_client_event_subscribe(struct api_dbus *api, int id, const
}
/* subscribe the request to the event */
- rc = afb_xreq_subscribe(memo->xreq, ev->event);
+ rc = afb_xreq_subscribe(memo->xreq, ev->eventid);
if (rc < 0)
ERROR("can't subscribe: %m");
}
@@ -511,7 +511,7 @@ static void api_dbus_client_event_unsubscribe(struct api_dbus *api, int id, cons
}
/* unsubscribe the request from the event */
- rc = afb_xreq_unsubscribe(memo->xreq, ev->event);
+ rc = afb_xreq_unsubscribe(memo->xreq, ev->eventid);
if (rc < 0)
ERROR("can't unsubscribe: %m");
}
@@ -842,27 +842,27 @@ static void dbus_req_fail(struct afb_xreq *xreq, const char *status, const char
static void afb_api_dbus_server_event_send(struct origin *origin, char order, const char *event, int eventid, const char *data, uint64_t msgid);
-static int dbus_req_subscribe(struct afb_xreq *xreq, struct afb_event event)
+static int dbus_req_subscribe(struct afb_xreq *xreq, struct afb_eventid *eventid)
{
struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
uint64_t msgid;
int rc;
- rc = afb_evt_add_watch(dreq->listener->listener, event);
+ rc = afb_evt_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(event), afb_evt_event_id(event), "", msgid);
+ afb_api_dbus_server_event_send(dreq->listener->origin, 'S', afb_evt_event_fullname(eventid), afb_evt_event_id(eventid), "", msgid);
return rc;
}
-static int dbus_req_unsubscribe(struct afb_xreq *xreq, struct afb_event event)
+static int dbus_req_unsubscribe(struct afb_xreq *xreq, struct afb_eventid *eventid)
{
struct dbus_req *dreq = CONTAINER_OF_XREQ(struct dbus_req, xreq);
uint64_t msgid;
int rc;
sd_bus_message_get_cookie(dreq->message, &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);
+ 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);
return rc;
}
diff --git a/src/afb-evt.c b/src/afb-evt.c
index aba5e9b6..e3a34202 100644
--- a/src/afb-evt.c
+++ b/src/afb-evt.c
@@ -1,6 +1,5 @@
/*
* Copyright (C) 2015, 2016, 2017 "IoT.bzh"
- * Author "Fulup Ar Foll"
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -635,50 +634,50 @@ void afb_evt_update_hooks()
pthread_mutex_unlock(&events_mutex);
}
-struct afb_evtid *afb_evt_to_evtid(struct afb_event event)
+inline struct afb_evtid *afb_evt_to_evtid(struct afb_eventid *eventid)
{
- return (struct afb_evtid*)(event.itf == &afb_evt_hooked_eventid_itf ? event.closure : NULL);
+ return (struct afb_evtid*)eventid;
}
-struct afb_event afb_evt_from_evtid(struct afb_evtid *evtid)
+inline struct afb_eventid *afb_evt_from_evtid(struct afb_evtid *evtid)
{
- return (struct afb_event){ .itf = evtid ? &afb_evt_hooked_eventid_itf : NULL, .closure = &evtid->eventid };
+ return &evtid->eventid;
}
/*
* Creates an event of 'fullname' and returns it.
* Returns an event with closure==NULL in case of error.
*/
-struct afb_event afb_evt_create_event(const char *fullname)
+struct afb_eventid *afb_evt_create_event(const char *fullname)
{
return afb_evt_from_evtid(afb_evt_evtid_create(fullname));
}
/*
- * Returns the fullname of the 'event'
+ * Returns the fullname of the 'eventid'
*/
-const char *afb_evt_event_fullname(struct afb_event event)
+const char *afb_evt_event_fullname(struct afb_eventid *eventid)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(event);
+ struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
return evtid ? evtid->fullname : NULL;
}
/*
- * Returns the id of the 'event'
+ * Returns the id of the 'eventid'
*/
-int afb_evt_event_id(struct afb_event event)
+int afb_evt_event_id(struct afb_eventid *eventid)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(event);
+ struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
return evtid ? evtid->id : 0;
}
/*
- * Makes the 'listener' watching 'event'
+ * Makes the 'listener' watching 'eventid'
* Returns 0 in case of success or else -1.
*/
-int afb_evt_add_watch(struct afb_evt_listener *listener, struct afb_event event)
+int afb_evt_add_watch(struct afb_evt_listener *listener, struct afb_eventid *eventid)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(event);
+ struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
/* check parameter */
if (!evtid) {
@@ -691,12 +690,12 @@ int afb_evt_add_watch(struct afb_evt_listener *listener, struct afb_event event)
}
/*
- * Avoids the 'listener' to watch 'event'
+ * Avoids the 'listener' to watch 'eventid'
* Returns 0 in case of success or else -1.
*/
-int afb_evt_remove_watch(struct afb_evt_listener *listener, struct afb_event event)
+int afb_evt_remove_watch(struct afb_evt_listener *listener, struct afb_eventid *eventid)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(event);
+ struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
/* check parameter */
if (!evtid) {
@@ -708,21 +707,34 @@ int afb_evt_remove_watch(struct afb_evt_listener *listener, struct afb_event eve
return afb_evt_watch_sub_evtid(listener, evtid);
}
-int afb_evt_push(struct afb_event event, struct json_object *object)
+int afb_evt_push(struct afb_eventid *eventid, struct json_object *object)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(event);
+ struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
if (evtid)
return afb_evt_evtid_hooked_push(evtid, object);
json_object_put(object);
return 0;
}
-int afb_evt_unhooked_push(struct afb_event event, struct json_object *object)
+int afb_evt_unhooked_push(struct afb_eventid *eventid, struct json_object *object)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(event);
+ struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
if (evtid)
return afb_evt_evtid_push(evtid, object);
json_object_put(object);
return 0;
}
+struct afb_event afb_event_from_evtid(struct afb_evtid *evtid)
+{
+ return evtid
+ ? (struct afb_event){ .itf = &afb_evt_hooked_eventid_itf, .closure = &evtid->eventid }
+ : (struct afb_event){ .itf = NULL, .closure = NULL };
+}
+
+void afb_evt_event_unref(struct afb_eventid *eventid)
+{
+ struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
+ if (evtid)
+ afb_evt_evtid_unref(evtid);
+}
diff --git a/src/afb-evt.h b/src/afb-evt.h
index 823f8fd0..ea083299 100644
--- a/src/afb-evt.h
+++ b/src/afb-evt.h
@@ -64,15 +64,18 @@ extern int afb_evt_watch_sub_evtid(struct afb_evt_listener *listener, struct afb
extern void afb_evt_update_hooks();
-extern struct afb_event afb_evt_create_event(const char *fullname);
-extern const char *afb_evt_event_fullname(struct afb_event event);
-extern int afb_evt_event_id(struct afb_event event);
+extern struct afb_eventid *afb_evt_create_event(const char *fullname);
+extern const char *afb_evt_event_fullname(struct afb_eventid *eventid);
+extern int afb_evt_event_id(struct afb_eventid *eventid);
+extern void afb_evt_event_unref(struct afb_eventid *eventid);
-extern int afb_evt_push(struct afb_event event, struct json_object *object);
-extern int afb_evt_unhooked_push(struct afb_event event, struct json_object *object);
+extern int afb_evt_push(struct afb_eventid *eventid, struct json_object *object);
+extern int afb_evt_unhooked_push(struct afb_eventid *eventid, struct json_object *object);
-extern int afb_evt_add_watch(struct afb_evt_listener *listener, struct afb_event event);
-extern int afb_evt_remove_watch(struct afb_evt_listener *listener, struct afb_event event);
+extern int afb_evt_add_watch(struct afb_evt_listener *listener, struct afb_eventid *eventid);
+extern int afb_evt_remove_watch(struct afb_evt_listener *listener, struct afb_eventid *eventid);
+
+extern struct afb_evtid *afb_evt_to_evtid(struct afb_eventid *eventid);
+extern struct afb_eventid *afb_evt_from_evtid(struct afb_evtid *evtid);
+extern struct afb_event afb_event_from_evtid(struct afb_evtid *evtid);
-extern struct afb_evtid *afb_evt_to_evtid(struct afb_event event);
-extern struct afb_event afb_evt_from_evtid(struct afb_evtid *evtid);
diff --git a/src/afb-export.c b/src/afb-export.c
index 90507b64..fb9bb747 100644
--- a/src/afb-export.c
+++ b/src/afb-export.c
@@ -137,6 +137,7 @@ static struct afb_event event_make_cb(void *closure, const char *name)
size_t plen, nlen;
char *event;
struct afb_export *export = closure;
+ struct afb_eventid *eventid;
/* check daemon state */
if (export->state == Api_State_Pre_Init) {
@@ -154,7 +155,8 @@ static struct afb_event event_make_cb(void *closure, const char *name)
memcpy(event + plen + 1, name, nlen + 1);
/* create the event */
- return afb_evt_create_event(event);
+ eventid = afb_evt_create_event(event);
+ return (struct afb_event){ .itf = eventid ? eventid->itf : NULL, .closure = eventid };
}
static int event_broadcast_cb(void *closure, const char *name, struct json_object *object)
@@ -248,7 +250,8 @@ static struct afb_event hooked_event_make_cb(void *closure, const char *name)
{
struct afb_export *export = closure;
struct afb_event r = event_make_cb(closure, name);
- return afb_hook_ditf_event_make(export, name, r);
+ afb_hook_ditf_event_make(export, name, r.closure);
+ return r;
}
static int hooked_event_broadcast_cb(void *closure, const char *name, struct json_object *object)
@@ -743,6 +746,7 @@ struct afb_export *afb_export_create_v2(struct afb_apiset *apiset, const char *a
export->init.v2 = init;
export->on_event.v12 = onevent;
export->export.v2 = data;
+ data->verbosity = verbosity;
data->daemon.closure = export;
data->service.closure = export;
afb_export_update_hook(export);
diff --git a/src/afb-hook.c b/src/afb-hook.c
index 12cf7a12..38ecfdcc 100644
--- a/src/afb-hook.c
+++ b/src/afb-hook.c
@@ -281,14 +281,14 @@ static void hook_xreq_session_set_LOA_default_cb(void *closure, const struct afb
_hook_xreq_(xreq, "session_set_LOA(%u) -> %d", level, result);
}
-static void hook_xreq_subscribe_default_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_event event, int result)
+static void hook_xreq_subscribe_default_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_eventid *eventid, int result)
{
- _hook_xreq_(xreq, "subscribe(%s:%d) -> %d", afb_evt_event_fullname(event), afb_evt_event_id(event), result);
+ _hook_xreq_(xreq, "subscribe(%s:%d) -> %d", afb_evt_event_fullname(eventid), afb_evt_event_id(eventid), result);
}
-static void hook_xreq_unsubscribe_default_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_event event, int result)
+static void hook_xreq_unsubscribe_default_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_eventid *eventid, int result)
{
- _hook_xreq_(xreq, "unsubscribe(%s:%d) -> %d", afb_evt_event_fullname(event), afb_evt_event_id(event), result);
+ _hook_xreq_(xreq, "unsubscribe(%s:%d) -> %d", afb_evt_event_fullname(eventid), afb_evt_event_id(eventid), result);
}
static void hook_xreq_subcall_default_cb(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args)
@@ -480,15 +480,15 @@ int afb_hook_xreq_session_set_LOA(const struct afb_xreq *xreq, unsigned level, i
return result;
}
-int afb_hook_xreq_subscribe(const struct afb_xreq *xreq, struct afb_event event, int result)
+int afb_hook_xreq_subscribe(const struct afb_xreq *xreq, struct afb_eventid *eventid, int result)
{
- _HOOK_XREQ_(subscribe, xreq, event, result);
+ _HOOK_XREQ_(subscribe, xreq, eventid, result);
return result;
}
-int afb_hook_xreq_unsubscribe(const struct afb_xreq *xreq, struct afb_event event, int result)
+int afb_hook_xreq_unsubscribe(const struct afb_xreq *xreq, struct afb_eventid *eventid, int result)
{
- _HOOK_XREQ_(unsubscribe, xreq, event, result);
+ _HOOK_XREQ_(unsubscribe, xreq, eventid, result);
return result;
}
@@ -724,7 +724,7 @@ static void hook_ditf_vverbose_cb(void *closure, const struct afb_hookid *hookid
}
}
-static void hook_ditf_event_make_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct afb_event result)
+static void hook_ditf_event_make_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct afb_eventid *result)
{
_hook_ditf_(export, "event_make(%s) -> %s:%d", name, afb_evt_event_fullname(result), afb_evt_event_id(result));
}
@@ -852,7 +852,7 @@ void afb_hook_ditf_vverbose(const struct afb_export *export, int level, const ch
_HOOK_DITF_(vverbose, export, level, file, line, function, fmt, args);
}
-struct afb_event afb_hook_ditf_event_make(const struct afb_export *export, const char *name, struct afb_event result)
+struct afb_eventid *afb_hook_ditf_event_make(const struct afb_export *export, const char *name, struct afb_eventid *result)
{
_HOOK_DITF_(event_make, export, name, result);
return result;
diff --git a/src/afb-hook.h b/src/afb-hook.h
index 57e88dc3..b7fd88d8 100644
--- a/src/afb-hook.h
+++ b/src/afb-hook.h
@@ -24,7 +24,7 @@ struct req;
struct afb_context;
struct json_object;
struct afb_arg;
-struct afb_event;
+struct afb_eventid;
struct afb_session;
struct afb_xreq;
struct afb_export;
@@ -116,8 +116,8 @@ struct afb_hook_xreq_itf {
void (*hook_xreq_unref)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq);
void (*hook_xreq_session_close)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq);
void (*hook_xreq_session_set_LOA)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, unsigned level, int result);
- void (*hook_xreq_subscribe)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_event event, int result);
- void (*hook_xreq_unsubscribe)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_event event, int result);
+ void (*hook_xreq_subscribe)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_eventid *eventid, int result);
+ void (*hook_xreq_unsubscribe)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_eventid *eventid, int result);
void (*hook_xreq_subcall)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
void (*hook_xreq_subcall_result)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, int status, struct json_object *result);
void (*hook_xreq_subcallsync)(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
@@ -151,8 +151,8 @@ extern void afb_hook_xreq_addref(const struct afb_xreq *xreq);
extern void afb_hook_xreq_unref(const struct afb_xreq *xreq);
extern void afb_hook_xreq_session_close(const struct afb_xreq *xreq);
extern int afb_hook_xreq_session_set_LOA(const struct afb_xreq *xreq, unsigned level, int result);
-extern int afb_hook_xreq_subscribe(const struct afb_xreq *xreq, struct afb_event event, int result);
-extern int afb_hook_xreq_unsubscribe(const struct afb_xreq *xreq, struct afb_event event, int result);
+extern int afb_hook_xreq_subscribe(const struct afb_xreq *xreq, struct afb_eventid *eventid, int result);
+extern int afb_hook_xreq_unsubscribe(const struct afb_xreq *xreq, struct afb_eventid *eventid, int result);
extern void afb_hook_xreq_subcall(const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
extern void afb_hook_xreq_subcall_result(const struct afb_xreq *xreq, int status, struct json_object *result);
extern void afb_hook_xreq_subcallsync(const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
@@ -209,7 +209,7 @@ struct afb_hook_ditf_itf {
void (*hook_ditf_get_user_bus)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct sd_bus *result);
void (*hook_ditf_get_system_bus)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, struct sd_bus *result);
void (*hook_ditf_vverbose)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int level, const char *file, int line, const char *function, const char *fmt, va_list args);
- void (*hook_ditf_event_make)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct afb_event result);
+ void (*hook_ditf_event_make)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct afb_eventid *result);
void (*hook_ditf_rootdir_get_fd)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result);
void (*hook_ditf_rootdir_open_locale)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *filename, int flags, const char *locale, int result);
void (*hook_ditf_queue_job)(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result);
@@ -225,7 +225,7 @@ extern struct sd_event *afb_hook_ditf_get_event_loop(const struct afb_export *ex
extern struct sd_bus *afb_hook_ditf_get_user_bus(const struct afb_export *export, struct sd_bus *result);
extern struct sd_bus *afb_hook_ditf_get_system_bus(const struct afb_export *export, struct sd_bus *result);
extern void afb_hook_ditf_vverbose(const struct afb_export *export, int level, const char *file, int line, const char *function, const char *fmt, va_list args);
-extern struct afb_event afb_hook_ditf_event_make(const struct afb_export *export, const char *name, struct afb_event result);
+extern struct afb_eventid *afb_hook_ditf_event_make(const struct afb_export *export, const char *name, struct afb_eventid *result);
extern int afb_hook_ditf_rootdir_get_fd(const struct afb_export *export, int result);
extern int afb_hook_ditf_rootdir_open_locale(const struct afb_export *export, const char *filename, int flags, const char *locale, int result);
extern int afb_hook_ditf_queue_job(const struct afb_export *export, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result);
diff --git a/src/afb-stub-ws.c b/src/afb-stub-ws.c
index e7c8997e..625cea38 100644
--- a/src/afb-stub-ws.c
+++ b/src/afb-stub-ws.c
@@ -102,8 +102,8 @@ struct server_req {
struct client_event
{
struct client_event *next;
- struct afb_event event;
- int eventid;
+ struct afb_eventid *eventid;
+ int id;
int refcount;
};
@@ -204,7 +204,7 @@ static void server_req_subcall_cb(struct afb_xreq *xreq, const char *api, const
ERROR("error while sending subcall");
}
-static int server_req_subscribe_cb(struct afb_xreq *xreq, struct afb_event event)
+static int server_req_subscribe_cb(struct afb_xreq *xreq, struct afb_eventid *event)
{
int rc;
struct server_req *wreq = CONTAINER_OF_XREQ(struct server_req, xreq);
@@ -217,7 +217,7 @@ static int server_req_subscribe_cb(struct afb_xreq *xreq, struct afb_event event
return rc;
}
-static int server_req_unsubscribe_cb(struct afb_xreq *xreq, struct afb_event event)
+static int server_req_unsubscribe_cb(struct afb_xreq *xreq, struct afb_eventid *event)
{
int rc, rc2;
struct server_req *wreq = CONTAINER_OF_XREQ(struct server_req, xreq);
@@ -248,7 +248,7 @@ static struct client_event *client_event_search(struct afb_stub_ws *stubws, uint
struct client_event *ev;
ev = stubws->events;
- while (ev != NULL && (ev->eventid != eventid || 0 != strcmp(afb_evt_event_fullname(ev->event), name)))
+ while (ev != NULL && (ev->id != eventid || 0 != strcmp(afb_evt_event_fullname(ev->eventid), name)))
ev = ev->next;
return ev;
@@ -360,10 +360,10 @@ static void on_event_create(void *closure, const char *event_name, int event_id)
/* no conflict, try to add it */
ev = malloc(sizeof *ev);
if (ev != NULL) {
- ev->event = afb_evt_create_event(event_name);
- if (ev->event.closure != NULL) {
+ ev->eventid = afb_evt_create_event(event_name);
+ if (ev->eventid != NULL) {
ev->refcount = 1;
- ev->eventid = event_id;
+ ev->id = event_id;
ev->next = stubws->events;
stubws->events = ev;
return;
@@ -394,7 +394,7 @@ static void on_event_remove(void *closure, const char *event_name, int event_id)
*prv = ev->next;
/* destroys the event */
- afb_event_unref(ev->event);
+ afb_evt_event_unref(ev->eventid);
free(ev);
}
@@ -409,7 +409,7 @@ static void on_event_subscribe(void *closure, void *request, const char *event_n
if (ev == NULL)
return;
- if (afb_xreq_subscribe(xreq, ev->event) < 0)
+ if (afb_xreq_subscribe(xreq, ev->eventid) < 0)
ERROR("can't subscribe: %m");
}
@@ -424,7 +424,7 @@ static void on_event_unsubscribe(void *closure, void *request, const char *event
if (ev == NULL)
return;
- if (afb_xreq_unsubscribe(xreq, ev->event) < 0)
+ if (afb_xreq_unsubscribe(xreq, ev->eventid) < 0)
ERROR("can't unsubscribe: %m");
}
@@ -436,7 +436,7 @@ static void on_event_push(void *closure, const char *event_name, int event_id, s
/* check conflicts */
ev = client_event_search(stubws, event_id, event_name);
if (ev)
- afb_event_push(ev->event, data);
+ afb_evt_push(ev->eventid, data);
else
ERROR("unreadable push event");
}
@@ -585,7 +585,7 @@ static void drop_all_events(struct afb_stub_ws *stubws)
while (ev) {
nxt = ev->next;
- afb_event_unref(ev->event);
+ afb_evt_event_unref(ev->eventid);
free(ev);
ev = nxt;
}
diff --git a/src/afb-trace.c b/src/afb-trace.c
index 4d8a4f73..2c2bb52b 100644
--- a/src/afb-trace.c
+++ b/src/afb-trace.c
@@ -361,21 +361,21 @@ static void hook_xreq_session_set_LOA(void *closure, const struct afb_hookid *ho
"result", result);
}
-static void hook_xreq_subscribe(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_event event, int result)
+static void hook_xreq_subscribe(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_eventid *eventid, int result)
{
hook_xreq(closure, hookid, xreq, "subscribe", "{s{ss si} si}",
"event",
- "name", afb_evt_event_fullname(event),
- "id", afb_evt_event_id(event),
+ "name", afb_evt_event_fullname(eventid),
+ "id", afb_evt_event_id(eventid),
"result", result);
}
-static void hook_xreq_unsubscribe(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_event event, int result)
+static void hook_xreq_unsubscribe(void *closure, const struct afb_hookid *hookid, const struct afb_xreq *xreq, struct afb_eventid *eventid, int result)
{
hook_xreq(closure, hookid, xreq, "unsubscribe", "{s{ss? si} si}",
"event",
- "name", afb_evt_event_fullname(event),
- "id", afb_evt_event_id(event),
+ "name", afb_evt_event_fullname(eventid),
+ "id", afb_evt_event_id(eventid),
"result", result);
}
@@ -611,7 +611,7 @@ static void hook_ditf_vverbose(void *closure, const struct afb_hookid *hookid, c
free(msg);
}
-static void hook_ditf_event_make(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct afb_event result)
+static void hook_ditf_event_make(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, const char *name, struct afb_eventid *result)
{
hook_ditf(closure, hookid, export, "event_make", "{ss ss si}",
"name", name, "event", afb_evt_event_fullname(result), "id", afb_evt_event_id(result));
@@ -1098,7 +1098,7 @@ static struct event *trace_get_event(struct afb_trace *trace, const char *name,
if (!event && alloc) {
event = malloc(sizeof * event);
if (event) {
- event->evtid = afb_evt_to_evtid(trace->daemon->itf->event_make(trace->daemon->closure, name));
+ event->evtid = afb_evt_to_evtid(trace->daemon->itf->event_make(trace->daemon->closure, name).closure);
if (event->evtid) {
event->next = trace->events;
trace->events = event;
@@ -1264,7 +1264,7 @@ static void addhook(struct desc *desc, enum trace_type type)
}
/* attach and activate the hook */
- afb_req_subscribe(desc->context->req, afb_evt_from_evtid(hook->event->evtid));
+ afb_req_subscribe(desc->context->req, afb_event_from_evtid(hook->event->evtid));
trace_attach_hook(trace, hook, type);
}
diff --git a/src/afb-xreq.c b/src/afb-xreq.c
index 8a050705..8ff45c4e 100644
--- a/src/afb-xreq.c
+++ b/src/afb-xreq.c
@@ -104,18 +104,18 @@ struct subcall
};
};
-static int subcall_subscribe_cb(struct afb_xreq *xreq, struct afb_event event)
+static int subcall_subscribe_cb(struct afb_xreq *xreq, struct afb_eventid *eventid)
{
struct subcall *subcall = CONTAINER_OF_XREQ(struct subcall, xreq);
- return afb_xreq_subscribe(subcall->xreq.caller, event);
+ return afb_xreq_subscribe(subcall->xreq.caller, eventid);
}
-static int subcall_unsubscribe_cb(struct afb_xreq *xreq, struct afb_event event)
+static int subcall_unsubscribe_cb(struct afb_xreq *xreq, struct afb_eventid *eventid)
{
struct subcall *subcall = CONTAINER_OF_XREQ(struct subcall, xreq);
- return afb_xreq_unsubscribe(subcall->xreq.caller, event);
+ return afb_xreq_unsubscribe(subcall->xreq.caller, eventid);
}
static void subcall_reply_cb(struct afb_xreq *xreq, int status, struct json_object *result)
@@ -420,35 +420,47 @@ static int xreq_session_set_LOA_cb(struct afb_request *closure, unsigned level)
return afb_context_change_loa(&xreq->context, level);
}
+static int xreq_subscribe_eventid_cb(struct afb_request *closure, struct afb_eventid *eventid);
static int xreq_subscribe_cb(struct afb_request *closure, struct afb_event event)
{
+ return xreq_subscribe_eventid_cb(closure, event.closure);
+}
+
+static int xreq_subscribe_eventid_cb(struct afb_request *closure, struct afb_eventid *eventid)
+{
struct afb_xreq *xreq = from_request(closure);
- return afb_xreq_subscribe(xreq, event);
+ return afb_xreq_subscribe(xreq, eventid);
}
-int afb_xreq_subscribe(struct afb_xreq *xreq, struct afb_event event)
+int afb_xreq_subscribe(struct afb_xreq *xreq, struct afb_eventid *eventid)
{
if (xreq->listener)
- return afb_evt_add_watch(xreq->listener, event);
+ return afb_evt_add_watch(xreq->listener, eventid);
if (xreq->queryitf->subscribe)
- return xreq->queryitf->subscribe(xreq, event);
+ return xreq->queryitf->subscribe(xreq, eventid);
ERROR("no event listener, subscription impossible");
errno = EINVAL;
return -1;
}
+static int xreq_unsubscribe_eventid_cb(struct afb_request *closure, struct afb_eventid *eventid);
static int xreq_unsubscribe_cb(struct afb_request *closure, struct afb_event event)
{
+ return xreq_unsubscribe_eventid_cb(closure, event.closure);
+}
+
+static int xreq_unsubscribe_eventid_cb(struct afb_request *closure, struct afb_eventid *eventid)
+{
struct afb_xreq *xreq = from_request(closure);
- return afb_xreq_unsubscribe(xreq, event);
+ return afb_xreq_unsubscribe(xreq, eventid);
}
-int afb_xreq_unsubscribe(struct afb_xreq *xreq, struct afb_event event)
+int afb_xreq_unsubscribe(struct afb_xreq *xreq, struct afb_eventid *eventid)
{
if (xreq->listener)
- return afb_evt_remove_watch(xreq->listener, event);
+ return afb_evt_remove_watch(xreq->listener, eventid);
if (xreq->queryitf->unsubscribe)
- return xreq->queryitf->unsubscribe(xreq, event);
+ return xreq->queryitf->unsubscribe(xreq, eventid);
ERROR("no event listener, unsubscription impossible");
errno = EINVAL;
return -1;
@@ -630,14 +642,14 @@ static int xreq_hooked_subscribe_cb(struct afb_request *closure, struct afb_even
{
int r = xreq_subscribe_cb(closure, event);
struct afb_xreq *xreq = from_request(closure);
- return afb_hook_xreq_subscribe(xreq, event, r);
+ return afb_hook_xreq_subscribe(xreq, event.closure, r);
}
static int xreq_hooked_unsubscribe_cb(struct afb_request *closure, struct afb_event event)
{
int r = xreq_unsubscribe_cb(closure, event);
struct afb_xreq *xreq = from_request(closure);
- return afb_hook_xreq_unsubscribe(xreq, event, r);
+ return afb_hook_xreq_unsubscribe(xreq, event.closure, r);
}
static void xreq_hooked_subcall_cb(struct afb_request *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure)
diff --git a/src/afb-xreq.h b/src/afb-xreq.h
index df868bf6..497b1635 100644
--- a/src/afb-xreq.h
+++ b/src/afb-xreq.h
@@ -25,7 +25,7 @@ struct afb_evt_listener;
struct afb_xreq;
struct afb_cred;
struct afb_apiset;
-struct afb_event;
+struct afb_eventid;
struct afb_verb_desc_v1;
struct afb_verb_v2;
struct afb_req;
@@ -40,8 +40,8 @@ struct afb_xreq_query_itf {
void (*fail)(struct afb_xreq *xreq, const char *status, const char *info);
void (*reply)(struct afb_xreq *xreq, int status, struct json_object *obj);
void (*unref)(struct afb_xreq *xreq);
- int (*subscribe)(struct afb_xreq *xreq, struct afb_event event);
- int (*unsubscribe)(struct afb_xreq *xreq, struct afb_event event);
+ int (*subscribe)(struct afb_xreq *xreq, struct afb_eventid *eventid);
+ int (*unsubscribe)(struct afb_xreq *xreq, struct afb_eventid *eventid);
void (*subcall)(
struct afb_xreq *xreq,
const char *api,
@@ -110,8 +110,8 @@ extern void afb_xreq_fail_unknown_verb(struct afb_xreq *xreq);
extern const char *afb_xreq_raw(struct afb_xreq *xreq, size_t *size);
-extern int afb_xreq_subscribe(struct afb_xreq *xreq, struct afb_event event);
-extern int afb_xreq_unsubscribe(struct afb_xreq *xreq, struct afb_event event);
+extern int afb_xreq_subscribe(struct afb_xreq *xreq, struct afb_eventid *eventid);
+extern int afb_xreq_unsubscribe(struct afb_xreq *xreq, struct afb_eventid *eventid);
extern void afb_xreq_subcall(
struct afb_xreq *xreq,