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