Subversion Repositories programming

Rev

Rev 344 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
338 ira 1
/*******************************************************************************
2
 * controller.h
3
 *
4
 * Header file for the Controller class.
5
 *
6
 * Copyright 2006, Ira W. Snyder (devel@irasnyder.com)
7
 ******************************************************************************/
321 ira 8
 
9
#ifndef CONTROLLER_H
10
#define CONTROLLER_H
11
 
12
#include <assert.h>
13
#include <vector>
344 ira 14
#include <queue>
328 ira 15
#include <limits.h>
16
#include <math.h>
344 ira 17
#include <iostream>
18
#include <iomanip>
340 ira 19
 
344 ira 20
#include <glibmm.h>
21
 
321 ira 22
#include "elevator.h"
344 ira 23
#include "dispatch_data.h"
340 ira 24
#include "elevator_window.h"
321 ira 25
 
331 ira 26
class Elevator;
340 ira 27
class Elevator_Window;
331 ira 28
 
321 ira 29
class Controller
30
{
31
    public:
32
        Controller (int num_floors, int num_elevators);
33
        ~Controller ();
34
 
344 ira 35
        // Mass thread functions
331 ira 36
        void start_all_elevators ();
37
        void stop_all_elevators ();
38
        void pause_all_elevators ();
39
        void unpause_all_elevators ();
40
 
329 ira 41
        void request_elevator (int on_floor, int direction);
321 ira 42
 
344 ira 43
        // Public Dispatcher Stuff
340 ira 44
        void set_gui (Elevator_Window *gui);
344 ira 45
        void push_to_gui_queue (Dispatch_Data data);
46
        void push_button_in_elevator (int elevator_num, int floor);
340 ira 47
 
321 ira 48
    private:
328 ira 49
        bool floor_already_requested (int on_floor);
332 ira 50
        int find_closest_elevator (int to_floor, int in_direction);
340 ira 51
        int which_elevator_is (Elevator *e);
328 ira 52
 
334 ira 53
        std::vector<Elevator*> elevator;
321 ira 54
        int num_floors;
55
        int num_elevators;
340 ira 56
 
344 ira 57
        // GUI Functions
346 ira 58
        void stop_at_floor (Elevator *e, int on_floor, int direction);
344 ira 59
        void update_elevator_position (Elevator *e, float new_floor);
60
 
61
        // Dispatcher Stuff
62
        Glib::Dispatcher dispatcher;
63
        std::queue<Dispatch_Data> gui_events;
64
        void dispatch_handler ();
65
 
340 ira 66
        Elevator_Window *gui;
321 ira 67
};
68
 
69
#endif // CONTROLLER_H
70