api-v3: First draft
[src/app-framework-binder.git] / include / afb / afb-daemon-v1.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-daemon-itf-x1.h"
21
22 /**
23  * @deprecated use bindings version 3
24  *
25  * Retrieves the common systemd's event loop of AFB
26  * 'daemon' MUST be the daemon given in interface when activating the binding.
27  */
28 static inline struct sd_event *afb_daemon_get_event_loop_v1(struct afb_daemon_x1 daemon)
29 {
30         return daemon.itf->get_event_loop(daemon.closure);
31 }
32
33 /**
34  * @deprecated use bindings version 3
35  *
36  * Retrieves the common systemd's user/session d-bus of AFB
37  * 'daemon' MUST be the daemon given in interface when activating the binding.
38  */
39 static inline struct sd_bus *afb_daemon_get_user_bus_v1(struct afb_daemon_x1 daemon)
40 {
41         return daemon.itf->get_user_bus(daemon.closure);
42 }
43
44 /**
45  * @deprecated use bindings version 3
46  *
47  * Retrieves the common systemd's system d-bus of AFB
48  * 'daemon' MUST be the daemon given in interface when activating the binding.
49  */
50 static inline struct sd_bus *afb_daemon_get_system_bus_v1(struct afb_daemon_x1 daemon)
51 {
52         return daemon.itf->get_system_bus(daemon.closure);
53 }
54
55 /**
56  * @deprecated use bindings version 3
57  *
58  * Broadcasts widely the event of 'name' with the data 'object'.
59  * 'object' can be NULL.
60  * 'daemon' MUST be the daemon given in interface when activating the binding.
61  *
62  * For convenience, the function calls 'json_object_put' for 'object'.
63  * Thus, in the case where 'object' should remain available after
64  * the function returns, the function 'json_object_get' shall be used.
65  *
66  * Calling this function is only forbidden during preinit.
67  *
68  * Returns the count of clients that received the event.
69  */
70 static inline int afb_daemon_broadcast_event_v1(struct afb_daemon_x1 daemon, const char *name, struct json_object *object)
71 {
72         return daemon.itf->event_broadcast(daemon.closure, name, object);
73 }
74
75 /**
76  * @deprecated use bindings version 3
77  *
78  * Creates an event of 'name' and returns it.
79  * 'daemon' MUST be the daemon given in interface when activating the binding.
80  *
81  * Calling this function is only forbidden during preinit.
82  *
83  * See afb_event_is_valid to check if there is an error.
84  */
85 static inline struct afb_event_x1 afb_daemon_make_event_v1(struct afb_daemon_x1 daemon, const char *name)
86 {
87         return daemon.itf->event_make(daemon.closure, name);
88 }
89
90 /**
91  * @deprecated use bindings version 3
92  *
93  * Send a message described by 'fmt' and following parameters
94  * to the journal for the verbosity 'level'.
95  *
96  * 'file' and 'line' are indicators of position of the code in source files
97  * (see macros __FILE__ and __LINE__).
98  *
99  * 'daemon' MUST be the daemon given in interface when activating the binding.
100  *
101  * 'level' is defined by syslog standard:
102  *      EMERGENCY         0        System is unusable
103  *      ALERT             1        Action must be taken immediately
104  *      CRITICAL          2        Critical conditions
105  *      ERROR             3        Error conditions
106  *      WARNING           4        Warning conditions
107  *      NOTICE            5        Normal but significant condition
108  *      INFO              6        Informational
109  *      DEBUG             7        Debug-level messages
110  */
111 static inline void afb_daemon_verbose_v1(struct afb_daemon_x1 daemon, int level, const char *file, int line, const char *fmt, ...) __attribute__((format(printf, 5, 6)));
112 static inline void afb_daemon_verbose_v1(struct afb_daemon_x1 daemon, int level, const char *file, int line, const char *fmt, ...)
113 {
114         va_list args;
115         va_start(args, fmt);
116         daemon.itf->vverbose_v1(daemon.closure, level, file, line, fmt, args);
117         va_end(args);
118 }
119
120 /**
121  * @deprecated use bindings version 3
122  *
123  * Send a message described by 'fmt' and following parameters
124  * to the journal for the verbosity 'level'.
125  *
126  * 'file', 'line' and 'func' are indicators of position of the code in source files
127  * (see macros __FILE__, __LINE__ and __func__).
128  *
129  * 'daemon' MUST be the daemon given in interface when activating the binding.
130  *
131  * 'level' is defined by syslog standard:
132  *      EMERGENCY         0        System is unusable
133  *      ALERT             1        Action must be taken immediately
134  *      CRITICAL          2        Critical conditions
135  *      ERROR             3        Error conditions
136  *      WARNING           4        Warning conditions
137  *      NOTICE            5        Normal but significant condition
138  *      INFO              6        Informational
139  *      DEBUG             7        Debug-level messages
140  */
141 static inline void afb_daemon_verbose2_v1(struct afb_daemon_x1 daemon, int level, const char *file, int line, const char *func, const char *fmt, ...) __attribute__((format(printf, 6, 7)));
142 static inline void afb_daemon_verbose2_v1(struct afb_daemon_x1 daemon, int level, const char *file, int line, const char *func, const char *fmt, ...)
143 {
144         va_list args;
145         va_start(args, fmt);
146         daemon.itf->vverbose_v2(daemon.closure, level, file, line, func, fmt, args);
147         va_end(args);
148 }
149
150 /**
151  * @deprecated use bindings version 3
152  *
153  * Get the root directory file descriptor. This file descriptor can
154  * be used with functions 'openat', 'fstatat', ...
155  *
156  * Returns the file descriptor or -1 in case of error.
157  */
158 static inline int afb_daemon_rootdir_get_fd_v1(struct afb_daemon_x1 daemon)
159 {
160         return daemon.itf->rootdir_get_fd(daemon.closure);
161 }
162
163 /**
164  * @deprecated use bindings version 3
165  *
166  * using the 'locale' definition (example: "jp,en-US") that can be NULL.
167  *
168  * Returns the file descriptor or -1 in case of error.
169  */
170 static inline int afb_daemon_rootdir_open_locale_v1(struct afb_daemon_x1 daemon, const char *filename, int flags, const char *locale)
171 {
172         return daemon.itf->rootdir_open_locale(daemon.closure, filename, flags, locale);
173 }
174
175 /**
176  * @deprecated use bindings version 3
177  *
178  * Queue the job defined by 'callback' and 'argument' for being executed asynchronously
179  * in this thread (later) or in an other thread.
180  * If 'group' is not NUL, the jobs queued with a same value (as the pointer value 'group')
181  * are executed in sequence in the order of there submission.
182  * If 'timeout' is not 0, it represent the maximum execution time for the job in seconds.
183  * At first, the job is called with 0 as signum and the given argument.
184  * The job is executed with the monitoring of its time and some signals like SIGSEGV and
185  * SIGFPE. When a such signal is catched, the job is terminated and reexecuted but with
186  * signum being the signal number (SIGALRM when timeout expired).
187  *
188  * Returns 0 in case of success or -1 in case of error.
189  */
190 static inline int afb_daemon_queue_job_v1(struct afb_daemon_x1 daemon, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout)
191 {
192         return daemon.itf->queue_job(daemon.closure, callback, argument, group, timeout);
193 }
194
195 /**
196  * @deprecated use bindings version 3
197  *
198  * Tells that it requires the API of "name" to exist
199  * and if 'initialized' is not null to be initialized.
200  * Calling this function is only allowed within init.
201  *
202  * Returns 0 in case of success or -1 in case of error.
203  */
204 static inline int afb_daemon_require_api_v1(struct afb_daemon_x1 daemon, const char *name, int initialized)
205 {
206         return daemon.itf->require_api(daemon.closure, name, initialized);
207 }
208
209 /**
210  * @deprecated use bindings version 3
211  *
212  * Create an aliased name 'as_name' for the api 'name'.
213  * Calling this function is only allowed within preinit.
214  *
215  * Returns 0 in case of success or -1 in case of error.
216  */
217 static inline int afb_daemon_add_alias_v1(struct afb_daemon_x1 daemon, const char *name, const char *as_name)
218 {
219         return daemon.itf->add_alias(daemon.closure, name, as_name);
220 }
221
222 /**
223  * @deprecated use bindings version 3
224  *
225  * Creates a new api of name 'api' with brief 'info'.
226  *
227  * Returns 0 in case of success or -1 in case of error.
228  */
229 static inline int afb_daemon_new_api_v1(
230         struct afb_daemon_x1 daemon,
231         const char *api,
232         const char *info,
233         int noconcurrency,
234         int (*preinit)(void*, struct afb_api_x3 *),
235         void *closure)
236 {
237         return -!daemon.itf->new_api(daemon.closure, api, info, noconcurrency, preinit, closure);
238 }