2 * Copyright (C) 2016, 2017, 2018 "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.
20 #include "afb-event-x2-itf.h"
22 /** @defgroup AFB_EVENT
26 * Checks whether the 'event' is valid or not.
28 * @param event the event to check
30 * @return 0 if not valid or 1 if valid.
32 static inline int afb_event_x2_is_valid(struct afb_event_x2 *event)
38 * Broadcasts widely an event of 'event' with the data 'object'.
39 * 'object' can be NULL.
41 * For convenience, the function calls 'json_object_put' for 'object'.
42 * Thus, in the case where 'object' should remain available after
43 * the function returns, the function 'json_object_get' shall be used.
45 * @param event the event to broadcast
46 * @param object the companion object to associate to the broadcasted event (can be NULL)
48 * @return the count of clients that received the event.
50 static inline int afb_event_x2_broadcast(
51 struct afb_event_x2 *event,
52 struct json_object *object)
54 return event->itf->broadcast(event, object);
58 * Pushes an event of 'event' with the data 'object' to its observers.
59 * 'object' can be NULL.
61 * For convenience, the function calls 'json_object_put' for 'object'.
62 * Thus, in the case where 'object' should remain available after
63 * the function returns, the function 'json_object_get' shall be used.
65 * @param event the event to push
66 * @param object the companion object to associate to the pushed event (can be NULL)
68 * @return the count of clients that received the event.
70 static inline int afb_event_x2_push(
71 struct afb_event_x2 *event,
72 struct json_object *object)
74 return event->itf->push(event, object);
78 * Gets the name associated to 'event'.
80 * @param event the event whose name is requested
82 * @return the name of the event
84 * The returned name can be used until call to 'afb_event_x2_unref'.
85 * It shouldn't be freed.
87 static inline const char *afb_event_x2_name(struct afb_event_x2 *event)
89 return event->itf->name(event);
93 * Decrease the count of references to 'event'.
94 * Call this function when the evenid is no more used.
95 * It destroys the event_x2 when the reference count falls to zero.
97 * @param event the event
99 static inline void afb_event_x2_unref(struct afb_event_x2 *event)
101 event->itf->unref(event);
105 * Increases the count of references to 'event'
107 * @param event the event
111 static inline struct afb_event_x2 *afb_event_x2_addref(
112 struct afb_event_x2 *event)
114 return event->itf->addref(event);