4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 /******************************************************************************
25 * File: email-debug-log.h
26 * Desc: email-common-use debug header
31 * 2006.08.01 : created
32 *****************************************************************************/
33 #ifndef __EMAIL_DEBUG_LOG_H__
34 #define __EMAIL_DEBUG_LOG_H__
46 #define __FEATURE_DEBUG_LOG__
48 #ifdef __FEATURE_DEBUG_LOG__
50 /* definition of LOG_TAG */
55 #define LOG_TAG "email-service"
57 #define EM_DEBUG_LOG(format, arg...) \
58 SLOGD("[%s() :%s:%d] " format "\n", __FUNCTION__, \
59 (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ), __LINE__, ##arg)
60 #define EM_DEBUG_EXCEPTION(format, arg...) \
61 SLOGE("[%s() :%s:%d][EXCEPTION!!] " format "\n", __FUNCTION__, \
62 (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ), __LINE__, ##arg)
64 #ifdef _DEBUG_MIME_PARSE_
65 #define EM_DEBUG_LOG_MIME(format, arg...) EM_DEBUG_LOG(format, ##arg)
66 #else /* _DEBUG_MIME_PARSE */
67 #define EM_DEBUG_LOG_MIME(format, arg...)
68 #endif /* _DEBUG_MIME_PARSE */
70 #define EM_DEBUG_FUNC_BEGIN(format, arg...) EM_DEBUG_LOG("BEGIN - "format, ##arg)
71 #define EM_DEBUG_FUNC_END(format, arg...) EM_DEBUG_LOG("END - "format, ##arg)
72 #define EM_DEBUG_LINE EM_DEBUG_LOG("FUNC[%s : %d]", __FUNCTION__, __LINE__)
73 #define EM_DEBUG_DB_EXEC(eval, expr, X) if (eval) { EM_DEBUG_LOG X; expr;} else {;}
75 #define EM_DEBUG_ERROR_FILE_PATH "/opt/data/email/.emfdata/.critical_error.log"
76 #define EM_DEBUG_CRITICAL_EXCEPTION(format, arg...) \
78 FILE *fp_error = NULL;\
79 fp_error = fopen(EM_DEBUG_ERROR_FILE_PATH, "a");\
81 fprintf(fp_error, "[%s() :%s:%d] " format "\n", \
82 __FUNCTION__, (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ),\
87 #define EM_DEBUG_PERROR(str) ({\
89 strerror_r(errno, buf, sizeof(buf));\
90 EM_DEBUG_EXCEPTION("%s: %s(%d)", str, buf, errno);\
93 #ifdef _USE_PROFILE_DEBUG_
94 #define EM_PROFILE_BEGIN(pfid) \
95 unsigned int __prf_l1_##pfid = __LINE__;\
96 struct timeval __prf_1_##pfid;\
97 struct timeval __prf_2_##pfid;\
99 gettimeofday(&__prf_1_##pfid, 0);\
100 EM_DEBUG_LOG("**PROFILE BEGIN** [EMAILFW: %s() :%s %u ~ ] " #pfid \
101 " -> Start Time: %u.%06u seconds\n",\
103 rindex(__FILE__,'/')+1, \
105 (unsigned int)__prf_1_##pfid.tv_sec,\
106 (unsigned int)__prf_1_##pfid.tv_usec );\
109 #define EM_PROFILE_END(pfid) \
110 unsigned int __prf_l2_##pfid = __LINE__;\
112 gettimeofday(&__prf_2_##pfid, 0);\
113 long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
114 long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
115 if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
116 EM_DEBUG_LOG("**PROFILE END** [EMAILFW: %s() :%s %u ~ %u] " #pfid \
117 " -> Elapsed Time: %u.%06u seconds\n",\
119 rindex(__FILE__, '/')+1,\
122 (unsigned int)(__ds),\
123 (unsigned int)(__dm));\
127 #define EM_PROFILE_BEGIN(pfid)
128 #define EM_PROFILE_END(pfid)
133 #else /* __FEATURE_DEBUG_LOG__ */
135 #define EM_DEBUG_LINE
136 #define EM_DEBUG_LOG(format, arg...)
137 #define EM_DEBUG_ASSERT(format, arg...)
138 #define EM_DEBUG_EXCEPTION(format, arg...)
141 #define EM_DEBUG_DB_EXEC(eval, expr, X) if (eval) { EM_DEBUG_DB X; expr;} else {;}
142 #define EM_PROFILE_BEGIN(pfid)
143 #define EM_PROFILE_END(pfid)
145 #endif /* __FEATURE_DEBUG_LOG__ */
148 #define EM_NULL_CHECK_FOR_VOID(expr) \
151 EM_DEBUG_EXCEPTION ("INVALID PARAM: "#expr" NULL ");\
156 #define EM_IF_NULL_RETURN_VALUE(expr, val) \
159 EM_DEBUG_EXCEPTION ("INVALID PARAM: "#expr" NULL ");\
164 #define EM_RETURN_ERR_CODE(err_ptr, err_code, ret) \
166 if(err_ptr) *err_ptr = err_code;\
170 #define EM_EXIT_ERR_CODE(err_ptr, err_code) \
172 if(err_ptr) *err_ptr = err_code;\
177 #define EM_SAFE_FREE(expr) \
185 #define EM_SAFE_STRDUP(s) \
187 char* _s = (char*)s;\
188 (_s)? strdup(_s) : NULL;\
191 #define EM_SAFE_STRCMP(dest, src) \
195 ((_src) && (_dest))? strcmp(_dest, _src) : -1;\
198 #define EM_SAFE_STRCPY(dest, src) \
202 ((_src) && (_dest))? strcpy(_dest, _src) : NULL;\
205 #define EM_SAFE_STRNCPY(dest, src, size) \
210 ((_src) && (_dest))? strncpy(_dest, _src, _size) : NULL;\
213 #define EM_SAFE_STRCAT(dest, src) \
217 ((_src) && (_dest))? strcat(_dest, _src) : NULL;\
220 #define EM_SAFE_STRLEN(s) \
222 char* _s = (char*)s;\
223 (_s)? strlen(_s) : 0;\
227 #define EM_IF_ACCOUNT_ID_NULL(expr, ret) {\
229 EM_DEBUG_EXCEPTION ("EM_IF_ACCOUNT_ID_NULL: Account ID [ %d ] ", expr);\
235 #define EM_STRERROR(err) ({ char buf[128]; strerror_r(err, buf, sizeof(buf));})
240 #endif /* __cplusplu */
242 #endif /* __EMAIL_DEBUG_LOG_H__ */