00001 #ifndef __J2K__Train_HPP__
00002 #define __J2K__Train_HPP__
00003
00004 #include <j2k/Fred/Standard.hpp>
00005 #include <j2k/nto/Semaphore.hpp>
00006
00007 #include <j2k/nto/Controller.hpp>
00008
00009 typedef struct tmp_Train_t
00010 {
00011 UCHAR id;
00012 int speed;
00013 BOOL direction;
00014 UCHAR priority;
00015 BOOL lights_on;
00016
00017 UCHAR startTrackIndex;
00018 UCHAR currTrackIndex;
00019 UCHAR endTrackIndex;
00020
00021 _uint64 elapsed;
00022 _uint64 deadline;
00023
00024 UCHAR color;
00025
00026 } Train_t;
00027
00028 class Train {
00029 public:
00030 Train();
00031 virtual ~Train();
00032
00033 void setSpeed( int speed );
00034 int getSpeed();
00035
00036 void setLights( BOOL lights_on );
00037 BOOL getLights();
00038
00039 void setDirection( BOOL clockwise );
00040 BOOL getDirection();
00041
00042 void setID( UCHAR id );
00043 UCHAR getID();
00044
00045 void setController( Controller* c );
00046
00047 void setPrority( UCHAR prio );
00048 UCHAR getPrority();
00049
00050 void printStatus();
00051
00052 void stop();
00053 void emergencyStop();
00054
00055
00056 void setStartTrack( UCHAR where );
00057 UCHAR getStartTrack();
00058
00059
00060 void setEndTrack( UCHAR where );
00061 UCHAR getEndTrack();
00062
00063
00064 void setCurrentTrack( UCHAR index );
00065 UCHAR getCurrentTrack();
00066
00067
00068 _uint64 getElapsed();
00069
00070
00071 void setDeadline( _uint64 delta_time );
00072 _uint64 getDeadline();
00073
00074
00075 void setColor( UCHAR color = 0 );
00076 int getColor();
00077
00078 void setName( const char* n );
00079
00080 inline char* getName()
00081 {
00082 return strdup( name );
00083 }
00084
00085
00086 inline void notify( Train* ambulance, int reserved )
00087 {
00088 sem_notify.V();
00089 }
00090
00091 inline void wait()
00092 {
00093 sem_notify.P();
00094 }
00095
00096 BOOL isStronger( Train* t, int reserved )
00097 {
00098 return true;
00099 }
00100
00101
00102 protected:
00103 Controller* ctrl;
00104 Semaphore sem_notify;
00105
00106 char* name;
00107 size_t name_length;
00108
00109 Train_t train;
00110
00111 private:
00112 Train( const Train& src );
00113 const Train& operator=( const Train& src );
00114 };
00115
00116 #endif