Bindings V2: Remove explicit references to daemon/service
[src/app-framework-binder.git] / include / afb / afb-binding-v2.h
1 /*
2  * Copyright (C) 2016, 2017 "IoT.bzh"
3  * Author: José Bollo <jose.bollo@iot.bzh>
4  *
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
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 #pragma once
19
20 #include <stdint.h>
21
22 #include "afb-auth.h"
23 #include "afb-req-itf.h"
24 #include "afb-event-itf.h"
25 #include "afb-service-common.h"
26 #include "afb-daemon-common.h"
27
28 #include "afb-session-v2.h"
29
30 struct json_object;
31
32 /*
33  * Description of one verb of the API provided by the binding
34  * This enumeration is valid for bindings of type version 2
35  */
36 struct afb_verb_v2
37 {
38         const char *verb;                       /* name of the verb */
39         void (*callback)(struct afb_req req);   /* callback function implementing the verb */
40         const struct afb_auth *auth;            /* required authorisation */
41         uint32_t session;                       /* authorisation and session requirements of the verb */
42 };
43
44 /*
45  * Description of the bindings of type version 2
46  */
47 struct afb_binding_v2
48 {
49         const char *api;                        /* api name for the binding */
50         const char *specification;              /* textual specification of the binding */
51         const struct afb_verb_v2 *verbs;        /* array of descriptions of verbs terminated by a NULL name */
52         int (*preinit)();
53         int (*init)();
54         void (*onevent)(const char *event, struct json_object *object);
55         unsigned noconcurrency: 1;              /* avoids concurrent requests to verbs */
56 };
57
58 struct afb_binding_data_v2
59 {
60         int verbosity;                  /* level of verbosity */
61         struct afb_daemon daemon;       /* access to daemon APIs */
62         struct afb_service service;     /* access to service APIs */
63 };
64
65 /*
66  * A binding V2 MUST have two exported symbols of name:
67  *
68  *            -  afbBindingV2
69  *            -  afbBindingV2data
70  *
71  */
72 #if !defined(AFB_BINDING_MAIN_NAME_V2)
73 extern const struct afb_binding_v2 afbBindingV2;
74 #endif
75
76 #if !defined(AFB_BINDING_DATA_NAME_V2)
77 #define AFB_BINDING_DATA_NAME_V2 afbBindingV2data
78 #endif
79
80 #if AFB_BINDING_VERSION == 2
81 struct afb_binding_data_v2 AFB_BINDING_DATA_NAME_V2  __attribute__ ((weak));
82 #else
83 extern struct afb_binding_data_v2 AFB_BINDING_DATA_NAME_V2;
84 #endif
85
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)
89
90 /*
91  * Macros for logging messages
92  */
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,...) \
96         do{ \
97                 if(AFB_BINDING_DATA_NAME_V2.verbosity>=vlevel) \
98                         afb_daemon_verbose_v2(llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
99         }while(0)
100 # else
101 #  define _AFB_LOGGING_V2_(vlevel,llevel,...) \
102         do{ \
103                 if(afbBindingV2data.verbosity>=vlevel) \
104                         afb_daemon_verbose_v2(llevel,NULL,0,NULL,__VA_ARGS__); \
105         }while(0)
106 # endif
107 # define AFB_ERROR_V2(...)   _AFB_LOGGING_V2_(0,3,__VA_ARGS__)
108 # define AFB_WARNING_V2(...) _AFB_LOGGING_V2_(1,4,__VA_ARGS__)
109 # define AFB_NOTICE_V2(...)  _AFB_LOGGING_V2_(1,5,__VA_ARGS__)
110 # define AFB_INFO_V2(...)    _AFB_LOGGING_V2_(2,6,__VA_ARGS__)
111 # define AFB_DEBUG_V2(...)   _AFB_LOGGING_V2_(3,7,__VA_ARGS__)
112 #endif
113
114 #include "afb-daemon-v2.h"
115 #include "afb-service-v2.h"
116
117 /***************************************************************************************************/
118
119 #if AFB_BINDING_VERSION == 2
120
121 # define afb_binding            afb_binding_v2
122 # define afb_binding_interface  afb_binding_interface_v2
123
124 # define AFB_SESSION_NONE       AFB_SESSION_NONE_V2
125 # define AFB_SESSION_CLOSE      AFB_SESSION_CLOSE_V2
126 # define AFB_SESSION_RENEW      AFB_SESSION_REFRESH_V2
127 # define AFB_SESSION_REFRESH    AFB_SESSION_REFRESH_V2
128 # define AFB_SESSION_CHECK      AFB_SESSION_CHECK_V2
129
130 # define AFB_SESSION_LOA_MASK   AFB_SESSION_LOA_MASK_V2
131
132 # define AFB_SESSION_LOA_0      AFB_SESSION_LOA_0_V2
133 # define AFB_SESSION_LOA_1      AFB_SESSION_LOA_1_V2
134 # define AFB_SESSION_LOA_2      AFB_SESSION_LOA_2_V2
135 # define AFB_SESSION_LOA_3      AFB_SESSION_LOA_3_V2
136
137 # if !defined(AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO)
138
139 #  define ERROR                 AFB_ERROR_V2
140 #  define WARNING               AFB_WARNING_V2
141 #  define NOTICE                AFB_NOTICE_V2
142 #  define INFO                  AFB_INFO_V2
143 #  define DEBUG                 AFB_DEBUG_V2
144
145 # endif
146
147 #define afb_daemon_get_event_loop       afb_daemon_get_event_loop_v2
148 #define afb_daemon_get_user_bus         afb_daemon_get_user_bus_v2
149 #define afb_daemon_get_system_bus       afb_daemon_get_system_bus_v2
150 #define afb_daemon_broadcast_event      afb_daemon_broadcast_event_v2
151 #define afb_daemon_make_event           afb_daemon_make_event_v2
152 #define afb_daemon_verbose              afb_daemon_verbose_v2
153 #define afb_daemon_rootdir_get_fd       afb_daemon_rootdir_get_fd_v2
154 #define afb_daemon_rootdir_open_locale  afb_daemon_rootdir_open_locale_v2
155 #define afb_daemon_queue_job            afb_daemon_queue_job_v2
156
157 #define afb_service_call                afb_service_call_v2
158
159 #endif