From fd2999ffdb7f1b6818322823e7c47a6851984e69 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 11 Oct 2023 10:20:31 +1000 Subject: [PATCH] tools: add a --interval option to the demo server and client Makes testing a few things easier. --- tools/ei-demo-client.c | 11 +++++++++-- tools/eis-demo-server.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/ei-demo-client.c b/tools/ei-demo-client.c index 03815e2..64a1323 100644 --- a/tools/ei-demo-client.c +++ b/tools/ei-demo-client.c @@ -166,7 +166,7 @@ static void usage(FILE *fp, const char *argv0) { fprintf(fp, - "Usage: %s [--verbose] [--socket|--portal] [--busname=a.b.c.d] [--layout=us]\n" + "Usage: %s [--verbose] [--socket|--portal] [--busname=a.b.c.d] [--layout=us] [--interval=2000]\n" "\n" "Start an EI demo client. The client will connect to EIS\n" "with the chosen backend (default: socket) and emulate pointer\n" @@ -179,6 +179,7 @@ usage(FILE *fp, const char *argv0) " --busname Use the given busname (default: org.freedesktop.portal.Desktop)\n" " --verbose Enable debugging output\n" " --receiver Create a receiver EIS context, receiving events instead of sending them\n" + " --interval Interval in milliseconds between polling\n" "", argv0); } @@ -191,6 +192,7 @@ int main(int argc, char **argv) } backend = SOCKET; bool verbose = false; bool receiver = false; + unsigned int interval = 2000; _cleanup_free_ char *busname = xstrdup("org.freedesktop.portal.Desktop"); while (1) { @@ -200,6 +202,7 @@ int main(int argc, char **argv) OPT_BUSNAME, OPT_VERBOSE, OPT_RECEIVER, + OPT_INTERVAL, }; static struct option long_opts[] = { {"socket", no_argument, 0, OPT_BACKEND_SOCKET}, @@ -207,6 +210,7 @@ int main(int argc, char **argv) {"busname", required_argument, 0, OPT_BUSNAME}, {"verbose", no_argument, 0, OPT_VERBOSE}, {"receiver", no_argument, 0, OPT_RECEIVER}, + {"interval", required_argument, 0, OPT_INTERVAL}, {"help", no_argument, 0, 'h'}, {.name = NULL}, }; @@ -236,6 +240,9 @@ int main(int argc, char **argv) case OPT_RECEIVER: receiver = true; break; + case OPT_INTERVAL: + interval = atoi(optarg); + break; default: usage(stderr, argv[0]); return EXIT_FAILURE; @@ -291,7 +298,7 @@ int main(int argc, char **argv) uint32_t sequence = 0; - while (!stop && poll(&fds, 1, 2000) > -1) { + while (!stop && poll(&fds, 1, interval) > -1) { ei_dispatch(ei); while (!stop) { diff --git a/tools/eis-demo-server.c b/tools/eis-demo-server.c index 9a4d14e..9808503 100644 --- a/tools/eis-demo-server.c +++ b/tools/eis-demo-server.c @@ -550,7 +550,7 @@ static void usage(FILE *fp, const char *argv0) { fprintf(fp, - "Usage: %s [--verbose] [--uinput] [--socketpath=/path/to/socket]\n" + "Usage: %s [--verbose] [--uinput] [--socketpath=/path/to/socket] [--interval=1000]\n" "\n" "Start an EIS demo server. The server accepts all client connections\n" "and devices and prints any events from the client to stdout.\n" @@ -559,6 +559,7 @@ usage(FILE *fp, const char *argv0) " --socketpath Use the given socket path. Default: $XDG_RUNTIME_DIR/eis-0\n" " --layout Use the given XKB layout (requires libxkbcommon). Default: none\n" " --uinput Set up each device as uinput device (this requires root)\n" + " --interval Interval in milliseconds between polling\n" " --verbose Enable debugging output\n" "", argv0); @@ -568,6 +569,7 @@ int main(int argc, char **argv) { bool verbose = false; bool uinput = false; + unsigned int interval = 1000; const char *layout = NULL; _cleanup_unlink_free_ char *socketpath = NULL; @@ -581,12 +583,14 @@ int main(int argc, char **argv) OPT_LAYOUT, OPT_SOCKETPATH, OPT_UINPUT, + OPT_INTERVAL, }; static struct option long_opts[] = { {"socketpath", required_argument, 0, OPT_SOCKETPATH}, {"layout", required_argument, 0, OPT_LAYOUT}, {"uinput", no_argument, 0, OPT_UINPUT}, {"verbose", no_argument, 0, OPT_VERBOSE}, + {"interval", required_argument, 0, OPT_INTERVAL}, {"help", no_argument, 0, 'h'}, {NULL}, }; @@ -613,6 +617,9 @@ int main(int argc, char **argv) case OPT_VERBOSE: verbose = true; break; + case OPT_INTERVAL: + interval = atoi(optarg); + break; default: usage(stderr, argv[0]); return EXIT_FAILURE; @@ -668,7 +675,7 @@ int main(int argc, char **argv) }; int nevents; - while (!stop && (nevents = poll(&fds, 1, 1000)) > -1) { + while (!stop && (nevents = poll(&fds, 1, interval)) > -1) { if (nevents == 0 && server.nreceiver_clients == 0) continue;