Eclipse SUMO - Simulation of Urban MObility
TraCIServerAPI_Junction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2009-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // APIs for getting/setting junction values via TraCI
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
29 #include "TraCIServer.h"
30 #include <libsumo/Junction.h>
32 
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
37 bool
39  tcpip::Storage& outputStorage) {
40  const int variable = inputStorage.readUnsignedByte();
41  const std::string id = inputStorage.readString();
43  try {
44  if (!libsumo::Junction::handleVariable(id, variable, &server)) {
45  switch (variable) {
46  case libsumo::VAR_SHAPE:
48  break;
49  default:
50  return server.writeErrorStatusCmd(libsumo::CMD_GET_JUNCTION_VARIABLE, "Get Junction Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
51  }
52  }
53  } catch (libsumo::TraCIException& e) {
54  return server.writeErrorStatusCmd(libsumo::CMD_GET_JUNCTION_VARIABLE, e.what(), outputStorage);
55  }
57  server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
58  return true;
59 }
60 
61 
62 /****************************************************************************/
TRACI_CONST int RESPONSE_GET_JUNCTION_VARIABLE
TRACI_CONST int RTYPE_OK
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa9: Get Junction Variable)
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
virtual int readUnsignedByte()
static TraCIPositionVector getShape(const std::string &junctionID)
Definition: Junction.cpp:69
TRACI_CONST int VAR_SHAPE
tcpip::Storage & getWrapperStorage()
virtual std::string readString()
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:62
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
void writePositionVector(tcpip::Storage &outputStorage, const libsumo::TraCIPositionVector &shape)
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:58
TRACI_CONST int CMD_GET_JUNCTION_VARIABLE
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
void initWrapper(const int domainID, const int variable, const std::string &objID)
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: Junction.cpp:113