Bindings V2: enforce prefix AFB_ to logging macros
[src/app-framework-binder.git] / include / afb / afb-binding.h
1 /*
2  * Copyright (C) 2016, 2017 "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 <stdarg.h>
21
22 /*****************************************************************************
23  * This files is the main file to include for writing bindings dedicated to
24  *
25  *                      AFB-DAEMON
26  *
27  * Functions of bindings of afb-daemon are accessible by authorized clients
28  * through the apis module of afb-daemon.
29  */
30
31 #define AFB_BINDING_LOWER_VERSION     1
32 #define AFB_BINDING_UPPER_VERSION     2
33
34 #ifndef AFB_BINDING_VERSION
35 #define AFB_BINDING_VERSION   1
36 #pragma GCC warning "\
37 \n\
38 \n\
39   AFB_BINDING_VERSION should be defined before including <afb/afb-binding.h>\n\
40   AFB_BINDING_VERSION defines the version of binding that you use.\n\
41   Currently, known versions are 1 or 2.\n\
42   Setting now AFB_BINDING_VERSION to 1 (version 1 by default)\n\
43   NOTE THAT VERSION 2 IS NOW RECOMMENDED!\n\
44   Consider to add one of the following define before including <afb/afb-binding.h>:\n\
45 \n\
46     #define AFB_BINDING_VERSION 1\n\
47     #define AFB_BINDING_VERSION 2\n\
48 \n\
49   Note that in some case it will enforce you to include <stdio.h>\n\
50 "
51 #include <stdio.h> /* old version side effect */
52 #else
53 #  if AFB_BINDING_VERSION == 1
54 #    pragma GCC warning "Using binding version 1, consider to switch to version 2"
55 #  endif
56 #endif
57
58 #if AFB_BINDING_VERSION != 0
59 # if AFB_BINDING_VERSION < AFB_BINDING_LOWER_VERSION || AFB_BINDING_VERSION > AFB_BINDING_UPPER_VERSION
60 #  error "Unsupported binding version AFB_BINDING_VERSION " #AFB_BINDING_VERSION
61 # endif
62 #endif
63
64 /*
65  * Some function of the library are exported to afb-daemon.
66  */
67
68 #include "afb-binding-v1.h"
69 #include "afb-binding-v2.h"
70
71 typedef struct afb_verb_desc_v1         afb_verb_desc_v1;
72 typedef struct afb_binding_desc_v1      afb_binding_desc_v1;
73 typedef struct afb_binding_v1           afb_binding_v1;
74 typedef struct afb_binding_interface_v1 afb_binding_interface_v1;
75
76 typedef struct afb_verb_v2              afb_verb_v2;
77 typedef struct afb_binding_v2           afb_binding_v2;
78
79 typedef enum   afb_auth_type            afb_auth_type;
80 typedef struct afb_auth                 afb_auth;
81 typedef struct afb_daemon               afb_daemon;
82 typedef struct afb_event                afb_event;
83 typedef struct afb_arg                  afb_arg;
84 typedef struct afb_req                  afb_req;
85 typedef struct afb_stored_req           afb_stored_req;
86 typedef struct afb_service              afb_service;
87
88 #if 0
89 /* these typedef's shouldn't be needed */
90 typedef enum   afb_binding_type_v1      afb_binding_type_v1;
91 typedef enum   afb_mode_v1              afb_mode_v1;
92 typedef enum   afb_session_flags_v1     afb_session_flags_v1;
93 typedef enum   afb_session_flags_v2     afb_session_flags_v2;
94 typedef struct afb_binding_data_v2      afb_binding_data_v2;
95 typedef struct afb_daemon_itf           afb_daemon_itf;
96 typedef struct afb_event_itf            afb_event_itf;
97 typedef struct afb_req_itf              afb_req_itf;
98 typedef struct afb_service_itf          afb_service_itf;
99 #endif
100
101 /***************************************************************************************************/
102
103 #if AFB_BINDING_VERSION == 1
104
105 # define afb_binding            afb_binding_v1
106 # define afb_binding_interface  afb_binding_interface_v1
107
108 # define AFB_SESSION_NONE       AFB_SESSION_NONE_V1
109 # define AFB_SESSION_CREATE     AFB_SESSION_CREATE_V1
110 # define AFB_SESSION_CLOSE      AFB_SESSION_CLOSE_V1
111 # define AFB_SESSION_RENEW      AFB_SESSION_RENEW_V1
112 # define AFB_SESSION_CHECK      AFB_SESSION_CHECK_V1
113
114 # define AFB_SESSION_LOA_GE     AFB_SESSION_LOA_GE_V1
115 # define AFB_SESSION_LOA_LE     AFB_SESSION_LOA_LE_V1
116 # define AFB_SESSION_LOA_EQ     AFB_SESSION_LOA_EQ_V1
117
118 # define AFB_SESSION_LOA_SHIFT  AFB_SESSION_LOA_SHIFT_V1
119 # define AFB_SESSION_LOA_MASK   AFB_SESSION_LOA_MASK_V1
120
121 # define AFB_SESSION_LOA_0      AFB_SESSION_LOA_0_V1
122 # define AFB_SESSION_LOA_1      AFB_SESSION_LOA_1_V1
123 # define AFB_SESSION_LOA_2      AFB_SESSION_LOA_2_V1
124 # define AFB_SESSION_LOA_3      AFB_SESSION_LOA_3_V1
125 # define AFB_SESSION_LOA_4      AFB_SESSION_LOA_4_V1
126
127 # define AFB_SESSION_LOA_LE_0   AFB_SESSION_LOA_LE_0_V1
128 # define AFB_SESSION_LOA_LE_1   AFB_SESSION_LOA_LE_1_V1
129 # define AFB_SESSION_LOA_LE_2   AFB_SESSION_LOA_LE_2_V1
130 # define AFB_SESSION_LOA_LE_3   AFB_SESSION_LOA_LE_3_V1
131
132 # define AFB_SESSION_LOA_EQ_0   AFB_SESSION_LOA_EQ_0_V1
133 # define AFB_SESSION_LOA_EQ_1   AFB_SESSION_LOA_EQ_1_V1
134 # define AFB_SESSION_LOA_EQ_2   AFB_SESSION_LOA_EQ_2_V1
135 # define AFB_SESSION_LOA_EQ_3   AFB_SESSION_LOA_EQ_3_V1
136
137 # define AFB_SESSION_LOA_GE_0   AFB_SESSION_LOA_GE_0_V1
138 # define AFB_SESSION_LOA_GE_1   AFB_SESSION_LOA_GE_1_V1
139 # define AFB_SESSION_LOA_GE_2   AFB_SESSION_LOA_GE_2_V1
140 # define AFB_SESSION_LOA_GE_3   AFB_SESSION_LOA_GE_3_V1
141
142 # if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO)
143
144 #  define AFB_ERROR             AFB_ERROR_V1
145 #  define AFB_WARNING           AFB_WARNING_V1
146 #  define AFB_NOTICE            AFB_NOTICE_V1
147 #  define AFB_INFO              AFB_INFO_V1
148 #  define AFB_DEBUG             AFB_DEBUG_V1
149
150 #  define AFB_REQ_ERROR         AFB_REQ_ERROR_V1
151 #  define AFB_REQ_WARNING       AFB_REQ_WARNING_V1
152 #  define AFB_REQ_NOTICE        AFB_REQ_NOTICE_V1
153 #  define AFB_REQ_INFO          AFB_REQ_INFO_V1
154 #  define AFB_REQ_DEBUG         AFB_REQ_DEBUG_V1
155
156 # endif
157
158 #define afb_daemon_get_event_loop       afb_daemon_get_event_loop_v1
159 #define afb_daemon_get_user_bus         afb_daemon_get_user_bus_v1
160 #define afb_daemon_get_system_bus       afb_daemon_get_system_bus_v1
161 #define afb_daemon_broadcast_event      afb_daemon_broadcast_event_v1
162 #define afb_daemon_make_event           afb_daemon_make_event_v1
163 #define afb_daemon_verbose              afb_daemon_verbose_v1
164 #define afb_daemon_rootdir_get_fd       afb_daemon_rootdir_get_fd_v1
165 #define afb_daemon_rootdir_open_locale  afb_daemon_rootdir_open_locale_v1
166 #define afb_daemon_queue_job            afb_daemon_queue_job_v1
167 #define afb_daemon_require_api          afb_daemon_require_api_v1
168
169 #define afb_service_call                afb_service_call_v1
170 #define afb_service_call_sync           afb_service_call_sync_v1
171
172 #define afb_req_store                   afb_req_store_v1
173 #define afb_req_unstore                 afb_req_unstore_v1
174
175 #endif
176
177 /***************************************************************************************************/
178
179 #if AFB_BINDING_VERSION == 2
180
181 # define afb_binding            afb_binding_v2
182 # define afb_get_verbosity      afb_get_verbosity_v2
183 # define afb_get_daemon         afb_get_daemon_v2
184 # define afb_get_service        afb_get_service_v2
185
186
187 # define AFB_SESSION_NONE       AFB_SESSION_NONE_V2
188 # define AFB_SESSION_CLOSE      AFB_SESSION_CLOSE_V2
189 # define AFB_SESSION_RENEW      AFB_SESSION_REFRESH_V2
190 # define AFB_SESSION_REFRESH    AFB_SESSION_REFRESH_V2
191 # define AFB_SESSION_CHECK      AFB_SESSION_CHECK_V2
192
193 # define AFB_SESSION_LOA_MASK   AFB_SESSION_LOA_MASK_V2
194
195 # define AFB_SESSION_LOA_0      AFB_SESSION_LOA_0_V2
196 # define AFB_SESSION_LOA_1      AFB_SESSION_LOA_1_V2
197 # define AFB_SESSION_LOA_2      AFB_SESSION_LOA_2_V2
198 # define AFB_SESSION_LOA_3      AFB_SESSION_LOA_3_V2
199
200 # if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO)
201
202 #  define AFB_ERROR             AFB_ERROR_V2
203 #  define AFB_WARNING           AFB_WARNING_V2
204 #  define AFB_NOTICE            AFB_NOTICE_V2
205 #  define AFB_INFO              AFB_INFO_V2
206 #  define AFB_DEBUG             AFB_DEBUG_V2
207
208 #  define AFB_REQ_ERROR         AFB_REQ_ERROR_V2
209 #  define AFB_REQ_WARNING       AFB_REQ_WARNING_V2
210 #  define AFB_REQ_NOTICE        AFB_REQ_NOTICE_V2
211 #  define AFB_REQ_INFO          AFB_REQ_INFO_V2
212 #  define AFB_REQ_DEBUG         AFB_REQ_DEBUG_V2
213
214 # endif
215
216 #define afb_daemon_get_event_loop       afb_daemon_get_event_loop_v2
217 #define afb_daemon_get_user_bus         afb_daemon_get_user_bus_v2
218 #define afb_daemon_get_system_bus       afb_daemon_get_system_bus_v2
219 #define afb_daemon_broadcast_event      afb_daemon_broadcast_event_v2
220 #define afb_daemon_make_event           afb_daemon_make_event_v2
221 #define afb_daemon_verbose              afb_daemon_verbose_v2
222 #define afb_daemon_rootdir_get_fd       afb_daemon_rootdir_get_fd_v2
223 #define afb_daemon_rootdir_open_locale  afb_daemon_rootdir_open_locale_v2
224 #define afb_daemon_queue_job            afb_daemon_queue_job_v2
225 #define afb_daemon_unstore_req          afb_daemon_unstore_req_v2
226 #define afb_daemon_require_api          afb_daemon_require_api_v2
227
228 #define afb_service_call                afb_service_call_v2
229 #define afb_service_call_sync           afb_service_call_sync_v2
230
231 #define afb_req_store                   afb_req_store_v2
232 #define afb_req_unstore                 afb_daemon_unstore_req_v2
233
234 #endif
235
236 /***************************************************************************************************/
237
238 #if AFB_BINDING_VERSION >= 2
239
240 # define afb_verbose_error()    (afb_get_verbosity() >= 0)
241 # define afb_verbose_warning()  (afb_get_verbosity() >= 1)
242 # define afb_verbose_notice()   (afb_get_verbosity() >= 1)
243 # define afb_verbose_info()     (afb_get_verbosity() >= 2)
244 # define afb_verbose_debug()    (afb_get_verbosity() >= 3)
245
246 # if !defined(AFB_BINDING_PRAGMA_KEEP_VERBOSE_UNPREFIX) && !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_UNPREFIX)
247 #  define AFB_BINDING_PRAGMA_NO_VERBOSE_UNPREFIX
248 # endif
249 #endif
250
251 /***************************************************************************************************/
252
253 #if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_UNPREFIX)
254 # if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO)
255 #  define ERROR                 AFB_ERROR
256 #  define WARNING               AFB_WARNING
257 #  define NOTICE                AFB_NOTICE
258 #  define INFO                  AFB_INFO
259 #  define DEBUG                 AFB_DEBUG
260
261 #  define REQ_ERROR             AFB_REQ_ERROR
262 #  define REQ_WARNING           AFB_REQ_WARNING
263 #  define REQ_NOTICE            AFB_REQ_NOTICE
264 #  define REQ_INFO              AFB_REQ_INFO
265 #  define REQ_DEBUG             AFB_REQ_DEBUG
266 # endif
267 #endif
268