Path: blob/main/src/traci-server/TraCIServerAPI_ParkingArea.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_ParkingArea.cpp14/// @author Jakob Erdmann15/// @date 16.03.202016///17// APIs for getting/setting parking area values via TraCI18/****************************************************************************/19#include <config.h>2021#include <microsim/MSNet.h>22#include <microsim/MSEdge.h>23#include <microsim/MSStoppingPlace.h>24#include <libsumo/ParkingArea.h>25#include <libsumo/TraCIConstants.h>26#include "TraCIServerAPI_ParkingArea.h"272829// ===========================================================================30// method definitions31// ===========================================================================32bool33TraCIServerAPI_ParkingArea::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_PARKINGAREA_VARIABLE, variable, id);38try {39if (!libsumo::ParkingArea::handleVariable(id, variable, &server, &inputStorage)) {40return server.writeErrorStatusCmd(libsumo::CMD_GET_PARKINGAREA_VARIABLE, "Get ParkingArea Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);41}42} catch (libsumo::TraCIException& e) {43return server.writeErrorStatusCmd(libsumo::CMD_GET_PARKINGAREA_VARIABLE, e.what(), outputStorage);44}45server.writeStatusCmd(libsumo::CMD_GET_PARKINGAREA_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);46server.writeResponseWithLength(outputStorage, server.getWrapperStorage());47return true;48}495051bool52TraCIServerAPI_ParkingArea::processSet(TraCIServer& server, tcpip::Storage& inputStorage,53tcpip::Storage& outputStorage) {54std::string warning = ""; // additional description for response55// variable56int variable = inputStorage.readUnsignedByte();57if (variable != libsumo::VAR_PARAMETER &&58variable != libsumo::VAR_ACCESS_BADGE) {59return server.writeErrorStatusCmd(libsumo::CMD_SET_PARKINGAREA_VARIABLE, "Change ParkingArea State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);60}61// id62std::string id = inputStorage.readString();6364try {65// process66switch (variable) {67case libsumo::VAR_PARAMETER: {68if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {69return server.writeErrorStatusCmd(libsumo::CMD_SET_PARKINGAREA_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);70}71//read itemNo72inputStorage.readInt();73std::string name;74if (!server.readTypeCheckingString(inputStorage, name)) {75return server.writeErrorStatusCmd(libsumo::CMD_SET_PARKINGAREA_VARIABLE, "The name of the parameter must be given as a string.", outputStorage);76}77std::string value;78if (!server.readTypeCheckingString(inputStorage, value)) {79return server.writeErrorStatusCmd(libsumo::CMD_SET_PARKINGAREA_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);80}81libsumo::ParkingArea::setParameter(id, name, value);82break;83}84case libsumo::VAR_ACCESS_BADGE: {85std::vector<std::string> badges;86if (!server.readTypeCheckingStringList(inputStorage, badges)) {87return server.writeErrorStatusCmd(libsumo::CMD_SET_PARKINGAREA_VARIABLE, "A string list is needed to update the ParkingArea access badges.", outputStorage);88}89libsumo::ParkingArea::setAcceptedBadges(id, badges);90break;91}92default:93break;94}95} catch (libsumo::TraCIException& e) {96return server.writeErrorStatusCmd(libsumo::CMD_SET_PARKINGAREA_VARIABLE, e.what(), outputStorage);97}98server.writeStatusCmd(libsumo::CMD_SET_PARKINGAREA_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);99return true;100}101102103/****************************************************************************/104105106