1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <unistd.h>
4: #include <fcntl.h>
5: #include <signal.h>
6: #include <sys/types.h>
7: #include <sys/event.h>
8: #include <sys/stat.h>
9: #include <sys/signal.h>
10: #include <netinet/in.h>
11: #include <aitsched.h>
12:
13: intptr_t Kill;
14:
15: void *event(sched_task_t *arg)
16: {
17: printf("Event::\n");
18: return NULL;
19: }
20:
21: void *eventlo(sched_task_t *arg)
22: {
23: printf("EventLOW::\n");
24: return NULL;
25: }
26:
27: void *timer(sched_task_t *arg)
28: {
29: printf("Timer %p sec::\n", TASK_ARG(arg));
30: return NULL;
31: }
32:
33: void *alarmz(sched_task_t *arg)
34: {
35: printf("Alarm %ld sec::\n", (u_long) TASK_ARG(arg));
36: return NULL;
37: }
38:
39: void *node(sched_task_t *arg)
40: {
41: printf("Node %s fflags 0x%X\n", (char*) TASK_ARG(arg), (u_int) TASK_DATLEN(arg));
42: return NULL;
43: }
44:
45: void *proc(sched_task_t *arg)
46: {
47: printf("Proc pid=%ld fflags 0x%X data %p\n", TASK_VAL(arg), (u_int) TASK_DATLEN(arg),
48: TASK_DATA(arg));
49: return NULL;
50: }
51:
52: void *sigz(sched_task_t *arg)
53: {
54: printf("Signal signal=%ld\n", TASK_VAL(arg));
55: return NULL;
56: }
57:
58: #ifdef EVFILT_USER
59: void *user(sched_task_t *arg)
60: {
61: printf("User trigger id %ld fflags %d\n", TASK_VAL(arg), TASK_DATLEN(arg) & NOTE_FFLAGSMASK);
62: return NULL;
63: }
64: #endif
65:
66: void *once(sched_task_t *arg)
67: {
68: printf("once::\n");
69: return NULL;
70: }
71:
72: void sig(int s)
73: {
74: switch (s) {
75: case SIGTERM:
76: Kill++;
77: break;
78: case SIGUSR1:
79: break;
80: }
81: }
82:
83: int
84: main(int argc, char **argv)
85: {
86: sched_root_task_t *root;
87: struct timespec ts = { 20, 0 };
88: // struct timespec p = { 0, 10000000 };
89: int f = 0;
90: struct sigaction sa;
91: #ifdef EVFILT_USER
92: sched_task_t *t[4];
93: #endif
94:
95: sa.sa_handler = sig;
96: sigemptyset(&sa.sa_mask);
97: sigaction(SIGTERM, &sa, NULL);
98: sigaction(SIGUSR1, &sa, NULL);
99:
100: root = schedBegin();
101: if (!root) {
102: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
103: return 1;
104: }
105:
106: if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
107: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
108: return 4;
109: } else
110: ts.tv_sec = 15;
111: if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
112: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
113: return 4;
114: } else
115: ts.tv_sec = 10;
116:
117: if (!schedEvent(root, event, "piuk", 1234, NULL, 0)) {
118: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
119: return 2;
120: }
121:
122: if (!schedEventLo(root, eventlo, "piuk", 1111, NULL, 0)) {
123: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
124: return 3;
125: }
126:
127: if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
128: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
129: return 4;
130: }
131:
132: if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, NULL, 0)) {
133: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
134: return 5;
135: } else {
136: ts.tv_sec = 3;
137: ts.tv_nsec = 500000000;
138: }
139:
140: if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 1, 0)) {
141: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
142: return 5;
143: }
144: if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 2, 0)) {
145: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
146: return 5;
147: } else {
148: ts.tv_sec = 0;
149: ts.tv_nsec = 700000000;
150: }
151: if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 3, 0)) {
152: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
153: return 5;
154: }
155:
156: #ifdef EVFILT_USER
157: if (!(t[0] = schedUser(root, user, NULL, 42, 0, 0))) {
158: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
159: return 6;
160: }
161: if (!(t[1] = schedUser(root, user, NULL, 1, 0, 73))) {
162: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
163: return 6;
164: }
165: if (!(t[2] = schedUser(root, user, NULL, 0xaa, 0, NOTE_FFAND | 0xaa))) {
166: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
167: return 6;
168: }
169: if (!(t[3] = schedUser(root, user, NULL, -1, 0, NOTE_FFCOPY | 1003))) {
170: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
171: return 6;
172: }
173: #endif
174:
175: if (argc > 1)
176: if (!schedProc(root, proc, NULL, atoi(argv[1]), 0, 0)) {
177: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
178: return 7;
179: }
180: if (argc > 2) {
181: f = open(argv[2], O_RDWR);
182: if (f == -1) {
183: perror("open()");
184: return 8;
185: }
186: if (!schedNode(root, node, argv[2], f, 0, 0)) {
187: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
188: close(f);
189: return 8;
190: }
191: }
192:
193: #ifdef EVFILT_USER
194: schedTrigger(t[3]);
195: schedTrigger(t[1]);
196: #endif
197:
198: if (!schedSignal(root, sigz, NULL, SIGUSR1, 0, 0)) {
199: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
200: close(f);
201: return 9;
202: }
203:
204: #ifdef EVFILT_USER
205: schedTrigger(t[2]);
206: schedTrigger(t[0]);
207: #endif
208:
209: schedCallOnce(root, once, "000000", 42, NULL, 0);
210:
211: printf("read_queue=%d timer_queue=%d\n",
212: ROOT_QUEUE_EMPTY(root, read), ROOT_QUEUE_EMPTY(root, timer));
213:
214: // schedPolling(root, &p, NULL);
215: schedRun(root, &Kill);
216: schedEnd(&root);
217:
218: if (f > 2)
219: close(f);
220: return 0;
221: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>