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>
*p = e->next;
/* destroys */
- afb_event_drop(e->event);
+ afb_event_unref(e->event);
free(e);
return 0;
}
int broadcast(json_object *object) const;
int push(json_object *object) const;
- void drop();
+ void unref();
+ void addref();
const char *name() const;
};
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 */
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);
};
/*
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);
}
*prv = ev->next;
/* destroys the event */
- afb_event_drop(ev->event);
+ afb_event_unref(ev->event);
free(ev);
}
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 */
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);
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'
*/
_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");
.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
};
_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);
#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)
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);
};
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);
*prv = ev->next;
/* destroys the event */
- afb_event_drop(ev->event);
+ afb_event_unref(ev->event);
free(ev);
}
while (ev) {
nxt = ev->next;
- afb_event_drop(ev->event);
+ afb_event_unref(ev->event);
free(ev);
ev = nxt;
}
{ "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 },
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);
.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
};