357a85f6dfc362cc22ff81cba45541771adc1822
[src/app-framework-binder.git] / include / afb / afb-binding-vdyn.h
1 /*
2  * Copyright (C) 2016, 2017, 2018 "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 "afb-auth.h"
21 #include "afb-session-v2.h"
22 #include "afb-verbosity.h"
23
24 #include "afb-eventid.h"
25 #include "afb-request.h"
26 #include "afb-dynapi.h"
27
28 /*
29  * The function afbBindingVdyn if exported allows to create
30  * pure dynamic bindings. When the binding is loaded, it receives
31  * a virtual dynapi that can be used to create apis. The
32  * given API can not be used except for creating dynamic apis.
33  */
34 extern int afbBindingVdyn(struct afb_dynapi *dynapi);
35
36 /*
37  * Macros for logging messages
38  */
39 #if defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DATA)
40
41 # define _AFB_DYNAPI_LOGGING_(vlevel,llevel,dynapi,...) \
42         do{ \
43                 if(dynapi->verbosity>=vlevel) {\
44                         if (llevel <= AFB_VERBOSITY_LEVEL_ERROR) \
45                                 afb_dynapi_verbose(dynapi,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
46                         else \
47                                 afb_dynapi_verbose(dynapi,llevel,__FILE__,__LINE__,NULL,NULL); \
48                 } \
49         }while(0)
50 # define _AFB_REQUEST_LOGGING_(vlevel,llevel,request,...) \
51         do{ \
52                 if(request->dynapi->verbosity>=vlevel) \
53                         afb_request_verbose(request,llevel,__FILE__,__LINE__,NULL,NULL); \
54         }while(0)
55
56 #elif defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
57
58 # define _AFB_DYNAPI_LOGGING_(vlevel,llevel,dynapi,...) \
59         do{ \
60                 if(dynapi->verbosity>=vlevel) \
61                         afb_dynapi_verbose(dynapi,llevel,NULL,0,NULL,__VA_ARGS__); \
62         }while(0)
63 # define _AFB_REQUEST_LOGGING_(vlevel,llevel,request,...) \
64         do{ \
65                 if(request->dynapi->verbosity>=vlevel) \
66                         afb_request_verbose(request,llevel,NULL,0,NULL,__VA_ARGS__); \
67         }while(0)
68
69 #else
70
71 # define _AFB_DYNAPI_LOGGING_(vlevel,llevel,dynapi,...) \
72         do{ \
73                 if(dynapi->verbosity>=vlevel) \
74                         afb_dynapi_verbose(dynapi,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
75         }while(0)
76 # define _AFB_REQUEST_LOGGING_(vlevel,llevel,request,...) \
77         do{ \
78                 if(request->dynapi->verbosity>=vlevel) \
79                         afb_request_verbose(request,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
80         }while(0)
81
82 #endif
83
84 #define AFB_DYNAPI_ERROR(...)     _AFB_DYNAPI_LOGGING_(AFB_VERBOSITY_LEVEL_ERROR,_AFB_SYSLOG_LEVEL_ERROR_,__VA_ARGS__)
85 #define AFB_DYNAPI_WARNING(...)   _AFB_DYNAPI_LOGGING_(AFB_VERBOSITY_LEVEL_WARNING,_AFB_SYSLOG_LEVEL_WARNING_,__VA_ARGS__)
86 #define AFB_DYNAPI_NOTICE(...)    _AFB_DYNAPI_LOGGING_(AFB_VERBOSITY_LEVEL_NOTICE,_AFB_SYSLOG_LEVEL_NOTICE_,__VA_ARGS__)
87 #define AFB_DYNAPI_INFO(...)      _AFB_DYNAPI_LOGGING_(AFB_VERBOSITY_LEVEL_INFO,_AFB_SYSLOG_LEVEL_INFO_,__VA_ARGS__)
88 #define AFB_DYNAPI_DEBUG(...)     _AFB_DYNAPI_LOGGING_(AFB_VERBOSITY_LEVEL_DEBUG,_AFB_SYSLOG_LEVEL_DEBUG_,__VA_ARGS__)
89 #define AFB_REQUEST_ERROR(...)    _AFB_REQUEST_LOGGING_(AFB_VERBOSITY_LEVEL_ERROR,_AFB_SYSLOG_LEVEL_ERROR_,__VA_ARGS__)
90 #define AFB_REQUEST_WARNING(...)  _AFB_REQUEST_LOGGING_(AFB_VERBOSITY_LEVEL_WARNING,_AFB_SYSLOG_LEVEL_WARNING_,__VA_ARGS__)
91 #define AFB_REQUEST_NOTICE(...)   _AFB_REQUEST_LOGGING_(AFB_VERBOSITY_LEVEL_NOTICE,_AFB_SYSLOG_LEVEL_NOTICE_,__VA_ARGS__)
92 #define AFB_REQUEST_INFO(...)     _AFB_REQUEST_LOGGING_(AFB_VERBOSITY_LEVEL_INFO,_AFB_SYSLOG_LEVEL_INFO_,__VA_ARGS__)
93 #define AFB_REQUEST_DEBUG(...)    _AFB_REQUEST_LOGGING_(AFB_VERBOSITY_LEVEL_DEBUG,_AFB_SYSLOG_LEVEL_DEBUG_,__VA_ARGS__)
94
95