Use timer to call the output change callback of the sub-thread.
[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 #include <tdm_common.h>
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 #undef EXTERN
51 #undef DEPRECATED
52 #undef INTERN
53
54 #if defined(__GNUC__) && __GNUC__ >= 4
55 #define EXTERN __attribute__ ((visibility("default")))
56 #else
57 #define EXTERN
58 #endif
59
60 #if defined(__GNUC__) && __GNUC__ >= 4
61 #define INTERN __attribute__ ((visibility("hidden")))
62 #else
63 #define INTERN
64 #endif
65
66 #if defined(__GNUC__) && __GNUC__ >= 4
67 #define DEPRECATED __attribute__ ((deprecated))
68 #else
69 #define DEPRECATED
70 #endif
71
72 /* check condition */
73 #define TDM_RETURN_IF_FAIL(cond) { \
74         if (!(cond))  { \
75                 TDM_ERR("'%s' failed", #cond); \
76                 return; \
77         } \
78 }
79 #define TDM_RETURN_VAL_IF_FAIL(cond, val) { \
80         if (!(cond)) { \
81                 TDM_ERR("'%s' failed", #cond); \
82                 return val; \
83         } \
84 }
85 #define TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(cond, error_v, val) { \
86         if (!(cond)) { \
87                 TDM_ERR("'%s' failed", #cond); \
88                 ret = error_v; \
89                 if (error) *error = ret; \
90                 return val; \
91         } \
92 }
93
94 #define TDM_WARNING_IF_FAIL(cond)  { \
95         if (!(cond)) \
96                 TDM_ERR("'%s' failed", #cond); \
97 }
98 #define TDM_GOTO_IF_FAIL(cond, dst) { \
99         if (!(cond)) { \
100                 TDM_ERR("'%s' failed", #cond); \
101                 goto dst; \
102         } \
103 }
104
105 #define TDM_NEVER_GET_HERE() TDM_WRN("** NEVER GET HERE **")
106
107 #define TDM_SNPRINTF(p, len, fmt, ARG...)  \
108         do { \
109                 if (p && len && *len > 0) { \
110                         int s = snprintf(p, *len, fmt, ##ARG); \
111                         p += s; \
112                         *len -= s; \
113                 } \
114         } while (0)
115
116 #define C(b, m)             (((b) >> (m)) & 0xFF)
117 #define B(c, s)             ((((unsigned int)(c)) & 0xff) << (s))
118 #define FOURCC(a, b, c, d)  (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
119 #define FOURCC_STR(id)      C(id, 0), C(id, 8), C(id, 16), C(id, 24)
120 #define FOURCC_ID(str)      FOURCC(((char*)str)[0], ((char*)str)[1], ((char*)str)[2], ((char*)str)[3])
121
122
123 #define TDM_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
124
125 struct tdm_type_name {
126         int type;
127         const char *name;
128 };
129
130 #define TDM_TYPE_NAME_FN(res) \
131 static inline const char * tdm_##res##_str(int type)    \
132 {                       \
133         unsigned int i;                                 \
134         for (i = 0; i < TDM_ARRAY_SIZE(tdm_##res##_names); i++) { \
135                 if (tdm_##res##_names[i].type == type)  \
136                         return tdm_##res##_names[i].name;       \
137         }                                               \
138         return "(invalid)";                             \
139 }
140
141 static struct tdm_type_name tdm_dpms_names[] = {
142         { TDM_OUTPUT_DPMS_ON, "on" },
143         { TDM_OUTPUT_DPMS_STANDBY, "standby" },
144         { TDM_OUTPUT_DPMS_SUSPEND, "suspend" },
145         { TDM_OUTPUT_DPMS_OFF, "off" },
146 };
147
148 TDM_TYPE_NAME_FN(dpms)
149
150 static struct tdm_type_name tdm_status_names[] = {
151         { TDM_OUTPUT_CONN_STATUS_DISCONNECTED, "disconnected" },
152         { TDM_OUTPUT_CONN_STATUS_CONNECTED, "connected" },
153         { TDM_OUTPUT_CONN_STATUS_MODE_SETTED, "mode_setted" },
154 };
155
156 TDM_TYPE_NAME_FN(status)
157
158 #ifdef __cplusplus
159 }
160 #endif
161
162 #endif /* _TDM_MACRO_H_ */