1 | #ifndef DEBUG_H |
---|
2 | #define DEBUG_H |
---|
3 | |
---|
4 | #include "Common/include/Message.h" |
---|
5 | #include "Behavioural/include/Debug_component.h" |
---|
6 | #include <stdio.h> |
---|
7 | #include <string.h> |
---|
8 | #include <iostream> |
---|
9 | #include <sstream> |
---|
10 | #include <string> |
---|
11 | |
---|
12 | // Debug's Level : |
---|
13 | // * None : print elementary information |
---|
14 | // * Info : print basic information |
---|
15 | // * Trace : trace internal variable |
---|
16 | // * Func : trace call and return function |
---|
17 | // * All : print all information |
---|
18 | |
---|
19 | enum _debug_verbosity |
---|
20 | { |
---|
21 | DEBUG_NONE , |
---|
22 | DEBUG_INFO , |
---|
23 | DEBUG_TRACE, |
---|
24 | DEBUG_FUNC , |
---|
25 | DEBUG_ALL |
---|
26 | }; |
---|
27 | |
---|
28 | #ifdef DEBUG |
---|
29 | //Debug |
---|
30 | # define log_printf(level, component, func, str... ) \ |
---|
31 | do \ |
---|
32 | { \ |
---|
33 | if ((DEBUG == DEBUG_ALL ) or \ |
---|
34 | (DEBUG_ ## level == DEBUG_NONE) or \ |
---|
35 | (( DEBUG_ ## level <= DEBUG) and \ |
---|
36 | ( DEBUG_ ## component == true )) ) \ |
---|
37 | { \ |
---|
38 | if (DEBUG >= DEBUG_ALL ) \ |
---|
39 | { \ |
---|
40 | switch (DEBUG_ ## level) \ |
---|
41 | { \ |
---|
42 | case DEBUG_NONE : msg(_("(none ) ")); break; \ |
---|
43 | case DEBUG_INFO : msg(_("(information) ")); break; \ |
---|
44 | case DEBUG_TRACE : msg(_("(trace ) ")); break; \ |
---|
45 | case DEBUG_FUNC : msg(_("(function ) ")); break; \ |
---|
46 | case DEBUG_ALL : msg(_("(all ) ")); break; \ |
---|
47 | default : msg(_("(undefine ) ")); break; \ |
---|
48 | } \ |
---|
49 | } \ |
---|
50 | msg(_("<%s> "),func); \ |
---|
51 | if (DEBUG >= DEBUG_FUNC) \ |
---|
52 | { \ |
---|
53 | msg(_("In file %s, "),__FILE__); \ |
---|
54 | msg(_("at line %d, "),__LINE__); \ |
---|
55 | } \ |
---|
56 | msg(_(": ")); \ |
---|
57 | msg(str); \ |
---|
58 | msg(_("\n")); \ |
---|
59 | fflush (stdout); \ |
---|
60 | } \ |
---|
61 | } while(0) |
---|
62 | |
---|
63 | #else |
---|
64 | // No debug |
---|
65 | |
---|
66 | # define log_printf(level, component, func, str... ) \ |
---|
67 | do \ |
---|
68 | { \ |
---|
69 | } while(0) |
---|
70 | |
---|
71 | #endif // DEBUG |
---|
72 | |
---|
73 | #endif // !DEBUG_H |
---|