Improve naming of evt_eventids
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 22 Sep 2017 15:04:22 +0000 (17:04 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 9 Oct 2017 12:08:33 +0000 (14:08 +0200)
Change-Id: I1fa3cf776110f67ad1b18c4c83f3a1707692ae8b
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-api-dbus.c
src/afb-evt.c
src/afb-evt.h
src/afb-export.c
src/afb-hook.c
src/afb-stub-ws.c
src/afb-trace.c
src/afb-xreq.c

index 806d743..cace4d2 100644 (file)
@@ -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,8 +861,8 @@ 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;
 }
 
index e3a3420..18f4bca 100644 (file)
@@ -634,12 +634,12 @@ void afb_evt_update_hooks()
        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;
 }
@@ -648,26 +648,26 @@ inline struct afb_eventid *afb_evt_from_evtid(struct afb_evtid *evtid)
  * 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;
 }
 
@@ -675,9 +675,9 @@ int afb_evt_event_id(struct afb_eventid *eventid)
  * 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) {
@@ -693,9 +693,9 @@ int afb_evt_add_watch(struct afb_evt_listener *listener, struct afb_eventid *eve
  * 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) {
@@ -707,34 +707,34 @@ int afb_evt_remove_watch(struct afb_evt_listener *listener, struct afb_eventid *
        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);
 }
index ea08329..a6bfda1 100644 (file)
@@ -64,18 +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_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);
 
index 7fd475a..19aab0c 100644 (file)
@@ -173,7 +173,7 @@ static struct afb_eventid *eventid_make_cb(void *closure, const char *name)
        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)
index 123a641..7ae713e 100644 (file)
@@ -283,12 +283,12 @@ static void hook_xreq_session_set_LOA_default_cb(void *closure, const struct afb
 
 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)
@@ -726,7 +726,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_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)
index 2b6a232..7637f22 100644 (file)
@@ -209,9 +209,9 @@ static int server_req_subscribe_cb(struct afb_xreq *xreq, struct afb_eventid *ev
        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;
@@ -222,8 +222,8 @@ static int server_req_unsubscribe_cb(struct afb_xreq *xreq, struct afb_eventid *
        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)
@@ -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->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;
@@ -360,7 +360,7 @@ 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->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;
@@ -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_evt_event_unref(ev->eventid);
+       afb_evt_eventid_unref(ev->eventid);
        free(ev);
 }
 
@@ -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_evt_push(ev->eventid, data);
+               afb_evt_eventid_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_evt_event_unref(ev->eventid);
+               afb_evt_eventid_unref(ev->eventid);
                free(ev);
                ev = nxt;
        }
index fb8cc19..40f27a2 100644 (file)
@@ -366,8 +366,8 @@ static void hook_xreq_subscribe(void *closure, const struct afb_hookid *hookid,
 {
        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);
 }
 
@@ -375,8 +375,8 @@ static void hook_xreq_unsubscribe(void *closure, const struct afb_hookid *hookid
 {
        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);
 }
 
@@ -615,7 +615,7 @@ static void hook_ditf_vverbose(void *closure, const struct afb_hookid *hookid, c
 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)
@@ -1101,7 +1101,7 @@ static struct event *trace_get_event(struct afb_trace *trace, const char *name,
                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;
@@ -1267,7 +1267,7 @@ static void addhook(struct desc *desc, enum trace_type type)
        }
 
        /* 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);
 }
 
index 5f6c745..2e6108d 100644 (file)
@@ -463,7 +463,7 @@ static int xreq_subscribe_eventid_cb(struct afb_request *closure, struct afb_eve
 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");
@@ -486,7 +486,7 @@ static int xreq_unsubscribe_eventid_cb(struct afb_request *closure, struct afb_e
 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");