SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TraCIAPI Class Reference

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

#include <TraCIAPI.h>

Inheritance diagram for TraCIAPI:
testclient::TraCITestClient

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  LaneScope
 Scope for interaction with lanes. More...
 
class  MeMeScope
 Scope for interaction with multi entry/-exit detectors. 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...
 
struct  TraCIBoundary
 A 3D-bounding box. More...
 
struct  TraCIColor
 
class  TraCILink
 
class  TraCILogic
 
class  TraCIPhase
 
struct  TraCIPosition
 A 3D-position. More...
 
class  TraCIScopeWrapper
 An abstract interface for accessing type-dependent values. More...
 
class  TrafficLightScope
 Scope for interaction with traffic lights. More...
 
class  VehicleTypeScope
 Scope for interaction with vehicle types. More...
 

Public Types

Structures definitions
typedef std::vector
< TraCIPosition
TraCIPositionVector
 

Public Member Functions

 TraCIAPI ()
 Constructor. More...
 
 ~TraCIAPI ()
 Destructor. More...
 
Connection handling
void connect (const std::string &host, int port)
 Connects to the specified SUMO server. More...
 
void close ()
 Closes the connection. More...
 
Atomar getter
SUMOTime getSUMOTime (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
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)
 
SUMOReal getFloat (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
SUMOReal getDouble (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
TraCIBoundary getBoundingBox (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
TraCIPositionVector getPolygon (int cmd, int var, const std::string &id, tcpip::Storage *add=0)
 
TraCIPosition getPosition (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)
 
TraCIColor getColor (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...
 
MeMeScope multientryexit
 Scope for interaction with multi-entry/-exit detectors. 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...
 
VehicleTypeScope vehicletype
 Scope for interaction with vehicle types. More...
 

Protected Member Functions

Command sending methods
void send_commandSimulationStep (SUMOTime time) const
 Sends a SimulationStep command. More...
 
void send_commandClose () const
 Sends a Close command. More...
 
void send_commandGetVariable (int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const
 Sends a GetVariable request. More...
 
void send_commandSetValue (int domID, int varID, const std::string &objID, tcpip::Storage &content) const
 Sends a SetVariable request. More...
 
void send_commandSubscribeObjectVariable (int domID, const std::string &objID, int beginTime, int endTime, const std::vector< int > &vars) const
 Sends a SubscribeVariable request. More...
 
void send_commandSubscribeObjectContext (int domID, const std::string &objID, int beginTime, int endTime, int domain, SUMOReal 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...
 
void check_commandGetResult (tcpip::Storage &inMsg, int command, int expectedType=-1, bool ignoreCommandId=false) const
 
void processGET (tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const
 

Protected Attributes

tcpip::SocketmySocket
 The socket. More...
 

Detailed Description

C++ TraCI client API implementation.

Definition at line 52 of file TraCIAPI.h.

Member Typedef Documentation

Definition at line 74 of file TraCIAPI.h.

Constructor & Destructor Documentation

TraCIAPI::TraCIAPI ( )

Constructor.

Definition at line 47 of file TraCIAPI.cpp.

TraCIAPI::~TraCIAPI ( )

Destructor.

Definition at line 56 of file TraCIAPI.cpp.

References mySocket.

Member Function Documentation

void TraCIAPI::check_commandGetResult ( tcpip::Storage inMsg,
int  command,
int  expectedType = -1,
bool  ignoreCommandId = false 
) const
protected
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 219 of file TraCIAPI.cpp.

References mySocket, tcpip::Storage::position(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), tcpip::Socket::receiveExact(), RTYPE_ERR, RTYPE_NOTIMPLEMENTED, RTYPE_OK, and toString().

Referenced by testclient::TraCITestClient::commandClose(), testclient::TraCITestClient::commandGetVariable(), testclient::TraCITestClient::commandSetValue(), testclient::TraCITestClient::commandSimulationStep(), testclient::TraCITestClient::commandSubscribeContextVariable(), testclient::TraCITestClient::commandSubscribeObjectVariable(), and processGET().

void TraCIAPI::close ( )

Closes the connection.

Definition at line 75 of file TraCIAPI.cpp.

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

Referenced by testclient::TraCITestClient::run().

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

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

Referenced by testclient::TraCITestClient::run().

int TraCIAPI::getByte ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
SUMOReal TraCIAPI::getDouble ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
SUMOReal TraCIAPI::getFloat ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
int TraCIAPI::getInt ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
TraCIAPI::TraCIPosition TraCIAPI::getPosition ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
std::string TraCIAPI::getString ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
std::vector< std::string > TraCIAPI::getStringVector ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
SUMOTime TraCIAPI::getSUMOTime ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
int TraCIAPI::getUnsignedByte ( int  cmd,
int  var,
const std::string &  id,
tcpip::Storage add = 0 
)
void TraCIAPI::processGET ( tcpip::Storage inMsg,
int  command,
int  expectedType,
bool  ignoreCommandId = false 
) const
protected
void TraCIAPI::send_commandClose ( ) const
protected

Sends a Close command.

Definition at line 99 of file TraCIAPI.cpp.

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

Referenced by testclient::TraCITestClient::commandClose().

void TraCIAPI::send_commandGetVariable ( int  domID,
int  varID,
const std::string &  objID,
tcpip::Storage add = 0 
) const
protected

Sends a GetVariable request.

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

Definition at line 110 of file TraCIAPI.cpp.

References mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeStorage(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().

Referenced by testclient::TraCITestClient::commandGetVariable(), getBoundingBox(), getByte(), getColor(), getDouble(), getFloat(), getInt(), getPolygon(), getPosition(), getString(), getStringVector(), getSUMOTime(), and getUnsignedByte().

void TraCIAPI::send_commandSetValue ( int  domID,
int  varID,
const std::string &  objID,
tcpip::Storage content 
) const
protected

Sends a SetVariable request.

Parameters
[in]domIDThe domain of the variable
[in]varIDThe variable to set
[in]objIDThe object to change
[in]contentThe value of the variable

Definition at line 137 of file TraCIAPI.cpp.

References mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeStorage(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().

Referenced by testclient::TraCITestClient::commandSetValue().

void TraCIAPI::send_commandSimulationStep ( SUMOTime  time) const
protected
void TraCIAPI::send_commandSubscribeObjectContext ( int  domID,
const std::string &  objID,
int  beginTime,
int  endTime,
int  domain,
SUMOReal  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 186 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 testclient::TraCITestClient::commandSubscribeContextVariable().

void TraCIAPI::send_commandSubscribeObjectVariable ( int  domID,
const std::string &  objID,
int  beginTime,
int  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 158 of file TraCIAPI.cpp.

References mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeInt(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().

Referenced by testclient::TraCITestClient::commandSubscribeObjectVariable().

Field Documentation

EdgeScope TraCIAPI::edge

Scope for interaction with edges.

Definition at line 625 of file TraCIAPI.h.

GUIScope TraCIAPI::gui

Scope for interaction with the gui.

Definition at line 627 of file TraCIAPI.h.

InductionLoopScope TraCIAPI::inductionloop

Scope for interaction with inductive loops.

Definition at line 629 of file TraCIAPI.h.

JunctionScope TraCIAPI::junction

Scope for interaction with junctions.

Definition at line 631 of file TraCIAPI.h.

LaneScope TraCIAPI::lane

Scope for interaction with lanes.

Definition at line 633 of file TraCIAPI.h.

MeMeScope TraCIAPI::multientryexit

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

Definition at line 635 of file TraCIAPI.h.

POIScope TraCIAPI::poi

Scope for interaction with POIs.

Definition at line 637 of file TraCIAPI.h.

PolygonScope TraCIAPI::polygon

Scope for interaction with polygons.

Definition at line 639 of file TraCIAPI.h.

RouteScope TraCIAPI::route

Scope for interaction with routes.

Definition at line 641 of file TraCIAPI.h.

SimulationScope TraCIAPI::simulation

Scope for interaction with the simulation.

Definition at line 643 of file TraCIAPI.h.

TrafficLightScope TraCIAPI::trafficlights

Scope for interaction with traffic lights.

Definition at line 645 of file TraCIAPI.h.

VehicleTypeScope TraCIAPI::vehicletype

Scope for interaction with vehicle types.

Definition at line 647 of file TraCIAPI.h.


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