Subversion Repositories programming

Rev

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