policy-default: Install the default policy
authorMarius Vlad <marius.vlad@collabora.com>
Tue, 3 Mar 2020 12:49:35 +0000 (14:49 +0200)
committerMarius Vlad <marius.vlad@collabora.com>
Wed, 4 Mar 2020 11:19:09 +0000 (13:19 +0200)
This is just an example on how to use the policy frame work.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: I83c9e61a2f2a89c373352232009cea4c6f6a3ad6

meson.build
src/main.c
src/policy-default.c [new file with mode: 0644]

index 4d89c73..04ddaff 100644 (file)
@@ -123,6 +123,7 @@ srcs_agl_compositor = [
        'src/desktop.c',
        'src/layout.c',
        'src/policy.c',
+       'src/policy-default.c',
        'src/shell.c',
        'shared/option-parser.c',
        'shared/os-compatibility.c',
index f715280..2b12a7b 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 #include "ivi-compositor.h"
+#include "policy.h"
 
 #include <assert.h>
 #include <errno.h>
@@ -1228,6 +1229,9 @@ int main(int argc, char *argv[])
        if (ivi_desktop_init(&ivi) < 0)
                goto error_compositor;
 
+       if (ivi_policy_init(&ivi) < 0)
+               goto error_compositor;
+
        if (ivi_shell_init(&ivi) < 0)
                goto error_compositor;
 
@@ -1263,6 +1267,8 @@ error_compositor:
 
        weston_log_subscriber_destroy_log(logger);
 
+       ivi_policy_destroy(ivi.policy);
+
 error_signals:
        for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
                if (signals[i])
diff --git a/src/policy-default.c b/src/policy-default.c
new file mode 100644 (file)
index 0000000..051688a
--- /dev/null
@@ -0,0 +1,74 @@
+#include "ivi-compositor.h"
+#include "policy.h"
+
+/*
+ * default policy implementation allows every action to be possible
+ *
+ * This is an example, that implements the API
+ *
+ * - policy_rule_allow_to_add is required in order to add further policy rules
+ * - policy_rule_try_event is a hook that should be implemented in order
+ *   for agl-shell-policy to work correctly.
+ */
+static bool
+ivi_policy_default_surface_create(struct ivi_surface *surf, void *user_data)
+{
+       /* verify that the surface should be created */
+       return true;
+}
+
+static bool
+ivi_policy_default_surface_commmited(struct ivi_surface *surf, void *user_data)
+{
+       /* verify that the surface should be commited */
+       return true;
+}
+
+static bool
+ivi_policy_default_surface_activate(struct ivi_surface *surf, void *user_data)
+{
+       /* verify that the surface shuld be switched to */
+       return true;
+}
+
+static bool
+ivi_policy_default_allow_to_add(void *user_data)
+{
+       /* verify that it can inject events with the protocol */
+       return true;
+}
+
+static void
+ivi_policy_default_try_event(struct ivi_a_policy *a_policy)
+{
+       uint32_t event = a_policy->event;
+
+       switch (event) {
+       case AGL_SHELL_POLICY_EVENT_SHOW:
+               ivi_layout_activate(a_policy->output, a_policy->app_id);
+               break;
+       case AGL_SHELL_POLICY_EVENT_HIDE:
+               /* FIXME: remove the active one, like basically unmap it? */
+       default:
+               break;
+       }
+}
+
+static const struct ivi_policy_api policy_api = {
+       .struct_size = sizeof(policy_api),
+       .surface_create = ivi_policy_default_surface_create,
+       .surface_commited = ivi_policy_default_surface_commmited,
+       .surface_activate = ivi_policy_default_surface_activate,
+       .policy_rule_allow_to_add = ivi_policy_default_allow_to_add,
+       .policy_rule_try_event = ivi_policy_default_try_event,
+};
+
+int
+ivi_policy_init(struct ivi_compositor *ivi)
+{
+       ivi->policy = ivi_policy_create(ivi, &policy_api, ivi);
+       if (!ivi->policy)
+               return -1;
+
+       return 0;
+}