checking backend ABI version
[platform/core/uifw/libtdm.git] / src / tdm_backend.c
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 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #include "tdm.h"
41 #include "tdm_backend.h"
42 #include "tdm_private.h"
43
44 #define BACKEND_FUNC_ENTRY() \
45     tdm_private_display *private_display; \
46     TDM_RETURN_VAL_IF_FAIL(dpy != NULL, TDM_ERROR_INVALID_PARAMETER); \
47     private_display = (tdm_private_display*)dpy;
48
49 static int
50 _check_abi_version(tdm_backend_module *module, int abimaj, int abimin)
51 {
52     int major = TDM_BACKEND_GET_ABI_MAJOR(module->abi_version);
53     int minor = TDM_BACKEND_GET_ABI_MINOR(module->abi_version);
54
55     if (major < abimaj) goto failed;
56     if (major > abimaj) return 1;
57     if (minor < abimin) goto failed;
58     return 1;
59 failed:
60     TDM_ERR("The ABI version(%d.%d) of '%s' is less than %d.%d",
61             major, minor, module->name ? module->name : "unknown",
62             abimaj, abimin);
63     return 0;
64 }
65
66 EXTERN tdm_error
67 tdm_backend_register_func_display(tdm_display *dpy, tdm_func_display *func_display)
68 {
69     tdm_backend_module *module;
70
71     BACKEND_FUNC_ENTRY();
72
73     TDM_RETURN_VAL_IF_FAIL(func_display != NULL, TDM_ERROR_INVALID_PARAMETER);
74
75     /* the ABI version of backend module should be more than 1.1 */
76     module = private_display->module_data;
77     if (_check_abi_version(module, 1, 1) < 0)
78         return TDM_ERROR_BAD_MODULE;
79
80     pthread_mutex_lock(&private_display->lock);
81     private_display->func_display = *func_display;
82     pthread_mutex_unlock(&private_display->lock);
83
84     return TDM_ERROR_NONE;
85 }
86
87 EXTERN tdm_error
88 tdm_backend_register_func_output(tdm_display *dpy, tdm_func_output *func_output)
89 {
90     tdm_backend_module *module;
91
92     BACKEND_FUNC_ENTRY();
93
94     TDM_RETURN_VAL_IF_FAIL(func_output != NULL, TDM_ERROR_INVALID_PARAMETER);
95
96     /* the ABI version of backend module should be more than 1.1 */
97     module = private_display->module_data;
98     if (_check_abi_version(module, 1, 1) < 0)
99         return TDM_ERROR_BAD_MODULE;
100
101     pthread_mutex_lock(&private_display->lock);
102     private_display->func_output = *func_output;
103     pthread_mutex_unlock(&private_display->lock);
104
105     return TDM_ERROR_NONE;
106 }
107
108 EXTERN tdm_error
109 tdm_backend_register_func_layer(tdm_display *dpy, tdm_func_layer *func_layer)
110 {
111     tdm_backend_module *module;
112
113     BACKEND_FUNC_ENTRY();
114
115     TDM_RETURN_VAL_IF_FAIL(func_layer != NULL, TDM_ERROR_INVALID_PARAMETER);
116
117     /* the ABI version of backend module should be more than 1.1 */
118     module = private_display->module_data;
119     if (_check_abi_version(module, 1, 1) < 0)
120         return TDM_ERROR_BAD_MODULE;
121
122     pthread_mutex_lock(&private_display->lock);
123     private_display->func_layer = *func_layer;
124     pthread_mutex_unlock(&private_display->lock);
125
126     return TDM_ERROR_NONE;
127 }
128
129 EXTERN tdm_error
130 tdm_backend_register_func_pp(tdm_display *dpy, tdm_func_pp *func_pp)
131 {
132     BACKEND_FUNC_ENTRY();
133
134     if (!func_pp)
135         return TDM_ERROR_NONE;
136
137     pthread_mutex_lock(&private_display->lock);
138     private_display->capabilities |= TDM_DISPLAY_CAPABILITY_PP;
139     private_display->func_pp = *func_pp;
140     pthread_mutex_unlock(&private_display->lock);
141
142     return TDM_ERROR_NONE;
143 }
144
145 EXTERN tdm_error
146 tdm_backend_register_func_capture(tdm_display *dpy, tdm_func_capture *func_capture)
147 {
148     BACKEND_FUNC_ENTRY();
149
150     if (!func_capture)
151         return TDM_ERROR_NONE;
152
153     pthread_mutex_lock(&private_display->lock);
154     private_display->capabilities |= TDM_DISPLAY_CAPABILITY_CAPTURE;
155     private_display->func_capture = *func_capture;
156     pthread_mutex_unlock(&private_display->lock);
157
158     return TDM_ERROR_NONE;
159 }
160