compositor: Generalize module loading
We can now load any number of general modules, and the shell and xwayland are just two of them. We continue to use the mechanism for testing but custom input drivers or logging mechanisms, for example are other use cases.
This commit is contained in:
parent
eb00e2e24b
commit
a6813d2887
@ -100,8 +100,8 @@ Append log messages to the file
|
|||||||
.I file.log
|
.I file.log
|
||||||
instead of writing them to stderr.
|
instead of writing them to stderr.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-module\fR=\fImodule.so\fR
|
\fB\-\-modules\fR=\fImodule1.so,module2.so\fR
|
||||||
Load a generic plugin module \fImodule.so\fR. Only used by the test
|
Load the comma-separated list of modules. Only used by the test
|
||||||
suite. The file is searched for in
|
suite. The file is searched for in
|
||||||
.IR "__weston_modules_dir__" ,
|
.IR "__weston_modules_dir__" ,
|
||||||
or you can pass an absolute path.
|
or you can pass an absolute path.
|
||||||
|
@ -2871,6 +2871,13 @@ load_module(const char *name, const char *entrypoint)
|
|||||||
else
|
else
|
||||||
snprintf(path, sizeof path, "%s", name);
|
snprintf(path, sizeof path, "%s", name);
|
||||||
|
|
||||||
|
module = dlopen(path, RTLD_NOW | RTLD_NOLOAD);
|
||||||
|
if (module) {
|
||||||
|
weston_log("Module '%s' already loaded\n", path);
|
||||||
|
dlclose(module);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
weston_log("Loading module '%s'\n", path);
|
weston_log("Loading module '%s'\n", path);
|
||||||
module = dlopen(path, RTLD_NOW);
|
module = dlopen(path, RTLD_NOW);
|
||||||
if (!module) {
|
if (!module) {
|
||||||
@ -2887,6 +2894,32 @@ load_module(const char *name, const char *entrypoint)
|
|||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
load_modules(struct weston_compositor *ec, const char *modules)
|
||||||
|
{
|
||||||
|
const char *p, *end;
|
||||||
|
char buffer[256];
|
||||||
|
int (*module_init)(struct weston_compositor *ec);
|
||||||
|
|
||||||
|
if (modules == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
p = modules;
|
||||||
|
while (*p) {
|
||||||
|
end = strchrnul(p, ',');
|
||||||
|
snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
|
||||||
|
module_init = load_module(buffer, "module_init");
|
||||||
|
if (module_init)
|
||||||
|
module_init(ec);
|
||||||
|
p = end;
|
||||||
|
while (*p == ',')
|
||||||
|
p++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const char xdg_error_message[] =
|
static const char xdg_error_message[] =
|
||||||
"fatal: environment variable XDG_RUNTIME_DIR is not set.\n";
|
"fatal: environment variable XDG_RUNTIME_DIR is not set.\n";
|
||||||
|
|
||||||
@ -2945,8 +2978,7 @@ usage(int error_code)
|
|||||||
"\t\t\t\tx11-backend.so or wayland-backend.so\n"
|
"\t\t\t\tx11-backend.so or wayland-backend.so\n"
|
||||||
" -S, --socket=NAME\tName of socket to listen on\n"
|
" -S, --socket=NAME\tName of socket to listen on\n"
|
||||||
" -i, --idle-time=SECS\tIdle time in seconds\n"
|
" -i, --idle-time=SECS\tIdle time in seconds\n"
|
||||||
" --xserver\t\tEnable X server integration\n"
|
" --modules\t\tLoad the comma-separated list of modules\n"
|
||||||
" --module\t\tLoad the specified module\n"
|
|
||||||
" --log==FILE\t\tLog to the given file\n"
|
" --log==FILE\t\tLog to the given file\n"
|
||||||
" -h, --help\t\tThis help message\n\n");
|
" -h, --help\t\tThis help message\n\n");
|
||||||
|
|
||||||
@ -2982,36 +3014,32 @@ int main(int argc, char *argv[])
|
|||||||
struct wl_event_source *signals[4];
|
struct wl_event_source *signals[4];
|
||||||
struct wl_event_loop *loop;
|
struct wl_event_loop *loop;
|
||||||
struct sigaction segv_action;
|
struct sigaction segv_action;
|
||||||
int (*module_init)(struct weston_compositor *ec);
|
|
||||||
struct weston_compositor
|
struct weston_compositor
|
||||||
*(*backend_init)(struct wl_display *display,
|
*(*backend_init)(struct wl_display *display,
|
||||||
int argc, char *argv[], const char *config_file);
|
int argc, char *argv[], const char *config_file);
|
||||||
int i;
|
int i;
|
||||||
char *backend = NULL;
|
char *backend = NULL;
|
||||||
char *shell = NULL;
|
const char *modules = "desktop-shell.so", *option_modules = NULL;
|
||||||
char *module = NULL;
|
|
||||||
char *log = NULL;
|
char *log = NULL;
|
||||||
int32_t idle_time = 300;
|
int32_t idle_time = 300;
|
||||||
int32_t xserver = 0;
|
|
||||||
int32_t help = 0;
|
int32_t help = 0;
|
||||||
char *socket_name = "wayland-0";
|
char *socket_name = "wayland-0";
|
||||||
char *config_file;
|
char *config_file;
|
||||||
|
|
||||||
const struct config_key shell_config_keys[] = {
|
const struct config_key core_config_keys[] = {
|
||||||
{ "type", CONFIG_KEY_STRING, &shell },
|
{ "modules", CONFIG_KEY_STRING, &modules },
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct config_section cs[] = {
|
const struct config_section cs[] = {
|
||||||
{ "shell",
|
{ "core",
|
||||||
shell_config_keys, ARRAY_LENGTH(shell_config_keys) },
|
core_config_keys, ARRAY_LENGTH(core_config_keys) },
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct weston_option core_options[] = {
|
const struct weston_option core_options[] = {
|
||||||
{ WESTON_OPTION_STRING, "backend", 'B', &backend },
|
{ WESTON_OPTION_STRING, "backend", 'B', &backend },
|
||||||
{ WESTON_OPTION_STRING, "socket", 'S', &socket_name },
|
{ WESTON_OPTION_STRING, "socket", 'S', &socket_name },
|
||||||
{ WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time },
|
{ WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time },
|
||||||
{ WESTON_OPTION_BOOLEAN, "xserver", 0, &xserver },
|
{ WESTON_OPTION_STRING, "modules", 0, &option_modules },
|
||||||
{ WESTON_OPTION_STRING, "module", 0, &module },
|
|
||||||
{ WESTON_OPTION_STRING, "log", 0, &log },
|
{ WESTON_OPTION_STRING, "log", 0, &log },
|
||||||
{ WESTON_OPTION_BOOLEAN, "help", 'h', &help },
|
{ WESTON_OPTION_BOOLEAN, "help", 'h', &help },
|
||||||
};
|
};
|
||||||
@ -3058,7 +3086,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
config_file = config_file_path("weston.ini");
|
config_file = config_file_path("weston.ini");
|
||||||
parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell);
|
parse_config_file(config_file, cs, ARRAY_LENGTH(cs), NULL);
|
||||||
|
|
||||||
backend_init = load_module(backend, "backend_init");
|
backend_init = load_module(backend, "backend_init");
|
||||||
if (!backend_init)
|
if (!backend_init)
|
||||||
@ -3090,30 +3118,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
setenv("WAYLAND_DISPLAY", socket_name, 1);
|
setenv("WAYLAND_DISPLAY", socket_name, 1);
|
||||||
|
|
||||||
module_init = NULL;
|
if (load_modules(ec, modules) < 0)
|
||||||
if (xserver)
|
|
||||||
module_init = load_module("xwayland.so", "module_init");
|
|
||||||
if (module_init && module_init(ec) < 0) {
|
|
||||||
ret = EXIT_FAILURE;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
if (load_modules(ec, option_modules) < 0)
|
||||||
|
|
||||||
if (!shell)
|
|
||||||
shell = "desktop-shell.so";
|
|
||||||
module_init = load_module(shell, "module_init");
|
|
||||||
if (!module_init || module_init(ec) < 0) {
|
|
||||||
ret = EXIT_FAILURE;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
module_init = NULL;
|
|
||||||
if (module)
|
|
||||||
module_init = load_module(module, "module_init");
|
|
||||||
if (module_init && module_init(ec) < 0) {
|
|
||||||
ret = EXIT_FAILURE;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wl_display_add_socket(display, socket_name)) {
|
if (wl_display_add_socket(display, socket_name)) {
|
||||||
weston_log("fatal: failed to add socket: %m\n");
|
weston_log("fatal: failed to add socket: %m\n");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
../src/weston --module=$abs_builddir/.libs/${1/.la/.so}
|
../src/weston --modules=$abs_builddir/.libs/${1/.la/.so}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user