Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ElevatorBank Class Reference

The following class defines a bank of elevators. More...

#include <elevator.h>

Inheritance diagram for ElevatorBank::

CallBackObj List of all members.

Public Methods

 ElevatorBank (int numElvtrs, int numFlrs, CallBackObj *riders, CallBackObj *controllers)
 Initialize the elevator hardware, use "riders" and "controllers" to notify the rider/controller threads that an event occurred they should be interested in (such as, elevator arrives, doors open, etc). More...

 ~ElevatorBank ()
 deallocate the elevator hardware. More...

void OpenDoors (int elevator)
 Open the elevator doors; elevator must not be in motion! More...

void CloseDoors (int elevator)
 Close the elevator doors. More...

void MoveTo (int goingToFloor, int elevator)
 Set the elevator into motion. Elevator doors must be closed. If elevator is already in motion, this causes the elevator to stop at a new floor (eg, if a rider presses a new floor while the elevator is moving). More...

int WhereIsElevator (int elevator)
 return the current position of the elevator (which floor its on). More...

void MarkDirection (int elevator, Direction dir)
 change the display to show riders where this elevator is headed. More...

ElevatorEvent getNextControllerEvent (int *floor, int *elevator)
 when the elevator device calls back, this will tell you what event(s) (relevant to controller threads) triggered the callback. More...

void PressButton (int onFloor, Direction goingTo)
 Press button outside elevator to indicate where rider wants to go. More...

Direction getDirection (int elevator)
 return the indicated direction (set by MarkDirection()) of this elevator. More...

bool EnterElevator (int onFloor, int elevator)
 Step onto the elevator; elevator must have MaxRiders people on it currently Returns false if doors have closed (might have happened between when riders got OpenDoors event and when they decided to step onto the elevator). More...

void PressFloor (int goingToFloor, int onElevator)
 Press button inside elevator to indicate where rider wants to go; thread must be on the elevator. More...

bool ExitElevator (int onFloor, int elevator)
 Step off the elevator. Returns false if doors have closed. More...

ElevatorEvent getNextRiderEvent (int *floor, int *elevator)
 when the elevator device calls back, this will tell you what event(s) (relevant to rider threads) triggered the callback. More...


Private Methods

void CallBack ()
 called internally when the elevator hardware generates an interrupt. More...

void PostEvent (ListOfEvents *list, ElevatorEvent event, int floor, int elevator, bool inHandler)
 an event occurred that requires a callback. More...

ElevatorEvent getNextEvent (ListOfEvents *list, int *floor, int *elevator)
 pull next event off the pending list of events, return NoEvent if list is empty. More...


Private Attributes

int numElevators
 how many elevators in this bank? More...

int numFloors
 how many floors in this building? More...

CallBackObjcallRiders
 call when an event occurs that riders would be interested in. More...

CallBackObjcallControllers
 call when an event occurs that elevator controller threads would be interested in. More...

ListOfEventsriderEvents
 pending events relevant to riders. More...

ListOfEventscontrollerEvents
 pending events relevant to controllers. More...

ElevatorInfo** elevators
 array of per-elevator state. More...


Detailed Description

The following class defines a bank of elevators.

Definition at line 43 of file elevator.h.


Constructor & Destructor Documentation

ElevatorBank::ElevatorBank ( int numElvtrs,
int numFlrs,
CallBackObj * riders,
CallBackObj * controllers )
 

Initialize the elevator hardware, use "riders" and "controllers" to notify the rider/controller threads that an event occurred they should be interested in (such as, elevator arrives, doors open, etc).

ElevatorBank::ElevatorBank Initialize the elevator hardware, calling "riders" and "controllers" to notify the rider/controller threads that an event has occurred that they should be interested in (such as, elevator arrives, doors open, etc)

Definition at line 111 of file elevator.cc.

ElevatorBank::~ElevatorBank ( )
 

deallocate the elevator hardware.

ElevatorBank::~ElevatorBank Deallocate the elevator hardware.

Definition at line 131 of file elevator.cc.


Member Function Documentation

void ElevatorBank::CallBack ( ) [private, virtual]
 

called internally when the elevator hardware generates an interrupt.

ElevatorBank::CallBack An event has occurred; check if someone needs to wakeup.

Reimplemented from CallBackObj.

Definition at line 290 of file elevator.cc.

void ElevatorBank::CloseDoors ( int elevator )
 

Close the elevator doors.

ElevatorBank::CloseDoors Close an elevator's doors.

Definition at line 160 of file elevator.cc.

Referenced by ElevatorInspector::ControllerTest().

bool ElevatorBank::EnterElevator ( int onFloor,
int elevator )
 

Step onto the elevator; elevator must have MaxRiders people on it currently Returns false if doors have closed (might have happened between when riders got OpenDoors event and when they decided to step onto the elevator).

ElevatorBank::EnterElevator Rider steps onto elevator. Elevator must be at "onFloor", and there must be space on the elevator.

Returns FALSE if doors have closed and/or elevator is on a different floor.

Definition at line 247 of file elevator.cc.

Referenced by ElevatorInspector::RiderTest().

bool ElevatorBank::ExitElevator ( int onFloor,
int elevator )
 

Step off the elevator. Returns false if doors have closed.

