Eclipse SUMO - Simulation of Urban MObility
TraCIAPI Class Reference

C++ TraCI client API implementation. More...

#include <TraCIAPI.h>

Inheritance diagram for TraCIAPI:
[legend]
Collaboration diagram for TraCIAPI:
[legend]

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 More...
 
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...
 
RerouterScope rerouter
 Scope for interaction with rerouters. More...
 
RouteScope route
 Scope for interaction with routes. More...
 
RouteProbeScope routeprobe
 Scope for interaction with route probes. 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::SocketmySocket
 The socket. More...
 

Detailed Description

C++ TraCI client API implementation.

Definition at line 48 of file TraCIAPI.h.

Constructor & Destructor Documentation

◆ TraCIAPI()

◆ ~TraCIAPI()

TraCIAPI::~TraCIAPI ( )

Destructor.

Definition at line 70 of file TraCIAPI.cpp.

References mySocket.

Member Function Documentation

◆ check_commandGetResult()

int TraCIAPI::check_commandGetResult ( tcpip::Storage inMsg,
int  command,
int  expectedType = -1,
bool  ignoreCommandId = false 
) const
protected

Validates the result state of a command.

Returns
The command Id

Definition at line 307 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().

Here is the caller graph for this function:

◆ check_resultState()

void TraCIAPI::check_resultState ( tcpip::Storage inMsg,
int  command,
bool  ignoreCommandId = false,
std::string *  acknowledgement = 0 
) const
protected

Validates the result state of a command.

Parameters
[in]inMsgThe buffer to read the message from
[in]commandThe original command id
[in]ignoreCommandIdWhether the returning command id shall be validated
[in]acknowledgementPointer to an existing string into which the acknowledgement message shall be inserted

Definition at line 268 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().

Here is the caller graph for this function:

◆ close()

void TraCIAPI::close ( )

ends the simulation and closes the connection

Definition at line 104 of file TraCIAPI.cpp.

References check_resultState(), closeSocket(), libsumo::CMD_CLOSE, and send_commandClose().

◆ closeSocket()

void TraCIAPI::closeSocket ( )
protected

Closes the connection.

Definition at line 114 of file TraCIAPI.cpp.

References tcpip::Socket::close(), and mySocket.

Referenced by close(), and TraCITestClient::run().

Here is the caller graph for this function:

◆ connect()

void TraCIAPI::connect ( const std::string &  host,
int  port 
)

Connects to the specified SUMO server.

Parameters
[in]hostThe name of the host to connect to
[in]portThe port to connect to
Exceptions
tcpip::SocketExceptionif the connection fails

Definition at line 76 of file TraCIAPI.cpp.

References tcpip::Socket::connect(), and mySocket.

Referenced by TraCITestClient::joinToString(), and TraCITestClient::run().

Here is the caller graph for this function:

◆ createCommand()

void TraCIAPI::createCommand ( int  cmdID,
int  varID,
const std::string &  objID,
tcpip::Storage add = nullptr 
) const
protected

Sends a GetVariable / SetVariable request if mySocket is connected. Otherwise writes to myOutput only.

Parameters
[in]cmdIDThe command and domain of the variable
[in]varIDThe variable to retrieve
[in]objIDThe object to retrieve the variable from
[in]addOptional additional parameter

Definition at line 162 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().

Here is the caller graph for this function:

◆ createFilterCommand()

void TraCIAPI::createFilterCommand ( int  cmdID,
int  varID,
tcpip::Storage add = nullptr 
) const
protected

◆ getVersion()

std::pair< int, std::string > TraCIAPI::getVersion ( )

return TraCI API and SUMO version

Definition at line 487 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().

Here is the caller graph for this function:

◆ load()

void TraCIAPI::load ( const std::vector< std::string > &  args)

Let sumo load a simulation using the given command line like options.

Definition at line 469 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().

Here is the caller graph for this function:

◆ processGet()

bool TraCIAPI::processGet ( int  command,
int  expectedType,
bool  ignoreCommandId = false 
)
protected

◆ processSet()

bool TraCIAPI::processSet ( int  command)
protected

◆ readContextSubscription()

void TraCIAPI::readContextSubscription ( int  cmdId,
tcpip::Storage inMsg 
)
protected

Definition at line 432 of file TraCIAPI.cpp.

References myDomains, tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), and readVariables().

Referenced by simulationStep().

Here is the caller graph for this function:

◆ readVariables()

void TraCIAPI::readVariables ( tcpip::Storage inMsg,
const std::string &  objectID,
int  variableCount,
libsumo::SubscriptionResults into 
)
protected

Definition at line 356 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().

Here is the caller graph for this function:

◆ readVariableSubscription()

void TraCIAPI::readVariableSubscription ( int  cmdId,
tcpip::Storage inMsg 
)
protected

Definition at line 424 of file TraCIAPI.cpp.

References myDomains, tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), and readVariables().

Referenced by simulationStep().

Here is the caller graph for this function:

◆ send_commandClose()

void TraCIAPI::send_commandClose ( ) const
protected

Sends a Close command.

Definition at line 138 of file TraCIAPI.cpp.

References libsumo::CMD_CLOSE, mySocket, tcpip::Socket::sendExact(), and tcpip::Storage::writeUnsignedByte().

Referenced by close(), and TraCITestClient::commandClose().

Here is the caller graph for this function:

◆ send_commandSetOrder()

void TraCIAPI::send_commandSetOrder ( int  order) const
protected

Sends a SetOrder command.

Definition at line 149 of file TraCIAPI.cpp.

