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 | RerouterScope |
Scope for interaction with rerouters. More... | |
class | RouteProbeScope |
Scope for interaction with route probes. 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 | |
std::pair< int, std::string > | getVersion () |
return TraCI API and SUMO version | |
void | load (const std::vector< std::string > &args) |
Let sumo load a simulation using the given command line like options. | |
void | simulationStep (double time=0) |
Advances by one step (or up to the given time) | |
TraCIAPI () | |
Constructor. | |
~TraCIAPI () | |
Destructor. | |
Connection handling | |
void | connect (const std::string &host, int port) |
Connects to the specified SUMO server. | |
void | setOrder (int order) |
set priority (execution order) for the client | |
void | close () |
ends the simulation and closes the connection | |
Data Fields | |
EdgeScope | edge |
Scope for interaction with edges. | |
GUIScope | gui |
Scope for interaction with the gui. | |
InductionLoopScope | inductionloop |
Scope for interaction with inductive loops. | |
JunctionScope | junction |
Scope for interaction with junctions. | |
LaneScope | lane |
Scope for interaction with lanes. | |
LaneAreaScope | lanearea |
Scope for interaction with lanes. | |
MeMeScope | multientryexit |
Scope for interaction with multi-entry/-exit detectors. | |
PersonScope | person |
Scope for interaction with persons. | |
POIScope | poi |
Scope for interaction with POIs. | |
PolygonScope | polygon |
Scope for interaction with polygons. | |
RerouterScope | rerouter |
Scope for interaction with rerouters. | |
RouteScope | route |
Scope for interaction with routes. | |
RouteProbeScope | routeprobe |
Scope for interaction with route probes. | |
SimulationScope | simulation |
Scope for interaction with the simulation. | |
TrafficLightScope | trafficlights |
Scope for interaction with traffic lights. | |
VehicleScope | vehicle |
Scope for interaction with vehicles. | |
VehicleTypeScope | vehicletype |
Scope for interaction with vehicle types. | |
Protected Member Functions | |
void | closeSocket () |
Closes the connection. | |
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) |
Command sending methods | |
void | send_commandSimulationStep (double time) const |
Sends a SimulationStep command. | |
void | send_commandClose () const |
Sends a Close command. | |
void | send_commandSetOrder (int order) const |
Sends a SetOrder command. | |
void | createCommand (int cmdID, int varID, const std::string &objID, tcpip::Storage *add=nullptr) const |
Sends a GetVariable / SetVariable request if mySocket is connected. Otherwise writes to myOutput only. | |
void | createFilterCommand (int cmdID, int varID, tcpip::Storage *add=nullptr) const |
void | send_commandSubscribeObjectVariable (int domID, const std::string &objID, double beginTime, double endTime, const std::vector< int > &vars) const |
Sends a SubscribeVariable request. | |
void | send_commandSubscribeObjectContext (int domID, const std::string &objID, double beginTime, double endTime, int domain, double range, const std::vector< int > &vars) const |
Sends a SubscribeContext request. | |
void | check_resultState (tcpip::Storage &inMsg, int command, bool ignoreCommandId=false, std::string *acknowledgement=0) const |
Validates the result state of a command. | |
int | check_commandGetResult (tcpip::Storage &inMsg, int command, int expectedType=-1, bool ignoreCommandId=false) const |
Validates the result state of a command. | |
bool | processGet (int command, int expectedType, bool ignoreCommandId=false) |
bool | processSet (int command) |
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. | |
tcpip::Storage | myOutput |
The reusable output storage. | |
tcpip::Socket * | mySocket |
The socket. | |
C++ TraCI client API implementation.
Definition at line 48 of file TraCIAPI.h.
TraCIAPI::TraCIAPI | ( | ) |
Constructor.
Definition at line 34 of file TraCIAPI.cpp.
References edge, gui, junction, lane, lanearea, multientryexit, myDomains, person, poi, polygon, rerouter, 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_REROUTER_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_ROUTE_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_ROUTEPROBE_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_SIM_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_TL_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_VEHICLE_VARIABLE, libsumo::RESPONSE_SUBSCRIBE_VEHICLETYPE_VARIABLE, route, routeprobe, simulation, trafficlights, vehicle, and vehicletype.
TraCIAPI::~TraCIAPI | ( | ) |
|
protected |
Validates the result state of a command.
Definition at line 299 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 260 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(), getVersion(), load(), processGet(), processSet(), setOrder(), and simulationStep().
void TraCIAPI::close | ( | ) |
ends the simulation and closes the connection
Definition at line 96 of file TraCIAPI.cpp.
References check_resultState(), closeSocket(), libsumo::CMD_CLOSE, and send_commandClose().
|
protected |
Closes the connection.
Definition at line 106 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 68 of file TraCIAPI.cpp.
References tcpip::Socket::connect(), and mySocket.
Referenced by TraCITestClient::joinToString(), TraCITestClient::joinToString(), TraCITestClient::joinToString(), and 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 154 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(), and TraCITestClient::commandSetValue().
|
protected |
Definition at line 178 of file TraCIAPI.cpp.
References myOutput, tcpip::Storage::reset(), tcpip::Storage::size(), tcpip::Storage::writeInt(), tcpip::Storage::writeStorage(), and tcpip::Storage::writeUnsignedByte().
std::pair< int, std::string > TraCIAPI::getVersion | ( | ) |
return TraCI API and SUMO version
Definition at line 479 of file TraCIAPI.cpp.
References check_resultState(), libsumo::CMD_GETVERSION, mySocket, tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), tcpip::Socket::sendExact(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::testAPI().
void TraCIAPI::load | ( | const std::vector< std::string > & | args | ) |
Let sumo load a simulation using the given command line like options.
Definition at line 461 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 323 of file TraCIAPI.cpp.
References check_commandGetResult(), check_resultState(), myInput, myOutput, mySocket, tcpip::Storage::reset(), and tcpip::Socket::sendExact().
|
protected |
Definition at line 336 of file TraCIAPI.cpp.
References check_resultState(), myInput, myOutput, mySocket, tcpip::Storage::reset(), and tcpip::Socket::sendExact().
|
protected |
Definition at line 424 of file TraCIAPI.cpp.
References myDomains, tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), and readVariables().
Referenced by simulationStep().
|
protected |
Definition at line 348 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 416 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 130 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 141 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 117 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 229 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 201 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 81 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 439 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 942 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 829 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
GUIScope TraCIAPI::gui |
Scope for interaction with the gui.
Definition at line 831 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
InductionLoopScope TraCIAPI::inductionloop |
Scope for interaction with inductive loops.
Definition at line 833 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI().
JunctionScope TraCIAPI::junction |
Scope for interaction with junctions.
Definition at line 835 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
LaneScope TraCIAPI::lane |
Scope for interaction with lanes.
Definition at line 837 of file TraCIAPI.h.
Referenced by TraCIAPI::VehicleScope::moveToXY(), TraCITestClient::testAPI(), and TraCIAPI().
LaneAreaScope TraCIAPI::lanearea |
Scope for interaction with lanes.
Definition at line 839 of file TraCIAPI.h.
Referenced by TraCIAPI().
MeMeScope TraCIAPI::multientryexit |
Scope for interaction with multi-entry/-exit detectors.
Definition at line 841 of file TraCIAPI.h.
Referenced by TraCIAPI().
|
protected |
Definition at line 954 of file TraCIAPI.h.
Referenced by readContextSubscription(), readVariableSubscription(), simulationStep(), and TraCIAPI().
|
mutableprotected |
The reusable input storage.
Definition at line 960 of file TraCIAPI.h.
Referenced by processGet(), and processSet().
|
mutableprotected |
The reusable output storage.
Definition at line 958 of file TraCIAPI.h.
Referenced by TraCITestClient::commandGetVariable(), TraCITestClient::commandSetValue(), createCommand(), createFilterCommand(), processGet(), and processSet().
|
protected |
The socket.
Definition at line 956 of file TraCIAPI.h.
Referenced by check_resultState(), closeSocket(), TraCITestClient::commandGetVariable(), TraCITestClient::commandSetValue(), connect(), getVersion(), 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 843 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
POIScope TraCIAPI::poi |
Scope for interaction with POIs.
Definition at line 845 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
PolygonScope TraCIAPI::polygon |
Scope for interaction with polygons.
Definition at line 847 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
RerouterScope TraCIAPI::rerouter |
Scope for interaction with rerouters.
Definition at line 849 of file TraCIAPI.h.
Referenced by TraCIAPI().
RouteScope TraCIAPI::route |
Scope for interaction with routes.
Definition at line 851 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
RouteProbeScope TraCIAPI::routeprobe |
Scope for interaction with route probes.
Definition at line 853 of file TraCIAPI.h.
Referenced by TraCIAPI().
SimulationScope TraCIAPI::simulation |
Scope for interaction with the simulation.
Definition at line 855 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
TrafficLightScope TraCIAPI::trafficlights |
Scope for interaction with traffic lights.
Definition at line 857 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
VehicleScope TraCIAPI::vehicle |
Scope for interaction with vehicles.
Definition at line 859 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
VehicleTypeScope TraCIAPI::vehicletype |
Scope for interaction with vehicle types.
Definition at line 861 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().