LCOV - code coverage report
Current view: top level - src/traci-server - TraCIServerAPI_Route.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 30 35 85.7 %
Date: 2024-05-08 15:29:52 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-2024 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_Route.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Laura Bieker
      17             : /// @author  Michael Behrisch
      18             : /// @date    07.05.2009
      19             : ///
      20             : // APIs for getting/setting route values via TraCI
      21             : /****************************************************************************/
      22             : #include <config.h>
      23             : 
      24             : #include <microsim/MSNet.h>
      25             : #include <microsim/MSRoute.h>
      26             : #include <microsim/MSEdge.h>
      27             : #include <libsumo/Route.h>
      28             : #include <libsumo/TraCIConstants.h>
      29             : #include "TraCIServerAPI_Route.h"
      30             : 
      31             : 
      32             : // ===========================================================================
      33             : // method definitions
      34             : // ===========================================================================
      35             : bool
      36         253 : TraCIServerAPI_Route::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
      37             :                                  tcpip::Storage& outputStorage) {
      38         253 :     const int variable = inputStorage.readUnsignedByte();
      39         253 :     const std::string id = inputStorage.readString();
      40         253 :     server.initWrapper(libsumo::RESPONSE_GET_ROUTE_VARIABLE, variable, id);
      41             :     try {
      42         253 :         if (!libsumo::Route::handleVariable(id, variable, &server, &inputStorage)) {
      43           4 :             return server.writeErrorStatusCmd(libsumo::CMD_GET_ROUTE_VARIABLE, "Get Route Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
      44             :         }
      45           2 :     } catch (libsumo::TraCIException& e) {
      46           2 :         return server.writeErrorStatusCmd(libsumo::CMD_GET_ROUTE_VARIABLE, e.what(), outputStorage);
      47           2 :     }
      48         249 :     server.writeStatusCmd(libsumo::CMD_GET_ROUTE_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);
      49         249 :     server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
      50             :     return true;
      51             : }
      52             : 
      53             : 
      54             : bool
      55         197 : TraCIServerAPI_Route::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
      56             :                                  tcpip::Storage& outputStorage) {
      57         197 :     std::string warning = ""; // additional description for response
      58             :     // variable
      59         197 :     int variable = inputStorage.readUnsignedByte();
      60         197 :     if (variable != libsumo::ADD && variable != libsumo::VAR_PARAMETER) {
      61           0 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "Change Route State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
      62             :     }
      63             :     // id
      64         197 :     std::string id = inputStorage.readString();
      65             : 
      66             :     try {
      67             :         // process
      68         197 :         switch (variable) {
      69             :             case libsumo::ADD: {
      70             :                 std::vector<std::string> edgeIDs;
      71         149 :                 if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
      72           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "A string list is needed for adding a new route.", outputStorage);
      73             :                 }
      74         149 :                 libsumo::Route::add(id, edgeIDs);
      75         149 :             }
      76             :             break;
      77          48 :             case libsumo::VAR_PARAMETER: {
      78          48 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
      79           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);
      80             :                 }
      81             :                 //read itemNo
      82          48 :                 inputStorage.readInt();
      83             :                 std::string name;
      84          48 :                 if (!server.readTypeCheckingString(inputStorage, name)) {
      85           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "The name of the parameter must be given as a string.", outputStorage);
      86             :                 }
      87             :                 std::string value;
      88          48 :                 if (!server.readTypeCheckingString(inputStorage, value)) {
      89           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);
      90             :                 }
      91          48 :                 libsumo::Route::setParameter(id, name, value);
      92             :             }
      93             :             break;
      94             :             default:
      95             :                 break;
      96             :         }
      97           8 :     } catch (libsumo::TraCIException& e) {
      98           8 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, e.what(), outputStorage);
      99           8 :     }
     100         189 :     server.writeStatusCmd(libsumo::CMD_SET_ROUTE_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
     101             :     return true;
     102             : }
     103             : 
     104             : 
     105             : /****************************************************************************/

Generated by: LCOV version 1.14