Rev 14 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 1 | pmbaty | 1 | #ifndef HARNESS_TRACE_H | 
        
| 2 | #define HARNESS_TRACE_H | 
        ||
| 3 | |||
| 4 | #include "brender/br_types.h" | 
        ||
| 5 | #include <stdlib.h> | 
        ||
| 6 | |||
| 7 | extern int harness_debug_level;  | 
        ||
| 8 | extern int OS_IsDebuggerPresent(void);  | 
        ||
| 9 | |||
| 10 | void debug_printf(const char* fmt, const char* fn, const char* fmt2, ...);  | 
        ||
| 11 | void debug_print_vector3(const char* fmt, const char* fn, char* msg, br_vector3* v);  | 
        ||
| 12 | void debug_print_matrix34(const char* fmt, const char* fn, char* name, br_matrix34* m);  | 
        ||
| 13 | void debug_print_matrix4(const char* fmt, const char* fn, char* name, br_matrix4* m);  | 
        ||
| 14 | |||
| 15 | #define BLUE | 
        ||
| 16 | |||
| 17 | #define LOG_TRACE(...)                                         \ | 
        ||
| 18 |     if (harness_debug_level >= 5) {                            \ | 
        ||
| 19 |         debug_printf("[TRACE] %s", __FUNCTION__, __VA_ARGS__); \ | 
        ||
| 20 |     } | 
        ||
| 21 | |||
| 22 | #define LOG_TRACE10(...)                                       \ | 
        ||
| 23 |     if (harness_debug_level >= 10) {                           \ | 
        ||
| 24 |         debug_printf("[TRACE] %s", __FUNCTION__, __VA_ARGS__); \ | 
        ||
| 25 |     } | 
        ||
| 26 | #define LOG_TRACE9(...)                                        \ | 
        ||
| 27 |     if (harness_debug_level >= 9) {                            \ | 
        ||
| 28 |         debug_printf("[TRACE] %s", __FUNCTION__, __VA_ARGS__); \ | 
        ||
| 29 |     } | 
        ||
| 30 | |||
| 31 | #define LOG_TRACE8(...)                                        \ | 
        ||
| 32 |     if (harness_debug_level >= 8) {                            \ | 
        ||
| 33 |         debug_printf("[TRACE] %s", __FUNCTION__, __VA_ARGS__); \ | 
        ||
| 34 |     } | 
        ||
| 35 | |||
| 36 | #define LOG_DEBUG(...) debug_printf("\033[0;34m[DEBUG] %s ", __FUNCTION__, __VA_ARGS__) | 
        ||
| 37 | #define LOG_VEC(msg, v) debug_print_vector3("\033[0;34m[DEBUG] %s ", __FUNCTION__, msg, v) | 
        ||
| 38 | #define LOG_MATRIX(msg, m) debug_print_matrix34("\033[0;34m[DEBUG] %s ", __FUNCTION__, msg, m) | 
        ||
| 39 | #define LOG_MATRIX4(msg, m) debug_print_matrix4("\033[0;34m[DEBUG] %s ", __FUNCTION__, msg, m) | 
        ||
| 40 | #define LOG_INFO(...) debug_printf("[INFO] %s ", __FUNCTION__, __VA_ARGS__) | 
        ||
| 41 | #define LOG_WARN(...) debug_printf("\033[0;33m[WARN] %s ", __FUNCTION__, __VA_ARGS__) | 
        ||
| 42 | #define LOG_PANIC(...)                                                    \ | 
        ||
| 43 |     do {                                                                  \ | 
        ||
| 44 |         debug_printf("\033[0;31m[PANIC] %s ", __FUNCTION__, __VA_ARGS__); \ | 
        ||
| 45 |         abort();                                                          \ | 
        ||
| 46 |     } while (0) | 
        ||
| 47 | |||
| 48 | #define LOG_WARN_ONCE(...)                                               \ | 
        ||
| 49 |     static int warn_printed = 0;                                         \ | 
        ||
| 50 |     if (!warn_printed) {                                                 \ | 
        ||
| 51 |         debug_printf("\033[0;33m[WARN] %s ", __FUNCTION__, __VA_ARGS__); \ | 
        ||
| 52 |         warn_printed = 1;                                                \ | 
        ||
| 53 |     } | 
        ||
| 54 | |||
| 55 | #define NOT_IMPLEMENTED() \ | 
        ||
| 56 |     LOG_PANIC("not implemented") | 
        ||
| 57 | |||
| 58 | #define TELL_ME_IF_WE_PASS_THIS_WAY() \ | 
        ||
| 59 |     LOG_PANIC("code path not expected") | 
        ||
| 60 | |||
| 61 | #define STUB() \ | 
        ||
| 62 |     debug_printf("\033[0;31m[WARN] %s ", __FUNCTION__, "%s", "stubbed"); | 
        ||
| 63 | |||
| 64 | #define STUB_ONCE()                                                          \ | 
        ||
| 65 |     static int stub_printed = 0;                                             \ | 
        ||
| 66 |     if (!stub_printed) {                                                     \ | 
        ||
| 67 |         debug_printf("\033[0;31m[WARN] %s ", __FUNCTION__, "%s", "stubbed"); \ | 
        ||
| 68 |         stub_printed = 1;                                                    \ | 
        ||
| 69 |     } | 
        ||
| 70 | |||
| 71 | // int count_open_fds(); | 
        ||
| 72 | |||
| 73 | #endif |