diff options
author | Jose Bollo <jose.bollo@iot.bzh> | 2019-12-17 08:22:00 +0100 |
---|---|---|
committer | Jose Bollo <jose.bollo@iot.bzh> | 2020-01-03 16:53:38 +0100 |
commit | f40979c718fa6fe6b571e133e1bf19fc90957298 (patch) | |
tree | c54c20daa5652d431254a90e67ada7e5cae97aa3 /src/afb-evt.c | |
parent | ca0f859d96599c8ae295c85f825030c891969de1 (diff) |
afb-proto-ws: Add message for unexpected event
This new message allows to revoke an event no more
expected or listened.
Bug-AGL: SPEC-3069
Change-Id: I71945e322276f29b01b628bdf43d75599b521fc3
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-evt.c')
-rw-r--r-- | src/afb-evt.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/afb-evt.c b/src/afb-evt.c index c0e43200..1c8798fd 100644 --- a/src/afb-evt.c +++ b/src/afb-evt.c @@ -894,6 +894,36 @@ int afb_evt_watch_sub_evtid(struct afb_evt_listener *listener, struct afb_evtid return -1; } +/* + * Avoids the 'listener' to watch 'eventid' + * Returns 0 in case of success or else -1. + */ +int afb_evt_watch_sub_eventid(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 |