Path: blob/main/src/traci-server/TraCIServerAPI_MultiEntryExit.cpp
169665 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-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 TraCIServerAPI_MultiEntryExit.cpp14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @date 07.05.200917///18// APIs for getting/setting multi-entry/multi-exit detector values via TraCI19/****************************************************************************/20#include <config.h>2122#include <microsim/output/MSDetectorControl.h>23#include <libsumo/MultiEntryExit.h>24#include <libsumo/TraCIConstants.h>25#include <libsumo/StorageHelper.h>26#include "TraCIServerAPI_MultiEntryExit.h"272829// ===========================================================================30// method definitions31// ===========================================================================32bool33TraCIServerAPI_MultiEntryExit::processGet(TraCIServer& server, tcpip::Storage& inputStorage,34tcpip::Storage& outputStorage) {35const int variable = inputStorage.readUnsignedByte();36const std::string id = inputStorage.readString();37server.initWrapper(libsumo::RESPONSE_GET_MULTIENTRYEXIT_VARIABLE, variable, id);38try {39if (!libsumo::MultiEntryExit::handleVariable(id, variable, &server, &inputStorage)) {40return server.writeErrorStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, "Get Multi Entry Exit Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);41}42} catch (libsumo::TraCIException& e) {43return server.writeErrorStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, e.what(), outputStorage);44}45server.writeStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);46server.writeResponseWithLength(outputStorage, server.getWrapperStorage());47return true;48}495051bool52TraCIServerAPI_MultiEntryExit::processSet(TraCIServer& server, tcpip::Storage& inputStorage,53tcpip::Storage& outputStorage) {54std::string warning = ""; // additional description for response55// variable56int variable = inputStorage.readUnsignedByte();57if (variable != libsumo::VAR_PARAMETER58) {59return server.writeErrorStatusCmd(libsumo::CMD_SET_MULTIENTRYEXIT_VARIABLE, "Set Multi Entry Exit Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);60}61// id62std::string id = inputStorage.readString();63// process64try {65switch (variable) {66case libsumo::VAR_PARAMETER: {67StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");68const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");69const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");70libsumo::MultiEntryExit::setParameter(id, name, value);71break;72}73default:74break;75}76} catch (libsumo::TraCIException& e) {77return server.writeErrorStatusCmd(libsumo::CMD_SET_MULTIENTRYEXIT_VARIABLE, e.what(), outputStorage);78}79server.writeStatusCmd(libsumo::CMD_SET_MULTIENTRYEXIT_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);80return true;81}828384/****************************************************************************/858687