LCOV - code coverage report
Current view: top level - src/traci-server - TraCIServerAPI_Lane.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 91.7 % 36 33
Test Date: 2025-12-06 15:35:27 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2009-2025 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    TraCIServerAPI_Lane.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @author  Laura Bieker
      19              : /// @author  Mario Krumnow
      20              : /// @author  Leonhard Luecken
      21              : /// @author  Mirko Barthauer
      22              : /// @date    07.05.2009
      23              : ///
      24              : // APIs for getting/setting lane values via TraCI
      25              : /****************************************************************************/
      26              : #include <config.h>
      27              : 
      28              : #include <microsim/MSEdge.h>
      29              : #include <microsim/MSEdgeControl.h>
      30              : #include <microsim/MSLane.h>
      31              : #include <microsim/MSNet.h>
      32              : #include <microsim/MSVehicle.h>
      33              : #include <microsim/transportables/MSTransportable.h>
      34              : #include <libsumo/Lane.h>
      35              : #include <libsumo/TraCIConstants.h>
      36              : #include <libsumo/StorageHelper.h>
      37              : #include "TraCIServer.h"
      38              : #include "TraCIServerAPI_Lane.h"
      39              : 
      40              : 
      41              : // ===========================================================================
      42              : // method definitions
      43              : // ===========================================================================
      44              : bool
      45          156 : TraCIServerAPI_Lane::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
      46              :                                 tcpip::Storage& outputStorage) {
      47          156 :     std::string warning = ""; // additional description for response
      48              :     // variable
      49          156 :     int variable = inputStorage.readUnsignedByte();
      50          156 :     if (variable != libsumo::VAR_MAXSPEED && variable != libsumo::VAR_LENGTH && variable != libsumo::LANE_ALLOWED && variable != libsumo::LANE_DISALLOWED
      51           72 :             && variable != libsumo::VAR_PARAMETER && variable != libsumo::LANE_CHANGES) {
      52            0 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, "Change Lane State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
      53              :     }
      54              :     // id
      55          156 :     std::string id = inputStorage.readString();
      56          156 :     MSLane* l = MSLane::dictionary(id);
      57          156 :     if (l == nullptr) {
      58           12 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, "Lane '" + id + "' is not known", outputStorage);
      59              :     }
      60              :     try {
      61              :         // process
      62          152 :         switch (variable) {
      63              :             case libsumo::VAR_MAXSPEED: {
      64           23 :                 const double value = StoHelp::readTypedDouble(inputStorage, "The speed must be given as a double.");
      65           22 :                 libsumo::Lane::setMaxSpeed(id, value);
      66              :                 break;
      67              :             }
      68              :             case libsumo::VAR_FRICTION: {
      69            0 :                 const double value = StoHelp::readTypedDouble(inputStorage, "The friction must be given as a double.");
      70            0 :                 libsumo::Lane::setFriction(id, value);
      71              :                 break;
      72              :             }
      73              :             case libsumo::VAR_LENGTH: {
      74           10 :                 const double value = StoHelp::readTypedDouble(inputStorage, "The length must be given as a double.");
      75            9 :                 libsumo::Lane::setLength(id, value);
      76              :                 break;
      77              :             }
      78              :             case libsumo::LANE_ALLOWED: {
      79           34 :                 const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Allowed vehicle classes must be given as a list of strings.");
      80           33 :                 libsumo::Lane::setAllowed(id, classes);
      81              :                 break;
      82           33 :             }
      83              :             case libsumo::LANE_DISALLOWED: {
      84           13 :                 const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Not allowed vehicle classes must be given as a list of strings.");
      85           12 :                 libsumo::Lane::setDisallowed(id, classes);
      86              :                 break;
      87           12 :             }
      88              :             case libsumo::LANE_CHANGES: {
      89           10 :                 StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting lane change permissions.");
      90           10 :                 const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Vehicle classes allowed to change lane must be given as a list of strings.");
      91           10 :                 const int direction = StoHelp::readTypedByte(inputStorage, "The lane change direction must be given as an integer.");
      92           10 :                 libsumo::Lane::setChangePermissions(id, classes, direction);
      93              :                 break;
      94           10 :             }
      95              :             case libsumo::VAR_PARAMETER: {
      96           62 :                 StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");
      97           62 :                 const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");
      98           62 :                 const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");
      99           62 :                 libsumo::Lane::setParameter(id, name, value);
     100              :                 break;
     101              :             }
     102              :             default:
     103              :                 break;
     104              :         }
     105            4 :     } catch (libsumo::TraCIException& e) {
     106            4 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, e.what(), outputStorage);
     107            4 :     }
     108          148 :     server.writeStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
     109              :     return true;
     110              : }
     111              : 
     112              : 
     113              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1