22 #include <plugins/openprs/mod_utils.h> 24 #include <utils/time/time.h> 26 #include <default-hook.h> 27 #include <oprs-rerror_f-pub.h> 31 pred_time_lt(TermList terms)
33 Term *t1_sec, *t1_usec, *t2_sec, *t2_usec;
34 t1_sec = (Term *)get_list_pos(terms, 1);
35 t1_usec = (Term *)get_list_pos(terms, 2);
36 t2_sec = (Term *)get_list_pos(terms, 3);
37 t2_usec = (Term *)get_list_pos(terms, 4);
39 long long int t1_sec_val, t1_usec_val, t2_sec_val, t2_usec_val;
40 if (t1_sec->type == LONG_LONG) {
41 t1_sec_val = t1_sec->u.llintval;
42 }
else if (t1_sec->type == INTEGER) {
43 t1_sec_val = t1_sec->u.intval;
45 fprintf(stderr,
"time-lt: t1_sec neither of type integer nor long long\n");
48 if (t1_usec->type == LONG_LONG) {
49 t1_usec_val = t1_usec->u.llintval;
50 }
else if (t1_usec->type == INTEGER) {
51 t1_usec_val = t1_usec->u.intval;
53 fprintf(stderr,
"time-lt: t1_usec neither of type integer nor long long\n");
56 if (t2_sec->type == LONG_LONG) {
57 t2_sec_val = t2_sec->u.llintval;
58 }
else if (t2_sec->type == INTEGER) {
59 t2_sec_val = t2_sec->u.intval;
61 fprintf(stderr,
"time-lt: t2_sec neither of type integer nor long long\n");
64 if (t2_usec->type == LONG_LONG) {
65 t2_usec_val = t2_usec->u.llintval;
66 }
else if (t2_usec->type == INTEGER) {
67 t2_usec_val = t2_usec->u.intval;
69 fprintf(stderr,
"time-lt: t2_usec neither of type integer nor long long\n");
73 return ((t1_sec_val < t2_sec_val) || (t1_sec_val == t2_sec_val && t1_usec_val < t2_usec_val));
79 pred_time_eq(TermList terms)
81 Term *t1_sec, *t1_usec, *t2_sec, *t2_usec;
82 t1_sec = (Term *)get_list_pos(terms, 1);
83 t1_usec = (Term *)get_list_pos(terms, 2);
84 t2_sec = (Term *)get_list_pos(terms, 3);
85 t2_usec = (Term *)get_list_pos(terms, 4);
87 if (t1_sec->type != LONG_LONG || t1_usec->type != LONG_LONG ||
88 t2_sec->type != LONG_LONG || t2_usec->type != LONG_LONG)
90 fprintf(stderr,
"time-eq: time values not (all) of type integer (types %i %i %i %i)\n",
91 t1_sec->type, t1_usec->type, t2_sec->type, t2_usec->type);
98 if (t1_sec->u.intval == t2_sec->u.intval && t1_usec->u.intval == t2_usec->u.intval)
109 pred_time_neq(TermList terms)
111 Term *t1_sec, *t1_usec, *t2_sec, *t2_usec;
112 t1_sec = (Term *)get_list_pos(terms, 1);
113 t1_usec = (Term *)get_list_pos(terms, 2);
114 t2_sec = (Term *)get_list_pos(terms, 3);
115 t2_usec = (Term *)get_list_pos(terms, 4);
117 if (t1_sec->type != LONG_LONG || t1_usec->type != LONG_LONG ||
118 t2_sec->type != LONG_LONG || t2_usec->type != LONG_LONG)
120 fprintf(stderr,
"time-neq: time values not (all) of type integer (types %i %i %i %i)\n",
121 t1_sec->type, t1_usec->type, t2_sec->type, t2_usec->type);
130 if ((t1_sec->u.intval != t2_sec->u.intval) ||
131 (t1_sec->u.intval == t2_sec->u.intval && t1_usec->u.intval != t2_usec->u.intval))
142 pred_timeout(TermList terms)
144 Term *t1_sec, *t1_usec, *t2_sec, *t2_usec, *interval;
145 t1_sec = (Term *)get_list_pos(terms, 1);
146 t1_usec = (Term *)get_list_pos(terms, 2);
147 t2_sec = (Term *)get_list_pos(terms, 3);
148 t2_usec = (Term *)get_list_pos(terms, 4);
149 interval = (Term *)get_list_pos(terms, 5);
151 if (t1_sec->type != LONG_LONG || t1_usec->type != LONG_LONG ||
152 t2_sec->type != LONG_LONG || t2_usec->type != LONG_LONG ||
153 (interval->type != LONG_LONG && interval->type != FLOAT && interval->type != INTEGER))
155 fprintf(stderr,
"timeout: time values not (all) of type LONG_LONG (types %i %i %i %i)\n",
156 t1_sec->type, t1_usec->type, t2_sec->type, t2_usec->type);
160 double compare_val = 0;
161 if (interval->type == LONG_LONG) {
162 compare_val = interval->u.llintval;
163 }
else if (interval->type == INTEGER) {
164 compare_val = interval->u.intval;
165 }
else if (interval->type == FLOAT) {
166 compare_val = *interval->u.doubleptr;
170 t2_sec->u.llintval, t2_usec->u.llintval) > compare_val);
175 action_set_idle_looptime(TermList terms)
177 Term *t_sec, *t_usec;
179 t_sec = (Term *)get_list_pos(terms, 1);
180 t_usec = (Term *)get_list_pos(terms, 2);
182 if ((t_sec->type != INTEGER && t_sec->type != LONG_LONG) ||
183 (t_usec->type != INTEGER && t_usec->type != LONG_LONG))
185 fprintf(stderr,
"time-set-looptime: time values not (all) of type " 186 "integer (types %i %i)\n", t_sec->type, t_usec->type);
190 if (t_sec->type == INTEGER) {
191 main_loop_pool_sec = t_sec->u.intval;
192 }
else if (t_sec->type == LONG_LONG) {
193 main_loop_pool_sec = t_sec->u.llintval;
196 if (t_usec->type == INTEGER) {
197 main_loop_pool_usec = t_usec->u.intval;
198 }
else if (t_usec->type == LONG_LONG) {
199 main_loop_pool_usec = t_usec->u.llintval;
202 printf(
"Setting idle loop time: %li sec %li usec\n", main_loop_pool_sec, main_loop_pool_usec);
211 printf(
"*** LOADING mod_time\n");
212 make_and_declare_eval_pred(
"time-lt", pred_time_lt, 4, TRUE);
213 make_and_declare_eval_pred(
"time-eq", pred_time_eq, 4, TRUE);
214 make_and_declare_eval_pred(
"time-neq", pred_time_neq, 4, TRUE);
215 make_and_declare_eval_pred(
"timeout", pred_timeout, 5, TRUE);
216 make_and_declare_action(
"time-set-idle-looptime", action_set_idle_looptime, 2);
double time_diff_sec(const timeval &a, const timeval &b)
Calculate time difference of two time structs.