Subversion Repositories programming

Rev

Rev 329 | Rev 332 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 329 Rev 331
Line 5... Line 5...
5
{
5
{
6
    assert (num_floors > 2);
6
    assert (num_floors > 2);
7
    assert (num_elevators > 0);
7
    assert (num_elevators > 0);
8
 
8
 
9
    elevators = std::vector<Elevator> (num_elevators, Elevator (num_floors));
9
    elevators = std::vector<Elevator> (num_elevators, Elevator (num_floors));
-
 
10
 
-
 
11
    for (int i=0; i<num_elevators; i++)
-
 
12
        elevators[i].set_controller (this);
10
}
13
}
11
 
14
 
12
Controller::~Controller ()
15
Controller::~Controller ()
13
{
16
{
14
}
17
}
15
 
18
 
16
void Controller::request_elevator (int on_floor, int direction)
19
void Controller::request_elevator (int on_floor, int direction)
17
{
20
{
18
    assert (on_floor <= num_floors);
21
    assert (on_floor <= num_floors);
19
    assert (on_floor > 0);
22
    assert (on_floor > 0);
-
 
23
    assert (direction == MOVE_UP || direction == MOVE_DOWN);
20
 
24
 
21
    float distance = INT_MAX;
25
    float distance = INT_MAX;
22
    int elevator_number;
26
    int elevator_number;
23
 
27
 
24
    // check that there is not already an elevator requested
28
    // check that there is not already an elevator requested
Line 108... Line 112...
108
void Controller::enable_elevator (int elevator_number)
112
void Controller::enable_elevator (int elevator_number)
109
{
113
{
110
    // make sure elevator is enabled first
114
    // make sure elevator is enabled first
111
}
115
}
112
 
116
 
-
 
117
void Controller::start_all_elevators ()
-
 
118
{
-
 
119
    int i;
-
 
120
 
-
 
121
    for (i=0; i<num_elevators; i++)
-
 
122
        elevators[i].thread_start ();
-
 
123
}
-
 
124
 
-
 
125
void Controller::stop_all_elevators ()
-
 
126
{
-
 
127
    int i;
-
 
128
 
-
 
129
    for (i=0; i<num_elevators; i++)
-
 
130
        elevators[i].thread_stop ();
-
 
131
}
-
 
132
 
-
 
133
void Controller::pause_all_elevators ()
-
 
134
{
-
 
135
    int i;
-
 
136
 
-
 
137
    for (i=0; i<num_elevators; i++)
-
 
138
        elevators[i].thread_pause ();
-
 
139
}
-
 
140
 
-
 
141
void Controller::unpause_all_elevators ()
-
 
142
{
-
 
143
    int i;
-
 
144
 
-
 
145
    for (i=0; i<num_elevators; i++)
-
 
146
        elevators[i].thread_unpause ();
-
 
147
}
-
 
148