Subversion Repositories programming

Rev

Rev 321 | Rev 329 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
321 ira 1
 
2
#ifndef ELEVATOR_H
3
#define ELEVATOR_H
4
 
5
#include <cstdio>
6
#include <iostream>
7
#include <unistd.h>
8
#include <assert.h>
9
#include <vector>
10
 
11
/* Custom #defines for just the elevator class */
12
#define MOVE_UP     0
13
#define MOVE_DOWN   1
14
#define IDLE        2
15
 
16
#define ELEVATOR_TIME_MOVE_AMOUNT   0.1
17
#define ELEVATOR_TIME_DELAY_USEC    500000
18
#define ELEVATOR_TIME_PAUSE_USEC    50000
19
 
20
class Elevator
21
{
22
    public:
23
        Elevator (int num_floors);
24
        ~Elevator ();
25
 
26
        // Service Functions
27
        int floors_above_current ();
28
        int floors_below_current ();
29
        bool has_any_floors_to_stop_at ();
30
        void push_button (int floor);
328 ira 31
        bool button_is_pushed (int floor);
321 ira 32
 
33
        // Getters and Setters
34
        int get_direction ();
35
        float get_current_floor ();
36
 
37
        // Thread Functions
38
        static void thread_entry (const Elevator *me);
39
        void thread_exit ();
40
        void thread_pause ();
41
        void thread_unpause ();
42
 
43
    private:
44
        // Private Functions
45
        bool near_a_floor ();
46
        bool near_floor (int floor);
47
        bool has_floors_to_stop_at ();
48
        bool should_stop_at_current_floor ();
49
 
50
        // Thread Functions
51
        void run_elevator_logic ();
52
 
53
        // Private Variables
54
        int num_floors;
55
        float current_floor;
56
        std::vector<bool> stop_at_floors;
57
        int direction;
58
 
59
        // Thread Variable
60
        bool terminate;
61
        bool pause;
62
 
63
};
64
 
65
#endif // ELEVATOR_H
66