Subversion Repositories programming

Rev

Rev 328 | Go to most recent revision | Details | 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
using namespace std;
11
 
12
/* Custom #defines for just the elevator class */
13
#define MOVE_UP     0
14
#define MOVE_DOWN   1
15
#define IDLE        2
16
 
17
#define ELEVATOR_TIME_MOVE_AMOUNT   0.1
18
#define ELEVATOR_TIME_DELAY_USEC    500000
19
#define ELEVATOR_TIME_PAUSE_USEC    50000
20
 
21
class Elevator
22
{
23
    public:
24
        Elevator (int num_floors);
25
        ~Elevator ();
26
 
27
        // Service Functions
28
        int floors_above_current ();
29
        int floors_below_current ();
30
        bool has_any_floors_to_stop_at ();
31
        void push_button (int floor);
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