main: Teach agl-compositor to load additional modules 81/26281/1
authorMarius Vlad <marius.vlad@collabora.com>
Tue, 20 Apr 2021 10:31:18 +0000 (13:31 +0300)
committerMarius Vlad <marius.vlad@collabora.com>
Tue, 20 Apr 2021 12:51:50 +0000 (15:51 +0300)
Passing modules arguments to the compositor instance would be useful
when using the testing framework/harness because that way the test
itself can start-up. The idea here is that we would need to load-up a
testing plug-in (either one from weston) or one written specifically for
this.

Bug-AGL: SPEC-3888

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

src/main.c

index 340d0e0..5605841 100644 (file)
@@ -1153,6 +1153,46 @@ load_backend(struct ivi_compositor *ivi, const char *backend,
        return -1;
 }
 
+static int
+load_modules(struct ivi_compositor *ivi, const char *modules,
+            int *argc, char *argv[], bool *xwayland)
+{
+       const char *p, *end;
+       char buffer[256];
+       int (*module_init)(struct weston_compositor *wc, int argc, char *argv[]);
+
+       if (modules == NULL)
+               return 0;
+
+       p = modules;
+       while (*p) {
+               end = strchrnul(p, ',');
+               snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
+
+               if (strstr(buffer, "xwayland.so")) {
+                       weston_log("Xwayland plug-in not supported!\n");
+                       p = end;
+                       while (*p == ',')
+                               p++;
+                       continue;
+               }
+
+               module_init = weston_load_module(buffer, "wet_module_init");
+               if (!module_init)
+                       return -1;
+
+               if (module_init(ivi->compositor, *argc, argv) < 0)
+                       return -1;
+
+               p = end;
+               while (*p == ',')
+                       p++;
+       }
+
+       return 0;
+}
+
+
 static char *
 choose_default_backend(void)
 {
@@ -1512,6 +1552,8 @@ int main(int argc, char *argv[])
        char *backend = NULL;
        char *socket_name = NULL;
        char *log = NULL;
+       char *modules = NULL;
+       char *option_modules = NULL;
        int help = 0;
        int version = 0;
        int no_config = 0;
@@ -1520,6 +1562,7 @@ int main(int argc, char *argv[])
        struct weston_log_context *log_ctx = NULL;
        struct weston_log_subscriber *logger;
        int ret = EXIT_FAILURE;
+       bool xwayland = false;
 
        const struct weston_option core_options[] = {
                { WESTON_OPTION_STRING, "backend", 'B', &backend },
@@ -1530,6 +1573,7 @@ int main(int argc, char *argv[])
                { WESTON_OPTION_BOOLEAN, "no-config", 0, &no_config },
                { WESTON_OPTION_BOOLEAN, "debug", 0, &debug },
                { WESTON_OPTION_STRING, "config", 'c', &config_file },
+               { WESTON_OPTION_STRING, "modules", 0, &option_modules },
        };
 
        wl_list_init(&ivi.outputs);
@@ -1625,6 +1669,14 @@ int main(int argc, char *argv[])
 
        ivi_seat_init(&ivi);
 
+       /* load additional modules */
+       weston_config_section_get_string(section, "modules", &modules, "");
+       if (load_modules(&ivi, modules, &argc, argv, &xwayland) < 0)
+               goto error_compositor;
+
+       if (load_modules(&ivi, option_modules, &argc, argv, &xwayland) < 0)
+               goto error_compositor;
+
        if (ivi_policy_init(&ivi) < 0)
                goto error_compositor;