Introduce afb_eventid
[src/app-framework-binder.git] / include / afb / afb-eventid.h
1 /*
2  * Copyright (C) 2016, 2017 "IoT.bzh"
3  * Author: José Bollo <jose.bollo@iot.bzh>
4  *
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
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #pragma once
19
20 #include "afb-eventid-itf.h"
21
22 /*
23  * Broadcasts widely an event of 'eventid' with the data 'object'.
24  * 'object' can be NULL.
25  *
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.
29  *
30  * Returns the count of clients that received the event.
31  */
32 static inline int afb_eventid_broadcast(struct afb_eventid *eventid, struct json_object *object)
33 {
34         return eventid->itf->broadcast(eventid, object);
35 }
36
37 /*
38  * Pushes an event of 'eventid' with the data 'object' to its observers.
39  * 'object' can be NULL.
40  *
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.
44  *
45  * Returns the count of clients that received the event.
46  */
47 static inline int afb_eventid_push(struct afb_eventid *eventid, struct json_object *object)
48 {
49         return eventid->itf->push(eventid, object);
50 }
51
52 /*
53  * Gets the name associated to 'eventid'.
54  */
55 static inline const char *afb_eventid_name(struct afb_eventid *eventid)
56 {
57         return eventid->itf->name(eventid);
58 }
59
60 /*
61  * Decrease the count of reference to 'eventid' and
62  * destroys the eventid when the reference count falls to zero.
63  */
64 static inline void afb_eventid_unref(struct afb_eventid *eventid)
65 {
66         eventid->itf->unref(eventid);
67 }
68
69 /*
70  * Increases the count of reference to 'eventid'
71  */
72 static inline struct afb_eventid *afb_eventid_addref(struct afb_eventid *eventid)
73 {
74         return eventid->itf->addref(eventid);
75 }
76