Subversion Repositories programming

Rev

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

Rev Author Line No. Line
338 ira 1
/*******************************************************************************
2
 * elevator.h
3
 *
4
 * Header file for the Elevator class.
5
 *
6
 * Copyright 2006, Ira W. Snyder (devel@irasnyder.com)
7
 ******************************************************************************/
321 ira 8
 
9
#ifndef ELEVATOR_H
10
#define ELEVATOR_H
11
 
12
#include <cstdio>
13
#include <iostream>
14
#include <unistd.h>
15
#include <assert.h>
16
#include <vector>
331 ira 17
#include <string>
321 ira 18
 
329 ira 19
#include <boost/thread/thread.hpp>
20
#include <boost/bind.hpp>
331 ira 21
#include <boost/algorithm/string.hpp>
329 ira 22
 
331 ira 23
#include "controller.h"
321 ira 24
 
331 ira 25
const int MOVE_UP   = 0;
26
const int MOVE_DOWN = 1;
27
const int IDLE      = 2;
321 ira 28
 
331 ira 29
const float ELEVATOR_TIME_MOVE_AMOUNT = 0.1;
30
const int   ELEVATOR_TIME_DELAY_USEC  = 500000;
31
const int   ELEVATOR_TIME_PAUSE_USEC  = 50000;
32
 
33
class Controller;
34
 
321 ira 35
class Elevator
36
{
37
    public:
38
        Elevator (int num_floors);
39
        ~Elevator ();
40
 
41
        // Service Functions
42
        int floors_above_current ();
43
        int floors_below_current ();
44
        void push_button (int floor);
328 ira 45
        bool button_is_pushed (int floor);
321 ira 46
 
331 ira 47
        // User interaction
48
        void have_user_enter_buttons ();
49
 
321 ira 50
        // Getters and Setters
51
        int get_direction ();
52
        float get_current_floor ();
331 ira 53
        void set_controller (Controller *c);
321 ira 54
 
55
        // Thread Functions
329 ira 56
        void thread_start ();
331 ira 57
        void thread_stop ();
321 ira 58
        void thread_pause ();
59
        void thread_unpause ();
60
 
61
    private:
62
        // Private Functions
63
        bool near_a_floor ();
64
        bool near_floor (int floor);
65
        bool has_floors_to_stop_at ();
66
        bool should_stop_at_current_floor ();
340 ira 67
        void stop_at_floor (int in_direction);
321 ira 68
 
69
        // Thread Functions
70
        void run_elevator_logic ();
329 ira 71
        static void thread_entry (const Elevator *me);
321 ira 72
 
73
        // Private Variables
74
        int num_floors;
75
        float current_floor;
331 ira 76
        int direction;
321 ira 77
        std::vector<bool> stop_at_floors;
331 ira 78
        Controller *controller;
321 ira 79
 
80
        // Thread Variable
81
        bool terminate;
82
        bool pause;
83
 
84
};
85
 
86
#endif // ELEVATOR_H
87