 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
181 : myServerSocket(nullptr), myTargetTime(begin), myLastContextSubscription(nullptr) {
182 #ifdef DEBUG_MULTI_CLIENTS
183 std::cout <<
"Creating new TraCIServer for " << numClients <<
" clients on port " << port <<
"." << std::endl;
231 WRITE_WARNING(
"Starting TraCI without using internal lanes!");
239 if (numClients > 1) {
242 while ((
int)
mySockets.size() < numClients) {
258 if (numClients > 1) {
263 if (numClients > 1) {
290 for (std::map<int, CmdExecutor>::const_iterator i = execs.begin(); i != execs.end(); ++i) {
326 for (std::map<int, SocketInfo*>::iterator i =
mySockets.begin(); i !=
mySockets.end(); ++i) {
327 i->second->vehicleStateChanges[to].push_back(vehicle->
getID());
335 #ifdef DEBUG_MULTI_CLIENTS
336 std::cout <<
"Checking client order requests." << std::endl;
342 #ifdef DEBUG_MULTI_CLIENTS
343 std::cout <<
" Socket " <<
myCurrentSocket->second->socket <<
":" << std::endl;
347 #pragma warning(push)
348 #pragma warning(disable: 4127) // do not warn about constant conditional expression
356 int commandStart, commandLength;
358 #ifdef DEBUG_MULTI_CLIENTS
359 std::cout <<
" received command " << commandId << std::endl;
365 #ifdef DEBUG_MULTI_CLIENTS
366 std::cout <<
" Init command. Sending response." << std::endl;
385 #ifdef DEBUG_MULTI_CLIENTS
386 std::cout <<
" Client " <<
myCurrentSocket->second->socket <<
" did not set order initially." << std::endl;
388 throw ProcessError(
"Execution order (libsumo::CMD_SETORDER) was not set for all TraCI clients in pre-execution phase.");
406 std::map<int, SocketInfo*>::iterator j;
407 #ifdef DEBUG_MULTI_CLIENTS
408 std::cout <<
SIMTIME <<
" Current socket ordering:\n";
410 std::cout <<
" " << j->first <<
": " << j->second->socket <<
"\n";
412 std::cout <<
"Reordering requests:\n";
414 std::cout <<
" Socket " << i->second->socket <<
" -> " << i->first <<
"\n";
421 if (j->second->socket == i->second->socket) {
433 #ifdef DEBUG_MULTI_CLIENTS
434 std::cout <<
"New socket ordering:\n";
436 std::cout <<
" " << j->first <<
": " << j->second->socket <<
"\n";
438 std::cout << std::endl;
446 #ifdef DEBUG_MULTI_CLIENTS
447 std::cout <<
"\n Determining new target time..." << std::endl;
449 std::cout <<
" All clients have disconnected." << std::endl;
452 std::map<int, SocketInfo*>::const_iterator i;
453 SUMOTime targetTime = std::numeric_limits<SUMOTime>::max();
455 #ifdef DEBUG_MULTI_CLIENTS
456 std::cout <<
" target time for client " << i->second->socket <<
": " << i->second->targetTime <<
"\n";
458 targetTime =
MIN2(targetTime, i->second->targetTime);
460 #ifdef DEBUG_MULTI_CLIENTS
461 std::cout << std::endl;
470 #ifdef DEBUG_MULTI_CLIENTS
471 std::cout <<
"\n Sending subscription results to clients:\n";
473 std::map<int, SocketInfo*>::const_iterator i =
mySockets.begin();
478 #ifdef DEBUG_MULTI_CLIENTS
479 std::cout << i->second->socket <<
"\n";
484 #ifdef DEBUG_MULTI_CLIENTS
485 std::cout << std::endl;
492 #ifdef DEBUG_MULTI_CLIENTS
493 std::cout <<
SIMTIME <<
" processCommandsUntilSimStep(step = " << step <<
"):\n" << std::endl;
512 #ifdef DEBUG_MULTI_CLIENTS
514 std::cout <<
" next target time is larger than next SUMO simstep (" << step <<
"). Returning from processCommandsUntilSimStep()." << std::endl;
526 #ifdef DEBUG_MULTI_CLIENTS
527 std::cout <<
" Next target time: " <<
myTargetTime << std::endl;
532 #ifdef DEBUG_MULTI_CLIENTS
540 #ifdef DEBUG_MULTI_CLIENTS
542 <<
" with target time " <<
myCurrentSocket->second->targetTime << std::endl;
550 while (!done && !closed && !load) {
554 #ifdef DEBUG_MULTI_CLIENTS
555 std::cout <<
" sending response..." << std::endl;
561 #ifdef DEBUG_MULTI_CLIENTS
562 std::cout <<
" No input and no output stored (This is the next client)." << std::endl;
565 #ifdef DEBUG_MULTI_CLIENTS
566 std::cout <<
" resetting input storage and reading next command..." << std::endl;
576 #ifdef DEBUG_MULTI_CLIENTS
577 std::cout <<
" Received command " << cmd << std::endl;
580 #ifdef DEBUG_MULTI_CLIENTS
581 std::cout <<
" Received command SIM_STEP, end turn for client " <<
myCurrentSocket->second->socket << std::endl;
585 #ifdef DEBUG_MULTI_CLIENTS
586 std::cout <<
" Received command LOAD." << std::endl;
590 #ifdef DEBUG_MULTI_CLIENTS
591 std::cout <<
" Received command CLOSE." << std::endl;
614 #ifdef DEBUG_MULTI_CLIENTS
615 std::cout <<
" Breaking loop to load new simulation." << std::endl;
619 #ifdef DEBUG_MULTI_CLIENTS
620 std::cout <<
" Breaking loop because last client closed connection." << std::endl;
638 }
catch (std::invalid_argument& e) {
658 std::map<MSNet::VehicleState, std::vector<std::string> >::iterator i;
666 std::map<int, TraCIServer::SocketInfo*>::iterator
668 #ifdef DEBUG_MULTI_CLIENTS
700 if (commandLength == 0) {
703 #ifdef DEBUG_RAW_INPUT
704 std::cout <<
" commandStart=" << commandStart <<
" commandLength=" << commandLength <<
" pos=" <<
myInputStorage.
position() <<
" raw=";
706 std::cout << (int)*it <<
" ";
716 int commandStart, commandLength;
718 #ifdef DEBUG_MULTI_CLIENTS
719 std::cout <<
" dispatchCommand() called for client " <<
myCurrentSocket->second->socket
720 <<
", commandId = " << commandId << std::endl;
722 bool success =
false;
732 std::vector<std::string> args;
736 #ifdef DEBUG_MULTI_CLIENTS
737 std::cout <<
" commandId == libsumo::CMD_LOAD"
738 <<
", args = " <<
toString(args) << std::endl;
760 #ifdef DEBUG_MULTI_CLIENTS
761 std::cout <<
" commandId == libsumo::CMD_SIMSTEP"
762 <<
", next target time for client is " <<
myCurrentSocket->second->targetTime << std::endl;
783 #ifdef DEBUG_MULTI_CLIENTS
784 std::cout <<
" commandId == libsumo::CMD_SETORDER"
785 <<
", order index is " << order << std::endl;
850 std::ostringstream msg;
851 msg <<
"Wrong position in requestMessage after dispatching command " << commandId <<
".";
852 msg <<
" Expected command length was " << commandLength;
868 answerTmp.
writeString(std::string(
"SUMO ") + sumoVersion);
884 #ifdef DEBUG_MULTI_CLIENTS
885 std::cout <<
" postProcessSimulationStep() at time " << t << std::endl;
894 if ((s.
endTime < t) || isArrivedVehicle || isArrivedPerson) {
905 #ifdef DEBUG_SUBSCRIPTIONS
907 <<
"\n Nr. of active subscriptions = " << noActive << std::endl;
910 #ifdef DEBUG_SUBSCRIPTIONS
922 #ifdef DEBUG_SUBSCRIPTIONS
923 std::cout <<
" Size of into-store for subscription " << s.
id
924 <<
": " << into.
size() << std::endl;
934 #ifdef DEBUG_SUBSCRIPTIONS
942 #ifdef DEBUG_MULTI_CLIENTS
943 std::cout <<
" Sending cached simstep response to current client " <<
myCurrentSocket->second->socket
944 <<
" (-> intermediate TraCI step)."
970 WRITE_ERROR(
"Answered with error to command " +
toHex(commandId, 2) +
": " + description);
972 WRITE_ERROR(
"Requested command not implemented (" +
toHex(commandId, 2) +
"): " + description);
974 outputStorage.
writeUnsignedByte(1 + 1 + 1 + 4 +
static_cast<int>(description.length()));
1033 std::vector<libsumo::Subscription>::iterator j;
1035 if (j->id ==
id && j->commandId == commandId && (domain < 0 || j->contextDomain == domain)) {
1062 std::string& errors) {
1066 std::set<std::string> objIDs;
1075 objIDs.insert(s.
id);
1079 for (std::set<std::string>::iterator j = objIDs.begin(); j != objIDs.end(); ++j) {
1088 std::vector<std::vector<unsigned char> >::const_iterator k = s.
parameters.begin();
1089 for (std::vector<int>::const_iterator i = s.
variables.begin(); i != s.
variables.end(); ++i, ++k) {
1096 ok &=
myExecutors[getCommandId](*
this, message, tmpOutput);
1104 while (--length > 0) {
1107 int lengthLength = 1;
1119 length -= (lengthLength + 1 + 4 + (int)
id.length());
1120 while (--length > 0) {
1135 errors = errors + msg;
1140 int length = (1 + 4) + 1 + (4 + (
int)(s.
id.length())) + 1 + (int)outputStorage.
size();
1153 writeInto.
writeInt((
int)objIDs.size() - skipped);
1172 std::vector<int> variables;
1173 std::vector<std::vector<unsigned char> > parameters;
1174 for (
int i = 0; i < num; ++i) {
1176 variables.push_back(varID);
1177 parameters.push_back(std::vector<unsigned char>());
1183 if (variables.size() == 0) {
1197 bool success =
true;
1199 WRITE_WARNING(
"addSubscriptionFilter: No previous vehicle context subscription exists to apply the context filter.");
1206 switch (filterType) {
1214 std::vector<int> lanes;
1215 for (
int i = 0; i < nrLanes; ++i) {
1254 std::set<std::string> vTypesSet;
1255 vTypesSet.insert(vTypesVector.begin(), vTypesVector.end());
1281 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1282 std::cout <<
"Removing filters" << std::endl;
1289 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1290 std::cout <<
"Adding lane filter (lanes=" <<
toString(lanes) <<
")" << std::endl;
1298 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1299 std::cout <<
"Adding no opposite filter" << std::endl;
1306 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1307 std::cout <<
"Adding downstream dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1315 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1316 std::cout <<
"Adding upstream dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1324 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1325 std::cout <<
"Adding Lead/Follow-maneuver filter" << std::endl;
1332 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1333 std::cout <<
"Adding turn-maneuver filter" << std::endl;
1340 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1341 std::cout <<
"Adding vClass filter (vClasses=" <<
toString(vClasses) <<
")" << std::endl;
1349 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1350 std::cout <<
"Adding vType filter (vTypes=" <<
toString(vTypes) <<
")" << std::endl;
1358 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1359 std::cout <<
"Adding FieldOfVision filter (openingAngle=" <<
toString(openingAngle) <<
")" << std::endl;
1367 if (tempMsg.
size() < 254) {
1380 if (shape.size() < 256) {
1384 outputStorage.
writeInt((
int)shape.size());
1398 into = inputStorage.
readInt();
1496 size = inputStorage.
readInt();
1499 for (
int i = 0; i < size; ++i) {
1502 if (std::isnan(x) || std::isnan(y)) {
1515 s.second->targetTime = targetTime;
TRACI_CONST int CMD_SUBSCRIBE_VEHICLETYPE_VARIABLE
TRACI_CONST int CMD_GET_TL_VARIABLE
TRACI_CONST int FILTER_TYPE_VCLASS
void addSubscriptionFilterUpstreamDistance(double dist)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change Route State)
virtual double readDouble()
int activeFilters
Active filters for the subscription (bitset,.
bool wrapRoadPosition(const std::string &objID, const int variable, const libsumo::TraCIRoadPosition &value)
TRACI_CONST int CMD_GET_POLYGON_VARIABLE
TRACI_CONST int CMD_SET_GUI_VARIABLE
std::map< MSNet::VehicleState, std::vector< std::string > > myVehicleStateChanges
Changes in the states of simulated vehicles.
TRACI_CONST int TYPE_COLOR
@ VEHICLE_STATE_DEPARTED
The vehicle has departed (was inserted into the network)
void setTargetTime(SUMOTime targetTime)
Sets myTargetTime on server and sockets to the given value.
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc4: Change Vehicle State)
double filterUpstreamDist
Upstream distance specified by the upstream distance filter.
void checkClientOrdering()
Called once after connection of all clients for executing SET_ORDER (and possibly prior GET_VERSION) ...
void addSubscriptionFilterFieldOfVision(double openingAngle)
Filter only vehicles within field of vision.
TraCIServer(const SUMOTime begin, const int port, const int numClients)
Constructor.
#define WRITE_WARNING(msg)
TRACI_CONST int CMD_SUBSCRIBE_VEHICLE_VARIABLE
TRACI_CONST double INVALID_DOUBLE_VALUE
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa5: Get Vehicle Type Variable)
TRACI_CONST int POSITION_3D
bool readTypeCheckingUnsignedByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and an unsigned byte, verifying the type.
bool addSubscriptionFilter()
double filterDownstreamDist
Downstream distance specified by the downstream distance filter.
TRACI_CONST int CMD_CLOSE
TRACI_CONST int CMD_SUBSCRIBE_ROUTE_CONTEXT
virtual void writeUnsignedByte(int)
int dispatchCommand()
Handles command, writes response to myOutputStorage.
static TraCIServer * myInstance
Singleton instance of the server.
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xab: Get Simulation Variable)
bool readTypeCheckingColor(tcpip::Storage &inputStorage, libsumo::TraCIColor &into)
Reads the value type and a color, verifying the type.
void addSubscriptionFilterNoOpposite()
bool addObjectVariableSubscription(const int commandId, const bool hasContext)
virtual const std::string & getID() const =0
Get the vehicle's ID.
std::map< int, SocketInfo * > mySocketReorderRequests
This stores the setOrder(int) requests of the clients.
TRACI_CONST int CMD_GET_PERSON_VARIABLE
virtual std::vector< std::string > readStringList()
TRACI_CONST int CMD_SET_POI_VARIABLE
bool commandGetVersion()
Returns the TraCI-version.
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
TRACI_CONST int CMD_SET_POLYGON_VARIABLE
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc8: Change Polygon State)
std::vector< int > filterLanes
lanes specified by the lanes filter
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
TRACI_CONST int CMD_GET_LANEAREA_VARIABLE
Representation of a vehicle.
std::string id
The id of the object that is subscribed.
TRACI_CONST int CMD_SET_SIM_VARIABLE
bool wrapDouble(const std::string &objID, const int variable, const double value)
static OptionsCont & getOptions()
Retrieves the options.
virtual void writePacket(unsigned char *packet, int length)
StorageType::const_iterator end() const
static bool needNewSubscription(libsumo::Subscription &s, std::vector< Subscription > &subscriptions, libsumo::Subscription *&modifiedSubscription)
TRACI_CONST int TYPE_DOUBLELIST
TRACI_CONST int CMD_SUBSCRIBE_PERSON_CONTEXT
TRACI_CONST int TYPE_BYTE
TRACI_CONST int CMD_SUBSCRIBE_JUNCTION_VARIABLE
SUMOTime endTime
The end time of the subscription.
std::vector< libsumo::Subscription > mySubscriptions
The list of known, still valid subscriptions.
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get MeMeDetector Variable)
Socket * accept(const bool create=false)
Wait for a incoming connection to port_.
static void applySubscriptionFilters(const Subscription &s, std::set< std::string > &objIDs)
Filter the given ID-Set (which was obtained from an R-Tree search) according to the filters set by th...
TRACI_CONST int FILTER_TYPE_FIELD_OF_VISION
void addSubscriptionFilterLeadFollow()
virtual unsigned char readChar()
TRACI_CONST int CMD_SUBSCRIBE_POI_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_PERSON_VARIABLE
TRACI_CONST int VAR_LEADER
TRACI_CONST int CMD_SUBSCRIBE_LANEAREA_CONTEXT
TRACI_CONST int CMD_GET_LANE_VARIABLE
SUMOTime myTargetTime
The time step to reach until processing the next commands.
@ VEHICLE_STATE_ARRIVED
The vehicle arrived at his destination (is deleted)
TRACI_CONST int CMD_SUBSCRIBE_VEHICLE_CONTEXT
static void close()
request termination of connection
@ VEHICLE_STATE_NEWROUTE
The vehicle got a new route.
tcpip::Storage & getWrapperStorage()
std::map< int, SocketInfo * >::iterator removeCurrentSocket()
removes myCurrentSocket from mySockets and returns an iterator pointing to the next member according ...
TRACI_CONST int CMD_GET_VEHICLE_VARIABLE
TRACI_CONST int CMD_SET_VEHICLE_VARIABLE
TRACI_CONST int CMD_GET_VEHICLETYPE_VARIABLE
void addSubscriptionFilterLanes(std::vector< int > lanes)
std::vector< int > variables
The subscribed variables.
TRACI_CONST int CMD_ADD_SUBSCRIPTION_FILTER
int readCommandID(int &commandStart, int &commandLength)
Reads the next command ID from the input storage.
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
@ VEHICLE_STATE_EMERGENCYSTOP
The vehicle had to brake harder than permitted.
void initialiseSubscription(libsumo::Subscription &s)
TRACI_CONST int FILTER_TYPE_UPSTREAM_DIST
tcpip::Storage mySubscriptionCache
The last timestep's subscription results.
virtual void writeByte(int)
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
std::vector< std::vector< unsigned char > > parameters
The parameters for the subscribed variables.
virtual ~TraCIServer()
Destructor.
TRACI_CONST int CMD_SUBSCRIBE_EDGE_VARIABLE
TRACI_CONST int FILTER_TYPE_LEAD_FOLLOW
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
TRACI_CONST int FILTER_TYPE_NOOPPOSITE
MSTransportable * get(const std::string &id) const
Returns the named transportable, if existing.
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc7: Change PoI State)
void initWrapper(const int domainID, const int variable, const std::string &objID)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xcb: Set Simulation Variable)
TRACI_CONST int CMD_SUBSCRIBE_POLYGON_CONTEXT
TRACI_CONST int CMD_SETORDER
int commandId
commandIdArg The command id of the subscription
tcpip::Storage myInputStorage
The storage to read from.
TRACI_CONST int CMD_SUBSCRIBE_SIM_CONTEXT
bool centralObject(const libsumo::Subscription &s, const std::string &objID)
check whether a found objID refers to the central object of a context subscription
void addSubscriptionFilterVType(std::set< std::string > vTypes)
virtual int readUnsignedByte()
bool readTypeCheckingDoubleList(tcpip::Storage &inputStorage, std::vector< double > &into)
Reads the value type and a double list, verifying the type.
virtual void writeInt(int)
TRACI_CONST int CMD_GETVERSION
bool readTypeCheckingPolygon(tcpip::Storage &inputStorage, PositionVector &into)
Reads the value type and a polygon, verifying the type.
TRACI_CONST int FILTER_TYPE_TURN
@ VEHICLE_STATE_STARTING_PARKING
The vehicles starts to park.
TRACI_CONST int TYPE_DOUBLE
TRACI_CONST int TYPE_POLYGON
virtual unsigned int position() const
TRACI_CONST int CMD_GET_POI_VARIABLE
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa4: Get Vehicle Variable)
virtual std::string readString()
bool readTypeCheckingByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and a byte, verifying the type.
TRACI_CONST int CMD_SUBSCRIBE_GUI_VARIABLE
bool wrapPosition(const std::string &objID, const int variable, const libsumo::TraCIPosition &value)
@ SUBS_FILTER_UPSTREAM_DIST
TRACI_CONST int CMD_SUBSCRIBE_SIM_VARIABLE
Representation of a subscription.
double filterFieldOfVisionOpeningAngle
Opening angle (in deg) specified by the field of vision filter.
TRACI_CONST int FILTER_TYPE_VTYPE
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
TRACI_CONST int TYPE_INTEGER
VehicleState
Definition of a vehicle state.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
TRACI_CONST int CMD_SET_VEHICLETYPE_VARIABLE
virtual void writeStorage(tcpip::Storage &store)
tcpip::Storage myOutputStorage
The storage to write to.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
void addSubscriptionFilterDownstreamDistance(double dist)
int filterVClasses
vClasses specified by the vClasses filter,
virtual void writeStringList(const std::vector< std::string > &s)
TRACI_CONST int CMD_SUBSCRIBE_VEHICLETYPE_CONTEXT
void postProcessSimulationStep()
Handles subscriptions to send after a simstep2 command.
TRACI_CONST int CMD_SET_LANE_VARIABLE
TRACI_CONST int FILTER_TYPE_NONE
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa0: Get Induction Loop Variable)
TRACI_CONST int RTYPE_ERR
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
static bool myDoCloseConnection
Whether the connection was set to be to close.
std::vector< std::string > myLoadArgs
TRACI_CONST int CMD_SUBSCRIBE_POLYGON_VARIABLE
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
TRACI_CONST int CMD_SUBSCRIBE_LANEAREA_VARIABLE
@ VEHICLE_STATE_COLLISION
The vehicle is involved in a collision.
std::string toHex(const T i, std::streamsize numDigits=0)
@ VEHICLE_STATE_STARTING_TELEPORT
The vehicle started to teleport.
TRACI_CONST int CMD_SET_TL_VARIABLE
TRACI_CONST int CMD_SET_PERSON_VARIABLE
@ VEHICLE_STATE_BUILT
The vehicle was built, but has not yet departed.
A point in 2D or 3D with translation and scaling methods.
TRACI_CONST int CMD_GET_SIM_VARIABLE
@ VEHICLE_STATE_STARTING_STOP
The vehicles starts to stop.
bool wrapColor(const std::string &objID, const int variable, const libsumo::TraCIColor &value)
TRACI_CONST int TRACI_ID_LIST
std::map< int, int > myParameterSizes
Map of variable ids to the size of the parameter in bytes.
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc5: Change Vehicle Type State)
SUMOTime beginTime
The begin time of the subscription.
TRACI_CONST int CMD_SUBSCRIBE_JUNCTION_CONTEXT
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get Route Variable)
void processReorderingRequests()
checks for and processes reordering requests (relevant for multiple clients)
tcpip::Storage myWrapperStorage
A temporary storage to let the wrapper write to.
std::map< int, SocketInfo * > mySockets
The socket connections to the clients the first component (index) determines the client's order (lowe...
void cleanup()
clean up subscriptions
bool processSingleSubscription(const libsumo::Subscription &s, tcpip::Storage &writeInto, std::string &errors)
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
void processCommandsUntilSimStep(SUMOTime step)
process all commands until the next SUMO simulation step. It is guaranteed that t->getTargetTime() >=...
SUMOTime string2time(const std::string &r)
TRACI_CONST int CMD_SUBSCRIBE_GUI_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_POI_VARIABLE
static void openSocket(const std::map< int, CmdExecutor > &execs)
Initialises the server.
void writePositionVector(tcpip::Storage &outputStorage, const libsumo::TraCIPositionVector &shape)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xce: Change Person State)
TRACI_CONST int TYPE_STRINGLIST
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xca: Change Edge State)
TRACI_CONST int CMD_SUBSCRIBE_TL_CONTEXT
virtual void writeString(const std::string &s)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc3: Change Lane State)
TRACI_CONST int CMD_SUBSCRIBE_ROUTE_VARIABLE
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
@ VEHICLE_STATE_MANEUVERING
Vehicle maneuvering either entering or exiting a parking space.
std::map< int, SocketInfo * >::iterator myCurrentSocket
The currently active client socket.
TRACI_CONST int CMD_GET_GUI_VARIABLE
static void collectObjectsInRange(int domain, const PositionVector &shape, double range, std::set< std::string > &into)
libsumo::Subscription * myLastContextSubscription
The last modified context subscription (the one to add a filter to, see @addSubscriptionFilter(),...
void addSubscriptionFilterVClass(SVCPermissions vClasses)
bool readTypeCheckingInt(tcpip::Storage &inputStorage, int &into)
Reads the value type and an int, verifying the type.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
virtual MSTransportableControl & getPersonControl()
Returns the person control.
TRACI_CONST int CMD_GET_MULTIENTRYEXIT_VARIABLE
StorageType::const_iterator begin() const
TRACI_CONST int FILTER_TYPE_DOWNSTREAM_DIST
TRACI_CONST int CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa2: Get Traffic Lights Variable)
TRACI_CONST int POSITION_2D
double range
The range of the context.
TRACI_CONST int CMD_GET_INDUCTIONLOOP_VARIABLE
void sendOutputToAll() const
send out subscription results (actually just the content of myOutputStorage) to clients which will ac...
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get AreaDetector Variable)
TRACI_CONST int TYPE_STRING
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa8: Get Polygon Variable)
TRACI_CONST int MAX_ORDER
TRACI_CONST int CMD_SUBSCRIBE_LANE_CONTEXT
TRACI_CONST int VAR_POSITION3D
@ VEHICLE_STATE_ENDING_PARKING
The vehicle ends to park.
@ SUBS_FILTER_DOWNSTREAM_DIST
static void findObjectShape(int domain, const std::string &id, PositionVector &shape)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa3: Get Lane Variable)
TRACI_CONST int CMD_SET_EDGE_VARIABLE
TRACI_CONST int FILTER_TYPE_LANES
TRACI_CONST int TYPE_UBYTE
TRACI_CONST int CMD_SUBSCRIBE_EDGE_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE
@ VEHICLE_STATE_ENDING_TELEPORT
The vehicle ended being teleported.
StorageType::size_type size() const
@ SUBS_FILTER_FIELD_OF_VISION
TRACI_CONST int CMD_SUBSCRIBE_INDUCTIONLOOP_VARIABLE
An edgeId, position and laneIndex.
int contextDomain
The domain ID of the context.
bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)
SUMOTime nextTargetTime() const
get the minimal next target time among all clients
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa9: Get Junction Variable)
TRACI_CONST int TRACI_VERSION
TRACI_CONST int CMD_SUBSCRIBE_MULTIENTRYEXIT_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_LANE_VARIABLE
tcpip::Socket * myServerSocket
The server socket.
void removeSubscription(int commandId, const std::string &identity, int domain)
virtual void writeDouble(double)
std::vector< TraCIPosition > TraCIPositionVector
bool wrapInt(const std::string &objID, const int variable, const int value)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc2: Change Traffic Lights State)
static bool wasClosed()
check whether close was requested
TraCI server used to control sumo by a remote TraCI client.
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xae: Get Person Variable)
void addSubscriptionFilterTurn()
@ SUBS_FILTER_LEAD_FOLLOW
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xaa: Get Edge Variable)
bool isVehicleToVehicleContextSubscription(const libsumo::Subscription &s)
void sendSingleSimStepResponse()
sends an empty response to a simstep command to the current client. (This applies to a situation wher...
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa7: Get PoI Variable)
TRACI_CONST int CMD_SUBSCRIBE_TL_VARIABLE
virtual std::vector< double > readDoubleList()
TRACI_CONST int CMD_SET_ROUTE_VARIABLE
std::map< int, CmdExecutor > myExecutors
Map of commandIds -> their executors; applicable if the executor applies to the method footprint.
TRACI_CONST int CMD_GET_EDGE_VARIABLE
bool readTypeCheckingPosition2D(tcpip::Storage &inputStorage, libsumo::TraCIPosition &into)
Reads the value type and a 2D position, verifying the type.
@ VEHICLE_STATE_ENDING_STOP
The vehicle ends to stop.
#define WRITE_MESSAGE(msg)
TRACI_CONST int RTYPE_NOTIMPLEMENTED
bool wrapString(const std::string &objID, const int variable, const std::string &value)
TRACI_CONST int CMD_SIMSTEP
std::set< std::string > filterVTypes
vTypes specified by the vTypes filter
TRACI_CONST int CMD_GET_JUNCTION_VARIABLE
TRACI_CONST int CMD_GET_ROUTE_VARIABLE
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.