Changeset 8192 for trunk/Ohana/src/opihi/pantasks/CheckTimeRanges.c
- Timestamp:
- Aug 5, 2006, 1:39:43 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pantasks/CheckTimeRanges.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pantasks/CheckTimeRanges.c
r8191 r8192 1 1 # 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 */ 5 static time_t daytime, weektime, abstime; 2 6 3 7 /* test if we meet all time range qualifications */ 4 8 int CheckTimeRanges (TimeRange *ranges, int Nranges) { 5 9 6 int i, intime, valid;7 time_t daytime, weektime, abstime,testtime;10 int i, intime, Ninclude, include, exclude, valid; 11 time_t testtime; 8 12 struct timeval now; 9 13 struct tm Now; … … 16 20 abstime = now.tv_sec; 17 21 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 20 29 switch (ranges[i].type) { 21 30 /* set the testtime */ … … 35 44 36 45 /* 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) { 38 47 if (ranges[i].Nrun >= ranges[i].Nmax) return (FALSE); 39 48 } 40 49 /* 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) { 42 51 ranges[i].Nrun = 0; 43 52 } 44 53 45 54 /* 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; 47 57 } 58 59 if (Ninclude == 0) include = TRUE; 60 valid = include && !exclude; 61 48 62 return (valid); 49 63 } … … 53 67 int BumpTimeRanges (TimeRange *ranges, int Nranges) { 54 68 55 int i; 69 int i, intime; 70 time_t testtime; 56 71 72 /* only increment the counter for ranges which are valid */ 57 73 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 (); 60 90 } 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 ++; 61 95 } 62 96 return (TRUE);
Note:
See TracChangeset
for help on using the changeset viewer.
