compositor: Use stdint for specifing integer storage
[src/agl-compositor.git] / src / policy-rba.c
1 /*
2  * Copyright © 2020 Collabora, Ltd.
3  * Copyright (c) 2020 DENSO CORPORATION.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial
15  * portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26
27 #include "ivi-compositor.h"
28 #include "policy.h"
29 #include "rba_adapter.h"
30
31 #include <string.h>
32
33 static bool
34 ivi_policy_rba_surface_create(struct ivi_surface *surf, void *user_data)
35 {
36         return true;
37 }
38
39 static bool
40 ivi_policy_rba_surface_commmited(struct ivi_surface *surf, void *user_data)
41 {
42         return true;
43 }
44
45 static bool
46 ivi_policy_rba_surface_activate(struct ivi_surface *surf, void *user_data)
47 {
48         const char *app_id = NULL;
49         app_id = weston_desktop_surface_get_app_id(surf->dsurface);
50         if (app_id == NULL) {
51                 weston_log("app_id is NULL, surface activation failed.\n");
52                 return false;
53         }
54         return rba_adapter_arbitrate(app_id,surf->ivi);
55 }
56
57 static bool
58 ivi_policy_rba_surface_deactivate(struct ivi_surface *surf, void *user_data)
59 {
60         return true;
61 }
62
63 static bool
64 ivi_policy_rba_surface_activate_default(struct ivi_surface *surf, void *user_data)
65 {
66         return true;
67 }
68
69 static bool
70 ivi_policy_rba_surface_advertise_state_change(struct ivi_surface *surf, void *user_data)
71 {
72         return true;
73 }
74
75 static bool
76 ivi_policy_rba_shell_bind_interface(void *client, void *interface)
77 {
78         return rba_adapter_initialize();
79 }
80
81 static const struct ivi_policy_api policy_api = {
82         .struct_size = sizeof(policy_api),
83         .surface_create = ivi_policy_rba_surface_create,
84         .surface_commited = ivi_policy_rba_surface_commmited,
85         .surface_activate = ivi_policy_rba_surface_activate,
86         .surface_deactivate = ivi_policy_rba_surface_deactivate,
87         .surface_activate_by_default = ivi_policy_rba_surface_activate_default,
88         .surface_advertise_state_change = ivi_policy_rba_surface_advertise_state_change,
89         .shell_bind_interface = ivi_policy_rba_shell_bind_interface,
90         .policy_rule_allow_to_add = NULL,
91         .policy_rule_try_event = NULL,
92 };
93
94 int
95 ivi_policy_init(struct ivi_compositor *ivi)
96 {
97         ivi->policy = ivi_policy_create(ivi, &policy_api, ivi);
98         if (!ivi->policy)
99                 return -1;
100
101         weston_log("Installing 'rba(Rule Base Arbitration)' policy engine\n");
102         return 0;
103 }