Merge "Revert "Change the way to conver Mbs to Wcs and vice versa"" into tizen_2.1
[platform/framework/native/appfw.git] / inc / FBaseSysLog.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                FBaseSysLog.h
20  * @brief               This is the header file for the %Log macros.
21  *
22  * This header file defines the %Log macros.
23  */
24
25 #ifndef _FBASE_SYS_LOG_H_
26 #define _FBASE_SYS_LOG_H_
27
28 #include <stdarg.h>
29 #include <FOspConfig.h>
30 #include <FBaseDataType.h>
31 #include <FIoRegistry.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif // __cplusplus
36
37 #ifndef likely
38 #define likely(x)    __builtin_expect(!!(x), 1)
39 #endif
40 #ifndef unlikely
41 #define unlikely(x)  __builtin_expect(!!(x), 0)
42 #endif
43
44 /** 
45  * @mainpage Tizen Platform API Reference
46  *
47  * The Tizen platform API Reference provides descriptions of APIs for the platform developers.
48  */
49
50 /**
51  * @defgroup GroupMacros Debugging Macros
52  *
53  * This page describes Tizen debugging macros used by the Tizen modules.
54  * These debugging macros should use specific NID ( Namespace ID ) to distinguish each Tizen modules.
55  *
56  * @since 2.0
57  */
58
59
60 /**
61  * @addtogroup  GroupMacros
62  *
63  * @{
64  */
65
66 /**
67  * This macro allows display of informative log messages.
68  * This system log macro is for the platform modules.
69  *
70  * @since 2.0
71  *
72  * @param[in]   NID                     The Tizen namespace
73  * @param[in]   ...                     The message to display
74  *
75  * The following example demonstrates how to use the SysLog macro.
76  *
77  * @code
78  *      bool
79  *      MyEngine::Init(int value)
80  *      {
81  *         SysLog(NID, "Initialization successful.");
82  *
83  *         return true; 
84  *      }
85  * @endcode
86  * @hideinitializer
87  */
88 #define SysLog(NID, ...)               SysLogInternal(NID, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
89
90 /**
91  * This macro allows display of exception log messages with a tag and sets the last result.
92  * This system log macro is for the platform modules.
93  *
94  * @since 2.0
95  *
96  * @param[in]   NID                     The Tizen namespace
97  * @param[in]   r                       The last result to set
98  * @param[in]   ...                     The message to display
99  *
100  * The following example demonstrates how to use the SysLogException macro.
101  *
102  * @code
103  *      bool
104  *      MyEngine::Init(int value)
105  *      {
106  *         //...
107  *         if (something_wrong)   // The Try family macros can be used instead.
108  *         {
109  *            SysLogException(NID,  E_INVALID_ARG, "An unexpected error has occurred.");
110  *
111  *            return false;
112  *         }
113  *   //...
114  *
115  *         return true;
116  *      }
117  * @endcode
118  * @hideinitializer
119  */
120 #define SysLogException(NID, r, ...)               SysLogExceptionInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
121
122 /**
123  * This macro allows display of informative log messages with a tag.
124  * This system log macro is for the platform modules.
125  *
126  * @since 2.0
127  *
128  * @param[in]   NID                     The Tizen namespace
129  * @param[in]   tag                     The user defined tag
130  * @param[in]   ...                     The message to display
131  *
132  * The following example demonstrates how to use the SysLogTag macro.
133  *
134  * @code
135  *      bool
136  *      MyEngine::Init(int value)
137  *      {
138  *         SysLogTag(NID, "MyTag", "Initialization successful.");
139  *
140  *         return true;
141  *      }
142  * @endcode
143  * @hideinitializer
144  */
145 #define SysLogTag(NID, tag, ...)       SysLogTagInternal(NID, tag, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
146
147 /**
148  * This macro allows display of exception log messages with a tag and sets the last result.
149  * This system log macro is for the platform modules.
150  *
151  * @since 2.0
152  *
153  * @param[in]   NID                     The Tizen namespace
154  * @param[in]   tag                     The user defined tag
155  * @param[in]   r                       The last result to set
156  * @param[in]   ...                     The message to display
157  *
158  * The following example demonstrates how to use the SysLogTagException macro.
159  *
160  * @code
161  *      bool
162  *      MyEngine::Init(int value)
163  *      {
164  *         SysLogExceptionTag(NID, "MyTag", E_INVALID_ARG, "Initialization successful.");
165  *
166  *         return true;
167  *      }
168  * @endcode
169  * @hideinitializer
170  */
171 #define SysLogExceptionTag(NID, tag, r, ...)       SysLogExceptionTagInternal(NID, tag, r, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
172
173
174
175 /**
176  * This macro allows display of informative log message with a tag, when the condition is @c false.
177  * This system log macro is for the platform modules.
178  *
179  * @since 2.0
180  *
181  * @param[in]   NID                     The Tizen namespace
182  * @param[in]   condition               The condition that is expected to be true
183  * @param[in]   ...                     The message to display
184  *
185  * The following example demonstrates how to use the SysTryLog macro.
186  *
187  * @code
188  *      void
189  *      MyEngine::Init(int value)
190  *      {
191  *         //...
192  *
193  *         SysTryLog(NID, condition, "An unexpected error has occurred.");
194  *
195  *         //...
196  *      }
197  * @endcode
198  * @hideinitializer
199  */
200 #define SysTryLog(NID, condition, ...) \
201         do \
202         { \
203                 if (unlikely(!(condition))) {   \
204                         SysLog(NID, __VA_ARGS__); \
205                 } \
206         } while (0);
207
208 /**
209  * This macro allows display of informative log message, when the condition is @c false.
210  * Executes statements and goes to label.
211  * This system log macro is for the platform modules.
212  *
213  * @since 2.0
214  *
215  * @param[in]   NID                     The Tizen namespace
216  * @param[in]   condition               The condition that is expected to be true
217  * @param[in]   expr                    Expressions that are evaluated before going to CATCH label
218  * @param[in]   ...                     The message to display
219  *
220  * The following example demonstrates how to use the SysTryLogCatch macro.
221  *
222  * @code
223  *      bool
224  *      MyEngine::Init(int value)
225  *      {
226  *         //...
227  *
228  *         SysTryLogCatch(NID, condition, r=E_INVALID_ARG, "An unexpected error has occurred.");
229  *
230  *         //...
231  *         CATCH:
232  *                      return false;
233  *      }
234  * @endcode
235  * @hideinitializer
236  */
237 #define SysTryLogCatch(NID, condition, expr, ...)       \
238         do \
239         { \
240                 if (unlikely(!(condition))) { \
241                         SysLog(NID, __VA_ARGS__); \
242                         expr; \
243                         goto CATCH;     \
244                 } \
245         } while (0);
246
247 /**
248  * This macro allows display of informative log message and returns returnValue, when the condition is @c false.
249  * This system log macro is for the platform modules.
250  *
251  * @since 2.0
252  *
253  * @param[in]   NID                     The Tizen namespace
254  * @param[in]   condition               The condition that is expected to be true
255  * @param[in]   returnValue             The value to return when the condition is @c false
256  * @param[in]   ...                     The message to display
257  *
258  * The following example demonstrates how to use the SysTryLogReturn macro.
259  *
260  * @code
261  *      bool
262  *      MyEngine::Init(int value)
263  *      {
264  *         //...
265  *
266  *         SysTryLogReturn(NID, condition, false, "An unexpected error has occurred.");
267  *
268  *         //...
269  *         return true;
270  *      }
271  * @endcode
272  * @hideinitializer
273  */
274 #define SysTryLogReturn(NID, condition, returnValue, ...) \
275         do \
276         { \
277                 if (unlikely(!(condition))) { \
278                         SysLog(NID, __VA_ARGS__); \
279                         return returnValue;     \
280                 } \
281         } while (0);
282
283
284 /**
285  * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
286  * This system log macro is for the platform modules.
287  *
288  * @since 2.0
289  *
290  * @param[in]   NID                     The Tizen namespace
291  * @param[in]   condition               The condition that is expected to be true
292  * @param[in]   returnValue             The value to return when the condition is @c false
293  * @param[in]   r                       The last result to set
294  * @param[in]   ...                     The message to display
295  *
296  * The following example demonstrates how to use the SysTryReturn macro.
297  *
298  * @code
299  *      bool
300  *      MyEngine::Init(int value)
301  *      {
302  *         //...
303  *
304  *         SysTryReturn(NID, condition, false,  E_INVALID_ARG, "An unexpected error has occurred.");
305  *
306  *         //...
307  *         return true;
308  *      }
309  * @endcode
310  * @hideinitializer
311  */
312 #define SysTryReturn(NID, condition, returnValue, r, ...) \
313         do \
314         { \
315                 if (unlikely(!(condition))) {   \
316                         SysLogException(NID, r, __VA_ARGS__); \
317                         return returnValue;     \
318                 } \
319         } while (0);
320
321 /**
322  * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
323  * This is a shorthand macro for SysTryReturn(NID, condition, r, r, "[" # r "] " ...).
324  * This system log macro is for the platform modules.
325  *
326  * @since 2.0
327  *
328  * @param[in]   NID                     The Tizen namespace
329  * @param[in]   condition               The condition that is expected to be true
330  * @param[in]   r                       The last result to set
331  * @param[in]   ...                     The message to display
332  *
333  * The following example demonstrates how to use the SysTryReturnResult macro.
334  *
335  * @code
336  * #define E_UNKNOWN_ERROR 1
337  *      result
338  *      MyEngine::Init(int value)
339  *      {
340  *         //...
341  *
342  *         SysTryReturnResult(NID, condition, E_UNKNOWN_ERROR, "An unexpected error has occurred.");
343  *
344  *         //...
345  *         return E_SUCCESS;
346  *      }
347  * @endcode
348  * @hideinitializer
349  */
350 #define SysTryReturnResult(NID, condition, r, ...) \
351         do \
352         { \
353                 if (unlikely(!(condition))) {   \
354                         SysTryReturnResultInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
355                         return r;       \
356                 } \
357         } while (0);
358
359 /**
360  * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
361  * This system log macro is for the platform modules.
362  *
363  * @since 2.0
364  *
365  * @param[in]   NID                     The Tizen namespace
366  * @param[in]   condition               The condition that is expected to be true
367  * @param[in]   r                       The last result to set
368  * @param[in]   ...                     The message to display
369  *
370  * The following example demonstrates how to use the SysTryReturnVoidResult macro.
371  *
372  * @code
373  *      void
374  *      MyEngine::Init(int value)
375  *      {
376  *         //...
377  *
378  *         SysTryReturnVoidResult(NID, condition,  E_INVALID_ARG, "An unexpected error has occurred.");
379  *
380  *         //...
381  *         return;
382  *      }
383  * @endcode
384  * @hideinitializer
385  */
386 #define SysTryReturnVoidResult(NID, condition, r, ...)  \
387         do \
388         { \
389                 if (unlikely(!(condition))) {   \
390                         SysLogException(NID, r, __VA_ARGS__); \
391                         return; \
392                 } \
393         } while (0);
394
395 /**
396  * This macro allows display of exception log message with a tag, when the condition is @c false.
397  * Executes statements, sets the last result and goes to label.
398  * This system log macro is for the platform modules.
399  *
400  * @since 2.0
401  *
402  * @param[in]   NID                     The Tizen namespace
403  * @param[in]   condition               The condition that is expected to be true
404  * @param[in]   expr                    Expressions that are evaluated before going to CATCH label
405  * @param[in]   r                       The last result to set
406  * @param[in]   ...                     The message to display
407  *
408  * The following example demonstrates how to use the SysTryCatch macro.
409  *
410  * @code
411  *      bool
412  *      MyEngine::Init(int value)
413  *      {
414  *         //...
415  *
416  *         SysTryCatch(NID, condition, r=E_INVALID_ARG, E_INVALID_ARG, "An unexpected error has occurred.");
417  *
418  *         //...
419  *         CATCH:
420  *                      return false;
421  *      }
422  * @endcode
423  * @hideinitializer
424  */
425 #define SysTryCatch(NID, condition, expr, r, ...) \
426         do \
427         { \
428                 if (unlikely(!(condition))) {   \
429                         SysLogException(NID, r, __VA_ARGS__); \
430                         expr; \
431                         goto CATCH;     \
432                 } \
433         } while (0);
434
435 /**
436  * This macro allows display of exception log message with a tag, when the condition is @c false.
437  * Executes statements, sets the last result and goes to label.
438  * This system log macro is for the platform modules.
439  *
440  * @since 2.0
441  *
442  * @param[in]   NID                     The Tizen namespace
443  * @param[in]   condition               The condition that is expected to be true
444  * @param[in]   expr                    Expressions that are evaluated before going to catchLabel label
445  * @param[in]   catchLabel              The label for goto operation
446  * @param[in]   r                       The last result to set
447  * @param[in]   ...                     The message to display
448  *
449  * The following example demonstrates how to use the SysTryCatchLabel macro.
450  *
451  * @code
452  *      bool
453  *      MyEngine::Init(int value)
454  *      {
455  *         //...
456  *
457  *         SysTryCatchLabel(NID, condition, r=E_INVALID_ARG, LABEL, E_INVALID_ARG, "An unexpected error has occurred.");
458  *
459  *         //...
460  *         LABEL:
461  *                      return false;
462  *      }
463  * @endcode
464  * @hideinitializer
465  */
466 #define SysTryCatchLabel(NID, condition, expr, catchLabel, r, ...) \
467         do \
468         { \
469                 if (unlikely(!(condition))) {   \
470                         SysLogException(NID, r, __VA_ARGS__); \
471                         expr; \
472                         goto catchLabel; \
473                 } \
474         } while (0);
475
476
477 /**
478  * This macro allows display of exception log message and the program will expire, when the condition is @c false.
479  * This system log macro is for the platform modules.
480  *
481  * @since 2.0
482  *
483  * @param[in]   condition               The condition that is expected to be true
484  *
485  * The following example demonstrates how to use the SysAssert macro.
486  *
487  * @code
488  *      bool
489  *      MyEngine::Init(int value)
490  *      {
491  *         //...
492  *
493  *         SysAssert(condition);
494  *
495  *         //...
496  *      }
497  * @endcode
498  * @hideinitializer
499  */
500 #define SysAssert(condition) \
501         do \
502         { \
503                 if (unlikely(!(condition))) { \
504                         SysAssertInternal(__FILE__, __LINE__, __PRETTY_FUNCTION__);     \
505                 } \
506         } while (0);
507
508 /**
509  * This macro allows display of exception log message with a tag and the program will expire, when the condition is @c false.
510  * This system log macro is for the platform modules.
511  *
512  * @since 2.0
513  *
514  * @param[in]   condition               The condition that is expected to be true
515  * @param[in]   ...                     The message to display
516  *
517  * The following example demonstrates how to use the SysAssertf macro.
518  *
519  * @code
520  *      bool
521  *      MyEngine::Init(int value)
522  *      {
523  *         //...
524  *
525  *         SysAssertf(condition, "");
526  *
527  *         //...
528  *      }
529  * @endcode
530  * @hideinitializer
531  */
532 #define SysAssertf(condition, ...) \
533         do \
534         { \
535                 if (unlikely(!(condition))) { \
536                         SysAssertfInternal(# condition, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__); \
537                 } \
538         } while (0);
539
540
541 /**
542  * This macro generates an error message during compile time, when the condition is @c false.
543  * This system log macro is for the platform modules.
544  *
545  * @since 2.0
546  *
547  * @param[in]   condition               The condition that is expected to be true
548  *
549  * The following example demonstrates how to use the SysStaticAssert macro.
550  *
551  * @code
552  *      bool
553  *      MyEngine::Init(int value)
554  *      {
555  *         //...
556  *
557  *         SysStaticAssert(condition);
558  *
559  *         //...
560  *      }
561  * @endcode
562  * @hideinitializer
563  */
564 #define SysStaticAssert(condition) switch (0) { \
565 case 0: \
566 case condition: \
567   ; \
568 }
569
570
571 /**
572  * This macro allows display of exception log messages.
573  * This system log macro is for the platform modules.
574  *
575  * @since 2.0
576  *
577  * @param[in]   NID                     The Tizen namespace
578  * @param[in]   r                       The last result to set
579  *
580  * The following example demonstrates how to use the SysPropagate macro.
581  *
582  * @code
583  *      bool
584  *      MyEngine::Init(int value)
585  *      {
586  *         //...
587  *
588  *         SysPropagate(NID, E_INVALID_ARG);
589  *
590  *         //...
591  *      }
592  * @endcode
593  * @hideinitializer
594  */
595 #define SysPropagate(NID, r)        SysPropagateInternal(__PRETTY_FUNCTION__, __LINE__, NID, r)
596
597 // Secure Macros
598 #if defined(_SECURE_LOG)
599
600 #define SysSecureLog(NID, ...)                          SysLogInternal(NID, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
601 #define SysSecureLogException(NID, r,...)               SysLogExceptionInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
602
603 #define SysSecureLogTag(NID, tag, ...)                  SysLogTagInternal(NID, tag, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
604 #define SysSecureLogExceptionTag(NID, tag, r, ...)      SysLogExceptionTagInternal(NID, tag, r, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__)
605
606 #else
607
608 /**
609  * This macro is to protect informative log messages which needs to keep security.
610  * It allows display of informative log messages if compiled with "_SECURE_LOG" definition.
611  * Otherwise, it will be removed in the compile time.
612  * This system log macro is for the platform modules.
613  *
614  * @since 2.1
615  *
616  * @param[in]   NID                     The Tizen namespace ID
617  * @param[in]   ...                     The message to display
618  *
619  * The following example demonstrates how to use the SysSecureLog macro.
620  *
621  * @code
622  *        bool
623  *        MyEngine::Init(int value)
624  *        {
625  *           SysSecureLog(NID, "User ID : 'JoneDoe'");
626  *
627  *           return true;
628  *        }
629  * @endcode
630  * @hideinitializer
631  */
632 #define SysSecureLog(NID, ...)
633
634 /**
635  * This macro is to protect exception log messages which needs to keep security, and sets the last result.
636  * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
637  * Otherwise, log printing functionality will be removed in the compile time.
638  * This system log macro is for the platform modules.
639  *
640  * @since 2.1
641  *
642  * @param[in]   NID                     The Tizen namespace ID
643  * @param[in]   r                       The last result to set
644  * @param[in]   ...                     The message to display
645  *
646  * The following example demonstrates how to use the SysSecureLogException macro.
647  *
648  * @code
649  *        bool
650  *        MyEngine::Init(int value)
651  *        {
652  *           //...
653  *           if (something_wrong)
654  *           {
655  *              SysSecureLogException(NID,  E_INVALID_ARG, "User ID : 'JoneDoe' mismatch.");
656  *
657  *              return false;
658  *           }
659  *   //...
660  *
661  *           return true;
662  *        }
663  * @endcode
664  * @hideinitializer
665  */
666 #define SysSecureLogException(NID, r,...)                       SetLastResult(r);
667
668 /**
669  * This macro is to protect informative log messages which needs to keep security, with a tag.
670  * It allows display of informative log messages if compiled with "_SECURE_LOG" definition.
671  * Otherwise, it will be removed in the compile time.
672  * This system log macro is for the platform modules.
673  *
674  * @since 2.1
675  *
676  * @param[in]   NID                     The Tizen namespace ID
677  * @param[in]   tag                     The user defined tag
678  * @param[in]   ...                     The message to display
679  *
680  * The following example demonstrates how to use the SysSecureLogTag macro.
681  *
682  * @code
683  *        bool
684  *        MyEngine::Init(int value)
685  *        {
686  *           SysSecureLogTag(NID, "MyTag", "User ID : 'JoneDoe'");
687  *
688  *           return true;
689  *        }
690  * @endcode
691  * @hideinitializer
692  */
693 #define SysSecureLogTag(NID, tag, ...)
694
695 /**
696  * This macro is to protect exception log messages which needs to keep security, with a tag and sets the last result.
697  * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
698  * Otherwise, log printing functionality will be removed in the compile time.
699  * This system log macro is for the platform modules.
700  *
701  * @since 2.1
702  *
703  * @param[in]   NID                     The Tizen namespace ID
704  * @param[in]   tag                     The user defined tag
705  * @param[in]   r                       The last result to set
706  * @param[in]   ...                     The message to display
707  *
708  * The following example demonstrates how to use the SysSecureLogExceptionTag macro.
709  *
710  * @code
711  *        bool
712  *        MyEngine::Init(int value)
713  *        {
714  *           SysSecureLogExceptionTag(NID, "MyTag", E_INVALID_ARG, "User ID : 'JoneDoe' mismatch.");
715  *
716  *           return true;
717  *        }
718  * @endcode
719  * @hideinitializer
720  */
721 #define SysSecureLogExceptionTag(NID, tag, r, ...)              SetLastResult(r);
722
723 #endif
724
725 /**
726  * This macro allows display of informative log message with a tag, when the condition is @c false.
727  * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
728  * Otherwise, log printing functionality will be removed in the compile time.
729  * This system log macro is for the platform modules.
730  *
731  * @since 2.1
732  *
733  * @param[in]   NID                     The Tizen namespace
734  * @param[in]   condition               The condition that is expected to be true
735  * @param[in]   ...                     The message to display
736  *
737  * The following example demonstrates how to use the SysSecureTry macro.
738  *
739  * @code
740  *      bool
741  *      MyEngine::Init(int value)
742  *      {
743  *         //...
744  *
745  *         SysSecureTryLog(NID, condition, "Password mismatch : %s", password );
746  *
747  *         //...
748  *      }
749  * @endcode
750  * @hideinitializer
751  */
752 #define SysSecureTryLog(NID, condition, ...) \
753         do \
754         { \
755                 if (unlikely(!(condition))) {   \
756                         SysSecureLog(NID, __VA_ARGS__); \
757                 } \
758         } while (0);
759
760 /**
761  * This macro allows display of informative log message, when the condition is @c false.
762  * Executes statements and goes to label.
763  * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
764  * Otherwise, log printing functionality will be removed in the compile time.
765  * This system log macro is for the platform modules.
766  *
767  * @since 2.1
768  *
769  * @param[in]   NID                     The Tizen namespace
770  * @param[in]   condition               The condition that is expected to be true
771  * @param[in]   expr                    Expressions that are evaluated before going to CATCH label
772  * @param[in]   ...                     The message to display
773  * @hideinitializer
774  */
775 #define SysSecureTryLogCatch(NID, condition, expr, ...) \
776         do \
777         { \
778                 if (unlikely(!(condition))) { \
779                         SysSecureLog(NID, __VA_ARGS__); \
780                         expr; \
781                         goto CATCH;     \
782                 } \
783         } while (0);
784
785 /**
786  * This macro allows display of informative log message and returns returnValue, when the condition is @c false.
787  * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
788  * Otherwise, log printing functionality will be removed in the compile time.
789  * This system log macro is for the platform modules.
790  *
791  * @since 2.1
792  *
793  * @param[in]   NID                     The Tizen namespace
794  * @param[in]   condition               The condition that is expected to be true
795  * @param[in]   returnValue             The value to return when the condition is @c false
796  * @param[in]   ...                     The message to display
797  * @hideinitializer
798  */
799 #define SysSecureTryLogReturn(NID, condition, returnValue, ...) \
800         do \
801         { \
802                 if (unlikely(!(condition))) { \
803                         SysSecureLog(NID, __VA_ARGS__); \
804                         return returnValue;     \
805                 } \
806         } while (0);
807
808 /**
809  * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
810  * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
811  * Otherwise, log printing functionality will be removed in the compile time.
812  * This system log macro is for the platform modules.
813  *
814  * @since 2.1
815  *
816  * @param[in]   NID                     The Tizen namespace
817  * @param[in]   condition               The condition that is expected to be true
818  * @param[in]   returnValue             The value to return when the condition is @c false
819  * @param[in]   r                       The last result to set
820  * @param[in]   ...                     The message to display
821  * @hideinitializer
822  */
823 #define SysSecureTryReturn(NID, condition, returnValue, r, ...) \
824         do \
825         { \
826                 if (unlikely(!(condition))) {   \
827                         SysSecureLogException(NID, r, __VA_ARGS__); \
828                         return returnValue;     \
829                 } \
830         } while (0);
831
832 #if defined(_SECURE_LOG)
833 /**
834  * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
835  * This is a shorthand macro for SysSecureTryReturn(NID, condition, r, r, "[" # r "] " ...).
836  * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
837  * Otherwise, log printing functionality will be removed in the compile time.
838  * This system log macro is for the platform modules.
839  *
840  * @since 2.1
841  *
842  * @param[in]   NID                     The Tizen namespace
843  * @param[in]   condition               The condition that is expected to be true
844  * @param[in]   r                       The last result to set
845  * @param[in]   ...                     The message to display
846  * @hideinitializer
847  */
848 #define SysSecureTryReturnResult(NID, condition, r, ...) \
849         do \
850         { \
851                 if (unlikely(!(condition))) {   \
852                         SysTryReturnResultInternal(NID, r, __PRETTY_FUNCTION__, __LINE__, "[SECURE_LOG] "__VA_ARGS__); \
853                         return r;       \
854                 } \
855         } while (0);
856
857 #else
858 #define SysSecureTryReturnResult(NID, condition, r, ...) \
859         do \
860         { \
861                 if (unlikely(!(condition))) {   \
862                         SetLastResult(r); \
863                         return r;       \
864                 } \
865         } while (0);
866 #endif
867
868 /**
869  * This macro allows display of exception log message with a tag and sets the last result, when the condition is @c false.
870  * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
871  * Otherwise, log printing functionality will be removed in the compile time.
872  * This system log macro is for the platform modules.
873  *
874  * @since 2.1
875  *
876  * @param[in]   NID                     The Tizen namespace
877  * @param[in]   condition               The condition that is expected to be true
878  * @param[in]   r                       The last result to set
879  * @param[in]   ...                     The message to display
880  * @hideinitializer
881  */
882 #define SysSecureTryReturnVoidResult(NID, condition, r, ...)    \
883         do \
884         { \
885                 if (unlikely(!(condition))) {   \
886                         SysSecureLogException(NID, r, __VA_ARGS__); \
887                         return; \
888                 } \
889         } while (0);
890
891 /**
892  * This macro allows display of exception log message with a tag, when the condition is @c false.
893  * Executes statements, sets the last result and goes to label.
894  * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
895  * Otherwise, log printing functionality will be removed in the compile time.
896  * This system log macro is for the platform modules.
897  *
898  * @since 2.1
899  *
900  * @param[in]   NID                     The Tizen namespace
901  * @param[in]   condition               The condition that is expected to be true
902  * @param[in]   expr                    Expressions that are evaluated before going to CATCH label
903  * @param[in]   r                       The last result to set
904  * @param[in]   ...                     The message to display
905  * @hideinitializer
906  */
907 #define SysSecureTryCatch(NID, condition, expr, r, ...) \
908         do \
909         { \
910                 if (unlikely(!(condition))) {   \
911                         SysSecureLogException(NID, r, __VA_ARGS__); \
912                         expr; \
913                         goto CATCH;     \
914                 } \
915         } while (0);
916
917 /**
918  * This macro allows display of exception log message with a tag, when the condition is @c false.
919  * Executes statements, sets the last result and goes to label.
920  * It allows display of exception log messages if compiled with "_SECURE_LOG" definition.
921  * Otherwise, log printing functionality will be removed in the compile time.
922  * This system log macro is for the platform modules.
923  *
924  * @since 2.1
925  *
926  * @param[in]   NID                     The Tizen namespace
927  * @param[in]   condition               The condition that is expected to be true
928  * @param[in]   expr                    Expressions that are evaluated before going to catchLabel label
929  * @param[in]   catchLabel              The label for goto operation
930  * @param[in]   r                       The last result to set
931  * @param[in]   ...                     The message to display
932  * @hideinitializer
933  */
934 #define SysSecureTryCatchLabel(NID, condition, expr, catchLabel, r, ...) \
935         do \
936         { \
937                 if (unlikely(!(condition))) {   \
938                         SysSecureLogException(NID, r, __VA_ARGS__); \
939                         expr; \
940                         goto catchLabel; \
941                 } \
942         } while (0);
943
944
945 /**
946  * Defines the log ID.
947  */
948 enum LogID
949 {
950 //Tizen Namespace ID ===============================================================
951         NID_APP = 0,
952
953         NID_BASE = 10,
954         NID_BASE_COL = 11,
955         NID_BASE_RT = 12,
956         NID_BASE_UTIL = 13,
957
958         NID_CNT = 20,
959
960         NID_CTXT = 30,
961
962         NID_GRP = 40,
963
964         NID_IO = 50,
965
966         NID_LCL = 60,
967
968         NID_LOC = 70,
969         NID_LOC_CTRL = 71,
970         NID_LOC_SVC = 72,
971
972         NID_MEDIA = 80,
973
974         NID_MSG = 90,
975
976         NID_NET = 100,
977         NID_NET_BT = 101,
978         NID_NET_HTTP = 102,
979         NID_NET_NFC = 103,
980         NID_NET_SOCK = 104,
981         NID_NET_WIFI = 105,
982
983         NID_SEC = 110,
984         NID_SEC_CERT = 111,
985         NID_SEC_CRYPTO = 112,
986
987         NID_SCL = 120,
988
989         NID_SYS = 130,
990
991         NID_TEL = 140,
992
993         NID_TEXT = 150,
994
995         NID_UI = 160,
996         NID_UI_ANIM = 161,
997         NID_UI_CTRL = 162,
998         NID_UI_EFFECT = 163,
999         NID_UI_IME = 164,
1000         NID_UI_SCENES = 165,
1001
1002         NID_UIX = 170,
1003         NID_UIX_SPEECH = 171,
1004
1005         NID_WEB = 180,
1006         NID_WEB_CTRL = 181,
1007         NID_WEB_JSON = 182,
1008
1009         NID_SHELL = 190
1010 };
1011
1012 /**
1013 *
1014 @} */
1015
1016 _OSP_EXPORT_ void SysLogInternal(unsigned long id, const char* pFunction, int lineNumber, const char* pFormat, ...);
1017 _OSP_EXPORT_ void SysLogExceptionInternal(unsigned long id, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
1018
1019 _OSP_EXPORT_ void SysLogTagInternal(unsigned long id, const char* pTag, const char* pFunction, int lineNumber, const char* pFormat, ...);
1020 _OSP_EXPORT_ void SysLogExceptionTagInternal(unsigned long id, const char* pTag, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
1021
1022 _OSP_EXPORT_ void SysAssertInternal(const char* pFileName, int lineNumber, const char* pFunction);
1023 _OSP_EXPORT_ void SysAssertfInternal(const char* expr, const char* pFunction, int lineNumber, const char* pFormat, ...);
1024
1025 _OSP_EXPORT_ void SysPropagateInternal(const char* pFunction, int lineNumber, unsigned long nid, result r);
1026
1027 _OSP_EXPORT_ void SysTryReturnResultInternal(unsigned long id, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
1028
1029 #ifdef __cplusplus
1030 }
1031 #endif // __cplusplus
1032
1033
1034 #endif // _FBASE_SYS_LOG_H_