00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __J2K__Train__Train_HPP__
00011 #define __J2K__Train__Train_HPP__
00012
00013 #include <j2k/Fred/Boolean.hpp>
00014 #include <j2k/Fred/StdTypes.hpp>
00015
00016 #include "timer.hh"
00017
00018
00019 #include "model.hh"
00020 #include "constants.h"
00021
00022 typedef Fake_controller_proxy Controller_proxy;
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 class Train : public Timer_thread
00071 {
00072 public:
00073 Train();
00074 ~Train();
00075
00076 private:
00077 UCHAR set_speed_;
00078 char direction_;
00079 SCHAR position_;
00080 char id_;
00081 Controller_proxy* controller_;
00082
00083 public:
00084 Train(Controller_proxy* controller, char id, char initial_pos);
00085
00086
00087 virtual void tick();
00088
00089 char get_position();
00090
00091 void set_position(char pos);
00092
00093
00094 UCHAR get_speed();
00095 void set_speed(UCHAR speed);
00096
00097 SCHAR get_direction();
00098 void set_direction(SCHAR dir);
00099
00100 private:
00101 DECLARE_MESSAGE_TABLE;
00102 };
00103
00104 class Train_proxy
00105 {
00106 private:
00107 Train t_;
00108 TrainStatus stat_;
00109 int sector_;
00110 BOOL has_alt_;
00111 UCHAR user_speed_;
00112
00113 public:
00114 Train_proxy(Controller_proxy* c, char id, char ipos, timespec& ts,
00115 int alg, int prio)
00116 : t_(c,id,ipos), stat_(WAITING), sector_(0), has_alt_(FALSE),
00117 user_speed_(0)
00118 {
00119 t_.start(ts, alg, prio);
00120 }
00121 int proxy_error() const
00122 {
00123 return t_.get_pid() == -1;
00124 }
00125 ~Train_proxy()
00126 {
00127 t_.stop();
00128 }
00129 char get_position();
00130 void set_position(char pos);
00131 UCHAR get_speed();
00132 void set_speed( UCHAR speed);
00133
00134 SCHAR get_direction();
00135 void set_direction( SCHAR dir);
00136 void set_state(TrainStatus s)
00137 {
00138 stat_ = s;
00139 }
00140 TrainStatus get_state() const
00141 {
00142 return stat_;
00143 }
00144 void request_sector(int s)
00145 {
00146 sector_ = s;
00147 }
00148 BOOL requires_resource()
00149 {
00150 if(stat_ != PARKED &&
00151 CURRENTSECTOR[get_position()-1] == sector_)
00152 return TRUE;
00153 return FALSE;
00154 }
00155
00156 BOOL get_alternate() const
00157 {
00158 return has_alt_;
00159 }
00160
00161 void got_alternate(BOOL has_alt = TRUE)
00162 {
00163 has_alt_ = has_alt;
00164 }
00165
00166 void set_user_speed( UCHAR user_speed)
00167 {
00168 user_speed_ = user_speed;
00169 }
00170 void sync_speeds()
00171 {
00172 set_speed(user_speed_);
00173 }
00174 };
00175
00176 #endif