SUMO - Simulation of Urban MObility
|
#include <TraCIServer.h>
Data Structures | |
class | Subscription |
Public Types | |
typedef bool(* | CmdExecutor )(traci::TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage) |
Definition of a method to be called for serving an associated commandID. | |
Public Member Functions | |
std::map< int, CmdExecutor > & | getExecutors () |
Returns the list of (unified) command executors. | |
const std::map < MSNet::VehicleState, std::vector< std::string > > & | getVehicleStateChanges () const |
void | vehicleStateChanged (const SUMOVehicle *const vehicle, MSNet::VehicleState to) |
Called if a vehicle changes its state. | |
void | writeResponseWithLength (tcpip::Storage &outputStorage, tcpip::Storage &tempMsg) |
void | writeStatusCmd (int commandId, int status, const std::string &description) |
void | writeStatusCmd (int commandId, int status, const std::string &description, tcpip::Storage &outputStorage) |
Static Public Member Functions | |
static void | close () |
request termination of connection | |
static void | openSocket (const std::map< int, CmdExecutor > &execs) |
Initialises the server. | |
static void | processCommandsUntilSimStep (SUMOTime step) |
process all commands until a simulation step is wanted | |
static bool | wasClosed () |
check whether close was requested | |
Private Member Functions | |
bool | addSubscription (int commandId) |
bool | commandAddVehicle () |
bool | commandCloseConnection () |
bool | commandGetVersion () |
int | dispatchCommand () |
void | postProcessSimulationStep2 () |
bool | processSingleSubscription (const TraCIServer::Subscription &s, tcpip::Storage &writeInto, std::string &errors) |
TraCIServer (int port=0) | |
virtual | ~TraCIServer () |
Private Attributes | |
const bool | myAmEmbedded |
bool | myDoingSimStep |
std::map< int, CmdExecutor > | myExecutors |
Map of commandIds -> their executors; applicable if the executor applies to the method footprint. | |
bool | myHaveWarnedDeprecation |
tcpip::Storage | myInputStorage |
tcpip::Storage | myOutputStorage |
tcpip::Socket * | mySocket |
socket on which server is listening on | |
std::vector< Subscription > | mySubscriptions |
SUMOTime | myTargetTime |
std::map< MSNet::VehicleState, std::vector< std::string > > | myVehicleStateChanges |
Static Private Attributes | |
static bool | myDoCloseConnection = false |
static TraCIServer * | myInstance = 0 |
singleton instance of the server |
Definition at line 76 of file TraCIServer.h.
typedef bool(* traci::TraCIServer::CmdExecutor)(traci::TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage) |
Definition of a method to be called for serving an associated commandID.
Definition at line 79 of file TraCIServer.h.
TraCIServer::TraCIServer | ( | int | port = 0 | ) | [private] |
Definition at line 125 of file TraCIServer.cpp.
References tcpip::Socket::accept(), MSNet::addVehicleStateListener(), CMD_GET_EDGE_VARIABLE, CMD_GET_INDUCTIONLOOP_VARIABLE, CMD_GET_JUNCTION_VARIABLE, CMD_GET_LANE_VARIABLE, CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_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_POI_VARIABLE, CMD_SET_POLYGON_VARIABLE, CMD_SET_ROUTE_VARIABLE, CMD_SET_TL_VARIABLE, CMD_SET_VEHICLE_VARIABLE, CMD_SET_VEHICLETYPE_VARIABLE, MSNet::getInstance(), MsgHandler::getWarningInstance(), MSGlobals::gUsingInternalLanes, MsgHandler::inform(), myAmEmbedded, myDoCloseConnection, myExecutors, mySocket, myVehicleStateChanges, TraCIServerAPI_Edge::processGet(), TraCIServerAPI_Route::processGet(), TraCIServerAPI_TLS::processGet(), TraCIServerAPI_POI::processGet(), TraCIServerAPI_Polygon::processGet(), TraCIServerAPI_VehicleType::processGet(), TraCIServerAPI_Junction::processGet(), TraCIServerAPI_Lane::processGet(), TraCIServerAPI_InductionLoop::processGet(), TraCIServerAPI_MeMeDetector::processGet(), TraCIServerAPI_Vehicle::processGet(), TraCIServerAPI_Simulation::processGet(), TraCIServerAPI_Edge::processSet(), TraCIServerAPI_Route::processSet(), TraCIServerAPI_Lane::processSet(), TraCIServerAPI_POI::processSet(), TraCIServerAPI_TLS::processSet(), TraCIServerAPI_Polygon::processSet(), TraCIServerAPI_Vehicle::processSet(), TraCIServerAPI_VehicleType::processSet(), toString(), MSNet::VEHICLE_STATE_ARRIVED, MSNet::VEHICLE_STATE_BUILT, MSNet::VEHICLE_STATE_DEPARTED, MSNet::VEHICLE_STATE_ENDING_TELEPORT, MSNet::VEHICLE_STATE_NEWROUTE, MSNet::VEHICLE_STATE_STARTING_TELEPORT, tcpip::SocketException::what(), WRITE_MESSAGE, and WRITE_WARNING.
Referenced by openSocket(), and processCommandsUntilSimStep().
TraCIServer::~TraCIServer | ( | ) | [private, virtual] |
Definition at line 179 of file TraCIServer.cpp.
References tcpip::Socket::close(), MSNet::getInstance(), mySocket, and MSNet::removeVehicleStateListener().
bool TraCIServer::addSubscription | ( | int | commandId | ) | [private] |
Definition at line 642 of file TraCIServer.cpp.
References traci::TraCIServer::Subscription::commandId, traci::TraCIServer::Subscription::endTime, MSNet::getCurrentTimeStep(), MSNet::getInstance(), myInputStorage, myOutputStorage, mySubscriptions, processSingleSubscription(), tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), RTYPE_ERR, RTYPE_OK, writeStatusCmd(), and tcpip::Storage::writeStorage().
Referenced by dispatchCommand().
void TraCIServer::close | ( | ) | [static] |
request termination of connection
Definition at line 272 of file TraCIServer.cpp.
References myDoCloseConnection, and myInstance.
Referenced by MSNet::closeSimulation().
bool TraCIServer::commandAddVehicle | ( | ) | [private] |
Definition at line 532 of file TraCIServer.cpp.
References MSVehicleControl::addVehicle(), MSRoute::begin(), MSVehicleControl::buildVehicle(), CMD_ADDVEHICLE, CMD_STOP, MSVehicleControl::deleteVehicle(), SUMOVehicleParameter::depart, MSRoute::dictionary(), MSLane::dictionary(), MSNet::getCurrentTimeStep(), MSLane::getEdge(), MSRoute::getEdges(), MSBaseVehicle::getID(), MSNet::getInstance(), MSBaseVehicle::getMaxSpeed(), MSLane::getMaxSpeed(), MSNet::getVehicleControl(), MSVehicleControl::getVType(), SUMOVehicleParameter::id, MSLane::isInsertionSuccess(), MIN2(), MIN3(), myInputStorage, MSBaseVehicle::onDepart(), tcpip::Storage::readFloat(), tcpip::Storage::readString(), RTYPE_ERR, RTYPE_OK, SUMOReal, and writeStatusCmd().
Referenced by dispatchCommand().
bool TraCIServer::commandCloseConnection | ( | ) | [private] |
Definition at line 522 of file TraCIServer.cpp.
References CMD_CLOSE, myDoCloseConnection, RTYPE_OK, and writeStatusCmd().
Referenced by dispatchCommand().
bool TraCIServer::commandGetVersion | ( | ) | [private] |
Definition at line 497 of file TraCIServer.cpp.
References CMD_GETVERSION, myOutputStorage, RTYPE_OK, tcpip::Storage::size(), TRACI_VERSION, VERSION_STRING, tcpip::Storage::writeInt(), writeStatusCmd(), tcpip::Storage::writeStorage(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
Referenced by dispatchCommand().
int TraCIServer::dispatchCommand | ( | ) | [private] |
Definition at line 359 of file TraCIServer.cpp.
References addSubscription(), CMD_ADDVEHICLE, CMD_CLOSE, CMD_DISTANCEREQUEST, CMD_GETVERSION, CMD_POSITIONCONVERSION, CMD_SIMSTEP2, CMD_SUBSCRIBE_EDGE_VARIABLE, CMD_SUBSCRIBE_GUI_VARIABLE, CMD_SUBSCRIBE_INDUCTIONLOOP_VARIABLE, CMD_SUBSCRIBE_JUNCTION_VARIABLE, CMD_SUBSCRIBE_LANE_VARIABLE, CMD_SUBSCRIBE_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, CMD_SUBSCRIBE_POI_VARIABLE, CMD_SUBSCRIBE_POLYGON_VARIABLE, CMD_SUBSCRIBE_ROUTE_VARIABLE, CMD_SUBSCRIBE_SIM_VARIABLE, CMD_SUBSCRIBE_TL_VARIABLE, CMD_SUBSCRIBE_VEHICLE_VARIABLE, CMD_SUBSCRIBE_VEHICLETYPE_VARIABLE, commandAddVehicle(), commandCloseConnection(), TraCIServerAPI_Simulation::commandDistanceRequest(), commandGetVersion(), TraCIServerAPI_Simulation::commandPositionConversion(), DELTA_T, MSNet::getInstance(), myAmEmbedded, myDoCloseConnection, myExecutors, myHaveWarnedDeprecation, myInputStorage, myOutputStorage, myTargetTime, tcpip::Storage::position(), postProcessSimulationStep2(), tcpip::Storage::readChar(), tcpip::Storage::readInt(), tcpip::Storage::readUnsignedByte(), RTYPE_ERR, RTYPE_NOTIMPLEMENTED, RTYPE_OK, MSNet::simulationStep(), tcpip::Storage::valid_pos(), WRITE_WARNING, writeStatusCmd(), and tcpip::Storage::writeStorage().
Referenced by processCommandsUntilSimStep().
std::map<int, CmdExecutor>& traci::TraCIServer::getExecutors | ( | ) | [inline] |
Returns the list of (unified) command executors.
Not all command executor methods apply to the wanted footprint; other comments may be served internally (aka there are more commandIds recognized than within this container
Definition at line 120 of file TraCIServer.h.
References myExecutors.
const std::map<MSNet::VehicleState, std::vector<std::string> >& traci::TraCIServer::getVehicleStateChanges | ( | ) | const [inline] |
Definition at line 109 of file TraCIServer.h.
References myVehicleStateChanges.
Referenced by TraCIServerAPI_Simulation::processGet().
void TraCIServer::openSocket | ( | const std::map< int, CmdExecutor > & | execs | ) | [static] |
Initialises the server.
[in] | execs | The (additional) command executors to use |
Definition at line 112 of file TraCIServer.cpp.
References OptionsCont::getOptions(), myDoCloseConnection, myExecutors, myInstance, and TraCIServer().
Referenced by GUIApplicationWindow::handleEvent_SimulationLoaded().
void TraCIServer::postProcessSimulationStep2 | ( | ) | [private] |
Definition at line 464 of file TraCIServer.cpp.
References traci::TraCIServer::Subscription::beginTime, CMD_SIMSTEP2, CMD_SUBSCRIBE_VEHICLE_VARIABLE, traci::TraCIServer::Subscription::commandId, traci::TraCIServer::Subscription::endTime, MSNet::getCurrentTimeStep(), MSNet::getInstance(), traci::TraCIServer::Subscription::id, myOutputStorage, mySubscriptions, myVehicleStateChanges, processSingleSubscription(), RTYPE_OK, MSNet::VEHICLE_STATE_ARRIVED, tcpip::Storage::writeInt(), writeStatusCmd(), and tcpip::Storage::writeStorage().
Referenced by dispatchCommand(), and processCommandsUntilSimStep().
void TraCIServer::processCommandsUntilSimStep | ( | SUMOTime | step | ) | [static] |
process all commands until a simulation step is wanted
Definition at line 199 of file TraCIServer.cpp.
References CMD_SIMSTEP2, dispatchCommand(), OptionsCont::getOptions(), myAmEmbedded, myDoCloseConnection, myDoingSimStep, myInputStorage, myInstance, myOutputStorage, mySocket, myTargetTime, myVehicleStateChanges, postProcessSimulationStep2(), tcpip::Socket::receiveExact(), tcpip::Storage::reset(), tcpip::Socket::sendExact(), tcpip::Storage::size(), TraCIServer(), tcpip::Storage::valid_pos(), and tcpip::SocketException::what().
Referenced by MSNet::simulationStep().
bool TraCIServer::processSingleSubscription | ( | const TraCIServer::Subscription & | s, |
tcpip::Storage & | writeInto, | ||
std::string & | errors | ||
) | [private] |
Definition at line 692 of file TraCIServer.cpp.
References traci::TraCIServer::Subscription::commandId, traci::TraCIServer::Subscription::id, myExecutors, tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), RTYPE_ERR, RTYPE_NOTIMPLEMENTED, RTYPE_OK, tcpip::Storage::size(), TYPE_STRING, traci::TraCIServer::Subscription::variables, tcpip::Storage::writeInt(), writeStatusCmd(), tcpip::Storage::writeStorage(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
Referenced by addSubscription(), and postProcessSimulationStep2().
void TraCIServer::vehicleStateChanged | ( | const SUMOVehicle *const | vehicle, |
MSNet::VehicleState | to | ||
) | [virtual] |
Called if a vehicle changes its state.
[in] | vehicle | The vehicle which changed its state |
[in] | to | The state the vehicle has changed to |
Implements MSNet::VehicleStateListener.
Definition at line 190 of file TraCIServer.cpp.
References SUMOVehicle::getID(), OptionsCont::getOptions(), myDoCloseConnection, and myVehicleStateChanges.
bool TraCIServer::wasClosed | ( | ) | [static] |
check whether close was requested
Definition at line 266 of file TraCIServer.cpp.
References myDoCloseConnection.
Referenced by GUIRunThread::makeStep(), MSNet::simulate(), and MSNet::simulationState().
void TraCIServer::writeResponseWithLength | ( | tcpip::Storage & | outputStorage, |
tcpip::Storage & | tempMsg | ||
) |
Definition at line 755 of file TraCIServer.cpp.
References tcpip::Storage::size(), tcpip::Storage::writeInt(), tcpip::Storage::writeStorage(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCIServerAPI_Edge::processGet(), TraCIServerAPI_VehicleType::processGet(), TraCIServerAPI_InductionLoop::processGet(), TraCIServerAPI_TLS::processGet(), TraCIServerAPI_Lane::processGet(), TraCIServerAPI_Route::processGet(), TraCIServerAPI_Polygon::processGet(), TraCIServerAPI_POI::processGet(), TraCIServerAPI_MeMeDetector::processGet(), TraCIServerAPI_Junction::processGet(), TraCIServerAPI_Vehicle::processGet(), and TraCIServerAPI_Simulation::processGet().
void TraCIServer::writeStatusCmd | ( | int | commandId, |
int | status, | ||
const std::string & | description | ||
) |
Definition at line 621 of file TraCIServer.cpp.
References myOutputStorage.
Referenced by addSubscription(), commandAddVehicle(), commandCloseConnection(), TraCIServerAPI_Vehicle::commandDistanceRequest(), TraCIServerAPI_Simulation::commandDistanceRequest(), commandGetVersion(), TraCIServerAPI_Simulation::commandPositionConversion(), dispatchCommand(), postProcessSimulationStep2(), TraCIServerAPI_Edge::processGet(), TraCIServerAPI_Polygon::processGet(), TraCIServerAPI_Route::processGet(), TraCIServerAPI_InductionLoop::processGet(), TraCIServerAPI_Junction::processGet(), TraCIServerAPI_Lane::processGet(), TraCIServerAPI_TLS::processGet(), TraCIServerAPI_MeMeDetector::processGet(), TraCIServerAPI_VehicleType::processGet(), TraCIServerAPI_POI::processGet(), TraCIServerAPI_Vehicle::processGet(), TraCIServerAPI_Simulation::processGet(), TraCIServerAPI_Edge::processSet(), TraCIServerAPI_POI::processSet(), TraCIServerAPI_Polygon::processSet(), TraCIServerAPI_Route::processSet(), TraCIServerAPI_Lane::processSet(), TraCIServerAPI_TLS::processSet(), TraCIServerAPI_Vehicle::processSet(), TraCIServerAPI_VehicleType::processSet(), processSingleSubscription(), and TraCIServerAPI_VehicleType::setVariable().
void TraCIServer::writeStatusCmd | ( | int | commandId, |
int | status, | ||
const std::string & | description, | ||
tcpip::Storage & | outputStorage | ||
) |
Definition at line 627 of file TraCIServer.cpp.
References RTYPE_ERR, RTYPE_NOTIMPLEMENTED, toString(), WRITE_ERROR, tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
const bool traci::TraCIServer::myAmEmbedded [private] |
Definition at line 163 of file TraCIServer.h.
Referenced by dispatchCommand(), processCommandsUntilSimStep(), and TraCIServer().
bool TraCIServer::myDoCloseConnection = false [static, private] |
Definition at line 150 of file TraCIServer.h.
Referenced by close(), commandCloseConnection(), dispatchCommand(), openSocket(), processCommandsUntilSimStep(), TraCIServer(), vehicleStateChanged(), and wasClosed().
bool traci::TraCIServer::myDoingSimStep [private] |
Definition at line 161 of file TraCIServer.h.
Referenced by processCommandsUntilSimStep().
std::map<int, CmdExecutor> traci::TraCIServer::myExecutors [private] |
Map of commandIds -> their executors; applicable if the executor applies to the method footprint.
Definition at line 166 of file TraCIServer.h.
Referenced by dispatchCommand(), getExecutors(), openSocket(), processSingleSubscription(), and TraCIServer().
Definition at line 162 of file TraCIServer.h.
Referenced by dispatchCommand().
Definition at line 159 of file TraCIServer.h.
Referenced by addSubscription(), commandAddVehicle(), dispatchCommand(), and processCommandsUntilSimStep().
TraCIServer * TraCIServer::myInstance = 0 [static, private] |
singleton instance of the server
Definition at line 149 of file TraCIServer.h.
Referenced by close(), openSocket(), and processCommandsUntilSimStep().
Definition at line 160 of file TraCIServer.h.
Referenced by addSubscription(), commandGetVersion(), dispatchCommand(), postProcessSimulationStep2(), processCommandsUntilSimStep(), and writeStatusCmd().
tcpip::Socket* traci::TraCIServer::mySocket [private] |
socket on which server is listening on
Definition at line 153 of file TraCIServer.h.
Referenced by processCommandsUntilSimStep(), TraCIServer(), and ~TraCIServer().
std::vector<Subscription> traci::TraCIServer::mySubscriptions [private] |
Definition at line 182 of file TraCIServer.h.
Referenced by addSubscription(), and postProcessSimulationStep2().
SUMOTime traci::TraCIServer::myTargetTime [private] |
Definition at line 156 of file TraCIServer.h.
Referenced by dispatchCommand(), and processCommandsUntilSimStep().
std::map<MSNet::VehicleState, std::vector<std::string> > traci::TraCIServer::myVehicleStateChanges [private] |
Definition at line 187 of file TraCIServer.h.
Referenced by getVehicleStateChanges(), postProcessSimulationStep2(), processCommandsUntilSimStep(), TraCIServer(), and vehicleStateChanged().