Allow dynamic creation of APIs
[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 #include "afb-binding-vdyn.h"
71
72 typedef struct afb_verb_desc_v1         afb_verb_desc_v1;
73 typedef struct afb_binding_desc_v1      afb_binding_desc_v1;
74 typedef struct afb_binding_v1           afb_binding_v1;
75 typedef struct afb_binding_interface_v1 afb_binding_interface_v1;
76
77 typedef struct afb_verb_v2              afb_verb_v2;
78 typedef struct afb_binding_v2           afb_binding_v2;
79
80 typedef enum   afb_auth_type            afb_auth_type;
81 typedef struct afb_auth                 afb_auth;
82 typedef struct afb_daemon               afb_daemon;
83 typedef struct afb_event                afb_event;
84 typedef struct afb_arg                  afb_arg;
85 typedef struct afb_req                  afb_req;
86 typedef struct afb_stored_req           afb_stored_req;
87 typedef struct afb_service              afb_service;
88
89 typedef struct afb_dynapi               afb_dynapi;
90 typedef struct afb_request              afb_request;
91 typedef struct afb_eventid              afb_eventid;
92
93 #if 0
94 /* these typedef's shouldn't be needed */
95 typedef enum   afb_binding_type_v1      afb_binding_type_v1;
96 typedef enum   afb_mode_v1              afb_mode_v1;
97 typedef enum   afb_session_flags_v1     afb_session_flags_v1;
98 typedef enum   afb_session_flags_v2     afb_session_flags_v2;
99 typedef struct afb_binding_data_v2      afb_binding_data_v2;
100 typedef struct afb_daemon_itf           afb_daemon_itf;
101 typedef struct afb_event_itf            afb_event_itf;
102 typedef struct afb_req_itf              afb_req_itf;
103 typedef struct afb_service_itf          afb_service_itf;
104 #endif
105
106 /***************************************************************************************************/
107
108 #if AFB_BINDING_VERSION == 1
109
110 # define afb_binding            afb_binding_v1
111 # define afb_binding_interface  afb_binding_interface_v1
112
113 # define AFB_SESSION_NONE       AFB_SESSION_NONE_V1
114 # define AFB_SESSION_CREATE     AFB_SESSION_CREATE_V1
115 # define AFB_SESSION_CLOSE      AFB_SESSION_CLOSE_V1
116 # define AFB_SESSION_RENEW      AFB_SESSION_RENEW_V1
117 # define AFB_SESSION_CHECK      AFB_SESSION_CHECK_V1
118
119 # define AFB_SESSION_LOA_GE     AFB_SESSION_LOA_GE_V1
120 # define AFB_SESSION_LOA_LE     AFB_SESSION_LOA_LE_V1
121 # define AFB_SESSION_LOA_EQ     AFB_SESSION_LOA_EQ_V1
122
123 # define AFB_SESSION_LOA_SHIFT  AFB_SESSION_LOA_SHIFT_V1
124 # define AFB_SESSION_LOA_MASK   AFB_SESSION_LOA_MASK_V1
125
126 # define AFB_SESSION_LOA_0      AFB_SESSION_LOA_0_V1
127 # define AFB_SESSION_LOA_1      AFB_SESSION_LOA_1_V1
128 # define AFB_SESSION_LOA_2      AFB_SESSION_LOA_2_V1
129 # define AFB_SESSION_LOA_3      AFB_SESSION_LOA_3_V1
130 # define AFB_SESSION_LOA_4      AFB_SESSION_LOA_4_V1
131
132 # define AFB_SESSION_LOA_LE_0   AFB_SESSION_LOA_LE_0_V1
133 # define AFB_SESSION_LOA_LE_1   AFB_SESSION_LOA_LE_1_V1
134 # define AFB_SESSION_LOA_LE_2   AFB_SESSION_LOA_LE_2_V1
135 # define AFB_SESSION_LOA_LE_3   AFB_SESSION_LOA_LE_3_V1
136
137 # define AFB_SESSION_LOA_EQ_0   AFB_SESSION_LOA_EQ_0_V1
138 # define AFB_SESSION_LOA_EQ_1   AFB_SESSION_LOA_EQ_1_V1
139 # define AFB_SESSION_LOA_EQ_2   AFB_SESSION_LOA_EQ_2_V1
140 # define AFB_SESSION_LOA_EQ_3   AFB_SESSION_LOA_EQ_3_V1
141
142 # define AFB_SESSION_LOA_GE_0   AFB_SESSION_LOA_GE_0_V1
143 # define AFB_SESSION_LOA_GE_1   AFB_SESSION_LOA_GE_1_V1
144 # define AFB_SESSION_LOA_GE_2   AFB_SESSION_LOA_GE_2_V1
145 # define AFB_SESSION_LOA_GE_3   AFB_SESSION_LOA_GE_3_V1
146
147 # define AFB_ERROR              AFB_ERROR_V1
148 # define AFB_WARNING            AFB_WARNING_V1
149 # define AFB_NOTICE             AFB_NOTICE_V1
150 # define AFB_INFO               AFB_INFO_V1
151 # define AFB_DEBUG              AFB_DEBUG_V1
152
153 # define AFB_REQ_ERROR          AFB_REQ_ERROR_V1
154 # define AFB_REQ_WARNING        AFB_REQ_WARNING_V1
155 # define AFB_REQ_NOTICE         AFB_REQ_NOTICE_V1
156 # define AFB_REQ_INFO           AFB_REQ_INFO_V1
157 # define AFB_REQ_DEBUG          AFB_REQ_DEBUG_V1
158
159 #define afb_daemon_get_event_loop       afb_daemon_get_event_loop_v1
160 #define afb_daemon_get_user_bus         afb_daemon_get_user_bus_v1
161 #define afb_daemon_get_system_bus       afb_daemon_get_system_bus_v1
162 #define afb_daemon_broadcast_event      afb_daemon_broadcast_event_v1
163 #define afb_daemon_make_event           afb_daemon_make_event_v1
164 #define afb_daemon_verbose              afb_daemon_verbose_v1
165 #define afb_daemon_rootdir_get_fd       afb_daemon_rootdir_get_fd_v1
166 #define afb_daemon_rootdir_open_locale  afb_daemon_rootdir_open_locale_v1
167 #define afb_daemon_queue_job            afb_daemon_queue_job_v1
168 #define afb_daemon_require_api          afb_daemon_require_api_v1
169 #define afb_daemon_rename_api           afb_daemon_rename_api_v1
170
171 #define afb_service_call                afb_service_call_v1
172 #define afb_service_call_sync           afb_service_call_sync_v1
173
174 #define afb_req_store                   afb_req_store_v1
175 #define afb_req_unstore                 afb_req_unstore_v1
176
177 #endif
178
179 /***************************************************************************************************/
180
181 #if AFB_BINDING_VERSION == 2
182
183 # define afb_binding            afb_binding_v2
184 # define afb_get_verbosity      afb_get_verbosity_v2
185 # define afb_get_daemon         afb_get_daemon_v2
186 # define afb_get_service        afb_get_service_v2
187
188
189 # define AFB_SESSION_NONE       AFB_SESSION_NONE_V2
190 # define AFB_SESSION_CLOSE      AFB_SESSION_CLOSE_V2
191 # define AFB_SESSION_RENEW      AFB_SESSION_REFRESH_V2
192 # define AFB_SESSION_REFRESH    AFB_SESSION_REFRESH_V2
193 # define AFB_SESSION_CHECK      AFB_SESSION_CHECK_V2
194
195 # define AFB_SESSION_LOA_MASK   AFB_SESSION_LOA_MASK_V2
196
197 # define AFB_SESSION_LOA_0      AFB_SESSION_LOA_0_V2
198 # define AFB_SESSION_LOA_1      AFB_SESSION_LOA_1_V2
199 # define AFB_SESSION_LOA_2      AFB_SESSION_LOA_2_V2
200 # define AFB_SESSION_LOA_3      AFB_SESSION_LOA_3_V2
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 #define afb_daemon_get_event_loop       afb_daemon_get_event_loop_v2
215 #define afb_daemon_get_user_bus         afb_daemon_get_user_bus_v2
216 #define afb_daemon_get_system_bus       afb_daemon_get_system_bus_v2
217 #define afb_daemon_broadcast_event      afb_daemon_broadcast_event_v2
218 #define afb_daemon_make_event           afb_daemon_make_event_v2
219 #define afb_daemon_verbose              afb_daemon_verbose_v2
220 #define afb_daemon_rootdir_get_fd       afb_daemon_rootdir_get_fd_v2
221 #define afb_daemon_rootdir_open_locale  afb_daemon_rootdir_open_locale_v2
222 #define afb_daemon_queue_job            afb_daemon_queue_job_v2
223 #define afb_daemon_unstore_req          afb_daemon_unstore_req_v2
224 #define afb_daemon_require_api          afb_daemon_require_api_v2
225 #define afb_daemon_rename_api           afb_daemon_rename_api_v2
226
227 #define afb_service_call                afb_service_call_v2
228 #define afb_service_call_sync           afb_service_call_sync_v2
229
230 #define afb_req_store                   afb_req_store_v2
231 #define afb_req_unstore                 afb_daemon_unstore_req_v2
232
233 #endif
234
235 /***************************************************************************************************/
236
237 #if AFB_BINDING_VERSION >= 2
238
239 # define afb_verbose_error()    (afb_get_verbosity() >= AFB_VERBOSITY_LEVEL_ERROR)
240 # define afb_verbose_warning()  (afb_get_verbosity() >= AFB_VERBOSITY_LEVEL_WARNING)
241 # define afb_verbose_notice()   (afb_get_verbosity() >= AFB_VERBOSITY_LEVEL_NOTICE)
242 # define afb_verbose_info()     (afb_get_verbosity() >= AFB_VERBOSITY_LEVEL_INFO)
243 # define afb_verbose_debug()    (afb_get_verbosity() >= AFB_VERBOSITY_LEVEL_DEBUG)
244
245 #endif
246
247 /***************************************************************************************************/
248
249 #if defined(AFB_BINDING_PRAGMA_KEEP_VERBOSE_UNPREFIX)
250 # define ERROR                  AFB_ERROR
251 # define WARNING                AFB_WARNING
252 # define NOTICE                 AFB_NOTICE
253 # define INFO                   AFB_INFO
254 # define DEBUG                  AFB_DEBUG
255
256 # define REQ_ERROR              AFB_REQ_ERROR
257 # define REQ_WARNING            AFB_REQ_WARNING
258 # define REQ_NOTICE             AFB_REQ_NOTICE
259 # define REQ_INFO               AFB_REQ_INFO
260 # define REQ_DEBUG              AFB_REQ_DEBUG
261 #endif
262