Subversion Repositories programming

Rev

Rev 340 | 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
 
344 ira 19
#include <glibmm.h>
20
 
329 ira 21
#include <boost/thread/thread.hpp>
22
#include <boost/bind.hpp>
23
 
344 ira 24
#include "dispatch_data.h"
331 ira 25
#include "controller.h"
321 ira 26
 
331 ira 27
const int MOVE_UP   = 0;
28
const int MOVE_DOWN = 1;
29
const int IDLE      = 2;
321 ira 30
 
331 ira 31
const float ELEVATOR_TIME_MOVE_AMOUNT = 0.1;
32
const int   ELEVATOR_TIME_DELAY_USEC  = 500000;
33
const int   ELEVATOR_TIME_PAUSE_USEC  = 50000;
34
 
35
class Controller;
36
 
321 ira 37
class Elevator
38
{
39
    public:
40
        Elevator (int num_floors);
41
        ~Elevator ();
42
 
43
        // Service Functions
44
        int floors_above_current ();
45
        int floors_below_current ();
46
        void push_button (int floor);
328 ira 47
        bool button_is_pushed (int floor);
321 ira 48
 
49
        // Getters and Setters
50
        int get_direction ();
51
        float get_current_floor ();
331 ira 52
        void set_controller (Controller *c);
344 ira 53
        void set_dispatcher (Glib::Dispatcher *d);
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
 
344 ira 80
        // Dispatcher
81
        Glib::Dispatcher *dispatcher;
82
 
321 ira 83
        // Thread Variable
84
        bool terminate;
85
        bool pause;
86
 
87
};
88
 
89
#endif // ELEVATOR_H
90