Eclipse SUMO - Simulation of Urban MObility
TraCIServerAPI_MultiEntryExit.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
16 // APIs for getting/setting multi-entry/multi-exit detector values via TraCI
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
26 #include <libsumo/MultiEntryExit.h>
27 #include <libsumo/TraCIConstants.h>
29 
30 
31 // ===========================================================================
32 // method definitions
33 // ===========================================================================
34 bool
36  tcpip::Storage& outputStorage) {
37  const int variable = inputStorage.readUnsignedByte();
38  const std::string id = inputStorage.readString();
40  try {
41  if (!libsumo::MultiEntryExit::handleVariable(id, variable, &server)) {
42  return server.writeErrorStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, "Get Multi Entry Exit Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
43  }
44  } catch (libsumo::TraCIException& e) {
45  return server.writeErrorStatusCmd(libsumo::CMD_GET_MULTIENTRYEXIT_VARIABLE, e.what(), outputStorage);
46  }
48  server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
49  return true;
50 }
51 
52 
53 /****************************************************************************/
TRACI_CONST int RTYPE_OK
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()
TRACI_CONST int RESPONSE_GET_MULTIENTRYEXIT_VARIABLE
TRACI_CONST int CMD_GET_MULTIENTRYEXIT_VARIABLE
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:58
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get MeMeDetector 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)