--- libaitsched/example/test_time.c 2012/05/10 14:44:22 1.1.2.2 +++ libaitsched/example/test_time.c 2012/05/31 14:45:10 1.3.2.1 @@ -1,9 +1,10 @@ #include +#include #include #include #include #include -#include +#include #include #include @@ -23,10 +24,40 @@ void *eventlo(sched_task_t *arg) void *timer(sched_task_t *arg) { - printf("Timer %ld sec::\n", (intptr_t) TASK_ARG(arg)); + printf("Timer %d sec::\n", (int) TASK_ARG(arg)); return NULL; } +void *alarmz(sched_task_t *arg) +{ + printf("Alarm %ld sec::\n", (u_long) TASK_ARG(arg)); + return NULL; +} + +void *node(sched_task_t *arg) +{ + printf("Node %s\n", (char*) TASK_ARG(arg)); + return NULL; +} + +void *proc(sched_task_t *arg) +{ + printf("Proc pid=%ld\n", TASK_VAL(arg)); + return NULL; +} + +void *sigz(sched_task_t *arg) +{ + printf("Signal signal=%ld\n", TASK_VAL(arg)); + return NULL; +} + +void *user(sched_task_t *arg) +{ + printf("User trigger id %ld\n", TASK_VAL(arg)); + return NULL; +} + void *once(sched_task_t *arg) { printf("once::\n"); @@ -48,6 +79,7 @@ main(int argc, char **argv) sched_root_task_t *root; struct timespec ts = { 20, 0 }; // struct timespec p = { 0, 10000000 }; + int f = 0; signal(SIGTERM, sig); @@ -83,10 +115,63 @@ main(int argc, char **argv) return 4; } + if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, NULL, 0)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 5; + } else { + ts.tv_sec = 3; + ts.tv_nsec = 500000000; + } + + if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 1, 0)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 5; + } + if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 2, 0)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 5; + } else { + ts.tv_sec = 0; + ts.tv_nsec = 700000000; + } + if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 3, 0)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 5; + } + + if (!schedUser(root, user, NULL, 42, 0, 0)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 6; + } + + if (argc > 1) + if (!schedProc(root, proc, NULL, atoi(argv[1]), 0, 0)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + return 7; + } + if (argc > 2) { + f = open(argv[2], O_RDWR); + if (f == -1) { + perror("open()"); + return 8; + } + if (!schedNode(root, node, argv[2], f, 0, 0)) { + printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError()); + close(f); + return 8; + } + } + schedCallOnce(root, once, "000000", 42, NULL, 0); + printf("read_queue=%d timer_queue=%d\n", + ROOT_QUEUE_EMPTY(root, read), ROOT_QUEUE_EMPTY(root, timer)); + // schedPolling(root, &p, NULL); schedRun(root, &Kill); schedEnd(&root); + + if (f > 2) + close(f); return 0; }