00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include <pthread.h>
00048 #include "command_line_parser.h"
00049 #include "timer.h"
00050 #include "scheduler.h"
00051 #include "socket_comm.h"
00052 #include "global.h"
00053
00054 int scheduler (command_options_t *options) {
00055 enum {INIT,WAIT,EXECUTE};
00056 static int sch_state=INIT;
00057 static timer_struct_t ts;
00058 static pthread_t thread;
00059 int ret_val=0;
00060
00061 switch (sch_state) {
00062 case INIT:
00063 ts.timer_period=TIMER_PERIOD_COUNTS;
00064 ts.timeout=0;
00065 pthread_create(&thread,NULL,periodic_thread,&ts);
00066 sch_state=WAIT;
00067 break;
00068 case WAIT:
00069 if (ts.timeout) {
00070 ts.timeout=0;
00071 sch_state=EXECUTE;
00072 }
00073 break;
00074 case EXECUTE:
00075 socket_comm(options);
00076 sch_state=WAIT;
00077 break;
00078 }
00079 return (ret_val);
00080 }
00081
00082
00083
00084
00085