Beispiel #1
0
void Elevator::Initialize(Environment &env) {
	env.RegisterEventHandler("Environment::All", this, &Elevator::HandleUpdate);
	env.RegisterEventHandler("Elevator::Up", this, &Elevator::HandleUp);
	env.RegisterEventHandler("Elevator::Down", this, &Elevator::HandleDown);
	env.RegisterEventHandler("Elevator::Stop", this, &Elevator::HandleStop);
	env.RegisterEventHandler("Elevator::Open", this, &Elevator::HandleOpen);
	env.RegisterEventHandler("Elevator::Close", this, &Elevator::HandleClose);
	env.RegisterEventHandler("Elevator::Beep", this, &Elevator::HandleBeep);
	env.RegisterEventHandler("Elevator::Beeping", this, &Elevator::HandleBeeping);
	env.RegisterEventHandler("Elevator::StopBeep", this, &Elevator::HandleStopBeep);
	env.RegisterEventHandler("Elevator::Malfunction", this,
			&Elevator::HandleMalfunction);
	env.RegisterEventHandler("Elevator::Fixed", this, &Elevator::HandleFixed);

	env.RegisterEventHandler("Elevator::Opened", this, &Elevator::HandleOpened);
	env.RegisterEventHandler("Elevator::Closed", this, &Elevator::HandleClosed);
}
Beispiel #2
0
void Person::Initialize(Environment &env) {
	env.RegisterEventHandler("UpDownButton::Decide", this, &Person::HandleDecide);
	env.RegisterEventHandler("Elevator::Opened", this, &Person::HandleOpened);
	env.RegisterEventHandler("Elevator::Beeping", this, &Person::HandleBeeping);
	env.RegisterEventHandler("Elevator::Beeped", this, &Person::HandleBeeped);
	env.RegisterEventHandler("Person::Entered", this, &Person::HandleEntered);
	env.RegisterEventHandler("Person::Exiting", this, &Person::HandleExiting);
	env.RegisterEventHandler("Person::Exited", this, &Person::HandleExited);
	env.RegisterEventHandler("Elevator::Closed", this, &Person::HandleClosed);
	env.RegisterEventHandler("Elevator::Moving", this, &Person::HandleMoving);
	env.RegisterEventHandler("Elevator::Fixed", this, &Person::HandleFixed);
	env.RegisterEventHandler("Elevator::Malfunction", this, &Person::HandleMalfunction);
	env.RegisterEventHandler("Interface::Notify", this, &Person::HandleNotify);
	env.RegisterEventHandler("Elevator::Closing", this, &Person::HandleClosing);

	std::list<Floor*> init;
	init.push_front(current_);

	std::list<std::list<Floor*>> paths;
	paths.push_front(init);

	do {

		std::list<Floor*> path = paths.front();
		Floor *current = path.back();

		paths.pop_front();

		if (current == final_) {
			path.pop_front();
			path_ = path;
			break;
		}

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

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

			for (int j = 0; j < ele->GetInterfaceCount(); ++j) {

				Interface *binterf = ele->GetInterface(j);
				Floor *floor = static_cast<Floor*>(binterf->GetLoadable(0));

				if (floor != current) {
					path.push_back(floor);
					paths.push_back(path);
					path.pop_back();
				}
			}
		}

	} while (true);

	std::cout << "Path for " << GetName() << " is ";
	for (Floor *floor : path_) {
		std::cout << "Floor " << floor->GetId() << " ";
	}
	std::cout << std::endl;

	RequestElevator(env, start_);
}
Beispiel #3
0
void ElevatorLogic::Initialize(Environment &env) {
	env.RegisterEventHandler("Interface::Notify", this, &ElevatorLogic::HandleNotify);
	env.RegisterEventHandler("Elevator::Stopped", this, &ElevatorLogic::HandleStopped);
	env.RegisterEventHandler("Elevator::Opened", this, &ElevatorLogic::HandleOpened);
	env.RegisterEventHandler("Elevator::Closed", this, &ElevatorLogic::HandleClosed);
}