SUMO - Simulation of Urban MObility
TraCIServerAPI_LaneArea.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-2018 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 areal detector values via TraCI
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
28 #include "TraCIConstants.h"
29 #include "TraCIServer.h"
30 #include <libsumo/LaneArea.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();
42  server.initWrapper(RESPONSE_GET_LANEAREA_VARIABLE, variable, id);
43  try {
44  if (!libsumo::LaneArea::handleVariable(id, variable, &server)) {
45  return server.writeErrorStatusCmd(CMD_GET_LANEAREA_VARIABLE, "Get Lane Area Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
46  }
47  } catch (libsumo::TraCIException& e) {
48  return server.writeErrorStatusCmd(CMD_GET_LANEAREA_VARIABLE, e.what(), outputStorage);
49  }
50  server.writeStatusCmd(CMD_GET_LANEAREA_VARIABLE, RTYPE_OK, "", outputStorage);
51  server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
52  return true;
53 }
54 
55 
56 /****************************************************************************/
#define RTYPE_OK
#define CMD_GET_LANEAREA_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 bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get AreaDetector Variable)
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: LaneArea.cpp:141
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)
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:59
#define RESPONSE_GET_LANEAREA_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)