a547c0a4a82c5a88d054351b33c66e5f307821e2
[platform/core/uifw/libtdm.git] / src / tdm_macro.h
1 /**************************************************************************
2
3 libtdm
4
5 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8          JinYoung Jeon <jy0.jeon@samsung.com>,
9          Taeheon Kim <th908.kim@samsung.com>,
10          YoungJun Cho <yj44.cho@samsung.com>,
11          SooChan Lim <sc1.lim@samsung.com>,
12          Boram Park <sc1.lim@samsung.com>
13
14 Permission is hereby granted, free of charge, to any person obtaining a
15 copy of this software and associated documentation files (the
16 "Software"), to deal in the Software without restriction, including
17 without limitation the rights to use, copy, modify, merge, publish,
18 distribute, sub license, and/or sell copies of the Software, and to
19 permit persons to whom the Software is furnished to do so, subject to
20 the following conditions:
21
22 The above copyright notice and this permission notice (including the
23 next paragraph) shall be included in all copies or substantial portions
24 of the Software.
25
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
34 **************************************************************************/
35
36 #ifndef _TDM_MACRO_H_
37 #define _TDM_MACRO_H_
38
39 #include <stdio.h>
40 #include <string.h>
41 #include <stdlib.h>
42 #include <sys/types.h>
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #undef EXTERN
49 #undef DEPRECATED
50 #undef INTERN
51
52 #if defined(__GNUC__) && __GNUC__ >= 4
53 #define EXTERN __attribute__ ((visibility("default")))
54 #else
55 #define EXTERN
56 #endif
57
58 #if defined(__GNUC__) && __GNUC__ >= 4
59 #define INTERN __attribute__ ((visibility("hidden")))
60 #else
61 #define INTERN
62 #endif
63
64 #if defined(__GNUC__) && __GNUC__ >= 4
65 #define DEPRECATED __attribute__ ((deprecated))
66 #else
67 #define DEPRECATED
68 #endif
69
70 /* check condition */
71 #define TDM_RETURN_IF_FAIL(cond) {\
72     if (!(cond)) {\
73         TDM_ERR ("'%s' failed", #cond);\
74         return;\
75     }\
76 }
77 #define TDM_RETURN_VAL_IF_FAIL(cond, val) {\
78     if (!(cond)) {\
79         TDM_ERR ("'%s' failed", #cond);\
80         return val;\
81     }\
82 }
83 #define TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(cond, error_v, val) {\
84     if (!(cond)) {\
85         TDM_ERR ("'%s' failed", #cond);\
86         ret = error_v;\
87         if (error) *error = ret;\
88         return val;\
89     }\
90 }
91
92 #define TDM_WARNING_IF_FAIL(cond)  {\
93     if (!(cond))\
94         TDM_ERR ("'%s' failed", #cond);\
95 }
96 #define TDM_GOTO_IF_FAIL(cond, dst) {\
97     if (!(cond)) {\
98         TDM_ERR ("'%s' failed", #cond);\
99         goto dst;\
100     }\
101 }
102
103 #define TDM_NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **")
104
105 #define TDM_SNPRINTF(p, len, fmt, ARG...)  \
106     do { \
107         if (p && len && *len > 0) \
108         { \
109             int s = snprintf(p, *len, fmt, ##ARG); \
110             p += s; \
111             *len -= s; \
112         } \
113     } while (0)
114
115 #define C(b,m)              (((b) >> (m)) & 0xFF)
116 #define B(c,s)              ((((unsigned int)(c)) & 0xff) << (s))
117 #define FOURCC(a,b,c,d)     (B(d,24) | B(c,16) | B(b,8) | B(a,0))
118 #define FOURCC_STR(id)      C(id,0), C(id,8), C(id,16), C(id,24)
119 #define FOURCC_ID(str)      FOURCC(((char*)str)[0],((char*)str)[1],((char*)str)[2],((char*)str)[3])
120
121 #ifdef __cplusplus
122 }
123 #endif
124
125 #endif /* _TDM_MACRO_H_ */