compositor: Use stdint for specifing integer storage
[src/agl-compositor.git] / src / policy-default.c
1 /*
2  * Copyright © 2020 Collabora, Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25
26 #include "ivi-compositor.h"
27 #include "policy.h"
28
29 #include <string.h>
30
31 /*
32  * default policy implementation allows every action to be possible
33  *
34  * This is an example, that implements the API
35  *
36  * For injecting rules back in the compositor one should use ivi_policy_add()
37  * - policy_rule_allow_to_add is required in order to add further policy rules
38  * - policy_rule_try_event will be callback executed when handling the state
39  *   change
40  */
41 static bool
42 ivi_policy_default_surface_create(struct ivi_surface *surf, void *user_data)
43 {
44         /* verify that the surface should be created */
45         return true;
46 }
47
48 static bool
49 ivi_policy_default_surface_commmited(struct ivi_surface *surf, void *user_data)
50 {
51         /* verify that the surface should be committed */
52         return true;
53 }
54
55 static bool
56 ivi_policy_default_surface_activate(struct ivi_surface *surf, void *user_data)
57 {
58         /* verify that the surface should be switched to */
59         return true;
60 }
61
62 static bool
63 ivi_policy_default_surface_deactivate(struct ivi_surface *surf, void *user_data)
64 {
65         /* verify that the surface should be de-activated to */
66         return true;
67 }
68
69 static bool
70 ivi_policy_default_surface_activate_default(struct ivi_surface *surf, void *user_data)
71 {
72         /* verify that the surface should be switched to */
73         return true;
74 }
75
76 static bool
77 ivi_policy_default_surface_advertise_state_change(struct ivi_surface *surf, void *user_data)
78 {
79         /* verify that the surface should sent as notification */
80         return true;
81 }
82
83 /* we allow all applications to bind to private extensions. See the deny-all
84  * policy instead for how to retrieve the clients fd and its label to check
85  * against */
86 static bool
87 ivi_policy_default_shell_bind_interface(void *client, void *interface)
88 {
89         return true;
90 }
91
92 static bool
93 ivi_policy_default_allow_to_add(void *user_data)
94 {
95         /* verify that policy rules can be added with ivi_policy_add() */
96         return true;
97 }
98
99 /*
100  * Policy rules added by ivi_policy_add() will be handled by this callback, and
101  * should be treated depending on the event. Note this is just an example.
102  */
103 static void
104 ivi_policy_default_try_event(struct ivi_a_policy *a_policy)
105 {
106         uint32_t event = a_policy->event;
107
108         switch (event) {
109         case AGL_SHELL_POLICY_EVENT_SHOW:
110                 ivi_layout_activate(a_policy->output, a_policy->app_id);
111                 break;
112         case AGL_SHELL_POLICY_EVENT_HIDE:
113                 ivi_layout_deactivate(a_policy->policy->ivi, a_policy->app_id);
114         default:
115                 break;
116         }
117 }
118
119 static const struct ivi_policy_api policy_api = {
120         .struct_size = sizeof(policy_api),
121         .surface_create = ivi_policy_default_surface_create,
122         .surface_commited = ivi_policy_default_surface_commmited,
123         .surface_activate = ivi_policy_default_surface_activate,
124         .surface_deactivate = ivi_policy_default_surface_deactivate,
125         .surface_activate_by_default = ivi_policy_default_surface_activate_default,
126         .surface_advertise_state_change = ivi_policy_default_surface_advertise_state_change,
127         .shell_bind_interface = ivi_policy_default_shell_bind_interface,
128         .policy_rule_allow_to_add = ivi_policy_default_allow_to_add,
129         .policy_rule_try_event = ivi_policy_default_try_event,
130 };
131
132 int
133 ivi_policy_init(struct ivi_compositor *ivi)
134 {
135         ivi->policy = ivi_policy_create(ivi, &policy_api, ivi);
136         if (!ivi->policy)
137                 return -1;
138
139         weston_log("Installing 'allow-all' policy engine\n");
140         return 0;
141 }