SUMO - Simulation of Urban MObility
TraCIServer Class Reference

TraCI server used to control sumo by a remote TraCI client. More...

#include <TraCIServer.h>

Inheritance diagram for TraCIServer:
Inheritance graph
Collaboration diagram for TraCIServer:
Collaboration graph

Data Structures

struct  SocketInfo
 
class  Subscription
 Representation of a subscription. More...
 

Public Types

typedef bool(* CmdExecutor) (TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
 Definition of a method to be called for serving an associated commandID. More...
 

Public Member Functions

void cleanup ()
 clean up subscriptions More...
 
void collectObjectsInRange (int domain, const PositionVector &shape, double range, std::set< std::string > &into)
 
std::vector< std::string > & getLoadArgs ()
 
SUMOTime getTargetTime () const
 
const std::map< MSNet::VehicleState, std::vector< std::string > > & getVehicleStateChanges () const
 
bool isEmbedded () const
 
void processCommandsUntilSimStep (SUMOTime step)
 process all commands until the next SUMO simulation step. It is guaranteed that t->getTargetTime() >= myStep after call (except the case that a load or close command is received)s More...
 
void setTargetTime (SUMOTime targetTime)
 Sets myTargetTime on server and sockets to the given value. More...
 
void vehicleStateChanged (const SUMOVehicle *const vehicle, MSNet::VehicleState to)
 Called if a vehicle changes its state. More...
 
void writeResponseWithLength (tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
 
Writing Status Messages
void writeStatusCmd (int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
 Writes a status command to the given storage. More...
 
void writeStatusCmd (int commandId, int status, const std::string &description)
 Writes a status command to myOutputStorage. More...
 
bool writeErrorStatusCmd (int commandId, const std::string &description, tcpip::Storage &outputStorage)
 Writes a status command to the given storage with status = RTYPE_ERR. More...
 
Helpers for reading and checking values
bool readTypeCheckingInt (tcpip::Storage &inputStorage, int &into)
 Reads the value type and an int, verifying the type. More...
 
bool readTypeCheckingDouble (tcpip::Storage &inputStorage, double &into)
 Reads the value type and a double, verifying the type. More...
 
bool readTypeCheckingString (tcpip::Storage &inputStorage, std::string &into)
 Reads the value type and a string, verifying the type. More...
 
bool readTypeCheckingStringList (tcpip::Storage &inputStorage, std::vector< std::string > &into)
 Reads the value type and a string list, verifying the type. More...
 
bool readTypeCheckingColor (tcpip::Storage &inputStorage, libsumo::TraCIColor &into)
 Reads the value type and a color, verifying the type. More...
 
bool readTypeCheckingPosition2D (tcpip::Storage &inputStorage, libsumo::TraCIPosition &into)
 Reads the value type and a 2D position, verifying the type. More...
 
bool readTypeCheckingBoundary (tcpip::Storage &inputStorage, Boundary &into)
 Reads the value type and a 2D bounding box, verifying the type. More...
 
bool readTypeCheckingByte (tcpip::Storage &inputStorage, int &into)
 Reads the value type and a byte, verifying the type. More...
 
bool readTypeCheckingUnsignedByte (tcpip::Storage &inputStorage, int &into)
 Reads the value type and an unsigned byte, verifying the type. More...
 
bool readTypeCheckingPolygon (tcpip::Storage &inputStorage, PositionVector &into)
 Reads the value type and a polygon, verifying the type. More...
 

Static Public Member Functions

static TraCIServergetInstance ()
 
Initialisation and Shutdown
static void openSocket (const std::map< int, CmdExecutor > &execs)
 Initialises the server. More...
 
static void close ()
 request termination of connection More...
 
static bool wasClosed ()
 check whether close was requested More...
 

Private Member Functions

bool addObjectVariableSubscription (const int commandId, const bool hasContext)
 
void checkClientOrdering ()
 Called once after connection of all clients for executing SET_ORDER (and possibly prior GET_VERSION) commands, that should be executed before simulation starts (in processCommandsUntilNextSimStep()). More...
 
int dispatchCommand ()
 Handles command, writes response to myOutputStorage. More...
 
bool findObjectShape (int domain, const std::string &id, PositionVector &shape)
 
void initialiseSubscription (const Subscription &s)
 
SUMOTime nextTargetTime () const
 get the minimal next target time among all clients More...
 
TraCIServeroperator= (const TraCIServer &s)
 Invalidated assignment operator. More...
 
void processReorderingRequests ()
 checks for and processes reordering requests (relevant for multiple clients) More...
 
bool processSingleSubscription (const TraCIServer::Subscription &s, tcpip::Storage &writeInto, std::string &errors)
 
int readCommandID (int &commandStart, int &commandLength)
 Reads the next command ID from the input storage. More...
 
std::map< int, SocketInfo * >::iterator removeCurrentSocket ()
 removes myCurrentSocket from mySockets and returns an iterator pointing to the next member according to the ordering More...
 
void removeSubscription (int commandId, const std::string &identity, int domain)
 
void sendOutputToAll () const
 send out subscription results (actually just the content of myOutputStorage) to clients which will act in this step (i.e. with client target time <= myTargetTime) More...
 
void sendSingleSimStepResponse ()
 sends an empty response to a simstep command to the current client. (This applies to a situation where the TraCI step frequency is higher than the SUMO step frequency) More...
 
 TraCIServer (const SUMOTime begin, const int port, const int numClients)
 Constructor. More...
 
virtual ~TraCIServer ()
 Destructor. More...
 
Server-internal command handling
bool commandGetVersion ()
 Returns the TraCI-version. More...
 
void postProcessSimulationStep ()
 Handles subscriptions to send after a simstep2 command. More...
 

Private Attributes

const bool myAmEmbedded
 Whether the server runs in embedded mode. More...
 
std::map< int, SocketInfo * >::iterator myCurrentSocket
 The currently active client socket. More...
 
std::map< int, CmdExecutormyExecutors
 Map of commandIds -> their executors; applicable if the executor applies to the method footprint. More...
 
tcpip::Storage myInputStorage
 The storage to read from. More...
 
std::vector< std::string > myLoadArgs
 
tcpip::Storage myOutputStorage
 The storage to writeto. More...
 
std::map< int, int > myParameterSizes
 Map of variable ids to the size of the parameter in bytes. More...
 
tcpip::SocketmyServerSocket
 The server socket. More...
 
std::map< int, SocketInfo * > mySocketReorderRequests
 This stores the setOrder(int) requests of the clients. More...
 
std::map< int, SocketInfo * > mySockets
 The socket connections to the clients the first component (index) determines the client's order (lowest index's commands are processed first),. More...
 
tcpip::Storage mySubscriptionCache
 The last timestep's subscription results. More...
 
std::vector< SubscriptionmySubscriptions
 The list of known, still valid subscriptions. More...
 
SUMOTime myTargetTime
 The time step to reach until processing the next commands. More...
 
std::map< MSNet::VehicleState, std::vector< std::string > > myVehicleStateChanges
 Changes in the states of simulated vehicles. More...
 

Static Private Attributes

static bool myDoCloseConnection = false
 Whether the connection was set to be to close. More...
 
static TraCIServermyInstance = 0
 Singleton instance of the server. More...
 

Detailed Description

TraCI server used to control sumo by a remote TraCI client.

Definition at line 69 of file TraCIServer.h.

Member Typedef Documentation

◆ CmdExecutor

typedef bool(* TraCIServer::CmdExecutor) (TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)

Definition of a method to be called for serving an associated commandID.

Definition at line 72 of file TraCIServer.h.

Constructor & Destructor Documentation

◆ TraCIServer()

TraCIServer::TraCIServer ( const SUMOTime  begin,
const int  port,
const int  numClients 
)
private

Constructor.

Parameters
[in]portThe port to listen to (to open)

Definition at line 110 of file TraCIServer.cpp.

References tcpip::Socket::accept(), checkClientOrdering(), CMD_GET_EDGE_VARIABLE, CMD_GET_INDUCTIONLOOP_VARIABLE, CMD_GET_JUNCTION_VARIABLE, CMD_GET_LANE_VARIABLE, CMD_GET_LANEAREA_VARIABLE, CMD_GET_MULTIENTRYEXIT_VARIABLE, CMD_GET_PERSON_VARIABLE, CMD_GET_POI_VARIABLE, CMD_GET_POLYGON_VARIABLE, CMD_GET_ROUTE_VARIABLE, CMD_GET_SIM_VARIABLE, CMD_GET_TL_VARIABLE, CMD_GET_VEHICLE_VARIABLE, CMD_GET_VEHICLETYPE_VARIABLE, CMD_SET_EDGE_VARIABLE, CMD_SET_LANE_VARIABLE, CMD_SET_PERSON_VARIABLE, CMD_SET_POI_VARIABLE, CMD_SET_POLYGON_VARIABLE, CMD_SET_ROUTE_VARIABLE, CMD_SET_SIM_VARIABLE, CMD_SET_TL_VARIABLE, CMD_SET_VEHICLE_VARIABLE, CMD_SET_VEHICLETYPE_VARIABLE, MsgHandler::getWarningInstance(), MSGlobals::gUsingInternalLanes, MsgHandler::inform(), MAX_ORDER, myAmEmbedded, myCurrentSocket, myDoCloseConnection, myExecutors, myParameterSizes, myServerSocket, mySockets, myVehicleStateChanges, TraCIServerAPI_Edge::processGet(), TraCIServerAPI_VehicleType::processGet(), TraCIServerAPI_Route::processGet(), TraCIServerAPI_TrafficLight::processGet(), TraCIServerAPI_POI::processGet(), TraCIServerAPI_MultiEntryExit::processGet(), TraCIServerAPI_Polygon::processGet(), TraCIServerAPI_InductionLoop::processGet(), TraCIServerAPI_Vehicle::processGet(), TraCIServerAPI_Simulation::processGet(), TraCIServerAPI_Person::processGet(), TraCIServerAPI_LaneArea::processGet(), TraCIServerAPI_Lane::processGet(), TraCIServerAPI_Junction::processGet(), TraCIServerAPI_Edge::processSet(), TraCIServerAPI_POI::processSet(), TraCIServerAPI_TrafficLight::processSet(), TraCIServerAPI_Route::processSet(), TraCIServerAPI_Polygon::processSet(), TraCIServerAPI_Vehicle::processSet(), TraCIServerAPI_Simulation::processSet(), TraCIServerAPI_Person::processSet(), TraCIServerAPI_Lane::processSet(), TraCIServerAPI_VehicleType::processSet(), toString(), VAR_LEADER, MSNet::VEHICLE_STATE_ARRIVED, MSNet::VEHICLE_STATE_BUILT, MSNet::VEHICLE_STATE_DEPARTED, MSNet::VEHICLE_STATE_ENDING_PARKING, MSNet::VEHICLE_STATE_ENDING_STOP, MSNet::VEHICLE_STATE_ENDING_TELEPORT, MSNet::VEHICLE_STATE_NEWROUTE, MSNet::VEHICLE_STATE_STARTING_PARKING, MSNet::VEHICLE_STATE_STARTING_STOP, MSNet::VEHICLE_STATE_STARTING_TELEPORT, tcpip::SocketException::what(), WRITE_MESSAGE, and WRITE_WARNING.

Referenced by getLoadArgs(), and openSocket().

◆ ~TraCIServer()

TraCIServer::~TraCIServer ( )
privatevirtual

Destructor.

Definition at line 196 of file TraCIServer.cpp.

References cleanup(), myCurrentSocket, myServerSocket, and mySockets.

Referenced by getLoadArgs().

Member Function Documentation

◆ addObjectVariableSubscription()

bool TraCIServer::addObjectVariableSubscription ( const int  commandId,
const bool  hasContext 
)
private

◆ checkClientOrdering()

void TraCIServer::checkClientOrdering ( )
private

Called once after connection of all clients for executing SET_ORDER (and possibly prior GET_VERSION) commands, that should be executed before simulation starts (in processCommandsUntilNextSimStep()).

Definition at line 260 of file TraCIServer.cpp.

References CMD_GETVERSION, CMD_SETORDER, dispatchCommand(), myCurrentSocket, myInputStorage, myOutputStorage, mySockets, readCommandID(), tcpip::Storage::reset(), tcpip::Storage::writeStorage(), and tcpip::Storage::writeUnsignedByte().

Referenced by TraCIServer().

◆ cleanup()

◆ close()

void TraCIServer::close ( )
static

request termination of connection

Definition at line 228 of file TraCIServer.cpp.

References myDoCloseConnection, and myInstance.

Referenced by getInstance(), and main().

◆ collectObjectsInRange()

void TraCIServer::collectObjectsInRange ( int  domain,
const PositionVector shape,
double  range,
std::set< std::string > &  into 
)

Referenced by getVehicleStateChanges().

◆ commandGetVersion()

bool TraCIServer::commandGetVersion ( )
private

◆ dispatchCommand()

int TraCIServer::dispatchCommand ( )
private

Handles command, writes response to myOutputStorage.

Definition at line 714 of file TraCIServer.cpp.

References addObjectVariableSubscription(), CMD_CLOSE, CMD_GETVERSION, CMD_LOAD, CMD_SETORDER, CMD_SIMSTEP, CMD_SUBSCRIBE_EDGE_CONTEXT, CMD_SUBSCRIBE_EDGE_VARIABLE, CMD_SUBSCRIBE_GUI_CONTEXT, CMD_SUBSCRIBE_GUI_VARIABLE, CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT, CMD_SUBSCRIBE_INDUCTIONLOOP_VARIABLE, CMD_SUBSCRIBE_JUNCTION_CONTEXT, CMD_SUBSCRIBE_JUNCTION_VARIABLE, CMD_SUBSCRIBE_LANE_CONTEXT, CMD_SUBSCRIBE_LANE_VARIABLE, CMD_SUBSCRIBE_LANEAREA_CONTEXT, CMD_SUBSCRIBE_LANEAREA_VARIABLE, CMD_SUBSCRIBE_MULTIENTRYEXIT_CONTEXT, CMD_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE, CMD_SUBSCRIBE_PERSON_CONTEXT, CMD_SUBSCRIBE_PERSON_VARIABLE, CMD_SUBSCRIBE_POI_CONTEXT, CMD_SUBSCRIBE_POI_VARIABLE, CMD_SUBSCRIBE_POLYGON_CONTEXT, CMD_SUBSCRIBE_POLYGON_VARIABLE, CMD_SUBSCRIBE_ROUTE_CONTEXT, CMD_SUBSCRIBE_ROUTE_VARIABLE, CMD_SUBSCRIBE_SIM_CONTEXT, CMD_SUBSCRIBE_SIM_VARIABLE, CMD_SUBSCRIBE_TL_CONTEXT, CMD_SUBSCRIBE_TL_VARIABLE, CMD_SUBSCRIBE_VEHICLE_CONTEXT, CMD_SUBSCRIBE_VEHICLE_VARIABLE, CMD_SUBSCRIBE_VEHICLETYPE_CONTEXT, CMD_SUBSCRIBE_VEHICLETYPE_VARIABLE, commandGetVersion(), DELTA_T, MSNet::getCurrentTimeStep(), MSNet::getInstance(), MAX_ORDER, myAmEmbedded, myCurrentSocket, myDoCloseConnection, myExecutors, myInputStorage, myLoadArgs, myOutputStorage, mySocketReorderRequests, mySockets, myTargetTime, myVehicleStateChanges, tcpip::Storage::position(), postProcessSimulationStep(), tcpip::Storage::readChar(), readCommandID(), tcpip::Storage::readInt(), readTypeCheckingStringList(), tcpip::Storage::reset(), RTYPE_ERR, RTYPE_NOTIMPLEMENTED, RTYPE_OK, sendSingleSimStepResponse(), MSNet::simulationStep(), toString(), tcpip::Storage::valid_pos(), writeErrorStatusCmd(), and writeStatusCmd().

Referenced by checkClientOrdering(), cleanup(), and processCommandsUntilSimStep().

◆ findObjectShape()

◆ getInstance()

◆ getLoadArgs()

std::vector<std::string>& TraCIServer::getLoadArgs ( )
inline

Definition at line 269 of file TraCIServer.h.

References myLoadArgs, TraCIServer(), and ~TraCIServer().

Referenced by GUIRunThread::makeStep(), and MSNet::simulate().

◆ getTargetTime()

SUMOTime TraCIServer::getTargetTime ( ) const
inline

Definition at line 75 of file TraCIServer.h.

References myTargetTime.

Referenced by MSNet::simulationStep().

◆ getVehicleStateChanges()

◆ initialiseSubscription()

◆ isEmbedded()

bool TraCIServer::isEmbedded ( ) const
inline

Definition at line 78 of file TraCIServer.h.

References myAmEmbedded.

Referenced by MSNet::simulationStep().

◆ nextTargetTime()

SUMOTime TraCIServer::nextTargetTime ( ) const
private

get the minimal next target time among all clients

Definition at line 369 of file TraCIServer.cpp.

References MIN2(), and mySockets.

Referenced by processCommandsUntilSimStep().

◆ openSocket()

void TraCIServer::openSocket ( const std::map< int, CmdExecutor > &  execs)
static

Initialises the server.

Parameters
[in]execsThe (additional) command executors to use

Definition at line 207 of file TraCIServer.cpp.

References MSNet::addVehicleStateListener(), MSNet::getInstance(), OptionsCont::getOptions(), myDoCloseConnection, myExecutors, myInstance, string2time(), and TraCIServer().

Referenced by getInstance(), NLBuilder::init(), and GUILoadThread::run().

◆ operator=()

TraCIServer& TraCIServer::operator= ( const TraCIServer s)
private

Invalidated assignment operator.

◆ postProcessSimulationStep()

◆ processCommandsUntilSimStep()

void TraCIServer::processCommandsUntilSimStep ( SUMOTime  step)

◆ processReorderingRequests()

void TraCIServer::processReorderingRequests ( )
private

checks for and processes reordering requests (relevant for multiple clients)

Definition at line 325 of file TraCIServer.cpp.

References mySocketReorderRequests, mySockets, and SIMTIME.

Referenced by processCommandsUntilSimStep().

◆ processSingleSubscription()

◆ readCommandID()

int TraCIServer::readCommandID ( int &  commandStart,
int &  commandLength 
)
private

Reads the next command ID from the input storage.

Returns
the command ID
Parameters
[out]theversion with reference parameters provides information on the command start position and length used in dispatchCommand for checking purposes

Definition at line 703 of file TraCIServer.cpp.

References myInputStorage, tcpip::Storage::position(), tcpip::Storage::readInt(), and tcpip::Storage::readUnsignedByte().

Referenced by checkClientOrdering(), and dispatchCommand().

◆ readTypeCheckingBoundary()

bool TraCIServer::readTypeCheckingBoundary ( tcpip::Storage inputStorage,
Boundary into 
)

Reads the value type and a 2D bounding box, verifying the type.

Parameters

Definition at line 1336 of file TraCIServer.cpp.

References tcpip::Storage::readDouble(), tcpip::Storage::readUnsignedByte(), Boundary::set(), and TYPE_BOUNDINGBOX.

Referenced by getVehicleStateChanges(), and TraCIServerAPI_GUI::processSet().

◆ readTypeCheckingByte()

bool TraCIServer::readTypeCheckingByte ( tcpip::Storage inputStorage,
int &  into 
)

Reads the value type and a byte, verifying the type.

Parameters

Definition at line 1350 of file TraCIServer.cpp.

References tcpip::Storage::readByte(), tcpip::Storage::readUnsignedByte(), and TYPE_BYTE.

Referenced by getVehicleStateChanges(), TraCIServerAPI_Vehicle::processSet(), and TraCIServerAPI_Person::processSet().

◆ readTypeCheckingColor()

◆ readTypeCheckingDouble()

◆ readTypeCheckingInt()

◆ readTypeCheckingPolygon()

bool TraCIServer::readTypeCheckingPolygon ( tcpip::Storage inputStorage,
PositionVector into 
)

Reads the value type and a polygon, verifying the type.

Parameters

Definition at line 1370 of file TraCIServer.cpp.

References tcpip::Storage::readDouble(), tcpip::Storage::readUnsignedByte(), and TYPE_POLYGON.

Referenced by getVehicleStateChanges(), and TraCIServerAPI_Polygon::processSet().

◆ readTypeCheckingPosition2D()

bool TraCIServer::readTypeCheckingPosition2D ( tcpip::Storage inputStorage,
libsumo::TraCIPosition into 
)

◆ readTypeCheckingString()

◆ readTypeCheckingStringList()

bool TraCIServer::readTypeCheckingStringList ( tcpip::Storage inputStorage,
std::vector< std::string > &  into 
)

◆ readTypeCheckingUnsignedByte()

bool TraCIServer::readTypeCheckingUnsignedByte ( tcpip::Storage inputStorage,
int &  into 
)

Reads the value type and an unsigned byte, verifying the type.

Parameters

Definition at line 1360 of file TraCIServer.cpp.

References tcpip::Storage::readUnsignedByte(), and TYPE_UBYTE.

Referenced by TraCIServerAPI_Simulation::commandPositionConversion(), getVehicleStateChanges(), and TraCIServerAPI_Polygon::processSet().

◆ removeCurrentSocket()

std::map< int, TraCIServer::SocketInfo * >::iterator TraCIServer::removeCurrentSocket ( )
private

removes myCurrentSocket from mySockets and returns an iterator pointing to the next member according to the ordering

Definition at line 673 of file TraCIServer.cpp.

References myCurrentSocket, and mySockets.

Referenced by processCommandsUntilSimStep().

◆ removeSubscription()

void TraCIServer::removeSubscription ( int  commandId,
const std::string &  identity,
int  domain 
)
private

Definition at line 1046 of file TraCIServer.cpp.

References mySubscriptions, RTYPE_OK, and writeStatusCmd().

Referenced by addObjectVariableSubscription().

◆ sendOutputToAll()

void TraCIServer::sendOutputToAll ( ) const
private

send out subscription results (actually just the content of myOutputStorage) to clients which will act in this step (i.e. with client target time <= myTargetTime)

Definition at line 393 of file TraCIServer.cpp.

References MSNet::getCurrentTimeStep(), MSNet::getInstance(), myOutputStorage, and mySockets.

Referenced by processCommandsUntilSimStep().

◆ sendSingleSimStepResponse()

void TraCIServer::sendSingleSimStepResponse ( )
private

sends an empty response to a simstep command to the current client. (This applies to a situation where the TraCI step frequency is higher than the SUMO step frequency)

Definition at line 948 of file TraCIServer.cpp.

References CMD_SIMSTEP, myCurrentSocket, myOutputStorage, mySubscriptionCache, tcpip::Storage::reset(), RTYPE_OK, tcpip::Storage::size(), writeStatusCmd(), and tcpip::Storage::writeStorage().

Referenced by dispatchCommand().

◆ setTargetTime()

void TraCIServer::setTargetTime ( SUMOTime  targetTime)

Sets myTargetTime on server and sockets to the given value.

Note
Used in MSStateHandler to update the server's time after loading a state

Definition at line 1386 of file TraCIServer.cpp.

References mySockets, and myTargetTime.

Referenced by NLBuilder::build(), and getVehicleStateChanges().

◆ vehicleStateChanged()

void TraCIServer::vehicleStateChanged ( const SUMOVehicle *const  vehicle,
MSNet::VehicleState  to 
)
virtual

Called if a vehicle changes its state.

Parameters
[in]vehicleThe vehicle which changed its state
[in]toThe state the vehicle has changed to

Implements MSNet::VehicleStateListener.

Definition at line 248 of file TraCIServer.cpp.

References SUMOVehicle::getID(), myAmEmbedded, myDoCloseConnection, mySockets, and myVehicleStateChanges.

Referenced by getInstance().

◆ wasClosed()

bool TraCIServer::wasClosed ( )
static

check whether close was requested

Returns
Whether the connection was closed

Definition at line 239 of file TraCIServer.cpp.

References myDoCloseConnection.

Referenced by getInstance(), GUIRunThread::makeStep(), MSNet::simulate(), MSNet::simulationState(), and MSNet::simulationStep().

◆ writeErrorStatusCmd()

bool TraCIServer::writeErrorStatusCmd ( int  commandId,
const std::string &  description,
tcpip::Storage outputStorage 
)

◆ writeResponseWithLength()

◆ writeStatusCmd() [1/2]

void TraCIServer::writeStatusCmd ( int  commandId,
int  status,
const std::string &  description,
tcpip::Storage outputStorage 
)

Writes a status command to the given storage.

Parameters
[in]commandIdThe id of the command to respond to
[in]statusThe status to send
[in]descriptionThe status description (error message, for example)

Definition at line 975 of file TraCIServer.cpp.

References RTYPE_ERR, RTYPE_NOTIMPLEMENTED, toHex(), WRITE_ERROR, tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().

Referenced by TraCIServerAPI_Simulation::commandDistanceRequest(), commandGetVersion(), TraCIServerAPI_Simulation::commandPositionConversion(), dispatchCommand(), getInstance(), initialiseSubscription(), postProcessSimulationStep(), TraCIServerAPI_Edge::processGet(), TraCIServerAPI_TrafficLight::processGet(), TraCIServerAPI_VehicleType::processGet(), TraCIServerAPI_MultiEntryExit::processGet(), TraCIServerAPI_POI::processGet(), TraCIServerAPI_Polygon::processGet(), TraCIServerAPI_Route::processGet(), TraCIServerAPI_InductionLoop::processGet(), TraCIServerAPI_Vehicle::processGet(), TraCIServerAPI_GUI::processGet(), TraCIServerAPI_Simulation::processGet(), TraCIServerAPI_Person::processGet(), TraCIServerAPI_LaneArea::processGet(), TraCIServerAPI_Lane::processGet(), TraCIServerAPI_Junction::processGet(), TraCIServerAPI_Edge::processSet(), TraCIServerAPI_TrafficLight::processSet(), TraCIServerAPI_Route::processSet(), TraCIServerAPI_POI::processSet(), TraCIServerAPI_Polygon::processSet(), TraCIServerAPI_Vehicle::processSet(), TraCIServerAPI_GUI::processSet(), TraCIServerAPI_Simulation::processSet(), TraCIServerAPI_Person::processSet(), TraCIServerAPI_Lane::processSet(), TraCIServerAPI_VehicleType::processSet(), processSingleSubscription(), removeSubscription(), sendSingleSimStepResponse(), writeErrorStatusCmd(), and writeStatusCmd().

◆ writeStatusCmd() [2/2]

void TraCIServer::writeStatusCmd ( int  commandId,
int  status,
const std::string &  description 
)

Writes a status command to myOutputStorage.

Parameters
[in]commandIdThe id of the command to respond to
[in]statusThe status to send
[in]descriptionThe status description (error message, for example)

Definition at line 969 of file TraCIServer.cpp.

References myOutputStorage, and writeStatusCmd().

Field Documentation

◆ myAmEmbedded

const bool TraCIServer::myAmEmbedded
private

Whether the server runs in embedded mode.

Definition at line 381 of file TraCIServer.h.

Referenced by dispatchCommand(), getVehicleStateChanges(), isEmbedded(), processCommandsUntilSimStep(), TraCIServer(), and vehicleStateChanged().

◆ myCurrentSocket

std::map<int, SocketInfo*>::iterator TraCIServer::myCurrentSocket
private

◆ myDoCloseConnection

bool TraCIServer::myDoCloseConnection = false
staticprivate

Whether the connection was set to be to close.

Definition at line 353 of file TraCIServer.h.

Referenced by close(), dispatchCommand(), openSocket(), processCommandsUntilSimStep(), TraCIServer(), vehicleStateChanged(), and wasClosed().

◆ myExecutors

std::map<int, CmdExecutor> TraCIServer::myExecutors
private

Map of commandIds -> their executors; applicable if the executor applies to the method footprint.

Definition at line 384 of file TraCIServer.h.

Referenced by dispatchCommand(), openSocket(), processSingleSubscription(), and TraCIServer().

◆ myInputStorage

tcpip::Storage TraCIServer::myInputStorage
private

◆ myInstance

TraCIServer * TraCIServer::myInstance = 0
staticprivate

Singleton instance of the server.

Definition at line 350 of file TraCIServer.h.

Referenced by cleanup(), close(), getInstance(), and openSocket().

◆ myLoadArgs

std::vector<std::string> TraCIServer::myLoadArgs
private

Definition at line 389 of file TraCIServer.h.

Referenced by dispatchCommand(), getLoadArgs(), and processCommandsUntilSimStep().

◆ myOutputStorage

◆ myParameterSizes

std::map<int, int> TraCIServer::myParameterSizes
private

Map of variable ids to the size of the parameter in bytes.

Definition at line 387 of file TraCIServer.h.

Referenced by addObjectVariableSubscription(), and TraCIServer().

◆ myServerSocket

tcpip::Socket* TraCIServer::myServerSocket
private

The server socket.

Definition at line 356 of file TraCIServer.h.

Referenced by TraCIServer(), and ~TraCIServer().

◆ mySocketReorderRequests

std::map<int, SocketInfo*> TraCIServer::mySocketReorderRequests
private

This stores the setOrder(int) requests of the clients.

Definition at line 363 of file TraCIServer.h.

Referenced by dispatchCommand(), and processReorderingRequests().

◆ mySockets

std::map<int, SocketInfo*> TraCIServer::mySockets
private

The socket connections to the clients the first component (index) determines the client's order (lowest index's commands are processed first),.

See also
CMD_SETORDER

Definition at line 360 of file TraCIServer.h.

Referenced by checkClientOrdering(), cleanup(), dispatchCommand(), getVehicleStateChanges(), nextTargetTime(), processCommandsUntilSimStep(), processReorderingRequests(), removeCurrentSocket(), sendOutputToAll(), setTargetTime(), TraCIServer(), vehicleStateChanged(), and ~TraCIServer().

◆ mySubscriptionCache

tcpip::Storage TraCIServer::mySubscriptionCache
private

The last timestep's subscription results.

Definition at line 378 of file TraCIServer.h.

Referenced by cleanup(), initialiseSubscription(), postProcessSimulationStep(), and sendSingleSimStepResponse().

◆ mySubscriptions

std::vector<Subscription> TraCIServer::mySubscriptions
private

The list of known, still valid subscriptions.

Definition at line 434 of file TraCIServer.h.

Referenced by cleanup(), initialiseSubscription(), postProcessSimulationStep(), and removeSubscription().

◆ myTargetTime

SUMOTime TraCIServer::myTargetTime
private

The time step to reach until processing the next commands.

Definition at line 369 of file TraCIServer.h.

Referenced by cleanup(), dispatchCommand(), getTargetTime(), processCommandsUntilSimStep(), and setTargetTime().

◆ myVehicleStateChanges

std::map<MSNet::VehicleState, std::vector<std::string> > TraCIServer::myVehicleStateChanges
private

Changes in the states of simulated vehicles.

Note
Server cache myVehicleStateChanges is used for managing last steps subscription updates and for client information in case that myAmEmbedded==true, which implies a single client. For the potential multiclient case (myAmEmbedded==false), each socket in mySockets is associated with a proper vehicleStateChanges container mySockets[...].second->vehicleStateChanges Performance could be improved if for a single client, myVehicleStateChanges is used only.

Definition at line 443 of file TraCIServer.h.

Referenced by cleanup(), dispatchCommand(), getVehicleStateChanges(), postProcessSimulationStep(), processCommandsUntilSimStep(), TraCIServer(), and vehicleStateChanged().


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