OMpush_status_range and OMpop_status_range
Synopsis
int OMpush_status_range(
int min_percent,
int max_percent);
int OMpop_status_range();
Description
These routines allow you to encapsulate a subroutine that uses the OMstatus_check routine to set the percent_done value. The subroutine sets percent done from 0 to 100. These routines determine how much contribution the subroutine has on the percent done of the calling routine.
Arguments
min_percent
After calling OMpush_status_range, a percent_done argument of 0 in OMstatus_check is mapped to this value.
max_percent
After calling OMpush_status_range, a percent_done argument of 100 in OMstatus_check is mapped to this value.
Example
You might have a function that computes an array of numbers called get_random_values. This function is coded so that it calls OMstatus_check at intervals from 0 to 100 as it walks through elements in the array. You then write a module which calls this function multiple times with different sized arrays. The higher level function can set a status range before calling the lower level function:
int
get_random_values(int arr[], int size)
{
int i, stop;
for (i = 0; i < size; i++) {
if (!(i & 0xf)) { /* do only every so often... */
(void) OMstatus_check(i * 100 / size, NULL, &stop);
if (stop) return(0); /* user interrupted us */
}
arr[i] = random();
}
return(1);
}
int
update_me(OMobj_id obj_id, OMevent_mask mask, int seq_num)
{
int arr1[1000], arr2[500];
int stat;
OMpush_status_range(0,75);
stat = get_random_values(arr1,1000);
OMpop_status_range();
if (stat != 1) return(0); /* interrupted */
OMpush_status_range(75,100);
stat = get_random_values(arr2,500);
OMpop_status_range();
if (stat != 1) return(0);
... set the values in arr1 and arr2 into objects...
See also