LCOV - code coverage report
Current view: top level - src/traci-server - TraCIServerAPI_Person.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 206 262 78.6 %
Date: 2024-05-07 15:28:01 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_Person.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @date    26.05.2014
      17             : ///
      18             : // APIs for getting/setting person values via TraCI
      19             : /****************************************************************************/
      20             : #include <config.h>
      21             : 
      22             : #include <utils/common/StringTokenizer.h>
      23             : #include <microsim/transportables/MSTransportableControl.h>
      24             : #include <microsim/MSVehicleControl.h>
      25             : #include <microsim/transportables/MSPerson.h>
      26             : #include <microsim/MSNet.h>
      27             : #include <microsim/MSEdge.h>
      28             : #include <libsumo/Person.h>
      29             : #include <libsumo/StorageHelper.h>
      30             : #include <libsumo/TraCIConstants.h>
      31             : #include <libsumo/VehicleType.h>
      32             : #include "TraCIServer.h"
      33             : #include "TraCIServerAPI_VehicleType.h"
      34             : #include "TraCIServerAPI_Person.h"
      35             : #include "TraCIServerAPI_Simulation.h"
      36             : 
      37             : 
      38             : // ===========================================================================
      39             : // method definitions
      40             : // ===========================================================================
      41             : bool
      42      149793 : TraCIServerAPI_Person::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
      43             :                                   tcpip::Storage& outputStorage) {
      44      149793 :     const int variable = inputStorage.readUnsignedByte();
      45      149793 :     const std::string id = inputStorage.readString();
      46      149793 :     server.initWrapper(libsumo::RESPONSE_GET_PERSON_VARIABLE, variable, id);
      47             :     try {
      48             :         // in case of SPLIT_TAXI_RESERVATIONS id is a reservation id and handleVariable would throw an "unknown person" error
      49      149793 :         if (variable == libsumo::SPLIT_TAXI_RESERVATIONS || !libsumo::Person::handleVariable(id, variable, &server, &inputStorage)) {
      50        6265 :             switch (variable) {
      51         915 :                 case libsumo::VAR_EDGES: {
      52         915 :                     int nextStageIndex = 0;
      53         915 :                     if (!server.readTypeCheckingInt(inputStorage, nextStageIndex)) {
      54           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_GET_PERSON_VARIABLE, "The message must contain the stage index.", outputStorage);
      55             :                     }
      56         915 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRINGLIST);
      57         915 :                     server.getWrapperStorage().writeStringList(libsumo::Person::getEdges(id, nextStageIndex));
      58         915 :                     break;
      59             :                 }
      60         646 :                 case libsumo::VAR_STAGE: {
      61         646 :                     int nextStageIndex = 0;
      62         646 :                     if (!server.readTypeCheckingInt(inputStorage, nextStageIndex)) {
      63           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_GET_PERSON_VARIABLE, "The message must contain the stage index.", outputStorage);
      64             :                     }
      65         646 :                     libsumo::StorageHelper::writeStage(server.getWrapperStorage(), libsumo::Person::getStage(id, nextStageIndex));
      66         591 :                     break;
      67             :                 }
      68        4698 :                 case libsumo::VAR_TAXI_RESERVATIONS: {
      69        4698 :                     int onlyNew = 0;
      70        4698 :                     if (!server.readTypeCheckingInt(inputStorage, onlyNew)) {
      71           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_GET_PERSON_VARIABLE, "Retrieval of reservations requires an integer flag.", outputStorage);
      72             :                     }
      73        4698 :                     const std::vector<libsumo::TraCIReservation> result = libsumo::Person::getTaxiReservations(onlyNew);
      74        4698 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_COMPOUND);
      75        4698 :                     server.getWrapperStorage().writeInt((int)result.size());
      76       10537 :                     for (const libsumo::TraCIReservation& r : result) {
      77        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_COMPOUND);
      78        5839 :                         server.getWrapperStorage().writeInt(10);
      79        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
      80        5839 :                         server.getWrapperStorage().writeString(r.id);
      81        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRINGLIST);
      82        5839 :                         server.getWrapperStorage().writeStringList(r.persons);
      83        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
      84        5839 :                         server.getWrapperStorage().writeString(r.group);
      85        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
      86        5839 :                         server.getWrapperStorage().writeString(r.fromEdge);
      87        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
      88        5839 :                         server.getWrapperStorage().writeString(r.toEdge);
      89        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_DOUBLE);
      90        5839 :                         server.getWrapperStorage().writeDouble(r.departPos);
      91        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_DOUBLE);
      92        5839 :                         server.getWrapperStorage().writeDouble(r.arrivalPos);
      93        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_DOUBLE);
      94        5839 :                         server.getWrapperStorage().writeDouble(r.depart);
      95        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_DOUBLE);
      96        5839 :                         server.getWrapperStorage().writeDouble(r.reservationTime);
      97        5839 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_INTEGER);
      98        5839 :                         server.getWrapperStorage().writeInt(r.state);
      99             :                     }
     100             :                     break;
     101        4698 :                 }
     102             :                 case libsumo::SPLIT_TAXI_RESERVATIONS: {
     103             :                     std::vector<std::string> persons;
     104           4 :                     if (!server.readTypeCheckingStringList(inputStorage, persons)) {
     105           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_GET_PERSON_VARIABLE, "Splitting of reservations requires an string list.", outputStorage);
     106             :                     }
     107           4 :                     std::string splitID = libsumo::Person::splitTaxiReservation(id, persons);
     108           4 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
     109           4 :                     server.getWrapperStorage().writeString(splitID);
     110             :                     break;
     111           4 :                 }
     112           2 :                 default:
     113           4 :                     return server.writeErrorStatusCmd(libsumo::CMD_GET_PERSON_VARIABLE, "Get Person Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
     114             :             }
     115             :         }
     116          65 :     } catch (libsumo::TraCIException& e) {
     117          65 :         return server.writeErrorStatusCmd(libsumo::CMD_GET_PERSON_VARIABLE, e.what(), outputStorage);
     118          65 :     }
     119      149726 :     server.writeStatusCmd(libsumo::CMD_GET_PERSON_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);
     120      149726 :     server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
     121             :     return true;
     122             : }
     123             : 
     124             : 
     125             : bool
     126        3570 : TraCIServerAPI_Person::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
     127             :                                   tcpip::Storage& outputStorage) {
     128        3570 :     std::string warning = ""; // additional description for response
     129             :     // variable
     130        3570 :     int variable = inputStorage.readUnsignedByte();
     131        3570 :     if (variable != libsumo::VAR_PARAMETER
     132        3570 :             && variable != libsumo::ADD
     133        3334 :             && variable != libsumo::REMOVE
     134        3334 :             && variable != libsumo::APPEND_STAGE
     135        3101 :             && variable != libsumo::REPLACE_STAGE
     136        3101 :             && variable != libsumo::REMOVE_STAGE
     137        2918 :             && variable != libsumo::CMD_REROUTE_TRAVELTIME
     138        2918 :             && variable != libsumo::VAR_MOVE_TO
     139        2119 :             && variable != libsumo::MOVE_TO_XY
     140        2119 :             && variable != libsumo::VAR_SPEED
     141          46 :             && variable != libsumo::VAR_TYPE
     142          46 :             && variable != libsumo::VAR_SPEED_FACTOR
     143          25 :             && variable != libsumo::VAR_LENGTH
     144          25 :             && variable != libsumo::VAR_WIDTH
     145          15 :             && variable != libsumo::VAR_HEIGHT
     146          15 :             && variable != libsumo::VAR_MINGAP
     147           5 :             && variable != libsumo::VAR_COLOR
     148             :        ) {
     149           0 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Change Person State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
     150             :     }
     151             : 
     152             :     try {
     153             :         // TODO: remove declaration of c after completion
     154        3570 :         MSTransportableControl& c = MSNet::getInstance()->getPersonControl();
     155             :         // id
     156        3570 :         std::string id = inputStorage.readString();
     157             :         // TODO: remove declaration of p after completion
     158             :         const bool shouldExist = variable != libsumo::ADD;
     159        3570 :         MSTransportable* p = c.get(id);
     160        3570 :         if (p == nullptr && shouldExist) {
     161           0 :             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Person '" + id + "' is not known", outputStorage);
     162             :         }
     163             :         // process
     164        3570 :         switch (variable) {
     165          13 :             case libsumo::VAR_SPEED: {
     166          13 :                 double speed = 0;
     167          13 :                 if (!server.readTypeCheckingDouble(inputStorage, speed)) {
     168           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Setting speed requires a double.", outputStorage);
     169             :                 }
     170             :                 // set the speed for all present and future (walking) stages and modify the vType so that stages added later are also affected
     171          13 :                 libsumo::Person::setSpeed(id, speed);
     172             :             }
     173          13 :             break;
     174             :             case libsumo::VAR_TYPE: {
     175             :                 std::string vTypeID;
     176          13 :                 if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
     177           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The vehicle type id must be given as a string.", outputStorage);
     178             :                 }
     179          13 :                 libsumo::Person::setType(id, vTypeID);
     180             :                 break;
     181             :             }
     182           8 :             case libsumo::VAR_SPEED_FACTOR: {
     183           8 :                 double speedfactor = 0;
     184           8 :                 if (!server.readTypeCheckingDouble(inputStorage, speedfactor)) {
     185           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Setting SpeedFactor requires a double.", outputStorage);
     186             :                 }
     187           8 :                 libsumo::Person::setSpeedFactor(id, speedfactor);
     188             :             }
     189           8 :             break;
     190             :             case libsumo::VAR_COLOR: {
     191             :                 libsumo::TraCIColor col;
     192           5 :                 if (!server.readTypeCheckingColor(inputStorage, col)) {
     193           8 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The color must be given using the according type.", outputStorage);
     194             :                 }
     195           5 :                 libsumo::Person::setColor(id, col);
     196             :                 break;
     197             :             }
     198         181 :             case libsumo::ADD: {
     199         181 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     200           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Adding a person requires a compound object.", outputStorage);
     201             :                 }
     202         181 :                 if (inputStorage.readInt() != 4) {
     203           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Adding a person needs four parameters.", outputStorage);
     204             :                 }
     205             :                 std::string vTypeID;
     206         181 :                 if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
     207           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "First parameter (type) requires a string.", outputStorage);
     208             :                 }
     209             :                 std::string edgeID;
     210         181 :                 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
     211           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Second parameter (edge) requires a string.", outputStorage);
     212             :                 }
     213             :                 double depart;
     214         181 :                 if (!server.readTypeCheckingDouble(inputStorage, depart)) {
     215           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Third parameter (depart) requires a double.", outputStorage);
     216             :                 }
     217             :                 double pos;
     218         181 :                 if (!server.readTypeCheckingDouble(inputStorage, pos)) {
     219           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Fourth parameter (position) requires a double.", outputStorage);
     220             :                 }
     221         362 :                 libsumo::Person::add(id, edgeID, pos, depart, vTypeID);
     222             :             }
     223             :             break;
     224           8 :             case libsumo::REMOVE: {
     225           8 :                 int why = 0;
     226           8 :                 if (!server.readTypeCheckingByte(inputStorage, why)) {
     227           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Removing a person requires a byte.", outputStorage);
     228             :                 }
     229           8 :                 libsumo::Person::remove(id, (char)why);
     230             :             }
     231           8 :             break;
     232         225 :             case libsumo::APPEND_STAGE: {
     233         225 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     234           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Adding a person stage requires a compound object.", outputStorage);
     235             :                 }
     236         225 :                 int numParameters = inputStorage.readInt();
     237         225 :                 if (numParameters == 13) {
     238          34 :                     libsumo::TraCIStage stage;
     239          17 :                     libsumo::StorageHelper::readStage(inputStorage, stage);
     240          17 :                     libsumo::Person::appendStage(id, stage);
     241          17 :                 } else {
     242             :                     int stageType;
     243         208 :                     if (!server.readTypeCheckingInt(inputStorage, stageType)) {
     244           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first parameter for adding a stage must be the stage type given as int.", outputStorage);
     245             :                     }
     246         208 :                     if (stageType == libsumo::STAGE_DRIVING) {
     247             :                         // append driving stage
     248          13 :                         if (numParameters != 4) {
     249           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Adding a driving stage needs four parameters.", outputStorage);
     250             :                         }
     251             :                         std::string edgeID;
     252          13 :                         if (!server.readTypeCheckingString(inputStorage, edgeID)) {
     253           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Second parameter (edge) requires a string.", outputStorage);
     254             :                         }
     255             :                         std::string lines;
     256          13 :                         if (!server.readTypeCheckingString(inputStorage, lines)) {
     257           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Third parameter (lines) requires a string.", outputStorage);
     258             :                         }
     259             :                         std::string stopID;
     260          13 :                         if (!server.readTypeCheckingString(inputStorage, stopID)) {
     261           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Fourth parameter (stopID) requires a string.", outputStorage);
     262             :                         }
     263          13 :                         libsumo::Person::appendDrivingStage(id, edgeID, lines, stopID);
     264         195 :                     } else if (stageType == libsumo::STAGE_WAITING) {
     265             :                         // append waiting stage
     266          21 :                         if (numParameters != 4) {
     267           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Adding a waiting stage needs four parameters.", outputStorage);
     268             :                         }
     269             :                         double duration;
     270          21 :                         if (!server.readTypeCheckingDouble(inputStorage, duration)) {
     271           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Second parameter (duration) requires a double.", outputStorage);
     272             :                         }
     273             :                         std::string description;
     274          21 :                         if (!server.readTypeCheckingString(inputStorage, description)) {
     275           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Third parameter (description) requires a string.", outputStorage);
     276             :                         }
     277             :                         std::string stopID;
     278          21 :                         if (!server.readTypeCheckingString(inputStorage, stopID)) {
     279           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Fourth parameter (stopID) requires a string.", outputStorage);
     280             :                         }
     281          21 :                         libsumo::Person::appendWaitingStage(id, duration, description, stopID);
     282         174 :                     } else if (stageType == libsumo::STAGE_WALKING) {
     283             :                         // append walking stage
     284         174 :                         if (numParameters != 6) {
     285           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Adding a walking stage needs six parameters.", outputStorage);
     286             :                         }
     287             :                         std::vector<std::string> edgeIDs;
     288         174 :                         if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
     289           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Second parameter (edges) route must be defined as a list of edge ids.", outputStorage);
     290             :                         }
     291             :                         double arrivalPos;
     292         174 :                         if (!server.readTypeCheckingDouble(inputStorage, arrivalPos)) {
     293           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Third parameter (arrivalPos) requires a double.", outputStorage);
     294             :                         }
     295             :                         double duration;
     296         174 :                         if (!server.readTypeCheckingDouble(inputStorage, duration)) {
     297           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Fourth parameter (duration) requires a double.", outputStorage);
     298             :                         }
     299             :                         double speed;
     300         174 :                         if (!server.readTypeCheckingDouble(inputStorage, speed)) {
     301           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Fifth parameter (speed) requires a double.", outputStorage);
     302             :                         }
     303             :                         std::string stopID;
     304         174 :                         if (!server.readTypeCheckingString(inputStorage, stopID)) {
     305           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Fourth parameter (stopID) requires a string.", outputStorage);
     306             :                         }
     307         174 :                         libsumo::Person::appendWalkingStage(id, edgeIDs, arrivalPos, duration, speed, stopID);
     308         174 :                     } else {
     309           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Invalid stage type for person '" + id + "'", outputStorage);
     310             :                     }
     311             :                 }
     312             : 
     313             :             }
     314             :             break;
     315             : 
     316           8 :             case libsumo::REPLACE_STAGE : {
     317           8 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     318           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Replacing a person stage requires a compound object.", outputStorage);
     319             :                 }
     320           8 :                 if (inputStorage.readInt() != 2) {
     321           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Replacing a person stage requires a compound object of size 2.", outputStorage);
     322             :                 }
     323           8 :                 int nextStageIndex = 0;
     324           8 :                 if (!server.readTypeCheckingInt(inputStorage, nextStageIndex)) {
     325           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "First parameter of replace stage should be an integer", outputStorage);
     326             :                 }
     327           8 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     328           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Second parameter of replace stage should be a compound object", outputStorage);
     329             :                 }
     330           8 :                 if (inputStorage.readInt() != 13) {
     331           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Second parameter of replace stage should be a compound object of size 13", outputStorage);
     332             :                 }
     333          16 :                 libsumo::TraCIStage stage;
     334           8 :                 libsumo::StorageHelper::readStage(inputStorage, stage);
     335           8 :                 libsumo::Person::replaceStage(id, nextStageIndex, stage);
     336           8 :             }
     337           8 :             break;
     338             : 
     339         175 :             case libsumo::REMOVE_STAGE: {
     340         175 :                 int nextStageIndex = 0;
     341         175 :                 if (!server.readTypeCheckingInt(inputStorage, nextStageIndex)) {
     342           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The message must contain the stage index.", outputStorage);
     343             :                 }
     344         175 :                 libsumo::Person::removeStage(id, nextStageIndex);
     345             :             }
     346         175 :             break;
     347         783 :             case libsumo::CMD_REROUTE_TRAVELTIME: {
     348         783 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     349           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Rerouting requires a compound object.", outputStorage);
     350             :                 }
     351         783 :                 if (inputStorage.readInt() != 0) {
     352           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);
     353             :                 }
     354         783 :                 libsumo::Person::rerouteTraveltime(id);
     355             :             }
     356             :             break;
     357          16 :             case libsumo::VAR_MOVE_TO: {
     358          16 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     359           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Setting position requires a compound object.", outputStorage);
     360             :                 }
     361          16 :                 const int numArgs = inputStorage.readInt();
     362          16 :                 if (numArgs != 3) {
     363           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Setting position should obtain the edge id, the position and the lateral position.", outputStorage);
     364             :                 }
     365             :                 std::string laneID;
     366          16 :                 if (!server.readTypeCheckingString(inputStorage, laneID)) {
     367           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The first parameter for setting a position must be the laneID given as a string.", outputStorage);
     368             :                 }
     369          16 :                 double position = 0;
     370          16 :                 if (!server.readTypeCheckingDouble(inputStorage, position)) {
     371           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The second parameter for setting a position must be the position given as a double.", outputStorage);
     372             :                 }
     373          16 :                 double posLat = 0;
     374          16 :                 if (!server.readTypeCheckingDouble(inputStorage, posLat)) {
     375           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The third parameter for setting a position must be the lateral position given as a double.", outputStorage);
     376             :                 }
     377             :                 // process
     378          16 :                 libsumo::Person::moveTo(id, laneID, position, posLat);
     379             :             }
     380             :             break;
     381        2060 :             case libsumo::MOVE_TO_XY: {
     382        2060 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     383           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "MoveToXY person requires a compound object.", outputStorage);
     384             :                 }
     385        2060 :                 const int numArgs = inputStorage.readInt();
     386        2060 :                 if (numArgs != 5 && numArgs != 6) {
     387           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "MoveToXY person should obtain: edgeID, x, y, angle, keepRouteFlag and optionally matchThreshold.", outputStorage);
     388             :                 }
     389             :                 // edge ID
     390             :                 std::string edgeID;
     391        2060 :                 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
     392           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The first parameter for moveToXY must be the edge ID given as a string.", outputStorage);
     393             :                 }
     394             :                 // x
     395        2060 :                 double x = 0;
     396        2060 :                 if (!server.readTypeCheckingDouble(inputStorage, x)) {
     397           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The second parameter for moveToXY must be the x-position given as a double.", outputStorage);
     398             :                 }
     399             :                 // y
     400        2060 :                 double y = 0;
     401        2060 :                 if (!server.readTypeCheckingDouble(inputStorage, y)) {
     402           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The third parameter for moveToXY must be the y-position given as a double.", outputStorage);
     403             :                 }
     404             :                 // angle
     405        2060 :                 double angle = 0;
     406        2060 :                 if (!server.readTypeCheckingDouble(inputStorage, angle)) {
     407           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The fourth parameter for moveToXY must be the angle given as a double.", outputStorage);
     408             :                 }
     409        2060 :                 int keepRouteFlag = 1;
     410        2060 :                 if (!server.readTypeCheckingByte(inputStorage, keepRouteFlag)) {
     411           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The fifth parameter for moveToXY must be the keepRouteFlag given as a byte.", outputStorage);
     412             :                 }
     413        2060 :                 double matchThreshold = 100;
     414        2060 :                 if (numArgs == 6) {
     415        2060 :                     if (!server.readTypeCheckingDouble(inputStorage, matchThreshold)) {
     416           4 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The sixth parameter for moveToXY must be the matchThreshold given as a double.", outputStorage);
     417             :                     }
     418             :                 }
     419        2060 :                 libsumo::Person::moveToXY(id, edgeID, x, y, angle, keepRouteFlag, matchThreshold);
     420             :             }
     421             :             break;
     422          55 :             case libsumo::VAR_PARAMETER: {
     423          55 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     424           8 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);
     425             :                 }
     426             :                 //read itemNo
     427          55 :                 inputStorage.readInt();
     428             :                 std::string name;
     429          55 :                 if (!server.readTypeCheckingString(inputStorage, name)) {
     430           4 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The name of the parameter must be given as a string.", outputStorage);
     431             :                 }
     432             :                 std::string value;
     433          55 :                 if (!server.readTypeCheckingString(inputStorage, value)) {
     434           4 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);
     435             :                 }
     436          55 :                 libsumo::Person::setParameter(id, name, value);
     437             :             }
     438             :             break;
     439          20 :             default:
     440             :                 try {
     441          20 :                     if (!TraCIServerAPI_VehicleType::setVariable(libsumo::CMD_SET_PERSON_VARIABLE, variable, p->getSingularType().getID(), server, inputStorage, outputStorage)) {
     442             :                         return false;
     443             :                     }
     444           0 :                 } catch (ProcessError& e) {
     445           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, e.what(), outputStorage);
     446           0 :                 }
     447             :                 break;
     448             :         }
     449           8 :     } catch (libsumo::TraCIException& e) {
     450           8 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, e.what(), outputStorage);
     451           8 :     }
     452        3562 :     server.writeStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
     453             :     return true;
     454             : }
     455             : 
     456             : 
     457             : /****************************************************************************/

Generated by: LCOV version 1.14