2 * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
3 * Author: José Bollo <jose.bollo@iot.bzh>
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 /******************************************************************************/
22 #include "afb-verbosity.h"
24 #include "afb-event-x1.h"
25 #include "afb-req-x1.h"
26 #include "afb-service-itf-x1.h"
27 #include "afb-daemon-itf-x1.h"
29 #include "afb-req-v2.h"
30 #include "afb-session-x2.h"
32 /******************************************************************************/
35 * @deprecated use bindings version 3
37 * Description of one verb as provided for binding API version 2
41 const char *verb; /**< name of the verb, NULL only at end of the array */
42 void (*callback)(struct afb_req_x1 req);/**< callback function implementing the verb */
43 const struct afb_auth *auth; /**< required authorisation, can be NULL */
44 const char *info; /**< some info about the verb, can be NULL */
45 uint32_t session; /**< authorisation and session requirements of the verb */
49 * @deprecated use bindings version 3
51 * Description of the bindings of type version 2
55 const char *api; /**< api name for the binding */
56 const char *specification; /**< textual specification of the binding, can be NULL */
57 const char *info; /**< some info about the api, can be NULL */
58 const struct afb_verb_v2 *verbs; /**< array of descriptions of verbs terminated by a NULL name */
59 int (*preinit)(); /**< callback at load of the binding */
60 int (*init)(); /**< callback for starting the service */
61 void (*onevent)(const char *event, struct json_object *object); /**< callback for handling events */
62 unsigned noconcurrency: 1; /**< avoids concurrent requests to verbs */
66 * @deprecated use bindings version 3
68 * structure for the global data of the binding
70 struct afb_binding_data_v2
72 int verbosity; /**< level of verbosity */
73 struct afb_daemon_x1 daemon; /**< access to daemon APIs */
74 struct afb_service_x1 service; /**< access to service APIs */
78 * @page validity-v2 Validity of a binding v2
80 * A binding V2 MUST have two exported symbols of name:
83 * - @ref afbBindingV2data
87 * @deprecated use bindings version 3
89 * The global mandatory description of the binding
91 #if !defined(AFB_BINDING_MAIN_NAME_V2)
92 extern const struct afb_binding_v2 afbBindingV2;
96 * @deprecated use bindings version 3
98 * The global auto declared internal data of the binding
100 #if AFB_BINDING_VERSION != 2
103 struct afb_binding_data_v2 afbBindingV2data __attribute__ ((weak));
105 #define afb_get_verbosity_v2() (afbBindingV2data.verbosity)
106 #define afb_get_daemon_v2() (afbBindingV2data.daemon)
107 #define afb_get_service_v2() (afbBindingV2data.service)
109 /******************************************************************************/
111 * Macros for logging messages
113 #if defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DATA)
115 #define AFB_VERBOSE_V2(level,...) \
116 do { if(level <= AFB_VERBOSITY_LEVEL_ERROR) \
117 afb_daemon_verbose_v2(level,__FILE__,__LINE__,NULL,__VA_ARGS__); \
118 else afb_daemon_verbose_v2(level,__FILE__,__LINE__,NULL); } while(0)
120 #define AFB_REQ_VERBOSE_V2(req,level,...) \
121 do { if(level <= AFB_VERBOSITY_LEVEL_ERROR) \
122 afb_req_x1_verbose(req,level,__FILE__,__LINE__,NULL,__VA_ARGS__); \
123 else afb_req_x1_verbose(req,level,__FILE__,__LINE__,NULL); } while(0)
125 #elif defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
127 #define AFB_VERBOSE_V2(level,...) \
128 afb_daemon_verbose_v2(level,NULL,0,NULL,__VA_ARGS__)
130 #define AFB_REQ_VERBOSE_V2(req,level,...) \
131 afb_req_x1_verbose(req,level,NULL,0,NULL,__VA_ARGS__)
135 #define AFB_VERBOSE_V2(level,...) \
136 afb_daemon_verbose_v2(level,__FILE__,__LINE__,__func__,__VA_ARGS__)
138 #define AFB_REQ_VERBOSE_V2(req,level,...) \
139 afb_req_x1_verbose(req,level,__FILE__,__LINE__,__func__,__VA_ARGS__)
143 #define _AFB_LOGGING_V2_(vlevel,llevel,...) \
144 do{ if(afb_get_verbosity_v2()>=vlevel) AFB_VERBOSE_V2(llevel,__VA_ARGS__); } while(0)
145 #define _AFB_REQ_LOGGING_V2_(vlevel,llevel,req,...) \
146 do{ if(afb_get_verbosity_v2()>=vlevel) AFB_REQ_VERBOSE_V2(req,llevel,__VA_ARGS__); } while(0)
148 #define AFB_ERROR_V2(...) _AFB_LOGGING_V2_(AFB_VERBOSITY_LEVEL_ERROR,AFB_SYSLOG_LEVEL_ERROR,__VA_ARGS__)
149 #define AFB_WARNING_V2(...) _AFB_LOGGING_V2_(AFB_VERBOSITY_LEVEL_WARNING,AFB_SYSLOG_LEVEL_WARNING,__VA_ARGS__)
150 #define AFB_NOTICE_V2(...) _AFB_LOGGING_V2_(AFB_VERBOSITY_LEVEL_NOTICE,AFB_SYSLOG_LEVEL_NOTICE,__VA_ARGS__)
151 #define AFB_INFO_V2(...) _AFB_LOGGING_V2_(AFB_VERBOSITY_LEVEL_INFO,AFB_SYSLOG_LEVEL_INFO,__VA_ARGS__)
152 #define AFB_DEBUG_V2(...) _AFB_LOGGING_V2_(AFB_VERBOSITY_LEVEL_DEBUG,AFB_SYSLOG_LEVEL_DEBUG,__VA_ARGS__)
153 #define AFB_REQ_ERROR_V2(...) _AFB_REQ_LOGGING_V2_(AFB_VERBOSITY_LEVEL_ERROR,AFB_SYSLOG_LEVEL_ERROR,__VA_ARGS__)
154 #define AFB_REQ_WARNING_V2(...) _AFB_REQ_LOGGING_V2_(AFB_VERBOSITY_LEVEL_WARNING,AFB_SYSLOG_LEVEL_WARNING,__VA_ARGS__)
155 #define AFB_REQ_NOTICE_V2(...) _AFB_REQ_LOGGING_V2_(AFB_VERBOSITY_LEVEL_NOTICE,AFB_SYSLOG_LEVEL_NOTICE,__VA_ARGS__)
156 #define AFB_REQ_INFO_V2(...) _AFB_REQ_LOGGING_V2_(AFB_VERBOSITY_LEVEL_INFO,AFB_SYSLOG_LEVEL_INFO,__VA_ARGS__)
157 #define AFB_REQ_DEBUG_V2(...) _AFB_REQ_LOGGING_V2_(AFB_VERBOSITY_LEVEL_DEBUG,AFB_SYSLOG_LEVEL_DEBUG,__VA_ARGS__)
159 /******************************************************************************/
161 #if 0 && AFB_BINDING_VERSION >= 2
163 # define afb_verbose_error() (afb_get_verbosity() >= AFB_VERBOSITY_LEVEL_ERROR)
164 # define afb_verbose_warning() (afb_get_verbosity() >= AFB_VERBOSITY_LEVEL_WARNING)
165 # define afb_verbose_notice() (afb_get_verbosity() >= AFB_VERBOSITY_LEVEL_NOTICE)
166 # define afb_verbose_info() (afb_get_verbosity() >= AFB_VERBOSITY_LEVEL_INFO)
167 # define afb_verbose_debug() (afb_get_verbosity() >= AFB_VERBOSITY_LEVEL_DEBUG)
171 #include "afb-daemon-v2.h"
172 #include "afb-service-v2.h"