References libsumo::CMD_SETORDER, mySocket, tcpip::Socket::sendExact(), tcpip::Storage::writeInt(), and tcpip::Storage::writeUnsignedByte().

Referenced by TraCITestClient::commandSetOrder().

Here is the caller graph for this function:

◆ send_commandSimulationStep()

void TraCIAPI::send_commandSimulationStep ( double  time) const
protected

Sends a SimulationStep command.

Definition at line 125 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().

Here is the caller graph for this function:

◆ send_commandSubscribeObjectContext()

void TraCIAPI::send_commandSubscribeObjectContext ( int  domID,
const std::string &  objID,
double  beginTime,
double  endTime,
int  domain,
double  range,
const std::vector< int > &  vars 
) const
protected

Sends a SubscribeContext request.

Parameters
[in]domIDThe domain of the variable
[in]objIDThe object to subscribe the variables from
[in]beginTimeThe begin time step of subscriptions
[in]endTimeThe end time step of subscriptions
[in]domainThe domain of the objects which values shall be returned
[in]rangeThe range around the obj to investigate
[in]varsThe variables to subscribe

Definition at line 237 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().

Here is the caller graph for this function:

◆ send_commandSubscribeObjectVariable()

void TraCIAPI::send_commandSubscribeObjectVariable ( int  domID,
const std::string &  objID,
double  beginTime,
double  endTime,
const std::vector< int > &  vars 
) const
protected

Sends a SubscribeVariable request.

Parameters
[in]domIDThe domain of the variable
[in]objIDThe object to subscribe the variables from
[in]beginTimeThe begin time step of subscriptions
[in]endTimeThe end time step of subscriptions
[in]varsThe variables to subscribe

Definition at line 209 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().

Here is the caller graph for this function:

◆ setOrder()

void TraCIAPI::setOrder ( int  order)

set priority (execution order) for the client

Definition at line 89 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().

Here is the caller graph for this function:

◆ simulationStep()

void TraCIAPI::simulationStep ( double  time = 0)

Advances by one step (or up to the given time)

Definition at line 447 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().

Here is the caller graph for this function:

◆ toString()

template<class T >
static std::string TraCIAPI::toString ( const T &  t,
std::streamsize  accuracy = PRECISION 
)
inlinestaticprotected

Definition at line 924 of file TraCIAPI.h.

Referenced by TraCIAPI::VehicleScope::add(), check_commandGetResult(), check_resultState(), and readVariables().

Here is the caller graph for this function:

Field Documentation

◆ edge

EdgeScope TraCIAPI::edge

Scope for interaction with edges.

Definition at line 811 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().

◆ gui

GUIScope TraCIAPI::gui

Scope for interaction with the gui.

Definition at line 813 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().

◆ inductionloop

InductionLoopScope TraCIAPI::inductionloop

Scope for interaction with inductive loops.

Definition at line 815 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI().

◆ junction

JunctionScope TraCIAPI::junction

Scope for interaction with junctions.

Definition at line 817 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().

◆ lane

LaneScope TraCIAPI::lane

Scope for interaction with lanes.

Definition at line 819 of file TraCIAPI.h.

Referenced by TraCIAPI::VehicleScope::moveToXY(), TraCITestClient::testAPI(), and TraCIAPI().

◆ lanearea

LaneAreaScope TraCIAPI::lanearea

Scope for interaction with lanes.

Definition at line 821 of file TraCIAPI.h.

Referenced by TraCIAPI().

◆ multientryexit

MeMeScope TraCIAPI::multientryexit

Scope for interaction with multi-entry/-exit detectors.

Definition at line 823 of file TraCIAPI.h.

Referenced by TraCIAPI().

◆ myDomains

std::map<int, TraCIScopeWrapper*> TraCIAPI::myDomains
protected

◆ myInput

tcpip::Storage TraCIAPI::myInput
mutableprotected

The reusable input storage.

Definition at line 942 of file TraCIAPI.h.

Referenced by processGet(), and processSet().

◆ myOutput

tcpip::Storage TraCIAPI::myOutput
mutableprotected

◆ mySocket

◆ person

PersonScope TraCIAPI::person

Scope for interaction with persons.

Definition at line 825 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().

◆ poi

POIScope TraCIAPI::poi

Scope for interaction with POIs.

Definition at line 827 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().

◆ polygon

PolygonScope TraCIAPI::polygon

Scope for interaction with polygons.

Definition at line 829 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().

◆ rerouter

RerouterScope TraCIAPI::rerouter

Scope for interaction with rerouters.

Definition at line 831 of file TraCIAPI.h.

Referenced by TraCIAPI().

◆ route

RouteScope TraCIAPI::route

Scope for interaction with routes.

Definition at line 833 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().

◆ routeprobe

RouteProbeScope TraCIAPI::routeprobe

Scope for interaction with route probes.

Definition at line 835 of file TraCIAPI.h.

Referenced by TraCIAPI().

◆ simulation

SimulationScope TraCIAPI::simulation

Scope for interaction with the simulation.

Definition at line 837 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().

◆ trafficlights

TrafficLightScope TraCIAPI::trafficlights

Scope for interaction with traffic lights.

Definition at line 839 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().

◆ vehicle

VehicleScope TraCIAPI::vehicle

Scope for interaction with vehicles.

Definition at line 841 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().

◆ vehicletype

VehicleTypeScope TraCIAPI::vehicletype

Scope for interaction with vehicle types.

Definition at line 843 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI(), and TraCIAPI().


The documentation for this class was generated from the following files: