initial upload for tizen 2.0 beta
[apps/home/gallery.git] / ug / ug-gallery-efl / include / ge-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
22 #ifdef _cplusplus
23 extern "C" {
24 #endif
25
26 #ifdef LOG_TAG
27 #undef LOG_TAG
28 #endif
29
30 #define LOG_TAG "GALLERY-EFL"
31
32 typedef enum {
33         DEBUG_CRITICAL,
34         DEBUG_CHECK,
35         MB_DEBUG_LOG,
36         DEBUG_MAX
37 } GlDebugType;
38
39 /* anci c color type */
40 #define FONT_COLOR_RESET    "\033[0m"
41 #define FONT_COLOR_RED      "\033[31m"
42 #define FONT_COLOR_GREEN    "\033[32m"
43 #define FONT_COLOR_YELLOW   "\033[33m"
44 #define FONT_COLOR_BLUE     "\033[34m"
45 #define FONT_COLOR_PURPLE   "\033[35m"
46 #define FONT_COLOR_CYAN     "\033[36m"
47 #define FONT_COLOR_GRAY     "\033[37m"
48
49 #ifdef _USE_LOG_FILE_
50 FILE* g_log_fp;
51 #endif // _USE_LOG_FILE_
52
53 #ifdef _USE_LOG_FILE_
54
55 #define ge_dbg(fmt,arg...)              fprintf(g_log_fp, "[%s: %d]" fmt "\n", __FUNCTION__, __LINE__, ##arg)
56
57 #elif defined _USE_DLOG_
58
59 #define ge_dbg(fmt, arg...)             LOGD("[%s : %d] " fmt "\n", __FUNCTION__, __LINE__, ##arg)
60 #define ge_dbgW(fmt, arg...)            LOGW(FONT_COLOR_GREEN"[%s : %d] " fmt "\n"FONT_COLOR_RESET, __FUNCTION__, __LINE__,  ##arg)
61 #define ge_dbgE(fmt, arg...)            LOGE(FONT_COLOR_RED"[%s : %d] " fmt "\n"FONT_COLOR_RESET, __FUNCTION__, __LINE__,  ##arg)
62
63 #elif defined _USE_LOG_CONSOLE_
64
65 #define ge_dbg(fmt,arg...)              fprintf(stdout, "[%s: %d] [%s]" fmt "\n", __FILE__, __LINE__, __FUNCTION__, ##arg)
66 #define ge_dbgW(fmt, arg...)            fprintf(stdout, "[%s : %d] [%s] " fmt "\n", __FILE__, __LINE__, __FUNCTION__,  ##arg)
67 #define ge_dbgE(fmt, arg...)            fprintf(stdout, "[%s : %d] [%s] " fmt "\n", __FILE__, __LINE__, __FUNCTION__,  ##arg)
68
69 #else
70
71 #define ge_dbg(fmt,arg...)
72 #define ge_dbgW(fmt, arg...)
73 #define ge_dbgE(fmt, arg...)
74 #endif
75
76 #define ge_warn_if(expr, fmt, arg...) do { \
77         if(expr) { \
78             ge_dbg("(%s) -> "fmt, #expr, ##arg); \
79         } \
80     } while (0)
81 #define ge_ret_if(expr) do { \
82         if(expr) { \
83             ge_dbgE("(%s) -> %s() return", #expr, __FUNCTION__); \
84             return; \
85         } \
86     } while (0)
87 #define ge_retv_if(expr, val) do { \
88         if(expr) { \
89             ge_dbgE("(%s) -> %s() return", #expr, __FUNCTION__); \
90             return (val); \
91         } \
92     } while (0)
93 #define ge_retm_if(expr, fmt, arg...) do { \
94         if(expr) { \
95             ge_dbgE(fmt, ##arg); \
96             ge_dbgE("(%s) -> %s() return", #expr, __FUNCTION__); \
97             return; \
98         } \
99     } while (0)
100 #define ge_retvm_if(expr, val, fmt, arg...) do { \
101         if(expr) { \
102             ge_dbgE(fmt, ##arg); \
103             ge_dbgE("(%s) -> %s() return", #expr, __FUNCTION__); \
104             return (val); \
105         } \
106     } while (0)
107
108
109 #define GE_CHECK_VAL(expr, val)                 ge_retvm_if(!(expr), val, "Invalid parameter, return ERROR code!")
110 #define GE_CHECK_NULL(expr)                     ge_retvm_if(!(expr), NULL, "Invalid parameter, return NULL!")
111 #define GE_CHECK_FALSE(expr)                    ge_retvm_if(!(expr), false, "Invalid parameter, return FALSE!")
112 #define GE_CHECK_CANCEL(expr)                   ge_retvm_if(!(expr), ECORE_CALLBACK_CANCEL, "Invalid parameter, return ECORE_CALLBACK_CANCEL!")
113 #define GE_CHECK(expr)                                  ge_retm_if(!(expr), "Invalid parameter, return!")
114
115
116 #include <time.h>
117 #include <sys/time.h>
118
119 void _ge_print_debug_time_ex(long start, long end, const char* func_name, char* time_string);
120
121 #ifdef _cplusplus
122 }
123 #endif
124
125 #endif /* _GL_DEBUG_H_ */
126