Make afb_event_drop obsolete
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 21 Sep 2017 10:34:12 +0000 (12:34 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 9 Oct 2017 12:08:32 +0000 (14:08 +0200)
The function is now replaced by the function afb_event_unref.
In the same time, the function afb_event_addref is made available.

Change-Id: I9aa30e80e64e82f3b16ab359982337771b287185
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
bindings/samples/HelloWorld.c
include/afb/afb-binding.hpp
include/afb/afb-event-itf.h
src/afb-api-dbus.c
src/afb-evt.c
src/afb-hook.c
src/afb-hook.h
src/afb-stub-ws.c
src/afb-trace.c

index c5a79de..0b0d1a9 100644 (file)
@@ -59,7 +59,7 @@ static int event_del(const char *tag)
        *p = e->next;
 
        /* destroys */
-       afb_event_drop(e->event);
+       afb_event_unref(e->event);
        free(e);
        return 0;
 }
index 1fc8b49..6e062b2 100644 (file)
@@ -110,7 +110,8 @@ public:
        int broadcast(json_object *object) const;
        int push(json_object *object) const;
 
-       void drop();
+       void unref();
+       void addref();
        const char *name() const;
 };
 
@@ -261,7 +262,8 @@ inline void event::invalidate() { event_.itf = NULL; event_.closure = NULL; }
 inline int event::broadcast(json_object *object) const { return afb_event_broadcast(event_, object); } 
 inline int event::push(json_object *object) const { return afb_event_push(event_, object); }
 
-inline void event::drop() { afb_event_drop(event_); invalidate(); }
+inline void event::unref() { afb_event_unref(event_); invalidate(); }
+inline void event::addref() { afb_event_addref(event_); }
 inline const char *event::name() const { return afb_event_name(event_); }
 
 /* args */
index b1776ea..6827d86 100644 (file)
@@ -32,8 +32,9 @@ struct afb_event_itf
 
        int (*broadcast)(void *closure, struct json_object *obj);
        int (*push)(void *closure, struct json_object *obj);
-       void (*drop)(void *closure);
+       void (*unref)(void *closure);
        const char *(*name)(void *closure);
+       void (*addref)(void *closure);
 };
 
 /*
@@ -85,21 +86,33 @@ static inline int afb_event_push(struct afb_event event, struct json_object *obj
        return event.itf->push(event.closure, object);
 }
 
+/* OBSOLETE */
+#define afb_event_drop afb_event_unref
+
 /*
- * Drops the data associated to the 'event'
- * After calling this function, the event
- * MUST NOT BE USED ANYMORE.
+ * Gets the name associated to the 'event'.
  */
-static inline void afb_event_drop(struct afb_event event)
+static inline const char *afb_event_name(struct afb_event event)
 {
-       event.itf->drop(event.closure);
+       return event.itf->name(event.closure);
 }
 
 /*
- * Gets the name associated to the 'event'.
+ * Decrease the count of reference to 'event' and
+ * destroys the event when the reference count falls to zero.
  */
-static inline const char *afb_event_name(struct afb_event event)
+static inline void afb_event_unref(struct afb_event event)
 {
-       return event.itf->name(event.closure);
+       event.itf->unref(event.closure);
+}
+
+/*
+ * remove one reference to the data associated to the 'event'
+ * After calling this function, the event
+ * MUST NOT BE USED ANYMORE.
+ */
+static inline void afb_event_addref(struct afb_event event)
+{
+       event.itf->addref(event.closure);
 }
 
index 69f63ae..a940157 100644 (file)
@@ -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_drop(ev->event);
+       afb_event_unref(ev->event);
        free(ev);
 }
 
index 2bac083..96366de 100644 (file)
@@ -108,23 +108,22 @@ struct afb_evt_watch {
        unsigned activity;
 };
 
