Subversion Repositories programming

Rev

Rev 328 | Rev 330 | 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
 
329 ira 19
#define ELEVATOR_TIME_MOVE_AMOUNT   0.05   //0.1
20
#define ELEVATOR_TIME_DELAY_USEC    250000 //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
        bool has_any_floors_to_stop_at ();
33
        void push_button (int floor);
328 ira 34
        bool button_is_pushed (int floor);
321 ira 35
 
36
        // Getters and Setters
37
        int get_direction ();
38
        float get_current_floor ();
39
 
40
        // Thread Functions
329 ira 41
        void thread_start ();
321 ira 42
        void thread_exit ();
43
        void thread_pause ();
44
        void thread_unpause ();
45
 
46
    private:
47
        // Private Functions
48
        bool near_a_floor ();
49
        bool near_floor (int floor);
50
        bool has_floors_to_stop_at ();
51
        bool should_stop_at_current_floor ();
52
 
53
        // Thread Functions
54
        void run_elevator_logic ();
329 ira 55
        static void thread_entry (const Elevator *me);
321 ira 56
 
57
        // Private Variables
58
        int num_floors;
59
        float current_floor;
60
        std::vector<bool> stop_at_floors;
61
        int direction;
62
 
63
        // Thread Variable
64
        bool terminate;
65
        bool pause;
66
 
67
};
68
 
69
#endif // ELEVATOR_H
70