ElevatorBank::ExitElevator Rider steps off elevator. Rider must be on elevator. Return FALSE if doors have closed.

Definition at line 277 of file elevator.cc.

Referenced by ElevatorInspector::RiderTest().

void ElevatorBank::MarkDirection ( int elevator,
Direction dir )
 

change the display to show riders where this elevator is headed.

ElevatorBank::MarkDirection Change the display showing where this elevator is headed.

Definition at line 204 of file elevator.cc.

Referenced by ElevatorInspector::ControllerTest().

void ElevatorBank::MoveTo ( int goingToFloor,
int elevator )
 

Set the elevator into motion. Elevator doors must be closed. If elevator is already in motion, this causes the elevator to stop at a new floor (eg, if a rider presses a new floor while the elevator is moving).

ElevatorBank::MoveTo Set the elevator into motion to "goingToFloor". Elevator doors must be closed. If elevator is already in motion, then if the new destination is ahead, keep going but stop at the new spot. If the new destination is behind us, wait until we get to the next even floor boundary, then change direction.

Definition at line 176 of file elevator.cc.

Referenced by ElevatorInspector::ControllerTest().

void ElevatorBank::OpenDoors ( int elevator )
 

Open the elevator doors; elevator must not be in motion!

ElevatorBank::OpenDoors Open an elevator's doors; the elevator must not be in motion!

Definition at line 147 of file elevator.cc.

Referenced by ElevatorInspector::ControllerTest().

void ElevatorBank::PostEvent ( ListOfEvents * list,
ElevatorEvent event,
int floor,
int elevator,
bool inHandler ) [private]
 

an event occurred that requires a callback.

Definition at line 343 of file elevator.cc.

Referenced by CallBack(), OpenDoors(), PressButton(), and PressFloor().

void ElevatorBank::PressButton ( int onFloor,
Direction goingTo )
 

Press button outside elevator to indicate where rider wants to go.

ElevatorBank::PressButton Rider has pressed button to indicate where he/she wants to go

Definition at line 217 of file elevator.cc.

Referenced by ElevatorInspector::RiderTest().

void ElevatorBank::PressFloor ( int goingToFloor,
int onElevator )
 

Press button inside elevator to indicate where rider wants to go; thread must be on the elevator.

ElevatorBank::PressFloor Rider presses button inside elevator to say which floor he/she wants to go to. Rider must be on elevator!

Definition at line 261 of file elevator.cc.

Referenced by ElevatorInspector::RiderTest().

int ElevatorBank::WhereIsElevator ( int elevator )
 

return the current position of the elevator (which floor its on).

ElevatorBank::WhereIsElevator Return the current position of the elevator (which floor its on). If elevator is in motion, return the last floor we've gone by.

Definition at line 192 of file elevator.cc.

Referenced by ElevatorInspector::ControllerTest().

Direction ElevatorBank::getDirection ( int elevator )
 

return the indicated direction (set by MarkDirection()) of this elevator.

ElevatorBank::getDirection Return direction set by MarkDirection

Definition at line 231 of file elevator.cc.

Referenced by ElevatorInspector::RiderTest().

ElevatorEvent ElevatorBank::getNextControllerEvent ( int * floor,
int * elevator ) [inline]
 

when the elevator device calls back, this will tell you what event(s) (relevant to controller threads) triggered the callback.

Definition at line 78 of file elevator.h.

Referenced by ElevatorInspector::WaitForNextControllerEvent().

ElevatorEvent ElevatorBank::getNextEvent ( ListOfEvents * list,
int * floor,
int * elevator ) [private]
 

pull next event off the pending list of events, return NoEvent if list is empty.

ElevatorBank::getNextEvent Retrieve an event posted by the elevator device.

Definition at line 325 of file elevator.cc.

Referenced by getNextControllerEvent(), and getNextRiderEvent().

ElevatorEvent ElevatorBank::getNextRiderEvent ( int * floor,
int * elevator ) [inline]
 

when the elevator device calls back, this will tell you what event(s) (relevant to rider threads) triggered the callback.

Definition at line 114 of file elevator.h.

Referenced by ElevatorInspector::WaitForNextRiderEvent().


Member Data Documentation

CallBackObj * ElevatorBank::callControllers [private]
 

call when an event occurs that elevator controller threads would be interested in.

Definition at line 126 of file elevator.h.

CallBackObj * ElevatorBank::callRiders [private]
 

call when an event occurs that riders would be interested in.

Definition at line 124 of file elevator.h.

ListOfEvents * ElevatorBank::controllerEvents [private]
 

pending events relevant to controllers.

Definition at line 130 of file elevator.h.

ElevatorInfo ** ElevatorBank::elevators [private]
 

array of per-elevator state.

Definition at line 131 of file elevator.h.

int ElevatorBank::numElevators [private]
 

how many elevators in this bank?

Definition at line 122 of file elevator.h.

int ElevatorBank::numFloors [private]
 

how many floors in this building?

Definition at line 123 of file elevator.h.

ListOfEvents * ElevatorBank::riderEvents [private]
 

pending events relevant to riders.

Definition at line 129 of file elevator.h.


The documentation for this class was generated from the following files:
Generated at Wed Jul 4 11:32:23 2001 for Nachos by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001