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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-08-24 20:09:14 +10:00
parent 8cf7b3573e
commit c063ec023c

View file

@ -25,6 +25,7 @@
#include <assert.h>
#include <errno.h>
#include <getopt.h>
#include <poll.h>
#include <stdio.h>
#include <signal.h>
@ -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,