41648c284c8de95e1a2ab12cef4cf4b29b87cd6f
[src/app-framework-binder.git] / include / afb / afb-dynapi-legacy.h
1
2 /*
3  * Copyright (C) 2018, 2019 "IoT.bzh"
4  * Author: José Bollo <jose.bollo@iot.bzh>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *   http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #pragma once
20
21 /***************************************************************************************************/
22
23 #define afb_dynapi                      afb_api_x3
24 #define afb_dynapi_itf                  afb_api_x3_itf
25
26 #define afb_request                     afb_req_x2
27 #define afb_request_get_dynapi          afb_req_x2_get_api
28 #define afb_request_get_vcbdata         afb_req_x2_get_vcbdata
29 #define afb_request_get_api             afb_req_x2_get_called_api
30 #define afb_request_get_verb            afb_req_x2_get_called_verb
31 #define afb_request_wants_log_level     afb_req_x2_wants_log_level
32
33 #define afb_request_get                 afb_req_x2_get
34 #define afb_request_value               afb_req_x2_value
35 #define afb_request_path                afb_req_x2_path
36 #define afb_request_json                afb_req_x2_json
37 #define afb_request_reply               afb_req_x2_reply
38 #define afb_request_reply_f             afb_req_x2_reply_f
39 #define afb_request_reply_v             afb_req_x2_reply_v
40 #define afb_request_success(r,o,i)      afb_req_x2_reply(r,o,0,i)
41 #define afb_request_success_f(r,o,...)  afb_req_x2_reply_f(r,o,0,__VA_ARGS__)
42 #define afb_request_success_v(r,o,f,v)  afb_req_x2_reply_v(r,o,0,f,v)
43 #define afb_request_fail(r,e,i)         afb_req_x2_reply(r,0,e,i)
44 #define afb_request_fail_f(r,e,f,...)   afb_req_x2_reply_f(r,0,e,f,__VA_ARGS__)
45 #define afb_request_fail_v(r,e,f,v)     afb_req_x2_reply_v(r,0,e,f,v)
46 #define afb_request_context_get         afb_req_x2_context_get
47 #define afb_request_context_set         afb_req_x2_context_set
48 #define afb_request_context             afb_req_x2_context
49 #define afb_request_context_clear       afb_req_x2_context_clear
50 #define afb_request_addref              afb_req_x2_addref
51 #define afb_request_unref               afb_req_x2_unref
52 #define afb_request_session_close       afb_req_x2_session_close
53 #define afb_request_session_set_LOA     afb_req_x2_session_set_LOA
54 #define afb_request_subscribe           afb_req_x2_subscribe
55 #define afb_request_unsubscribe         afb_req_x2_unsubscribe
56 #define afb_request_subcall             afb_req_x2_subcall_legacy
57 #define afb_request_subcall_sync        afb_req_x2_subcall_sync_legacy
58 #define afb_request_verbose             afb_req_x2_verbose
59 #define afb_request_has_permission      afb_req_x2_has_permission
60 #define afb_request_get_application_id  afb_req_x2_get_application_id
61 #define afb_request_get_uid             afb_req_x2_get_uid
62 #define afb_request_get_client_info     afb_req_x2_get_client_info
63
64 #define afb_dynapi_name                 afb_api_x3_name
65 #define afb_dynapi_get_userdata         afb_api_x3_get_userdata
66 #define afb_dynapi_set_userdata         afb_api_x3_set_userdata
67 #define afb_dynapi_wants_log_level      afb_api_x3_wants_log_level
68
69 #define afb_dynapi_verbose              afb_api_x3_verbose
70 #define afb_dynapi_vverbose             afb_api_x3_vverbose
71 #define afb_dynapi_get_event_loop       afb_api_x3_get_event_loop
72 #define afb_dynapi_get_user_bus         afb_api_x3_get_user_bus
73 #define afb_dynapi_get_system_bus       afb_api_x3_get_system_bus
74 #define afb_dynapi_rootdir_get_fd       afb_api_x3_rootdir_get_fd
75 #define afb_dynapi_rootdir_open_locale  afb_api_x3_rootdir_open_locale
76 #define afb_dynapi_queue_job            afb_api_x3_queue_job
77 #define afb_dynapi_require_api          afb_api_x3_require_api
78 #define afb_dynapi_rename_api           afb_api_x3_add_alias
79 #define afb_dynapi_broadcast_event      afb_api_x3_broadcast_event
80 #define afb_dynapi_make_eventid         afb_api_x3_make_event_x2
81 #define afb_dynapi_call                 afb_api_x3_call_legacy
82 #define afb_dynapi_call_sync            afb_api_x3_call_sync_legacy
83 #define afb_dynapi_new_api(...)         (-!afb_api_x3_new_api(__VA_ARGS__))
84 #define afb_dynapi_set_verbs_v2         afb_api_x3_set_verbs_v2
85 #define afb_dynapi_add_verb(a,b,c,d,e,f,g)      afb_api_x3_add_verb(a,b,c,d,e,f,g,0)
86 #define afb_dynapi_sub_verb(a,b)        afb_api_x3_del_verb(a,b,NULL)
87 #define afb_dynapi_on_event             afb_api_x3_on_event
88 #define afb_dynapi_on_init              afb_api_x3_on_init
89 #define afb_dynapi_seal                 afb_api_x3_seal
90
91 #define afb_eventid_broadcast           afb_event_x2_broadcast
92 #define afb_eventid_push                afb_event_x2_push
93 #define afb_eventid_name                afb_event_x2_name
94 #define afb_eventid_unref               afb_event_x2_unref
95 #define afb_eventid_addref              afb_event_x2_addref
96
97 #define afb_eventid                     afb_event_x2
98 #define afb_eventid_is_valid            afb_event_x2_is_valid
99 #define afb_eventid_broadcast           afb_event_x2_broadcast
100 #define afb_eventid_push                afb_event_x2_push
101 #define afb_eventid_drop                afb_event_x2_unref
102 #define afb_eventid_name                afb_event_x2_name
103 #define afb_eventid_unref               afb_event_x2_unref
104 #define afb_eventid_addref              afb_event_x2_addref
105
106 /*
107  * The function afbBindingVdyn if exported allows to create
108  * pure dynamic bindings. When the binding is loaded, it receives
109  * a virtual dynapi that can be used to create apis. The
110  * given API can not be used except for creating dynamic apis.
111  */
112 extern int afbBindingVdyn(struct afb_dynapi *dynapi);
113
114 /*
115  * Macros for logging messages
116  */
117 /* macro for setting file, line and function automatically */
118 # if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
119 #define AFB_REQUEST_VERBOSE(req,level,...) afb_req_x2_verbose(req,level,__FILE__,__LINE__,__func__,__VA_ARGS__)
120 #else
121 #define AFB_REQUEST_VERBOSE(req,level,...) afb_req_x2_verbose(req,level,NULL,0,NULL,__VA_ARGS__)
122 #endif
123
124 #if defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DATA)
125
126 # define _AFB_DYNAPI_LOGGING_(llevel,dynapi,...) \
127         do{ \
128                 if(_AFB_SYSLOG_MASK_WANT_(dynapi->logmask,llevel)) {\
129                         if (llevel <= AFB_VERBOSITY_LEVEL_ERROR) \
130                                 afb_dynapi_verbose(dynapi,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
131                         else \
132                                 afb_dynapi_verbose(dynapi,llevel,__FILE__,__LINE__,NULL,NULL); \
133                 } \
134         }while(0)
135 # define _AFB_REQUEST_LOGGING_(llevel,request,...) \
136         do{ \
137                 if(request->_AFB_SYSLOG_MASK_WANT_(dynapi->logmask,llevel)) \
138                         afb_request_verbose(request,llevel,__FILE__,__LINE__,NULL,NULL); \
139         }while(0)
140
141 #elif defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
142
143 # define _AFB_DYNAPI_LOGGING_(llevel,dynapi,...) \
144         do{ \
145                 if(_AFB_SYSLOG_MASK_WANT_(dynapi->logmask,llevel)) \
146                         afb_dynapi_verbose(dynapi,llevel,NULL,0,NULL,__VA_ARGS__); \
147         }while(0)
148 # define _AFB_REQUEST_LOGGING_(llevel,request,...) \
149         do{ \
150                 if(request->_AFB_SYSLOG_MASK_WANT_(dynapi->logmask,llevel)) \
151                         afb_request_verbose(request,llevel,NULL,0,NULL,__VA_ARGS__); \
152         }while(0)
153
154 #else
155
156 # define _AFB_DYNAPI_LOGGING_(llevel,dynapi,...) \
157         do{ \
158                 if(AFB_SYSLOG_MASK_WANT(dynapi->logmask,llevel)) \
159                         afb_dynapi_verbose(dynapi,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
160         }while(0)
161 # define _AFB_REQUEST_LOGGING_(llevel,request,...) \
162         do{ \
163                 if(AFB_SYSLOG_MASK_WANT(request->api->logmask,llevel)) \
164                         afb_request_verbose(request,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
165         }while(0)
166
167 #endif
168
169 #define AFB_DYNAPI_ERROR(...)     _AFB_DYNAPI_LOGGING_(AFB_SYSLOG_LEVEL_ERROR,__VA_ARGS__)
170 #define AFB_DYNAPI_WARNING(...)   _AFB_DYNAPI_LOGGING_(AFB_SYSLOG_LEVEL_WARNING,__VA_ARGS__)
171 #define AFB_DYNAPI_NOTICE(...)    _AFB_DYNAPI_LOGGING_(AFB_SYSLOG_LEVEL_NOTICE,__VA_ARGS__)
172 #define AFB_DYNAPI_INFO(...)      _AFB_DYNAPI_LOGGING_(AFB_SYSLOG_LEVEL_INFO,__VA_ARGS__)
173 #define AFB_DYNAPI_DEBUG(...)     _AFB_DYNAPI_LOGGING_(AFB_SYSLOG_LEVEL_DEBUG,__VA_ARGS__)
174 #define AFB_REQUEST_ERROR(...)    _AFB_REQUEST_LOGGING_(AFB_SYSLOG_LEVEL_ERROR,__VA_ARGS__)
175 #define AFB_REQUEST_WARNING(...)  _AFB_REQUEST_LOGGING_(AFB_SYSLOG_LEVEL_WARNING,__VA_ARGS__)
176 #define AFB_REQUEST_NOTICE(...)   _AFB_REQUEST_LOGGING_(AFB_SYSLOG_LEVEL_NOTICE,__VA_ARGS__)
177 #define AFB_REQUEST_INFO(...)     _AFB_REQUEST_LOGGING_(AFB_SYSLOG_LEVEL_INFO,__VA_ARGS__)
178 #define AFB_REQUEST_DEBUG(...)    _AFB_REQUEST_LOGGING_(AFB_SYSLOG_LEVEL_DEBUG,__VA_ARGS__)
179
180 typedef struct afb_eventid afb_eventid;
181 typedef struct afb_dynapi afb_dynapi;
182 typedef struct afb_request afb_request;
183
184 #define _AFB_SYSLOG_LEVEL_EMERGENCY_    AFB_SYSLOG_LEVEL_EMERGENCY
185 #define _AFB_SYSLOG_LEVEL_ALERT_        AFB_SYSLOG_LEVEL_ALERT
186 #define _AFB_SYSLOG_LEVEL_CRITICAL_     AFB_SYSLOG_LEVEL_CRITICAL
187 #define _AFB_SYSLOG_LEVEL_ERROR_        AFB_SYSLOG_LEVEL_ERROR
188 #define _AFB_SYSLOG_LEVEL_WARNING_      AFB_SYSLOG_LEVEL_WARNING
189 #define _AFB_SYSLOG_LEVEL_NOTICE_       AFB_SYSLOG_LEVEL_NOTICE
190 #define _AFB_SYSLOG_LEVEL_INFO_         AFB_SYSLOG_LEVEL_INFO
191 #define _AFB_SYSLOG_LEVEL_DEBUG_        AFB_SYSLOG_LEVEL_DEBUG