![]() |
Eclipse SUMO - Simulation of Urban MObility
|
C++ TraCI client API implementation. More...
#include <TraCIAPI.h>
Data Structures | |
class | EdgeScope |
Scope for interaction with edges. More... | |
class | GUIScope |
Scope for interaction with the gui. More... | |
class | InductionLoopScope |
Scope for interaction with inductive loops. More... | |
class | JunctionScope |
Scope for interaction with junctions. More... | |
class | LaneAreaScope |
Scope for interaction with lane area detectors. More... | |
class | LaneScope |
Scope for interaction with lanes. More... | |
class | MeMeScope |
Scope for interaction with multi entry/-exit detectors. More... | |
class | PersonScope |
Scope for interaction with vehicles. More... | |
class | POIScope |
Scope for interaction with POIs. More... | |
class | PolygonScope |
Scope for interaction with polygons. More... | |
class | RouteScope |
Scope for interaction with routes. More... | |
class | SimulationScope |
Scope for interaction with the simulation. More... | |
class | TraCIScopeWrapper |
An abstract interface for accessing type-dependent values. More... | |
class | TrafficLightScope |
Scope for interaction with traffic lights. More... | |
class | VehicleScope |
Scope for interaction with vehicles. More... | |
class | VehicleTypeScope |
Scope for interaction with vehicle types. More... | |
Public Member Functions | |
const tcpip::Storage & | getCommandStorage () const |
void | load (const std::vector< std::string > &args) |
Let sumo load a simulation using the given command line like options. More... | |
void | simulationStep (double time=0) |
Advances by one step (or up to the given time) More... | |
TraCIAPI () | |
Constructor. More... | |
~TraCIAPI () | |
Destructor. More... | |
Data Fields | |
EdgeScope | edge |
Scope for interaction with edges. More... | |
GUIScope | gui |
Scope for interaction with the gui. More... | |
InductionLoopScope | inductionloop |
Scope for interaction with inductive loops. More... | |
JunctionScope | junction |
Scope for interaction with junctions. More... | |
LaneScope | lane |
Scope for interaction with lanes. More... | |
LaneAreaScope | lanearea |
Scope for interaction with lanes. More... | |
MeMeScope | multientryexit |
Scope for interaction with multi-entry/-exit detectors. More... | |
PersonScope | person |
Scope for interaction with persons. More... | |
POIScope | poi |
Scope for interaction with POIs. More... | |
PolygonScope | polygon |
Scope for interaction with polygons. More... | |
RouteScope | route |
Scope for interaction with routes. More... | |
SimulationScope | simulation |
Scope for interaction with the simulation. More... | |
TrafficLightScope | trafficlights |
Scope for interaction with traffic lights. More... | |
VehicleScope | vehicle |
Scope for interaction with vehicles. More... | |
VehicleTypeScope | vehicletype |
Scope for interaction with vehicle types. More... | |
Protected Member Functions | |
void | closeSocket () |
Closes the connection. More... | |
void | readContextSubscription (int cmdId, tcpip::Storage &inMsg) |
void | readVariables (tcpip::Storage &inMsg, const std::string &objectID, int variableCount, libsumo::SubscriptionResults &into) |
void | readVariableSubscription (int cmdId, tcpip::Storage &inMsg) |
Static Protected Member Functions | |
template<class T > | |
static std::string | toString (const T &t, std::streamsize accuracy=PRECISION) |
Protected Attributes | |
std::map< int, TraCIScopeWrapper * > | myDomains |
tcpip::Storage | myInput |
The reusable input storage. More... | |
tcpip::Storage | myOutput |
The reusable output storage. More... | |
tcpip::Socket * | mySocket |
The socket. More... | |
C++ TraCI client API implementation.
Definition at line 49 of file TraCIAPI.h.
TraCIAPI::TraCIAPI | ( | ) |
Constructor.
Definition at line 41 of file TraCIAPI.cpp.
References edge, gui, junction, lane, lanearea, multientryexit, myDomains, person, poi, polygon, libsumo::RESPONSE_SUBSCRIBE_EDGE_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_GUI_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_JUNCTION_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_LANE_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_LANEAREA_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_PERSON_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_POI_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_POLYGON_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_ROUTE_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_SIM_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_TL_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_VEHICLE_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_VEHICLETYPE_VARIABLE, route, simulation, trafficlights, vehicle, and vehicletype.
TraCIAPI::~TraCIAPI | ( | ) |
|
protected |
Validates the result state of a command.
Definition at line 305 of file TraCIAPI.cpp.
References tcpip::Storage::position(), tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), and toString().
Referenced by TraCITestClient::commandGetVariable(), processGet(), and simulationStep().
|
protected |
Validates the result state of a command.
[in] | inMsg | The buffer to read the message from |
[in] | command | The original command id |
[in] | ignoreCommandId | Whether the returning command id shall be validated |
[in] | acknowledgement | Pointer to an existing string into which the acknowledgement message shall be inserted |
Definition at line 266 of file TraCIAPI.cpp.
References mySocket, tcpip::Storage::position(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), tcpip::Socket::receiveExact(), libsumo::RTYPE_ERR, libsumo::RTYPE_NOTIMPLEMENTED, libsumo::RTYPE_OK, and toString().
Referenced by close(), TraCITestClient::commandClose(), TraCITestClient::commandGetVariable(), TraCITestClient::commandSetOrder(), TraCITestClient::commandSetValue(), TraCITestClient::commandSimulationStep(), TraCITestClient::commandSubscribeContextVariable(), TraCITestClient::commandSubscribeObjectVariable(), load(), processGet(), processSet(), setOrder(), and simulationStep().
void TraCIAPI::close | ( | ) |
ends the simulation and closes the connection
Definition at line 102 of file TraCIAPI.cpp.
References check_resultState(), closeSocket(), libsumo::CMD_CLOSE, and send_commandClose().
|
protected |
Closes the connection.
Definition at line 112 of file TraCIAPI.cpp.
References tcpip::Socket::close(), and mySocket.
Referenced by close(), and TraCITestClient::run().
void TraCIAPI::connect | ( | const std::string & | host, |
int | port | ||
) |
Connects to the specified SUMO server.
[in] | host | The name of the host to connect to |
[in] | port | The port to connect to |
tcpip::SocketException | if the connection fails |
Definition at line 74 of file TraCIAPI.cpp.
References tcpip::Socket::connect(), and mySocket.
Referenced by TraCITestClient::run().
|
protected |
Sends a GetVariable / SetVariable request if mySocket is connected. Otherwise writes to myOutput only.
[in] | cmdID | The command and domain of the variable |
[in] | varID | The variable to retrieve |
[in] | objID | The object to retrieve the variable from |
[in] | add | Optional additional parameter |
Definition at line 160 of file TraCIAPI.cpp.
References myOutput, tcpip::Storage::reset(), tcpip::Storage::size(), tcpip::Storage::writeInt(), tcpip::Storage::writeStorage(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandGetVariable(), TraCITestClient::commandSetValue(), getByte(), getColor(), getDouble(), getInt(), getPolygon(), getPosition(), getPosition3D(), getString(), getStringVector(), getTraCIStage(), and getUnsignedByte().
|
protected |
Definition at line 184 of file TraCIAPI.cpp.
References myOutput, tcpip::Storage::reset(), tcpip::Storage::size(), tcpip::Storage::writeInt(), tcpip::Storage::writeStorage(), and tcpip::Storage::writeUnsignedByte().
int TraCIAPI::getByte | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 364 of file TraCIAPI.cpp.
References createCommand(), libsumo::INVALID_INT_VALUE, myInput, processGet(), tcpip::Storage::readByte(), and libsumo::TYPE_BYTE.
libsumo::TraCIColor TraCIAPI::getColor | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 466 of file TraCIAPI.cpp.
References libsumo::TraCIColor::a, libsumo::TraCIColor::b, createCommand(), libsumo::TraCIColor::g, myInput, processGet(), libsumo::TraCIColor::r, tcpip::Storage::readUnsignedByte(), and libsumo::TYPE_COLOR.
|
inline |
Definition at line 96 of file TraCIAPI.h.
References myOutput.
double TraCIAPI::getDouble | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 385 of file TraCIAPI.cpp.
References createCommand(), libsumo::INVALID_DOUBLE_VALUE, myInput, processGet(), tcpip::Storage::readDouble(), and libsumo::TYPE_DOUBLE.
int TraCIAPI::getInt | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 375 of file TraCIAPI.cpp.
References createCommand(), libsumo::INVALID_INT_VALUE, myInput, processGet(), tcpip::Storage::readInt(), and libsumo::TYPE_INTEGER.
libsumo::TraCIPositionVector TraCIAPI::getPolygon | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 395 of file TraCIAPI.cpp.
References createCommand(), myInput, processGet(), tcpip::Storage::readDouble(), tcpip::Storage::readInt(), tcpip::Storage::readUnsignedByte(), libsumo::TYPE_POLYGON, libsumo::TraCIPosition::x, libsumo::TraCIPosition::y, and libsumo::TraCIPosition::z.
libsumo::TraCIPosition TraCIAPI::getPosition | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 416 of file TraCIAPI.cpp.
References createCommand(), myInput, libsumo::POSITION_2D, processGet(), tcpip::Storage::readDouble(), libsumo::TraCIPosition::x, libsumo::TraCIPosition::y, and libsumo::TraCIPosition::z.
libsumo::TraCIPosition TraCIAPI::getPosition3D | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 429 of file TraCIAPI.cpp.
References createCommand(), myInput, libsumo::POSITION_3D, processGet(), tcpip::Storage::readDouble(), libsumo::TraCIPosition::x, libsumo::TraCIPosition::y, and libsumo::TraCIPosition::z.
std::string TraCIAPI::getString | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 442 of file TraCIAPI.cpp.
References createCommand(), myInput, processGet(), tcpip::Storage::readString(), and libsumo::TYPE_STRING.
std::vector< std::string > TraCIAPI::getStringVector | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 452 of file TraCIAPI.cpp.
References createCommand(), myInput, processGet(), tcpip::Storage::readInt(), tcpip::Storage::readString(), and libsumo::TYPE_STRINGLIST.
Referenced by TraCIAPI::EdgeScope::getIDList().
libsumo::TraCIStage TraCIAPI::getTraCIStage | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 480 of file TraCIAPI.cpp.
References libsumo::TraCIStage::arrivalPos, libsumo::TraCIStage::cost, createCommand(), libsumo::TraCIStage::depart, libsumo::TraCIStage::departPos, libsumo::TraCIStage::description, libsumo::TraCIStage::destStop, libsumo::TraCIStage::edges, libsumo::TraCIStage::intended, libsumo::TraCIStage::length, libsumo::TraCIStage::line, myInput, processGet(), tcpip::Storage::readDouble(), tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readStringList(), tcpip::Storage::readUnsignedByte(), libsumo::TraCIStage::travelTime, libsumo::TraCIStage::type, libsumo::TYPE_COMPOUND, and libsumo::TraCIStage::vType.
int TraCIAPI::getUnsignedByte | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 354 of file TraCIAPI.cpp.
References createCommand(), libsumo::INVALID_INT_VALUE, myInput, processGet(), tcpip::Storage::readUnsignedByte(), and libsumo::TYPE_UBYTE.
void TraCIAPI::load | ( | const std::vector< std::string > & | args | ) |
Let sumo load a simulation using the given command line like options.
Definition at line 642 of file TraCIAPI.cpp.
References check_resultState(), libsumo::CMD_LOAD, mySocket, tcpip::Socket::sendExact(), libsumo::TYPE_STRINGLIST, tcpip::Storage::writeInt(), tcpip::Storage::writeStringList(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::testAPI().
|
protected |
Definition at line 329 of file TraCIAPI.cpp.
References check_commandGetResult(), check_resultState(), myInput, myOutput, mySocket, tcpip::Storage::reset(), and tcpip::Socket::sendExact().
Referenced by getByte(), getColor(), getDouble(), getInt(), getPolygon(), getPosition(), getPosition3D(), getString(), getStringVector(), getTraCIStage(), and getUnsignedByte().
|
protected |
Definition at line 342 of file TraCIAPI.cpp.
References check_resultState(), myInput, myOutput, mySocket, tcpip::Storage::reset(), and tcpip::Socket::sendExact().
|
protected |
Definition at line 605 of file TraCIAPI.cpp.
References myDomains, tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), and readVariables().
Referenced by simulationStep().
|
protected |
Definition at line 529 of file TraCIAPI.cpp.
References libsumo::POSITION_2D, libsumo::POSITION_3D, tcpip::Storage::readDouble(), tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), libsumo::RTYPE_OK, toString(), libsumo::TYPE_COLOR, libsumo::TYPE_DOUBLE, libsumo::TYPE_INTEGER, libsumo::TYPE_STRING, and libsumo::TYPE_STRINGLIST.
Referenced by readContextSubscription(), and readVariableSubscription().
|
protected |
Definition at line 597 of file TraCIAPI.cpp.
References myDomains, tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), and readVariables().
Referenced by simulationStep().
|
protected |
Sends a Close command.
Definition at line 136 of file TraCIAPI.cpp.
References libsumo::CMD_CLOSE, mySocket, tcpip::Socket::sendExact(), and tcpip::Storage::writeUnsignedByte().
Referenced by close(), and TraCITestClient::commandClose().
|
protected |
Sends a SetOrder command.
Definition at line 147 of file TraCIAPI.cpp.
References libsumo::CMD_SETORDER, mySocket, tcpip::Socket::sendExact(), tcpip::Storage::writeInt(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandSetOrder().
|
protected |
Sends a SimulationStep command.
Definition at line 123 of file TraCIAPI.cpp.
References libsumo::CMD_SIMSTEP, mySocket, tcpip::Socket::sendExact(), tcpip::Storage::writeDouble(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandSimulationStep(), and simulationStep().
|
protected |
Sends a SubscribeContext request.
[in] | domID | The domain of the variable |
[in] | objID | The object to subscribe the variables from |
[in] | beginTime | The begin time step of subscriptions |
[in] | endTime | The end time step of subscriptions |
[in] | domain | The domain of the objects which values shall be returned |
[in] | range | The range around the obj to investigate |
[in] | vars | The variables to subscribe |
Definition at line 235 of file TraCIAPI.cpp.
References mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeDouble(), tcpip::Storage::writeInt(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandSubscribeContextVariable().
|
protected |
Sends a SubscribeVariable request.
[in] | domID | The domain of the variable |
[in] | objID | The object to subscribe the variables from |
[in] | beginTime | The begin time step of subscriptions |
[in] | endTime | The end time step of subscriptions |
[in] | vars | The variables to subscribe |
Definition at line 207 of file TraCIAPI.cpp.
References mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeDouble(), tcpip::Storage::writeInt(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandSubscribeObjectVariable().
void TraCIAPI::setOrder | ( | int | order | ) |
set priority (execution order) for the client
Definition at line 87 of file TraCIAPI.cpp.
References check_resultState(), libsumo::CMD_SETORDER, mySocket, tcpip::Socket::sendExact(), tcpip::Storage::writeInt(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::testAPI().
void TraCIAPI::simulationStep | ( | double | time = 0 | ) |
Advances by one step (or up to the given time)
Definition at line 620 of file TraCIAPI.cpp.
References check_commandGetResult(), check_resultState(), libsumo::CMD_SIMSTEP, myDomains, readContextSubscription(), tcpip::Storage::readInt(), readVariableSubscription(), libsumo::RESPONSE_SUBSCRIBE_INDUCTIONLOOP_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_PERSON_VARIABLE, and send_commandSimulationStep().
Referenced by TraCITestClient::testAPI().
|
inlinestaticprotected |
Definition at line 1043 of file TraCIAPI.h.
Referenced by TraCIAPI::VehicleScope::add(), check_commandGetResult(), check_resultState(), and readVariables().
EdgeScope TraCIAPI::edge |
Scope for interaction with edges.
Definition at line 934 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
GUIScope TraCIAPI::gui |
Scope for interaction with the gui.
Definition at line 936 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
InductionLoopScope TraCIAPI::inductionloop |
Scope for interaction with inductive loops.
Definition at line 938 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI().
JunctionScope TraCIAPI::junction |
Scope for interaction with junctions.
Definition at line 940 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
LaneScope TraCIAPI::lane |
Scope for interaction with lanes.
Definition at line 942 of file TraCIAPI.h.
Referenced by TraCIAPI::VehicleScope::moveToXY(), TraCITestClient::testAPI(), and TraCIAPI().
LaneAreaScope TraCIAPI::lanearea |
Scope for interaction with lanes.
Definition at line 944 of file TraCIAPI.h.
Referenced by TraCIAPI().
MeMeScope TraCIAPI::multientryexit |
Scope for interaction with multi-entry/-exit detectors.
Definition at line 946 of file TraCIAPI.h.
Referenced by TraCIAPI().
|
protected |
Definition at line 1055 of file TraCIAPI.h.
Referenced by readContextSubscription(), readVariableSubscription(), simulationStep(), and TraCIAPI().
|
mutableprotected |
The reusable input storage.
Definition at line 1061 of file TraCIAPI.h.
Referenced by getByte(), getColor(), getDouble(), getInt(), getPolygon(), getPosition(), getPosition3D(), getString(), getStringVector(), getTraCIStage(), getUnsignedByte(), processGet(), and processSet().
|
mutableprotected |
The reusable output storage.
Definition at line 1059 of file TraCIAPI.h.
Referenced by TraCITestClient::commandGetVariable(), TraCITestClient::commandSetValue(), createCommand(), createFilterCommand(), getCommandStorage(), processGet(), and processSet().
|
protected |
The socket.
Definition at line 1057 of file TraCIAPI.h.
Referenced by check_resultState(), closeSocket(), TraCITestClient::commandGetVariable(), TraCITestClient::commandSetValue(), connect(), load(), processGet(), processSet(), send_commandClose(), send_commandSetOrder(), send_commandSimulationStep(), send_commandSubscribeObjectContext(), send_commandSubscribeObjectVariable(), setOrder(), and ~TraCIAPI().
PersonScope TraCIAPI::person |
Scope for interaction with persons.
Definition at line 948 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
POIScope TraCIAPI::poi |
Scope for interaction with POIs.
Definition at line 950 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
PolygonScope TraCIAPI::polygon |
Scope for interaction with polygons.
Definition at line 952 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
RouteScope TraCIAPI::route |
Scope for interaction with routes.
Definition at line 954 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
SimulationScope TraCIAPI::simulation |
Scope for interaction with the simulation.
Definition at line 956 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
TrafficLightScope TraCIAPI::trafficlights |
Scope for interaction with traffic lights.
Definition at line 958 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
VehicleScope TraCIAPI::vehicle |
Scope for interaction with vehicles.
Definition at line 960 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
VehicleTypeScope TraCIAPI::vehicletype |
Scope for interaction with vehicle types.
Definition at line 962 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().