Changeset 8192
- Timestamp:
- Aug 5, 2006, 1:39:43 PM (20 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 9 edited
-
cmd.data/queuedrop.c (modified) (2 diffs)
-
cmd.data/queuepop.c (modified) (1 diff)
-
include/convert.h (modified) (1 diff)
-
include/pantasks.h (modified) (1 diff)
-
lib.data/convert.c (modified) (1 diff)
-
pantasks/CheckTimeRanges.c (modified) (4 diffs)
-
pantasks/TaskOps.c (modified) (4 diffs)
-
pantasks/task.c (modified) (2 diffs)
-
pantasks/task_trange.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/queuedrop.c
r8177 r8192 3 3 int queuedrop (int argc, char **argv) { 4 4 5 int N, Key; 5 int N; 6 char *Key; 6 7 char *var; 7 8 char *line; … … 9 10 Queue *queue; 10 11 11 Key = -1;12 Key = NULL; 12 13 if ((N = get_argument (argc, argv, "-key"))) { 13 14 remove_argument (N, &argc, argv); 14 Key = atoi(argv[N]);15 Key = strcreate (argv[N]); 15 16 remove_argument (N, &argc, argv); 16 17 Value = strcreate (argv[N]); 17 18 remove_argument (N, &argc, argv); 18 19 } 19 20 20 21 21 if ((argc != 2) || (Key == -1)) { -
trunk/Ohana/src/opihi/cmd.data/queuepop.c
r8190 r8192 25 25 remove_argument (N, &argc, argv); 26 26 } 27 28 27 29 28 if (argc != 2) { -
trunk/Ohana/src/opihi/include/convert.h
r4810 r8192 15 15 int day_to_sec PROTO((char *string, time_t *second)); 16 16 int hms_to_sec PROTO((char *string, time_t *second)); 17 char *sec_to_hms PROTO((time_t second)); 18 char *sec_to_day PROTO((time_t second)); 17 19 18 20 char *meade_deg_to_str PROTO((double deg)); -
trunk/Ohana/src/opihi/include/pantasks.h
r8191 r8192 51 51 time_t stop; 52 52 char type; 53 char keep;53 char include; 54 54 int Nmax; 55 55 int Nrun; -
trunk/Ohana/src/opihi/lib.data/convert.c
r4810 r8192 116 116 } 117 117 118 /***** convert seconds to HH:MM:SS ****/ 119 char *sec_to_hms (time_t second) { 120 121 struct tm *gmt; 122 char *line; 123 124 ALLOCATE (line, char, 64); 125 gmt = gmtime (&second); 126 sprintf (line, "%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 127 return (line); 128 } 129 130 /***** convert seconds to Day@HH:MM:SS ****/ 131 char *sec_to_day (time_t second) { 132 133 struct tm *gmt; 134 char *line; 135 136 ALLOCATE (line, char, 64); 137 gmt = gmtime (&second); 138 switch (gmt[0].tm_wday) { 139 case 0: 140 sprintf (line, "Sun@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 141 break; 142 case 1: 143 sprintf (line, "Mon@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 144 break; 145 case 2: 146 sprintf (line, "Tue@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 147 break; 148 case 3: 149 sprintf (line, "Wed@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 150 break; 151 case 4: 152 sprintf (line, "Thu@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 153 break; 154 case 5: 155 sprintf (line, "Fri@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 156 break; 157 case 6: 158 sprintf (line, "Sat@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec); 159 break; 160 } 161 return (line); 162 } 163 118 164 int hh_hm (double hh, int *hr, double *mn) { 119 165 -
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); -
trunk/Ohana/src/opihi/pantasks/TaskOps.c
r8129 r8192 52 52 void ListTasks (int verbose) { 53 53 54 int i, valid; 54 int i, j, valid; 55 char *start, *stop; 55 56 56 57 gprint (GP_LOG, "\n"); … … 78 79 gprint (GP_LOG, " spawn period: %f, polling period: %f, timeout period: %f\n", 79 80 tasks[i][0].exec_period, tasks[i][0].poll_period, tasks[i][0].timeout_period); 81 for (j = 0; j < tasks[i][0].Nranges; j++) { 82 switch (tasks[i][0].ranges[j].type) { 83 case RANGE_ABS: 84 start = sec_to_date (tasks[i][0].ranges[j].start); 85 stop = sec_to_date (tasks[i][0].ranges[j].stop); 86 break; 87 case RANGE_DAY: 88 start = sec_to_hms (tasks[i][0].ranges[j].start); 89 stop = sec_to_hms (tasks[i][0].ranges[j].stop); 90 break; 91 case RANGE_WEEK: 92 start = sec_to_day (tasks[i][0].ranges[j].start); 93 stop = sec_to_day (tasks[i][0].ranges[j].stop); 94 break; 95 default: 96 abort (); 97 } 98 if (tasks[i][0].ranges[j].include) { 99 gprint (GP_LOG, " active : %s - %s", start, stop); 100 if (tasks[i][0].ranges[j].Nmax) gprint (GP_LOG, " (%d of %d)", tasks[i][0].ranges[j].Nrun, tasks[i][0].ranges[j].Nmax); 101 gprint (GP_LOG, "\n"); 102 } else { 103 gprint (GP_LOG, " avoid : %s - %s\n", start, stop); 104 } 105 free (start); 106 free (stop); 107 } 80 108 if (tasks[i][0].host == NULL) { 81 109 gprint (GP_LOG, " task runs locally\n"); … … 99 127 int ShowTask (char *name) { 100 128 101 int i; 129 int i, j; 130 char *start, *stop 102 131 Task *task; 103 132 … … 138 167 periods: 139 168 gprint (GP_LOG, " time periods: exec: %f poll: %f timeout: %f\n", 140 task[0].exec_period, task[0].poll_period, task[0].timeout_period); 169 task[0].exec_period, task[0].poll_period, task[0].timeout_period); 170 171 for (j = 0; j < tasks[i][0].Nranges; j++) { 172 switch (tasks[i][0].ranges[j].type) { 173 case RANGE_ABS: 174 start = sec_to_date (tasks[i][0].ranges[j].start); 175 stop = sec_to_date (tasks[i][0].ranges[j].stop); 176 break; 177 case RANGE_DAY: 178 start = sec_to_hms (tasks[i][0].ranges[j].start); 179 stop = sec_to_hms (tasks[i][0].ranges[j].stop); 180 break; 181 case RANGE_WEEK: 182 start = sec_to_day (tasks[i][0].ranges[j].start); 183 stop = sec_to_day (tasks[i][0].ranges[j].stop); 184 break; 185 default: 186 abort (); 187 } 188 if (tasks[i][0].ranges[j].include) { 189 gprint (GP_LOG, " active : %s - %s", start, stop); 190 if (tasks[i][0].ranges[j].Nmax) gprint (GP_LOG, " (%d of %d)", tasks[i][0].ranges[j].Nrun, tasks[i][0].ranges[j].Nmax); 191 gprint (GP_LOG, "\n"); 192 } else { 193 gprint (GP_LOG, " avoid : %s - %s\n", start, stop); 194 } 195 free (start); 196 free (stop); 197 } 141 198 142 199 gprint (GP_LOG, "\n pre-execute macro\n"); -
trunk/Ohana/src/opihi/pantasks/task.c
r8129 r8192 23 23 if ((N = get_argument (argc, argv, "-show"))) { 24 24 remove_argument (N, &argc, argv); 25 if (argc != 2) goto usage; 25 26 ShowTask (argv[N]); 26 27 return (TRUE); 27 28 } 28 29 29 if (argc != 2) { 30 gprint (GP_ERR, "USAGE: task <name>\n"); 31 gprint (GP_ERR, " (enter commands & task functions; end with the word 'END')\n"); 32 return (FALSE); 33 } 30 if (argc != 2) goto usage; 34 31 35 32 task = FindTask (argv[1]); … … 108 105 } 109 106 } 110 /* cannot ever reach here */ 107 108 usage: 109 gprint (GP_ERR, "USAGE: task -list\n"); 110 gprint (GP_ERR, "USAGE: task -longlist\n"); 111 gprint (GP_ERR, "USAGE: task -show (task)\n"); 112 gprint (GP_ERR, "USAGE: task <name>\n"); 113 gprint (GP_ERR, " (enter commands & task functions; end with the word 'END')\n"); 111 114 return (FALSE); 112 115 } -
trunk/Ohana/src/opihi/pantasks/task_trange.c
r8191 r8192 7 7 TimeRange range; 8 8 9 /* add a -reset option?10 if ( N = get_argument (argc, argv, "-reset")) {9 /* reset the tranges for the current task */ 10 if ((N = get_argument (argc, argv, "-reset"))) { 11 11 remove_argument (N, &argc, argv); 12 } */ 12 if (argc != 1) goto usage; 13 14 task = GetNewTask (); 15 if (task == NULL) { 16 gprint (GP_ERR, "ERROR: not defining or running a task\n"); 17 return (FALSE); 18 } 19 20 task[0].Nranges = 0; 21 REALLOCATE (task[0].ranges, TimeRange, 1); 22 return (TRUE); 23 } 13 24 14 25 range.Nmax = 0; 15 26 range.Nrun = 0; 16 if ( N = get_argument (argc, argv, "-nmax")) {27 if ((N = get_argument (argc, argv, "-nmax"))) { 17 28 remove_argument (N, &argc, argv); 18 29 range.Nmax = atoi (argv[N]); … … 22 33 /* keep = true means the time range defines a valid time range 23 34 keep = false means the time range defines an invalid range */ 24 range. keep= TRUE;35 range.include = TRUE; 25 36 if ((N = get_argument (argc, argv, "-exclude"))) { 26 37 remove_argument (N, &argc, argv); 27 range. keep= FALSE;38 range.include = FALSE; 28 39 } 29 40 … … 38 49 /* test for Mon[@HH:MM:SS] - both must match */ 39 50 if (day_to_sec (argv[1], &range.start)) { 40 if (!day_to_sec (argv[2], &range.stop)) goto usage; 51 if (!day_to_sec (argv[2], &range.stop)) { 52 gprint (GP_ERR, "invalid day/time %s\n", argv[2]); 53 goto usage; 54 } 41 55 range.type = RANGE_WEEK; 42 56 goto valid; … … 45 59 /* test for HH:MM:SS */ 46 60 if (hms_to_sec (argv[1], &range.start)) { 47 if (!hms_to_sec (argv[2], &range.stop)) goto usage; 61 if (!hms_to_sec (argv[2], &range.stop)) { 62 gprint (GP_ERR, "invalid time %s\n", argv[2]); 63 goto usage; 64 } 48 65 range.type = RANGE_DAY; 49 66 goto valid; … … 53 70 /* test for YYYY/MM/DD - both must match */ 54 71 if (str_to_time (argv[1], &range.start)) { 55 if (!str_to_time (argv[2], &range.stop)) goto usage; 72 if (!str_to_time (argv[2], &range.stop)) { 73 gprint (GP_ERR, "invalid date/time %s\n", argv[2]); 74 goto usage; 75 } 56 76 range.type = RANGE_ABS; 57 77 goto valid; … … 68 88 69 89 usage: 70 gprint (GP_ERR, "USAGE: trange start end\n"); 90 gprint (GP_ERR, "USAGE: trange start end [-nmax N]\n"); 91 gprint (GP_ERR, "USAGE: trange -reset\n"); 71 92 return (FALSE); 72 93 }
Note:
See TracChangeset
for help on using the changeset viewer.
