tools: add a --interval option to the demo server and client

Makes testing a few things easier.
This commit is contained in:
Peter Hutterer 2023-10-11 10:20:31 +10:00
parent cefef7b1a5
commit fd2999ffdb
2 changed files with 18 additions and 4 deletions

View file

@ -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) {

View file

@ -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;