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-eventid-itf.h"
23 * Broadcasts widely an event of 'eventid' with the data 'object'.
24 * 'object' can be NULL.
26 * For convenience, the function calls 'json_object_put' for 'object'.
27 * Thus, in the case where 'object' should remain available after
28 * the function returns, the function 'json_object_get' shall be used.
30 * Returns the count of clients that received the event.
32 static inline int afb_eventid_broadcast(
33 struct afb_eventid *eventid,
34 struct json_object *object)
36 return eventid->itf->broadcast(eventid, object);
40 * Pushes an event of 'eventid' with the data 'object' to its observers.
41 * 'object' can be NULL.
43 * For convenience, the function calls 'json_object_put' for 'object'.
44 * Thus, in the case where 'object' should remain available after
45 * the function returns, the function 'json_object_get' shall be used.
47 * Returns the count of clients that received the event.
49 static inline int afb_eventid_push(
50 struct afb_eventid *eventid,
51 struct json_object *object)
53 return eventid->itf->push(eventid, object);
57 * Gets the name associated to 'eventid'.
58 * The returned name can be used until call to 'afb_eventid_unref'.
60 static inline const char *afb_eventid_name(struct afb_eventid *eventid)
62 return eventid->itf->name(eventid);
66 * Decrease the count of references to 'eventid'.
67 * Call this function when the evenid is no more used.
68 * It destroys the eventid when the reference count falls to zero.
70 static inline void afb_eventid_unref(struct afb_eventid *eventid)
72 eventid->itf->unref(eventid);
76 * Increases the count of references to 'eventid'
78 static inline struct afb_eventid *afb_eventid_addref(
79 struct afb_eventid *eventid)
81 return eventid->itf->addref(eventid);