Beispiel #1
0
void Elevator::HandleOpen(Environment &env, const Event &e) {

	if (ForMe(e)) {
		env.SendEvent("Elevator::Opening", 0, this);
		env.SendEvent("Elevator::Opened", 3, this);
	}
}
Beispiel #2
0
void Person::HandleDecide(Environment &env, const Event &e) {

	if (ForMe(e)) {
		if (current_->IsAbove(path_.front()))
			env.SendEvent("UpDownButton::Up", 0, this, e.GetSender());

		if (current_->IsBelow(path_.front()))
			env.SendEvent("UpDownButton::Down", 0, this, e.GetSender());
	}
}
Beispiel #3
0
void Elevator::HandleClose(Environment &env, const Event &e) {

	if (ForMe(e)) {
		isOpen_ = false;
		env.SendEvent("Elevator::Closing", 0, this);
		env.SendEvent("Elevator::Closed", 3, this);
		if (position_ > 0.49 && position_ < 0.51 && state_ == Idle)
			position_ = 0.5; // set the position to 0.5 to avoid floating point errors
	}
}
Beispiel #4
0
void ElevatorLogic::HandleClosed(Environment &env, const Event &e) {

	Elevator *ele = static_cast<Elevator*>(e.GetSender());

	if (!moved_) {
		env.SendEvent("Elevator::Up", 0, this, ele);
		env.SendEvent("Elevator::Stop", 4, this, ele);

		moved_ = true;
	}
}
Beispiel #5
0
void Person::RequestElevator(Environment &env, int time) {

	if (current_ == final_)
		return;

	Floor *next = path_.front();

	if (!next) {
		std::ostringstream oss("Invalid operation: no next floor in path ", std::ostringstream::ate);
		oss << "ID of person: <" << GetId();
		oss << ", this error should never occur.";
		throw std::runtime_error(oss.str());
	}

	for (int i = 0; i < current_->GetInterfaceCount(); ++i) {

		Interface *interf = current_->GetInterface(i);
		Elevator *ele = static_cast<Elevator*>(interf->GetLoadable(0));

		if (ele->HasFloor(next)) {

			requested_ = current_->GetInterface(i);
			env.SendEvent("Interface::Interact", time - env.GetClock(), this, requested_);

			return;
		}
	}

	std::ostringstream oss("Invalid operation: no elevator available to go from Floor ", std::ostringstream::ate);
	oss << current_->GetId() << " to Floor " << next->GetId();
	oss << ", this error should never occur.";
	throw std::runtime_error(oss.str());
}
Beispiel #6
0
void Person::RequestFloor(Environment &env) {

	Floor *next = path_.front();

	if (!next) {
		std::ostringstream oss("Invalid operation: no next floor in path ", std::ostringstream::ate);
		oss << "ID of person: <" << GetId();
		oss << ", this error should never occur.";
		throw std::runtime_error(oss.str());
	}

	for (int i = 0; i < elevator_->GetInterfaceCount(); ++i) {

		Interface *interf = elevator_->GetInterface(i);
		Floor *floor = static_cast<Floor*>(interf->GetLoadable(0));

		if (floor == next) {
			action_ = env.SendEvent("Interface::Interact", 3, this, elevator_->GetInterface(i));

			return;
		}
	}

	std::ostringstream oss("Invalid operation: ", std::ostringstream::ate);
	oss << elevator_->GetName() << " can not go to Floor " << next->GetId();
	oss << ", this error should never occur.";
	throw std::runtime_error(oss.str());
}
Beispiel #7
0
void Elevator::HandleStop(Environment &env, const Event &e) {

	if (ForMe(e)) {
		state_ = Idle;
		env.SendEvent("Elevator::Stopped", 0, this);
	}
}
Beispiel #8
0
void Elevator::HandleDown(Environment &env, const Event &e) {

	if (ForMe(e)) {
		state_ = Down;
		env.SendEvent("Elevator::Moving", 0, this);
	}
}
Beispiel #9
0
void Person::Enter(Environment &env) {

	if (current_ == final_) {

		// The person is at the destination floor
		elevator_ = nullptr;

	} else {


		// The person is not at the destination floor
		env.SendEvent("Person::Entering", 0, this, elevator_);
		action_ = env.SendEvent("Person::Entered", 3, this, elevator_);
		isEnteringOrExiting_ = true;

	}

}
Beispiel #10
0
void Elevator::HandleStopBeep(Environment &env, const Event &e) {

	if (ForMe(e)) {
		if (beeping_ != 0) {
			env.CancelEvent(beeping_);
			beeping_ = 0;
		} else
			env.SendEvent("Elevator::Beeped", 0, this);
	}
}
Beispiel #11
0
void Person::Cancel(Environment &env) {

	if (action_) {

		env.CancelEvent(action_);
		env.SendEvent("Person::Canceled", 0, this);

		action_ = 0;

		isEnteringOrExiting_ = false;
	}
}
Beispiel #12
0
void ElevatorLogic::HandleNotify(Environment &env, const Event &e) {

	Interface *interf = static_cast<Interface*>(e.GetSender());
	Loadable *loadable = interf->GetLoadable(0);

	if (loadable->GetType() == "Elevator") {

		Elevator *ele = static_cast<Elevator*>(loadable);

		env.SendEvent("Elevator::Open", 0, this, ele);
	}
}
Beispiel #13
0
void Person::Exit(Environment &env) {

	env.SendEvent("Person::Exiting", 0, this, elevator_);
	action_ = env.SendEvent("Person::Exited", 3, this, elevator_);
	isEnteringOrExiting_ = true;
}
Beispiel #14
0
void Elevator::HandleBeep(Environment &env, const Event &e) {

	if (ForMe(e))
		beeping_ = env.SendEvent("Elevator::Beeping", 0, this);
}
Beispiel #15
0
void ElevatorLogic::HandleOpened(Environment &env, const Event &e) {

	Elevator *ele = static_cast<Elevator*>(e.GetSender());

	env.SendEvent("Elevator::Close", 4, this, ele);
}