Distributed Publish Subscribe for IoT
dbg.h
Go to the documentation of this file.
1 /*
2  *******************************************************************
3  *
4  * Copyright 2016 Intel Corporation All rights reserved.
5  *
6  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22 
23 #ifndef _DPS_DBG_H
24 #define _DPS_DBG_H
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 #include <stdio.h>
29 #include <assert.h>
30 #include <uv.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 extern int DPS_Debug;
37 
38 typedef enum {
44 } DPS_LogLevel;
45 
46 void DPS_Log(DPS_LogLevel level, const char* file, int line, const char *function, const char *fmt, ...);
47 
48 #define DPS_ERRPRINT(fmt, ...) DPS_Log(DPS_LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, fmt, ##__VA_ARGS__)
49 
50 #define DPS_PRINT(fmt, ...) DPS_Log(DPS_LOG_PRINT, __FILE__, __LINE__, __FUNCTION__, fmt, ##__VA_ARGS__)
51 
52 /*
53  * Same a DPS_PRINT but prepends a sytem timestamp
54  */
55 #define DPS_PRINTT(fmt, ...) DPS_Log(DPS_LOG_PRINTT, __FILE__, __LINE__, __FUNCTION__, fmt, ##__VA_ARGS__)
56 
57 #define DPS_DEBUG_OFF 0
58 #define DPS_DEBUG_ON 1
59 #define DPS_DEBUG_FORCE 2
60 
61 #define DPS_DEBUG_ENABLED() ((DPS_Debug && (__DPS_DebugControl == DPS_DEBUG_ON)) || (__DPS_DebugControl == DPS_DEBUG_FORCE))
62 
63 #ifdef DPS_DEBUG
64 #define DPS_DBGTRACE() (DPS_DEBUG_ENABLED() ? DPS_Log(DPS_LOG_DBGTRACE, __FILE__, __LINE__, __FUNCTION__, "\n") : 0)
65 #define DPS_DBGPRINT(fmt, ...) (DPS_DEBUG_ENABLED() ? DPS_Log(DPS_LOG_DBGPRINT, __FILE__, __LINE__, __FUNCTION__, fmt, ##__VA_ARGS__) : 0)
66 #else
67 #define DPS_DBGTRACE()
68 #define DPS_DBGPRINT(...)
69 #endif
70 
71 /*
72  * Used at the top of a file to turn debugging on or off for that file
73  */
74 #ifdef _WIN32
75 #define DPS_DEBUG_CONTROL(dbg) static int __DPS_DebugControl = dbg
76 #else
77 #define DPS_DEBUG_CONTROL(dbg) __attribute__((__unused__))static int __DPS_DebugControl = dbg
78 #endif
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
Definition: dbg.h:39
Definition: dbg.h:40
DPS_LogLevel
Definition: dbg.h:38
int DPS_Debug
Definition: dbg.h:41
Definition: dbg.h:43
void DPS_Log(DPS_LogLevel level, const char *file, int line, const char *function, const char *fmt,...)
Definition: dbg.h:42