2 * Copyright (C) 2015-2019 "IoT.bzh"
3 * Author José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
26 #include <json-c/json.h>
27 #include <afb/afb-event-x2-itf.h>
28 #include <afb/afb-event-x1.h>
39 * Structure for event listeners
41 struct afb_evt_listener {
43 /* chaining listeners */
44 struct afb_evt_listener *next;
46 /* interface for callbacks */
47 const struct afb_evt_itf *itf;
49 /* closure for the callback */
52 /* head of the list of events listened */
53 struct afb_evt_watch *watchs;
55 /* rwlock of the listener */
56 pthread_rwlock_t rwlock;
58 /* count of reference to the listener */
63 * Structure for describing events
68 struct afb_event_x2 eventid;
71 struct afb_evtid *next;
73 /* head of the list of listeners watching the event */
74 struct afb_evt_watch *watchs;
76 /* rwlock of the event */
77 pthread_rwlock_t rwlock;
93 /* fullname of the event */
98 * Structure for associating events and listeners
100 struct afb_evt_watch {
103 struct afb_evtid *evtid;
105 /* link to the next watcher for the same evtid */
106 struct afb_evt_watch *next_by_evtid;
109 struct afb_evt_listener *listener;
111 /* link to the next watcher for the same listener */
112 struct afb_evt_watch *next_by_listener;
119 * structure for job of broadcasting events
123 /** object atached to the event */
124 struct json_object *object;
126 /** the uuid of the event */
132 /** name of the event to broadcast */
137 * structure for job of broadcasting or pushing events
141 /** the event to broadcast */
142 struct afb_evtid *evtid;
144 /** object atached to the event */
145 struct json_object *object;
148 /* the interface for events */
149 static struct afb_event_x2_itf afb_evt_event_x2_itf = {
150 .broadcast = (void*)afb_evt_evtid_broadcast,
151 .push = (void*)afb_evt_evtid_push,
152 .unref = (void*)afb_evt_evtid_unref,
153 .name = (void*)afb_evt_evtid_name,
154 .addref = (void*)afb_evt_evtid_addref
158 /* the interface for events */
159 static struct afb_event_x2_itf afb_evt_hooked_event_x2_itf = {
160 .broadcast = (void*)afb_evt_evtid_hooked_broadcast,
161 .push = (void*)afb_evt_evtid_hooked_push,
162 .unref = (void*)afb_evt_evtid_hooked_unref,
163 .name = (void*)afb_evt_evtid_hooked_name,
164 .addref = (void*)afb_evt_evtid_hooked_addref
168 /* job groups for events push/broadcast */
169 #define BROADCAST_JOB_GROUP (&afb_evt_event_x2_itf)
170 #define PUSH_JOB_GROUP (&afb_evt_event_x2_itf)
172 /* head of the list of listeners */
173 static pthread_rwlock_t listeners_rwlock = PTHREAD_RWLOCK_INITIALIZER;
174 static struct afb_evt_listener *listeners = NULL;
176 /* handling id of events */
177 static pthread_rwlock_t events_rwlock = PTHREAD_RWLOCK_INITIALIZER;
178 static struct afb_evtid *evtids = NULL;
179 static int event_id_counter = 0;
180 static int event_id_wrapped = 0;
182 /* head of uniqueness of events */
183 #if !defined(EVENT_BROADCAST_HOP_MAX)
184 # define EVENT_BROADCAST_HOP_MAX 10
186 #if !defined(EVENT_BROADCAST_MEMORY_COUNT)
187 # define EVENT_BROADCAST_MEMORY_COUNT 8
190 #if EVENT_BROADCAST_MEMORY_COUNT
192 pthread_mutex_t mutex;
195 uuid_binary_t uuids[EVENT_BROADCAST_MEMORY_COUNT];
197 .mutex = PTHREAD_MUTEX_INITIALIZER,
204 * Create structure for job of broadcasting string 'event' with 'object'
205 * Returns the created structure or NULL if out of memory
207 static struct job_broadcast *make_job_broadcast(const char *event, struct json_object *object, const uuid_binary_t uuid, uint8_t hop)
209 size_t sz = 1 + strlen(event);
210 struct job_broadcast *jb = malloc(sz + sizeof *jb);
213 memcpy(jb->uuid, uuid, sizeof jb->uuid);
215 memcpy(jb->event, event, sz);
221 * Destroy structure 'jb' for job of broadcasting string events
223 static void destroy_job_broadcast(struct job_broadcast *jb)
225 json_object_put(jb->object);
230 * Create structure for job of broadcasting or pushing 'evtid' with 'object'
231 * Returns the created structure or NULL if out of memory
233 static struct job_evtid *make_job_evtid(struct afb_evtid *evtid, struct json_object *object)
235 struct job_evtid *je = malloc(sizeof *je);
237 je->evtid = afb_evt_evtid_addref(evtid);
244 * Destroy structure for job of broadcasting or pushing evtid
246 static void destroy_job_evtid(struct job_evtid *je)
248 afb_evt_evtid_unref(je->evtid);
249 json_object_put(je->object);
254 * Broadcasts the 'event' of 'id' with its 'object'
256 static void broadcast(struct job_broadcast *jb)
258 struct afb_evt_listener *listener;
260 pthread_rwlock_rdlock(&listeners_rwlock);
261 listener = listeners;
263 if (listener->itf->broadcast != NULL)
264 listener->itf->broadcast(listener->closure, jb->event, json_object_get(jb->object), jb->uuid, jb->hop);
265 listener = listener->next;
267 pthread_rwlock_unlock(&listeners_rwlock);
271 * Jobs callback for broadcasting string asynchronously
273 static void broadcast_job(int signum, void *closure)
275 struct job_broadcast *jb = closure;
279 destroy_job_broadcast(jb);
283 * Broadcasts the string 'event' with its 'object'
285 static int unhooked_broadcast(const char *event, struct json_object *object, const uuid_binary_t uuid, uint8_t hop)
287 uuid_binary_t local_uuid;
288 struct job_broadcast *jb;
290 #if EVENT_BROADCAST_MEMORY_COUNT
294 /* check if lately sent */
296 uuid_new_binary(local_uuid);
298 hop = EVENT_BROADCAST_HOP_MAX;
299 #if EVENT_BROADCAST_MEMORY_COUNT
300 pthread_mutex_lock(&uniqueness.mutex);
302 pthread_mutex_lock(&uniqueness.mutex);
303 iter = (int)uniqueness.base;
304 count = (int)uniqueness.count;
306 if (0 == memcmp(uuid, uniqueness.uuids[iter], sizeof(uuid_binary_t))) {
307 pthread_mutex_unlock(&uniqueness.mutex);
310 if (++iter == EVENT_BROADCAST_MEMORY_COUNT)
315 iter = (int)uniqueness.base;
316 if (uniqueness.count < EVENT_BROADCAST_MEMORY_COUNT)
317 iter += (int)(uniqueness.count++);
318 else if (++uniqueness.base == EVENT_BROADCAST_MEMORY_COUNT)
320 memcpy(uniqueness.uuids[iter], uuid, sizeof(uuid_binary_t));
321 pthread_mutex_unlock(&uniqueness.mutex);
326 /* create the structure for the job */
327 jb = make_job_broadcast(event, object, uuid, hop);
329 ERROR("Cant't create broadcast string job item for %s(%s)",
330 event, json_object_to_json_string(object));
331 json_object_put(object);
336 rc = jobs_queue(BROADCAST_JOB_GROUP, 0, broadcast_job, jb);
338 ERROR("cant't queue broadcast string job item for %s(%s)",
339 event, json_object_to_json_string(object));
340 destroy_job_broadcast(jb);
346 * Broadcasts the event 'evtid' with its 'object'
347 * 'object' is released (like json_object_put)
348 * Returns the count of listener that received the event.
350 int afb_evt_evtid_broadcast(struct afb_evtid *evtid, struct json_object *object)
352 return unhooked_broadcast(evtid->fullname, object, NULL, 0);
357 * Broadcasts the event 'evtid' with its 'object'
358 * 'object' is released (like json_object_put)
359 * Returns the count of listener that received the event.
361 int afb_evt_evtid_hooked_broadcast(struct afb_evtid *evtid, struct json_object *object)
365 json_object_get(object);
367 if (evtid->hookflags & afb_hook_flag_evt_broadcast_before)
368 afb_hook_evt_broadcast_before(evtid->fullname, evtid->id, object);
370 result = afb_evt_evtid_broadcast(evtid, object);
372 if (evtid->hookflags & afb_hook_flag_evt_broadcast_after)
373 afb_hook_evt_broadcast_after(evtid->fullname, evtid->id, object, result);
375 json_object_put(object);
381 int afb_evt_rebroadcast(const char *event, struct json_object *object, const uuid_binary_t uuid, uint8_t hop)
386 json_object_get(object);
387 afb_hook_evt_broadcast_before(event, 0, object);
390 result = unhooked_broadcast(event, object, uuid, hop);
393 afb_hook_evt_broadcast_after(event, 0, object, result);
394 json_object_put(object);
400 * Broadcasts the 'event' with its 'object'
401 * 'object' is released (like json_object_put)
402 * Returns the count of listener having receive the event.
404 int afb_evt_broadcast(const char *event, struct json_object *object)
406 return afb_evt_rebroadcast(event, object, NULL, 0);
410 * Pushes the event 'evtid' with 'obj' to its listeners
411 * Returns the count of listener that received the event.
413 static void push_evtid(struct afb_evtid *evtid, struct json_object *object)
416 struct afb_evt_watch *watch;
417 struct afb_evt_listener *listener;
420 pthread_rwlock_rdlock(&evtid->rwlock);
421 watch = evtid->watchs;
423 listener = watch->listener;
424 assert(listener->itf->push != NULL);
425 if (watch->activity != 0) {
426 listener->itf->push(listener->closure, evtid->fullname, evtid->id, json_object_get(object));
429 watch = watch->next_by_evtid;
431 evtid->has_client = has_client;
432 pthread_rwlock_unlock(&evtid->rwlock);
436 * Jobs callback for pushing evtid asynchronously
438 static void push_job_evtid(int signum, void *closure)
440 struct job_evtid *je = closure;
443 push_evtid(je->evtid, je->object);
444 destroy_job_evtid(je);
448 * Pushes the event 'evtid' with 'obj' to its listeners
449 * 'obj' is released (like json_object_put)
450 * Returns 1 if at least one listener exists or 0 if no listener exists or
451 * -1 in case of error and the event can't be delivered
453 int afb_evt_evtid_push(struct afb_evtid *evtid, struct json_object *object)
455 struct job_evtid *je;
458 je = make_job_evtid(evtid, object);
460 ERROR("Cant't create push evtid job item for %s(%s)",
461 evtid->fullname, json_object_to_json_string(object));
462 json_object_put(object);
466 rc = jobs_queue(PUSH_JOB_GROUP, 0, push_job_evtid, je);
468 rc = evtid->has_client;
470 ERROR("cant't queue push evtid job item for %s(%s)",
471 evtid->fullname, json_object_to_json_string(object));
472 destroy_job_evtid(je);
480 * Pushes the event 'evtid' with 'obj' to its listeners
481 * 'obj' is released (like json_object_put)
482 * Emits calls to hooks.
483 * Returns the count of listener taht received the event.
485 int afb_evt_evtid_hooked_push(struct afb_evtid *evtid, struct json_object *obj)
490 /* lease the object */
491 json_object_get(obj);
493 /* hook before push */
494 if (evtid->hookflags & afb_hook_flag_evt_push_before)
495 afb_hook_evt_push_before(evtid->fullname, evtid->id, obj);
498 result = afb_evt_evtid_push(evtid, obj);
500 /* hook after push */
501 if (evtid->hookflags & afb_hook_flag_evt_push_after)
502 afb_hook_evt_push_after(evtid->fullname, evtid->id, obj, result);
504 /* release the object */
505 json_object_put(obj);
513 static void remove_watch(struct afb_evt_watch *watch)
515 struct afb_evt_watch **prv;
516 struct afb_evtid *evtid;
517 struct afb_evt_listener *listener;
519 /* notify listener if needed */
520 evtid = watch->evtid;
521 listener = watch->listener;
522 if (watch->activity != 0 && listener->itf->remove != NULL)
523 listener->itf->remove(listener->closure, evtid->fullname, evtid->id);
525 /* unlink the watch for its event */
526 prv = &evtid->watchs;
528 prv = &(*prv)->next_by_evtid;
529 *prv = watch->next_by_evtid;
531 /* unlink the watch for its listener */
532 prv = &listener->watchs;
534 prv = &(*prv)->next_by_listener;
535 *prv = watch->next_by_listener;
542 * Creates an event of name 'fullname' and returns it or NULL on error.
544 struct afb_evtid *afb_evt_evtid_create(const char *fullname)
547 struct afb_evtid *evtid, *oevt;
549 /* allocates the event */
550 len = strlen(fullname);
551 evtid = malloc(len + 1 + sizeof * evtid);
555 /* allocates the id */
556 pthread_rwlock_wrlock(&events_rwlock);
558 if (++event_id_counter < 0) {
559 event_id_wrapped = 1;
560 event_id_counter = 1024; /* heuristic: small numbers are not destroyed */
562 if (!event_id_wrapped)
565 while(oevt != NULL && oevt->id != event_id_counter)
567 } while (oevt != NULL);
569 /* initialize the event */
570 memcpy(evtid->fullname, fullname, len + 1);
571 evtid->next = evtids;
573 evtid->watchs = NULL;
574 evtid->id = event_id_counter;
575 evtid->has_client = 0;
576 pthread_rwlock_init(&evtid->rwlock, NULL);
579 evtid->hookflags = afb_hook_flags_evt(evtid->fullname);
580 evtid->eventid.itf = evtid->hookflags ? &afb_evt_hooked_event_x2_itf : &afb_evt_event_x2_itf;
581 if (evtid->hookflags & afb_hook_flag_evt_create)
582 afb_hook_evt_create(evtid->fullname, evtid->id);
584 evtid->eventid.itf = &afb_evt_event_x2_itf;
586 pthread_rwlock_unlock(&events_rwlock);
588 /* returns the event */
595 * Creates an event of name 'prefix'/'name' and returns it or NULL on error.
597 struct afb_evtid *afb_evt_evtid_create2(const char *prefix, const char *name)
599 size_t prelen, postlen;
602 /* makes the event fullname */
603 prelen = strlen(prefix);
604 postlen = strlen(name);
605 fullname = alloca(prelen + postlen + 2);
606 memcpy(fullname, prefix, prelen);
607 fullname[prelen] = '/';
608 memcpy(fullname + prelen + 1, name, postlen + 1);
610 /* create the event */
611 return afb_evt_evtid_create(fullname);
615 * increment the reference count of the event 'evtid'
617 struct afb_evtid *afb_evt_evtid_addref(struct afb_evtid *evtid)
619 __atomic_add_fetch(&evtid->refcount, 1, __ATOMIC_RELAXED);
625 * increment the reference count of the event 'evtid'
627 struct afb_evtid *afb_evt_evtid_hooked_addref(struct afb_evtid *evtid)
629 if (evtid->hookflags & afb_hook_flag_evt_addref)
630 afb_hook_evt_addref(evtid->fullname, evtid->id);
631 return afb_evt_evtid_addref(evtid);
636 * decrement the reference count of the event 'evtid'
637 * and destroy it when the count reachs zero
639 void afb_evt_evtid_unref(struct afb_evtid *evtid)
642 struct afb_evtid **prv;
643 struct afb_evt_listener *listener;
645 if (!__atomic_sub_fetch(&evtid->refcount, 1, __ATOMIC_RELAXED)) {
646 /* unlinks the event if valid! */
647 pthread_rwlock_wrlock(&events_rwlock);
650 while (*prv && !(found = (*prv == evtid)))
654 pthread_rwlock_unlock(&events_rwlock);
656 /* destroys the event */
658 ERROR("event not found");
660 /* removes all watchers */
661 while(evtid->watchs != NULL) {
662 listener = evtid->watchs->listener;
663 pthread_rwlock_wrlock(&listener->rwlock);
664 pthread_rwlock_wrlock(&evtid->rwlock);
665 remove_watch(evtid->watchs);
666 pthread_rwlock_unlock(&evtid->rwlock);
667 pthread_rwlock_unlock(&listener->rwlock);
671 pthread_rwlock_destroy(&evtid->rwlock);
679 * decrement the reference count of the event 'evtid'
680 * and destroy it when the count reachs zero
682 void afb_evt_evtid_hooked_unref(struct afb_evtid *evtid)
684 if (evtid->hookflags & afb_hook_flag_evt_unref)
685 afb_hook_evt_unref(evtid->fullname, evtid->id);
686 afb_evt_evtid_unref(evtid);
691 * Returns the true name of the 'event'
693 const char *afb_evt_evtid_fullname(struct afb_evtid *evtid)
695 return evtid->fullname;
699 * Returns the name of the 'event'
701 const char *afb_evt_evtid_name(struct afb_evtid *evtid)
703 const char *name = strchr(evtid->fullname, '/');
704 return name ? name + 1 : evtid->fullname;
709 * Returns the name associated to the event 'evtid'.
711 const char *afb_evt_evtid_hooked_name(struct afb_evtid *evtid)
713 const char *result = afb_evt_evtid_name(evtid);
714 if (evtid->hookflags & afb_hook_flag_evt_name)
715 afb_hook_evt_name(evtid->fullname, evtid->id, result);
721 * Returns the id of the 'event'
723 int afb_evt_evtid_id(struct afb_evtid *evtid)
729 * Returns an instance of the listener defined by the 'send' callback
731 * Returns NULL in case of memory depletion.
733 struct afb_evt_listener *afb_evt_listener_create(const struct afb_evt_itf *itf, void *closure)
735 struct afb_evt_listener *listener;
737 /* search if an instance already exists */
738 pthread_rwlock_wrlock(&listeners_rwlock);
739 listener = listeners;
740 while (listener != NULL) {
741 if (listener->itf == itf && listener->closure == closure) {
742 listener = afb_evt_listener_addref(listener);
745 listener = listener->next;
749 listener = calloc(1, sizeof *listener);
750 if (listener != NULL) {
753 listener->closure = closure;
754 listener->watchs = NULL;
755 listener->refcount = 1;
756 pthread_rwlock_init(&listener->rwlock, NULL);
757 listener->next = listeners;
758 listeners = listener;
761 pthread_rwlock_unlock(&listeners_rwlock);
766 * Increases the reference count of 'listener' and returns it
768 struct afb_evt_listener *afb_evt_listener_addref(struct afb_evt_listener *listener)
770 __atomic_add_fetch(&listener->refcount, 1, __ATOMIC_RELAXED);
775 * Decreases the reference count of the 'listener' and destroys it
778 void afb_evt_listener_unref(struct afb_evt_listener *listener)
780 struct afb_evt_listener **prv;
781 struct afb_evtid *evtid;
783 if (listener && !__atomic_sub_fetch(&listener->refcount, 1, __ATOMIC_RELAXED)) {
785 /* unlink the listener */
786 pthread_rwlock_wrlock(&listeners_rwlock);
788 while (*prv != listener)
790 *prv = listener->next;
791 pthread_rwlock_unlock(&listeners_rwlock);
793 /* remove the watchers */
794 pthread_rwlock_wrlock(&listener->rwlock);
795 while (listener->watchs != NULL) {
796 evtid = listener->watchs->evtid;
797 pthread_rwlock_wrlock(&evtid->rwlock);
798 remove_watch(listener->watchs);
799 pthread_rwlock_unlock(&evtid->rwlock);
801 pthread_rwlock_unlock(&listener->rwlock);
803 /* free the listener */
804 pthread_rwlock_destroy(&listener->rwlock);
810 * Makes the 'listener' watching 'evtid'
811 * Returns 0 in case of success or else -1.
813 int afb_evt_watch_add_evtid(struct afb_evt_listener *listener, struct afb_evtid *evtid)
815 struct afb_evt_watch *watch;
817 /* check parameter */
818 if (listener->itf->push == NULL) {
823 /* search the existing watch for the listener */
824 pthread_rwlock_wrlock(&listener->rwlock);
825 watch = listener->watchs;
826 while(watch != NULL) {
827 if (watch->evtid == evtid)
829 watch = watch->next_by_listener;
832 /* not found, allocate a new */
833 watch = malloc(sizeof *watch);
835 pthread_rwlock_unlock(&listener->rwlock);
840 /* initialise and link */
841 watch->evtid = evtid;
843 watch->listener = listener;
844 watch->next_by_listener = listener->watchs;
845 listener->watchs = watch;
846 pthread_rwlock_wrlock(&evtid->rwlock);
847 watch->next_by_evtid = evtid->watchs;
848 evtid->watchs = watch;
849 pthread_rwlock_unlock(&evtid->rwlock);
852 if (watch->activity == 0 && listener->itf->add != NULL)
853 listener->itf->add(listener->closure, evtid->fullname, evtid->id);
855 evtid->has_client = 1;
856 pthread_rwlock_unlock(&listener->rwlock);
862 * Avoids the 'listener' to watch 'evtid'
863 * Returns 0 in case of success or else -1.
865 int afb_evt_watch_sub_evtid(struct afb_evt_listener *listener, struct afb_evtid *evtid)
867 struct afb_evt_watch *watch;
869 /* search the existing watch */
870 pthread_rwlock_wrlock(&listener->rwlock);
871 watch = listener->watchs;
872 while(watch != NULL) {
873 if (watch->evtid == evtid) {
874 if (watch->activity != 0) {
876 if (watch->activity == 0 && listener->itf->remove != NULL)
877 listener->itf->remove(listener->closure, evtid->fullname, evtid->id);
879 pthread_rwlock_unlock(&listener->rwlock);
882 watch = watch->next_by_listener;
884 pthread_rwlock_unlock(&listener->rwlock);
891 * update the hooks for events
893 void afb_evt_update_hooks()
895 struct afb_evtid *evtid;
897 pthread_rwlock_rdlock(&events_rwlock);
898 for (evtid = evtids ; evtid ; evtid = evtid->next) {
899 evtid->hookflags = afb_hook_flags_evt(evtid->fullname);
900 evtid->eventid.itf = evtid->hookflags ? &afb_evt_hooked_event_x2_itf : &afb_evt_event_x2_itf;
902 pthread_rwlock_unlock(&events_rwlock);
906 inline struct afb_evtid *afb_evt_event_x2_to_evtid(struct afb_event_x2 *eventid)
908 return (struct afb_evtid*)eventid;
911 inline struct afb_event_x2 *afb_evt_event_x2_from_evtid(struct afb_evtid *evtid)
913 return &evtid->eventid;
917 * Creates an event of 'fullname' and returns it.
918 * Returns an event with closure==NULL in case of error.
920 struct afb_event_x2 *afb_evt_event_x2_create(const char *fullname)
922 return afb_evt_event_x2_from_evtid(afb_evt_evtid_create(fullname));
926 * Creates an event of name 'prefix'/'name' and returns it.
927 * Returns an event with closure==NULL in case of error.
929 struct afb_event_x2 *afb_evt_event_x2_create2(const char *prefix, const char *name)
931 return afb_evt_event_x2_from_evtid(afb_evt_evtid_create2(prefix, name));
935 * Returns the fullname of the 'eventid'
937 const char *afb_evt_event_x2_fullname(struct afb_event_x2 *eventid)
939 struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid);
940 return evtid ? evtid->fullname : NULL;
944 * Returns the id of the 'eventid'
946 int afb_evt_event_x2_id(struct afb_event_x2 *eventid)
948 struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid);
949 return evtid ? evtid->id : 0;
953 * Makes the 'listener' watching 'eventid'
954 * Returns 0 in case of success or else -1.
956 int afb_evt_event_x2_add_watch(struct afb_evt_listener *listener, struct afb_event_x2 *eventid)
958 struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid);
960 /* check parameter */
966 /* search the existing watch for the listener */
967 return afb_evt_watch_add_evtid(listener, evtid);
971 * Avoids the 'listener' to watch 'eventid'
972 * Returns 0 in case of success or else -1.
974 int afb_evt_event_x2_remove_watch(struct afb_evt_listener *listener, struct afb_event_x2 *eventid)
976 struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid);
978 /* check parameter */
984 /* search the existing watch */
985 return afb_evt_watch_sub_evtid(listener, evtid);
988 int afb_evt_event_x2_push(struct afb_event_x2 *eventid, struct json_object *object)
991 struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid);
993 return afb_evt_evtid_hooked_push(evtid, object);
994 json_object_put(object);
998 __attribute__((alias("afb_evt_event_x2_unhooked_push")));
1001 int afb_evt_event_x2_unhooked_push(struct afb_event_x2 *eventid, struct json_object *object)
1003 struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid);
1005 return afb_evt_evtid_push(evtid, object);
1006 json_object_put(object);
1010 #if WITH_LEGACY_BINDING_V1 || WITH_LEGACY_BINDING_V2
1011 struct afb_event_x1 afb_evt_event_from_evtid(struct afb_evtid *evtid)
1015 ? (struct afb_event_x1){ .itf = &afb_evt_hooked_event_x2_itf, .closure = &evtid->eventid }
1017 ? (struct afb_event_x1){ .itf = &afb_evt_event_x2_itf, .closure = &evtid->eventid }
1019 : (struct afb_event_x1){ .itf = NULL, .closure = NULL };
1023 void afb_evt_event_x2_unref(struct afb_event_x2 *eventid)
1025 struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid);
1027 afb_evt_evtid_unref(evtid);
1030 struct afb_event_x2 *afb_evt_event_x2_addref(struct afb_event_x2 *eventid)
1032 struct afb_evtid *evtid = afb_evt_event_x2_to_evtid(eventid);
1034 afb_evt_evtid_addref(evtid);