Subversion Repositories programming

Rev

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


#ifndef ELEVATOR_H
#define ELEVATOR_H

#include <cstdio>
#include <iostream>
#include <unistd.h>
#include <assert.h>
#include <vector>
#include <string>

#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include <boost/algorithm/string.hpp>

#include "controller.h"

const int MOVE_UP   = 0;
const int MOVE_DOWN = 1;
const int IDLE      = 2;

const float ELEVATOR_TIME_MOVE_AMOUNT = 0.1;
const int   ELEVATOR_TIME_DELAY_USEC  = 500000;
const int   ELEVATOR_TIME_PAUSE_USEC  = 50000;

class Controller;

class Elevator
{
    public:
        Elevator (int num_floors);
        ~Elevator ();

        // Service Functions
        int floors_above_current ();
        int floors_below_current ();
        void push_button (int floor);
        bool button_is_pushed (int floor);

        // User interaction
        void have_user_enter_buttons ();

        // Getters and Setters
        int get_direction ();
        float get_current_floor ();
        void set_controller (Controller *c);

        // Thread Functions
        void thread_start ();
        void thread_stop ();
        void thread_pause ();
        void thread_unpause ();

    private:
        // Private Functions
        bool near_a_floor ();
        bool near_floor (int floor);
        bool has_floors_to_stop_at ();
        bool should_stop_at_current_floor ();

        // Thread Functions
        void run_elevator_logic ();
        static void thread_entry (const Elevator *me);

        // Private Variables
        int num_floors;
        float current_floor;
        int direction;
        std::vector<bool> stop_at_floors;
        Controller *controller;

        // Thread Variable
        bool terminate;
        bool pause;

};

#endif // ELEVATOR_H