From b167dd02fc691a9760e80a5848762fd47f060843 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Sat, 1 Mar 2008 12:16:31 +0000 Subject: [PATCH] Add API to determine next timeout --- libfprint/fprint.h | 1 + libfprint/poll.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/libfprint/fprint.h b/libfprint/fprint.h index 8ad8b2b..9645004 100644 --- a/libfprint/fprint.h +++ b/libfprint/fprint.h @@ -276,6 +276,7 @@ struct fp_pollfd { int fp_handle_events_timeout(struct timeval *timeout); int fp_handle_events(void); size_t fp_get_pollfds(struct fp_pollfd **pollfds); +int fp_get_next_timeout(struct timeval *tv); typedef void (*fp_pollfd_added_cb)(int fd, short events); typedef void (*fp_pollfd_removed_cb)(int fd); diff --git a/libfprint/poll.c b/libfprint/poll.c index 5e371bf..9bd226d 100644 --- a/libfprint/poll.c +++ b/libfprint/poll.c @@ -243,6 +243,33 @@ API_EXPORTED int fp_handle_events(void) return fp_handle_events_timeout(&tv); } +/* FIXME: docs + * returns 0 if no timeouts active + * returns 1 if timeout returned + * zero timeout means events are to be handled immediately */ +API_EXPORTED int fp_get_next_timeout(struct timeval *tv) +{ + struct timeval fprint_timeout; + struct timeval libusb_timeout; + int r_fprint; + int r_libusb; + + r_fprint = get_next_timeout_expiry(&fprint_timeout, NULL); + r_libusb = libusb_get_next_timeout(&libusb_timeout); + + /* if we have no pending timeouts and the same is true for libusb, + * indicate that we have no pending timouts */ + if (r_fprint == 0 && r_libusb == 0) + return 0; + + /* otherwise return the smaller of the 2 timeouts */ + else if (timercmp(&fprint_timeout, &libusb_timeout, <)) + *tv = fprint_timeout; + else + *tv = libusb_timeout; + return 1; +} + /** \ingroup poll * Retrieve a list of file descriptors that should be polled for events * interesting to libfprint. This function is only for users who wish to