Let oeffis-demo-tool start ei-demo-client optionally

This allows testing the EIS implementation when no public socket
is available.
This commit is contained in:
David Redondo 2024-04-05 11:52:38 +02:00
parent 1f9be0fd0a
commit 718bd425b0

View file

@ -29,6 +29,7 @@
#include "config.h"
#include <assert.h>
#include <getopt.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
@ -71,9 +72,81 @@ start_debug_events(int fd)
}
}
static void
start_demo_client(int fd)
{
pid_t pid = fork();
assert(pid != -1);
if (pid == 0) {
_cleanup_free_ char *fdstr = xaprintf("%d", fd);
execl(MESON_BUILDDIR "/ei-demo-client",
"ei-demo-client",
"--socketfd", fdstr, NULL);
fprintf(stderr, "Failed to fork: %m\n");
exit(1);
}
}
static void
usage(FILE *fp, const char *argv0)
{
fprintf(fp,
"Usage: %s [--client=debug-events|demo-client]\n"
"\n"
"Connect to the EIS implementation via the remote desktop portal.\n"
"Afterwards the specified action is taken.\n"
"\n"
"Options:\n"
" --client the tool to launch after connecting to the eis implementation,\n"
" one of debug-events (default) or demo-client\n",
argv0);
}
int
main(int argc, char **argv)
{
enum {
DEBUG,
CLIENT,
} action = DEBUG;
while (1) {
enum {
OPT_CLIENT,
};
static struct option long_opts[] = {
{"client", required_argument, 0, OPT_CLIENT},
{"help", no_argument, 0, 'h'},
{.name = NULL},
};
int optind = 0;
int c = getopt_long(argc, argv, "h", long_opts, &optind);
if (c == -1)
break;
switch(c) {
case 'h':
usage(stdout, argv[0]);
return EXIT_SUCCESS;
case OPT_CLIENT:
action = DEBUG;
if (strcmp(optarg, "debug-events") == 0) {
action = DEBUG;
break;
} else if (strcmp(optarg, "demo-client") == 0) {
action = CLIENT;
break;
}
_fallthrough_;
default:
usage(stderr, argv[0]);
return EXIT_FAILURE;
}
}
_unref_(oeffis) *oeffis = oeffis_new(NULL);
signal(SIGINT, sighandler);
@ -108,7 +181,14 @@ main(int argc, char **argv)
* cause the compositor or the portal to invalidate
* our EIS fd.
*/
start_debug_events(eisfd);
switch (action) {
case DEBUG:
start_debug_events(eisfd);
break;
case CLIENT:
start_demo_client(eisfd);
break;
}
break;
}
case OEFFIS_EVENT_DISCONNECTED: