[PATCH weston 3/3] libweston: Add a generic weston_compositor_load_module
Quentin Glidic
sardemff7+wayland at sardemff7.net
Mon Jul 4 13:58:09 UTC 2016
From: Quentin Glidic <sardemff7+git at sardemff7.net>
This way, we can share modules between libweston-based compositors, but
they can only be loaded explicitely by the compositor.
Signed-off-by: Quentin Glidic <sardemff7+git at sardemff7.net>
---
Makefile.am | 3 ++-
compositor/main.c | 38 ++++++++++++++++++++++++++++++++++++++
libweston/compositor.c | 13 ++++++++++---
libweston/compositor.h | 4 ++++
man/weston.ini.man | 8 +++++++-
man/weston.man | 6 ++++++
6 files changed, 67 insertions(+), 5 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 436bb1b..d99437a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1414,7 +1414,8 @@ endif
MAN_SUBSTS = \
-e 's|__weston_native_backend__|$(WESTON_NATIVE_BACKEND)|g' \
- -e 's|__weston_modules_dir__|$(pkglibdir)|g' \
+ -e 's|__libweston_modules_dir__|$(libweston_moduledir)|g' \
+ -e 's|__weston_modules_dir__|$(moduledir)|g' \
-e 's|__weston_shell_client__|$(WESTON_SHELL_CLIENT)|g' \
-e 's|__version__|$(PACKAGE_VERSION)|g'
diff --git a/compositor/main.c b/compositor/main.c
index 88f7911..ea89e47 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -780,6 +780,33 @@ wet_load_module(struct weston_compositor *compositor,
return 0;
}
+static int
+load_cmodules(struct weston_compositor *ec, const char *modules,
+ int *argc, char *argv[])
+{
+ const char *p, *end;
+ char buffer[256];
+
+ if (modules == NULL)
+ return 0;
+
+ p = modules;
+ while (*p) {
+ end = strchrnul(p, ',');
+ snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
+
+ if (weston_compositor_load_module(ec, buffer) < 0)
+ return -1;
+
+ p = end;
+ while (*p == ',')
+ p++;
+
+ }
+
+ return 0;
+}
+
static int
load_modules(struct weston_compositor *ec, const char *modules,
int *argc, char *argv[])
@@ -1589,7 +1616,9 @@ int main(int argc, char *argv[])
char *backend = NULL;
char *shell = NULL;
int32_t xwayland = 0;
+ char *cmodules = NULL;
char *modules = NULL;
+ char *option_cmodules = NULL;
char *option_modules = NULL;
char *log = NULL;
char *server_socket = NULL, *end;
@@ -1612,6 +1641,7 @@ int main(int argc, char *argv[])
{ WESTON_OPTION_STRING, "socket", 'S', &socket_name },
{ WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time },
{ WESTON_OPTION_BOOLEAN, "xwayland", 0, &xwayland },
+ { WESTON_OPTION_STRING, "common-modules", 0, &option_cmodules },
{ WESTON_OPTION_STRING, "modules", 0, &option_modules },
{ WESTON_OPTION_STRING, "log", 0, &log },
{ WESTON_OPTION_BOOLEAN, "help", 'h', &help },
@@ -1746,6 +1776,14 @@ int main(int argc, char *argv[])
if (wet_load_shell(ec, shell, &argc, argv) < 0)
goto out;
+ weston_config_section_get_string(section, "common-modules", &cmodules,
+ "");
+ if (load_cmodules(ec, cmodules, &argc, argv) < 0)
+ goto out;
+
+ if (load_cmodules(ec, option_cmodules, &argc, argv) < 0)
+ goto out;
+
weston_config_section_get_string(section, "modules", &modules, "");
if (load_modules(ec, modules, &argc, argv) < 0)
goto out;
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 8f30b46..0ed3b0c 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -5033,17 +5033,18 @@ weston_compositor_load_backend(struct weston_compositor *compositor,
}
WL_EXPORT int
-weston_compositor_load_xwayland(struct weston_compositor *compositor)
+weston_compositor_load_module(struct weston_compositor *compositor,
+ const char *name)
{
int (*weston_module_init)(struct weston_compositor *ec);
- weston_module_init = weston_load_module("xwayland.so", "weston_module_init");
+ weston_module_init = weston_load_module(name, "weston_module_init");
if (!weston_module_init) {
int (*module_init)(struct weston_compositor *ec,
int *argc, char *argv[]);
int argc = 0;
- module_init = weston_load_module("xwayland.so", "module_init");
+ module_init = weston_load_module(name, "module_init");
if (!module_init || module_init(compositor, &argc, NULL) < 0)
return -1;
} else if (weston_module_init(compositor) < 0) {
@@ -5051,3 +5052,9 @@ weston_compositor_load_xwayland(struct weston_compositor *compositor)
}
return 0;
}
+
+WL_EXPORT int
+weston_compositor_load_xwayland(struct weston_compositor *compositor)
+{
+ return weston_compositor_load_module(compositor, "xwayland.so");
+}
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 3fa9b02..827af8a 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -1723,6 +1723,10 @@ void
weston_seat_set_keyboard_focus(struct weston_seat *seat,
struct weston_surface *surface);
+
+int
+weston_compositor_load_module(struct weston_compositor *compositor, const char *name);
+
int
weston_compositor_load_xwayland(struct weston_compositor *compositor);
diff --git a/man/weston.ini.man b/man/weston.ini.man
index 1b1e05a..033b4b0 100644
--- a/man/weston.ini.man
+++ b/man/weston.ini.man
@@ -110,6 +110,12 @@ directory are:
ask Weston to load the XWayland module (boolean).
.RE
.TP 7
+.BI "common-modules=" cms-colord.so,screen-share.so
+specifies the modules to load (string). These are shared with other
+libweston-based compositors. The files are searched for in the
+.IR "__libweston_modules_dir__"
+directory.
+.TP 7
.BI "modules=" cms-colord.so,screen-share.so
specifies the modules to load (string). Available modules in the
.IR "__weston_modules_dir__"
@@ -124,7 +130,7 @@ directory are:
.TP 7
.BI "backend=" headless-backend.so
overrides defaults backend. Available backend modules in the
-.IR "__weston_modules_dir__"
+.IR "__libweston_modules_dir__"
directory are:
.PP
.RS 10
diff --git a/man/weston.man b/man/weston.man
index face229..5338b66 100644
--- a/man/weston.man
+++ b/man/weston.man
@@ -146,6 +146,12 @@ instead of writing them to stderr.
\fB\-\-xwayland\fR
Ask Weston to load the XWayland module.
.TP
+\fB\-\-common-modules\fR=\fImodule1.so,module2.so\fR
+Load the comma-separated list of modules shared with other
+libweston-based compositors. The file is searched for in
+.IR "__libweston_modules_dir__" ,
+or you can pass an absolute path.
+.TP
\fB\-\-modules\fR=\fImodule1.so,module2.so\fR
Load the comma-separated list of modules. Only used by the test
suite. The file is searched for in
--
2.9.0
More information about the wayland-devel
mailing list