aboutsummaryrefslogtreecommitdiffstats
path: root/meta-agl-profile-graphical/recipes-graphics/wayland/wayland-ivi-extension/0002-ivi-id-agent-added-ivi-id-agent.patch
blob: 0fe2abb35d6eb7611bab88e808ab1e2c5d5a0ed5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
From 42fc715a430068cdb4484e2cb119418da8ac4e6f Mon Sep 17 00:00:00 2001
From: Michael Teyfel <mteyfel@de.adit-jv.com>
Date: Fri, 12 Oct 2018 16:46:57 +0200
Subject: [PATCH 2/3] ivi-id-agent: added ivi-id-agent

This is a reference implementation of an ivi-id-agent plugin. It
creates surface-ids for desktop-surfaces depending on the configuration
provided in "weston.ini". For more please refer to the reference
implementation in this commit.

The only public interface available is the "id_agent_module_init"
function. It is responsible for initialization of structs and reading
the configuration.

In the reference "weston.ini" two types of configurations can be found:

[desktop-app] is used to configure a particular application. Therefore
the desired surface-id must be provided. Moreover "app-title" is the
title that is provided by the desktop application (xdg-protocol).
"app-id" behaves accordingly. Although both parameters can be set, it
is not mandatory. Finally at least one has to be set.

[desktop-app-default] enables the id-agent to generate generic
surface-ids for unconfigured applications, e.g. for development. This
tag is optional. To generate the id an interval starting from
"default-surface-id" to "default-surface-id-max" is used. The id is
incremented until the interval is exceeded.

In the function "get_id" a surface-id is assigned by means of the
configuration. It can be adjusted, if another behavior is desired.
In this plugin the parameters, that are described above, are evaluated.

To use these patches please also apply the dedicated patches for
weston: https://github.com/mtey/weston/tree/xdg_support_ivi_id_agent
Since libweston-desktop is used to introduce desktop-surface support,
xdg-protocol is supported.

Reworked for wayland-ivi-extension 2.2.0 by Scott Murray.

Signed-off-by: Michael Teyfel <mteyfel@de.adit-jv.com>
Signed-off-by: Scott Murray <scott.murray@konsulko.com>

