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.
22 #include "afb-req-itf.h"
23 #include "afb-event-itf.h"
24 #include "afb-service-common.h"
25 #include "afb-daemon-common.h"
27 #include "afb-session-v1.h"
28 #include "afb-service-v1.h"
29 #include "afb-daemon-v1.h"
31 struct afb_binding_v1;
32 struct afb_binding_interface_v1;
35 * Function for registering the binding
37 * A binding V1 MUST have an exported function of name
39 * afbBindingV1Register
41 * This function is called during loading of the binding. It
42 * receives an 'interface' that should be recorded for later access to
43 * functions provided by the framework.
45 * This function MUST return the address of a structure that describes
46 * the binding and its implemented verbs.
48 * In case of initialisation error, NULL must be returned.
50 * Be aware that the given 'interface' is not fully functionnal
51 * because no provision is given to the name and description
52 * of the binding. Check the function 'afbBindingV1ServiceInit'
53 * defined in the file <afb/afb-service-v1.h> because when
54 * the function 'afbBindingV1ServiceInit' is called, the 'interface'
55 * is fully functionnal.
57 extern const struct afb_binding_v1 *afbBindingV1Register (const struct afb_binding_interface_v1 *interface);
60 * When a binding have an exported implementation of the
61 * function 'afbBindingV1ServiceInit', defined below,
62 * the framework calls it for initialising the service after
63 * registration of all bindings.
65 * The object 'service' should be recorded. It has functions that
66 * allows the binding to call features with its own personality.
68 * The function should return 0 in case of success or, else, should return
71 extern int afbBindingV1ServiceInit(struct afb_service service);
74 * When a binding have an implementation of the function 'afbBindingV1ServiceEvent',
75 * defined below, the framework calls that function for any broadcasted event or for
76 * events that the service subscribed to in its name.
78 * It receive the 'event' name and its related data in 'object' (be aware that 'object'
81 extern void afbBindingV1ServiceEvent(const char *event, struct json_object *object);
85 * Description of one verb of the API provided by the binding
86 * This enumeration is valid for bindings of type version 1
88 struct afb_verb_desc_v1
90 const char *name; /* name of the verb */
91 enum afb_session_flags_v1 session; /* authorisation and session requirements of the verb */
92 void (*callback)(struct afb_req req); /* callback function implementing the verb */
93 const char *info; /* textual description of the verb */
97 * Description of the bindings of type version 1
99 struct afb_binding_desc_v1
101 const char *info; /* textual information about the binding */
102 const char *prefix; /* required prefix name for the binding */
103 const struct afb_verb_desc_v1 *verbs; /* array of descriptions of verbs terminated by a NULL name */
107 * Definition of the type+versions of the binding.
108 * The definition uses hashes.
110 enum afb_binding_type_v1
112 AFB_BINDING_VERSION_1 = 123456789
116 * Description of a binding
118 struct afb_binding_v1
120 enum afb_binding_type_v1 type; /* type of the binding */
122 struct afb_binding_desc_v1 v1; /* description of the binding of type 1 */
131 AFB_MODE_LOCAL = 0, /* run locally */
132 AFB_MODE_REMOTE, /* run remotely */
133 AFB_MODE_GLOBAL /* run either remotely or locally (DONT USE! reserved for future) */
137 * Interface between the daemon and the binding.
139 struct afb_binding_interface_v1
141 struct afb_daemon daemon; /* access to the daemon facilies */
142 int verbosity; /* level of verbosity */
143 enum afb_mode_v1 mode; /* run mode (local or remote) */
147 * Macros for logging messages
149 #if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO)
150 # if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
151 # define _AFB_LOGGING_V1_(itf,vlevel,llevel,...) \
153 if(itf->verbosity>=vlevel) \
154 afb_daemon_verbose2_v1(itf->daemon,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
156 # define _AFB_REQ_LOGGING_V1_(itf,vlevel,llevel,req,...) \
158 if(itf->verbosity>=vlevel) \
159 afb_req_verbose(req,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
162 # define _AFB_LOGGING_V1_(itf,vlevel,llevel,...) \
164 if(itf->verbosity>=vlevel) \
165 afb_daemon_verbose_v1(itf->daemon,llevel,NULL,0,NULL,__VA_ARGS__); \
167 # define _AFB_REQ_LOGGING_V1_(itf,vlevel,llevel,req,...) \
169 if(itf->verbosity>=vlevel) \
170 afb_req_verbose(req,llevel,NULL,0,NULL,__VA_ARGS__); \
173 # define AFB_ERROR_V1(itf,...) _AFB_LOGGING_V1_(itf,0,3,__VA_ARGS__)
174 # define AFB_WARNING_V1(itf,...) _AFB_LOGGING_V1_(itf,1,4,__VA_ARGS__)
175 # define AFB_NOTICE_V1(itf,...) _AFB_LOGGING_V1_(itf,1,5,__VA_ARGS__)
176 # define AFB_INFO_V1(itf,...) _AFB_LOGGING_V1_(itf,2,6,__VA_ARGS__)
177 # define AFB_DEBUG_V1(itf,...) _AFB_LOGGING_V1_(itf,3,7,__VA_ARGS__)
178 # define AFB_REQ_ERROR_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,0,3,__VA_ARGS__)
179 # define AFB_REQ_WARNING_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,1,4,__VA_ARGS__)
180 # define AFB_REQ_NOTICE_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,1,5,__VA_ARGS__)
181 # define AFB_REQ_INFO_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,2,6,__VA_ARGS__)
182 # define AFB_REQ_DEBUG_V1(itf,...) _AFB_REQ_LOGGING_V1_(itf,3,7,__VA_ARGS__)