1 /* Copyright 2018 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 #ifndef POLLED_ACTIVITY_CHECKER_H_ 7 #define POLLED_ACTIVITY_CHECKER_H_ 8 9 #include <time.h> 10 11 /* Represents a time interval, in seconds, which can be checked periodically. */ 12 struct polled_interval; 13 14 /* 15 * Creates a new polled_interval, of the specified duration. The interval will 16 * first elapse interval_sec after it was created. 17 * 18 * Call pic_update_current_time() shortly before this function. 19 */ 20 struct polled_interval *pic_polled_interval_create(int interval_sec); 21 22 /* 23 * Destroys the specified polled_interval, and set's the pointer to it to NULL. 24 */ 25 void pic_polled_interval_destroy(struct polled_interval **interval); 26 27 /* 28 * Whether the interval's duration has elapsed (since the interval was created 29 * or reset). 30 * 31 * Call pic_update_current_time() shortly before this function. 32 */ 33 int pic_interval_elapsed(const struct polled_interval *interval); 34 35 /* 36 * Resets the interval; it will elapse it's specified duration from now. 37 * 38 * Call pic_update_current_time() shortly before this function. 39 */ 40 void pic_interval_reset(struct polled_interval *pi); 41 42 /* 43 * Updates the current time, which is used in all other pic_* functions (which 44 * will never update the current time). This update is pulled out separately to 45 * allow the caller to control when and how often the time is updated. 46 */ 47 void pic_update_current_time(); 48 49 50 #endif /* POLLED_ACTIVITY_CHECKER_H_ */