2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @brief This is the header file for the %Log macros.
21 * This header file defines the %Log macros.
24 #ifndef _FBASE_SYS_LOG_H_
25 #define _FBASE_SYS_LOG_H_
28 #include <FOspConfig.h>
29 #include <FBaseDataType.h>
30 #include <FIoRegistry.h>
37 #define likely(x) __builtin_expect(!!(x), 1)
40 #define unlikely(x) __builtin_expect(!!(x), 0)
44 * @mainpage Tizen Platform API Reference
46 * The Tizen platform API Reference provides descriptions of APIs for the platform developers.
50 * @defgroup GroupMacros Debugging Macros
52 * This page describes Tizen debugging macros used by the Tizen modules.
53 * These debugging macros should use specific NID ( Namespace ID ) to distinguish each Tizen modules.
60 * @addtogroup GroupMacros
66 * This macro allows display of informative log messages.
67 * This system log macro is for the platform modules.
71 * @param[in] NID The Tizen namespace
72 * @param[in] ... The message to display
74 * The following example demonstrates how to use the SysLog macro.
78 * MyEngine::Init(int value)
80 * SysLog(NID, "Initialization successful.");
87 #define SysLog(NID, ...) SysLogInternal(NID, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
90 * This macro allows display of exception log messages with a tag and sets the last result.
91 * This system log macro is for the platform modules.
95 * @param[in] NID The Tizen namespace
96 * @param[in] r The last result to set
97 * @param[in] ... The message to display
99 * The following example demonstrates how to use the SysLogException macro.
103 * MyEngine::Init(int value)
106 * if (something_wrong) // The Try family macros can be used instead.
108 * SysLogException(NID, E_INVALID_ARG, "An unexpected error has occurred.");
119 #define SysLogException(NID, r, ...) SysLogExceptionInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
122 * This macro allows display of informative log messages with a tag.
123 * This system log macro is for the platform modules.
127 * @param[in] NID The Tizen namespace
128 * @param[in] tag The user defined tag
129 * @param[in] ... The message to display
131 * The following example demonstrates how to use the SysLogTag macro.
135 * MyEngine::Init(int value)
137 * SysLogTag(NID, "MyTag", "Initialization successful.");
144 #define SysLogTag(NID, tag, ...) SysLogTagInternal(NID, tag, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
147 * This macro allows display of exception log messages with a tag and sets the last result.
148 * This system log macro is for the platform modules.
152 * @param[in] NID The Tizen namespace
153 * @param[in] tag The user defined tag
154 * @param[in] r The last result to set
155 * @param[in] ... The message to display
157 * The following example demonstrates how to use the SysLogTagException macro.
161 * MyEngine::Init(int value)
163 * SysLogExceptionTag(NID, "MyTag", E_INVALID_ARG, "Initialization successful.");
170 #define SysLogExceptionTag(NID, tag, r, ...) SysLogExceptionTagInternal(NID, tag, r, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
175 * This macro allows display of informative log message with a tag, when the condition is @c false.
176 * This system log macro is for the platform modules.
180 * @param[in] NID The Tizen namespace
181 * @param[in] condition The condition that is expected to be true
182 * @param[in] ... The message to display
184 * The following example demonstrates how to use the SysTryLog macro.
188 * MyEngine::Init(int value)
192 * SysTryLog(NID, condition, "An unexpected error has occurred.");
199 #define SysTryLog(NID, condition, ...) \
202 if (unlikely(!(condition))) { \
203 SysLog(NID, __VA_ARGS__); \
208 * This macro allows display of informative log message, when the condition is @c false.
209 * Executes statements and goes to label.
210 * This system log macro is for the platform modules.
214 * @param[in] NID The Tizen namespace
215 * @param[in] condition The condition that is expected to be true
216 * @param[in] expr Expressions that are evaluated before going to CATCH label
217 * @param[in] ... The message to display
219 * The following example demonstrates how to use the SysTryLogCatch macro.
223 * MyEngine::Init(int value)
227 * SysTryLogCatch(NID, condition, r=E_INVALID_ARG, "An unexpected error has occurred.");
236 #define SysTryLogCatch(NID, condition, expr, ...) \
239 if (unlikely(!(condition))) { \
240 SysLog(NID, __VA_ARGS__); \
247 * This macro allows display of informative log message and returns returnValue, when the condition is @c false.
248 * This system log macro is for the platform modules.
252 * @param[in] NID The Tizen namespace
253 * @param[in] condition The condition that is expected to be true
254 * @param[in] returnValue The value to return when the condition is @c false
255 * @param[in] ... The message to display
257 * The following example demonstrates how to use the SysTryLogReturn macro.
261 * MyEngine::Init(int value)
265 * SysTryLogReturn(NID, condition, false, "An unexpected error has occurred.");
273 #define SysTryLogReturn(NID, condition, returnValue, ...) \
276 if (unlikely(!(condition))) { \
277 SysLog(NID, __VA_ARGS__); \
278 return returnValue; \
284 * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
285 * This system log macro is for the platform modules.
289 * @param[in] NID The Tizen namespace
290 * @param[in] condition The condition that is expected to be true
291 * @param[in] returnValue The value to return when the condition is @c false
292 * @param[in] r The last result to set
293 * @param[in] ... The message to display
295 * The following example demonstrates how to use the SysTryReturn macro.
299 * MyEngine::Init(int value)
303 * SysTryReturn(NID, condition, false, E_INVALID_ARG, "An unexpected error has occurred.");
311 #define SysTryReturn(NID, condition, returnValue, r, ...) \
314 if (unlikely(!(condition))) { \
315 SysLogException(NID, r, __VA_ARGS__); \
316 return returnValue; \
321 * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
322 * This is a shorthand macro for SysTryReturn(NID, condition, r, r, "[" # r "] " ...).
323 * This system log macro is for the platform modules.
327 * @param[in] NID The Tizen namespace
328 * @param[in] condition The condition that is expected to be true
329 * @param[in] r The last result to set
330 * @param[in] ... The message to display
332 * The following example demonstrates how to use the SysTryReturnResult macro.
335 * #define E_UNKNOWN_ERROR 1
337 * MyEngine::Init(int value)
341 * SysTryReturnResult(NID, condition, E_UNKNOWN_ERROR, "An unexpected error has occurred.");
349 #define SysTryReturnResult(NID, condition, r, ...) \
352 if (unlikely(!(condition))) { \
353 SysTryReturnResultInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
359 * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
360 * This system log macro is for the platform modules.
364 * @param[in] NID The Tizen namespace
365 * @param[in] condition The condition that is expected to be true
366 * @param[in] r The last result to set
367 * @param[in] ... The message to display
369 * The following example demonstrates how to use the SysTryReturnVoidResult macro.
373 * MyEngine::Init(int value)
377 * SysTryReturnVoidResult(NID, condition, E_INVALID_ARG, "An unexpected error has occurred.");
385 #define SysTryReturnVoidResult(NID, condition, r, ...) \
388 if (unlikely(!(condition))) { \
389 SysLogException(NID, r, __VA_ARGS__); \
395 * This macro allows display of exception log message with a tag, when the condition is @c false.
396 * Executes statements, sets the last result and goes to label.
397 * This system log macro is for the platform modules.
401 * @param[in] NID The Tizen namespace
402 * @param[in] condition The condition that is expected to be true
403 * @param[in] expr Expressions that are evaluated before going to CATCH label
404 * @param[in] r The last result to set
405 * @param[in] ... The message to display
407 * The following example demonstrates how to use the SysTryCatch macro.
411 * MyEngine::Init(int value)
415 * SysTryCatch(NID, condition, r=E_INVALID_ARG, E_INVALID_ARG, "An unexpected error has occurred.");
424 #define SysTryCatch(NID, condition, expr, r, ...) \
427 if (unlikely(!(condition))) { \
428 SysLogException(NID, r, __VA_ARGS__); \
435 * This macro allows display of exception log message with a tag, when the condition is @c false.
436 * Executes statements, sets the last result and goes to label.
437 * This system log macro is for the platform modules.
441 * @param[in] NID The Tizen namespace
442 * @param[in] condition The condition that is expected to be true
443 * @param[in] expr Expressions that are evaluated before going to catchLabel label
444 * @param[in] catchLabel The label for goto operation
445 * @param[in] r The last result to set
446 * @param[in] ... The message to display
448 * The following example demonstrates how to use the SysTryCatchLabel macro.
452 * MyEngine::Init(int value)
456 * SysTryCatchLabel(NID, condition, r=E_INVALID_ARG, LABEL, E_INVALID_ARG, "An unexpected error has occurred.");
465 #define SysTryCatchLabel(NID, condition, expr, catchLabel, r, ...) \
468 if (unlikely(!(condition))) { \
469 SysLogException(NID, r, __VA_ARGS__); \
477 * This macro allows display of exception log message and the program will expire, when the condition is @c false.
478 * This system log macro is for the platform modules.
482 * @param[in] condition The condition that is expected to be true
484 * The following example demonstrates how to use the SysAssert macro.
488 * MyEngine::Init(int value)
492 * SysAssert(condition);
499 #define SysAssert(condition) \
502 if (unlikely(!(condition))) { \
503 SysAssertInternal(__FILE__, __LINE__, __PRETTY_FUNCTION__); \
508 * This macro allows display of exception log message with a tag and the program will expire, when the condition is @c false.
509 * This system log macro is for the platform modules.
513 * @param[in] condition The condition that is expected to be true
514 * @param[in] ... The message to display
516 * The following example demonstrates how to use the SysAssertf macro.
520 * MyEngine::Init(int value)
524 * SysAssertf(condition, "");
531 #define SysAssertf(condition, ...) \
534 if (unlikely(!(condition))) { \
535 SysAssertfInternal(# condition, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
541 * This macro generates an error message during compile time, when the condition is @c false.
542 * This system log macro is for the platform modules.
546 * @param[in] condition The condition that is expected to be true
548 * The following example demonstrates how to use the SysStaticAssert macro.
552 * MyEngine::Init(int value)
556 * SysStaticAssert(condition);
563 #define SysStaticAssert(condition) switch (0) { \
571 * This macro allows display of exception log messages.
572 * This system log macro is for the platform modules.
576 * @param[in] NID The Tizen namespace
577 * @param[in] r The last result to set
579 * The following example demonstrates how to use the SysPropagate macro.
583 * MyEngine::Init(int value)
587 * SysPropagate(NID, E_INVALID_ARG);
594 #define SysPropagate(NID, r) SysPropagateInternal(__PRETTY_FUNCTION__, __LINE__, NID, r)
597 #if defined(_SECURE_LOG)
599 #define SysSecureLog(NID, ...) SysLogInternal(NID, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
600 #define SysSecureLogException(NID, r,...) SysLogExceptionInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
602 #define SysSecureLogTag(NID, tag, ...) SysLogTagInternal(NID, tag, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
603 #define SysSecureLogExceptionTag(NID, tag, r, ...) SysLogExceptionTagInternal(NID, tag, r, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
608 * This macro is to protect informative log messages which needs to keep security.
609 * It allows display of informative log messages if compiled with "_SECURE_LOG" definition.
610 * Otherwise, it will be removed in the compile time.
611 * This system log macro is for the platform modules.
615 * @param[in] NID The Tizen namespace ID
616 * @param[in] ... The message to display
618 * The following example demonstrates how to use the SysSecureLog macro.
622 * MyEngine::Init(int value)
624 * SysSecureLog(NID, "User ID : 'JoneDoe'");
631 #define SysSecureLog(NID, ...)
634 * This macro is to protect exception log messages which needs to keep security, and sets the last result.
635 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
636 * Otherwise, log printing functionality will be removed in the compile time.
637 * This system log macro is for the platform modules.
641 * @param[in] NID The Tizen namespace ID
642 * @param[in] r The last result to set
643 * @param[in] ... The message to display
645 * The following example demonstrates how to use the SysSecureLogException macro.
649 * MyEngine::Init(int value)
652 * if (something_wrong)
654 * SysSecureLogException(NID, E_INVALID_ARG, "User ID : 'JoneDoe' mismatch.");
665 #define SysSecureLogException(NID, r,...) SetLastResult(r);
668 * This macro is to protect informative log messages which needs to keep security, with a tag.
669 * It allows display of informative log messages if compiled with "_SECURE_LOG" definition.
670 * Otherwise, it will be removed in the compile time.
671 * This system log macro is for the platform modules.
675 * @param[in] NID The Tizen namespace ID
676 * @param[in] tag The user defined tag
677 * @param[in] ... The message to display
679 * The following example demonstrates how to use the SysSecureLogTag macro.
683 * MyEngine::Init(int value)
685 * SysSecureLogTag(NID, "MyTag", "User ID : 'JoneDoe'");
692 #define SysSecureLogTag(NID, tag, ...)
695 * This macro is to protect exception log messages which needs to keep security, with a tag and sets the last result.
696 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
697 * Otherwise, log printing functionality will be removed in the compile time.
698 * This system log macro is for the platform modules.
702 * @param[in] NID The Tizen namespace ID
703 * @param[in] tag The user defined tag
704 * @param[in] r The last result to set
705 * @param[in] ... The message to display
707 * The following example demonstrates how to use the SysSecureLogExceptionTag macro.
711 * MyEngine::Init(int value)
713 * SysSecureLogExceptionTag(NID, "MyTag", E_INVALID_ARG, "User ID : 'JoneDoe' mismatch.");
720 #define SysSecureLogExceptionTag(NID, tag, r, ...) SetLastResult(r);
725 * This macro allows display of informative log message with a tag, when the condition is @c false.
726 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
727 * Otherwise, log printing functionality will be removed in the compile time.
728 * This system log macro is for the platform modules.
732 * @param[in] NID The Tizen namespace
733 * @param[in] condition The condition that is expected to be true
734 * @param[in] ... The message to display
736 * The following example demonstrates how to use the SysSecureTry macro.
740 * MyEngine::Init(int value)
744 * SysSecureTryLog(NID, condition, "Password mismatch : %s", password );
751 #define SysSecureTryLog(NID, condition, ...) \
754 if (unlikely(!(condition))) { \
755 SysSecureLog(NID, __VA_ARGS__); \
760 * This macro allows display of informative log message, when the condition is @c false.
761 * Executes statements and goes to label.
762 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
763 * Otherwise, log printing functionality will be removed in the compile time.
764 * This system log macro is for the platform modules.
768 * @param[in] NID The Tizen namespace
769 * @param[in] condition The condition that is expected to be true
770 * @param[in] expr Expressions that are evaluated before going to CATCH label
771 * @param[in] ... The message to display
774 #define SysSecureTryLogCatch(NID, condition, expr, ...) \
777 if (unlikely(!(condition))) { \
778 SysSecureLog(NID, __VA_ARGS__); \
785 * This macro allows display of informative log message and returns returnValue, when the condition is @c false.
786 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
787 * Otherwise, log printing functionality will be removed in the compile time.
788 * This system log macro is for the platform modules.
792 * @param[in] NID The Tizen namespace
793 * @param[in] condition The condition that is expected to be true
794 * @param[in] returnValue The value to return when the condition is @c false
795 * @param[in] ... The message to display
798 #define SysSecureTryLogReturn(NID, condition, returnValue, ...) \
801 if (unlikely(!(condition))) { \
802 SysSecureLog(NID, __VA_ARGS__); \
803 return returnValue; \
808 * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
809 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
810 * Otherwise, log printing functionality will be removed in the compile time.
811 * This system log macro is for the platform modules.
815 * @param[in] NID The Tizen namespace
816 * @param[in] condition The condition that is expected to be true
817 * @param[in] returnValue The value to return when the condition is @c false
818 * @param[in] r The last result to set
819 * @param[in] ... The message to display
822 #define SysSecureTryReturn(NID, condition, returnValue, r, ...) \
825 if (unlikely(!(condition))) { \
826 SysSecureLogException(NID, r, __VA_ARGS__); \
827 return returnValue; \
831 #if defined(_SECURE_LOG)
833 * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
834 * This is a shorthand macro for SysSecureTryReturn(NID, condition, r, r, "[" # r "] " ...).
835 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
836 * Otherwise, log printing functionality will be removed in the compile time.
837 * This system log macro is for the platform modules.
841 * @param[in] NID The Tizen namespace
842 * @param[in] condition The condition that is expected to be true
843 * @param[in] r The last result to set
844 * @param[in] ... The message to display
847 #define SysSecureTryReturnResult(NID, condition, r, ...) \
850 if (unlikely(!(condition))) { \
851 SysTryReturnResultInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__); \
857 #define SysSecureTryReturnResult(NID, condition, r, ...) \
860 if (unlikely(!(condition))) { \
868 * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
869 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
870 * Otherwise, log printing functionality will be removed in the compile time.
871 * This system log macro is for the platform modules.
875 * @param[in] NID The Tizen namespace
876 * @param[in] condition The condition that is expected to be true
877 * @param[in] r The last result to set
878 * @param[in] ... The message to display
881 #define SysSecureTryReturnVoidResult(NID, condition, r, ...) \
884 if (unlikely(!(condition))) { \
885 SysSecureLogException(NID, r, __VA_ARGS__); \
891 * This macro allows display of exception log message with a tag, when the condition is @c false.
892 * Executes statements, sets the last result and goes to label.
893 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
894 * Otherwise, log printing functionality will be removed in the compile time.
895 * This system log macro is for the platform modules.
899 * @param[in] NID The Tizen namespace
900 * @param[in] condition The condition that is expected to be true
901 * @param[in] expr Expressions that are evaluated before going to CATCH label
902 * @param[in] r The last result to set
903 * @param[in] ... The message to display
906 #define SysSecureTryCatch(NID, condition, expr, r, ...) \
909 if (unlikely(!(condition))) { \
910 SysSecureLogException(NID, r, __VA_ARGS__); \
917 * This macro allows display of exception log message with a tag, when the condition is @c false.
918 * Executes statements, sets the last result and goes to label.
919 * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
920 * Otherwise, log printing functionality will be removed in the compile time.
921 * This system log macro is for the platform modules.
925 * @param[in] NID The Tizen namespace
926 * @param[in] condition The condition that is expected to be true
927 * @param[in] expr Expressions that are evaluated before going to catchLabel label
928 * @param[in] catchLabel The label for goto operation
929 * @param[in] r The last result to set
930 * @param[in] ... The message to display
933 #define SysSecureTryCatchLabel(NID, condition, expr, catchLabel, r, ...) \
936 if (unlikely(!(condition))) { \
937 SysSecureLogException(NID, r, __VA_ARGS__); \
945 * Defines the log ID.
949 //Tizen Namespace ID ===============================================================
984 NID_SEC_CRYPTO = 112,
1002 NID_UIX_SPEECH = 171,
1015 _OSP_EXPORT_ void SysLogInternal(unsigned long id, const char* pFunction, int lineNumber, const char* pFormat, ...);
1016 _OSP_EXPORT_ void SysLogExceptionInternal(unsigned long id, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
1018 _OSP_EXPORT_ void SysLogTagInternal(unsigned long id, const char* pTag, const char* pFunction, int lineNumber, const char* pFormat, ...);
1019 _OSP_EXPORT_ void SysLogExceptionTagInternal(unsigned long id, const char* pTag, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
1021 _OSP_EXPORT_ void SysAssertInternal(const char* pFileName, int lineNumber, const char* pFunction);
1022 _OSP_EXPORT_ void SysAssertfInternal(const char* expr, const char* pFunction, int lineNumber, const char* pFormat, ...);
1024 _OSP_EXPORT_ void SysPropagateInternal(const char* pFunction, int lineNumber, unsigned long nid, result r);
1026 _OSP_EXPORT_ void SysTryReturnResultInternal(unsigned long id, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
1030 #endif // __cplusplus
1033 #endif // _FBASE_SYS_LOG_H_