00001 Train::Train() {
00002 train_ID = -1;
00003 initfunctions();
00004 }
00005
00006 void Train::initfunctions() {
00007
00008
00009 *functions[0] = Train::nop( ... );
00010 *functions[1] = Train::change_speed( ... );
00011 *functions[2] = Train::change_direction( ... );
00012 }
00013
00014 void Train::run()
00015 {
00016 pid_t pid;
00017 int task = 0;
00018
00019 while(1)
00020 {
00021 const char* response;
00022
00023 if((pid = Receive(0, buffer_, sizeof(buffer_))) < 0)
00024 {
00025
00026 printf("ERROR--code %d\n", errno);
00027 return;
00028 } else {
00029 task = buffer_->action;
00030 if ( task >= 0 && task < 26 ) {
00031 functions[task]( buffer_ );
00032 } else {
00033 printf("Illegal task message request: %d", task );
00034 }
00035 }
00036
00037 printf("Got from %d: %s\n", pid, buffer_);
00038
00039 Reply(pid, response, strlen(response)+1);
00040 }
00041
00042 Reply(pid, ok_response, sizeof(ok_response));
00043 }
00044
00045