Back to index

openldap  2.4.31
Classes | Functions | Variables
lutil_meter.h File Reference
#include "portable.h"
#include <limits.h>
#include <stdio.h>
#include <sys/types.h>
#include <ac/stdlib.h>
#include <ac/time.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  lutil_meter_display_t
struct  lutil_meter_estimator_t
struct  lutil_meter_t

Functions

int lutil_meter_open (lutil_meter_t *lutil_meter, const lutil_meter_display_t *display, const lutil_meter_estimator_t *estimator, unsigned long goal_value)
int lutil_meter_update (lutil_meter_t *lutil_meter, unsigned long position, int force)
int lutil_meter_close (lutil_meter_t *lutil_meter)

Variables

const lutil_meter_display_t lutil_meter_text_display
const lutil_meter_estimator_t lutil_meter_linear_estimator

Class Documentation

struct lutil_meter_t

Definition at line 45 of file lutil_meter.h.

Collaboration diagram for lutil_meter_t:
Class Members
const lutil_meter_display_t * display
void * display_data
const lutil_meter_estimator_t * estimator
void * estimator_data
unsigned long goal_value
unsigned long last_position
double last_update
double start_time

Function Documentation

int lutil_meter_close ( lutil_meter_t lutil_meter)

Definition at line 188 of file meter.c.

Here is the caller graph for this function:

int lutil_meter_open ( lutil_meter_t lutil_meter,
const lutil_meter_display_t display,
const lutil_meter_estimator_t estimator,
unsigned long  goal_value 
)

Definition at line 98 of file meter.c.

{
       int rc;

       assert( meter != NULL );
       assert( display != NULL );
       assert( estimator != NULL );

       if (goal_value < 1) return -1;

       memset( (void*) meter, 0, sizeof( lutil_meter_t ));
       meter->display = display;
       meter->estimator = estimator;
       lutil_get_now( &meter->start_time );
       meter->last_update = meter->start_time;
       meter->goal_value = goal_value;
       meter->last_position = 0;

       rc = meter->display->display_open( &meter->display_data );
       if( rc != 0 ) return rc;
       
       rc = meter->estimator->estimator_open( &meter->estimator_data );
       if( rc != 0 ) {
              meter->display->display_close( &meter->display_data );
              return rc;
       }
       
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int lutil_meter_update ( lutil_meter_t lutil_meter,
unsigned long  position,
int  force 
)

Definition at line 133 of file meter.c.

{
       static const double display_rate = 0.5;
       double frac, cycle_length, speed, now;
       time_t remaining_time, elapsed;
       int rc;

       assert( meter != NULL );

       lutil_get_now( &now );

       if ( !force && now - meter->last_update < display_rate ) return 0;

       frac = ((double)position) / ((double) meter->goal_value);
       elapsed = now - meter->start_time;
       if (frac <= 0.0) return 0;
       if (frac >= 1.0) {
              rc = meter->display->display_update(
                     &meter->display_data,
                     1.0,
                     0,
                     (time_t) elapsed,
                     ((double)position) / elapsed);
       } else {
              rc = meter->estimator->estimator_update( 
                     &meter->estimator_data, 
                     meter->start_time,
                     frac,
                     &remaining_time );
              if ( rc == 0 ) {
                     cycle_length = now - meter->last_update;
                     speed = cycle_length > 0.0 ?
                            ((double)(position - meter->last_position)) 
                            / cycle_length :
                            0.0;
                     rc = meter->display->display_update(
                            &meter->display_data,
                            frac,
                            remaining_time,
                            (time_t) elapsed,
                            speed);
                     if ( rc == 0 ) {
                            meter->last_update = now;
                            meter->last_position = position;
                     }
              }
       }

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 384 of file meter.c.

Definition at line 380 of file meter.c.