Separate source files, clean up repository
[platform/core/appfw/pkgmgr-info.git] / include / pkgmgrinfo_debug.h
1 /*
2  * pkgmgrinfo_debug
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6   * Contact: junsuk. oh <junsuk77.oh@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef __PKGMGR_INFO_DEBUG_H__
23 #define __PKGMGR_INFO_DEBUG_H__
24
25 #include <dlog.h>
26
27 #define _LOGE(fmt, arg...) LOGE(fmt, ##arg)
28 #define _LOGD(fmt, arg...) LOGD(fmt, ##arg)
29
30 #define PKGMGR_INFO_ENABLE_DLOG
31
32 #define COLOR_RED               "\033[0;31m"
33 #define COLOR_BLUE              "\033[0;34m"
34 #define COLOR_END               "\033[0;m"
35
36 #ifdef PKGMGR_INFO_ENABLE_DLOG
37 #define PKGMGR_INFO_DEBUG(fmt, ...)\
38         do\
39         {\
40                 LOGD(fmt, ##__VA_ARGS__);\
41         } while (0)
42
43 #define PKGMGR_INFO_DEBUG_ERR(fmt, ...)\
44         do\
45         {\
46                 LOGE(COLOR_RED fmt COLOR_END, ##__VA_ARGS__);\
47         }while (0)
48
49 #define PKGMGR_INFO_BEGIN() \
50         do\
51     {\
52                 LOGD(COLOR_BLUE"BEGIN >>>>"COLOR_END);\
53     } while( 0 )
54
55 #define PKGMGR_INFO_END() \
56         do\
57     {\
58                 LOGD(COLOR_BLUE"END <<<<"COLOR_END);\
59     } \
60     while( 0 )
61
62 #else
63 #define PKGMGR_INFO_DEBUG(fmt, ...) \
64         do\
65         {\
66                 printf("\n [%s: %s(): %d] " fmt"\n",  rindex(__FILE__, '/')+1, __FUNCTION__, __LINE__, ##__VA_ARGS__);\
67         } while (0)
68
69 #define PKGMGR_INFO_BEGIN() \
70         do\
71     {\
72         printf("\n [%s: %d] : BEGIN >>>> %s() \n", rindex(__FILE__, '/')+1,  __LINE__ , __FUNCTION__);\
73     } while( 0 )
74
75 #define PKGMGR_INFO_END() \
76         do\
77     {\
78         printf("\n [%s: %d]: END   <<<< %s()\n", rindex(__FILE__, '/')+1,  __LINE__ , __FUNCTION__); \
79     } \
80     while( 0 )
81 #endif
82
83
84 #define ret_if(expr) do { \
85         if (expr) { \
86                 PKGMGR_INFO_DEBUG_ERR("(%s) ", #expr); \
87                 return; \
88         } \
89 } while (0)
90
91 #define retm_if(expr, fmt, arg...) do { \
92         if (expr) { \
93                 PKGMGR_INFO_DEBUG_ERR("(%s) "fmt, #expr, ##arg); \
94                 return; \
95         } \
96 } while (0)
97
98 #define retv_if(expr, val) do { \
99         if (expr) { \
100                 PKGMGR_INFO_DEBUG_ERR("(%s) ", #expr); \
101                 return (val); \
102         } \
103 } while (0)
104
105 #define retvm_if(expr, val, fmt, arg...) do { \
106         if (expr) { \
107                 PKGMGR_INFO_DEBUG_ERR("(%s) "fmt, #expr, ##arg); \
108                 return (val); \
109         } \
110 } while (0)
111
112 #define trym_if(expr, fmt, arg...) do { \
113         if (expr) { \
114                 PKGMGR_INFO_DEBUG_ERR("(%s) "fmt, #expr, ##arg); \
115                 goto catch; \
116         } \
117 } while (0)
118
119 #define tryvm_if(expr, val, fmt, arg...) do { \
120         if (expr) { \
121                 PKGMGR_INFO_DEBUG_ERR("(%s) "fmt, #expr, ##arg); \
122                 val; \
123                 goto catch; \
124         } \
125 } while (0)
126
127 #endif  /* __PKGMGR_INFO_DEBUG_H__ */