/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2017-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file Rerouter.cpp14/// @author Jakob Erdmann15/// @date 16.03.202016///17// C++ TraCI client API implementation18/****************************************************************************/19#include <config.h>2021#include <microsim/MSNet.h>22#include <microsim/MSEdge.h>23#include <microsim/trigger/MSTriggeredRerouter.h>24#include <libsumo/TraCIConstants.h>25#include "Helper.h"26#include "Rerouter.h"272829namespace libsumo {30// ===========================================================================31// static member initializations32// ===========================================================================33SubscriptionResults Rerouter::mySubscriptionResults;34ContextSubscriptionResults Rerouter::myContextSubscriptionResults;353637// ===========================================================================38// static member definitions39// ===========================================================================40std::vector<std::string>41Rerouter::getIDList() {42MSNet::getInstance(); // just to check that we actually have a network43std::vector<std::string> ids;44for (const auto& item : MSTriggeredRerouter::getInstances()) {45ids.push_back(item.first);46}47return ids;48}4950int51Rerouter::getIDCount() {52return (int)MSTriggeredRerouter::getInstances().size();53}545556std::string57Rerouter::getParameter(const std::string& /* rerouterID */, const std::string& /* param */) {58return "";59}606162LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(Rerouter)636465void66Rerouter::setParameter(const std::string& /* rerouterID */, const std::string& /* key */, const std::string& /* value */) {67//MSRerouter* r = const_cast<MSRerouter*>(getRerouter(rerouterID));68//r->setParameter(key, value);69}707172LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(Rerouter, REROUTER)737475MSTriggeredRerouter*76Rerouter::getRerouter(const std::string& id) {77MSTriggeredRerouter* s = nullptr;78if (s == nullptr) {79throw TraCIException("Rerouter '" + id + "' is not known");80}81return s;82}838485std::shared_ptr<VariableWrapper>86Rerouter::makeWrapper() {87return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);88}899091bool92Rerouter::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {93switch (variable) {94case TRACI_ID_LIST:95return wrapper->wrapStringList(objID, variable, getIDList());96case ID_COUNT:97return wrapper->wrapInt(objID, variable, getIDCount());98case libsumo::VAR_PARAMETER:99paramData->readUnsignedByte();100return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));101case libsumo::VAR_PARAMETER_WITH_KEY:102paramData->readUnsignedByte();103return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));104default:105return false;106}107}108109}110111112/****************************************************************************/113114115