190 : myTargetTime(begin), myLastContextSubscription(nullptr) {
191 #ifdef DEBUG_MULTI_CLIENTS
192 std::cout <<
"Creating new TraCIServer for " << numClients <<
" clients on port " << port <<
"." << std::endl;
258 WRITE_WARNING(
"Starting TraCI without using internal lanes!");
266 if (numClients > 1) {
269 while ((
int)
mySockets.size() < numClients) {
285 if (numClients > 1) {
290 if (numClients > 1) {
316 for (std::map<int, CmdExecutor>::const_iterator i = execs.begin(); i != execs.end(); ++i) {
352 for (std::map<int, SocketInfo*>::iterator i =
mySockets.begin(); i !=
mySockets.end(); ++i) {
353 i->second->vehicleStateChanges[to].push_back(vehicle->
getID());
361 #ifdef DEBUG_MULTI_CLIENTS
362 std::cout <<
"Checking client order requests." << std::endl;
368 #ifdef DEBUG_MULTI_CLIENTS
369 std::cout <<
" Socket " <<
myCurrentSocket->second->socket <<
":" << std::endl;
373 #pragma warning(push)
374 #pragma warning(disable: 4127)
382 int commandStart, commandLength;
384 #ifdef DEBUG_MULTI_CLIENTS
385 std::cout <<
" received command " << commandId << std::endl;
391 #ifdef DEBUG_MULTI_CLIENTS
392 std::cout <<
" Init command. Sending response." << std::endl;
411 #ifdef DEBUG_MULTI_CLIENTS
412 std::cout <<
" Client " <<
myCurrentSocket->second->socket <<
" did not set order initially." << std::endl;
414 throw ProcessError(
"Execution order (libsumo::CMD_SETORDER) was not set for all TraCI clients in pre-execution phase.");
432 std::map<int, SocketInfo*>::iterator j;
433 #ifdef DEBUG_MULTI_CLIENTS
434 std::cout <<
SIMTIME <<
" Current socket ordering:\n";
436 std::cout <<
" " << j->first <<
": " << j->second->socket <<
"\n";
438 std::cout <<
"Reordering requests:\n";
440 std::cout <<
" Socket " << i->second->socket <<
" -> " << i->first <<
"\n";
447 if (j->second->socket == i->second->socket) {
459 #ifdef DEBUG_MULTI_CLIENTS
460 std::cout <<
"New socket ordering:\n";
462 std::cout <<
" " << j->first <<
": " << j->second->socket <<
"\n";
464 std::cout << std::endl;
472 #ifdef DEBUG_MULTI_CLIENTS
473 std::cout <<
"\n Determining new target time..." << std::endl;
475 std::cout <<
" All clients have disconnected." << std::endl;
478 std::map<int, SocketInfo*>::const_iterator i;
479 SUMOTime targetTime = std::numeric_limits<SUMOTime>::max();
481 #ifdef DEBUG_MULTI_CLIENTS
482 std::cout <<
" target time for client " << i->second->socket <<
": " << i->second->targetTime <<
"\n";
484 targetTime =
MIN2(targetTime, i->second->targetTime);
486 #ifdef DEBUG_MULTI_CLIENTS
487 std::cout << std::endl;
496 #ifdef DEBUG_MULTI_CLIENTS
497 std::cout <<
"\n Sending subscription results to clients:\n";
499 std::map<int, SocketInfo*>::const_iterator i =
mySockets.begin();
504 #ifdef DEBUG_MULTI_CLIENTS
505 std::cout << i->second->socket <<
"\n";
510 #ifdef DEBUG_MULTI_CLIENTS
511 std::cout << std::endl;
518 #ifdef DEBUG_MULTI_CLIENTS
519 std::cout <<
SIMTIME <<
" processCommandsUntilSimStep(step = " << step <<
"):\n" << std::endl;
538 #ifdef DEBUG_MULTI_CLIENTS
540 std::cout <<
" next target time is larger than next SUMO simstep (" << step <<
"). Returning from processCommandsUntilSimStep()." << std::endl;
552 #ifdef DEBUG_MULTI_CLIENTS
553 std::cout <<
" Next target time: " <<
myTargetTime << std::endl;
558 #ifdef DEBUG_MULTI_CLIENTS
566 #ifdef DEBUG_MULTI_CLIENTS
568 <<
" with target time " <<
myCurrentSocket->second->targetTime << std::endl;
576 while (!done && !closed && !load) {
580 #ifdef DEBUG_MULTI_CLIENTS
581 std::cout <<
" sending response..." << std::endl;
587 #ifdef DEBUG_MULTI_CLIENTS
588 std::cout <<
" No input and no output stored (This is the next client)." << std::endl;
591 #ifdef DEBUG_MULTI_CLIENTS
592 std::cout <<
" resetting input storage and reading next command..." << std::endl;
602 #ifdef DEBUG_MULTI_CLIENTS
603 std::cout <<
" Received command " << cmd << std::endl;
606 #ifdef DEBUG_MULTI_CLIENTS
607 std::cout <<
" Received command SIM_STEP, end turn for client " <<
myCurrentSocket->second->socket << std::endl;
611 #ifdef DEBUG_MULTI_CLIENTS
612 std::cout <<
" Received command LOAD." << std::endl;
616 #ifdef DEBUG_MULTI_CLIENTS
617 std::cout <<
" Received command CLOSE." << std::endl;
640 #ifdef DEBUG_MULTI_CLIENTS
641 std::cout <<
" Breaking loop to load new simulation." << std::endl;
645 #ifdef DEBUG_MULTI_CLIENTS
646 std::cout <<
" Breaking loop because last client closed connection." << std::endl;
664 }
catch (std::invalid_argument& e) {
684 std::map<MSNet::VehicleState, std::vector<std::string> >::iterator i;
692 std::map<int, TraCIServer::SocketInfo*>::iterator
694 #ifdef DEBUG_MULTI_CLIENTS
726 if (commandLength == 0) {
729 #ifdef DEBUG_RAW_INPUT
730 std::cout <<
" commandStart=" << commandStart <<
" commandLength=" << commandLength <<
" pos=" <<
myInputStorage.
position() <<
" raw=";
732 std::cout << (int)*it <<
" ";
742 int commandStart, commandLength;
744 #ifdef DEBUG_MULTI_CLIENTS
745 std::cout <<
" dispatchCommand() called for client " <<
myCurrentSocket->second->socket
746 <<
", commandId = " << commandId << std::endl;
748 bool success =
false;
758 std::vector<std::string> args;
762 #ifdef DEBUG_MULTI_CLIENTS
763 std::cout <<
" commandId == libsumo::CMD_LOAD"
764 <<
", args = " <<
toString(args) << std::endl;
786 #ifdef DEBUG_MULTI_CLIENTS
787 std::cout <<
" commandId == libsumo::CMD_SIMSTEP"
788 <<
", next target time for client is " <<
myCurrentSocket->second->targetTime << std::endl;
809 #ifdef DEBUG_MULTI_CLIENTS
810 std::cout <<
" commandId == libsumo::CMD_SETORDER"
811 <<
", order index is " << order << std::endl;
876 std::ostringstream msg;
877 msg <<
"Wrong position in requestMessage after dispatching command " << commandId <<
".";
878 msg <<
" Expected command length was " << commandLength;
909 #ifdef DEBUG_MULTI_CLIENTS
910 std::cout <<
" postProcessSimulationStep() at time " << t << std::endl;
919 if ((s.
endTime < t) || isArrivedVehicle || isArrivedPerson) {
930 #ifdef DEBUG_SUBSCRIPTIONS
932 <<
"\n Nr. of active subscriptions = " << noActive << std::endl;
935 #ifdef DEBUG_SUBSCRIPTIONS
947 #ifdef DEBUG_SUBSCRIPTIONS
948 std::cout <<
" Size of into-store for subscription " << s.
id
949 <<
": " << into.
size() << std::endl;
959 #ifdef DEBUG_SUBSCRIPTIONS
967 #ifdef DEBUG_MULTI_CLIENTS
968 std::cout <<
" Sending cached simstep response to current client " <<
myCurrentSocket->second->socket
969 <<
" (-> intermediate TraCI step)."
995 WRITE_ERROR(
"Answered with error to command " +
toHex(commandId, 2) +
": " + description);
997 WRITE_ERROR(
"Requested command not implemented (" +
toHex(commandId, 2) +
"): " + description);
999 outputStorage.
writeUnsignedByte(1 + 1 + 1 + 4 +
static_cast<int>(description.length()));
1039 if (modifiedSubscription !=
nullptr && (
1058 std::vector<libsumo::Subscription>::iterator j;
1060 if (j->id ==
id && j->commandId == commandId && j->contextDomain == domain) {
1082 std::string& errors) {
1086 std::set<std::string> objIDs;
1095 objIDs.insert(s.
id);
1099 for (std::set<std::string>::iterator j = objIDs.begin(); j != objIDs.end(); ++j) {
1108 std::vector<std::vector<unsigned char> >::const_iterator k = s.
parameters.begin();
1109 for (std::vector<int>::const_iterator i = s.
variables.begin(); i != s.
variables.end(); ++i, ++k) {
1116 ok &=
myExecutors[getCommandId](*
this, message, tmpOutput);
1124 while (--length > 0) {
1127 int lengthLength = 1;
1139 length -= (lengthLength + 1 + 4 + (int)
id.length());
1140 while (--length > 0) {
1155 errors = errors + msg;
1160 int length = (1 + 4) + 1 + (4 + (
int)(s.
id.length())) + 1 + (int)outputStorage.
size();
1173 writeInto.
writeInt((
int)objIDs.size() - skipped);
1192 std::vector<int> variables;
1193 std::vector<std::vector<unsigned char> > parameters;
1194 for (
int i = 0; i < num; ++i) {
1196 variables.push_back(varID);
1197 parameters.push_back(std::vector<unsigned char>());
1207 for (
int j = 0; j < 4; j++) {
1208 parameters.back().push_back(tmp.
readChar());
1210 for (
int j = 0; j < length; j++) {
1216 if (variables.empty()) {
1230 bool success =
true;
1232 WRITE_WARNING(
"addSubscriptionFilter: No previous vehicle context subscription exists to apply the context filter.");
1239 switch (filterType) {
1247 std::vector<int> lanes;
1248 for (
int i = 0; i < nrLanes; ++i) {
1287 std::set<std::string> vTypesSet;
1288 vTypesSet.insert(vTypesVector.begin(), vTypesVector.end());
1320 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1321 std::cout <<
"Removing filters" << std::endl;
1328 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1329 std::cout <<
"Adding lane filter (lanes=" <<
toString(lanes) <<
")" << std::endl;
1337 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1338 std::cout <<
"Adding no opposite filter" << std::endl;
1345 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1346 std::cout <<
"Adding downstream dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1354 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1355 std::cout <<
"Adding upstream dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1363 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1364 std::cout <<
"Adding Lead/Follow-maneuver filter" << std::endl;
1371 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1372 std::cout <<
"Adding turn-maneuver filter" << std::endl;
1379 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1380 std::cout <<
"Adding vClass filter (vClasses=" <<
toString(vClasses) <<
")" << std::endl;
1388 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1389 std::cout <<
"Adding vType filter (vTypes=" <<
toString(vTypes) <<
")" << std::endl;
1397 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1398 std::cout <<
"Adding FieldOfVision filter (openingAngle=" <<
toString(openingAngle) <<
")" << std::endl;
1406 #ifdef DEBUG_SUBSCRIPTION_FILTERS
1407 std::cout <<
"Adding lateral dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1415 if (tempMsg.
size() < 254) {
1428 if (shape.size() < 256) {
1432 outputStorage.
writeInt((
int)shape.size());
1446 into = inputStorage.
readInt();
1544 size = inputStorage.
readInt();
1547 for (
int i = 0; i < size; ++i) {
1550 if (std::isnan(x) || std::isnan(y)) {
1563 s.second->targetTime = targetTime;
1564 for (
auto& stateChange : s.second->vehicleStateChanges) {
1565 stateChange.second.clear();
#define WRITE_MESSAGE(msg)
#define WRITE_WARNING(msg)
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
std::string toHex(const T i, std::streamsize numDigits=0)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
VehicleState
Definition of a vehicle state.
@ VEHICLE_STATE_NEWROUTE
The vehicle got a new route.
@ VEHICLE_STATE_ENDING_TELEPORT
The vehicle ended being teleported.
@ VEHICLE_STATE_DEPARTED
The vehicle has departed (was inserted into the network)
@ VEHICLE_STATE_STARTING_PARKING
The vehicles starts to park.
@ VEHICLE_STATE_MANEUVERING
Vehicle maneuvering either entering or exiting a parking space.
@ VEHICLE_STATE_ENDING_STOP
The vehicle ends to stop.
@ VEHICLE_STATE_ARRIVED
The vehicle arrived at his destination (is deleted)
@ VEHICLE_STATE_COLLISION
The vehicle is involved in a collision.
@ VEHICLE_STATE_EMERGENCYSTOP
The vehicle had to brake harder than permitted.
@ VEHICLE_STATE_STARTING_TELEPORT
The vehicle started to teleport.
@ VEHICLE_STATE_STARTING_STOP
The vehicles starts to stop.
@ VEHICLE_STATE_ENDING_PARKING
The vehicle ends to park.
@ VEHICLE_STATE_BUILT
The vehicle was built, but has not yet departed.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
MSTransportable * get(const std::string &id) const
Returns the named transportable, if existing.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
const std::string & getID() const
Returns the id.
static OptionsCont & getOptions()
Retrieves the options.
A point in 2D or 3D with translation and scaling methods.
Representation of a vehicle.
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change BusStop State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get BusStop Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change Calibrator State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get Calibrator Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get ChargingStation Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change ChargingStation State)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xca: Change Edge State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xaa: Get Edge Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa0: Get Induction Loop Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa9: Get Junction Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get AreaDetector Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa3: Get Lane Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc3: Change Lane State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get MeanData Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get MeMeDetector Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get OverheadWire Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change OverheadWire State)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc7: Change PoI State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa7: Get PoI Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change ParkingArea State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get ParkingArea Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xae: Get Person Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xce: Change Person State)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc8: Change Polygon State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa8: Get Polygon Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get Rerouter Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change Rerouter State)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change Route State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get Route Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change RouteProbe State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get RouteProbe Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xcb: Set Simulation Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xab: Get Simulation Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa2: Get Traffic Lights Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc2: Change Traffic Lights State)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change VariableSpeedSign State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get VariableSpeedSign Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc4: Change Vehicle State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa4: Get Vehicle Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc5: Change Vehicle Type State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa5: Get Vehicle Type Variable)
TraCI server used to control sumo by a remote TraCI client.
void addSubscriptionFilterDownstreamDistance(double dist)
static bool myDoCloseConnection
Whether the connection was set to be to close.
std::map< int, int > myParameterSizes
Map of variable ids to the size of the parameter in bytes.
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 addSubscriptionFilterLateralDistance(double dist)
Filter only vehicles within the given lateral distance.
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
static bool wasClosed()
check whether close was requested
bool centralObject(const libsumo::Subscription &s, const std::string &objID)
check whether a found objID refers to the central object of a context subscription
std::map< int, SocketInfo * >::iterator myCurrentSocket
The currently active client socket.
void addSubscriptionFilterVType(std::set< std::string > vTypes)
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
bool wrapInt(const std::string &objID, const int variable, const int value)
bool readTypeCheckingByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and a byte, verifying the type.
std::map< int, SocketInfo * >::iterator removeCurrentSocket()
removes myCurrentSocket from mySockets and returns an iterator pointing to the next member according ...
tcpip::Storage myOutputStorage
The storage to write to.
bool addObjectVariableSubscription(const int commandId, const bool hasContext)
void addSubscriptionFilterUpstreamDistance(double dist)
void stateLoaded(SUMOTime targetTime)
updates myTargetTime and resets vehicle state changes after loading a simulation state
void addSubscriptionFilterLeadFollow()
void addSubscriptionFilterNoOpposite()
tcpip::Storage & getWrapperStorage()
SUMOTime nextTargetTime() const
get the minimal next target time among all clients
void removeSubscription(int commandId, const std::string &identity, int domain)
bool wrapDouble(const std::string &objID, const int variable, const double value)
tcpip::Storage mySubscriptionCache
The last timestep's subscription results.
bool readTypeCheckingUnsignedByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and an unsigned byte, verifying the type.
bool wrapColor(const std::string &objID, const int variable, const libsumo::TraCIColor &value)
bool wrapString(const std::string &objID, const int variable, const std::string &value)
int dispatchCommand()
Handles command, writes response to myOutputStorage.
void initWrapper(const int domainID, const int variable, const std::string &objID)
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
void checkClientOrdering()
Called once after connection of all clients for executing SET_ORDER (and possibly prior GET_VERSION) ...
bool readTypeCheckingPosition2D(tcpip::Storage &inputStorage, libsumo::TraCIPosition &into)
Reads the value type and a 2D position, verifying the type.
void processReorderingRequests()
checks for and processes reordering requests (relevant for multiple clients)
void sendOutputToAll() const
send out subscription results (actually just the content of myOutputStorage) to clients which will ac...
void cleanup()
clean up subscriptions
static void close()
request termination of connection
void processCommandsUntilSimStep(SUMOTime step)
process all commands until the next SUMO simulation step. It is guaranteed that t->getTargetTime() >=...
void postProcessSimulationStep()
Handles subscriptions to send after a simstep2 command.
bool readTypeCheckingInt(tcpip::Storage &inputStorage, int &into)
Reads the value type and an int, verifying the type.
bool commandGetVersion()
Returns the TraCI-version.
bool wrapPosition(const std::string &objID, const int variable, const libsumo::TraCIPosition &value)
static void openSocket(const std::map< int, CmdExecutor > &execs)
Initialises the server.
std::vector< std::string > myLoadArgs
void addSubscriptionFilterLanes(std::vector< int > lanes)
bool readTypeCheckingDoubleList(tcpip::Storage &inputStorage, std::vector< double > &into)
Reads the value type and a double list, verifying the type.
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
SUMOTime myTargetTime
The time step to reach until processing the next commands.
virtual ~TraCIServer()
Destructor.
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
void writePositionVector(tcpip::Storage &outputStorage, const libsumo::TraCIPositionVector &shape)
void addSubscriptionFilterTurn()
std::map< MSNet::VehicleState, std::vector< std::string > > myVehicleStateChanges
Changes in the states of simulated vehicles.
int readCommandID(int &commandStart, int &commandLength)
Reads the next command ID from the input storage.
void sendSingleSimStepResponse()
sends an empty response to a simstep command to the current client. (This applies to a situation wher...
std::map< int, CmdExecutor > myExecutors
Map of commandIds -> their executors; applicable if the executor applies to the method footprint.
std::vector< libsumo::Subscription > mySubscriptions
The list of known, still valid subscriptions.
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
TraCIServer(const SUMOTime begin, const int port, const int numClients)
Constructor.
tcpip::Storage myInputStorage
The storage to read from.
libsumo::Subscription * myLastContextSubscription
The last modified context subscription (the one to add a filter to, see @addSubscriptionFilter(),...
bool wrapRoadPosition(const std::string &objID, const int variable, const libsumo::TraCIRoadPosition &value)
void addSubscriptionFilterVClass(SVCPermissions vClasses)
static TraCIServer * myInstance
Singleton instance of the server.
std::map< int, SocketInfo * > mySocketReorderRequests
This stores the setOrder(int) requests of the clients.
bool addSubscriptionFilter()
bool processSingleSubscription(const libsumo::Subscription &s, tcpip::Storage &writeInto, std::string &errors)
void initialiseSubscription(libsumo::Subscription &s)
bool readTypeCheckingPolygon(tcpip::Storage &inputStorage, PositionVector &into)
Reads the value type and a polygon, verifying the type.
void addSubscriptionFilterFieldOfVision(double openingAngle)
Filter only vehicles within field of vision.
bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)
bool readTypeCheckingColor(tcpip::Storage &inputStorage, libsumo::TraCIColor &into)
Reads the value type and a color, verifying the type.
static void findObjectShape(int domain, const std::string &id, PositionVector &shape)
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...
static void collectObjectIDsInRange(int domain, const PositionVector &shape, double range, std::set< std::string > &into)
static bool needNewSubscription(libsumo::Subscription &s, std::vector< Subscription > &subscriptions, libsumo::Subscription *&modifiedSubscription)
Representation of a subscription.
double filterUpstreamDist
Upstream distance specified by the upstream distance filter.
int commandId
commandIdArg The command id of the subscription
std::set< std::string > filterVTypes
vTypes specified by the vTypes filter
double filterFieldOfVisionOpeningAngle
Opening angle (in deg) specified by the field of vision filter.
std::vector< int > filterLanes
lanes specified by the lanes filter
std::string id
The id of the object that is subscribed.
int filterVClasses
vClasses specified by the vClasses filter,
SUMOTime endTime
The end time of the subscription.
int contextDomain
The domain ID of the context.
bool isVehicleToVehicleContextSubscription() const
SUMOTime beginTime
The begin time of the subscription.
std::vector< int > variables
The subscribed variables.
bool isVehicleToPersonContextSubscription() const
double filterDownstreamDist
Downstream distance specified by the downstream distance filter.
double filterLateralDist
Lateral distance specified by the lateral distance filter.
std::vector< std::vector< unsigned char > > parameters
The parameters for the subscribed variables.
int activeFilters
Active filters for the subscription (bitset,.
double range
The range of the context.
Socket * accept(const bool create=false)
Wait for a incoming connection to port_.
virtual void writePacket(unsigned char *packet, int length)
StorageType::const_iterator begin() const
virtual unsigned char readChar()
virtual std::string readString()
virtual void writeString(const std::string &s)
virtual unsigned int position() const
virtual void writeInt(int)
StorageType::const_iterator end() const
virtual void writeDouble(double)
virtual int readUnsignedByte()
virtual void writeStringList(const std::vector< std::string > &s)
virtual void writeUnsignedByte(int)
StorageType::size_type size() const
virtual void writeByte(int)
virtual void writeStorage(tcpip::Storage &store)
virtual std::vector< std::string > readStringList()
virtual double readDouble()
virtual std::vector< double > readDoubleList()
TRACI_CONST double INVALID_DOUBLE_VALUE
TRACI_CONST int TYPE_COLOR
TRACI_CONST int CMD_SUBSCRIBE_SIM_VARIABLE
TRACI_CONST int FILTER_TYPE_DOWNSTREAM_DIST
TRACI_CONST int POSITION_3D
TRACI_CONST int CMD_GET_CHARGINGSTATION_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_EDGE_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_VEHICLETYPE_VARIABLE
TRACI_CONST int RTYPE_NOTIMPLEMENTED
TRACI_CONST int CMD_SUBSCRIBE_LANE_CONTEXT
TRACI_CONST int FILTER_TYPE_NOOPPOSITE
TRACI_CONST int CMD_SET_OVERHEADWIRE_VARIABLE
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int CMD_GET_PARKINGAREA_VARIABLE
TRACI_CONST int CMD_GET_POI_VARIABLE
TRACI_CONST int CMD_GET_TL_VARIABLE
TRACI_CONST int CMD_SET_EDGE_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_JUNCTION_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_VEHICLE_CONTEXT
TRACI_CONST int CMD_GET_REROUTER_VARIABLE
TRACI_CONST int CMD_GET_VEHICLE_VARIABLE
TRACI_CONST int CMD_SET_CALIBRATOR_VARIABLE
TRACI_CONST int CMD_GET_EDGE_VARIABLE
TRACI_CONST int CMD_GET_CALIBRATOR_VARIABLE
TRACI_CONST int MAX_ORDER
TRACI_CONST int CMD_SUBSCRIBE_TL_CONTEXT
TRACI_CONST int FILTER_TYPE_FIELD_OF_VISION
TRACI_CONST int CMD_SET_REROUTER_VARIABLE
std::vector< TraCIPosition > TraCIPositionVector
TRACI_CONST int CMD_GET_PERSON_VARIABLE
TRACI_CONST int CMD_SET_VARIABLESPEEDSIGN_VARIABLE
TRACI_CONST int TYPE_UBYTE
TRACI_CONST int CMD_SUBSCRIBE_GUI_VARIABLE
TRACI_CONST int CMD_SET_POI_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_ROUTE_CONTEXT
TRACI_CONST int CMD_GET_ROUTEPROBE_VARIABLE
TRACI_CONST int CMD_GET_LANEAREA_VARIABLE
TRACI_CONST int CMD_SET_POLYGON_VARIABLE
TRACI_CONST int POSITION_2D
TRACI_CONST int CMD_GET_BUSSTOP_VARIABLE
TRACI_CONST int VAR_LEADER
TRACI_CONST int CMD_CLOSE
TRACI_CONST int TYPE_POLYGON
TRACI_CONST int CMD_GET_ROUTE_VARIABLE
TRACI_CONST int CMD_SET_ROUTE_VARIABLE
TRACI_CONST int CMD_SETORDER
TRACI_CONST int FILTER_TYPE_VTYPE
TRACI_CONST int TYPE_STRINGLIST
TRACI_CONST int CMD_SET_SIM_VARIABLE
TRACI_CONST int TYPE_INTEGER
TRACI_CONST int CMD_ADD_SUBSCRIPTION_FILTER
TRACI_CONST int CMD_GET_MEANDATA_VARIABLE
TRACI_CONST int CMD_GET_JUNCTION_VARIABLE
TRACI_CONST int CMD_SET_VEHICLE_VARIABLE
TRACI_CONST int CMD_SET_GUI_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_ROUTE_VARIABLE
TRACI_CONST int TRACI_VERSION
TRACI_CONST int CMD_GET_VARIABLESPEEDSIGN_VARIABLE
TRACI_CONST int CMD_SET_VEHICLETYPE_VARIABLE
TRACI_CONST int CMD_SET_PERSON_VARIABLE
TRACI_CONST int CMD_GET_SIM_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_POLYGON_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_PERSON_CONTEXT
TRACI_CONST int CMD_GET_VEHICLETYPE_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_POLYGON_CONTEXT
TRACI_CONST int CMD_SET_CHARGINGSTATION_VARIABLE
TRACI_CONST int CMD_SET_LANE_VARIABLE
TRACI_CONST int FILTER_TYPE_LEAD_FOLLOW
TRACI_CONST int CMD_SUBSCRIBE_GUI_CONTEXT
TRACI_CONST int CMD_SET_PARKINGAREA_VARIABLE
TRACI_CONST int CMD_GET_LANE_VARIABLE
TRACI_CONST int VAR_POSITION3D
TRACI_CONST int CMD_GET_GUI_VARIABLE
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int FILTER_TYPE_UPSTREAM_DIST
TRACI_CONST int TYPE_DOUBLELIST
TRACI_CONST int CMD_GET_POLYGON_VARIABLE
TRACI_CONST int FILTER_TYPE_TURN
TRACI_CONST int CMD_SUBSCRIBE_MULTIENTRYEXIT_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_VEHICLE_VARIABLE
TRACI_CONST int CMD_GET_MULTIENTRYEXIT_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_POI_VARIABLE
TRACI_CONST int TYPE_DOUBLE
@ SUBS_FILTER_LEAD_FOLLOW
@ SUBS_FILTER_UPSTREAM_DIST
@ SUBS_FILTER_DOWNSTREAM_DIST
@ SUBS_FILTER_LATERAL_DIST
@ SUBS_FILTER_FIELD_OF_VISION
TRACI_CONST int CMD_SUBSCRIBE_LANEAREA_VARIABLE
TRACI_CONST int TYPE_BYTE
TRACI_CONST int CMD_SUBSCRIBE_POI_CONTEXT
TRACI_CONST int CMD_SET_TL_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_INDUCTIONLOOP_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_SIM_CONTEXT
TRACI_CONST int FILTER_TYPE_VCLASS
TRACI_CONST int CMD_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE
TRACI_CONST int CMD_GETVERSION
TRACI_CONST int RTYPE_ERR
TRACI_CONST int CMD_SIMSTEP
TRACI_CONST int FILTER_TYPE_NONE
TRACI_CONST int CMD_SUBSCRIBE_VEHICLETYPE_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_LANE_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_PERSON_VARIABLE
TRACI_CONST int CMD_GET_INDUCTIONLOOP_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_TL_VARIABLE
TRACI_CONST int CMD_GET_OVERHEADWIRE_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_LANEAREA_CONTEXT
TRACI_CONST int FILTER_TYPE_LANES
TRACI_CONST int CMD_SUBSCRIBE_JUNCTION_CONTEXT
TRACI_CONST int CMD_SET_ROUTEPROBE_VARIABLE
TRACI_CONST int CMD_SET_BUSSTOP_VARIABLE
TRACI_CONST int FILTER_TYPE_LATERAL_DIST
TRACI_CONST int CMD_SUBSCRIBE_EDGE_VARIABLE
TRACI_CONST int TYPE_STRING
An edgeId, position and laneIndex.