22 #include <plugins/openprs/mod_utils.h> 23 #include <utils/time/time.h> 25 #include <default-hook.h> 26 #include <oprs-rerror_f-pub.h> 29 pred_time_lt(TermList terms)
31 Term *t1_sec, *t1_usec, *t2_sec, *t2_usec;
32 t1_sec = (Term *)get_list_pos(terms, 1);
33 t1_usec = (Term *)get_list_pos(terms, 2);
34 t2_sec = (Term *)get_list_pos(terms, 3);
35 t2_usec = (Term *)get_list_pos(terms, 4);
37 long long int t1_sec_val, t1_usec_val, t2_sec_val, t2_usec_val;
38 if (t1_sec->type == LONG_LONG) {
39 t1_sec_val = t1_sec->u.llintval;
40 }
else if (t1_sec->type == INTEGER) {
41 t1_sec_val = t1_sec->u.intval;
43 fprintf(stderr,
"time-lt: t1_sec neither of type integer nor long long\n");
46 if (t1_usec->type == LONG_LONG) {
47 t1_usec_val = t1_usec->u.llintval;
48 }
else if (t1_usec->type == INTEGER) {
49 t1_usec_val = t1_usec->u.intval;
51 fprintf(stderr,
"time-lt: t1_usec neither of type integer nor long long\n");
54 if (t2_sec->type == LONG_LONG) {
55 t2_sec_val = t2_sec->u.llintval;
56 }
else if (t2_sec->type == INTEGER) {
57 t2_sec_val = t2_sec->u.intval;
59 fprintf(stderr,
"time-lt: t2_sec neither of type integer nor long long\n");
62 if (t2_usec->type == LONG_LONG) {
63 t2_usec_val = t2_usec->u.llintval;
64 }
else if (t2_usec->type == INTEGER) {
65 t2_usec_val = t2_usec->u.intval;
67 fprintf(stderr,
"time-lt: t2_usec neither of type integer nor long long\n");
71 return ((t1_sec_val < t2_sec_val) || (t1_sec_val == t2_sec_val && t1_usec_val < t2_usec_val));
75 pred_time_eq(TermList terms)
77 Term *t1_sec, *t1_usec, *t2_sec, *t2_usec;
78 t1_sec = (Term *)get_list_pos(terms, 1);
79 t1_usec = (Term *)get_list_pos(terms, 2);
80 t2_sec = (Term *)get_list_pos(terms, 3);
81 t2_usec = (Term *)get_list_pos(terms, 4);
83 if (t1_sec->type != LONG_LONG || t1_usec->type != LONG_LONG || t2_sec->type != LONG_LONG
84 || t2_usec->type != LONG_LONG) {
86 "time-eq: time values not (all) of type integer (types %i %i %i %i)\n",
97 if (t1_sec->u.intval == t2_sec->u.intval && t1_usec->u.intval == t2_usec->u.intval) {
105 pred_time_neq(TermList terms)
107 Term *t1_sec, *t1_usec, *t2_sec, *t2_usec;
108 t1_sec = (Term *)get_list_pos(terms, 1);
109 t1_usec = (Term *)get_list_pos(terms, 2);
110 t2_sec = (Term *)get_list_pos(terms, 3);
111 t2_usec = (Term *)get_list_pos(terms, 4);
113 if (t1_sec->type != LONG_LONG || t1_usec->type != LONG_LONG || t2_sec->type != LONG_LONG
114 || t2_usec->type != LONG_LONG) {
116 "time-neq: time values not (all) of type integer (types %i %i %i %i)\n",
129 if (t1_sec->u.intval != t2_sec->u.intval || t1_usec->u.intval != t2_usec->u.intval) {
137 pred_timeout(TermList terms)
139 Term *t1_sec, *t1_usec, *t2_sec, *t2_usec, *interval;
140 t1_sec = (Term *)get_list_pos(terms, 1);
141 t1_usec = (Term *)get_list_pos(terms, 2);
142 t2_sec = (Term *)get_list_pos(terms, 3);
143 t2_usec = (Term *)get_list_pos(terms, 4);
144 interval = (Term *)get_list_pos(terms, 5);
146 if (t1_sec->type != LONG_LONG || t1_usec->type != LONG_LONG || t2_sec->type != LONG_LONG
147 || t2_usec->type != LONG_LONG
148 || (interval->type != LONG_LONG && interval->type != FLOAT && interval->type != INTEGER)) {
150 "timeout: time values not (all) of type LONG_LONG (types %i %i %i %i)\n",
158 double compare_val = 0;
159 if (interval->type == LONG_LONG) {
160 compare_val = interval->u.llintval;
161 }
else if (interval->type == INTEGER) {
162 compare_val = interval->u.intval;
163 }
else if (interval->type == FLOAT) {
164 compare_val = *interval->u.doubleptr;
168 t1_sec->u.llintval, t1_usec->u.llintval, t2_sec->u.llintval, t2_usec->u.llintval)
173 action_set_idle_looptime(TermList terms)
175 Term *t_sec, *t_usec;
177 t_sec = (Term *)get_list_pos(terms, 1);
178 t_usec = (Term *)get_list_pos(terms, 2);
180 if ((t_sec->type != INTEGER && t_sec->type != LONG_LONG)
181 || (t_usec->type != INTEGER && t_usec->type != LONG_LONG)) {
183 "time-set-looptime: time values not (all) of type " 184 "integer (types %i %i)\n",
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);
210 printf(
"*** LOADING mod_time\n");
211 make_and_declare_eval_pred(
"time-lt", pred_time_lt, 4, TRUE);
212 make_and_declare_eval_pred(
"time-eq", pred_time_eq, 4, TRUE);
213 make_and_declare_eval_pred(
"time-neq", pred_time_neq, 4, TRUE);
214 make_and_declare_eval_pred(
"timeout", pred_timeout, 5, TRUE);
215 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.