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 struct afb_binding_v1;
23 struct afb_binding_interface_v1;
26 * Function for registering the binding
28 * A binding V1 MUST have an exported function of name
30 * afbBindingV1Register
32 * This function is called during loading of the binding. It
33 * receives an 'interface' that should be recorded for later access to
34 * functions provided by the framework.
36 * This function MUST return the address of a structure that describes
37 * the binding and its implemented verbs.
39 * In case of initialisation error, NULL must be returned.
41 * Be aware that the given 'interface' is not fully functionnal
42 * because no provision is given to the name and description
43 * of the binding. Check the function 'afbBindingV1ServiceInit'
44 * defined in the file <afb/afb-service-itf.h> because when
45 * the function 'afbBindingV1ServiceInit' is called, the 'interface'
46 * is fully functionnal.
48 extern const struct afb_binding_v1 *afbBindingV1Register (const struct afb_binding_interface_v1 *interface);
51 * When a binding have an exported implementation of the
52 * function 'afbBindingV1ServiceInit', defined below,
53 * the framework calls it for initialising the service after
54 * registration of all bindings.
56 * The object 'service' should be recorded. It has functions that
57 * allows the binding to call features with its own personality.
59 * The function should return 0 in case of success or, else, should return
62 extern int afbBindingV1ServiceInit(struct afb_service service);
65 * When a binding have an implementation of the function 'afbBindingV1ServiceEvent',
66 * defined below, the framework calls that function for any broadcasted event or for
67 * events that the service subscribed to in its name.
69 * It receive the 'event' name and its related data in 'object' (be aware that 'object'
72 extern void afbBindingV1ServiceEvent(const char *event, struct json_object *object);
76 * Description of one verb of the API provided by the binding
77 * This enumeration is valid for bindings of type version 1
79 struct afb_verb_desc_v1
81 const char *name; /* name of the verb */
82 enum afb_session_flags session; /* authorisation and session requirements of the verb */
83 void (*callback)(struct afb_req req); /* callback function implementing the verb */
84 const char *info; /* textual description of the verb */
88 * Description of the bindings of type version 1
90 struct afb_binding_desc_v1
92 const char *info; /* textual information about the binding */
93 const char *prefix; /* required prefix name for the binding */
94 const struct afb_verb_desc_v1 *verbs; /* array of descriptions of verbs terminated by a NULL name */
98 * Definition of the type+versions of the binding.
99 * The definition uses hashes.
101 enum afb_binding_type_v1
103 AFB_BINDING_VERSION_1 = 123456789
107 * Description of a binding
109 struct afb_binding_v1
111 enum afb_binding_type_v1 type; /* type of the binding */
113 struct afb_binding_desc_v1 v1; /* description of the binding of type 1 */
121 AFB_MODE_LOCAL = 0, /* run locally */
122 AFB_MODE_REMOTE, /* run remotely */
123 AFB_MODE_GLOBAL /* run either remotely or locally (DONT USE! reserved for future) */
127 * Interface between the daemon and the binding.
129 struct afb_binding_interface_v1
131 struct afb_daemon daemon; /* access to the daemon facilies */
132 int verbosity; /* level of verbosity */
133 enum afb_mode_v1 mode; /* run mode (local or remote) */
137 * Macros for logging messages
139 #if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO)
140 # if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
141 # define AFB_ERROR_V1(itf,...) do{if(itf->verbosity>=0)afb_daemon_verbose(itf->daemon,3,__FILE__,__LINE__,__VA_ARGS__);}while(0)
142 # define AFB_WARNING_V1(itf,...) do{if(itf->verbosity>=1)afb_daemon_verbose(itf->daemon,4,__FILE__,__LINE__,__VA_ARGS__);}while(0)
143 # define AFB_NOTICE_V1(itf,...) do{if(itf->verbosity>=1)afb_daemon_verbose(itf->daemon,5,__FILE__,__LINE__,__VA_ARGS__);}while(0)
144 # define AFB_INFO_V1(itf,...) do{if(itf->verbosity>=2)afb_daemon_verbose(itf->daemon,6,__FILE__,__LINE__,__VA_ARGS__);}while(0)
145 # define AFB_DEBUG_V1(itf,...) do{if(itf->verbosity>=3)afb_daemon_verbose(itf->daemon,7,__FILE__,__LINE__,__VA_ARGS__);}while(0)
147 # define AFB_ERROR_V1(itf,...) do{if(itf->verbosity>=0)afb_daemon_verbose(itf->daemon,3,NULL,0,__VA_ARGS__);}while(0)
148 # define AFB_WARNING_V1(itf,...) do{if(itf->verbosity>=1)afb_daemon_verbose(itf->daemon,4,NULL,0,__VA_ARGS__);}while(0)
149 # define AFB_NOTICE_V1(itf,...) do{if(itf->verbosity>=1)afb_daemon_verbose(itf->daemon,5,NULL,0,__VA_ARGS__);}while(0)
150 # define AFB_INFO_V1(itf,...) do{if(itf->verbosity>=2)afb_daemon_verbose(itf->daemon,6,NULL,0,__VA_ARGS__);}while(0)
151 # define AFB_DEBUG_V1(itf,...) do{if(itf->verbosity>=3)afb_daemon_verbose(itf->daemon,7,NULL,0,__VA_ARGS__);}while(0)