2 * Copyright (C) 2016, 2017 "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.
23 #include "afb-event-itf.h"
24 #include "afb-req-common.h"
25 #include "afb-service-common.h"
26 #include "afb-daemon-common.h"
28 #include "afb-req-v2.h"
29 #include "afb-session-v2.h"
34 * Description of one verb of the API provided by the binding
35 * This enumeration is valid for bindings of type version 2
39 const char *verb; /* name of the verb */
40 void (*callback)(struct afb_req req); /* callback function implementing the verb */
41 const struct afb_auth *auth; /* required authorisation */
42 uint32_t session; /* authorisation and session requirements of the verb */
46 * Description of the bindings of type version 2
50 const char *api; /* api name for the binding */
51 const char *specification; /* textual specification of the binding */
52 const struct afb_verb_v2 *verbs; /* array of descriptions of verbs terminated by a NULL name */
55 void (*onevent)(const char *event, struct json_object *object);
56 unsigned noconcurrency: 1; /* avoids concurrent requests to verbs */
59 struct afb_binding_data_v2
61 int verbosity; /* level of verbosity */
62 struct afb_daemon daemon; /* access to daemon APIs */
63 struct afb_service service; /* access to service APIs */
67 * A binding V2 MUST have two exported symbols of name:
73 #if !defined(AFB_BINDING_MAIN_NAME_V2)
74 extern const struct afb_binding_v2 afbBindingV2;
77 #if !defined(AFB_BINDING_DATA_NAME_V2)
78 #define AFB_BINDING_DATA_NAME_V2 afbBindingV2data
81 #if AFB_BINDING_VERSION != 2
84 struct afb_binding_data_v2 AFB_BINDING_DATA_NAME_V2 __attribute__ ((weak));
86 #define afb_get_verbosity_v2() (AFB_BINDING_DATA_NAME_V2.verbosity)
87 #define afb_get_daemon_v2() (AFB_BINDING_DATA_NAME_V2.daemon)
88 #define afb_get_service_v2() (AFB_BINDING_DATA_NAME_V2.service)
91 * Macros for logging messages
93 #if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO)
94 # if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
95 # define _AFB_LOGGING_V2_(vlevel,llevel,...) \
97 if(AFB_BINDING_DATA_NAME_V2.verbosity>=vlevel) \
98 afb_daemon_verbose_v2(llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
100 # define _AFB_REQ_LOGGING_V2_(vlevel,llevel,req,...) \
102 if(AFB_BINDING_DATA_NAME_V2.verbosity>=vlevel) \
103 afb_req_verbose(req,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
106 # define _AFB_LOGGING_V2_(vlevel,llevel,...) \
108 if(afbBindingV2data.verbosity>=vlevel) \
109 afb_daemon_verbose_v2(llevel,NULL,0,NULL,__VA_ARGS__); \
111 # define _AFB_REQ_LOGGING_V2_(vlevel,llevel,req,...) \
113 if(AFB_BINDING_DATA_NAME_V2.verbosity>=vlevel) \
114 afb_req_verbose(req,llevel,NULL,0,NULL,__VA_ARGS__); \
117 # define AFB_ERROR_V2(...) _AFB_LOGGING_V2_(0,3,__VA_ARGS__)
118 # define AFB_WARNING_V2(...) _AFB_LOGGING_V2_(1,4,__VA_ARGS__)
119 # define AFB_NOTICE_V2(...) _AFB_LOGGING_V2_(1,5,__VA_ARGS__)
120 # define AFB_INFO_V2(...) _AFB_LOGGING_V2_(2,6,__VA_ARGS__)
121 # define AFB_DEBUG_V2(...) _AFB_LOGGING_V2_(3,7,__VA_ARGS__)
122 # define AFB_REQ_ERROR_V2(...) _AFB_REQ_LOGGING_V2_(0,3,__VA_ARGS__)
123 # define AFB_REQ_WARNING_V2(...) _AFB_REQ_LOGGING_V2_(1,4,__VA_ARGS__)
124 # define AFB_REQ_NOTICE_V2(...) _AFB_REQ_LOGGING_V2_(1,5,__VA_ARGS__)
125 # define AFB_REQ_INFO_V2(...) _AFB_REQ_LOGGING_V2_(2,6,__VA_ARGS__)
126 # define AFB_REQ_DEBUG_V2(...) _AFB_REQ_LOGGING_V2_(3,7,__VA_ARGS__)
129 #include "afb-daemon-v2.h"
130 #include "afb-service-v2.h"