-/* declare functions */
-static void evt_hooked_drop(struct afb_evtid *evtid);
-
 /* the interface for events */
 static struct afb_event_itf afb_evt_event_itf = {
        .broadcast = (void*)afb_evt_evtid_broadcast,
        .push = (void*)afb_evt_evtid_push,
-       .drop = (void*)afb_evt_evtid_unref,
-       .name = (void*)afb_evt_evtid_name
+       .unref = (void*)afb_evt_evtid_unref,
+       .name = (void*)afb_evt_evtid_name,
+       .addref = (void*)afb_evt_evtid_addref
 };
 
 /* the interface for events */
 static struct afb_event_itf afb_evt_hooked_event_itf = {
        .broadcast = (void*)afb_evt_evtid_hooked_broadcast,
        .push = (void*)afb_evt_evtid_hooked_push,
-       .drop = (void*)evt_hooked_drop,
-       .name = (void*)afb_evt_evtid_hooked_name
+       .unref = (void*)afb_evt_evtid_hooked_unref,
+       .name = (void*)afb_evt_evtid_hooked_name,
+       .addref = (void*)afb_evt_evtid_hooked_addref
 };
 
 /* head of the list of listeners */
@@ -406,10 +405,6 @@ void afb_evt_evtid_unref(struct afb_evtid *evtid)
                                pthread_mutex_unlock(&listener->mutex);
                        }
 
-                       /* hook */
-                       if (evtid->hookflags & afb_hook_flag_evt_drop)
-                               afb_hook_evt_drop(evtid->fullname, evtid->id);
-
                        /* free */
                        pthread_mutex_destroy(&evtid->mutex);
                        free(evtid);
@@ -428,13 +423,6 @@ void afb_evt_evtid_hooked_unref(struct afb_evtid *evtid)
        afb_evt_evtid_unref(evtid);
 }
 
-static void evt_hooked_drop(struct afb_evtid *evtid)
-{
-       if (evtid->hookflags & afb_hook_flag_evt_drop)
-               afb_hook_evt_drop(evtid->fullname, evtid->id);
-       afb_evt_evtid_unref(evtid);
-}
-
 /*
  * Returns the true name of the 'event'
  */
index 09e6062..3c015dc 100644 (file)
@@ -1239,11 +1239,6 @@ static void hook_evt_name_default_cb(void *closure, const struct afb_hookid *hoo
        _hook_evt_(evt, id, "name -> %s", result);
 }
 
-static void hook_evt_drop_default_cb(void *closure, const struct afb_hookid *hookid, const char *evt, int id)
-{
-       _hook_evt_(evt, id, "drop");
-}
-
 static void hook_evt_addref_default_cb(void *closure, const struct afb_hookid *hookid, const char *evt, int id)
 {
        _hook_evt_(evt, id, "addref");
@@ -1261,7 +1256,6 @@ static struct afb_hook_evt_itf hook_evt_default_itf = {
        .hook_evt_broadcast_before = hook_evt_broadcast_before_default_cb,
        .hook_evt_broadcast_after = hook_evt_broadcast_after_default_cb,
        .hook_evt_name = hook_evt_name_default_cb,
-       .hook_evt_drop = hook_evt_drop_default_cb,
        .hook_evt_addref = hook_evt_addref_default_cb,
        .hook_evt_unref = hook_evt_unref_default_cb
 };
@@ -1318,11 +1312,6 @@ void afb_hook_evt_name(const char *evt, int id, const char *result)
        _HOOK_EVT_(name, evt, id, result);
 }
 
-void afb_hook_evt_drop(const char *evt, int id)
-{
-       _HOOK_EVT_(drop, evt, id);
-}
-
 void afb_hook_evt_addref(const char *evt, int id)
 {
        _HOOK_EVT_(addref, evt, id);
index 9cdca9c..57e88dc 100644 (file)
@@ -292,14 +292,13 @@ extern void afb_hook_unref_svc(struct afb_hook_svc *hook);
 #define afb_hook_flag_evt_broadcast_before             0x000008
 #define afb_hook_flag_evt_broadcast_after              0x000010
 #define afb_hook_flag_evt_name                         0x000020
-#define afb_hook_flag_evt_drop                         0x000040
-#define afb_hook_flag_evt_addref                       0x000080
-#define afb_hook_flag_evt_unref                                0x000100
+#define afb_hook_flag_evt_addref                       0x000040
+#define afb_hook_flag_evt_unref                                0x000080
 
 #define afb_hook_flags_evt_common      (afb_hook_flag_evt_push_before|afb_hook_flag_evt_broadcast_before)
 #define afb_hook_flags_evt_extra       (afb_hook_flags_evt_common\
                                        |afb_hook_flag_evt_push_after|afb_hook_flag_evt_broadcast_after\
-                                       |afb_hook_flag_evt_create|afb_hook_flag_evt_drop\
+                                       |afb_hook_flag_evt_create\
                                        |afb_hook_flag_evt_addref|afb_hook_flag_evt_unref)
 #define afb_hook_flags_evt_all         (afb_hook_flags_evt_extra|afb_hook_flag_evt_name)
 
