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 %d sec::\n", (int) 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), 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 %x\n", TASK_VAL(arg), TASK_DATLEN(arg),
48: (uintptr_t) 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: void *user(sched_task_t *arg)
59: {
60: printf("User trigger id %ld fflags %d\n", TASK_VAL(arg), TASK_DATLEN(arg) & NOTE_FFLAGSMASK);
61: return NULL;
62: }
63:
64: void *once(sched_task_t *arg)
65: {
66: printf("once::\n");
67: return NULL;
68: }
69:
70: void sig(int s)
71: {
72: switch (s) {
73: case SIGTERM:
74: Kill++;
75: break;
76: case SIGUSR1:
77: break;
78: }
79: }
80:
81: int
82: main(int argc, char **argv)
83: {
84: sched_root_task_t *root;
85: struct timespec ts = { 20, 0 };
86: // struct timespec p = { 0, 10000000 };
87: int f = 0;
88: struct sigaction sa;
89: #ifdef EVFILT_USER
90: sched_task_t *t[4];
91: #endif
92:
93: sa.sa_handler = sig;
94: sigemptyset(&sa.sa_mask);
95: sigaction(SIGTERM, &sa, NULL);
96: sigaction(SIGUSR1, &sa, NULL);
97:
98: root = schedBegin();
99: if (!root) {
100: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
101: return 1;
102: }
103:
104: if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
105: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
106: return 4;
107: } else
108: ts.tv_sec = 15;
109: if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
110: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
111: return 4;
112: } else
113: ts.tv_sec = 10;
114:
115: if (!schedEvent(root, event, "piuk", 1234, NULL, 0)) {
116: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
117: return 2;
118: }
119:
120: if (!schedEventLo(root, eventlo, "piuk", 1111, NULL, 0)) {
121: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
122: return 3;
123: }
124:
125: if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
126: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
127: return 4;
128: }
129:
130: if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, NULL, 0)) {
131: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
132: return 5;
133: } else {
134: ts.tv_sec = 3;
135: ts.tv_nsec = 500000000;
136: }
137:
138: if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 1, 0)) {
139: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
140: return 5;
141: }
142: if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 2, 0)) {
143: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
144: return 5;
145: } else {
146: ts.tv_sec = 0;
147: ts.tv_nsec = 700000000;
148: }
149: if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 3, 0)) {
150: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
151: return 5;
152: }
153:
154: #ifdef EVFILT_USER
155: if (!(t[0] = schedUser(root, user, NULL, 42, 0, 0))) {
156: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
157: return 6;
158: }
159: if (!(t[1] = schedUser(root, user, NULL, 1, 0, 73))) {
160: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
161: return 6;
162: }
163: if (!(t[2] = schedUser(root, user, NULL, 0xaa, 0, NOTE_FFAND | 0xaa))) {
164: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
165: return 6;
166: }
167: if (!(t[3] = schedUser(root, user, NULL, -1, 0, NOTE_FFCOPY | 1003))) {
168: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
169: return 6;
170: }
171: #endif
172:
173: if (argc > 1)
174: if (!schedProc(root, proc, NULL, atoi(argv[1]), 0, 0)) {
175: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
176: return 7;
177: }
178: if (argc > 2) {
179: f = open(argv[2], O_RDWR);
180: if (f == -1) {
181: perror("open()");
182: return 8;
183: }
184: if (!schedNode(root, node, argv[2], f, 0, 0)) {
185: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
186: close(f);
187: return 8;
188: }
189: }
190:
191: schedTrigger(t[3]);
192: schedTrigger(t[1]);
193:
194: if (!schedSignal(root, sigz, NULL, SIGUSR1, 0, 0)) {
195: printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
196: close(f);
197: return 9;
198: }
199:
200: schedTrigger(t[2]);
201: schedTrigger(t[0]);
202:
203: schedCallOnce(root, once, "000000", 42, NULL, 0);
204:
205: printf("read_queue=%d timer_queue=%d\n",
206: ROOT_QUEUE_EMPTY(root, read), ROOT_QUEUE_EMPTY(root, timer));
207:
208: // schedPolling(root, &p, NULL);
209: schedRun(root, &Kill);
210: schedEnd(&root);
211:
212: if (f > 2)
213: close(f);
214: return 0;
215: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>