10690984dac77029fa14414e366765349e8fb0e8
[src/app-framework-main.git] / src / utils-jbus.h
1 /*
2  Copyright 2015 IoT.bzh
3
4  author: José Bollo <jose.bollo@iot.bzh>
5
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9
10      http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 */
18
19 struct jreq;
20 struct jbus;
21 struct pollfd;
22
23 extern struct jbus *create_jbus(const char *path, int session);
24 extern struct jbus *create_jbus_session(const char *path);
25 extern struct jbus *create_jbus_system(const char *path);
26
27 extern void jbus_addref(struct jbus *jbus);
28 extern void jbus_unref(struct jbus *jbus);
29
30 extern int jbus_fill_pollfds(
31                 struct jbus **jbuses,
32                 int njbuses,
33                 struct pollfd *fds);
34
35 extern int jbus_dispatch_pollfds(
36                 struct jbus **jbuses,
37                  int njbuses,
38                  struct pollfd *fds,
39                  int maxcount);
40
41 extern int jbus_read_write_dispatch_multiple(
42                 struct jbus **jbuses,
43                 int njbuses,
44                 int toms,
45                 int maxcount);
46
47 extern int jbus_dispatch_multiple(
48                 struct jbus **jbuses,
49                 int njbuses,
50                 int maxcount);
51
52 extern int jbus_read_write_dispatch(
53                 struct jbus *jbus,
54                 int toms);
55
56
57 /* verbs for the clients */
58 extern int jbus_call_ss(
59                 struct jbus *jbus,
60                 const char *method,
61                 const char *query,
62                 void (*onresp) (int, const char *, void *),
63                 void *data);
64
65 extern int jbus_call_js(
66                 struct jbus *jbus,
67                 const char *method,
68                 struct json_object *query,
69                 void (*onresp) (int, const char *, void *),
70                 void *data);
71
72 extern int jbus_call_sj(
73                 struct jbus *jbus,
74                 const char *method,
75                 const char *query,
76                 void (*onresp) (int, struct json_object *, void *),
77                 void *data);
78
79 extern int jbus_call_jj(
80                 struct jbus *jbus,
81                 const char *method,
82                 struct json_object *query,
83                 void (*onresp) (int, struct json_object *, void *),
84                 void *data);
85
86 extern char *jbus_call_ss_sync(
87                 struct jbus *jbus,
88                 const char *method,
89                 const char *query);
90
91 extern char *jbus_call_js_sync(
92                 struct jbus *jbus,
93                 const char *method,
94                 struct json_object *query);
95
96 extern struct json_object *jbus_call_sj_sync(
97                 struct jbus *jbus,
98                 const char *method,
99                 const char *query);
100
101 extern struct json_object *jbus_call_jj_sync(
102                 struct jbus *jbus,
103                 const char *method,
104                 struct json_object *query);
105
106 extern int jbus_on_signal_s(
107                 struct jbus *jbus,
108                 const char *name,
109                 void (*onsignal) (const char *, void *),
110                 void *data);
111
112 extern int jbus_on_signal_j(
113                 struct jbus *jbus,
114                 const char *name,
115                 void (*onsignal) (struct json_object *, void *),
116                 void *data);
117
118 /* verbs for servers */
119 extern int jbus_reply_s(
120                 struct jreq *jreq,
121                 const char *reply);
122
123 extern int jbus_reply_j(
124                 struct jreq *jreq,
125                 struct json_object *reply);
126
127 extern int jbus_reply_error_s(
128                 struct jreq *jreq,
129                 const char *reply);
130
131 extern int jbus_reply_error_j(
132                 struct jreq *jreq,
133                 struct json_object *reply);
134
135 extern int jbus_add_service_s(
136                 struct jbus *jbus,
137                 const char *method,
138                 void (*oncall) (struct jreq *, const char *, void *),
139                 void *data);
140
141 extern int jbus_add_service_j(
142                 struct jbus *jbus,
143                 const char *method,
144                 void (*oncall) (struct jreq *, struct json_object *, void *),
145                 void *data);
146
147 extern int jbus_start_serving(
148                 struct jbus *jbus);
149
150 extern int jbus_send_signal_s(
151                 struct jbus *jbus,
152                 const char *name,
153                 const char *content);
154
155 extern int jbus_send_signal_j(
156                 struct jbus *jbus,
157                 const char *name,
158                 struct json_object *content);
159