sync with tizen_2.0
[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  *      Bool
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  *      Bool
338  *      MyEngine::Init(int value)
339  *      {
340  *         //...
341  *
342  *         SysTryReturnResult(NID, condition, E_UNKNOWN_ERROR, "An unexpected error has occurred.");
343  *
344  *         //...
345  *         return true;
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  *      Bool
374  *      MyEngine::Init(int value)
375  *      {
376  *         //...
377  *
378  *         SysTryReturnVoidResult(NID, condition,  E_INVALID_ARG, "An unexpected error has occurred.");
379  *
380  *         //...
381  *         return true;
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
598 /**
599  * Defines the log ID.
600  */
601 enum LogID
602 {
603 //Tizen Namespace ID ===============================================================
604         NID_APP = 0,
605
606         NID_BASE = 10,
607         NID_BASE_COL = 11,
608         NID_BASE_RT = 12,
609         NID_BASE_UTIL = 13,
610
611         NID_CNT = 20,
612
613         NID_CTXT = 30,
614
615         NID_GRP = 40,
616
617         NID_IO = 50,
618
619         NID_LCL = 60,
620
621         NID_LOC = 70,
622         NID_LOC_CTRL = 71,
623         NID_LOC_SVC = 72,
624
625         NID_MEDIA = 80,
626
627         NID_MSG = 90,
628
629         NID_NET = 100,
630         NID_NET_BT = 101,
631         NID_NET_HTTP = 102,
632         NID_NET_NFC = 103,
633         NID_NET_SOCK = 104,
634         NID_NET_WIFI = 105,
635
636         NID_SEC = 110,
637         NID_SEC_CERT = 111,
638         NID_SEC_CRYPTO = 112,
639
640         NID_SCL = 120,
641
642         NID_SYS = 130,
643
644         NID_TEL = 140,
645
646         NID_TEXT = 150,
647
648         NID_UI = 160,
649         NID_UI_ANIM = 161,
650         NID_UI_CTRL = 162,
651         NID_UI_EFFECT = 163,
652         NID_UI_IME = 164,
653         NID_UI_SCENES = 165,
654
655         NID_UIX = 170,
656         NID_UIX_SPEECH = 171,
657
658         NID_WEB = 180,
659         NID_WEB_CTRL = 181,
660         NID_WEB_JSON = 182
661 };
662
663 /**
664 *
665 @} */
666
667 _OSP_EXPORT_ void SysLogInternal(unsigned long id, const char* pFunction, int lineNumber, const char* pFormat, ...);
668 _OSP_EXPORT_ void SysLogExceptionInternal(unsigned long id, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
669
670 _OSP_EXPORT_ void SysLogTagInternal(unsigned long id, const char* pTag, const char* pFunction, int lineNumber, const char* pFormat, ...);
671 _OSP_EXPORT_ void SysLogExceptionTagInternal(unsigned long id, const char* pTag, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
672
673 _OSP_EXPORT_ void SysAssertInternal(const char* pFileName, int lineNumber, const char* pFunction);
674 _OSP_EXPORT_ void SysAssertfInternal(const char* expr, const char* pFunction, int lineNumber, const char* pFormat, ...);
675
676 _OSP_EXPORT_ void SysPropagateInternal(const char* pFunction, int lineNumber, unsigned long nid, result r);
677
678 _OSP_EXPORT_ void SysTryReturnResultInternal(unsigned long id, result r, const char* pFunction, int lineNumber, const char* pFormat, ...);
679
680 #ifdef __cplusplus
681 }
682 #endif // __cplusplus
683
684
685 #endif // _FBASE_SYS_LOG_H_