1 /* $NetBSD: lutil_meter.h,v 1.2 2021/08/14 16:14:55 christos Exp $ */ 2 3 /* lutil_meter.h - progress meters */ 4 /* $OpenLDAP$ */ 5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 6 * 7 * Copyright (c) 2009 by Emily Backes, Symas Corp. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted only as authorized by the OpenLDAP 12 * Public License. 13 * 14 * A copy of this license is available in the file LICENSE in the 15 * top-level directory of the distribution or, alternatively, at 16 * <http://www.OpenLDAP.org/license.html>. 17 */ 18 /* ACKNOWLEDGEMENTS: 19 * This work was initially developed by Emily Backes for inclusion 20 * in OpenLDAP software. 21 */ 22 23 #ifndef _LUTIL_METER_H 24 #define _LUTIL_METER_H 25 26 #include <sys/cdefs.h> 27 __RCSID("$NetBSD: lutil_meter.h,v 1.2 2021/08/14 16:14:55 christos Exp $"); 28 29 #include "portable.h" 30 31 #include <limits.h> 32 #include <stdio.h> 33 #include <sys/types.h> 34 35 #include <ac/stdlib.h> 36 #include <ac/time.h> 37 38 typedef struct { 39 int (*display_open) (void **datap); 40 int (*display_update) (void **datap, double frac, time_t remaining_time, time_t elapsed, double byte_rate); 41 int (*display_close) (void **datap); 42 } lutil_meter_display_t; 43 44 typedef struct { 45 int (*estimator_open) (void **datap); 46 int (*estimator_update) (void **datap, double start, double frac, time_t *remaining_time); 47 int (*estimator_close) (void **datap); 48 } lutil_meter_estimator_t; 49 50 typedef struct { 51 const lutil_meter_display_t *display; 52 void * display_data; 53 const lutil_meter_estimator_t *estimator; 54 void * estimator_data; 55 double start_time; 56 double last_update; 57 size_t goal_value; 58 size_t last_position; 59 } lutil_meter_t; 60 61 extern const lutil_meter_display_t lutil_meter_text_display; 62 extern const lutil_meter_estimator_t lutil_meter_linear_estimator; 63 64 extern int lutil_meter_open ( 65 lutil_meter_t *lutil_meter, 66 const lutil_meter_display_t *display, 67 const lutil_meter_estimator_t *estimator, 68 size_t goal_value); 69 extern int lutil_meter_update ( 70 lutil_meter_t *lutil_meter, 71 size_t position, 72 int force); 73 extern int lutil_meter_close (lutil_meter_t *lutil_meter); 74 75 #endif /* _LUTIL_METER_H */ 76