diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/eina/src/include/eina_inline_log.x | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/eina/src/include/eina_inline_log.x')
-rw-r--r-- | libraries/eina/src/include/eina_inline_log.x | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/libraries/eina/src/include/eina_inline_log.x b/libraries/eina/src/include/eina_inline_log.x new file mode 100644 index 0000000..4cdd7d8 --- /dev/null +++ b/libraries/eina/src/include/eina_inline_log.x | |||
@@ -0,0 +1,197 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2002-2008 Gustavo Sverzut Barbieri | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifndef EINA_LOG_INLINE_H_ | ||
20 | #define EINA_LOG_INLINE_H_ | ||
21 | |||
22 | /** | ||
23 | * @addtogroup Eina_Log_Group Log | ||
24 | * | ||
25 | * @{ | ||
26 | */ | ||
27 | |||
28 | /** | ||
29 | * Checks whenever the given level should be printed out. | ||
30 | * | ||
31 | * This is useful to enable certain blocks of code just when given | ||
32 | * level is to be used. | ||
33 | * | ||
34 | * @code | ||
35 | * #include <Eina.h> | ||
36 | * | ||
37 | * void my_func(void *data) | ||
38 | * { | ||
39 | * if (eina_log_level_check(EINA_LOG_LEVEL_WARN)) | ||
40 | * expensive_debugging_code(data); | ||
41 | * | ||
42 | * my_func_code(data); | ||
43 | * } | ||
44 | * @endcode | ||
45 | * | ||
46 | * @return #EINA_TRUE if level is equal or smaller than the current global | ||
47 | * logging level. | ||
48 | */ | ||
49 | static inline Eina_Bool | ||
50 | eina_log_level_check(int level) | ||
51 | { | ||
52 | return eina_log_level_get() <= level; | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Checks whenever the given level should be printed out. | ||
57 | * | ||
58 | * This is useful to enable certain blocks of code just when given | ||
59 | * level is to be used. | ||
60 | * | ||
61 | * @code | ||
62 | * #include <Eina.h> | ||
63 | * | ||
64 | * extern int _my_log_dom; | ||
65 | * | ||
66 | * void my_func(void *data) | ||
67 | * { | ||
68 | * if (eina_log_domain_level_check(_my_log_dom, EINA_LOG_LEVEL_WARN)) | ||
69 | * expensive_debugging_code(data); | ||
70 | * | ||
71 | * my_func_code(data); | ||
72 | * } | ||
73 | * @endcode | ||
74 | * | ||
75 | * @return #EINA_TRUE if level is equal or smaller than the current | ||
76 | * domain logging level. | ||
77 | */ | ||
78 | static inline Eina_Bool | ||
79 | eina_log_domain_level_check(int domain, int level) | ||
80 | { | ||
81 | int dom_level = eina_log_domain_registered_level_get(domain); | ||
82 | if (EINA_UNLIKELY(dom_level == EINA_LOG_LEVEL_UNKNOWN)) | ||
83 | return EINA_FALSE; | ||
84 | return dom_level <= level; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * Function to format the level as a 3 character (+1 null byte) string. | ||
89 | * | ||
90 | * This function converts the given level to a known string name (CRI, | ||
91 | * ERR, WRN, INF or DBG) or a zero-padded 3-character string. In any | ||
92 | * case the last byte will contain a trailing null byte. | ||
93 | * | ||
94 | * If extreme level values are used (greater than 999 and smaller than | ||
95 | * -99), then the value will just consider the less significant | ||
96 | * part. This is so uncommon that users should handle this in their | ||
97 | * code. | ||
98 | * | ||
99 | * @param level what level value to use. | ||
100 | * @param name where to write the actual value. | ||
101 | * | ||
102 | * @return pointer to @p name. | ||
103 | */ | ||
104 | static inline const char * | ||
105 | eina_log_level_name_get(int level, char name[4]) | ||
106 | { | ||
107 | #define BCPY(A, B, C) \ | ||
108 | do { name[0] = A; name[1] = B; name[2] = C; } while (0) | ||
109 | |||
110 | if (EINA_UNLIKELY(level < 0)) | ||
111 | { | ||
112 | name[0] = '-'; | ||
113 | name[1] = '0' + (-level / 10) % 10; | ||
114 | name[2] = '0' + (-level % 10); | ||
115 | } | ||
116 | else if (EINA_UNLIKELY(level >= EINA_LOG_LEVELS)) | ||
117 | { | ||
118 | name[0] = '0' + (level / 100) % 10; | ||
119 | name[1] = '0' + (level / 10) % 10; | ||
120 | name[2] = '0' + level % 10; | ||
121 | } | ||
122 | else if (level == 0) | ||
123 | BCPY('C', 'R', 'I'); | ||
124 | else if (level == 1) | ||
125 | BCPY('E', 'R', 'R'); | ||
126 | else if (level == 2) | ||
127 | BCPY('W', 'R', 'N'); | ||
128 | else if (level == 3) | ||
129 | BCPY('I', 'N', 'F'); | ||
130 | else if (level == 4) | ||
131 | BCPY('D', 'B', 'G'); | ||
132 | else | ||
133 | BCPY('?', '?', '?'); | ||
134 | |||
135 | name[3] = '\0'; | ||
136 | |||
137 | return name; | ||
138 | } | ||
139 | |||
140 | /** | ||
141 | * Function to get recommended color value for level. | ||
142 | * | ||
143 | * This function will not check if colors are enabled or not before | ||
144 | * returning the level color. If you desire such check, use | ||
145 | * eina_log_level_color_if_enabled_get(). | ||
146 | * | ||
147 | * @param level what level value to use. | ||
148 | * | ||
149 | * @return pointer to null byte terminated ANSI color string to be | ||
150 | * used in virtual terminals supporting VT100 color codes. | ||
151 | * | ||
152 | * @see eina_log_level_color_if_enabled_get() | ||
153 | */ | ||
154 | static inline const char * | ||
155 | eina_log_level_color_get(int level) | ||
156 | { | ||
157 | if (level <= 0) | ||
158 | return EINA_COLOR_LIGHTRED; | ||
159 | else if (level == 1) | ||
160 | return EINA_COLOR_RED; | ||
161 | else if (level == 2) | ||
162 | return EINA_COLOR_YELLOW; | ||
163 | else if (level == 3) | ||
164 | return EINA_COLOR_GREEN; | ||
165 | else if (level == 4) | ||
166 | return EINA_COLOR_LIGHTBLUE; | ||
167 | else | ||
168 | return EINA_COLOR_BLUE; | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * Function to get recommended color value for level, if colors are | ||
173 | * enabled. | ||
174 | * | ||
175 | * This function will check if colors are enabled or not before | ||
176 | * returning the level color. If colors are disabled, then empty | ||
177 | * string is returned. | ||
178 | * | ||
179 | * @param level what level value to use. | ||
180 | * | ||
181 | * @return pointer to null byte terminated ANSI color string to be | ||
182 | * used in virtual terminals supporting VT100 color codes. If | ||
183 | * colors are disabled, the empty string is returned. | ||
184 | */ | ||
185 | static inline const char * | ||
186 | eina_log_level_color_if_enabled_get(int level) | ||
187 | { | ||
188 | if (eina_log_color_disable_get()) | ||
189 | return ""; | ||
190 | return eina_log_level_color_get(level); | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * @} | ||
195 | */ | ||
196 | |||
197 | #endif /* EINA_LOG_INLINE_H_ */ | ||