Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/QNX4/Fred/TRAIN.TXT

Go to the documentation of this file.
00001 /* A bit like a LinkList class Comp352,
00002    so you can send in one shot a queue of task to be done
00003 */
00004 
00005 #define bool  int
00006 
00007 class Message { 
00008 public:
00009     Message();
00010     ~Message();
00011 
00012     void AppendMessage( Message* msg ); // Append a msg
00013     void DeleteMessages();          // Delete a msg linklist
00014 
00015 protected:
00016     Message* next;
00017 };  
00018 
00019 class TrainMessage : public Message {
00020 public:
00021     TrainMessage();
00022     ~TrainMessage();
00023 
00024 protected:
00025     TrainInfo*  new_train_info;
00026     int     request;
00027     int     nbRequests;
00028 };
00029 
00030 class TrainInfo : public Info {
00031 public:
00032     TrainInfo();
00033     TrainInfo( int ID, char* name, ... );
00034 
00035     TrainInfo( TrainInfo&  info );
00036     ~TrainInfo();
00037 
00038 protected:
00039     int         ID;
00040     char*       name;
00041     char*       color;
00042 
00043 // Position Tracker class ?
00044     double      speed;  
00045     bool        direction;
00046     int         prev_track;
00047     int         current_track;
00048     int         next_track;
00049 
00050     int         serial_id;
00051     int         serial_speed;
00052     bool        serial_done;
00053 
00054     Position*   origin;
00055     Position*   destination;
00056 
00057     bool        running;    // Running or sleeping ?
00058     
00059     TrainInfo*  prev;       // Previous Train
00060     TrainInfo*  next;       // Next Train
00061 
00062     TrainInfo*  prevState;  // Previous State
00063     TrainInfo*  nextState;  // Next State
00064 
00065     TrainGUI*   traingui;
00066 
00067     Timer*      timer;
00068 
00069 // Might go in Info Class
00070     long        action;     // Code for the Action, 0 = NOP
00071 
00072     double      last_update;     // in microseconds
00073     double      normal_update;   // Make an average 
00074                      // if the delay is too long, then refresh...
00075 }
00076 
00077 class Train : public Thread {
00078 public:
00079         Train();
00080         Train( int ID );
00081         ~Train();
00082     void run();
00083 
00084 protected:
00085     (void*)functions[26]( TrainInfo* info );
00086 
00087     void        initfunctions();
00088 
00089     int         train_ID;
00090     TrainInfo*  current_train_info;
00091     TrainInfo*  buffer_;
00092 };
00093 
00094 Train::Train() {
00095     train_ID = -1;
00096     initfunctions();
00097 }
00098 
00099 void Train::initfunctions() {
00100     // Not sure of the syntax  ={
00101 
00102     *functions[0] = Train::nop( ... );      
00103     *functions[1] = Train::change_speed( ... );
00104     *functions[2] = Train::change_direction( ... );
00105 }
00106 
00107 void Train::run()
00108 {
00109     pid_t pid;
00110     int   task = 0;
00111 
00112     while(1)
00113     {
00114         const char* response;
00115         
00116         if((pid = Receive(0, buffer_, sizeof(buffer_))) < 0) 
00117         {
00118 
00119             printf("ERROR--code %d\n", errno);
00120             return;
00121         } else {
00122             task = buffer_->action;
00123             if ( task >= 0  &&  task < 26 ) {
00124                 functions[task]( buffer_ ); // Call the function to do...
00125             } else {
00126                 printf("Illegal task message request: %d", task );
00127             }
00128         }
00129 
00130         printf("Got from %d: %s\n", pid, buffer_);
00131         // send back
00132         Reply(pid, response, strlen(response)+1);
00133     }
00134     // send response and die
00135     Reply(pid, ok_response, sizeof(ok_response));
00136 }
00137 
00138 

Generated on Sun Oct 14 18:46:41 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001