[Fix:Conflict]Changed the animation of a default defined from none to fade.
[profile/ivi/ico-uxf-weston-plugin.git] / src / ico_ivi_common.c
1 /*
2  * Copyright © 2010-2011 Intel Corporation
3  * Copyright © 2008-2011 Kristian Høgsberg
4  * Copyright © 2013 TOYOTA MOTOR CORPORATION.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and
7  * its documentation for any purpose is hereby granted without fee, provided
8  * that the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of the copyright holders not be used in
11  * advertising or publicity pertaining to distribution of the software
12  * without specific, written prior permission.  The copyright holders make
13  * no representations about the suitability of this software for any
14  * purpose.  It is provided "as is" without express or implied warranty.
15  *
16  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23  */
24 /**
25  * @brief   Weston(Wayland) Plugin: IVI Common Functions.
26  *
27  * @date    Feb-08-2013
28  */
29
30 #define _GNU_SOURCE
31
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <stdbool.h>
35 #include <string.h>
36 #include <unistd.h>
37 #include <dlfcn.h>
38
39 #include <weston/compositor.h>
40 #include "ico_ivi_common.h"
41
42 /* IVI Plugin Common Table                  */
43 struct ico_ivi_common {
44     int32_t myNodeId;                       /* (HostId << 16) | DisplayNo               */
45     int (*usurf_2_node)(const int surfaceid);
46                                             /* Function address of nodeId from surfaceId*/
47     int (*send_to_mgr)(const int event, const int surfaceid, const char *appid,
48                        const int param1, const int param2, const int param3,
49                        const int param4, const int param5, const int param6);
50                                             /* Function address of send to manager      */
51     int (*send_surface_change)(struct weston_surface *surface,
52                                const int x, const int y, const int width, const int height);
53                                             /* Function address of send configure to manager*/
54 };
55
56 /* This function is called from the ico_plugin-loader and initializes this module.*/
57 int module_init(struct weston_compositor *ec);
58
59 /* Static area for control ico_ivi_common       */
60 static struct ico_ivi_common *_ico_ivi_common = NULL;
61
62 /* Special options                              */
63 static int  _ico_option_flag = 0;
64
65 /* Debug level                                  */
66 static int  _ico_ivi_debug = 3;
67
68 static const struct config_key debug_config_keys[] = {
69         { "option_flag", CONFIG_KEY_INTEGER, &_ico_option_flag },
70         { "ivi_debug", CONFIG_KEY_INTEGER, &_ico_ivi_debug },
71     };
72
73 static const struct config_section conf_debug[] = {
74         { "debug", debug_config_keys, ARRAY_LENGTH(debug_config_keys) },
75     };
76
77 /*--------------------------------------------------------------------------*/
78 /**
79  * @brief   ico_special_option: Answer special option flag
80  *
81  * @param       None
82  * @return      Special option flag
83  */
84 /*--------------------------------------------------------------------------*/
85 WL_EXPORT   int
86 ico_option_flag(void)
87 {
88     return _ico_option_flag;
89 }
90
91 /*--------------------------------------------------------------------------*/
92 /**
93  * @brief   ico_ivi_debuglevel: Answer debug output level.
94  *
95  * @param       None
96  * @return      Debug output level
97  * @retval      0       No debug output
98  * @retval      1       Only error output
99  * @retval      2       Error and information output
100  * @retval      3       All output with debug write
101  */
102 /*--------------------------------------------------------------------------*/
103 WL_EXPORT   int
104 ico_ivi_debuglevel(void)
105 {
106     return _ico_ivi_debug;
107 }
108
109 /*--------------------------------------------------------------------------*/
110 /**
111  * @brief   ico_ivi_get_mynode: Get my NodeId
112  *
113  * @param       None
114  * @return      NodeId of my node
115  */
116 /*--------------------------------------------------------------------------*/
117 WL_EXPORT   int
118 ico_ivi_get_mynode(void)
119 {
120     /* Reference Platform 0.50 only support 1 ECU   */
121     return 0;
122 }
123
124 /*--------------------------------------------------------------------------*/
125 /**
126  * @brief   ico_ivi_set_usurf_2_node: Regist function of convert surfaceId to NodeId
127  *
128  * @param[in]   usurf_2_node    Function address of usurf_2_node
129  * @return      None
130  */
131 /*--------------------------------------------------------------------------*/
132 WL_EXPORT   void
133 ico_ivi_set_usurf_2_node(int (*usurf_2_node)(const int surfaceid))
134 {
135     _ico_ivi_common->usurf_2_node = usurf_2_node;
136 }
137
138 /*--------------------------------------------------------------------------*/
139 /**
140  * @brief   ico_ivi_usurf_2_node: Convert surfaceId to NodeId
141  *
142  * @param[in]   surfaceid       ivi-shell surfaceId
143  * @return      NodeId
144  * @retval      >= 0            NodeId
145  * @retval      < 0             Surface dose not exist
146  */
147 /*--------------------------------------------------------------------------*/
148 WL_EXPORT   int
149 ico_ivi_usurf_2_node(const int surfaceid)
150 {
151     int     nodeId;
152
153     if (_ico_ivi_common->usurf_2_node)  {
154         /* If declared convert function, call function          */
155         nodeId = (*_ico_ivi_common->usurf_2_node) (surfaceid);
156         if (nodeId >= 0)    {
157             return nodeId;
158         }
159     }
160
161     /* If NOT declare convert function, convert from surfaceId  */
162     return ICO_IVI_SURFACEID_2_NODEID(surfaceid);
163 }
164
165 /*--------------------------------------------------------------------------*/
166 /**
167  * @brief   ico_ivi_set_send_to_mgr: Regist function of send to manager
168  *
169  * @param[in]   send_to_mgr     Function address of send to manager
170  * @return      None
171  */
172 /*--------------------------------------------------------------------------*/
173 WL_EXPORT   void
174 ico_ivi_set_send_to_mgr(int (*send_to_mgr)(const int event,
175                         const int surfaceid, const char *appid,
176                         const int param1, const int param2, const int param3,
177                         const int param4, const int param5, const int param6))
178 {
179     _ico_ivi_common->send_to_mgr = send_to_mgr;
180 }
181
182 /*--------------------------------------------------------------------------*/
183 /**
184  * @brief   ico_ivi_send_to_mgr: Send event to manager
185  *
186  * @param[in]   event           Event code
187  * @param[in]   client_resource Client resource
188  * @param[in]   surfaceid       SurfaceId  (depend of event code)
189  * @param[in]   appid           ApplicationId  (depend of event code)
190  * @param[in]   param1          Parameter.1 (depend of event code)
191  * @param[in]   param2          Parameter.2 (depend of event code)
192  * @param[in]     :
193  * @param[in]   param6          Parameter.6 (depend of event code)
194  * @return      number of managers
195  * @retval      > 0             number of managers
196  * @retval      0               manager not exist
197  * @retval      -1              Multi Input Manager not exist
198  */
199 /*--------------------------------------------------------------------------*/
200 WL_EXPORT   int
201 ico_ivi_send_to_mgr(const int event, struct wl_resource *client_resource,
202                     const int surfaceid, const char *appid,
203                     const int param1, const int param2, const int param3,
204                     const int param4, const int param5, const int param6)
205 {
206     if (_ico_ivi_common->send_to_mgr)   {
207         return (*_ico_ivi_common->send_to_mgr)(event, surfaceid, appid,
208                                                param1, param2, param3,
209                                                param4, param5, param6);
210     }
211     return -1;
212 }
213
214 /*--------------------------------------------------------------------------*/
215 /**
216  * @brief   ico_ivi_set_send_surface_change: Regist function of surface change
217  *
218  * @param[in]   send_surface_change     Function address of surface change
219  * @return      None
220  */
221 /*--------------------------------------------------------------------------*/
222 WL_EXPORT   void
223 ico_ivi_set_send_surface_change(int (*send_surface_change)(struct weston_surface *surface,
224                                                            const int x, const int y,
225                                                            const int width,
226                                                            const int height))
227 {
228     _ico_ivi_common->send_surface_change = send_surface_change;
229 }
230
231 /*--------------------------------------------------------------------------*/
232 /**
233  * @brief   ico_ivi_send_surface_change: Send surface change event to manager
234  *
235  * @param[in]   surface         Weston surface
236  * @return      number of managers
237  * @retval      > 0             number of managers
238  * @retval      0               manager not exist
239  * @retval      -1              Multi Input Manager not exist
240  */
241 /*--------------------------------------------------------------------------*/
242 WL_EXPORT   int
243 ico_ivi_send_surface_change(struct weston_surface *surface,
244                             const int x, const int y, const int width, const int height)
245 {
246     if (_ico_ivi_common->send_surface_change)   {
247         return (*_ico_ivi_common->send_surface_change)(surface, x, y, width, height);
248     }
249     return -1;
250 }
251
252 /*--------------------------------------------------------------------------*/
253 /**
254  * @brief   ico_ivi_nodename_2_node: Convert node name to hostId
255  *
256  * @param[in]   nodename    Node name(same as host name)
257  * @return      HostId
258  * @retval      >= 0        HostId
259  */
260 /*--------------------------------------------------------------------------*/
261 WL_EXPORT int
262 ico_ivi_nodename_2_node(const char *nodename)
263 {
264     if (nodename == NULL)   {
265         uifw_trace("ico_ivi_nodename_2_node: NULL => %d",
266                    ICO_IVI_NODEID_2_HOSTID(_ico_ivi_common->myNodeId));
267         return ICO_IVI_NODEID_2_HOSTID(_ico_ivi_common->myNodeId);
268     }
269
270     /* Reference Platform 0.50 only support 1 ECU   */
271     uifw_trace("ico_ivi_nodename_2_node: %s => None", nodename );
272     return 0;
273 }
274
275 /*--------------------------------------------------------------------------*/
276 /**
277  * @brief   ico_ivi_dispname_2_node: Convert display name to nodeId
278  *
279  * @param[in]   dispname    Node name(same as display name)
280  * @return      NodeId
281  * @retval      >= 0        NodeId
282  */
283 /*--------------------------------------------------------------------------*/
284 WL_EXPORT int
285 ico_ivi_dispname_2_node(const char *dispname)
286 {
287     if (dispname == NULL)   {
288         uifw_trace("ico_ivi_dispname_2_node: NULL => %x", _ico_ivi_common->myNodeId);
289         return _ico_ivi_common->myNodeId;
290     }
291
292     /* Reference Platform 0.50 only support 1 ECU   */
293     uifw_trace("ico_ivi_dispname_2_node: %s => None", dispname);
294     return 0;
295 }
296
297 /*--------------------------------------------------------------------------*/
298 /**
299  * @brief   IVI Common: Initialize function of ico_ivi_common.
300  *
301  * @param[in]   ec          Weston compositor. (from Weston)
302  * @return      result
303  * @retval      0           Normal end
304  * @retval      -1          Error
305  */
306 /*--------------------------------------------------------------------------*/
307 WL_EXPORT int
308 module_init(struct weston_compositor *ec)
309 {
310     int     config_fd;
311
312     uifw_info("ico_ivi_common: Enter(module_init)");
313
314     /* Get debug level from config file         */
315     config_fd = open_config_file(ICO_IVI_PLUGIN_CONFIG);
316     parse_config_file(config_fd, conf_debug, ARRAY_LENGTH(conf_debug), NULL);
317     close(config_fd);
318     
319     uifw_info("ico_ivi_common: option flag=0x%08x debug=%d",
320               ico_option_flag(), ico_ivi_debuglevel());
321
322     /* Allocate static area                     */
323     _ico_ivi_common = (struct ico_ivi_common *) malloc(sizeof(struct ico_ivi_common));
324     if (! _ico_ivi_common)  {
325         uifw_error("ico_ivi_common: Leave(No Memory)");
326         return -1;
327     }
328     memset(_ico_ivi_common, 0, sizeof(struct ico_ivi_common));
329
330     uifw_info("ico_ivi_common: Leave(module_init)");
331
332     return 0;
333 }
334