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