IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 5, 2006, 1:39:43 PM (20 years ago)
Author:
eugene
Message:

fixed up the trange concepts, fixed bugs in queuedrop/queuepop

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pantasks/CheckTimeRanges.c

    r8191 r8192  
    11# include "pantasks.h"
     2
     3/* the tested time is saved by CheckTimeRanges for a following BumpTimeRanges
     4   otherwise we could have an inconsistency between valid ranges and Nrun */
     5static time_t daytime, weektime, abstime;
    26
    37/* test if we meet all time range qualifications */
    48int CheckTimeRanges (TimeRange *ranges, int Nranges) {
    59
    6   int i, intime, valid;
    7   time_t daytime, weektime, abstime, testtime;
     10  int i, intime, Ninclude, include, exclude, valid;
     11  time_t testtime;
    812  struct timeval now;
    913  struct tm Now;
     
    1620  abstime  = now.tv_sec;
    1721
    18   valid = TRUE;
    19   for (i = 0; (i < Nranges) && valid; i++) {
     22  Ninclude = 0;
     23  include = FALSE;
     24  exclude = FALSE;
     25 
     26  for (i = 0; i < Nranges; i++) {
     27    if (ranges[i].include) Ninclude ++;
     28
    2029    switch (ranges[i].type) {
    2130      /* set the testtime */
     
    3544
    3645    /* check for more than max runs in time range */
    37     if (ranges[i].keep && intime && ranges[i].Nmax) {
     46    if (ranges[i].include && intime && ranges[i].Nmax) {
    3847      if (ranges[i].Nrun >= ranges[i].Nmax) return (FALSE);
    3948    }
    4049    /* reset Nrun if we are outside of intime */
    41     if (ranges[i].keep && !intime && ranges[i].Nmax && ranges[i].Nrun) {
     50    if (ranges[i].include && !intime && ranges[i].Nmax && ranges[i].Nrun) {
    4251      ranges[i].Nrun = 0;
    4352    }
    4453
    4554    /* is this a valid time? */
    46     valid = ranges[i].keep ? intime : !intime;
     55    if ( ranges[i].include &&  intime) include = TRUE;
     56    if (!ranges[i].include && !intime) exclude = TRUE;
    4757  }
     58
     59  if (Ninclude == 0) include = TRUE;
     60  valid = include && !exclude;
     61
    4862  return (valid);
    4963
     
    5367int BumpTimeRanges (TimeRange *ranges, int Nranges) {
    5468
    55   int i;
     69  int i, intime;
     70  time_t testtime;
    5671
     72  /* only increment the counter for ranges which are valid */
    5773  for (i = 0; i < Nranges; i++) {
    58     if (ranges[i].keep && ranges[i].Nmax) {
    59       ranges[i].Nrun ++;
     74    if (!ranges[i].Nmax) continue;
     75    if (!ranges[i].include) continue;
     76
     77    switch (ranges[i].type) {
     78      /* set the testtime */
     79      case RANGE_ABS:
     80        testtime = abstime;
     81        break;
     82      case RANGE_DAY:
     83        testtime = daytime;
     84        break;
     85      case RANGE_WEEK:
     86        testtime = weektime;
     87        break;
     88      default:
     89        abort ();
    6090    }
     91    intime = (testtime >= ranges[i].start) && (testtime <= ranges[i].stop);
     92
     93    /* reset Nrun if we are outside of intime */
     94    if (intime) ranges[i].Nrun ++;
    6195  }
    6296  return (TRUE);
Note: See TracChangeset for help on using the changeset viewer.