frontend: Use enums for backend type, not strings
Convert our backend type to an enum early, and use it in place of a string. Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
parent
ef87ad2237
commit
59968f7d78
64
compositor/config-helpers.c
Normal file
64
compositor/config-helpers.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2022 Collabora, Ltd.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the
|
||||
* next paragraph) shall be included in all copies or substantial
|
||||
* portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <libweston/libweston.h>
|
||||
#include <libweston/config-parser.h>
|
||||
|
||||
#include "shared/helpers.h"
|
||||
#include "weston-private.h"
|
||||
|
||||
struct {
|
||||
char *short_name;
|
||||
char *long_name;
|
||||
enum weston_compositor_backend backend;
|
||||
} backend_name_map[] = {
|
||||
{ "drm", "drm-backend.so", WESTON_BACKEND_DRM },
|
||||
{ "headless", "headless-backend.so", WESTON_BACKEND_HEADLESS },
|
||||
{ "rdp", "rdp-backend.so", WESTON_BACKEND_RDP },
|
||||
{ "vnc", "vnc-backend.so", WESTON_BACKEND_VNC },
|
||||
{ "wayland", "wayland-backend.so", WESTON_BACKEND_WAYLAND },
|
||||
{ "x11", "x11-backend.so", WESTON_BACKEND_X11 },
|
||||
};
|
||||
|
||||
bool
|
||||
get_backend_from_string(const char *name,
|
||||
enum weston_compositor_backend *backend)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(backend_name_map); i++) {
|
||||
if (strcmp(name, backend_name_map[i].short_name) == 0 ||
|
||||
strcmp(name, backend_name_map[i].long_name) == 0) {
|
||||
*backend = backend_name_map[i].backend;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -3481,30 +3481,32 @@ load_wayland_backend(struct weston_compositor *c,
|
||||
|
||||
|
||||
static int
|
||||
load_backend(struct weston_compositor *compositor, const char *backend,
|
||||
load_backend(struct weston_compositor *compositor, const char *name,
|
||||
int *argc, char **argv, struct weston_config *config)
|
||||
{
|
||||
if (strcmp(backend, "headless") == 0 ||
|
||||
strstr(backend, "headless-backend.so"))
|
||||
return load_headless_backend(compositor, argc, argv, config);
|
||||
else if (strcmp(backend, "rdp") == 0 ||
|
||||
strstr(backend, "rdp-backend.so"))
|
||||
return load_rdp_backend(compositor, argc, argv, config);
|
||||
else if (strcmp(backend, "vnc") == 0 ||
|
||||
strstr(backend, "vnc-backend.so"))
|
||||
return load_vnc_backend(compositor, argc, argv, config);
|
||||
else if (strcmp(backend, "drm") == 0 ||
|
||||
strstr(backend, "drm-backend.so"))
|
||||
return load_drm_backend(compositor, argc, argv, config);
|
||||
else if (strcmp(backend, "x11") == 0 ||
|
||||
strstr(backend, "x11-backend.so"))
|
||||
return load_x11_backend(compositor, argc, argv, config);
|
||||
else if (strcmp(backend, "wayland") == 0 ||
|
||||
strstr(backend, "wayland-backend.so"))
|
||||
return load_wayland_backend(compositor, argc, argv, config);
|
||||
enum weston_compositor_backend backend;
|
||||
|
||||
weston_log("Error: unknown backend \"%s\"\n", backend);
|
||||
return -1;
|
||||
if (!get_backend_from_string(name, &backend)) {
|
||||
weston_log("Error: unknown backend \"%s\"\n", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (backend) {
|
||||
case WESTON_BACKEND_DRM:
|
||||
return load_drm_backend(compositor, argc, argv, config);
|
||||
case WESTON_BACKEND_HEADLESS:
|
||||
return load_headless_backend(compositor, argc, argv, config);
|
||||
case WESTON_BACKEND_RDP:
|
||||
return load_rdp_backend(compositor, argc, argv, config);
|
||||
case WESTON_BACKEND_VNC:
|
||||
return load_vnc_backend(compositor, argc, argv, config);
|
||||
case WESTON_BACKEND_WAYLAND:
|
||||
return load_wayland_backend(compositor, argc, argv, config);
|
||||
case WESTON_BACKEND_X11:
|
||||
return load_x11_backend(compositor, argc, argv, config);
|
||||
default:
|
||||
unreachable("unknown backend type in load_backend()");
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -2,6 +2,7 @@ srcs_weston = [
|
||||
git_version_h,
|
||||
'main.c',
|
||||
'text-backend.c',
|
||||
'config-helpers.c',
|
||||
'weston-screenshooter.c',
|
||||
text_input_unstable_v1_server_protocol_h,
|
||||
text_input_unstable_v1_protocol_c,
|
||||
|
@ -28,6 +28,10 @@
|
||||
#include <libweston/libweston.h>
|
||||
#include <libweston/config-parser.h>
|
||||
|
||||
bool
|
||||
get_backend_from_string(const char *name,
|
||||
enum weston_compositor_backend *backend);
|
||||
|
||||
int
|
||||
wet_output_set_color_characteristics(struct weston_output *output,
|
||||
struct weston_config *wc,
|
||||
|
Loading…
Reference in New Issue
Block a user