diff --git a/ivi-id-agent-modules/ivi-id-agent/CMakeLists.txt b/ivi-id-agent-modules/ivi-id-agent/CMakeLists.txt
new file mode 100644
index 0000000..7354a7e
--- /dev/null
+++ b/ivi-id-agent-modules/ivi-id-agent/CMakeLists.txt
@@ -0,0 +1,69 @@
+###############################################################################
+#
+# Copyright (C) 2017 Advanced Driver Information Technology Joint Venture GmbH
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+###############################################################################
+
+cmake_minimum_required (VERSION 2.6)
+
+project(ivi-id-agent)
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(WAYLAND_SERVER wayland-server REQUIRED)
+pkg_check_modules(WESTON weston>=5.0.0 REQUIRED)
+pkg_check_modules(PIXMAN pixman-1 REQUIRED)
+pkg_check_modules(LIBWESTON_DESKTOP libweston-desktop-8 REQUIRED)
+
+find_package(Threads REQUIRED)
+
+include_directories(
+    src
+    ${WAYLAND_SERVER_INCLUDE_DIRS}
+    ${WESTON_INCLUDE_DIRS}
+    ${PIXMAN_INCLUDE_DIRS}
+)
+
+link_directories(
+    ${WAYLAND_SERVER_LIBRARY_DIRS}
+    ${PIXMAN_LIBRARY_DIRS}
+)
+
+
+add_library(${PROJECT_NAME} MODULE
+    src/ivi-id-agent.c
+)
+
+set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
+
+add_dependencies(${PROJECT_NAME}
+    ${WAYLAND_SERVER_LIBRARIES}
+    ${PIXMAN_LIBRARIES}
+)
+
+set(LIBS
+    ${LIBS}
+    ${WAYLAND_SERVER_LIBRARIES}
+    ${LIBWESTON_DESKTOP_LIBRARIES}
+)
+
+set(CMAKE_C_LDFLAGS "-module -avoid-version")
+
+target_link_libraries(${PROJECT_NAME} ${LIBS})
+
+install (
+    TARGETS             ${PROJECT_NAME}
+    LIBRARY DESTINATION lib${LIB_SUFFIX}/weston
+)
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
new file mode 100644
index 0000000..9bc115d
--- /dev/null
+++ b/ivi-id-agent-modules/ivi-id-agent/src/ivi-id-agent.c
@@ -0,0 +1,381 @@
+/*
+ * Copyright (C) 2017 Advanced Driver Information Technology Joint Venture GmbH
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+
+#include <weston.h>
+#include <libweston-desktop/libweston-desktop.h>
+#include "libweston/config-parser.h"
+#include <weston/ivi-layout-export.h>
+
+#ifndef INVALID_ID
+#define INVALID_ID 0xFFFFFFFF
+#endif
+
+struct db_elem
+{
+    struct wl_list link;
+    uint32_t surface_id;
+    char *cfg_app_id;
+    char *cfg_title;
+    struct ivi_layout_surface *layout_surface;
+};
+
+struct ivi_id_agent
+{
+    uint32_t default_behavior_set;
+    uint32_t default_surface_id;
+    uint32_t default_surface_id_max;
+    struct wl_list app_list;
+    struct weston_compositor *compositor;
+    const struct ivi_layout_interface *interface;
+
+    struct wl_listener desktop_surface_configured;
+    struct wl_listener destroy_listener;
+    struct wl_listener surface_removed;
+};
+
+static int32_t
+check_config_parameter(char *cfg_val, char *val)
+{
+    if (cfg_val == NULL)
+        return IVI_SUCCEEDED;
+    else if (val == NULL || strcmp(cfg_val, val) != 0)
+        return IVI_FAILED;
+
+    return IVI_SUCCEEDED;
+}
+
+static int32_t
+get_id_from_config(struct ivi_id_agent *ida, struct ivi_layout_surface
+        *layout_surface) {
+    struct db_elem *db_elem;
+    char *temp_app_id = NULL;
+    char *temp_title = NULL;
+    int ret = IVI_FAILED;
+
+    struct weston_surface *weston_surface =
+            ida->interface->surface_get_weston_surface(layout_surface);
+
+    /* Get app id and title */
+    struct weston_desktop_surface *wds = weston_surface_get_desktop_surface(
+            weston_surface);
+
+    if (weston_desktop_surface_get_app_id(wds) != NULL)
+        temp_app_id = strdup(weston_desktop_surface_get_app_id(wds));
+
+    if (weston_desktop_surface_get_title(wds) != NULL)
+        temp_title = strdup(weston_desktop_surface_get_title(wds));
+
+    /*
+     * Check for every config parameter to be fulfilled. This part must be
+     * extended, if additional attributes are desired to be checked.
+     */
+    wl_list_for_each(db_elem, &ida->app_list, link)
+    {
+        if (check_config_parameter(db_elem->cfg_app_id, temp_app_id) == 0) {
+            if (check_config_parameter(db_elem->cfg_title, temp_title) == 0) {
+                /* Found configuration for application. */
+                int res = ida->interface->surface_set_id(layout_surface,
+                        db_elem->surface_id);
+                if (res)
+                    continue;
+
+                db_elem->layout_surface = layout_surface;
+                ret = IVI_SUCCEEDED;
+
+                break;
+            }
+        }
+    }
+
+    free(temp_app_id);
+    free(temp_title);
+
+    return ret;
+}
+
+/*
+ * This function generates the id of a surface in regard to the desired
+ * parameters. For implementation of different behavior in id generation please
+ * adjust this function.
+ * In this implementation the app_id and/or title of the application is used for
+ * identification. It is also possible to use the pid, uid or gid for example.
+ */
+static int32_t
+get_id(struct ivi_id_agent *ida, struct ivi_layout_surface *layout_surface)
+{
+    if (get_id_from_config(ida, layout_surface) == IVI_SUCCEEDED)
+        return IVI_SUCCEEDED;
+
+    /* No default layer available */
+    if (ida->default_behavior_set == 0) {
+        weston_log("ivi-id-agent: Could not find configuration for application\n");
+        goto ivi_failed;
+
+    /* Default behavior for unknown applications */
+    } else if (ida->default_surface_id < ida->default_surface_id_max) {
+        weston_log("ivi-id-agent: No configuration for application adding to "
+                "default layer\n");
+
+        /*
+         * Check if ivi-shell application already created an application with
+         * desired surface_id
+         */
+        struct ivi_layout_surface *temp_layout_surf =
+                ida->interface->get_surface_from_id(
+                        ida->default_surface_id);
+        if ((temp_layout_surf != NULL) && (temp_layout_surf != layout_surface)) {
+            weston_log("ivi-id-agent: surface_id already used by an ivi-shell "
+                                "application\n");
+            goto ivi_failed;
+        }
+
+        ida->interface->surface_set_id(layout_surface,
+                                              ida->default_surface_id);
+        ida->default_surface_id++;
+
+    } else {
+        weston_log("ivi-id-agent: Interval for default surface_id generation "
+                "exceeded\n");
+        goto ivi_failed;
+    }
+
+    return IVI_SUCCEEDED;
+
+ivi_failed:
+    return IVI_FAILED;
+}
+
+static void
+desktop_surface_event_configure(struct wl_listener *listener,
+        void *data)
+{
+    struct ivi_id_agent *ida = wl_container_of(listener, ida,
+            desktop_surface_configured);
+
+    struct ivi_layout_surface *layout_surface =
+            (struct ivi_layout_surface *) data;
+
+    if (get_id(ida, layout_surface) == IVI_FAILED)
+        weston_log("ivi-id-agent: Could not create surface_id for application\n");
+}
+
+static void
+surface_event_remove(struct wl_listener *listener, void *data) {
+    struct ivi_id_agent *ida = wl_container_of(listener, ida,
+                surface_removed);
+    struct ivi_layout_surface *layout_surface =
+                (struct ivi_layout_surface *) data;
+    struct db_elem *db_elem = NULL;
+
+    wl_list_for_each(db_elem, &ida->app_list, link)
+    {
+        if(db_elem->layout_surface == layout_surface) {
+            db_elem->layout_surface = NULL;
+            break;
+        }
+    }
+}
+
+static int32_t deinit(struct ivi_id_agent *ida);
+
+static void
+id_agent_module_deinit(struct wl_listener *listener, void *data) {
+    (void)data;
+    struct ivi_id_agent *ida = wl_container_of(listener, ida, destroy_listener);
+
+    deinit(ida);
+}
+
+static int32_t
+check_config(struct db_elem *curr_db_elem, struct ivi_id_agent *ida)
+{
+    struct db_elem *db_elem;
+
+    if (ida->default_surface_id <= curr_db_elem->surface_id
+            && curr_db_elem->surface_id <= ida->default_surface_id_max) {
+        weston_log("ivi-id-agent: surface_id: %d in default id interval "
+                "[%d, %d] (CONFIG ERROR)\n", curr_db_elem->surface_id,
+                ida->default_surface_id, ida->default_surface_id_max);
+        goto ivi_failed;
+    }
+
+    wl_list_for_each(db_elem, &ida->app_list, link)
+    {
+        if(curr_db_elem == db_elem)
+            continue;
+
+        if (db_elem->surface_id == curr_db_elem->surface_id) {
+            weston_log("ivi-id-agent: Duplicate surface_id: %d (CONFIG ERROR)\n",
+                    curr_db_elem->surface_id);
+            goto ivi_failed;
+        }
+    }
+
+    return IVI_SUCCEEDED;
+
+ivi_failed:
+    return IVI_FAILED;
+}
+
+static int32_t
+read_config(struct ivi_id_agent *ida)
+{
+    struct weston_config *config = NULL;
+    struct weston_config_section *section = NULL;
+    const char *name = NULL;
+
+    config = wet_get_config(ida->compositor);
+    if (!config)
+        goto ivi_failed;
+
+    section = weston_config_get_section(config, "desktop-app-default", NULL,
+            NULL);
+
+    if (section) {
+        weston_log("ivi-id-agent: Default behavior for unknown applications is "
+                "set\n");
+        ida->default_behavior_set = 1;
+
+        weston_config_section_get_uint(section, "default-surface-id",
+                &ida->default_surface_id, INVALID_ID);
+        weston_config_section_get_uint(section, "default-surface-id-max",
+                &ida->default_surface_id_max, INVALID_ID);
+
+        if (ida->default_surface_id == INVALID_ID ||
+                ida->default_surface_id_max == INVALID_ID) {
+            weston_log("ivi-id-agent: Missing configuration for default "
+                    "behavior\n");
+            ida->default_behavior_set = 0;
+        }
+    } else {
+        ida->default_behavior_set = 0;
+    }
+
+    section = NULL;
+    while (weston_config_next_section(config, &section, &name)) {
+        struct db_elem *db_elem = NULL;
+
+        if (strcmp(name, "desktop-app") != 0)
+            continue;
+
+        db_elem = calloc(1, sizeof *db_elem);
+        if (db_elem == NULL) {
+            weston_log("ivi-id-agent: No memory to allocate\n");
+            goto ivi_failed;
+        }
+
+        wl_list_insert(&ida->app_list, &db_elem->link);
+
+        weston_config_section_get_uint(section, "surface-id",
+                         &db_elem->surface_id, INVALID_ID);
+
+        if (db_elem->surface_id == INVALID_ID) {
+            weston_log("ivi-id-agent: surface-id is not set in configuration\n");
+            goto ivi_failed;
+        }
+
+        weston_config_section_get_string(section, "app-id",
+                         &db_elem->cfg_app_id, NULL);
+        weston_config_section_get_string(section, "app-title",
+                         &db_elem->cfg_title, NULL);
+
+        if (db_elem->cfg_app_id == NULL && db_elem->cfg_title == NULL) {
+            weston_log("ivi-id-agent: Every parameter is NULL in app "
+                    "configuration\n");
+            goto ivi_failed;
+        }
+
+        if (check_config(db_elem, ida) == IVI_FAILED) {
+            weston_log("ivi-id-agent: No valid config found, deinit...\n");
+            goto ivi_failed;
+        }
+    }
+
+    if(ida->default_behavior_set == 0 && wl_list_empty(&ida->app_list)) {
+        weston_log("ivi-id-agent: No valid config found, deinit...\n");
+        goto ivi_failed;
+    }
+
+    return IVI_SUCCEEDED;
+
+ivi_failed:
+    return IVI_FAILED;
+}
+
+WL_EXPORT int32_t
+id_agent_module_init(struct weston_compositor *compositor,
+        const struct ivi_layout_interface *interface)
+{
+    struct ivi_id_agent *ida = NULL;
+
+    ida = calloc(1, sizeof *ida);
+    if (ida == NULL) {
+        weston_log("failed to allocate ivi_id_agent\n");
+        goto ivi_failed;
+    }
+
+    ida->compositor = compositor;
+    ida->interface = interface;
+    ida->desktop_surface_configured.notify = desktop_surface_event_configure;
+    ida->destroy_listener.notify = id_agent_module_deinit;
+    ida->surface_removed.notify = surface_event_remove;
+
+    wl_signal_add(&compositor->destroy_signal, &ida->destroy_listener);
+    ida->interface->add_listener_configure_desktop_surface(
+            &ida->desktop_surface_configured);
+    interface->add_listener_remove_surface(&ida->surface_removed);
+
+    wl_list_init(&ida->app_list);
+    if(read_config(ida) != 0) {
+        weston_log("ivi-id-agent: Read config failed\n");
+        deinit(ida);
+        goto ivi_failed;
+    }
+
+    return IVI_SUCCEEDED;
+
+ivi_failed:
+    return IVI_FAILED;
+}
+
+static int32_t
+deinit(struct ivi_id_agent *ida)
+{
+    struct db_elem *db_elem;
+    wl_list_for_each(db_elem, &ida->app_list, link) {
+        free(db_elem->cfg_app_id);
+        free(db_elem->cfg_title);
+        free(db_elem);
+    }
+
+    wl_list_remove(&ida->desktop_surface_configured.link);
+    wl_list_remove(&ida->destroy_listener.link);
+    wl_list_remove(&ida->surface_removed.link);
+    free(ida);
+
+    return IVI_SUCCEEDED;
+}
diff --git a/ivi-id-agent-modules/ivi-id-agent/weston.ini.in b/ivi-id-agent-modules/ivi-id-agent/weston.ini.in
new file mode 100644
index 0000000..48a196c
--- /dev/null
+++ b/ivi-id-agent-modules/ivi-id-agent/weston.ini.in
@@ -0,0 +1,20 @@
+[core]
+shell=ivi-shell.so
+require-input=false
+
+[ivi-shell]
+ivi-module=ivi-controller.so
+ivi-input-module=ivi-input-controller.so
+ivi-id-agent-module=ivi-id-agent.so
+
+[desktop-app]
+surface-id=111
+app-title=Flower
+
+[desktop-app]
+surface-id=251
+app-title=Flower
+
+[desktop-app-default]
+default-surface-id=2000000
+default-surface-id-max=2001000