Distributed Publish & Subscribe for IoT
dbg.h
Go to the documentation of this file.
1 
6 /*
7  *******************************************************************
8  *
9  * Copyright 2016 Intel Corporation All rights reserved.
10  *
11  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
12  *
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  *
25  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26  */
27 
28 #ifndef _DPS_DBG_H
29 #define _DPS_DBG_H
30 
31 #include <stdint.h>
32 #include <stddef.h>
33 #include <stdio.h>
34 #include <assert.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
47 extern int DPS_Debug;
48 
50 #define DPS_DBG_TAG NULL
51 
55 typedef enum {
56  DPS_LOG_INFO,
57  DPS_LOG_ERROR,
58  DPS_LOG_WARNING,
59  DPS_LOG_PRINT,
60  DPS_LOG_PRINTT,
61  DPS_LOG_DBGTRACE,
62  DPS_LOG_DBGPRINT,
63 } DPS_LogLevel;
64 
76 void DPS_Log(DPS_LogLevel level, const char* file, int line, const char *function, const char* tag, const char *fmt, ...);
77 
88 void DPS_LogBytes(DPS_LogLevel level, const char* file, int line, const char *function, const uint8_t *bytes, size_t n);
89 
93 #define DPS_ERRPRINT(fmt, ...) DPS_Log(DPS_LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, DPS_DBG_TAG, fmt, ##__VA_ARGS__)
94 
98 #define DPS_PRINT(fmt, ...) DPS_Log(DPS_LOG_PRINT, __FILE__, __LINE__, __FUNCTION__, DPS_DBG_TAG, fmt, ##__VA_ARGS__)
99 
103 #define DPS_PRINTT(fmt, ...) DPS_Log(DPS_LOG_PRINTT, __FILE__, __LINE__, __FUNCTION__, DPS_DBG_TAG, fmt, ##__VA_ARGS__)
104 
105 #define DPS_DEBUG_OFF 0
106 #define DPS_DEBUG_ON 1
107 #define DPS_DEBUG_FORCE 2
108 #define DPS_DEBUG_INFO 3
113 #define DPS_DEBUG_ENABLED() ((DPS_Debug && (__DPS_DebugControl == DPS_DEBUG_ON)) || (__DPS_DebugControl == DPS_DEBUG_FORCE))
114 
118 #define DPS_INFO_ENABLED() ((__DPS_DebugControl == DPS_DEBUG_INFO) || DPS_DEBUG_ENABLED())
119 
120 #ifdef DPS_DEBUG
121 
124 #define DPS_DBGINFO(fmt, ...) (DPS_INFO_ENABLED() ? DPS_Log(DPS_LOG_INFO, __FILE__, __LINE__, __FUNCTION__, DPS_DBG_TAG, fmt, ##__VA_ARGS__) : (void)0)
125 
128 #define DPS_DBGTRACE() (DPS_DEBUG_ENABLED() ? DPS_Log(DPS_LOG_DBGTRACE, __FILE__, __LINE__, __FUNCTION__, DPS_DBG_TAG, "\n") : (void)0)
129 
132 #define DPS_DBGTRACEA(fmt, ...) (DPS_DEBUG_ENABLED() ? DPS_Log(DPS_LOG_DBGTRACE, __FILE__, __LINE__, __FUNCTION__, DPS_DBG_TAG, fmt, ##__VA_ARGS__) : (void)0)
133 
136 #define DPS_DBGPRINT(fmt, ...) (DPS_DEBUG_ENABLED() ? DPS_Log(DPS_LOG_DBGPRINT, __FILE__, __LINE__, __FUNCTION__, DPS_DBG_TAG, fmt, ##__VA_ARGS__) : (void)0)
137 
140 #define DPS_WARNPRINT(fmt, ...) (DPS_DEBUG_ENABLED() ? DPS_Log(DPS_LOG_WARNING, __FILE__, __LINE__, __FUNCTION__, DPS_DBG_TAG, fmt, ##__VA_ARGS__) : (void)0)
141 
144 #define DPS_DBGBYTES(bytes, n) (DPS_DEBUG_ENABLED() ? DPS_LogBytes(DPS_LOG_DBGPRINT, __FILE__, __LINE__, __FUNCTION__, bytes, n) : (void)0)
145 #else
146 #define DPS_DBGINFO(...)
147 #define DPS_DBGTRACE()
148 #define DPS_DBGTRACEA(...)
149 #define DPS_DBGPRINT(...)
150 #define DPS_WARNPRINT(...)
151 #define DPS_DBGBYTES(bytes, n)
152 #endif
153 
157 #if defined(__GNUC__) || defined(__MINGW64__)
158 #define DPS_DEBUG_CONTROL(dbg) __attribute__((__unused__))static int __DPS_DebugControl = dbg
159 #elif defined(_WIN32)
160 #define DPS_DEBUG_CONTROL(dbg) static int __DPS_DebugControl = dbg
161 #endif
162 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif
void DPS_Log(DPS_LogLevel level, const char *file, int line, const char *function, const char *tag, const char *fmt,...)
Log a message.
void DPS_LogBytes(DPS_LogLevel level, const char *file, int line, const char *function, const uint8_t *bytes, size_t n)
Log an array of bytes.
int DPS_Debug
Debug control value.
DPS_LogLevel
Debug logging levels.
Definition: dbg.h:55