aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bindings/samples/HelloWorld.c2
-rw-r--r--include/afb/afb-binding.hpp6
-rw-r--r--include/afb/afb-event-itf.h31
-rw-r--r--src/afb-api-dbus.c2
-rw-r--r--src/afb-evt.c24
-rw-r--r--src/afb-hook.c11
-rw-r--r--src/afb-hook.h9
-rw-r--r--src/afb-stub-ws.c4
-rw-r--r--src/afb-trace.c7
9 files changed, 39 insertions, 57 deletions
diff --git a/bindings/samples/HelloWorld.c b/bindings/samples/HelloWorld.c
index c5a79deb..0b0d1a96 100644
--- a/bindings/samples/HelloWorld.c
+++ b/bindings/samples/HelloWorld.c
@@ -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;
}
diff --git a/include/afb/afb-binding.hpp b/include/afb/afb-binding.hpp
index 1fc8b497..6e062b2e 100644
--- a/include/afb/afb-binding.hpp
+++ b/include/afb/afb-binding.hpp
@@ -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 */
diff --git a/include/afb/afb-event-itf.h b/include/afb/afb-event-itf.h
index b1776ea0..6827d86a 100644
--- a/include/afb/afb-event-itf.h
+++ b/include/afb/afb-event-itf.h
@@ -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);
}
diff --git a/src/afb-api-dbus.c b/src/afb-api-dbus.c
index 69f63ae4..a9401570 100644
--- a/src/afb-api-dbus.c
+++ b/src/afb-api-dbus.c
@@ -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);
}
diff --git a/src/afb-evt.c b/src/afb-evt.c
index 2bac0837..96366de6 100644
--- a/src/afb-evt.c
+++ b/src/afb-evt.c
@@ -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'
*/
diff --git a/src/afb-hook.c b/src/afb-hook.c
index 09e6062a..3c015dcf 100644
--- a/src/afb-hook.c
+++ b/src/afb-hook.c
@@ -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);
diff --git a/src/afb-hook.h b/src/afb-hook.h
index 9cdca9c7..57e88dc3 100644
--- a/src/afb-hook.h
+++ b/src/afb-hook.h
@@ -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);
diff --git a/src/afb-stub-ws.c b/src/afb-stub-ws.c
index 9c903247..d1ce80b2 100644
--- a/src/afb-stub-ws.c
+++ b/src/afb-stub-ws.c
@@ -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;
}
diff --git a/src/afb-trace.c b/src/afb-trace.c
index 25fa5301..4d8a4f73 100644
--- a/src/afb-trace.c
+++ b/src/afb-trace.c
@@ -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
};