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.
23 #include "afb-event.h"
24 #include "afb-service-itf.h"
25 #include "afb-daemon-itf.h"
27 #include "afb-req-v1.h"
28 #include "afb-session-v1.h"
29 #include "afb-service-v1.h"
30 #include "afb-daemon-v1.h"
32 struct afb_binding_v1;
33 struct afb_binding_interface_v1;
36 * Function for registering the binding
38 * A binding V1 MUST have an exported function of name
40 * afbBindingV1Register
42 * This function is called during loading of the binding. It
43 * receives an 'interface' that should be recorded for later access to
44 * functions provided by the framework.
46 * This function MUST return the address of a structure that describes
47 * the binding and its implemented verbs.
49 * In case of initialisation error, NULL must be returned.
51 * Be aware that the given 'interface' is not fully functionnal
52 * because no provision is given to the name and description
53 * of the binding. Check the function 'afbBindingV1ServiceInit'
54 * defined in the file <afb/afb-service-v1.h> because when
55 * the function 'afbBindingV1ServiceInit' is called, the 'interface'
56 * is fully functionnal.
58 extern const struct afb_binding_v1 *afbBindingV1Register (const struct afb_binding_interface_v1 *interface);
61 * When a binding have an exported implementation of the
62 * function 'afbBindingV1ServiceInit', defined below,
63 * the framework calls it for initialising the service after
64 * registration of all bindings.
66 * The object 'service' should be recorded. It has functions that
67 * allows the binding to call features with its own personality.
69 * The function should return 0 in case of success or, else, should return
72 extern int afbBindingV1ServiceInit(struct afb_service service);
75 * When a binding have an implementation of the function 'afbBindingV1ServiceEvent',
76 * defined below, the framework calls that function for any broadcasted event or for
77 * events that the service subscribed to in its name.
79 * It receive the 'event' name and its related data in 'object' (be aware that 'object'
82 extern void afbBindingV1ServiceEvent(const char *event, struct json_object *object);
86 * Description of one verb of the API provided by the binding
87 * This enumeration is valid for bindings of type version 1
89 struct afb_verb_desc_v1
91 const char *name; /* name of the verb */
92 enum afb_session_flags_v1 session; /* authorisation and session requirements of the verb */
93 void (*callback)(struct afb_req req); /* callback function implementing the verb */
94 const char *info; /* textual description of the verb */
98 * Description of the bindings of type version 1
100 struct afb_binding_desc_v1
102 const char *info; /* textual information about the binding */
103 const char *prefix; /* required prefix name for the binding */
104 const struct afb_verb_desc_v1 *verbs; /* array of descriptions of verbs terminated by a NULL name */
108 * Definition of the type+versions of the binding.
109 * The definition uses hashes.
111 enum afb_binding_type_v1
113 AFB_BINDING_VERSION_1 = 123456789
117 * Description of a binding
119 struct afb_binding_v1
121 enum afb_binding_type_v1 type; /* type of the binding */
123 struct afb_binding_desc_v1 v1; /* description of the binding of type 1 */
132 AFB_MODE_LOCAL = 0, /* run locally */
133 AFB_MODE_REMOTE, /* run remotely */
134 AFB_MODE_GLOBAL /* run either remotely or locally (DONT USE! reserved for future) */
138 * Interface between the daemon and the binding.
140 struct afb_binding_interface_v1
142 struct afb_daemon daemon; /* access to the daemon facilies */
143 int verbosity; /* level of verbosity */
144 enum afb_mode_v1 mode; /* run mode (local or remote) */
148 * Macros for logging messages
150 #if defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DATA)
152 # define _AFB_LOGGING_V1_(itf,vlevel,llevel,...) \
154 if(itf->verbosity>=vlevel) {\
155 if (llevel <= AFB_VERBOSITY_LEVEL_ERROR) \
156 afb_daemon_verbose2_v1(itf->daemon,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
158 afb_daemon_verbose2_v1(itf->daemon,llevel,__FILE__,__LINE__,NULL,NULL); \
161 # define _AFB_REQ_LOGGING_V1_(itf,vlevel,llevel,req,...) \
163 if(itf->verbosity>=vlevel) \
164 afb_req_verbose(req,llevel,__FILE__,__LINE__,NULL,NULL); \
167 #elif defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
169 # define _AFB_LOGGING_V1_(itf,vlevel,llevel,...) \
171 if(itf->verbosity>=vlevel) \
172 afb_daemon_verbose2_v1(itf->daemon,llevel,NULL,0,NULL,__VA_ARGS__); \
174 # define _AFB_REQ_LOGGING_V1_(itf,vlevel,llevel,req,...) \
176 if(itf->verbosity>=vlevel) \
177 afb_req_verbose(req,llevel,NULL,0,NULL,__VA_ARGS__); \
182 # define _AFB_LOGGING_V1_(itf,vlevel,llevel,...) \
184 if(itf->verbosity>=vlevel) \
185 afb_daemon_verbose2_v1(itf->daemon,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
187 # define _AFB_REQ_LOGGING_V1_(itf,vlevel,llevel,req,...) \
189 if(itf->verbosity>=vlevel) \
190 afb_req_verbose(req,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
195 # include "afb-verbosity.h"
196 # define AFB_ERROR_V1(itf,...) _AFB_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_ERROR,_AFB_SYSLOG_LEVEL_ERROR_,__VA_ARGS__)
197 # define AFB_WARNING_V1(itf,...) _AFB_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_WARNING,_AFB_SYSLOG_LEVEL_WARNING_,__VA_ARGS__)
198 # define AFB_NOTICE_V1(itf,...) _AFB_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_NOTICE,_AFB_SYSLOG_LEVEL_NOTICE_,__VA_ARGS__)
199 # define AFB_INFO_V1(itf,...) _AFB_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_INFO,_AFB_SYSLOG_LEVEL_INFO_,__VA_ARGS__)
200 # define AFB_DEBUG_V1(itf,...) _AFB_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_DEBUG,_AFB_SYSLOG_LEVEL_DEBUG_,__VA_ARGS__)
201 # define AFB_REQ_ERROR_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_ERROR,_AFB_SYSLOG_LEVEL_ERROR_,__VA_ARGS__)
202 # define AFB_REQ_WARNING_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_WARNING,_AFB_SYSLOG_LEVEL_WARNING_,__VA_ARGS__)
203 # define AFB_REQ_NOTICE_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_NOTICE,_AFB_SYSLOG_LEVEL_NOTICE_,__VA_ARGS__)
204 # define AFB_REQ_INFO_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_INFO,_AFB_SYSLOG_LEVEL_INFO_,__VA_ARGS__)
205 # define AFB_REQ_DEBUG_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,AFB_VERBOSITY_LEVEL_DEBUG,_AFB_SYSLOG_LEVEL_DEBUG_,__VA_ARGS__)