tools: add an --iterations argument to ei-demo-client

Limits the number of poll() iterations before triggering a shutdown.
This allows us to use this tool for shutdown testing too - previously
it would just get killed and never performed a proper unwind.
This commit is contained in:
Peter Hutterer 2023-10-18 10:09:54 +10:00
parent 5dcdc696fb
commit 2df570b203

View file

@ -180,6 +180,7 @@ usage(FILE *fp, const char *argv0)
" --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"
" --iterations Limit the number of iterations and disconnect once reached\n"
"",
argv0);
}
@ -193,6 +194,7 @@ int main(int argc, char **argv)
bool verbose = false;
bool receiver = false;
unsigned int interval = 2000;
uint32_t iterations = UINT32_MAX;
_cleanup_free_ char *busname = xstrdup("org.freedesktop.portal.Desktop");
while (1) {
@ -203,6 +205,7 @@ int main(int argc, char **argv)
OPT_VERBOSE,
OPT_RECEIVER,
OPT_INTERVAL,
OPT_ITERATIONS,
};
static struct option long_opts[] = {
{"socket", no_argument, 0, OPT_BACKEND_SOCKET},
@ -211,6 +214,7 @@ int main(int argc, char **argv)
{"verbose", no_argument, 0, OPT_VERBOSE},
{"receiver", no_argument, 0, OPT_RECEIVER},
{"interval", required_argument, 0, OPT_INTERVAL},
{"iterations", required_argument, 0, OPT_ITERATIONS},
{"help", no_argument, 0, 'h'},
{.name = NULL},
};
@ -243,6 +247,9 @@ int main(int argc, char **argv)
case OPT_INTERVAL:
interval = atoi(optarg);
break;
case OPT_ITERATIONS:
iterations = atoi(optarg);
break;
default:
usage(stderr, argv[0]);
return EXIT_FAILURE;
@ -297,8 +304,10 @@ int main(int argc, char **argv)
struct ei_seat *default_seat = NULL;
uint32_t sequence = 0;
uint32_t iteration = 0;
while (!stop && poll(&fds, 1, interval) > -1) {
++iteration;
ei_dispatch(ei);
while (!stop) {
@ -488,7 +497,7 @@ int main(int argc, char **argv)
}
}
if (stop)
if (iteration >= iterations || stop)
break;
if (!receiver) {
@ -564,5 +573,26 @@ int main(int argc, char **argv)
}
}
colorprint("shutting down\n");
if (ptr)
ei_device_close(ptr);
if (kbd)
ei_device_close(kbd);
if (abs)
ei_device_close(abs);
if (touch)
ei_device_close(touch);
if (default_seat) {
ei_seat_bind_capabilities(default_seat, EI_DEVICE_CAP_POINTER,
EI_DEVICE_CAP_KEYBOARD,
EI_DEVICE_CAP_POINTER_ABSOLUTE,
EI_DEVICE_CAP_TOUCH,
EI_DEVICE_CAP_BUTTON,
EI_DEVICE_CAP_SCROLL, NULL);
ei_seat_unref(default_seat);
}
ei = ei_unref(ei);
return 0;
}