@@ -310,7 +309,6 @@ struct afb_hook_evt_itf {
        void (*hook_evt_broadcast_before)(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj);
        void (*hook_evt_broadcast_after)(void *closure, const struct afb_hookid *hookid, const char *evt, int id, struct json_object *obj, int result);
        void (*hook_evt_name)(void *closure, const struct afb_hookid *hookid, const char *evt, int id, const char *result);
-       void (*hook_evt_drop)(void *closure, const struct afb_hookid *hookid, const char *evt, int id);
        void (*hook_evt_addref)(void *closure, const struct afb_hookid *hookid, const char *evt, int id);
        void (*hook_evt_unref)(void *closure, const struct afb_hookid *hookid, const char *evt, int id);
 };
@@ -321,7 +319,6 @@ extern int afb_hook_evt_push_after(const char *evt, int id, struct json_object *
 extern void afb_hook_evt_broadcast_before(const char *evt, int id, struct json_object *obj);
 extern int afb_hook_evt_broadcast_after(const char *evt, int id, struct json_object *obj, int result);
 extern void afb_hook_evt_name(const char *evt, int id, const char *result);
-extern void afb_hook_evt_drop(const char *evt, int id);
 extern void afb_hook_evt_addref(const char *evt, int id);
 extern void afb_hook_evt_unref(const char *evt, int id);
 
index 9c90324..d1ce80b 100644 (file)
@@ -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_drop(ev->event);
+       afb_event_unref(ev->event);
        free(ev);
 }
 
@@ -585,7 +585,7 @@ static void drop_all_events(struct afb_stub_ws *stubws)
 
        while (ev) {
                nxt = ev->next;
-               afb_event_drop(ev->event);
+               afb_event_unref(ev->event);
                free(ev);
                ev = nxt;
        }
index 25fa530..4d8a4f7 100644 (file)
@@ -785,7 +785,6 @@ static struct flag evt_flags[] = { /* must be sorted by names */
                { "broadcast_before",   afb_hook_flag_evt_broadcast_before },
                { "common",             afb_hook_flags_evt_common },
                { "create",             afb_hook_flag_evt_create },
-               { "drop",               afb_hook_flag_evt_drop },
                { "extra",              afb_hook_flags_evt_extra },
                { "name",               afb_hook_flag_evt_name },
                { "push_after",         afb_hook_flag_evt_push_after },
@@ -842,11 +841,6 @@ static void hook_evt_name(void *closure, const struct afb_hookid *hookid, const
        hook_evt(closure, hookid, evt, id, "name", "{ss}", "result", result);
 }
 
-static void hook_evt_drop(void *closure, const struct afb_hookid *hookid, const char *evt, int id)
-{
-       hook_evt(closure, hookid, evt, id, "drop", NULL);
-}
-
 static void hook_evt_addref(void *closure, const struct afb_hookid *hookid, const char *evt, int id)
 {
        hook_evt(closure, hookid, evt, id, "addref", NULL);
@@ -864,7 +858,6 @@ static struct afb_hook_evt_itf hook_evt_itf = {
        .hook_evt_broadcast_before = hook_evt_broadcast_before,
        .hook_evt_broadcast_after = hook_evt_broadcast_after,
        .hook_evt_name = hook_evt_name,
-       .hook_evt_drop = hook_evt_drop,
        .hook_evt_addref = hook_evt_addref,
        .hook_evt_unref = hook_evt_unref
 };