void compute_subject_downtime_times(time_t start_time, time_t end_time, avail_subject *subject, archived_state *sd) { archived_state *temp_as; time_t part_start_time; time_t part_subject_state; int save_status=0; int saved_status=0; int saved_stamp=0; int calc_temp=0; int count=0; archived_state *temp_before; archived_state *last; #ifdef DEBUG2 printf("

ENTERING COMPUTE_SUBJECT_DOWNTIME_TIMES: start=%lu, end=%lu, t1=%lu, t2=%lu

",start_time,end_time,t1,t2); /* OPSERVICES */ #endif //printf("

ENTERING COMPUTE_SUBJECT_DOWNTIME_TIMES: start=%lu, end=%lu, t1=%lu, t2=%lu

",start_time,end_time,t1,t2); /* times are weird, so bail out... */ if(start_time>end_time) return; if(start_timet2) return; /* find starting point in archived state list */ if(sd==NULL) { #ifdef DEBUG2 printf("

TEMP_AS=SUBJECT->AS_LIST

"); #endif temp_as=subject->as_list; } else if(sd->misc_ptr==NULL) { #ifdef DEBUG2 printf("

TEMP_AS=SUBJECT->AS_LIST

"); #endif temp_as=subject->as_list; } else if(sd->misc_ptr->next==NULL) { #ifdef DEBUG2 printf("

TEMP_AS=SD->MISC_PTR

"); #endif temp_as=sd->misc_ptr; } else { #ifdef DEBUG2 printf("

TEMP_AS=SD->MISC_PTR->NEXT

"); #endif temp_as=sd->misc_ptr->next; } /* initialize values */ part_start_time=start_time; if(temp_as==NULL) part_subject_state=AS_NO_DATA; else if(temp_as->processed_state==AS_PROGRAM_START || temp_as->processed_state==AS_PROGRAM_END || temp_as->processed_state==AS_NO_DATA){ #ifdef DEBUG2 printf("

ENTRY TYPE #1: %d

",temp_as->entry_type); #endif part_subject_state=AS_NO_DATA; } else{ #ifdef DEBUG2 printf("

ENTRY TYPE #2: %d

",temp_as->entry_type); #endif part_subject_state=temp_as->processed_state; } #ifdef DEBUG2 printf("

TEMP_AS=%s

",(temp_as==NULL)?"NULL":"Not NULL"); printf("

SD=%s

",(sd==NULL)?"NULL":"Not NULL"); #endif temp_before=NULL; saved_status=0; saved_stamp=0; count=0; //printf("

0 <%ld> <%ld> <%ld> <%ld>

",count, start_time,end_time,part_subject_state); /* temp_as now points to first event to possibly "break" this chunk */ //time_t start_time, time_t end_time for(;temp_as!=NULL;temp_as=temp_as->next) { count++; //if ( (temp_as->entry_type==AS_PROGRAM_END) || (temp_as->entry_type==AS_PROGRAM_START) ) { // last=temp_as; // continue; //} last=temp_as; if (temp_before==NULL) { if (last->time_stamp>start_time) { if (last->time_stamp>end_time) { //printf("

1 <%ld> <%ld> <%ld> <%ld>

",count, start_time,last->time_stamp,part_subject_state); compute_subject_downtime_part_times(start_time,end_time,part_subject_state,subject); } else { //printf("

1.1 <%ld> <%ld> <%ld> <%ld>

",count, start_time,last->time_stamp,part_subject_state); compute_subject_downtime_part_times(start_time,last->time_stamp,part_subject_state,subject); } } temp_before=temp_as; saved_status=temp_as->entry_type; saved_stamp=temp_as->time_stamp; /* Check if first time is before schedule downtime */ if (saved_stampentry_type) { if(temp_as->time_stamp>end_time) { // is outside schedule time, use end schdule downtime if (saved_stamp 2 <%ld> <%ld> <%ld> <%ld>

",count, saved_stamp,end_time,saved_status); compute_subject_downtime_part_times(start_time,end_time,saved_status,subject); } else { compute_subject_downtime_part_times(saved_stamp,end_time,saved_status,subject); } } else { if (saved_stamp 3 <%ld> <%ld> <%ld> <%ld>

",count, saved_stamp,end_time,saved_status); compute_subject_downtime_part_times(start_time,temp_as->time_stamp,saved_status,subject); } else { compute_subject_downtime_part_times(saved_stamp,temp_as->time_stamp,saved_status,subject); } } saved_status=temp_as->entry_type; saved_stamp=temp_as->time_stamp; } } if (count==0) { // just one entry inside the schdule downtime //printf("

4 <%ld> <%ld> <%ld> <%ld>

",count, saved_stamp,end_time,saved_status); compute_subject_downtime_part_times(start_time,end_time,part_subject_state,subject); } else { if(last->time_stamp>end_time) { // is outside schedule time, use end schdule downtime //printf("

5 <%ld> <%ld> <%ld> <%ld>

",count, saved_stamp,end_time,saved_status); compute_subject_downtime_part_times(saved_stamp,end_time,saved_status,subject); } else { //printf("

6 <%ld> <%ld> <%ld> <%ld>

",count, saved_stamp,end_time,saved_status); compute_subject_downtime_part_times(saved_stamp,last->time_stamp,saved_status,subject); } } return; }