Annotation of libaitsched/example/test_time.c, revision 1.3.2.2

1.2       misho       1: #include <stdio.h>
1.3.2.1   misho       2: #include <stdlib.h>
1.2       misho       3: #include <unistd.h>
                      4: #include <fcntl.h>
1.3.2.2 ! misho       5: #include <signal.h>
1.2       misho       6: #include <sys/types.h>
1.3.2.2 ! misho       7: #include <sys/event.h>
1.2       misho       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: {
1.3.2.1   misho      29:        printf("Timer %d sec::\n", (int) TASK_ARG(arg));
1.2       misho      30:        return NULL;
                     31: }
                     32: 
1.3       misho      33: void *alarmz(sched_task_t *arg)
                     34: {
1.3.2.1   misho      35:        printf("Alarm %ld sec::\n", (u_long) TASK_ARG(arg));
                     36:        return NULL;
                     37: }
                     38: 
                     39: void *node(sched_task_t *arg)
                     40: {
1.3.2.2 ! misho      41:        printf("Node %s fflags 0x%X\n", (char*) TASK_ARG(arg), TASK_DATLEN(arg));
1.3.2.1   misho      42:        return NULL;
                     43: }
                     44: 
                     45: void *proc(sched_task_t *arg)
                     46: {
1.3.2.2 ! misho      47:        printf("Proc pid=%ld fflags 0x%X data %x\n", TASK_VAL(arg), TASK_DATLEN(arg), 
        !            48:                        (uintptr_t) TASK_DATA(arg));
1.3.2.1   misho      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: {
1.3.2.2 ! misho      60:        printf("User trigger id %ld fflags %d\n", TASK_VAL(arg), TASK_DATLEN(arg) & NOTE_FFLAGSMASK);
1.3       misho      61:        return NULL;
                     62: }
                     63: 
1.2       misho      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;
1.3.2.2 ! misho      76:                case SIGUSR1:
        !            77:                        break;
1.2       misho      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 };
1.3.2.1   misho      87:        int f = 0;
1.3.2.2 ! misho      88:        struct sigaction sa;
        !            89:        sched_task_t *t[4];
1.2       misho      90: 
1.3.2.2 ! misho      91:        sa.sa_handler = sig;
        !            92:        sigemptyset(&sa.sa_mask);
        !            93:        sigaction(SIGTERM, &sa, NULL);
        !            94:        sigaction(SIGUSR1, &sa, NULL);
1.2       misho      95: 
                     96:        root = schedBegin();
                     97:        if (!root) {
                     98:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                     99:                return 1;
                    100:        }
                    101: 
                    102:        if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
                    103:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    104:                return 4;
                    105:        } else
                    106:                ts.tv_sec = 15;
                    107:        if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
                    108:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    109:                return 4;
                    110:        } else
                    111:                ts.tv_sec = 10;
                    112: 
                    113:        if (!schedEvent(root, event, "piuk", 1234, NULL, 0)) {
                    114:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    115:                return 2;
                    116:        }
                    117: 
                    118:        if (!schedEventLo(root, eventlo, "piuk", 1111, NULL, 0)) {
                    119:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    120:                return 3;
                    121:        }
                    122: 
                    123:        if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
                    124:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    125:                return 4;
                    126:        }
                    127: 
1.3       misho     128:        if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, NULL, 0)) {
                    129:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    130:                return 5;
                    131:        } else {
                    132:                ts.tv_sec = 3;
                    133:                ts.tv_nsec = 500000000;
                    134:        }
                    135: 
                    136:        if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 1, 0)) {
                    137:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    138:                return 5;
                    139:        }
                    140:        if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 2, 0)) {
                    141:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    142:                return 5;
                    143:        } else {
                    144:                ts.tv_sec = 0;
                    145:                ts.tv_nsec = 700000000;
                    146:        }
                    147:        if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 3, 0)) {
                    148:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    149:                return 5;
                    150:        }
                    151: 
1.3.2.2 ! misho     152:        if (!(t[0] = schedUser(root, user, NULL, 42, 0, 0))) {
        !           153:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
        !           154:                return 6;
        !           155:        }
        !           156:        if (!(t[1] = schedUser(root, user, NULL, 1, 0, 73))) {
        !           157:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
        !           158:                return 6;
        !           159:        }
        !           160:        if (!(t[2] = schedUser(root, user, NULL, 0xaa, 0, NOTE_FFAND | 0xaa))) {
        !           161:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
        !           162:                return 6;
        !           163:        }
        !           164:        if (!(t[3] = schedUser(root, user, NULL, -1, 0, NOTE_FFCOPY | 1003))) {
1.3.2.1   misho     165:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    166:                return 6;
                    167:        }
                    168: 
                    169:        if (argc > 1)
                    170:                if (!schedProc(root, proc, NULL, atoi(argv[1]), 0, 0)) {
                    171:                        printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    172:                        return 7;
                    173:                }
                    174:        if (argc > 2) {
                    175:                f = open(argv[2], O_RDWR);
                    176:                if (f == -1) {
                    177:                        perror("open()");
                    178:                        return 8;
                    179:                }
                    180:                if (!schedNode(root, node, argv[2], f, 0, 0)) {
                    181:                        printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                    182:                        close(f);
                    183:                        return 8;
                    184:                }
                    185:        }
                    186: 
1.3.2.2 ! misho     187:        schedTrigger(t[3]);
        !           188:        schedTrigger(t[1]);
        !           189: 
        !           190:        if (!schedSignal(root, sigz, NULL, SIGUSR1, 0, 0)) {
        !           191:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
        !           192:                close(f);
        !           193:                return 9;
        !           194:        }
        !           195: 
        !           196:        schedTrigger(t[2]);
        !           197:        schedTrigger(t[0]);
        !           198: 
1.2       misho     199:        schedCallOnce(root, once, "000000", 42, NULL, 0);
                    200: 
                    201:        printf("read_queue=%d timer_queue=%d\n", 
                    202:                        ROOT_QUEUE_EMPTY(root, read), ROOT_QUEUE_EMPTY(root, timer));
                    203: 
                    204: //     schedPolling(root, &p, NULL);
                    205:        schedRun(root, &Kill);
                    206:        schedEnd(&root);
1.3.2.1   misho     207: 
                    208:        if (f > 2)
                    209:                close(f);
1.2       misho     210:        return 0;
                    211: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>