Rev 338 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/******************************************************************************** elevator.h** Header file for the Elevator class.** Copyright 2006, Ira W. Snyder (devel@irasnyder.com)******************************************************************************/#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 Functionsint floors_above_current ();int floors_below_current ();void push_button (int floor);bool button_is_pushed (int floor);// User interactionvoid have_user_enter_buttons ();// Getters and Settersint get_direction ();float get_current_floor ();void set_controller (Controller *c);// Thread Functionsvoid thread_start ();void thread_stop ();void thread_pause ();void thread_unpause ();private:// Private Functionsbool near_a_floor ();bool near_floor (int floor);bool has_floors_to_stop_at ();bool should_stop_at_current_floor ();void stop_at_floor (int in_direction);// Thread Functionsvoid run_elevator_logic ();static void thread_entry (const Elevator *me);// Private Variablesint num_floors;float current_floor;int direction;std::vector<bool> stop_at_floors;Controller *controller;// Thread Variablebool terminate;bool pause;};#endif // ELEVATOR_H