Enable build with iniparser v 3.1
[platform/framework/native/appfw.git] / inc / FBaseLog.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FBaseLog.h
19  * @brief               This is the header file for the diagnostic types.
20  *
21  * This header file defines the diagnostic types.
22  *
23  */
24 #ifndef _FBASE_LOG_H_
25 #define _FBASE_LOG_H_
26
27 #include <new>
28 #include <FOspConfig.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /**
35  * @defgroup GroupMacros Debugging Macros
36  *
37  * This page describes the Tizen debugging macros.
38  *
39  * @since 2.0
40  */
41
42 #if defined(_APP_LOG) || defined(_OSP_DEBUG_) || defined(_DEBUG)
43
44 // AppLog Macro
45
46 #define AppLog(...)                     AppLogInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
47 #define AppLogDebug(...)                AppLogDebugInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
48 #define AppLogException(...)            AppLogExceptionInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
49
50 #define AppLogTag(tag, ...)                     AppLogTagInternal(tag, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
51 #define AppLogDebugTag(tag, ...)                AppLogDebugTagInternal(tag, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
52 #define AppLogExceptionTag(tag, ...)            AppLogExceptionTagInternal(tag, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
53
54 #define AppLogIf(expression, ...) \
55         if (expression) { \
56                 AppLogInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__);     \
57         } \
58         else {;}
59
60 #define AppLogDebugIf(expression, ...) \
61         if (expression) { \
62                 AppLogDebugInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
63         } \
64         else {;}
65
66 #define AppLogExceptionIf(expression, ...) \
67         if (expression) { \
68                 AppLogExceptionInternal(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
69         } \
70         else {;}
71
72 #define AppAssert(condition) \
73         if (!(condition)) {     \
74                 AppassertInternal(__PRETTY_FUNCTION__, __LINE__); \
75         } \
76         else {;}
77
78 #define AppAssertf(condition, ...)      \
79         if (!(condition)) {     \
80                 AppassertfInternal(# condition, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
81         } \
82         else {;}
83 #else // defined(_APP_LOG)
84
85 /**
86  * @addtogroup  GroupMacros
87  *
88  * @{
89  */
90 /**
91  * This macro allows the display of arbitrary messages for future examination.
92  *
93  * @since 2.0
94  *
95  * @param[in]   ...                     The message to display
96  *
97  * The following example demonstrates how to use the AppLog macro.
98  *
99  * @code
100  *      bool
101  *      MyEngine::Init(int value)
102  *      {
103  *         AppLog("Initialization successful.");
104  *
105  *         return true;
106  *      }
107  * @endcode
108  * @hideinitializer
109  */
110 #define AppLog(...)
111
112 /**
113  * This macro must be added in your program if you want the debug messages to be displayed in the output.
114  *
115  * @since 2.0
116  *
117  * @param[in]   ...                     The message to display
118  *
119  *  @image html debugging_applog_output.png
120  *
121  * The following example demonstrates how to use the AppLogDebug macro.
122  *
123  * @code
124  *      bool
125  *      MyEngine::Init(int value)
126  *      {
127  *         AppLogDebug("Invoked with value: %d", value);
128  *
129  *         //...
130  *
131  *         AppLogDebug("Exit.");
132  *
133  *         return true;
134  *      }
135  * @endcode
136  * @hideinitializer
137  */
138 #define AppLogDebug(...)
139
140 /**
141  * This macro must be added in your program if you want the exception messages to be displayed in the output.
142  *
143  * @since 2.0
144  *
145  * @param[in]   ...                     The message to display
146  *
147  * The following example demonstrates how to use the AppLogException macro.
148  *
149  * @code
150  *      bool
151  *      MyEngine::Init(int value)
152  *      {
153  *         AppLogDebug("Invoked with value: %d", value);
154  *         //...
155  *         if (something_wrong)   // The Try family macros can be used instead.
156  *         {
157  *            AppLogException("An unexpected error occurred.");
158  *
159  *            return false;
160  *         }
161  *
162  *         AppLog("Initialization successful.");
163  *         AppLogDebug("Exit.");
164  *
165  *         return true;
166  *      }
167  * @endcode
168  * @hideinitializer
169  */
170 #define AppLogException(...)
171
172 /**
173  * This macro is used to check logical errors in a program.
174  * If the assertion fails, the current process is killed.
175  *
176  * @since 2.0
177  *
178  * @param[in]   condition  The condition that is expected to be true
179  * @hideinitializer
180  */
181 #define AppAssert(condition)
182
183 /**
184  * This macro is used to check logical errors in a program.
185  * If the assertion fails, a message is printed on the console and the current process is killed.
186  *
187  * @since 2.0
188  *
189  * @param[in]   condition               The condition that is expected to be true
190  * @param[in]   ...                             The message to print, if the assertion fails
191  *
192  * @image html debugging_appassert.png
193  *
194  * The following example demonstrates how to use the Assert macro.
195  *
196  * @code
197  *      result
198  *      MyClass::DoSomething(void)
199  *      {
200  *         result r = E_SUCCESS;
201  *         r = mutex.Acquire();
202  *         // Do something
203  *         r = mutex.Release();
204  *
205  *         // If false, console prints "Mutex Release Failed."
206  *         // and the process is killed.
207  *         AppAssertf(r == E_SUCCESS, "Mutex Release Failed.");
208  *
209  *         return r;
210  *      }
211  * @endcode
212  * @hideinitializer
213  */
214 #define AppAssertf(condition, ...)
215
216 /**
217  * This macro is added in a program to display a message when an expression is @c true.
218  *
219  * @since 2.0
220  *
221  * @param[in]   expression              The expression to evaluate
222  * @param[in]   ...                             The message to display
223  *
224  * The following example demonstrates how to use the AppLogIf macro.
225  *
226  * @code
227  *      bool
228  *      MyEngine::Init(int value)
229  *      {
230  *         AppLogIf(value !=0, "Invoked with value: %d", value);
231  *         //...
232  *
233  *         return true;
234  *      }
235  * @endcode
236  * @hideinitializer
237  */
238 #define AppLogIf(expression, ...)
239
240 /**
241  * This macro is added in a program to display a debug message when an expression is @c true.
242  *
243  * @since 2.0
244  *
245  * @param[in]   expression              The expression to evaluate
246  * @param[in]   ...                             The message to display
247  *
248  * The following example demonstrates how to use the AppLogDebugIf macro.
249  *
250  * @code
251  *      bool
252  *      MyEngine::Init(int value)
253  *      {
254  *         AppLogDebugIf(value !=0, "Invoked with value: %d", value);
255  *         //...
256  *
257  *         return true;
258  *      }
259  * @endcode
260  * @hideinitializer
261  */
262 #define AppLogDebugIf(expression, ...)
263
264 /**
265  * This macro is added in a program to display an exception message when an expression is @c true.
266  *
267  * @since 2.0
268  *
269  * @param[in]   expression              The expression to evaluate
270  * @param[in]   ...                             The message to display
271  *
272  * The following example demonstrates how to use the AppLogExceptionIf macro.
273  *
274  * @code
275  *      bool
276  *      MyEngine::Init(int value)
277  *      {
278  *         int status;
279  *
280  *         AppLogExceptionIf(status != 0, "status : %d.", status);
281  *         //...
282  *
283  *         return true;
284  *      }
285  * @endcode
286  * @hideinitializer
287  */
288 #define AppLogExceptionIf(expression, ...)
289
290 /**
291  * This macro is added in a program to display an info message with a tag.
292  *
293  * @since 2.0
294  *
295  * @param[in]   tag                     Used to identify the source of a log message
296  * @param[in]   ...                     The message to display
297  *
298  * The following example demonstrates how to use the AppLogTag macro.
299  *
300  * @code
301  *      bool
302  *      MyEngine::Init(int value)
303  *      {
304  *         int status;
305  *
306  *         AppLogTag("MyTag", "Initialization successful.");
307  *         //...
308  *
309  *         return true;
310  *      }
311  * @endcode
312  * @hideinitializer
313  */
314 #define AppLogTag(tag, ...)
315
316 /**
317  * This macro is added in a program to display a debug message with a tag.
318  *
319  * @since 2.0
320  *
321  * @param[in]   tag                     Used to identify the source of a log message
322  * @param[in]   ...                     The message to display
323  *
324  * The following example demonstrates how to use the AppLogDebugTag macro.
325  *
326   * @code
327  *      bool
328  *      MyEngine::Init(int value)
329  *      {
330  *         AppLogDebugTag("MyTag", "Invoked with value: %d", value);
331  *
332  *         //...
333  *
334  *         AppLogDebugTag("MyTag", "Exit.");
335  *
336  *         return true;
337  *      }
338  * @endcode
339  * @hideinitializer
340  */
341 #define AppLogDebugTag(tag, ...)
342
343 /**
344  * This macro is added in a program to display an exception message with a tag.
345  *
346  * @since 2.0
347  *
348  * @param[in]   tag                     Used to identify the source of a log message
349  * @param[in]   ...                     The message to display
350  *
351  * The following example demonstrates how to use the AppLogExceptionTag macro.
352  *
353  * @code
354  *      bool
355  *      MyEngine::Init(int value)
356  *      {
357  *         AppLogDebug("Invoked with value: %d", value);
358  *         //...
359  *         if (something_wrong)   // The Try family macros can be used instead.
360  *         {
361  *            AppLogExceptionTag("MyTag", "An unexpected error occurred.");
362  *
363  *            return false;
364  *         }
365  *
366  *         AppLog("Initialization successful.");
367  *         AppLogDebug("Exit.");
368  *
369  *         return true;
370  *      }
371  * @endcode
372  * @hideinitializer
373  */
374 #define AppLogExceptionTag(tag, ...)
375 /** @} */
376 #endif // defined(_APP_LOG)
377
378 // Try Macros
379 /**
380  * @addtogroup  GroupMacros
381  *
382  * @{
383  */
384 /**
385  * If the condition is @c false, it prints a message, evaluates a cleanup expression,
386  * and goes to <tt>CATCH</tt>.
387  *
388  * @since 2.0
389  *
390  * @param[in]   condition               The condition that is expected to be true
391  * @param[in]   expr                    Expressions that are evaluated before going to the CATCH label
392  * @param[in]   ...                             The message to display
393  *
394  * The following example demonstrates how to use the Try macro.
395  *
396  * @code
397  *      const  A*
398  *      MyClass::DoSomething(const wchar_t* pValue)
399  *      {
400  *         result r = E_SUCCESS;
401  *
402  *         // Do something...
403  *
404  *         // If pValue is null, print "pValue == null" to the
405  *         // console and return E_INVALID_ARG.
406  *         TryCatch(pValue != null, r = E_INVALID_ARG, "pValue == null");
407  *
408  *         SetLastResult(E_SUCCESS);
409  *
410  *         return _pValue;
411  *
412  *         CATCH:
413  *            SetLastResult(r);
414  *
415  *            return null;
416  *      }
417  * @endcode
418  * @hideinitializer
419  */
420 #define TryCatch(condition, expr, ...) \
421         if (!(condition)) {     \
422                 AppLogException(__VA_ARGS__); \
423                 expr; \
424                 goto CATCH;     \
425         } \
426         else {;}
427
428 /**
429  * If the condition is @c false, it prints a message, sets the last result, evaluates a cleanup expression
430  * and goes to <tt>CATCH</tt>.
431  *
432  * @since 2.0
433  *
434  * @param[in]   condition               The condition that is expected to be true
435  * @param[in]   expr                    Expressions that are evaluated before going to the CATCH label
436  * @param[in]   r                               The last result to set
437  * @param[in]   ...                             The message to display
438  * @hideinitializer
439  */
440 #define TryCatchResult(condition, expr, r, ...) \
441         if (!(condition)) { \
442                 SetLastResult(r); \
443                 AppLogException(__VA_ARGS__); \
444                 expr; \
445                 goto CATCH;     \
446         } \
447         else {;}
448
449 /**
450 * If the condition is @c false, it prints a message, sets the last result, evaluates a cleanup expression
451 * and goes to the catch label.
452 *
453 * @since 2.1
454 *
455 * @param[in]    condition               The condition that is expected to be true
456 * @param[in]    expr                    Expressions that are evaluated before going to the CATCH label
457 * @param[in]    catchLabel              The label for the goto operation
458 * @param[in]    r                               The last result to set
459 * @param[in]    ...                             The message to display
460 * @hideinitializer
461 */
462 #define TryCatchLabelResult(condition, expr, catchLabel, r, ...) \
463         if (!(condition)) { \
464                 SetLastResult(r); \
465                 AppLogException(__VA_ARGS__); \
466                 expr; \
467                 goto catchLabel;        \
468         } \
469         else {;}
470
471 /**
472  * If the condition is @c false, a message is printed and a value is returned.
473  *
474  * @since 2.0
475  *
476  * @param[in]   condition               The condition that is expected to be true
477  * @param[in]   returnValue             The value to return when the condition is @c false
478  * @param[in]   ...                             The message to display
479  * @hideinitializer
480  */
481 #define TryReturn(condition, returnValue, ...)  \
482         if (!(condition)) { \
483                 AppLogException(__VA_ARGS__); \
484                 return returnValue;     \
485         } \
486         else {;}
487
488 /**
489  * If the condition is @c false, a message is printed, the last result is set and a value is returned.
490  *
491  * @since 2.0
492  *
493  * @param[in]   condition               The condition that is expected to be true
494  * @param[in]   returnValue             The value to return when the condition is @c false
495  * @param[in]   r                               The last result to set
496  * @param[in]   ...                             The message to display
497  * @hideinitializer
498  */
499 #define TryReturnResult(condition, returnValue, r, ...) \
500         if (!(condition)) { \
501                 SetLastResult(r); \
502                 AppLogException(__VA_ARGS__); \
503                 return returnValue;     \
504         } \
505         else {;}
506
507 /**
508  * If the condition is @c false, a message is printed, the last result is set and no value is returned.
509  *
510  * @since 2.0
511  *
512  * @param[in]   condition       The condition that is expected to be true
513  * @param[in]   r                       The last result to set
514  * @param[in]   ...                     The message to display
515  * @hideinitializer
516  */
517 #define TryReturnVoidResult(condition, r, ...)  \
518         if (!(condition)) { \
519                 SetLastResult(r); \
520                 AppLogException(__VA_ARGS__); \
521                 return; \
522         } \
523         else {;}
524
525 /**
526  * If the condition is @c false, a message is printed and no value is returned.
527  *
528  * @since 2.0
529  *
530  * @param[in]   condition               The condition that is expected to be true
531  * @param[in]   ...                             The message to display
532  * @hideinitializer
533  */
534 #define TryReturnVoid(condition, ...) \
535         if (!(condition)) { \
536                 AppLogException(__VA_ARGS__); \
537                 return; \
538         } \
539         else {;}
540
541 /**
542  * If the condition is @c false, a message is printed.
543  *
544  * @since 2.0
545  *
546  * @param[in]   condition               The condition that is expected to be true
547  * @param[in]   ...                             The message to display
548  * @hideinitializer
549  */
550 #define TryLog(condition, ...)  \
551         if (!(condition)) { \
552                 AppLog(__VA_ARGS__); \
553         } \
554         else {;}
555
556 /**
557 * If the condition is @c false, an informative log message is printed and a value is returned.
558 *
559 * @since 2.1
560 *
561 * @param[in]    condition               The condition that is expected to be true
562 * @param[in]    returnValue             The value to return when the condition is @c false
563 * @param[in]    ...                             The message to display
564 * @hideinitializer
565 */
566 #define TryLogReturn(condition, returnValue, ...) \
567         if (!(condition)) { \
568                 AppLog(__VA_ARGS__); \
569                 return returnValue;     \
570         } \
571         else {;}
572
573 // TryTag Macros
574
575 /**
576  * If the condition is @c false, it prints a message with a tag, evaluates a cleanup expression
577  * and goes to <tt>CATCH</tt>.
578  *
579  * @since 2.0
580  *
581  * @param[in]   tag                             Used to identify the source of the log message
582  * @param[in]   condition               The condition that is expected to be true
583  * @param[in]   expr                    Expressions that are evaluated before going to the CATCH label
584  * @param[in]   ...                             The message to display
585  * @hideinitializer
586  */
587 #define TryCatchTag(tag, condition, expr, ...) \
588         if (!(condition)) { \
589                 AppLogExceptionTag(tag, __VA_ARGS__); \
590                 expr; \
591                 goto CATCH;     \
592         } \
593         else {;}
594
595 /**
596  * If the condition is @c false, it prints a message with a tag, sets the last result, evaluates a cleanup expression,
597  * and goes to <tt>CATCH</tt>.
598  *
599  * @since 2.0
600  *
601  * @param[in]   tag                             Used to identify the source of the log message
602  * @param[in]   condition               The condition that is expected to be true
603  * @param[in]   expr                    Expressions that are evaluated before going to the CATCH label
604  * @param[in]   r                               The last result to set
605  * @param[in]   ...                             The message to display
606  * @hideinitializer
607  */
608 #define TryCatchResultTag(tag, condition, expr, r, ...) \
609         if (!(condition)) { \
610                 SetLastResult(r); \
611                 AppLogExceptionTag(tag, __VA_ARGS__); \
612                 expr; \
613                 goto CATCH;     \
614         } \
615         else {;}
616
617 /**
618 * If the condition is @c false, it prints a message with a tag, sets the last result, evaluates a cleanup expression
619 * and goes to the catch label.
620 *
621 * @since 2.1
622 *
623 * @param[in]    tag                             Used to identify the source of the log message
624 * @param[in]    condition               The condition that is expected to be true
625 * @param[in]    expr                    Expressions that are evaluated before going to the CATCH label
626 * @param[in]    catchLabel              The label for the goto operation
627 * @param[in]    r                               The last result to set
628 * @param[in]    ...                             The message to display
629 * @hideinitializer
630 */
631 #define TryCatchLabelResultTag(tag, condition, expr, catchLabel, r, ...) \
632         if (!(condition)) { \
633                 SetLastResult(r); \
634                 AppLogExceptionTag(tag, __VA_ARGS__); \
635                 expr; \
636                 goto catchLabel;        \
637         } \
638         else {;}
639
640 /**
641  * If the condition is @c false, a message is printed with a tag and a value is returned.
642  *
643  * @since 2.0
644  *
645  * @param[in]   tag                             Used to identify the source of the log message
646  * @param[in]   condition               The condition that is expected to be true
647  * @param[in]   returnValue             The value to return when the condition is @c false
648  * @param[in]   ...                             The message to display
649  * @hideinitializer
650  */
651 #define TryReturnTag(tag, condition, returnValue, ...)  \
652         if (!(condition)) { \
653                 AppLogExceptionTag(tag, __VA_ARGS__); \
654                 return returnValue;     \
655         } \
656         else {;}
657
658 /**
659  * If the condition is @c false, it prints a message with a tag, sets the last result and returns a value.
660  *
661  * @since 2.0
662  *
663  * @param[in]   tag                             Used to identify the source of the log message
664  * @param[in]   condition               The condition that is expected to be true
665  * @param[in]   returnValue             The value to return when the condition is @c false
666  * @param[in]   r                               The last result to set
667  * @param[in]   ...                             The message to display
668  * @hideinitializer
669  */
670 #define TryReturnResultTag(tag, condition, returnValue, r, ...) \
671         if (!(condition)) { \
672                 SetLastResult(r); \
673                 AppLogExceptionTag(tag, __VA_ARGS__); \
674                 return returnValue;     \
675         } \
676         else {;}
677
678 /**
679  * If the condition is @c false, it prints a message with a tag, sets the last result and does not return any value.
680  *
681  * @since 2.0
682  *
683  * @param[in]   tag                             Used to identify the source of the log message
684  * @param[in]   condition               The condition that is expected to be true
685  * @param[in]   r                               The last result to set
686  * @param[in]   ...                             The message to display
687  * @hideinitializer
688  */
689 #define TryReturnVoidResultTag(tag, condition, r, ...)  \
690         if (!(condition)) { \
691                 SetLastResult(r); \
692                 AppLogExceptionTag(tag, __VA_ARGS__); \
693                 return; \
694         } \
695         else {;}
696
697 /**
698  * If the condition is @c false, a message is printed with a tag and no value is returned.
699  *
700  * @since 2.0
701  *
702  * @param[in]   tag                             Used to identify the source of the log message
703  * @param[in]   condition               The condition that is expected to be true
704  * @param[in]   ...                             The message to display
705  * @hideinitializer
706  */
707 #define TryReturnVoidTag(tag, condition, ...) \
708         if (!(condition)) { \
709                 AppLogExceptionTag(tag, __VA_ARGS__); \
710                 return; \
711         } \
712         else {;}
713
714 /**
715  * If the condition is @c false, a message is printed with a tag.
716  *
717  * @since 2.0
718  *
719  * @param[in]   tag                     Used to identify the source of the log message
720  * @param[in]   condition       The condition that is expected to be true
721  * @param[in]   ...                     The message to display
722  * @hideinitializer
723  */
724 #define TryLogTag(tag, condition, ...)  \
725         if (!(condition)) { \
726                 AppLogTag(tag, __VA_ARGS__); \
727         } \
728         else {;}
729
730 /**
731 * If the condition is @c false, an informative log message is printed with a tag and a value is returned.
732 *
733 * @since 2.1
734 *
735 * @param[in]    tag                             Used to identify the source of the log message
736 * @param[in]    condition               The condition that is expected to be true
737 * @param[in]    returnValue             The value to return when the condition is @c false
738 * @param[in]    ...                             The message to display
739 * @hideinitializer
740 */
741 #define TryLogReturnTag(tag, condition, returnValue, ...) \
742         if (!(condition)) { \
743                 AppLogTag(tag, __VA_ARGS__); \
744                 return returnValue;     \
745         } \
746         else {;}
747
748 /** @} */
749
750
751 // Secure Macros
752 /**
753  * @addtogroup  GroupMacros
754  *
755  * @{
756  */
757
758 #if (defined(_APP_LOG) || defined(_OSP_DEBUG_) || defined(_DEBUG)) && defined(_SECURE_LOG)
759
760 #define AppSecureLog(...)                               AppLogInternal(__PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
761 #define AppSecureLogDebug(...)                  AppLogDebugInternal(__PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
762 #define AppSecureLogException(...)              AppLogExceptionInternal(__PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
763
764 #define AppSecureLogTag(tag, ...)                       AppLogTagInternal(tag, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
765 #define AppSecureLogDebugTag(tag, ...)          AppLogDebugTagInternal(tag, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
766 #define AppSecureLogExceptionTag(tag, ...)      AppLogExceptionTagInternal(tag, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
767
768 #else
769 /**
770  * This macro is used to protect informative log messages which need security.
771  * It allows the display of informative log messages if compiled with the "_SECURE_LOG" definition.
772  * Otherwise, it is removed in the compile time.
773  *
774  * @since 2.1
775  *
776  * @param[in]   ...                     The message to display
777  *
778  * The following example demonstrates how to use the AppSecureLog macro.
779  *
780  * @code
781  *        bool
782  *        MyEngine::Init(int value)
783  *        {
784  *           AppSecureLog("User ID : 'JoneDoe'");
785  *
786  *           return true;
787  *        }
788  * @endcode
789  * @hideinitializer
790  */
791 #define AppSecureLog(...)
792
793 /**
794  * This macro is used to protect debug log messages which need security.
795  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
796  * Otherwise, it is removed in the compile time.
797  *
798  * @since 2.1
799  *
800  * @param[in]   ...                     The message to display
801  *
802  * The following example demonstrates how to use the AppSecureLogDebug macro.
803  *
804  * @code
805  *        bool
806  *        MyEngine::Init(int value)
807  *        {
808  *           //...
809  *           if (something_wrong)
810  *           {
811  *              AppSecureLogDebug("User ID : 'JoneDoe' mismatch.");
812  *
813  *              return false;
814  *           }
815  *   //...
816  *
817  *           return true;
818  *        }
819  * @endcode
820  * @hideinitializer
821  */
822 #define AppSecureLogDebug(...)
823
824 /**
825  * This macro is used to protect exception log messages which need security.
826  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
827  * Otherwise, it is removed in the compile time.
828  *
829  * @since 2.1
830  *
831  * @param[in]   ...                     The message to display
832  *
833  * The following example demonstrates how to use the AppSecureLogException macro.
834  *
835  * @code
836  *        bool
837  *        MyEngine::Init(int value)
838  *        {
839  *           //...
840  *           if (something_wrong)
841  *           {
842  *              AppSecureLogException("User ID : 'JoneDoe' mismatch.");
843  *
844  *              return false;
845  *           }
846  *   //...
847  *
848  *           return true;
849  *        }
850  * @endcode
851  * @hideinitializer
852  */
853 #define AppSecureLogException(...)
854
855 /**
856  * This macro is used to protect informative log messages which need security, with a tag.
857  * It allows the display of informative log messages if compiled with the "_SECURE_LOG" definition.
858  * Otherwise, it is removed in the compile time.
859  *
860  * @since 2.1
861  *
862  * @param[in]   tag                     The user defined tag
863  * @param[in]   ...                     The message to display
864  *
865  * The following example demonstrates how to use the AppSecureLogTag macro.
866  *
867  * @code
868  *        bool
869  *        MyEngine::Init(int value)
870  *        {
871  *           AppSecureLogTag("MyTag", "User ID : 'JoneDoe'");
872  *
873  *           return true;
874  *        }
875  * @endcode
876  * @hideinitializer
877  */
878 #define AppSecureLogTag(tag, ...)
879
880 /**
881  * This macro is used to protect debug log messages which need security, with a tag.
882  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
883  * Otherwise, it is removed in the compile time.
884  *
885  * @since 2.1
886  *
887  * @param[in]   tag                     The user defined tag
888  * @param[in]   ...                     The message to display
889  *
890  * The following example demonstrates how to use the AppSecureLogDebugTag macro.
891  *
892  * @code
893  *        bool
894  *        MyEngine::Init(int value)
895  *        {
896  *           AppSecureLogDebugTag("MyTag", "User ID : 'JoneDoe' mismatch.");
897  *
898  *           return true;
899  *        }
900  * @endcode
901  * @hideinitializer
902  */
903 #define AppSecureLogDebugTag(tag, ...)
904
905 /**
906  * This macro is used to protect exception log messages which need security, with a tag.
907  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
908  * Otherwise, it is removed in the compile time.
909  *
910  * @since 2.1
911  *
912  * @param[in]   tag                     The user defined tag
913  * @param[in]   ...                     The message to display
914  *
915  * The following example demonstrates how to use the AppSecureLogExceptionTag macro.
916  *
917  * @code
918  *        bool
919  *        MyEngine::Init(int value)
920  *        {
921  *           AppSecureLogExceptionTag("MyTag", "User ID : 'JoneDoe' mismatch.");
922  *
923  *           return true;
924  *        }
925  * @endcode
926  * @hideinitializer
927  */
928 #define AppSecureLogExceptionTag(tag, ...)
929
930 #endif
931
932 /**
933  * If the condition is @c false, it prints a message, evaluates a cleanup expression,
934  * and goes to <tt>CATCH</tt>.
935  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
936  * Otherwise, the log printing functionality is removed in the compile time.
937  *
938  * @since 2.1
939  *
940  * @param[in]   condition               The condition that is expected to be true
941  * @param[in]   expr                    Expressions that are evaluated before going to the CATCH label
942  * @param[in]   ...                             The message to display
943  *
944  * The following example demonstrates how to use the SecureTry macro.
945  *
946  * @code
947  *      result
948  *      MyClass::DoSomething(const String* passwd)
949  *      {
950  *         result r = E_SUCCESS;
951  *
952  *         // Do something...
953  *
954  *         // If password is wrong, print "[E_INVALID_ARG] The password '1234' is wrong." to the console
955  *         // execute the expression "r = E_INVALID_ARG", and move to CATCH
956  *         SecureTryCatch(*passwd != refPasswd, r = E_INVALID_ARG, "[E_INVALID_ARG] The password '%ls' is wrong.", passwd->GetPointer());
957  *
958  *         SetLastResult(E_SUCCESS);
959  *
960  *         return E_SUCCESS;// execute the expression "r = E_INVALID_ARG", and move to CATCH
961  *
962  *         CATCH:
963  *            SetLastResult(r);
964  *            // Do something
965  *
966  *            return r;
967  *      }
968  * @endcode
969  * @hideinitializer
970  */
971 #define SecureTryCatch(condition, expr, ...) \
972         if (!(condition)) { \
973                 AppSecureLogException(__VA_ARGS__); \
974                 expr; \
975                 goto CATCH;     \
976         } \
977         else {;}
978
979 /**
980  * If the condition is @c false, it prints a message, sets the last result, evaluates a cleanup expression
981  * and goes to <tt>CATCH</tt>.
982  * It allows the display of exception log messages if compiled with "_SECURE_LOG" definition.
983  * Otherwise, the log printing functionality is removed in the compile time.
984  *
985  * @since 2.1
986  *
987  * @param[in]   condition               The condition that is expected to be true
988  * @param[in]   expr                    Expressions that are evaluated before going to the CATCH label
989  * @param[in]   r                               The last result to set
990  * @param[in]   ...                             The message to display
991  * @hideinitializer
992  */
993 #define SecureTryCatchResult(condition, expr, r, ...) \
994         if (!(condition)) { \
995                 SetLastResult(r); \
996                 AppSecureLogException(__VA_ARGS__); \
997                 expr; \
998                 goto CATCH;     \
999         } \
1000         else {;}
1001
1002 /**
1003  * If the condition is @c false, it prints a message, sets the last result, evaluates a cleanup expression
1004  * and goes to the catch label.
1005  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1006  * Otherwise, the log printing functionality is removed in the compile time.
1007  *
1008  * @since 2.1
1009  *
1010  * @param[in]    condition              The condition that is expected to be true
1011  * @param[in]    expr                   Expressions that are evaluated before going to the CATCH label
1012  * @param[in]    catchLabel             The label for the goto operation
1013  * @param[in]    r                              The last result to set
1014  * @param[in]    ...                    The message to display
1015  * @hideinitializer
1016  */
1017 #define SecureTryCatchLabelResult(condition, expr, catchLabel, r, ...) \
1018         if (!(condition)) { \
1019                 SetLastResult(r); \
1020                 AppSecureLogException(__VA_ARGS__); \
1021                 expr; \
1022                 goto catchLabel;        \
1023         } \
1024         else {;}
1025
1026 /**
1027  * If the condition is @c false, a message is printed and a value is returned.
1028  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1029  * Otherwise, the log printing functionality is removed in the compile time.
1030  *
1031  * @since 2.1
1032  *
1033  * @param[in]   condition               The condition that is expected to be true
1034  * @param[in]   returnValue             The value to return when the condition is @c false
1035  * @param[in]   ...                             The message to display
1036  * @hideinitializer
1037  */
1038 #define SecureTryReturn(condition, returnValue, ...)    \
1039         if (!(condition)) { \
1040                 AppSecureLogException(__VA_ARGS__); \
1041                 return returnValue;     \
1042         } \
1043         else {;}
1044
1045 /**
1046  * If the condition is @c false, it prints a message, sets the last result and returns a value.
1047  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1048  * Otherwise, the log printing functionality is removed in the compile time.
1049  *
1050  * @since 2.1
1051  *
1052  * @param[in]   condition               The condition that is expected to be true
1053  * @param[in]   returnValue             The value to return when the condition is @c false
1054  * @param[in]   r                               The last result to set
1055  * @param[in]   ...                             The message to display
1056  * @hideinitializer
1057  */
1058 #define SecureTryReturnResult(condition, returnValue, r, ...)   \
1059         if (!(condition)) { \
1060                 SetLastResult(r); \
1061                 AppSecureLogException(__VA_ARGS__); \
1062                 return returnValue;     \
1063         } \
1064         else {;}
1065
1066 /**
1067  * If the condition is @c false, a message is printed, the last result is set and no value is returned.
1068  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1069  * Otherwise, the log printing functionality is removed in the compile time.
1070  *
1071  * @since 2.1
1072  *
1073  * @param[in]   condition               The condition that is expected to be true
1074  * @param[in]   r                               The last result to set
1075  * @param[in]   ...                             The message to display
1076  * @hideinitializer
1077  */
1078 #define SecureTryReturnVoidResult(condition, r, ...)    \
1079         if (!(condition)) { \
1080                 SetLastResult(r); \
1081                 AppSecureLogException(__VA_ARGS__); \
1082                 return; \
1083         } \
1084         else {;}
1085
1086 /**
1087  * If the condition is @c false, a message is printed and no value is returned.
1088  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1089  * Otherwise, the log printing functionality is removed in the compile time.
1090  *
1091  * @since 2.1
1092  *
1093  * @param[in]   condition               The condition that is expected to be true
1094  * @param[in]   ...                             The message to display
1095  * @hideinitializer
1096  */
1097 #define SecureTryReturnVoid(condition, ...) \
1098         if (!(condition)) { \
1099                 AppSecureLogException(__VA_ARGS__); \
1100                 return; \
1101         } \
1102         else {;}
1103
1104 /**
1105  * If the condition is @c false, a message is printed.
1106  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1107  * Otherwise, the log printing functionality is removed in the compile time.
1108  *
1109  * @since 2.1
1110  *
1111  * @param[in]   condition               The condition that is expected to be true
1112  * @param[in]   ...                             The message to display
1113  * @hideinitializer
1114  */
1115 #define SecureTryLog(condition, ...)    \
1116         if (!(condition)) { \
1117                 AppSecureLog(__VA_ARGS__); \
1118         } \
1119         else {;}
1120
1121 /**
1122  * If the condition is @c false, an informative log message is printed and a value is returned.
1123  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1124  * Otherwise, the log printing functionality is removed in the compile time.
1125  *
1126  * @since 2.1
1127  *
1128  * @param[in]    condition                      The condition that is expected to be true
1129  * @param[in]    returnValue            The value to return when the condition is @c false
1130  * @param[in]    ...                            The message to display
1131  * @hideinitializer
1132  */
1133 #define SecureTryLogReturn(condition, returnValue, ...) \
1134         if (!(condition)) { \
1135                 AppSecureLog(__VA_ARGS__); \
1136                 return returnValue;     \
1137         } \
1138         else {;}
1139
1140 // SecureTryTag Macros
1141
1142 /**
1143  * If the condition is @c false, it prints a message with a tag, evaluates a cleanup expression
1144  * and goes to <tt>CATCH</tt>.
1145  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1146  * Otherwise, the log printing functionality is removed in the compile time.
1147  *
1148  * @since 2.1
1149  *
1150  * @param[in]   tag                             Used to identify the source of the log message
1151  * @param[in]   condition               The condition that is expected to be true
1152  * @param[in]   expr                    Expressions that are evaluated before going to the CATCH label
1153  * @param[in]   ...                             The message to display
1154  * @hideinitializer
1155  */
1156 #define SecureTryCatchTag(tag, condition, expr, ...) \
1157         if (!(condition)) { \
1158                 AppSecureLogExceptionTag(tag, __VA_ARGS__); \
1159                 expr; \
1160                 goto CATCH;     \
1161         } \
1162         else {;}
1163
1164 /**
1165  * If the condition is @c false, it prints a message with a tag, sets the last result, evaluates a cleanup expression,
1166  * and goes to <tt>CATCH</tt>.
1167  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1168  * Otherwise, the log printing functionality is removed in the compile time.
1169  *
1170  * @since 2.1
1171  *
1172  * @param[in]   tag                             Used to identify the source of the log message
1173  * @param[in]   condition               The condition that is expected to be true
1174  * @param[in]   expr                    Expressions that are evaluated before going to the CATCH label
1175  * @param[in]   r                               The last result to set
1176  * @param[in]   ...                             The message to display
1177  * @hideinitializer
1178  */
1179 #define SecureTryCatchResultTag(tag, condition, expr, r, ...) \
1180         if (!(condition)) { \
1181                 SetLastResult(r); \
1182                 AppSecureLogExceptionTag(tag, __VA_ARGS__); \
1183                 expr; \
1184                 goto CATCH;     \
1185         } \
1186         else {;}
1187
1188 /**
1189  * If the condition is @c false, it prints a message with a tag, sets the last result, evaluates a cleanup expression
1190  * and goes to the catch label.
1191  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1192  * Otherwise, the log printing functionality is removed in the compile time.
1193  *
1194  * @since 2.1
1195  *
1196  * @param[in]    tag                    Used to identify the source of the log message
1197  * @param[in]    condition              The condition that is expected to be true
1198  * @param[in]    expr                   Expressions that are evaluated before going to the CATCH label
1199  * @param[in]    catchLabel             The label for the goto operation
1200  * @param[in]    r                              The last result to set
1201  * @param[in]    ...                    The message to display
1202  * @hideinitializer
1203  */
1204 #define SecureTryCatchLabelResultTag(tag, condition, expr, catchLabel, r, ...) \
1205         if (!(condition)) { \
1206                 SetLastResult(r); \
1207                 AppSecureLogExceptionTag(tag, __VA_ARGS__); \
1208                 expr; \
1209                 goto catchLabel;        \
1210         } \
1211         else {;}
1212
1213 /**
1214  * If the condition is @c false, a message is printed with a tag and a value is returned.
1215  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1216  * Otherwise, the log printing functionality is removed in the compile time.
1217  *
1218  * @since 2.1
1219  *
1220  * @param[in]   tag                             Used to identify the source of the log message
1221  * @param[in]   condition               The condition that is expected to be true
1222  * @param[in]   returnValue             The value to return when the condition is @c false
1223  * @param[in]   ...                             The message to display
1224  * @hideinitializer
1225  */
1226 #define SecureTryReturnTag(tag, condition, returnValue, ...)    \
1227         if (!(condition)) { \
1228                 AppSecureLogExceptionTag(tag, __VA_ARGS__); \
1229                 return returnValue;     \
1230         } \
1231         else {;}
1232
1233 /**
1234  * If the condition is @c false, a message is printed with a tag, the last result is set and a value is returned.
1235  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1236  * Otherwise, the log printing functionality is removed in the compile time.
1237  *
1238  * @since 2.1
1239  *
1240  * @param[in]   tag                             Used to identify the source of the log message
1241  * @param[in]   condition               The condition that is expected to be true
1242  * @param[in]   returnValue             The value to return when the condition is @c false
1243  * @param[in]   r                               The last result to set
1244  * @param[in]   ...                             The message to display
1245  * @hideinitializer
1246  */
1247 #define SecureTryReturnResultTag(tag, condition, returnValue, r, ...)   \
1248         if (!(condition)) { \
1249                 SetLastResult(r); \
1250                 AppSecureLogExceptionTag(tag, __VA_ARGS__); \
1251                 return returnValue;     \
1252         } \
1253         else {;}
1254
1255 /**
1256  * If the condition is @c false, a message is printed with a tag, the last result is set and no value is returned.
1257  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1258  * Otherwise, the log printing functionality is removed in the compile time.
1259  *
1260  * @since 2.1
1261  *
1262  * @param[in]   tag                     Used to identify the source of the log message
1263  * @param[in]   condition       The condition that is expected to be true
1264  * @param[in]   r                       The last result to set
1265  * @param[in]   ...                     The message to display
1266  * @hideinitializer
1267  */
1268 #define SecureTryReturnVoidResultTag(tag, condition, r, ...)    \
1269         if (!(condition)) { \
1270                 SetLastResult(r); \
1271                 AppSecureLogExceptionTag(tag, __VA_ARGS__); \
1272                 return; \
1273         } \
1274         else {;}
1275
1276 /**
1277  * If the condition is @c false, a message is printed with a tag and no value is returned.
1278  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1279  * Otherwise, the log printing functionality is removed in the compile time.
1280  *
1281  * @since 2.1
1282  *
1283  * @param[in]   tag                             Used to identify the source of the log message
1284  * @param[in]   condition               The condition that is expected to be true
1285  * @param[in]   ...                             The message to display
1286  * @hideinitializer
1287  */
1288 #define SecureTryReturnVoidTag(tag, condition, ...) \
1289         if (!(condition)) { \
1290                 AppSecureLogExceptionTag(tag, __VA_ARGS__); \
1291                 return; \
1292         } \
1293         else {;}
1294
1295 /**
1296  * If the condition is @c false, a message is printed with a tag.
1297  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1298  * Otherwise, the log printing functionality is removed in the compile time.
1299  *
1300  * @since 2.1
1301  *
1302  * @param[in]   tag                             Used to identify the source of the log message
1303  * @param[in]   condition               The condition that is expected to be true
1304  * @param[in]   ...                             The message to display
1305  * @hideinitializer
1306  */
1307 #define SecureTryLogTag(tag, condition, ...)    \
1308         if (!(condition)) {     \
1309                 AppSecureLogTag(tag, __VA_ARGS__); \
1310         } \
1311         else {;}
1312
1313 /**
1314  * If the condition is @c false, an informative log message is printed with a tag and a value is returned.
1315  * It allows the display of exception log messages if compiled with the "_SECURE_LOG" definition.
1316  * Otherwise, the log printing functionality is removed in the compile time.
1317  *
1318  * @since 2.1
1319  *
1320  * @param[in]    tag                            Used to identify the source of the log message
1321  * @param[in]    condition                      The condition that is expected to be true
1322  * @param[in]    returnValue            The value to return when the condition is @c false
1323  * @param[in]    ...                            The message to display
1324  * @hideinitializer
1325  */
1326 #define SecureTryLogReturnTag(tag, condition, returnValue, ...) \
1327         if (!(condition)) { \
1328                 AppSecureLogTag(tag, __VA_ARGS__); \
1329                 return returnValue;     \
1330         } \
1331         else {;}
1332
1333 /** @} */
1334
1335 _OSP_EXPORT_ void AppLogInternal(const char* pFunction, int lineNumber, const char* pFormat, ...);
1336 _OSP_EXPORT_ void AppLogDebugInternal(const char* pFunction, int lineNumber, const char* pFormat, ...);
1337 _OSP_EXPORT_ void AppLogExceptionInternal(const char* pFunction, int lineNumber, const char* pFormat, ...);
1338 _OSP_EXPORT_ void AppassertInternal(const char* pFunction, int lineNumber);
1339 _OSP_EXPORT_ void AppassertfInternal(const char* expr, const char* pFunction, int lineNumber, const char* pFormat, ...);
1340
1341 _OSP_EXPORT_ void AppLogTagInternal(const char* pTag, const char* pFunction, int lineNumber, const char* pFormat, ...);
1342 _OSP_EXPORT_ void AppLogDebugTagInternal(const char* pTag, const char* pFunction, int lineNumber, const char* pFormat, ...);
1343 _OSP_EXPORT_ void AppLogExceptionTagInternal(const char* pTag, const char* pFunction, int lineNumber, const char* pFormat, ...);
1344
1345 #ifdef __cplusplus
1346 }
1347 #endif
1348
1349 #endif // _FBASE_LOG_H_