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"
23 * Checks whether the 'event' is valid or not.
25 * @param event the event to check
27 * @return 0 if not valid or 1 if valid.
29 static inline int afb_event_x2_is_valid(struct afb_event_x2 *event)
35 * Broadcasts widely an event of 'event' with the data 'object'.
36 * 'object' can be NULL.
38 * For convenience, the function calls 'json_object_put' for 'object'.
39 * Thus, in the case where 'object' should remain available after
40 * the function returns, the function 'json_object_get' shall be used.
42 * @param event the event to broadcast
43 * @param object the companion object to associate to the broadcasted event (can be NULL)
45 * @return the count of clients that received the event.
47 static inline int afb_event_x2_broadcast(
48 struct afb_event_x2 *event,
49 struct json_object *object)
51 return event->itf->broadcast(event, object);
55 * Pushes an event of 'event' with the data 'object' to its observers.
56 * 'object' can be NULL.
58 * For convenience, the function calls 'json_object_put' for 'object'.
59 * Thus, in the case where 'object' should remain available after
60 * the function returns, the function 'json_object_get' shall be used.
62 * @param event the event to push
63 * @param object the companion object to associate to the pushed event (can be NULL)
65 * @return the count of clients that received the event.
67 static inline int afb_event_x2_push(
68 struct afb_event_x2 *event,
69 struct json_object *object)
71 return event->itf->push(event, object);
75 * Gets the name associated to 'event'.
77 * @param event the event whose name is requested
79 * @return the name of the event
81 * The returned name can be used until call to 'afb_event_x2_unref'.
82 * It shouldn't be freed.
84 static inline const char *afb_event_x2_name(struct afb_event_x2 *event)
86 return event->itf->name(event);
90 * Decrease the count of references to 'event'.
91 * Call this function when the evenid is no more used.
92 * It destroys the event_x2 when the reference count falls to zero.
94 * @param event the event
96 static inline void afb_event_x2_unref(struct afb_event_x2 *event)
98 event->itf->unref(event);
102 * Increases the count of references to 'event'
104 * @param event the event
108 static inline struct afb_event_x2 *afb_event_x2_addref(
109 struct afb_event_x2 *event)
111 return event->itf->addref(event);