[RCAR] disable a default config in kernel
[AGL/meta-agl.git] / meta-agl-profile-graphical / recipes-graphics / wayland / wayland-ivi-extension / 0002-ivi-id-agent-added-ivi-id-agent.patch
1 From 42fc715a430068cdb4484e2cb119418da8ac4e6f Mon Sep 17 00:00:00 2001
2 From: Michael Teyfel <mteyfel@de.adit-jv.com>
3 Date: Fri, 12 Oct 2018 16:46:57 +0200
4 Subject: [PATCH 2/3] ivi-id-agent: added ivi-id-agent
5
6 This is a reference implementation of an ivi-id-agent plugin. It
7 creates surface-ids for desktop-surfaces depending on the configuration
8 provided in "weston.ini". For more please refer to the reference
9 implementation in this commit.
10
11 The only public interface available is the "id_agent_module_init"
12 function. It is responsible for initialization of structs and reading
13 the configuration.
14
15 In the reference "weston.ini" two types of configurations can be found:
16
17 [desktop-app] is used to configure a particular application. Therefore
18 the desired surface-id must be provided. Moreover "app-title" is the
19 title that is provided by the desktop application (xdg-protocol).
20 "app-id" behaves accordingly. Although both parameters can be set, it
21 is not mandatory. Finally at least one has to be set.
22
23 [desktop-app-default] enables the id-agent to generate generic
24 surface-ids for unconfigured applications, e.g. for development. This
25 tag is optional. To generate the id an interval starting from
26 "default-surface-id" to "default-surface-id-max" is used. The id is
27 incremented until the interval is exceeded.
28
29 In the function "get_id" a surface-id is assigned by means of the
30 configuration. It can be adjusted, if another behavior is desired.
31 In this plugin the parameters, that are described above, are evaluated.
32
33 To use these patches please also apply the dedicated patches for
34 weston: https://github.com/mtey/weston/tree/xdg_support_ivi_id_agent
35 Since libweston-desktop is used to introduce desktop-surface support,
36 xdg-protocol is supported.
37
38 Reworked for wayland-ivi-extension 2.2.0 by Scott Murray.
39
40 Signed-off-by: Michael Teyfel <mteyfel@de.adit-jv.com>
41 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
42
43 diff --git a/ivi-id-agent-modules/ivi-id-agent/CMakeLists.txt b/ivi-id-agent-modules/ivi-id-agent/CMakeLists.txt
44 new file mode 100644
45 index 0000000..7354a7e
46 --- /dev/null
47 +++ b/ivi-id-agent-modules/ivi-id-agent/CMakeLists.txt
48 @@ -0,0 +1,69 @@
49 +###############################################################################
50 +#
51 +# Copyright (C) 2017 Advanced Driver Information Technology Joint Venture GmbH
52 +#
53 +#
54 +# Licensed under the Apache License, Version 2.0 (the "License");
55 +# you may not use this file except in compliance with the License.
56 +# You may obtain a copy of the License at
57 +#
58 +#      http://www.apache.org/licenses/LICENSE-2.0
59 +#
60 +# Unless required by applicable law or agreed to in writing, software
61 +# distributed under the License is distributed on an "AS IS" BASIS,
62 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63 +# See the License for the specific language governing permissions and
64 +# limitations under the License.
65 +#
66 +###############################################################################
67 +
68 +cmake_minimum_required (VERSION 2.6)
69 +
70 +project(ivi-id-agent)
71 +
72 +find_package(PkgConfig REQUIRED)
73 +pkg_check_modules(WAYLAND_SERVER wayland-server REQUIRED)
74 +pkg_check_modules(WESTON weston>=5.0.0 REQUIRED)
75 +pkg_check_modules(PIXMAN pixman-1 REQUIRED)
76 +pkg_check_modules(LIBWESTON_DESKTOP libweston-desktop-8 REQUIRED)
77 +
78 +find_package(Threads REQUIRED)
79 +
80 +include_directories(
81 +    src
82 +    ${WAYLAND_SERVER_INCLUDE_DIRS}
83 +    ${WESTON_INCLUDE_DIRS}
84 +    ${PIXMAN_INCLUDE_DIRS}
85 +)
86 +
87 +link_directories(
88 +    ${WAYLAND_SERVER_LIBRARY_DIRS}
89 +    ${PIXMAN_LIBRARY_DIRS}
90 +)
91 +
92 +
93 +add_library(${PROJECT_NAME} MODULE
94 +    src/ivi-id-agent.c
95 +)
96 +
97 +set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
98 +
99 +add_dependencies(${PROJECT_NAME}
100 +    ${WAYLAND_SERVER_LIBRARIES}
101 +    ${PIXMAN_LIBRARIES}
102 +)
103 +
104 +set(LIBS
105 +    ${LIBS}
106 +    ${WAYLAND_SERVER_LIBRARIES}
107 +    ${LIBWESTON_DESKTOP_LIBRARIES}
108 +)
109 +
110 +set(CMAKE_C_LDFLAGS "-module -avoid-version")
111 +
112 +target_link_libraries(${PROJECT_NAME} ${LIBS})
113 +
114 +install (
115 +    TARGETS             ${PROJECT_NAME}
116 +    LIBRARY DESTINATION lib${LIB_SUFFIX}/weston
117 +)
118 diff --git a/ivi-id-agent-modules/ivi-id-agent/src/ivi-id-agent.c b/ivi-id-agent-modules/ivi-id-agent/src/ivi-id-agent.c
119 new file mode 100644
120 index 0000000..9bc115d
121 --- /dev/null
122 +++ b/ivi-id-agent-modules/ivi-id-agent/src/ivi-id-agent.c
123 @@ -0,0 +1,381 @@
124 +/*
125 + * Copyright (C) 2017 Advanced Driver Information Technology Joint Venture GmbH
126 + *
127 + * Permission to use, copy, modify, distribute, and sell this software and
128 + * its documentation for any purpose is hereby granted without fee, provided
129 + * that the above copyright notice appear in all copies and that both that
130 + * copyright notice and this permission notice appear in supporting
131 + * documentation, and that the name of the copyright holders not be used in
132 + * advertising or publicity pertaining to distribution of the software
133 + * without specific, written prior permission.  The copyright holders make
134 + * no representations about the suitability of this software for any
135 + * purpose.  It is provided "as is" without express or implied warranty.
136 + *
137 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
138 + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
139 + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
140 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
141 + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
142 + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
143 + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
144 + */
145 +
146 +#include <stdlib.h>
147 +#include <stdio.h>
148 +#include <string.h>
149 +#include <limits.h>
150 +
151 +#include <weston.h>
152 +#include <libweston-desktop/libweston-desktop.h>
153 +#include "libweston/config-parser.h"
154 +#include <weston/ivi-layout-export.h>
155 +
156 +#ifndef INVALID_ID
157 +#define INVALID_ID 0xFFFFFFFF
158 +#endif
159 +
160 +struct db_elem
161 +{
162 +    struct wl_list link;
163 +    uint32_t surface_id;
164 +    char *cfg_app_id;
165 +    char *cfg_title;
166 +    struct ivi_layout_surface *layout_surface;
167 +};
168 +
169 +struct ivi_id_agent
170 +{
171 +    uint32_t default_behavior_set;
172 +    uint32_t default_surface_id;
173 +    uint32_t default_surface_id_max;
174 +    struct wl_list app_list;
175 +    struct weston_compositor *compositor;
176 +    const struct ivi_layout_interface *interface;
177 +
178 +    struct wl_listener desktop_surface_configured;
179 +    struct wl_listener destroy_listener;
180 +    struct wl_listener surface_removed;
181 +};
182 +
183 +static int32_t
184 +check_config_parameter(char *cfg_val, char *val)
185 +{
186 +    if (cfg_val == NULL)
187 +        return IVI_SUCCEEDED;
188 +    else if (val == NULL || strcmp(cfg_val, val) != 0)
189 +        return IVI_FAILED;
190 +
191 +    return IVI_SUCCEEDED;
192 +}
193 +
194 +static int32_t
195 +get_id_from_config(struct ivi_id_agent *ida, struct ivi_layout_surface
196 +        *layout_surface) {
197 +    struct db_elem *db_elem;
198 +    char *temp_app_id = NULL;
199 +    char *temp_title = NULL;
200 +    int ret = IVI_FAILED;
201 +
202 +    struct weston_surface *weston_surface =
203 +            ida->interface->surface_get_weston_surface(layout_surface);
204 +
205 +    /* Get app id and title */
206 +    struct weston_desktop_surface *wds = weston_surface_get_desktop_surface(
207 +            weston_surface);
208 +
209 +    if (weston_desktop_surface_get_app_id(wds) != NULL)
210 +        temp_app_id = strdup(weston_desktop_surface_get_app_id(wds));
211 +
212 +    if (weston_desktop_surface_get_title(wds) != NULL)
213 +        temp_title = strdup(weston_desktop_surface_get_title(wds));
214 +
215 +    /*
216 +     * Check for every config parameter to be fulfilled. This part must be
217 +     * extended, if additional attributes are desired to be checked.
218 +     */
219 +    wl_list_for_each(db_elem, &ida->app_list, link)
220 +    {
221 +        if (check_config_parameter(db_elem->cfg_app_id, temp_app_id) == 0) {
222 +            if (check_config_parameter(db_elem->cfg_title, temp_title) == 0) {
223 +                /* Found configuration for application. */
224 +                int res = ida->interface->surface_set_id(layout_surface,
225 +                        db_elem->surface_id);
226 +                if (res)
227 +                    continue;
228 +
229 +                db_elem->layout_surface = layout_surface;
230 +                ret = IVI_SUCCEEDED;
231 +
232 +                break;
233 +            }
234 +        }
235 +    }
236 +
237 +    free(temp_app_id);
238 +    free(temp_title);
239 +
240 +    return ret;
241 +}
242 +
243 +/*
244 + * This function generates the id of a surface in regard to the desired
245 + * parameters. For implementation of different behavior in id generation please
246 + * adjust this function.
247 + * In this implementation the app_id and/or title of the application is used for
248 + * identification. It is also possible to use the pid, uid or gid for example.
249 + */
250 +static int32_t
251 +get_id(struct ivi_id_agent *ida, struct ivi_layout_surface *layout_surface)
252 +{
253 +    if (get_id_from_config(ida, layout_surface) == IVI_SUCCEEDED)
254 +        return IVI_SUCCEEDED;
255 +
256 +    /* No default layer available */
257 +    if (ida->default_behavior_set == 0) {
258 +        weston_log("ivi-id-agent: Could not find configuration for application\n");
259 +        goto ivi_failed;
260 +
261 +    /* Default behavior for unknown applications */
262 +    } else if (ida->default_surface_id < ida->default_surface_id_max) {
263 +        weston_log("ivi-id-agent: No configuration for application adding to "
264 +                "default layer\n");
265 +
266 +        /*
267 +         * Check if ivi-shell application already created an application with
268 +         * desired surface_id
269 +         */
270 +        struct ivi_layout_surface *temp_layout_surf =
271 +                ida->interface->get_surface_from_id(
272 +                        ida->default_surface_id);
273 +        if ((temp_layout_surf != NULL) && (temp_layout_surf != layout_surface)) {
274 +            weston_log("ivi-id-agent: surface_id already used by an ivi-shell "
275 +                                "application\n");
276 +            goto ivi_failed;
277 +        }
278 +
279 +        ida->interface->surface_set_id(layout_surface,
280 +                                              ida->default_surface_id);
281 +        ida->default_surface_id++;
282 +
283 +    } else {
284 +        weston_log("ivi-id-agent: Interval for default surface_id generation "
285 +                "exceeded\n");
286 +        goto ivi_failed;
287 +    }
288 +
289 +    return IVI_SUCCEEDED;
290 +
291 +ivi_failed:
292 +    return IVI_FAILED;
293 +}
294 +
295 +static void
296 +desktop_surface_event_configure(struct wl_listener *listener,
297 +        void *data)
298 +{
299 +    struct ivi_id_agent *ida = wl_container_of(listener, ida,
300 +            desktop_surface_configured);
301 +
302 +    struct ivi_layout_surface *layout_surface =
303 +            (struct ivi_layout_surface *) data;
304 +
305 +    if (get_id(ida, layout_surface) == IVI_FAILED)
306 +        weston_log("ivi-id-agent: Could not create surface_id for application\n");
307 +}
308 +
309 +static void
310 +surface_event_remove(struct wl_listener *listener, void *data) {
311 +    struct ivi_id_agent *ida = wl_container_of(listener, ida,
312 +                surface_removed);
313 +    struct ivi_layout_surface *layout_surface =
314 +                (struct ivi_layout_surface *) data;
315 +    struct db_elem *db_elem = NULL;
316 +
317 +    wl_list_for_each(db_elem, &ida->app_list, link)
318 +    {
319 +        if(db_elem->layout_surface == layout_surface) {
320 +            db_elem->layout_surface = NULL;
321 +            break;
322 +        }
323 +    }
324 +}
325 +
326 +static int32_t deinit(struct ivi_id_agent *ida);
327 +
328 +static void
329 +id_agent_module_deinit(struct wl_listener *listener, void *data) {
330 +    (void)data;
331 +    struct ivi_id_agent *ida = wl_container_of(listener, ida, destroy_listener);
332 +
333 +    deinit(ida);
334 +}
335 +
336 +static int32_t
337 +check_config(struct db_elem *curr_db_elem, struct ivi_id_agent *ida)
338 +{
339 +    struct db_elem *db_elem;
340 +
341 +    if (ida->default_surface_id <= curr_db_elem->surface_id
342 +            && curr_db_elem->surface_id <= ida->default_surface_id_max) {
343 +        weston_log("ivi-id-agent: surface_id: %d in default id interval "
344 +                "[%d, %d] (CONFIG ERROR)\n", curr_db_elem->surface_id,
345 +                ida->default_surface_id, ida->default_surface_id_max);
346 +        goto ivi_failed;
347 +    }
348 +
349 +    wl_list_for_each(db_elem, &ida->app_list, link)
350 +    {
351 +        if(curr_db_elem == db_elem)
352 +            continue;
353 +
354 +        if (db_elem->surface_id == curr_db_elem->surface_id) {
355 +            weston_log("ivi-id-agent: Duplicate surface_id: %d (CONFIG ERROR)\n",
356 +                    curr_db_elem->surface_id);
357 +            goto ivi_failed;
358 +        }
359 +    }
360 +
361 +    return IVI_SUCCEEDED;
362 +
363 +ivi_failed:
364 +    return IVI_FAILED;
365 +}
366 +
367 +static int32_t
368 +read_config(struct ivi_id_agent *ida)
369 +{
370 +    struct weston_config *config = NULL;
371 +    struct weston_config_section *section = NULL;
372 +    const char *name = NULL;
373 +
374 +    config = wet_get_config(ida->compositor);
375 +    if (!config)
376 +        goto ivi_failed;
377 +
378 +    section = weston_config_get_section(config, "desktop-app-default", NULL,
379 +            NULL);
380 +
381 +    if (section) {
382 +        weston_log("ivi-id-agent: Default behavior for unknown applications is "
383 +                "set\n");
384 +        ida->default_behavior_set = 1;
385 +
386 +        weston_config_section_get_uint(section, "default-surface-id",
387 +                &ida->default_surface_id, INVALID_ID);
388 +        weston_config_section_get_uint(section, "default-surface-id-max",
389 +                &ida->default_surface_id_max, INVALID_ID);
390 +
391 +        if (ida->default_surface_id == INVALID_ID ||
392 +                ida->default_surface_id_max == INVALID_ID) {
393 +            weston_log("ivi-id-agent: Missing configuration for default "
394 +                    "behavior\n");
395 +            ida->default_behavior_set = 0;
396 +        }
397 +    } else {
398 +        ida->default_behavior_set = 0;
399 +    }
400 +
401 +    section = NULL;
402 +    while (weston_config_next_section(config, &section, &name)) {
403 +        struct db_elem *db_elem = NULL;
404 +
405 +        if (strcmp(name, "desktop-app") != 0)
406 +            continue;
407 +
408 +        db_elem = calloc(1, sizeof *db_elem);
409 +        if (db_elem == NULL) {
410 +            weston_log("ivi-id-agent: No memory to allocate\n");
411 +            goto ivi_failed;
412 +        }
413 +
414 +        wl_list_insert(&ida->app_list, &db_elem->link);
415 +
416 +        weston_config_section_get_uint(section, "surface-id",
417 +                         &db_elem->surface_id, INVALID_ID);
418 +
419 +        if (db_elem->surface_id == INVALID_ID) {
420 +            weston_log("ivi-id-agent: surface-id is not set in configuration\n");
421 +            goto ivi_failed;
422 +        }
423 +
424 +        weston_config_section_get_string(section, "app-id",
425 +                         &db_elem->cfg_app_id, NULL);
426 +        weston_config_section_get_string(section, "app-title",
427 +                         &db_elem->cfg_title, NULL);
428 +
429 +        if (db_elem->cfg_app_id == NULL && db_elem->cfg_title == NULL) {
430 +            weston_log("ivi-id-agent: Every parameter is NULL in app "
431 +                    "configuration\n");
432 +            goto ivi_failed;
433 +        }
434 +
435 +        if (check_config(db_elem, ida) == IVI_FAILED) {
436 +            weston_log("ivi-id-agent: No valid config found, deinit...\n");
437 +            goto ivi_failed;
438 +        }
439 +    }
440 +
441 +    if(ida->default_behavior_set == 0 && wl_list_empty(&ida->app_list)) {
442 +        weston_log("ivi-id-agent: No valid config found, deinit...\n");
443 +        goto ivi_failed;
444 +    }
445 +
446 +    return IVI_SUCCEEDED;
447 +
448 +ivi_failed:
449 +    return IVI_FAILED;
450 +}
451 +
452 +WL_EXPORT int32_t
453 +id_agent_module_init(struct weston_compositor *compositor,
454 +        const struct ivi_layout_interface *interface)
455 +{
456 +    struct ivi_id_agent *ida = NULL;
457 +
458 +    ida = calloc(1, sizeof *ida);
459 +    if (ida == NULL) {
460 +        weston_log("failed to allocate ivi_id_agent\n");
461 +        goto ivi_failed;
462 +    }
463 +
464 +    ida->compositor = compositor;
465 +    ida->interface = interface;
466 +    ida->desktop_surface_configured.notify = desktop_surface_event_configure;
467 +    ida->destroy_listener.notify = id_agent_module_deinit;
468 +    ida->surface_removed.notify = surface_event_remove;
469 +
470 +    wl_signal_add(&compositor->destroy_signal, &ida->destroy_listener);
471 +    ida->interface->add_listener_configure_desktop_surface(
472 +            &ida->desktop_surface_configured);
473 +    interface->add_listener_remove_surface(&ida->surface_removed);
474 +
475 +    wl_list_init(&ida->app_list);
476 +    if(read_config(ida) != 0) {
477 +        weston_log("ivi-id-agent: Read config failed\n");
478 +        deinit(ida);
479 +        goto ivi_failed;
480 +    }
481 +
482 +    return IVI_SUCCEEDED;
483 +
484 +ivi_failed:
485 +    return IVI_FAILED;
486 +}
487 +
488 +static int32_t
489 +deinit(struct ivi_id_agent *ida)
490 +{
491 +    struct db_elem *db_elem;
492 +    wl_list_for_each(db_elem, &ida->app_list, link) {
493 +        free(db_elem->cfg_app_id);
494 +        free(db_elem->cfg_title);
495 +        free(db_elem);
496 +    }
497 +
498 +    wl_list_remove(&ida->desktop_surface_configured.link);
499 +    wl_list_remove(&ida->destroy_listener.link);
500 +    wl_list_remove(&ida->surface_removed.link);
501 +    free(ida);
502 +
503 +    return IVI_SUCCEEDED;
504 +}
505 diff --git a/ivi-id-agent-modules/ivi-id-agent/weston.ini.in b/ivi-id-agent-modules/ivi-id-agent/weston.ini.in
506 new file mode 100644
507 index 0000000..48a196c
508 --- /dev/null
509 +++ b/ivi-id-agent-modules/ivi-id-agent/weston.ini.in
510 @@ -0,0 +1,20 @@
511 +[core]
512 +shell=ivi-shell.so
513 +require-input=false
514 +
515 +[ivi-shell]
516 +ivi-module=ivi-controller.so
517 +ivi-input-module=ivi-input-controller.so
518 +ivi-id-agent-module=ivi-id-agent.so
519 +
520 +[desktop-app]
521 +surface-id=111
522 +app-title=Flower
523 +
524 +[desktop-app]
525 +surface-id=251
526 +app-title=Flower
527 +
528 +[desktop-app-default]
529 +default-surface-id=2000000
530 +default-surface-id-max=2001000