Subversion Repositories programming

Rev

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