initial upload for tizen 2.0 beta
[apps/home/gallery.git] / include / util / gl-debug.h
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://www.tizenopensource.org/license
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17 #ifndef _GL_DEBUG_H_
18 #define _GL_DEBUG_H_
19
20 #include <dlog.h>
21 #include <assert.h>
22 #include <stdio.h>
23
24 #ifdef _cplusplus
25 extern "C"
26 {
27 #endif
28
29 #ifdef LOG_TAG
30 #undef LOG_TAG
31 #endif
32
33
34 #define LOG_TAG "GALLERY"
35 #define LOG_TAG_LAUNCH "GALLERY_LAUNCH"
36
37 /* anci c color type */
38 #define FONT_COLOR_RESET    "\033[0m"
39 #define FONT_COLOR_RED      "\033[31m"
40 #define FONT_COLOR_GREEN    "\033[32m"
41 #define FONT_COLOR_YELLOW   "\033[33m"
42 #define FONT_COLOR_BLUE     "\033[34m"
43 #define FONT_COLOR_PURPLE   "\033[35m"
44 #define FONT_COLOR_CYAN     "\033[36m"
45 #define FONT_COLOR_GRAY     "\033[37m"
46
47 #ifdef _USE_LOG_FILE_
48 FILE *g_log_fp;
49 #endif // _USE_LOG_FILE_
50
51 #ifdef _USE_LOG_FILE_
52
53 #define gl_dbg(fmt,arg...)              fprintf(g_log_fp, "[%s: %d]" fmt "\n", __FUNCTION__, __LINE__, ##arg)
54
55 #elif defined _USE_DLOG_
56
57 #define gl_dbg(fmt, arg...)             LOGD("[%s : %d] " fmt "\n", __FUNCTION__, __LINE__, ##arg)
58 #define gl_dbgW(fmt, arg...)            LOGW(FONT_COLOR_GREEN"[%s : %d] " fmt "\n"FONT_COLOR_RESET, __FUNCTION__, __LINE__,  ##arg)
59 #define gl_dbgE(fmt, arg...)            LOGE(FONT_COLOR_RED"[%s : %d] " fmt "\n"FONT_COLOR_RESET, __FUNCTION__, __LINE__,  ##arg)
60
61 typedef struct {
62         const char *fname;
63         int nline;
64         const char *szcategory;
65 } debug_msg_type;
66
67 void _custom_debug_msg(debug_msg_type *debug_msg, const char *msg, ...);
68
69 #define __LAUNCH_TEST_LOG(szCat,  ...)  \
70         do { \
71                 if (1)  \
72                 { \
73                         static debug_msg_type msg______unique______name___ = {          \
74                                 __FILE__,                                                       \
75                                 __LINE__,                                                       \
76                                 szCat,                                                          \
77                         };                                                                      \
78                         _custom_debug_msg(&msg______unique______name___, ##__VA_ARGS__); \
79                 } \
80         } while(0)
81
82 #define gl_dbg_launch(...)      __LAUNCH_TEST_LOG(LOG_TAG_LAUNCH, ##__VA_ARGS__)
83
84
85 #elif defined _USE_LOG_CONSOLE_
86
87 #define gl_dbg(fmt,arg...)              fprintf(stdout, "[%s: %d]" fmt "\n", __FUNCTION__, __LINE__, ##arg)
88 #define gl_dbgW(fmt, arg...)            fprintf(stdout, "[%s : %d] " fmt "\n", __FUNCTION__, __LINE__, ##arg)
89 #define gl_dbgE(fmt, arg...)            fprintf(stdout, "[%s : %d] " fmt "\n", __FUNCTION__, __LINE__, ##arg)
90
91 #else
92
93 #define gl_dbg(fmt,arg...)
94 #define gl_dbgW(fmt, arg...)
95 #define gl_dbgE(fmt, arg...)
96 #endif
97
98 //void gl_init_debug_handler (const char *appname);
99 //void gl_close_debug_handler();
100
101 #include <time.h>
102 #include <sys/time.h>
103
104 //long gl_get_debug_time(void);
105 //void gl_reset_debug_time(void);
106 //void gl_print_debug_time(char* time_string);
107 void gl_print_debug_time_ex(long start, long end, const char *func_name, char *time_string);
108
109
110
111 #define gl_retm_if(expr, fmt, arg...) do { \
112         if(expr) { \
113                 gl_dbgE(fmt, ##arg); \
114                 gl_dbgE("(%s) -> %s() return", #expr, __FUNCTION__); \
115                 return; \
116         } \
117 } while (0)
118
119 #define gl_retvm_if(expr, val, fmt, arg...) do { \
120         if(expr) { \
121                 gl_dbgE(fmt, ##arg); \
122                 gl_dbgE("(%s) -> %s() return", #expr, __FUNCTION__); \
123                 return (val); \
124         } \
125 } while (0)
126
127 #define GL_CHECK_EXCEP(expr) do { \
128         if(!(expr)) { \
129                 gl_dbgE("Critical ERROR ########################################## Check below item.");\
130                 goto gl_exception;\
131         } \
132 } while (0)
133
134 #define GL_CHECK_VAL(expr, val)                 gl_retvm_if(!(expr), val, "Invalid parameter, return ERROR code!")
135 #define GL_CHECK_NULL(expr)                     gl_retvm_if(!(expr), NULL, "Invalid parameter, return NULL!")
136 #define GL_CHECK_FALSE(expr)                    gl_retvm_if(!(expr), false, "Invalid parameter, return FALSE!")
137 #define GL_CHECK_CANCEL(expr)                   gl_retvm_if(!(expr), ECORE_CALLBACK_CANCEL, "Invalid parameter, return ECORE_CALLBACK_CANCEL!")
138 #define GL_CHECK(expr)                                  gl_retm_if(!(expr), "Invalid parameter, return!")
139
140 #define gl_assert(expr) do { \
141         if(!(expr)) { \
142                 gl_dbgE("Critical ERROR ########################################## Check below item.");\
143                 assert(false); \
144         } \
145 } while (0)
146
147 #ifdef _cplusplus
148 }
149 #endif
150
151 #endif /* _GL_DEBUG_H_ */