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
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.
11 The only public interface available is the "id_agent_module_init"
12 function. It is responsible for initialization of structs and reading
15 In the reference "weston.ini" two types of configurations can be found:
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.
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.
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.
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.
38 Reworked for wayland-ivi-extension 2.2.0 by Scott Murray.
40 Signed-off-by: Michael Teyfel <mteyfel@de.adit-jv.com>
41 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
43 diff --git a/ivi-id-agent-modules/ivi-id-agent/CMakeLists.txt b/ivi-id-agent-modules/ivi-id-agent/CMakeLists.txt
45 index 0000000..7354a7e
47 +++ b/ivi-id-agent-modules/ivi-id-agent/CMakeLists.txt
49 +###############################################################################
51 +# Copyright (C) 2017 Advanced Driver Information Technology Joint Venture GmbH
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
58 +# http://www.apache.org/licenses/LICENSE-2.0
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.
66 +###############################################################################
68 +cmake_minimum_required (VERSION 2.6)
70 +project(ivi-id-agent)
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)
78 +find_package(Threads REQUIRED)
82 + ${WAYLAND_SERVER_INCLUDE_DIRS}
83 + ${WESTON_INCLUDE_DIRS}
84 + ${PIXMAN_INCLUDE_DIRS}
88 + ${WAYLAND_SERVER_LIBRARY_DIRS}
89 + ${PIXMAN_LIBRARY_DIRS}
93 +add_library(${PROJECT_NAME} MODULE
97 +set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
99 +add_dependencies(${PROJECT_NAME}
100 + ${WAYLAND_SERVER_LIBRARIES}
101 + ${PIXMAN_LIBRARIES}
106 + ${WAYLAND_SERVER_LIBRARIES}
107 + ${LIBWESTON_DESKTOP_LIBRARIES}
110 +set(CMAKE_C_LDFLAGS "-module -avoid-version")
112 +target_link_libraries(${PROJECT_NAME} ${LIBS})
115 + TARGETS ${PROJECT_NAME}
116 + LIBRARY DESTINATION lib${LIB_SUFFIX}/weston
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
120 index 0000000..9bc115d
122 +++ b/ivi-id-agent-modules/ivi-id-agent/src/ivi-id-agent.c
125 + * Copyright (C) 2017 Advanced Driver Information Technology Joint Venture GmbH
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.
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.
152 +#include <libweston-desktop/libweston-desktop.h>
153 +#include "libweston/config-parser.h"
154 +#include <weston/ivi-layout-export.h>
157 +#define INVALID_ID 0xFFFFFFFF
162 + struct wl_list link;
163 + uint32_t surface_id;
166 + struct ivi_layout_surface *layout_surface;
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;
178 + struct wl_listener desktop_surface_configured;
179 + struct wl_listener destroy_listener;
180 + struct wl_listener surface_removed;
184 +check_config_parameter(char *cfg_val, char *val)
186 + if (cfg_val == NULL)
187 + return IVI_SUCCEEDED;
188 + else if (val == NULL || strcmp(cfg_val, val) != 0)
191 + return IVI_SUCCEEDED;
195 +get_id_from_config(struct ivi_id_agent *ida, struct ivi_layout_surface
197 + struct db_elem *db_elem;
198 + char *temp_app_id = NULL;
199 + char *temp_title = NULL;
200 + int ret = IVI_FAILED;
202 + struct weston_surface *weston_surface =
203 + ida->interface->surface_get_weston_surface(layout_surface);
205 + /* Get app id and title */
206 + struct weston_desktop_surface *wds = weston_surface_get_desktop_surface(
209 + if (weston_desktop_surface_get_app_id(wds) != NULL)
210 + temp_app_id = strdup(weston_desktop_surface_get_app_id(wds));
212 + if (weston_desktop_surface_get_title(wds) != NULL)
213 + temp_title = strdup(weston_desktop_surface_get_title(wds));
216 + * Check for every config parameter to be fulfilled. This part must be
217 + * extended, if additional attributes are desired to be checked.
219 + wl_list_for_each(db_elem, &ida->app_list, link)
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);
229 + db_elem->layout_surface = layout_surface;
230 + ret = IVI_SUCCEEDED;
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.
251 +get_id(struct ivi_id_agent *ida, struct ivi_layout_surface *layout_surface)
253 + if (get_id_from_config(ida, layout_surface) == IVI_SUCCEEDED)
254 + return IVI_SUCCEEDED;
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");
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");
267 + * Check if ivi-shell application already created an application with
268 + * desired surface_id
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 "
279 + ida->interface->surface_set_id(layout_surface,
280 + ida->default_surface_id);
281 + ida->default_surface_id++;
284 + weston_log("ivi-id-agent: Interval for default surface_id generation "
289 + return IVI_SUCCEEDED;
296 +desktop_surface_event_configure(struct wl_listener *listener,
299 + struct ivi_id_agent *ida = wl_container_of(listener, ida,
300 + desktop_surface_configured);
302 + struct ivi_layout_surface *layout_surface =
303 + (struct ivi_layout_surface *) data;
305 + if (get_id(ida, layout_surface) == IVI_FAILED)
306 + weston_log("ivi-id-agent: Could not create surface_id for application\n");
310 +surface_event_remove(struct wl_listener *listener, void *data) {
311 + struct ivi_id_agent *ida = wl_container_of(listener, ida,
313 + struct ivi_layout_surface *layout_surface =
314 + (struct ivi_layout_surface *) data;
315 + struct db_elem *db_elem = NULL;
317 + wl_list_for_each(db_elem, &ida->app_list, link)
319 + if(db_elem->layout_surface == layout_surface) {
320 + db_elem->layout_surface = NULL;
326 +static int32_t deinit(struct ivi_id_agent *ida);
329 +id_agent_module_deinit(struct wl_listener *listener, void *data) {
331 + struct ivi_id_agent *ida = wl_container_of(listener, ida, destroy_listener);
337 +check_config(struct db_elem *curr_db_elem, struct ivi_id_agent *ida)
339 + struct db_elem *db_elem;
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);
349 + wl_list_for_each(db_elem, &ida->app_list, link)
351 + if(curr_db_elem == db_elem)
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);
361 + return IVI_SUCCEEDED;
368 +read_config(struct ivi_id_agent *ida)
370 + struct weston_config *config = NULL;
371 + struct weston_config_section *section = NULL;
372 + const char *name = NULL;
374 + config = wet_get_config(ida->compositor);
378 + section = weston_config_get_section(config, "desktop-app-default", NULL,
382 + weston_log("ivi-id-agent: Default behavior for unknown applications is "
384 + ida->default_behavior_set = 1;
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);
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 "
395 + ida->default_behavior_set = 0;
398 + ida->default_behavior_set = 0;
402 + while (weston_config_next_section(config, §ion, &name)) {
403 + struct db_elem *db_elem = NULL;
405 + if (strcmp(name, "desktop-app") != 0)
408 + db_elem = calloc(1, sizeof *db_elem);
409 + if (db_elem == NULL) {
410 + weston_log("ivi-id-agent: No memory to allocate\n");
414 + wl_list_insert(&ida->app_list, &db_elem->link);
416 + weston_config_section_get_uint(section, "surface-id",
417 + &db_elem->surface_id, INVALID_ID);
419 + if (db_elem->surface_id == INVALID_ID) {
420 + weston_log("ivi-id-agent: surface-id is not set in configuration\n");
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);
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");
435 + if (check_config(db_elem, ida) == IVI_FAILED) {
436 + weston_log("ivi-id-agent: No valid config found, deinit...\n");
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");
446 + return IVI_SUCCEEDED;
453 +id_agent_module_init(struct weston_compositor *compositor,
454 + const struct ivi_layout_interface *interface)
456 + struct ivi_id_agent *ida = NULL;
458 + ida = calloc(1, sizeof *ida);
460 + weston_log("failed to allocate ivi_id_agent\n");
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;
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);
475 + wl_list_init(&ida->app_list);
476 + if(read_config(ida) != 0) {
477 + weston_log("ivi-id-agent: Read config failed\n");
482 + return IVI_SUCCEEDED;
489 +deinit(struct ivi_id_agent *ida)
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);
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);
503 + return IVI_SUCCEEDED;
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
507 index 0000000..48a196c
509 +++ b/ivi-id-agent-modules/ivi-id-agent/weston.ini.in
516 +ivi-module=ivi-controller.so
517 +ivi-input-module=ivi-input-controller.so
518 +ivi-id-agent-module=ivi-id-agent.so
528 +[desktop-app-default]
529 +default-surface-id=2000000
530 +default-surface-id-max=2001000