69d82a75030409e883997c97e8f57e26ebd956a4
[src/app-framework-binder.git] / include / afb / afb-eventid.h
1 /*
2  * Copyright (C) 2016, 2017, 2018 "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(
33                         struct afb_eventid *eventid,
34                         struct json_object *object)
35 {
36         return eventid->itf->broadcast(eventid, object);
37 }
38
39 /*
40  * Pushes an event of 'eventid' with the data 'object' to its observers.
41  * 'object' can be NULL.
42  *
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.
46  *
47  * Returns the count of clients that received the event.
48  */
49 static inline int afb_eventid_push(
50                         struct afb_eventid *eventid,
51                         struct json_object *object)
52 {
53         return eventid->itf->push(eventid, object);
54 }
55
56 /*
57  * Gets the name associated to 'eventid'.
58  * The returned name can be used until call to 'afb_eventid_unref'.
59  */
60 static inline const char *afb_eventid_name(struct afb_eventid *eventid)
61 {
62         return eventid->itf->name(eventid);
63 }
64
65 /*
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.
69  */
70 static inline void afb_eventid_unref(struct afb_eventid *eventid)
71 {
72         eventid->itf->unref(eventid);
73 }
74
75 /*
76  * Increases the count of references to 'eventid'
77  */
78 static inline struct afb_eventid *afb_eventid_addref(
79                                         struct afb_eventid *eventid)
80 {
81         return eventid->itf->addref(eventid);
82 }
83