LCOV - code coverage report
Current view: top level - src/traci-server - TraCIServerAPI_Person.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 78.6 % 262 206
Test Date: 2024-11-20 15:55:46 Functions: 100.0 % 2 2

            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        99080 : TraCIServerAPI_Person::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
      43              :                                   tcpip::Storage& outputStorage) {
      44        99080 :     const int variable = inputStorage.readUnsignedByte();
      45        99080 :     const std::string id = inputStorage.readString();
      46        99080 :     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        99080 :         if (variable == libsumo::SPLIT_TAXI_RESERVATIONS || !libsumo::Person::handleVariable(id, variable, &server, &inputStorage)) {
      50         3238 :             switch (variable) {
      51          687 :                 case libsumo::VAR_EDGES: {
      52          687 :                     int nextStageIndex = 0;
      53          687 :                     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          687 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRINGLIST);
      57          687 :                     server.getWrapperStorage().writeStringList(libsumo::Person::getEdges(id, nextStageIndex));
      58          687 :                     break;
      59              :                 }
      60          453 :                 case libsumo::VAR_STAGE: {
      61          453 :                     int nextStageIndex = 0;
      62          453 :                     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          453 :                     libsumo::StorageHelper::writeStage(server.getWrapperStorage(), libsumo::Person::getStage(id, nextStageIndex));
      66          412 :                     break;
      67              :                 }
      68         2093 :                 case libsumo::VAR_TAXI_RESERVATIONS: {
      69         2093 :                     int onlyNew = 0;
      70         2093 :                     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         2093 :                     const std::vector<libsumo::TraCIReservation> result = libsumo::Person::getTaxiReservations(onlyNew);
      74         2093 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_COMPOUND);
      75         2093 :                     server.getWrapperStorage().writeInt((int)result.size());
      76         5240 :                     for (const libsumo::TraCIReservation& r : result) {
      77         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_COMPOUND);
      78         3147 :                         server.getWrapperStorage().writeInt(10);
      79         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
      80         3147 :                         server.getWrapperStorage().writeString(r.id);
      81         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRINGLIST);
      82         3147 :                         server.getWrapperStorage().writeStringList(r.persons);
      83         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
      84         3147 :                         server.getWrapperStorage().writeString(r.group);
      85         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
      86         3147 :                         server.getWrapperStorage().writeString(r.fromEdge);
      87         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
      88         3147 :                         server.getWrapperStorage().writeString(r.toEdge);
      89         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_DOUBLE);
      90         3147 :                         server.getWrapperStorage().writeDouble(r.departPos);
      91         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_DOUBLE);
      92         3147 :                         server.getWrapperStorage().writeDouble(r.arrivalPos);
      93         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_DOUBLE);
      94         3147 :                         server.getWrapperStorage().writeDouble(r.depart);
      95         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_DOUBLE);
      96         3147 :                         server.getWrapperStorage().writeDouble(r.reservationTime);
      97         3147 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_INTEGER);
      98         3147 :                         server.getWrapperStorage().writeInt(r.state);
      99              :                     }
     100              :                     break;
     101         2093 :                 }
     102              :                 case libsumo::SPLIT_TAXI_RESERVATIONS: {
     103              :                     std::vector<std::string> persons;
     104            3 :                     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            3 :                     std::string splitID = libsumo::Person::splitTaxiReservation(id, persons);
     108            3 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
     109            3 :                     server.getWrapperStorage().writeString(splitID);
     110              :                     break;
     111            3 :                 }
     112            2 :                 default:
     113            6 :                     return server.writeErrorStatusCmd(libsumo::CMD_GET_PERSON_VARIABLE, "Get Person Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
     114              :             }
     115              :         }
     116           49 :     } catch (libsumo::TraCIException& e) {
     117           49 :         return server.writeErrorStatusCmd(libsumo::CMD_GET_PERSON_VARIABLE, e.what(), outputStorage);
     118           49 :     }
     119        99029 :     server.writeStatusCmd(libsumo::CMD_GET_PERSON_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);
     120        99029 :     server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
     121              :     return true;
     122              : }
     123              : 
     124              : 
     125              : bool
     126         2614 : TraCIServerAPI_Person::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
     127              :                                   tcpip::Storage& outputStorage) {
     128         2614 :     std::string warning = ""; // additional description for response
     129              :     // variable
     130         2614 :     int variable = inputStorage.readUnsignedByte();
     131         2614 :     if (variable != libsumo::VAR_PARAMETER
     132         2614 :             && variable != libsumo::ADD
     133         2466 :             && variable != libsumo::REMOVE
     134         2466 :             && variable != libsumo::APPEND_STAGE
     135         2305 :             && variable != libsumo::REPLACE_STAGE
     136         2305 :             && variable != libsumo::REMOVE_STAGE
     137         2195 :             && variable != libsumo::CMD_REROUTE_TRAVELTIME
     138         2195 :             && variable != libsumo::VAR_MOVE_TO
     139         1603 :             && variable != libsumo::MOVE_TO_XY
     140         1603 :             && variable != libsumo::VAR_SPEED
     141           48 :             && variable != libsumo::VAR_TYPE
     142           48 :             && variable != libsumo::VAR_SPEED_FACTOR
     143           20 :             && variable != libsumo::VAR_LENGTH
     144           20 :             && variable != libsumo::VAR_WIDTH
     145           12 :             && variable != libsumo::VAR_HEIGHT
     146           12 :             && variable != libsumo::VAR_MINGAP
     147            4 :             && 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         2614 :         MSTransportableControl& c = MSNet::getInstance()->getPersonControl();
     155              :         // id
     156         2614 :         std::string id = inputStorage.readString();
     157              :         // TODO: remove declaration of p after completion
     158              :         const bool shouldExist = variable != libsumo::ADD;
     159         2614 :         MSTransportable* p = c.get(id);
     160         2614 :         if (p == nullptr && shouldExist) {
     161            0 :             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Person '" + id + "' is not known", outputStorage);
     162              :         }
     163              :         // process
     164         2614 :         switch (variable) {
     165           10 :             case libsumo::VAR_SPEED: {
     166           10 :                 double speed = 0;
     167           10 :                 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           10 :                 libsumo::Person::setSpeed(id, speed);
     172              :             }
     173           10 :             break;
     174              :             case libsumo::VAR_TYPE: {
     175              :                 std::string vTypeID;
     176           10 :                 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           10 :                 libsumo::Person::setType(id, vTypeID);
     180              :                 break;
     181              :             }
     182           18 :             case libsumo::VAR_SPEED_FACTOR: {
     183           18 :                 double speedfactor = 0;
     184           18 :                 if (!server.readTypeCheckingDouble(inputStorage, speedfactor)) {
     185            0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Setting SpeedFactor requires a double.", outputStorage);
     186              :                 }
     187           18 :                 libsumo::Person::setSpeedFactor(id, speedfactor);
     188              :             }
     189           18 :             break;
     190              :             case libsumo::VAR_COLOR: {
     191              :                 libsumo::TraCIColor col;
     192            4 :                 if (!server.readTypeCheckingColor(inputStorage, col)) {
     193            6 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The color must be given using the according type.", outputStorage);
     194              :                 }
     195            4 :                 libsumo::Person::setColor(id, col);
     196              :                 break;
     197              :             }
     198          106 :             case libsumo::ADD: {
     199          106 :                 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          106 :                 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          106 :                 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          106 :                 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          106 :                 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          106 :                 if (!server.readTypeCheckingDouble(inputStorage, pos)) {
     219            0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Fourth parameter (position) requires a double.", outputStorage);
     220              :                 }
     221          212 :                 libsumo::Person::add(id, edgeID, pos, depart, vTypeID);
     222              :             }
     223              :             break;
     224            9 :             case libsumo::REMOVE: {
     225            9 :                 int why = 0;
     226            9 :                 if (!server.readTypeCheckingByte(inputStorage, why)) {
     227            0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Removing a person requires a byte.", outputStorage);
     228              :                 }
     229            9 :                 libsumo::Person::remove(id, (char)why);
     230              :             }
     231            9 :             break;
     232          152 :             case libsumo::APPEND_STAGE: {
     233          152 :                 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          152 :                 int numParameters = inputStorage.readInt();
     237          152 :                 if (numParameters == 13) {
     238           32 :                     libsumo::TraCIStage stage;
     239           16 :                     libsumo::StorageHelper::readStage(inputStorage, stage);
     240           16 :                     libsumo::Person::appendStage(id, stage);
     241           16 :                 } else {
     242              :                     int stageType;
     243          136 :                     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          136 :                     if (stageType == libsumo::STAGE_DRIVING) {
     247              :                         // append driving stage
     248           22 :                         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           22 :                         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           22 :                         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           22 :                         if (!server.readTypeCheckingString(inputStorage, stopID)) {
     261            0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Fourth parameter (stopID) requires a string.", outputStorage);
     262              :                         }
     263           22 :                         libsumo::Person::appendDrivingStage(id, edgeID, lines, stopID);
     264          114 :                     } else if (stageType == libsumo::STAGE_WAITING) {
     265              :                         // append waiting stage
     266           16 :                         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           16 :                         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           16 :                         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           16 :                         if (!server.readTypeCheckingString(inputStorage, stopID)) {
     279            0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Fourth parameter (stopID) requires a string.", outputStorage);
     280              :                         }
     281           16 :                         libsumo::Person::appendWaitingStage(id, duration, description, stopID);
     282           98 :                     } else if (stageType == libsumo::STAGE_WALKING) {
     283              :                         // append walking stage
     284           98 :                         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           98 :                         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           98 :                         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           98 :                         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           98 :                         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           98 :                         if (!server.readTypeCheckingString(inputStorage, stopID)) {
     305            0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Fourth parameter (stopID) requires a string.", outputStorage);
     306              :                         }
     307           98 :                         libsumo::Person::appendWalkingStage(id, edgeIDs, arrivalPos, duration, speed, stopID);
     308           98 :                     } 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            6 :             case libsumo::REPLACE_STAGE : {
     317            6 :                 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            6 :                 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            6 :                 int nextStageIndex = 0;
     324            6 :                 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            6 :                 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            6 :                 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           12 :                 libsumo::TraCIStage stage;
     334            6 :                 libsumo::StorageHelper::readStage(inputStorage, stage);
     335            6 :                 libsumo::Person::replaceStage(id, nextStageIndex, stage);
     336            6 :             }
     337            6 :             break;
     338              : 
     339          104 :             case libsumo::REMOVE_STAGE: {
     340          104 :                 int nextStageIndex = 0;
     341          104 :                 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          104 :                 libsumo::Person::removeStage(id, nextStageIndex);
     345              :             }
     346          104 :             break;
     347          580 :             case libsumo::CMD_REROUTE_TRAVELTIME: {
     348          580 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     349            0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Rerouting requires a compound object.", outputStorage);
     350              :                 }
     351          580 :                 if (inputStorage.readInt() != 0) {
     352            0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);
     353              :                 }
     354          580 :                 libsumo::Person::rerouteTraveltime(id);
     355              :             }
     356              :             break;
     357           12 :             case libsumo::VAR_MOVE_TO: {
     358           12 :                 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           12 :                 const int numArgs = inputStorage.readInt();
     362           12 :                 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           12 :                 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           12 :                 double position = 0;
     370           12 :                 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           12 :                 double posLat = 0;
     374           12 :                 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           12 :                 libsumo::Person::moveTo(id, laneID, position, posLat);
     379              :             }
     380              :             break;
     381         1545 :             case libsumo::MOVE_TO_XY: {
     382         1545 :                 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         1545 :                 const int numArgs = inputStorage.readInt();
     386         1545 :                 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         1545 :                 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         1545 :                 double x = 0;
     396         1545 :                 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         1545 :                 double y = 0;
     401         1545 :                 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         1545 :                 double angle = 0;
     406         1545 :                 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         1545 :                 int keepRouteFlag = 1;
     410         1545 :                 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         1545 :                 double matchThreshold = 100;
     414         1545 :                 if (numArgs == 6) {
     415         1545 :                     if (!server.readTypeCheckingDouble(inputStorage, matchThreshold)) {
     416            3 :                         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         1545 :                 libsumo::Person::moveToXY(id, edgeID, x, y, angle, keepRouteFlag, matchThreshold);
     420              :             }
     421              :             break;
     422           42 :             case libsumo::VAR_PARAMETER: {
     423           42 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     424            6 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);
     425              :                 }
     426              :                 //read itemNo
     427           42 :                 inputStorage.readInt();
     428              :                 std::string name;
     429           42 :                 if (!server.readTypeCheckingString(inputStorage, name)) {
     430            3 :                     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           42 :                 if (!server.readTypeCheckingString(inputStorage, value)) {
     434            3 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);
     435              :                 }
     436           42 :                 libsumo::Person::setParameter(id, name, value);
     437              :             }
     438              :             break;
     439           16 :             default:
     440              :                 try {
     441           16 :                     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            6 :     } catch (libsumo::TraCIException& e) {
     450            6 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, e.what(), outputStorage);
     451            6 :     }
     452         2608 :     server.writeStatusCmd(libsumo::CMD_SET_PERSON_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
     453              :     return true;
     454              : }
     455              : 
     456              : 
     457              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1