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;
/* 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 {
*prv = ev->next;
/* destroys the event */
- afb_evt_event_unref(ev->eventid);
+ afb_evt_eventid_unref(ev->eventid);
free(ev);
}
/* destroys the event */
object = json_tokener_parse(data);
- afb_evt_push(ev->eventid, object);
+ afb_evt_eventid_push(ev->eventid, object);
}
/* subscribes an event */
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;
}
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;
}
pthread_mutex_unlock(&events_mutex);
}
-inline struct afb_evtid *afb_evt_to_evtid(struct afb_eventid *eventid)
+inline struct afb_evtid *afb_evt_eventid_to_evtid(struct afb_eventid *eventid)
{
return (struct afb_evtid*)eventid;
}
-inline struct afb_eventid *afb_evt_from_evtid(struct afb_evtid *evtid)
+inline struct afb_eventid *afb_evt_eventid_from_evtid(struct afb_evtid *evtid)
{
return &evtid->eventid;
}
* Creates an event of 'fullname' and returns it.
* Returns an event with closure==NULL in case of error.
*/
-struct afb_eventid *afb_evt_create_event(const char *fullname)
+struct afb_eventid *afb_evt_eventid_create(const char *fullname)
{
- return afb_evt_from_evtid(afb_evt_evtid_create(fullname));
+ return afb_evt_eventid_from_evtid(afb_evt_evtid_create(fullname));
}
/*
* Returns the fullname of the 'eventid'
*/
-const char *afb_evt_event_fullname(struct afb_eventid *eventid)
+const char *afb_evt_eventid_fullname(struct afb_eventid *eventid)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
+ struct afb_evtid *evtid = afb_evt_eventid_to_evtid(eventid);
return evtid ? evtid->fullname : NULL;
}
/*
* Returns the id of the 'eventid'
*/
-int afb_evt_event_id(struct afb_eventid *eventid)
+int afb_evt_eventid_id(struct afb_eventid *eventid)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
+ struct afb_evtid *evtid = afb_evt_eventid_to_evtid(eventid);
return evtid ? evtid->id : 0;
}
* 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_eventid *eventid)
+int afb_evt_eventid_add_watch(struct afb_evt_listener *listener, struct afb_eventid *eventid)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
+ struct afb_evtid *evtid = afb_evt_eventid_to_evtid(eventid);
/* check parameter */
if (!evtid) {
* 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_eventid *eventid)
+int afb_evt_eventid_remove_watch(struct afb_evt_listener *listener, struct afb_eventid *eventid)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
+ struct afb_evtid *evtid = afb_evt_eventid_to_evtid(eventid);
/* check parameter */
if (!evtid) {
return afb_evt_watch_sub_evtid(listener, evtid);
}
-int afb_evt_push(struct afb_eventid *eventid, struct json_object *object)
+int afb_evt_eventid_push(struct afb_eventid *eventid, struct json_object *object)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
+ struct afb_evtid *evtid = afb_evt_eventid_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_eventid *eventid, struct json_object *object)
+int afb_evt_eventid_unhooked_push(struct afb_eventid *eventid, struct json_object *object)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
+ struct afb_evtid *evtid = afb_evt_eventid_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)
+struct afb_event afb_evt_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)
+void afb_evt_eventid_unref(struct afb_eventid *eventid)
{
- struct afb_evtid *evtid = afb_evt_to_evtid(eventid);
+ struct afb_evtid *evtid = afb_evt_eventid_to_evtid(eventid);
if (evtid)
afb_evt_evtid_unref(evtid);
}
extern void afb_evt_update_hooks();
-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 struct afb_eventid *afb_evt_eventid_create(const char *fullname);
+extern const char *afb_evt_eventid_fullname(struct afb_eventid *eventid);
+extern int afb_evt_eventid_id(struct afb_eventid *eventid);
+extern void afb_evt_eventid_unref(struct afb_eventid *eventid);
-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_eventid_push(struct afb_eventid *eventid, struct json_object *object);
+extern int afb_evt_eventid_unhooked_push(struct afb_eventid *eventid, struct json_object *object);
-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 int afb_evt_eventid_add_watch(struct afb_evt_listener *listener, struct afb_eventid *eventid);
+extern int afb_evt_eventid_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_eventid_to_evtid(struct afb_eventid *eventid);
+extern struct afb_eventid *afb_evt_eventid_from_evtid(struct afb_evtid *evtid);
+extern struct afb_event afb_evt_event_from_evtid(struct afb_evtid *evtid);
memcpy(event + plen + 1, name, nlen + 1);
/* create the event */
- return afb_evt_create_event(event);
+ return afb_evt_eventid_create(event);
}
static struct afb_event event_make_cb(void *closure, const char *name)
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(eventid), afb_evt_event_id(eventid), result);
+ _hook_xreq_(xreq, "subscribe(%s:%d) -> %d", afb_evt_eventid_fullname(eventid), afb_evt_eventid_id(eventid), 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(eventid), afb_evt_event_id(eventid), result);
+ _hook_xreq_(xreq, "unsubscribe(%s:%d) -> %d", afb_evt_eventid_fullname(eventid), afb_evt_eventid_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)
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));
+ _hook_ditf_(export, "event_make(%s) -> %s:%d", name, afb_evt_eventid_fullname(result), afb_evt_eventid_id(result));
}
static void hook_ditf_rootdir_get_fd_cb(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result)
int rc;
struct server_req *wreq = CONTAINER_OF_XREQ(struct server_req, xreq);
- rc = afb_evt_add_watch(wreq->stubws->listener, event);
+ rc = afb_evt_eventid_add_watch(wreq->stubws->listener, event);
if (rc >= 0)
- rc = afb_proto_ws_call_subscribe(wreq->call, afb_evt_event_fullname(event), afb_evt_event_id(event));
+ rc = afb_proto_ws_call_subscribe(wreq->call, afb_evt_eventid_fullname(event), afb_evt_eventid_id(event));
if (rc < 0)
ERROR("error while subscribing event");
return rc;
int rc, rc2;
struct server_req *wreq = CONTAINER_OF_XREQ(struct server_req, xreq);
- rc = afb_proto_ws_call_unsubscribe(wreq->call, afb_evt_event_fullname(event), afb_evt_event_id(event));
- rc2 = afb_evt_remove_watch(wreq->stubws->listener, event);
+ rc = afb_proto_ws_call_unsubscribe(wreq->call, afb_evt_eventid_fullname(event), afb_evt_eventid_id(event));
+ rc2 = afb_evt_eventid_remove_watch(wreq->stubws->listener, event);
if (rc >= 0 && rc2 < 0)
rc = rc2;
if (rc < 0)
struct client_event *ev;
ev = stubws->events;
- while (ev != NULL && (ev->id != eventid || 0 != strcmp(afb_evt_event_fullname(ev->eventid), name)))
+ while (ev != NULL && (ev->id != eventid || 0 != strcmp(afb_evt_eventid_fullname(ev->eventid), name)))
ev = ev->next;
return ev;
/* no conflict, try to add it */
ev = malloc(sizeof *ev);
if (ev != NULL) {
- ev->eventid = afb_evt_create_event(event_name);
+ ev->eventid = afb_evt_eventid_create(event_name);
if (ev->eventid != NULL) {
ev->refcount = 1;
ev->id = event_id;
*prv = ev->next;
/* destroys the event */
- afb_evt_event_unref(ev->eventid);
+ afb_evt_eventid_unref(ev->eventid);
free(ev);
}
/* check conflicts */
ev = client_event_search(stubws, event_id, event_name);
if (ev)
- afb_evt_push(ev->eventid, data);
+ afb_evt_eventid_push(ev->eventid, data);
else
ERROR("unreadable push event");
}
while (ev) {
nxt = ev->next;
- afb_evt_event_unref(ev->eventid);
+ afb_evt_eventid_unref(ev->eventid);
free(ev);
ev = nxt;
}
{
hook_xreq(closure, hookid, xreq, "subscribe", "{s{ss si} si}",
"event",
- "name", afb_evt_event_fullname(eventid),
- "id", afb_evt_event_id(eventid),
+ "name", afb_evt_eventid_fullname(eventid),
+ "id", afb_evt_eventid_id(eventid),
"result", result);
}
{
hook_xreq(closure, hookid, xreq, "unsubscribe", "{s{ss? si} si}",
"event",
- "name", afb_evt_event_fullname(eventid),
- "id", afb_evt_event_id(eventid),
+ "name", afb_evt_eventid_fullname(eventid),
+ "id", afb_evt_eventid_id(eventid),
"result", 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));
+ "name", name, "event", afb_evt_eventid_fullname(result), "id", afb_evt_eventid_id(result));
}
static void hook_ditf_rootdir_get_fd(void *closure, const struct afb_hookid *hookid, const struct afb_export *export, int result)
event = malloc(sizeof * event);
if (event) {
e = afb_daemon_make_event_v1(*trace->daemon, name);
- event->evtid = afb_evt_to_evtid(afb_event_to_eventid(e));
+ event->evtid = afb_evt_eventid_to_evtid(afb_event_to_eventid(e));
if (event->evtid) {
event->next = trace->events;
trace->events = event;
}
/* attach and activate the hook */
- afb_req_subscribe(desc->context->req, afb_event_from_evtid(hook->event->evtid));
+ afb_req_subscribe(desc->context->req, afb_evt_event_from_evtid(hook->event->evtid));
trace_attach_hook(trace, hook, type);
}
int afb_xreq_subscribe(struct afb_xreq *xreq, struct afb_eventid *eventid)
{
if (xreq->listener)
- return afb_evt_add_watch(xreq->listener, eventid);
+ return afb_evt_eventid_add_watch(xreq->listener, eventid);
if (xreq->queryitf->subscribe)
return xreq->queryitf->subscribe(xreq, eventid);
ERROR("no event listener, subscription impossible");
int afb_xreq_unsubscribe(struct afb_xreq *xreq, struct afb_eventid *eventid)
{
if (xreq->listener)
- return afb_evt_remove_watch(xreq->listener, eventid);
+ return afb_evt_eventid_remove_watch(xreq->listener, eventid);
if (xreq->queryitf->unsubscribe)
return xreq->queryitf->unsubscribe(xreq, eventid);
ERROR("no event listener, unsubscription impossible");