From c063ec023c3547c887e8d1b6e38a9aec23b621ea Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 24 Aug 2020 20:09:14 +1000 Subject: [PATCH] tools/ei-demo: add hooks for choosing a backend None exist other than the socket one but hey, the infrastructure is there. Signed-off-by: Peter Hutterer --- tools/ei-demo-client.c | 61 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/tools/ei-demo-client.c b/tools/ei-demo-client.c index 7f0a9b6..8913ba5 100644 --- a/tools/ei-demo-client.c +++ b/tools/ei-demo-client.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -107,9 +108,57 @@ setup_keymap(struct ei_device *kbd) #endif } +static void +usage(FILE *fp, const char *argv0) +{ + fprintf(fp, + "Usage: %s [--socket]\n" + "\n" + "Start an EI demo client. The client will connect to EIS\n" + "with the chosen backend (default: socket) and emulate pointer\n" + "and keyboard events in a loop.\n" + "\n" + "Options:\n" + " --socket Use the socket backend. The socket path is $LIBEI_SOCKET if set, \n" + " otherwise XDG_RUNTIME/eis-0\n", + argv0); +} + int main(int argc, char **argv) { - const char SOCKETNAME[] = "eis-0"; + enum { + SOCKET, + } backend = SOCKET; + + while (1) { + enum { + OPT_BACKEND_SOCKET, + OPT_VERBOSE, + }; + static struct option long_opts[] = { + {"socket", no_argument, 0, OPT_BACKEND_SOCKET}, + {"help", no_argument, 0, 'h'}, + {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_BACKEND_SOCKET: + backend = SOCKET; + break; + default: + usage(stderr, argv[0]); + return EXIT_FAILURE; + } + } + _cleanup_(ei_unrefp) struct ei *ei = ei_new(NULL); assert(ei); @@ -117,15 +166,19 @@ int main(int argc, char **argv) ei_configure_name(ei, "ei-demo-client"); - int rc = ei_setup_backend_socket(ei, getenv("LIBEI_SOCKET") ? NULL : SOCKETNAME); + int rc = -EINVAL; + + if (backend == SOCKET) { + const char SOCKETNAME[] = "eis-0"; + colorprint("connecting to %s\n", SOCKETNAME); + rc = ei_setup_backend_socket(ei, getenv("LIBEI_SOCKET") ? NULL : SOCKETNAME); + } if (rc != 0) { fprintf(stderr, "init failed: %s\n", strerror(errno)); return 1; } - colorprint("connected to %s\n", SOCKETNAME); - struct pollfd fds = { .fd = ei_get_fd(ei), .events = POLLIN,