blob: 0ebed7137d0edffa56274d49f7ecd8091e739776 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include "ejIntrn.h"
2#include "wsIntrn.h"
3
4
5typedef struct {
6 void (*routine)(void *arg, int id);
7 void *arg;
8 time_t at;
9 int schedid;
10} sched_t;
11
12
13static sched_t **sched;
14static int schedMax;
15
16
17void emfUnschedCallback(int schedid)
18{
19 sched_t *s;
20
21 if (sched == NULL || schedid == -1 || schedid >= schedMax ||
22 (s = sched[schedid]) == NULL) {
23 return;
24 }
25 bfree(B_L, s);
26 schedMax = hFree((void***) &sched, schedid);
27}
28
29
30#if 0
31int scriptEval(int engine, char_t *cmd, char_t **result, int chan)
32{
33 int ejid;
34
35 if (engine == EMF_SCRIPT_EJSCRIPT) {
36 ejid = (int) chan;
37
38 if (ejEval(ejid, cmd, result) ) {
39 return 0;
40 } else {
41 return -1;
42 }
43 }
44 return -1;
45}
46#endif
47
48
49int emfSchedCallback(int delay, emfSchedProc *proc, void *arg)
50{
51 sched_t *s;
52 int schedid;
53
54 if ((schedid = hAllocEntry((void***) &sched, &schedMax,
55 sizeof(sched_t))) < 0) {
56 return -1;
57 }
58 s = sched[schedid];
59 s->arg = arg;
60 s->routine = proc;
61 s->at = ((delay + 500) / 1000) + time(0);
62 s->schedid = schedid;
63
64 return schedid;
65}
66
67int strcmpci(char_t *s1, char_t *s2)
68{
69 int rc;
70
71 a_assert(s1 && s2);
72 if (s1 == NULL || s2 == NULL) {
73 return 0;
74 }
75
76 if (s1 == s2) {
77 return 0;
78 }
79
80 do {
81 rc = gtolower(*s1) - gtolower(*s2);
82 if (*s1 == '\0') {
83 break;
84 }
85 s1++;
86 s2++;
87 } while (rc == 0);
88 return rc;
89}
90
91void emfSchedProcess()
92{
93 sched_t *s;
94 int schedid;
95 static int next = 0;
96
97
98 if (schedMax <= 0) {
99 return;
100 }
101
102 if (next >= schedMax) {
103 next = 0;
104 }
105
106 schedid = next;
107 while(1) {
108 if ((s = sched[schedid]) != NULL && (int)s->at <= (int)time(0)) {
109 {
110 sched_t *s;
111
112 a_assert(0 <= schedid && schedid < schedMax);
113 s = sched[schedid];
114 a_assert(s);
115
116 (s->routine)(s->arg, s->schedid);
117 }
118 next = schedid + 1;
119 return;
120 }
121 if (++schedid >= schedMax) {
122 schedid = 0;
123 }
124 if (schedid == next) {
125
126 return;
127 }
128 };
129}
130
131void emfReschedCallback(int schedid, int delay)
132{
133 sched_t *s;
134
135 if (sched == NULL || schedid == -1 || schedid >= schedMax ||
136 (s = sched[schedid]) == NULL) {
137 return;
138 }
139 s->at = ((delay + 500) / 1000) + time(0);
140}
141