4 * Copyright (c) 2012 - 2013 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__
47 #define __FEATURE_DEBUG_LOG__
49 #ifdef __FEATURE_DEBUG_LOG__
51 /* definition of LOG_TAG */
56 #define LOG_TAG "EMAIL_SERVICE"
58 #define EM_DEBUG_LOG(format, arg...) SLOGD(format, ##arg)
59 #define EM_DEBUG_EXCEPTION(format, arg...) SLOGE("[EXCEPTION!] " format "\n", ##arg)
61 #ifdef _DEBUG_MIME_PARSE_
62 #define EM_DEBUG_LOG_MIME(format, arg...) EM_DEBUG_LOG(format, ##arg)
63 #else /* _DEBUG_MIME_PARSE */
64 #define EM_DEBUG_LOG_MIME(format, arg...)
65 #endif /* _DEBUG_MIME_PARSE */
67 #define EM_DEBUG_FUNC_BEGIN(format, arg...) EM_DEBUG_LOG("BEGIN - "format, ##arg)
68 #define EM_DEBUG_FUNC_END(format, arg...) EM_DEBUG_LOG("END - "format, ##arg)
69 #define EM_DEBUG_LINE EM_DEBUG_LOG("FUNC[%s : %d]", __FUNCTION__, __LINE__)
70 #define EM_DEBUG_DB_EXEC(eval, expr, X) if (eval) { EM_DEBUG_LOG X; expr;} else {;}
72 #define EM_DEBUG_ERROR_FILE_PATH "/opt/usr/data/email/.email_data/.critical_error.log"
73 #define EM_DEBUG_CRITICAL_EXCEPTION(format, arg...) \
75 FILE *fp_error = NULL;\
76 fp_error = fopen(EM_DEBUG_ERROR_FILE_PATH, "a");\
78 fprintf(fp_error, "[%s() :%s:%d] " format "\n", \
79 __FUNCTION__, (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ),\
84 #define EM_DEBUG_PERROR(str) ({\
86 strerror_r(errno, buf, sizeof(buf));\
87 EM_DEBUG_EXCEPTION("%s: %s(%d)", str, buf, errno);\
90 #define EM_VALIDATION_SYSTEM_LOG(CLASSIFICATION, MAIL_ID, FORMAT, ARG...) {char now_time_string[30] = {0,}; \
91 time_t now = time(NULL); \
92 strftime(now_time_string, 20, "%Y.%m.%d %H:%M:%S", localtime(&now)); \
93 LOG(LOG_VERBOSE, "VLD_EMAIL", "[Email " CLASSIFICATION "]%s, %d," FORMAT "\n", now_time_string, MAIL_ID, ##ARG);}
95 #ifdef _USE_PROFILE_DEBUG_
96 #define EM_PROFILE_BEGIN(pfid) \
97 unsigned int __prf_l1_##pfid = __LINE__;\
98 struct timeval __prf_1_##pfid;\
99 struct timeval __prf_2_##pfid;\
101 gettimeofday(&__prf_1_##pfid, 0);\
102 EM_DEBUG_LOG("**PROFILE BEGIN** [EMAILFW: %s() :%s %u ~ ] " #pfid \
103 " -> Start Time: %u.%06u seconds\n",\
105 rindex(__FILE__,'/')+1, \
107 (unsigned int)__prf_1_##pfid.tv_sec,\
108 (unsigned int)__prf_1_##pfid.tv_usec );\
111 #define EM_PROFILE_END(pfid) \
112 unsigned int __prf_l2_##pfid = __LINE__;\
114 gettimeofday(&__prf_2_##pfid, 0);\
115 long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
116 long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
117 if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
118 EM_DEBUG_LOG("**PROFILE END** [EMAILFW: %s() :%s %u ~ %u] " #pfid \
119 " -> Elapsed Time: %u.%06u seconds\n",\
121 rindex(__FILE__, '/')+1,\
124 (unsigned int)(__ds),\
125 (unsigned int)(__dm));\
129 #define EM_PROFILE_BEGIN(pfid)
130 #define EM_PROFILE_END(pfid)
135 #else /* __FEATURE_DEBUG_LOG__ */
137 #define EM_DEBUG_LINE
138 #define EM_DEBUG_LOG(format, arg...)
139 #define EM_DEBUG_ASSERT(format, arg...)
140 #define EM_DEBUG_EXCEPTION(format, arg...)
143 #define EM_DEBUG_DB_EXEC(eval, expr, X) if (eval) { EM_DEBUG_DB X; expr;} else {;}
144 #define EM_PROFILE_BEGIN(pfid)
145 #define EM_PROFILE_END(pfid)
147 #endif /* __FEATURE_DEBUG_LOG__ */
150 #define EM_NULL_CHECK_FOR_VOID(expr) \
153 EM_DEBUG_EXCEPTION ("INVALID PARAM: "#expr" NULL ");\
158 #define EM_IF_NULL_RETURN_VALUE(expr, val) \
161 EM_DEBUG_EXCEPTION ("INVALID PARAM: "#expr" NULL ");\
166 #define EM_RETURN_ERR_CODE(err_ptr, err_code, ret) \
168 if(err_ptr) *err_ptr = err_code;\
172 #define EM_EXIT_ERR_CODE(err_ptr, err_code) \
174 if(err_ptr) *err_ptr = err_code;\
179 #define EM_SAFE_FREE(expr) \
187 #define EM_SAFE_STRDUP(s) \
189 char* _s = (char*)s;\
190 (_s)? strdup(_s) : NULL;\
193 #define EM_SAFE_STRCMP(dest, src) \
197 ((_src) && (_dest))? strcmp(_dest, _src) : -1;\
200 #define EM_SAFE_STRCPY(dest, src) \
204 ((_src) && (_dest))? strcpy(_dest, _src) : NULL;\
207 #define EM_SAFE_STRNCPY(dest, src, size) \
212 ((_src) && (_dest))? strncpy(_dest, _src, _size) : NULL;\
215 #define EM_SAFE_STRCAT(dest, src) \
219 ((_src) && (_dest))? strcat(_dest, _src) : NULL;\
222 #define EM_SAFE_STRLEN(s) \
224 char* _s = (char*)s;\
225 (_s)? strlen(_s) : 0;\
229 #define EM_IF_ACCOUNT_ID_NULL(expr, ret) {\
231 EM_DEBUG_EXCEPTION ("EM_IF_ACCOUNT_ID_NULL: Account ID [ %d ] ", expr);\
237 #define EM_STRERROR(err) ({ char buf[128]; strerror_r(err, buf, sizeof(buf));})
242 #endif /* __cplusplu */
244 #endif /* __EMAIL_DEBUG_LOG_H__ */