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 /****************************************************************************/
18 // APIs for getting/setting junction values via TraCI
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
28 #include "TraCIServer.h"
29 #include <libsumo/Junction.h>
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
36 bool
38  tcpip::Storage& outputStorage) {
39  const int variable = inputStorage.readUnsignedByte();
40  const std::string id = inputStorage.readString();
42  try {
43  if (!libsumo::Junction::handleVariable(id, variable, &server)) {
44  switch (variable) {
45  case libsumo::VAR_SHAPE:
47  break;
48  default:
49  return server.writeErrorStatusCmd(libsumo::CMD_GET_JUNCTION_VARIABLE, "Get Junction Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
50  }
51  }
52  } catch (libsumo::TraCIException& e) {
53  return server.writeErrorStatusCmd(libsumo::CMD_GET_JUNCTION_VARIABLE, e.what(), outputStorage);
54  }
56  server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
57  return true;
58 }
59 
60 
61 /****************************************************************************/
libsumo::RTYPE_OK
TRACI_CONST int RTYPE_OK
Definition: TraCIConstants.h:352
libsumo::RESPONSE_GET_JUNCTION_VARIABLE
TRACI_CONST int RESPONSE_GET_JUNCTION_VARIABLE
Definition: TraCIConstants.h:226
Junction.h
TraCIServer::writeResponseWithLength
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
Definition: TraCIServer.cpp:1366
libsumo::Junction::handleVariable
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: Junction.cpp:112
MSJunctionControl.h
TraCIServer::getWrapperStorage
tcpip::Storage & getWrapperStorage()
Definition: TraCIServer.cpp:174
TraCIServer::writeStatusCmd
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
Definition: TraCIServer.cpp:968
TraCIServer::initWrapper
void initWrapper(const int domainID, const int variable, const std::string &objID)
Definition: TraCIServer.cpp:102
libsumo::VAR_SHAPE
TRACI_CONST int VAR_SHAPE
Definition: TraCIConstants.h:669
tcpip::Storage::readUnsignedByte
virtual int readUnsignedByte()
tcpip::Storage::readString
virtual std::string readString()
toHex
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:57
libsumo::TraCIException
Definition: TraCIDefs.h:89
TraCIServer::writePositionVector
void writePositionVector(tcpip::Storage &outputStorage, const libsumo::TraCIPositionVector &shape)
Definition: TraCIServer.cpp:1378
TraCIServerAPI_Junction.h
TraCIServer.h
config.h
TraCIServerAPI_Junction::processGet
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa9: Get Junction Variable)
Definition: TraCIServerAPI_Junction.cpp:37
TraCIServer
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:61
tcpip::Storage
Definition: storage.h:36
libsumo::Junction::getShape
static TraCIPositionVector getShape(const std::string &junctionID)
Definition: Junction.cpp:68
libsumo::CMD_GET_JUNCTION_VARIABLE
TRACI_CONST int CMD_GET_JUNCTION_VARIABLE
Definition: TraCIConstants.h:224
TraCIServer::writeErrorStatusCmd
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
Definition: TraCIServer.cpp:982