2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief This is the header file for the diagnostic types.
22 * This header file defines the diagnostic types.
29 #include <FOspConfig.h>
36 * @defgroup GroupMacros Debugging Macros
38 * This page describes Tizen debugging macros.
43 #if defined(_APP_LOG) || defined(_OSP_DEBUG_) || defined(_DEBUG)
47 #define AppLog(...) AppLogInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
48 #define AppLogDebug(...) AppLogDebugInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
49 #define AppLogException(...) AppLogExceptionInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
51 #define AppLogTag(tag, ...) AppLogTagInternal(tag, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
52 #define AppLogDebugTag(tag, ...) AppLogDebugTagInternal(tag, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
53 #define AppLogExceptionTag(tag, ...) AppLogExceptionTagInternal(tag, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
55 #define AppLogIf(expression, ...) \
57 AppLogInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
61 #define AppLogDebugIf(expression, ...) \
63 AppLogDebugInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
67 #define AppLogExceptionIf(expression, ...) \
69 AppLogExceptionInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
73 #define AppAssert(condition) \
75 AppassertInternal(__PRETTY_FUNCTION__, __LINE__); \
79 #define AppAssertf(condition, ...) \
81 AppassertfInternal(# condition, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
84 #else // defined(_APP_LOG)
87 * @addtogroup GroupMacros
92 * This macro allows display of arbitrary messages for future examination.
96 * @param[in] ... The message to display
98 * The following example demonstrates how to use the AppLog macro.
102 * MyEngine::Init(int value)
104 * AppLog("Initialization successful.");
114 * This macro must be added in your program if you want the debug messages to be displayed in the output.
118 * @param[in] ... The message to display
120 * @image html debugging_applog_output.png
122 * The following example demonstrates how to use the AppLogDebug macro.
126 * MyEngine::Init(int value)
128 * AppLogDebug("Invoked with value: %d", value);
132 * AppLogDebug("Exit.");
139 #define AppLogDebug(...)
142 * This macro must be added in your program if you want the exception messages to be displayed in the output.
146 * @param[in] ... The message to display
148 * The following example demonstrates how to use the AppLogException macro.
152 * MyEngine::Init(int value)
154 * AppLogDebug("Invoked with value: %d", value);
156 * if (something_wrong) // The Try family macros can be used instead.
158 * AppLogException("An unexpected error occurred.");
163 * AppLog("Initialization successful.");
164 * AppLogDebug("Exit.");
171 #define AppLogException(...)
174 * This macro is used to check logical errors in a program.
175 * If the assertion fails, the current process is killed.
179 * @param[in] condition The condition that is expected to be true
182 #define AppAssert(condition)
185 * This macro is used to check logical errors in a program.
186 * If the assertion fails, a message is printed on the console and the current process is killed.
190 * @param[in] condition The condition that is expected to be true
191 * @param[in] ... The message to print, if the assertion fails
193 * @image html debugging_appassert.png
195 * The following example demonstrates how to use the Assert macro.
199 * MyClass::DoSomething(void)
201 * result r = E_SUCCESS;
202 * r = mutex.Acquire();
204 * r = mutex.Release();
206 * // If false, console prints "Mutex Release Failed."
207 * // and the process is killed.
208 * AppAssertf(r == E_SUCCESS, "Mutex Release Failed.");
215 #define AppAssertf(condition, ...)
218 * This macro is added in a program to display a message when an expression is @c true.
222 * @param[in] expression The expression to evaluate
223 * @param[in] ... The message to display
225 * The following example demonstrates how to use the AppLogIf macro.
229 * MyEngine::Init(int value)
231 * AppLogIf(value !=0, "Invoked with value: %d", value);
239 #define AppLogIf(expression, ...)
242 * This macro is added in a program to display a debug message when an expression is @c true.
246 * @param[in] expression The expression to evaluate
247 * @param[in] ... The message to display
249 * The following example demonstrates how to use the AppLogDebugIf macro.
253 * MyEngine::Init(int value)
255 * AppLogDebugIf(value !=0, "Invoked with value: %d", value);
263 #define AppLogDebugIf(expression, ...)
266 * This macro is added in a program to display an exception message when an expression is @c true.
270 * @param[in] expression The expression to evaluate
271 * @param[in] ... The message to display
273 * The following example demonstrates how to use the AppLogExceptionIf macro.
277 * MyEngine::Init(int value)
281 * AppLogExceptionIf(status != 0, "status : %d.", status);
289 #define AppLogExceptionIf(expression, ...)
292 * This macro is added in a program to display an info message with a tag.
296 * @param[in] tag Used to identify the source of a log message
297 * @param[in] ... The message to display
299 * The following example demonstrates how to use the AppLogTag macro.
303 * MyEngine::Init(int value)
307 * AppLogTag("MyTag", "Initialization successful.");
315 #define AppLogTag(tag, ...)
318 * This macro is added in a program to display a debug message with a tag.
322 * @param[in] tag Used to identify the source of a log message
323 * @param[in] ... The message to display
325 * The following example demonstrates how to use the AppLogDebugTag macro.
329 * MyEngine::Init(int value)
331 * AppLogDebugTag("MyTag", "Invoked with value: %d", value);
335 * AppLogDebugTag("MyTag", "Exit.");
342 #define AppLogDebugTag(tag, ...)
345 * This macro is added in a program to display an exception message with a tag.
349 * @param[in] tag Used to identify the source of a log message
350 * @param[in] ... The message to display
352 * The following example demonstrates how to use the AppLogExceptionTag macro.
356 * MyEngine::Init(int value)
358 * AppLogDebug("Invoked with value: %d", value);
360 * if (something_wrong) // The Try family macros can be used instead.
362 * AppLogExceptionTag("MyTag", "An unexpected error occurred.");
367 * AppLog("Initialization successful.");
368 * AppLogDebug("Exit.");
375 #define AppLogExceptionTag(tag, ...)
377 #endif // defined(_APP_LOG)
381 * @addtogroup GroupMacros
386 * If the condition is @c false, it prints a message, evaluates a cleanup expression,
387 * and goes to <tt>CATCH</tt>.
391 * @param[in] condition The condition that is expected to be true
392 * @param[in] expr Expressions that are evaluated before going to CATCH label
393 * @param[in] ... The message to display
395 * The following example demonstrates how to use the Try macro.
399 * MyClass::DoSomething(const wchar_t* pValue)
401 * result r = E_SUCCESS;
405 * // If pValue is null, print "pValue == null" to the
406 * // console and return E_INVALID_ARG.
407 * TryCatch(pValue != null, r = E_INVALID_ARG, "pValue == null");
409 * SetLastResult(E_SUCCESS);
421 #define TryCatch(condition, expr, ...) \
422 if (!(condition)) { \
423 AppLogException(__VA_ARGS__); \
430 * If the condition is @c false, it prints a message, sets the last result, evaluates a cleanup expression
431 * and goes to <tt>CATCH</tt>.
435 * @param[in] condition The condition that is expected to be true
436 * @param[in] expr Expressions that are evaluated before going to CATCH label
437 * @param[in] r The last result to set
438 * @param[in] ... The message to display
441 #define TryCatchResult(condition, expr, r, ...) \
442 if (!(condition)) { \
444 AppLogException(__VA_ARGS__); \
451 * If the condition is @c false, the message is printed and a value is returned.
455 * @param[in] condition The condition that is expected to be true
456 * @param[in] returnValue The value to return when the condition is @c false
457 * @param[in] ... The message to display
460 #define TryReturn(condition, returnValue, ...) \
461 if (!(condition)) { \
462 AppLogException(__VA_ARGS__); \
463 return returnValue; \
468 * If the condition is @c false, the message is printed, sets the last result and a value is returned.
472 * @param[in] condition The condition that is expected to be true
473 * @param[in] returnValue The value to return when the condition is @c false
474 * @param[in] r The last result to set
475 * @param[in] ... The message to display
478 #define TryReturnResult(condition, returnValue, r, ...) \
479 if (!(condition)) { \
481 AppLogException(__VA_ARGS__); \
482 return returnValue; \
487 * If the condition is @c false, the message is printed, sets the last result and no value is returned.
491 * @param[in] condition The condition that is expected to be true
492 * @param[in] r The last result to set
493 * @param[in] ... The message to display
496 #define TryReturnVoidResult(condition, r, ...) \
497 if (!(condition)) { \
499 AppLogException(__VA_ARGS__); \
505 * If the condition is @c false, the message is printed and no value is returned.
509 * @param[in] condition The condition that is expected to be true
510 * @param[in] ... The message to display
513 #define TryReturnVoid(condition, ...) \
514 if (!(condition)) { \
515 AppLogException(__VA_ARGS__); \
521 * If the condition is @c false, the message is printed.
525 * @param[in] condition The condition that is expected to be true
526 * @param[in] ... The message to display
529 #define TryLog(condition, ...) \
530 if (!(condition)) { \
531 AppLog(__VA_ARGS__); \
539 * If the condition is @c false, it prints a message with a tag, evaluates a cleanup expression
540 * and goes to <tt>CATCH</tt>.
544 * @param[in] tag Used to identify the source of a log message
545 * @param[in] condition The condition that is expected to be true
546 * @param[in] expr Expressions that are evaluated before going to CATCH label
547 * @param[in] ... The message to display
550 #define TryCatchTag(tag, condition, expr, ...) \
551 if (!(condition)) { \
552 AppLogExceptionTag(tag, __VA_ARGS__); \
559 * If the condition is @c false, it prints a message with a tag, sets the last result, evaluates a cleanup expression,
560 * and goes to <tt>CATCH</tt>.
564 * @param[in] tag Used to identify the source of a log message
565 * @param[in] condition The condition that is expected to be true
566 * @param[in] expr Expressions that are evaluated before going to CATCH label
567 * @param[in] r The last result to set
568 * @param[in] ... The message to display
571 #define TryCatchResultTag(tag, condition, expr, r, ...) \
572 if (!(condition)) { \
574 AppLogExceptionTag(tag, __VA_ARGS__); \
581 * If the condition is @c false, the message is printed with a tag and a value is returned.
585 * @param[in] tag Used to identify the source of a log message
586 * @param[in] condition The condition that is expected to be true
587 * @param[in] returnValue The value to return when the condition is @c false
588 * @param[in] ... The message to display
591 #define TryReturnTag(tag, condition, returnValue, ...) \
592 if (!(condition)) { \
593 AppLogExceptionTag(tag, __VA_ARGS__); \
594 return returnValue; \
599 * If the condition is @c false, the message is printed with a tag, sets the last result and a value is returned.
603 * @param[in] tag Used to identify the source of a log message
604 * @param[in] condition The condition that is expected to be true
605 * @param[in] returnValue The value to return when the condition is @c false
606 * @param[in] r The last result to set
607 * @param[in] ... The message to display
610 #define TryReturnResultTag(tag, condition, returnValue, r, ...) \
611 if (!(condition)) { \
613 AppLogExceptionTag(tag, __VA_ARGS__); \
614 return returnValue; \
619 * If the condition is @c false, the message is printed with a tag, sets the last result and no value is returned.
623 * @param[in] tag Used to identify the source of a log message
624 * @param[in] condition The condition that is expected to be true
625 * @param[in] r The last result to set
626 * @param[in] ... The message to display
629 #define TryReturnVoidResultTag(tag, condition, r, ...) \
630 if (!(condition)) { \
632 AppLogExceptionTag(tag, __VA_ARGS__); \
638 * If the condition is @c false, the message is printed with a tag and no value is returned.
642 * @param[in] tag Used to identify the source of a log message
643 * @param[in] condition The condition that is expected to be true
644 * @param[in] ... The message to display
647 #define TryReturnVoidTag(tag, condition, ...) \
648 if (!(condition)) { \
649 AppLogExceptionTag(tag, __VA_ARGS__); \
655 * If the condition is @c false, the message is printed with a tag.
659 * @param[in] tag Used to identify the source of a log message
660 * @param[in] condition The condition that is expected to be true
661 * @param[in] ... The message to display
664 #define TryLogTag(tag, condition, ...) \
665 if (!(condition)) { \
666 AppLogTag(tag, __VA_ARGS__); \
672 _OSP_EXPORT_ void AppLogInternal(const char* pFunction, int lineNumber, const char* pFormat, ...);
673 _OSP_EXPORT_ void AppLogDebugInternal(const char* pFunction, int lineNumber, const char* pFormat, ...);
674 _OSP_EXPORT_ void AppLogExceptionInternal(const char* pFunction, int lineNumber, const char* pFormat, ...);
675 _OSP_EXPORT_ void AppassertInternal(const char* pFunction, int lineNumber);
676 _OSP_EXPORT_ void AppassertfInternal(const char* expr, const char* pFunction, int lineNumber, const char* pFormat, ...);
678 _OSP_EXPORT_ void AppLogTagInternal(const char* pTag, const char* pFunction, int lineNumber, const char* pFormat, ...);
679 _OSP_EXPORT_ void AppLogDebugTagInternal(const char* pTag, const char* pFunction, int lineNumber, const char* pFormat, ...);
680 _OSP_EXPORT_ void AppLogExceptionTagInternal(const char* pTag, const char* pFunction, int lineNumber, const char* pFormat, ...);
687 #endif // _FBASE_LOG_H_