Rev 329 | Rev 331 | 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 <boost/thread/thread.hpp>
#include <boost/bind.hpp>
/* Custom #defines for just the elevator class */
#define MOVE_UP 0
#define MOVE_DOWN 1
#define IDLE 2
#define ELEVATOR_TIME_MOVE_AMOUNT 0.1
#define ELEVATOR_TIME_DELAY_USEC 500000
#define ELEVATOR_TIME_PAUSE_USEC 50000
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);
// Getters and Setters
int get_direction ();
float get_current_floor ();
// Thread Functions
void thread_start ();
void thread_exit ();
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;
std::vector<bool> stop_at_floors;
int direction;
// Thread Variable
bool terminate;
bool pause;
};
#endif // ELEVATOR_H