Eclipse SUMO - Simulation of Urban MObility
TraCIAPI Class Reference

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

#include <TraCIAPI.h>

Inheritance diagram for TraCIAPI:
Collaboration diagram for TraCIAPI:

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::StoragegetCommandStorage () 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...
 
Connection handling
void connect (const std::string &host, int port)
 Connects to the specified SUMO server. More...
 
void setOrder (int order)
 set priority (execution order) for the client More...
 
void close ()
 ends the simulation and closes the connection More...
 
Atomar getter
int getUnsignedByte (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
int getByte (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
int getInt (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
double getDouble (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
libsumo::TraCIPositionVector getPolygon (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
libsumo::TraCIPosition getPosition (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
libsumo::TraCIPosition getPosition3D (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
std::string getString (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
std::vector< std::string > getStringVector (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
libsumo::TraCIColor getColor (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
libsumo::TraCIStage getTraCIStage (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 

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)
 
Command sending methods
void send_commandSimulationStep (double time) const
 Sends a SimulationStep command. More...
 
void send_commandClose () const
 Sends a Close command. More...
 
void send_commandSetOrder (int order) const
 Sends a SetOrder command. More...
 
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. More...
 
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. More...
 
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. More...
 
void check_resultState (tcpip::Storage &inMsg, int command, bool ignoreCommandId=false, std::string *acknowledgement=0) const
 Validates the result state of a command. More...
 
int check_commandGetResult (tcpip::Storage &inMsg, int command, int expectedType=-1, bool ignoreCommandId=false) const
 Validates the result state of a command. More...
 
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. More...
 
tcpip::Storage myOutput
 The reusable output storage. More...
 
tcpip::SocketmySocket
 The socket. More...
 

Detailed Description

C++ TraCI client API implementation.

Definition at line 47 of file TraCIAPI.h.

Constructor & Destructor Documentation

◆ TraCIAPI()

◆ ~TraCIAPI()

TraCIAPI::~TraCIAPI ( )

Destructor.

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

◆ 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 265 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().

◆ close()

void TraCIAPI::close ( )

ends the simulation and closes the connection

Definition at line 101 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 111 of file TraCIAPI.cpp.

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

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

◆ 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 73 of file TraCIAPI.cpp.

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

Referenced by TraCITestClient::run().

◆ 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 159 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().

◆ createFilterCommand()

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

◆ getByte()

int TraCIAPI::getByte ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)

◆ getColor()

◆ getCommandStorage()

const tcpip::Storage& TraCIAPI::getCommandStorage ( ) const
inline

Definition at line 94 of file TraCIAPI.h.

References myOutput.

◆ getDouble()

double TraCIAPI::getDouble ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)

◆ getInt()

int TraCIAPI::getInt ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)

◆ getPolygon()

◆ getPosition()

◆ getPosition3D()

libsumo::TraCIPosition TraCIAPI::getPosition3D ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)

◆ getString()

std::string TraCIAPI::getString ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)

◆ getStringVector()

std::vector< std::string > TraCIAPI::getStringVector ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)

◆ getTraCIStage()

◆ getUnsignedByte()

int TraCIAPI::getUnsignedByte ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)

◆ load()

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

◆ 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

◆ readVariables()

◆ readVariableSubscription()

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

◆ send_commandClose()

void TraCIAPI::send_commandClose ( ) const
protected

Sends a Close command.

Definition at line 135 of file TraCIAPI.cpp.

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

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

◆ send_commandSetOrder()

void TraCIAPI::send_commandSetOrder ( int  order) const
protected

◆ send_commandSimulationStep()

void TraCIAPI::send_commandSimulationStep ( double  time) const
protected

◆ 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 234 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().

◆ 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 206 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().

◆ setOrder()

void TraCIAPI::setOrder ( int  order)

set priority (execution order) for the client

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

◆ simulationStep()

◆ toString()

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

Field Documentation

◆ edge

EdgeScope TraCIAPI::edge

Scope for interaction with edges.

Definition at line 935 of file TraCIAPI.h.

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

◆ gui

GUIScope TraCIAPI::gui

Scope for interaction with the gui.

Definition at line 937 of file TraCIAPI.h.

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

◆ inductionloop

InductionLoopScope TraCIAPI::inductionloop

Scope for interaction with inductive loops.

Definition at line 939 of file TraCIAPI.h.

Referenced by TraCITestClient::testAPI().

◆ junction

JunctionScope TraCIAPI::junction

Scope for interaction with junctions.

Definition at line 941 of file TraCIAPI.h.

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

◆ lane

LaneScope TraCIAPI::lane

Scope for interaction with lanes.

Definition at line 943 of file TraCIAPI.h.

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

◆ lanearea

LaneAreaScope TraCIAPI::lanearea

Scope for interaction with lanes.

Definition at line 945 of file TraCIAPI.h.

Referenced by TraCIAPI().

◆ multientryexit

MeMeScope TraCIAPI::multientryexit

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

Definition at line 947 of file TraCIAPI.h.

Referenced by TraCIAPI().

◆ myDomains

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

◆ myInput

tcpip::Storage TraCIAPI::myInput
mutableprotected

◆ myOutput

tcpip::Storage TraCIAPI::myOutput
mutableprotected

◆ mySocket

◆ person

PersonScope TraCIAPI::person

Scope for interaction with persons.

Definition at line 949 of file TraCIAPI.h.

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

◆ poi

POIScope TraCIAPI::poi

Scope for interaction with POIs.

Definition at line 951 of file TraCIAPI.h.

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

◆ polygon

PolygonScope TraCIAPI::polygon

Scope for interaction with polygons.

Definition at line 953 of file TraCIAPI.h.

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

◆ route

RouteScope TraCIAPI::route

Scope for interaction with routes.

Definition at line 955 of file TraCIAPI.h.

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

◆ simulation

SimulationScope TraCIAPI::simulation

Scope for interaction with the simulation.

Definition at line 957 of file TraCIAPI.h.

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

◆ trafficlights

TrafficLightScope TraCIAPI::trafficlights

Scope for interaction with traffic lights.

Definition at line 959 of file TraCIAPI.h.

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

◆ vehicle

VehicleScope TraCIAPI::vehicle

Scope for interaction with vehicles.

Definition at line 961 of file TraCIAPI.h.

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

◆ vehicletype

VehicleTypeScope TraCIAPI::vehicletype

Scope for interaction with vehicle types.

Definition at line 963 of file TraCIAPI.h.

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


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