Allow dynamic creation of APIs
[src/app-framework-binder.git] / include / afb / afb-binding-vdyn.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 "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  * Macros for logging messages
30  */
31 #if defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DATA)
32
33 # define _AFB_DYNAPI_LOGGING_(vlevel,llevel,dynapi,...) \
34         do{ \
35                 if(dynapi->verbosity>=vlevel) {\
36                         if (llevel <= AFB_VERBOSITY_LEVEL_ERROR) \
37                                 afb_dynapi_verbose(dynapi,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
38                         else \
39                                 afb_dynapi_verbose(dynapi,llevel,__FILE__,__LINE__,NULL,NULL); \
40                 } \
41         }while(0)
42 # define _AFB_REQUEST_LOGGING_(vlevel,llevel,request,...) \
43         do{ \
44                 if(request->dynapi->verbosity>=vlevel) \
45                         afb_request_verbose(request,llevel,__FILE__,__LINE__,NULL,NULL); \
46         }while(0)
47
48 #elif defined(AFB_BINDING_PRAGMA_NO_VERBOSE_DETAILS)
49
50 # define _AFB_DYNAPI_LOGGING_(vlevel,llevel,dynapi,...) \
51         do{ \
52                 if(dynapi->verbosity>=vlevel) \
53                         afb_dynapi_verbose(dynapi,llevel,NULL,0,NULL,__VA_ARGS__); \
54         }while(0)
55 # define _AFB_REQUEST_LOGGING_(vlevel,llevel,request,...) \
56         do{ \
57                 if(request->dynapi->verbosity>=vlevel) \
58                         afb_request_verbose(request,llevel,NULL,0,NULL,__VA_ARGS__); \
59         }while(0)
60
61 #else
62
63 # define _AFB_DYNAPI_LOGGING_(vlevel,llevel,dynapi,...) \
64         do{ \
65                 if(dynapi->verbosity>=vlevel) \
66                         afb_dynapi_verbose(dynapi,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
67         }while(0)
68 # define _AFB_REQUEST_LOGGING_(vlevel,llevel,request,...) \
69         do{ \
70                 if(request->dynapi->verbosity>=vlevel) \
71                         afb_request_verbose(request,llevel,__FILE__,__LINE__,__func__,__VA_ARGS__); \
72         }while(0)
73
74 #endif
75
76 #define AFB_DYNAPI_ERROR(...)     _AFB_DYNAPI_LOGGING_(AFB_VERBOSITY_LEVEL_ERROR,_AFB_SYSLOG_LEVEL_ERROR_,__VA_ARGS__)
77 #define AFB_DYNAPI_WARNING(...)   _AFB_DYNAPI_LOGGING_(AFB_VERBOSITY_LEVEL_WARNING,_AFB_SYSLOG_LEVEL_WARNING_,__VA_ARGS__)
78 #define AFB_DYNAPI_NOTICE(...)    _AFB_DYNAPI_LOGGING_(AFB_VERBOSITY_LEVEL_NOTICE,_AFB_SYSLOG_LEVEL_NOTICE_,__VA_ARGS__)
79 #define AFB_DYNAPI_INFO(...)      _AFB_DYNAPI_LOGGING_(AFB_VERBOSITY_LEVEL_INFO,_AFB_SYSLOG_LEVEL_INFO_,__VA_ARGS__)
80 #define AFB_DYNAPI_DEBUG(...)     _AFB_DYNAPI_LOGGING_(AFB_VERBOSITY_LEVEL_DEBUG,_AFB_SYSLOG_LEVEL_DEBUG_,__VA_ARGS__)
81 #define AFB_REQUEST_ERROR(...)    _AFB_REQUEST_LOGGING_(AFB_VERBOSITY_LEVEL_ERROR,_AFB_SYSLOG_LEVEL_ERROR_,__VA_ARGS__)
82 #define AFB_REQUEST_WARNING(...)  _AFB_REQUEST_LOGGING_(AFB_VERBOSITY_LEVEL_WARNING,_AFB_SYSLOG_LEVEL_WARNING_,__VA_ARGS__)
83 #define AFB_REQUEST_NOTICE(...)   _AFB_REQUEST_LOGGING_(AFB_VERBOSITY_LEVEL_NOTICE,_AFB_SYSLOG_LEVEL_NOTICE_,__VA_ARGS__)
84 #define AFB_REQUEST_INFO(...)     _AFB_REQUEST_LOGGING_(AFB_VERBOSITY_LEVEL_INFO,_AFB_SYSLOG_LEVEL_INFO_,__VA_ARGS__)
85 #define AFB_REQUEST_DEBUG(...)    _AFB_REQUEST_LOGGING_(AFB_VERBOSITY_LEVEL_DEBUG,_AFB_SYSLOG_LEVEL_DEBUG_,__VA_ARGS__)
86
87