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.
22 struct afb_api_x3_itf;
34 * Structure for the APIv3
41 * Don't use it directly, prefer helper functions.
43 const struct afb_api_x3_itf *itf;
48 * @see afb_api_x3_name
55 * @see afb_api_x3_set_userdata
56 * @see afb_api_x3_get_userdata
61 * Current verbosity mask
63 * The bits tells what verbosity is required for the api.
64 * It is related to the syslog levels.
66 * EMERGENCY 0 System is unusable
67 * ALERT 1 Action must be taken immediately
68 * CRITICAL 2 Critical conditions
69 * ERROR 3 Error conditions
70 * WARNING 4 Warning conditions
71 * NOTICE 5 Normal but significant condition
72 * INFO 6 Informational
73 * DEBUG 7 Debug-level messages
79 * Definition of the function's interface for the APIv3
83 /* CAUTION: respect the order, add at the end */
85 /** sending log messages */
87 struct afb_api_x3 *api,
95 /** gets the common systemd's event loop */
96 struct sd_event *(*get_event_loop)(
97 struct afb_api_x3 *api);
99 /** gets the common systemd's user d-bus */
100 struct sd_bus *(*get_user_bus)(
101 struct afb_api_x3 *api);
103 /** gets the common systemd's system d-bus */
104 struct sd_bus *(*get_system_bus)(
105 struct afb_api_x3 *api);
107 /** get the file descriptor for the root directory */
108 int (*rootdir_get_fd)(
109 struct afb_api_x3 *api);
111 /** get a file using locale setting */
112 int (*rootdir_open_locale)(
113 struct afb_api_x3 *api,
114 const char *filename,
120 struct afb_api_x3 *api,
121 void (*callback)(int signum, void *arg),
126 /** requires an api initialized or not */
128 struct afb_api_x3 *api,
134 struct afb_api_x3 *api,
136 const char *as_name);
138 /** broadcasts event 'name' with 'object' */
139 int (*event_broadcast)(
140 struct afb_api_x3 *api,
142 struct json_object *object);
144 /** creates an event of 'name' */
145 struct afb_event_x2 *(*event_make)(
146 struct afb_api_x3 *api,
149 /** legacy asynchronous invocation */
151 struct afb_api_x3 *api,
154 struct json_object *args,
155 void (*callback)(void*, int, struct json_object*, struct afb_api_x3 *),
158 /** legacy synchronous invocation */
159 int (*legacy_call_sync)(
160 struct afb_api_x3 *api,
163 struct json_object *args,
164 struct json_object **result);
166 /** creation of a new api*/
167 struct afb_api_x3 *(*api_new_api)(
168 struct afb_api_x3 *api,
172 int (*preinit)(void*, struct afb_api_x3 *),
175 /** set verbs of the api using v2 description */
176 int (*api_set_verbs_v2)(
177 struct afb_api_x3 *api,
178 const struct afb_verb_v2 *verbs);
180 /** add one verb to the api */
182 struct afb_api_x3 *api,
185 void (*callback)(struct afb_req_x2 *req),
187 const struct afb_auth *auth,
191 /** delete one verb of the api */
193 struct afb_api_x3 *api,
197 /** set the api's callback for processing events */
198 int (*api_set_on_event)(
199 struct afb_api_x3 *api,
200 void (*onevent)(struct afb_api_x3 *api, const char *event, struct json_object *object));
202 /** set the api's callback for initialisation */
203 int (*api_set_on_init)(
204 struct afb_api_x3 *api,
205 int (*oninit)(struct afb_api_x3 *api));
209 struct afb_api_x3 *api);
211 /** set verbs of the api using v3 description */
212 int (*api_set_verbs_v3)(
213 struct afb_api_x3 *api,
214 const struct afb_verb_v3 *verbs);
216 /** add an event handler for the api */
217 int (*event_handler_add)(
218 struct afb_api_x3 *api,
220 void (*callback)(void *, const char*, struct json_object*, struct afb_api_x3*),
223 /** delete an event handler of the api */
224 int (*event_handler_del)(
225 struct afb_api_x3 *api,
229 /** asynchronous call for the api */
231 struct afb_api_x3 *api,
234 struct json_object *args,
235 void (*callback)(void*, struct json_object*, const char*, const char*, struct afb_api_x3 *),
238 /** synchronous call for the api */
240 struct afb_api_x3 *api,
243 struct json_object *args,
244 struct json_object **result,
248 /** indicate provided classes of the api */
249 int (*class_provide)(
250 struct afb_api_x3 *api,
253 /** indicate required classes of the api */
254 int (*class_require)(
255 struct afb_api_x3 *api,
258 /** delete the api */
260 struct afb_api_x3 *api);