Path: blob/main/src/traci-server/TraCIServerAPI_Route.cpp
193732 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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 TraCIServerAPI_Route.cpp14/// @author Daniel Krajzewicz15/// @author Laura Bieker16/// @author Michael Behrisch17/// @date 07.05.200918///19// APIs for getting/setting route values via TraCI20/****************************************************************************/21#include <config.h>2223#include <microsim/MSNet.h>24#include <microsim/MSRoute.h>25#include <microsim/MSEdge.h>26#include <libsumo/Route.h>27#include <libsumo/StorageHelper.h>28#include <libsumo/TraCIConstants.h>29#include "TraCIServerAPI_Route.h"303132// ===========================================================================33// method definitions34// ===========================================================================35bool36TraCIServerAPI_Route::processSet(TraCIServer& server, tcpip::Storage& inputStorage,37tcpip::Storage& outputStorage) {38std::string warning = ""; // additional description for response39// variable40int variable = inputStorage.readUnsignedByte();41if (variable != libsumo::ADD && variable != libsumo::REMOVE && variable != libsumo::VAR_PARAMETER) {42return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "Change Route State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);43}44// id45std::string id = inputStorage.readString();4647try {48// process49switch (variable) {50case libsumo::ADD:51libsumo::Route::add(id, StoHelp::readTypedStringList(inputStorage, "A string list is needed for adding a new route."));52break;53case libsumo::REMOVE: {54libsumo::Route::remove(id);55}56break;57case libsumo::VAR_PARAMETER: {58StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");59const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");60const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");61libsumo::Route::setParameter(id, name, value);62}63break;64default:65break;66}67} catch (libsumo::TraCIException& e) {68return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, e.what(), outputStorage);69}70server.writeStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);71return true;72}737475/****************************************************************************/767778