* Makes the 'listener' watching 'evtid'
* Returns 0 in case of success or else -1.
*/
-int afb_evt_watch_add_evtid(struct afb_evt_listener *listener, struct afb_evtid *evtid)
+int afb_evt_listener_watch_evt(struct afb_evt_listener *listener, struct afb_evtid *evtid)
{
struct afb_evt_watch *watch;
* Avoids the 'listener' to watch 'evtid'
* Returns 0 in case of success or else -1.
*/
-int afb_evt_watch_sub_evtid(struct afb_evt_listener *listener, struct afb_evtid *evtid)
+int afb_evt_listener_unwatch_evt(struct afb_evt_listener *listener, struct afb_evtid *evtid)
{
struct afb_evt_watch *watch;
return -1;
}
+/*
+ * Avoids the 'listener' to watch 'eventid'
+ * Returns 0 in case of success or else -1.
+ */
+int afb_evt_listener_unwatch_id(struct afb_evt_listener *listener, uint16_t eventid)
+{
+ struct afb_evt_watch *watch;
+ struct afb_evtid *evtid;
+
+ /* search the existing watch */
+ pthread_rwlock_wrlock(&listener->rwlock);
+ watch = listener->watchs;
+ while(watch != NULL) {
+ evtid = watch->evtid;
+ if (evtid->id == eventid) {
+ if (watch->activity != 0) {
+ watch->activity--;
+ if (watch->activity == 0 && listener->itf->remove != NULL)
+ listener->itf->remove(listener->closure, evtid->fullname, evtid->id);
+ }
+ pthread_rwlock_unlock(&listener->rwlock);
+ return 0;
+ }
+ watch = watch->next_by_listener;
+ }
+ pthread_rwlock_unlock(&listener->rwlock);
+ errno = ENOENT;
+ return -1;
+}
+
#if WITH_AFB_HOOK
/*
* update the hooks for events
* Makes the 'listener' watching 'eventid'
* Returns 0 in case of success or else -1.
*/
-int afb_evt_event_x2_add_watch(struct afb_evt_listener *listener, struct afb_event_x2 *eventid)
+int afb_evt_listener_watch_x2(struct afb_evt_listener *listener, struct afb_event_x2 *eventid)
{
struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid);
}
/* search the existing watch for the listener */
- return afb_evt_watch_add_evtid(listener, evtid);
+ return afb_evt_listener_watch_evt(listener, evtid);
}
/*
* Avoids the 'listener' to watch 'eventid'
* Returns 0 in case of success or else -1.
*/
-int afb_evt_event_x2_remove_watch(struct afb_evt_listener *listener, struct afb_event_x2 *eventid)
+int afb_evt_listener_unwatch_x2(struct afb_evt_listener *listener, struct afb_event_x2 *eventid)
{
struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid);
}
/* search the existing watch */
- return afb_evt_watch_sub_evtid(listener, evtid);
+ return afb_evt_listener_unwatch_evt(listener, evtid);
}
int afb_evt_event_x2_push(struct afb_event_x2 *eventid, struct json_object *object)