void Elevator::HandleOpen(Environment &env, const Event &e) { if (ForMe(e)) { env.SendEvent("Elevator::Opening", 0, this); env.SendEvent("Elevator::Opened", 3, this); } }
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()); } }
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 } }
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; } }
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()); }
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()); }
void Elevator::HandleStop(Environment &env, const Event &e) { if (ForMe(e)) { state_ = Idle; env.SendEvent("Elevator::Stopped", 0, this); } }
void Elevator::HandleDown(Environment &env, const Event &e) { if (ForMe(e)) { state_ = Down; env.SendEvent("Elevator::Moving", 0, this); } }
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; } }
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); } }
void Person::Cancel(Environment &env) { if (action_) { env.CancelEvent(action_); env.SendEvent("Person::Canceled", 0, this); action_ = 0; isEnteringOrExiting_ = false; } }
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); } }
void Person::Exit(Environment &env) { env.SendEvent("Person::Exiting", 0, this, elevator_); action_ = env.SendEvent("Person::Exited", 3, this, elevator_); isEnteringOrExiting_ = true; }
void Elevator::HandleBeep(Environment &env, const Event &e) { if (ForMe(e)) beeping_ = env.SendEvent("Elevator::Beeping", 0, this); }
void ElevatorLogic::HandleOpened(Environment &env, const Event &e) { Elevator *ele = static_cast<Elevator*>(e.GetSender()); env.SendEvent("Elevator::Close", 4, this, ele); }