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;
33 /** @addtogroup AFB_API
37 * Structure for the APIv3
44 * Don't use it directly, prefer helper functions.
46 const struct afb_api_x3_itf *itf;
51 * @see afb_api_x3_name
58 * @see afb_api_x3_set_userdata
59 * @see afb_api_x3_get_userdata
64 * Current verbosity mask
66 * The bits tells what verbosity is required for the api.
67 * It is related to the syslog levels.
69 * EMERGENCY 0 System is unusable
70 * ALERT 1 Action must be taken immediately
71 * CRITICAL 2 Critical conditions
72 * ERROR 3 Error conditions
73 * WARNING 4 Warning conditions
74 * NOTICE 5 Normal but significant condition
75 * INFO 6 Informational
76 * DEBUG 7 Debug-level messages
82 * Definition of the function's interface for the APIv3
86 /* CAUTION: respect the order, add at the end */
88 /** sending log messages */
90 struct afb_api_x3 *api,
98 /** gets the common systemd's event loop */
99 struct sd_event *(*get_event_loop)(
100 struct afb_api_x3 *api);
102 /** gets the common systemd's user d-bus */
103 struct sd_bus *(*get_user_bus)(
104 struct afb_api_x3 *api);
106 /** gets the common systemd's system d-bus */
107 struct sd_bus *(*get_system_bus)(
108 struct afb_api_x3 *api);
110 /** get the file descriptor for the root directory */
111 int (*rootdir_get_fd)(
112 struct afb_api_x3 *api);
114 /** get a file using locale setting */
115 int (*rootdir_open_locale)(
116 struct afb_api_x3 *api,
117 const char *filename,
123 struct afb_api_x3 *api,
124 void (*callback)(int signum, void *arg),
129 /** requires an api initialized or not */
131 struct afb_api_x3 *api,
137 struct afb_api_x3 *api,
139 const char *as_name);
141 /** broadcasts event 'name' with 'object' */
142 int (*event_broadcast)(
143 struct afb_api_x3 *api,
145 struct json_object *object);
147 /** creates an event of 'name' */
148 struct afb_event_x2 *(*event_make)(
149 struct afb_api_x3 *api,
152 /** legacy asynchronous invocation */
154 struct afb_api_x3 *api,
157 struct json_object *args,
158 void (*callback)(void*, int, struct json_object*, struct afb_api_x3 *),
161 /** legacy synchronous invocation */
162 int (*legacy_call_sync)(
163 struct afb_api_x3 *api,
166 struct json_object *args,
167 struct json_object **result);
169 /** creation of a new api*/
170 struct afb_api_x3 *(*api_new_api)(
171 struct afb_api_x3 *api,
175 int (*preinit)(void*, struct afb_api_x3 *),
178 /** set verbs of the api using v2 description */
179 int (*api_set_verbs_v2)(
180 struct afb_api_x3 *api,
181 const struct afb_verb_v2 *verbs);
183 /** add one verb to the api */
185 struct afb_api_x3 *api,
188 void (*callback)(struct afb_req_x2 *req),
190 const struct afb_auth *auth,
194 /** delete one verb of the api */
196 struct afb_api_x3 *api,
200 /** set the api's callback for processing events */
201 int (*api_set_on_event)(
202 struct afb_api_x3 *api,
203 void (*onevent)(struct afb_api_x3 *api, const char *event, struct json_object *object));
205 /** set the api's callback for initialisation */
206 int (*api_set_on_init)(
207 struct afb_api_x3 *api,
208 int (*oninit)(struct afb_api_x3 *api));
212 struct afb_api_x3 *api);
214 /** set verbs of the api using v3 description */
215 int (*api_set_verbs_v3)(
216 struct afb_api_x3 *api,
217 const struct afb_verb_v3 *verbs);
219 /** add an event handler for the api */
220 int (*event_handler_add)(
221 struct afb_api_x3 *api,
223 void (*callback)(void *, const char*, struct json_object*, struct afb_api_x3*),
226 /** delete an event handler of the api */
227 int (*event_handler_del)(
228 struct afb_api_x3 *api,
232 /** asynchronous call for the api */
234 struct afb_api_x3 *api,
237 struct json_object *args,
238 void (*callback)(void*, struct json_object*, const char*, const char*, struct afb_api_x3 *),
241 /** synchronous call for the api */
243 struct afb_api_x3 *api,
246 struct json_object *args,
247 struct json_object **result,
251 /** indicate provided classes of the api */
252 int (*class_provide)(
253 struct afb_api_x3 *api,
256 /** indicate required classes of the api */
257 int (*class_require)(
258 struct afb_api_x3 *api,
261 /** delete the api */
263 struct afb_api_x3 *api);
265 /** settings of the api */
266 struct json_object *(*settings)(
267 struct afb_api_x3 *api);