195 if (shape.
value.size() < 256) {
232 for (
const auto& p : value) {
294 for (
const std::shared_ptr<libsumo::TraCIPhase>& phase : logic.phases) {
301 for (
int n : phase->next) {
307 for (
const auto& item : logic.subParameter) {
318 for (
const std::vector<libsumo::TraCILink>& sublinks : value) {
319 cnt += (int)sublinks.size() + 1;
323 for (
const std::vector<libsumo::TraCILink>& sublinks : value) {
337 for (
const auto& c : value) {
348 for (
const auto& c : value) {
368 for (
const auto& s : value) {
369 const int legacyStopFlags = (s.stopFlags << 1) + (s.arrival >= 0 ? 1 : 0);
446 : myTargetTime(begin), myLastContextSubscription(nullptr) {
447#ifdef DEBUG_MULTI_CLIENTS
448 std::cout <<
"Creating new TraCIServer for " << numClients <<
" clients on port " << port <<
"." << std::endl;
544 if (numClients > 1) {
547 while ((
int)
mySockets.size() < numClients) {
568 if (numClients > 1) {
573 if (numClients > 1) {
586 delete socket.second;
599 for (std::map<int, CmdExecutor>::const_iterator i = execs.begin(); i != execs.end(); ++i) {
636 for (std::map<int, SocketInfo*>::iterator i =
mySockets.begin(); i !=
mySockets.end(); ++i) {
637 i->second->vehicleStateChanges[to].push_back(vehicle->
getID());
647 for (std::map<int, SocketInfo*>::iterator i =
mySockets.begin(); i !=
mySockets.end(); ++i) {
648 i->second->transportableStateChanges[to].push_back(transportable->
getID());
656#ifdef DEBUG_MULTI_CLIENTS
657 std::cout <<
"Checking client order requests." << std::endl;
663#ifdef DEBUG_MULTI_CLIENTS
664 std::cout <<
" Socket " <<
myCurrentSocket->second->socket <<
":" << std::endl;
670 int commandStart, commandLength;
672#ifdef DEBUG_MULTI_CLIENTS
673 std::cout <<
" received command " << commandId << std::endl;
679#ifdef DEBUG_MULTI_CLIENTS
680 std::cout <<
" Init command. Sending response." << std::endl;
699#ifdef DEBUG_MULTI_CLIENTS
700 std::cout <<
" Client " <<
myCurrentSocket->second->socket <<
" did not set order initially." << std::endl;
702 throw ProcessError(
TL(
"Execution order (libsumo::CMD_SETORDER) was not set for all TraCI clients in pre-execution phase."));
720 std::map<int, SocketInfo*>::iterator j;
721#ifdef DEBUG_MULTI_CLIENTS
722 std::cout <<
SIMTIME <<
" Current socket ordering:\n";
724 std::cout <<
" " << j->first <<
": " << j->second->socket <<
"\n";
726 std::cout <<
"Reordering requests:\n";
728 std::cout <<
" Socket " << i->second->socket <<
" -> " << i->first <<
"\n";
735 if (j->second->socket == i->second->socket) {
747#ifdef DEBUG_MULTI_CLIENTS
748 std::cout <<
"New socket ordering:\n";
750 std::cout <<
" " << j->first <<
": " << j->second->socket <<
"\n";
752 std::cout << std::endl;
760#ifdef DEBUG_MULTI_CLIENTS
761 std::cout <<
"\n Determining new target time..." << std::endl;
763 std::cout <<
" All clients have disconnected." << std::endl;
766 std::map<int, SocketInfo*>::const_iterator i;
767 SUMOTime targetTime = std::numeric_limits<SUMOTime>::max();
769#ifdef DEBUG_MULTI_CLIENTS
770 std::cout <<
" target time for client " << i->second->socket <<
": " << i->second->targetTime <<
"\n";
772 targetTime =
MIN2(targetTime, i->second->targetTime);
774#ifdef DEBUG_MULTI_CLIENTS
775 std::cout << std::endl;
784#ifdef DEBUG_MULTI_CLIENTS
785 std::cout <<
"\n Sending subscription results to clients:\n";
787 std::map<int, SocketInfo*>::const_iterator i =
mySockets.begin();
792#ifdef DEBUG_MULTI_CLIENTS
793 std::cout << i->second->socket <<
"\n";
798#ifdef DEBUG_MULTI_CLIENTS
799 std::cout << std::endl;
806#ifdef DEBUG_MULTI_CLIENTS
807 std::cout <<
SIMTIME <<
" processCommands(step = " << step <<
"):\n" << std::endl;
814 if (!firstStep && !afterMove) {
827#ifdef DEBUG_MULTI_CLIENTS
828 std::cout <<
" next target time is larger than next SUMO simstep (" << step <<
"). Returning from processCommands()." << std::endl;
839#ifdef DEBUG_MULTI_CLIENTS
840 std::cout <<
" Next target time: " <<
myTargetTime << std::endl;
845#ifdef DEBUG_MULTI_CLIENTS
853#ifdef DEBUG_MULTI_CLIENTS
855 <<
" with target time=" <<
myCurrentSocket->second->targetTime << std::endl;
861 while (finalCmd == 0) {
869#ifdef DEBUG_MULTI_CLIENTS
870 std::cout <<
" resetting input storage and reading next command..." << std::endl;
886#ifdef DEBUG_MULTI_CLIENTS
887 std::cout <<
" Breaking loop to load new simulation." << std::endl;
891#ifdef DEBUG_MULTI_CLIENTS
892 std::cout <<
" Breaking loop because last client closed connection." << std::endl;
914 }
catch (std::invalid_argument& e) {
927 const std::string
id = inputStorage.
readString();
932 if (!libsumo::InductionLoop::handleVariable(
id, variable,
this, &inputStorage)) {
937 if (!libsumo::MultiEntryExit::handleVariable(
id, variable,
this, &inputStorage)) {
942 if (!libsumo::TrafficLight::handleVariable(
id, variable,
this, &inputStorage)) {
945 StoHelp::readCompound(inputStorage, 3,
"A compound object of size 3 is needed for swapping constraints.");
947 const std::string foeSignal =
StoHelp::readTypedString(inputStorage,
"The foeSignal id must be given as a string.");
958 if (!libsumo::Lane::handleVariable(
id, variable,
this, &inputStorage)) {
963 if (!libsumo::Vehicle::handleVariable(
id, variable,
this, &inputStorage)) {
968 if (!libsumo::VehicleType::handleVariable(
id, variable,
this, &inputStorage)) {
973 if (!libsumo::Route::handleVariable(
id, variable,
this, &inputStorage)) {
978 if (!libsumo::POI::handleVariable(
id, variable,
this, &inputStorage)) {
983 if (!libsumo::Polygon::handleVariable(
id, variable,
this, &inputStorage)) {
988 if (!libsumo::Junction::handleVariable(
id, variable,
this, &inputStorage)) {
993 if (!libsumo::Edge::handleVariable(
id, variable,
this, &inputStorage)) {
1003 if (!libsumo::LaneArea::handleVariable(
id, variable,
this, &inputStorage)) {
1008 if (!libsumo::Person::handleVariable(
id, variable,
this, &inputStorage)) {
1013 if (!libsumo::BusStop::handleVariable(
id, variable,
this, &inputStorage)) {
1018 if (!libsumo::ParkingArea::handleVariable(
id, variable,
this, &inputStorage)) {
1023 if (!libsumo::ChargingStation::handleVariable(
id, variable,
this, &inputStorage)) {
1028 if (!libsumo::RouteProbe::handleVariable(
id, variable,
this, &inputStorage)) {
1033 if (!libsumo::Calibrator::handleVariable(
id, variable,
this, &inputStorage)) {
1038 if (!libsumo::Rerouter::handleVariable(
id, variable,
this, &inputStorage)) {
1043 if (!libsumo::VariableSpeedSign::handleVariable(
id, variable,
this, &inputStorage)) {
1048 if (!libsumo::MeanData::handleVariable(
id, variable,
this, &inputStorage)) {
1053 if (!libsumo::OverheadWire::handleVariable(
id, variable,
this, &inputStorage)) {
1090std::map<int, TraCIServer::SocketInfo*>::iterator
1092#ifdef DEBUG_MULTI_CLIENTS
1106 if (commandLength == 0) {
1109#ifdef DEBUG_RAW_INPUT
1110 std::cout <<
" commandStart=" << commandStart <<
" commandLength=" << commandLength <<
" pos=" <<
myInputStorage.
position() <<
" raw=";
1112 std::cout << (int)*it <<
" ";
1122 int commandStart, commandLength;
1124#ifdef DEBUG_MULTI_CLIENTS
1125 std::cout <<
" dispatchCommand() called for client " <<
myCurrentSocket->second->socket
1126 <<
", commandId = " << commandId << std::endl;
1128 bool success =
false;
1140 switch (commandId) {
1147#ifdef DEBUG_MULTI_CLIENTS
1148 std::cout <<
" commandId == libsumo::CMD_LOAD"
1149 <<
", args = " <<
toString(args) << std::endl;
1178#ifdef DEBUG_MULTI_CLIENTS
1179 std::cout <<
" commandId == libsumo::CMD_SIMSTEP"
1180 <<
", next target time for client is " <<
myCurrentSocket->second->targetTime << std::endl;
1192 item.second.clear();
1194 for (
auto& item :
myCurrentSocket->second->transportableStateChanges) {
1195 item.second.clear();
1214#ifdef DEBUG_MULTI_CLIENTS
1215 std::cout <<
" commandId == libsumo::CMD_SETORDER"
1216 <<
", order index is " << order << std::endl;
1298 std::ostringstream msg;
1299 msg <<
"Wrong position in requestMessage after dispatching command " << commandId <<
".";
1300 msg <<
" Expected command length was " << commandLength;
1331#ifdef DEBUG_MULTI_CLIENTS
1332 std::cout <<
" postProcessSimulationStep() at time=" << t << std::endl;
1342 if ((s.
endTime < t) || isArrivedVehicle || isArrivedPerson) {
1353#ifdef DEBUG_SUBSCRIPTIONS
1355 <<
"\n Nr. of active subscriptions = " << noActive << std::endl;
1358#ifdef DEBUG_SUBSCRIPTIONS
1370#ifdef DEBUG_SUBSCRIPTIONS
1371 std::cout <<
" Size of into-store for subscription " << s.
id
1372 <<
": " << into.
size() << std::endl;
1382#ifdef DEBUG_SUBSCRIPTIONS
1390#ifdef DEBUG_MULTI_CLIENTS
1391 std::cout <<
" Sending cached simstep response to current client " <<
myCurrentSocket->second->socket
1392 <<
" (-> intermediate TraCI step)."
1418 WRITE_ERROR(
"Answered with error to command " +
toHex(commandId, 2) +
": " + description);
1420 WRITE_ERROR(
"Requested command not implemented (" +
toHex(commandId, 2) +
"): " + description);
1422 outputStorage.
writeUnsignedByte(1 + 1 + 1 + 4 +
static_cast<int>(description.length()));
1463 if (modifiedSubscription !=
nullptr && (
1485 std::vector<libsumo::Subscription>::iterator j;
1487 if (j->id ==
id && j->commandId == commandId && j->contextDomain == domain) {
1509 std::string& errors) {
1513 std::set<std::string> objIDs;
1522 objIDs.insert(s.
id);
1526 for (std::set<std::string>::iterator j = objIDs.begin(); j != objIDs.end(); ++j) {
1535 std::vector<std::shared_ptr<tcpip::Storage> >::const_iterator k = s.
parameters.begin();
1536 for (std::vector<int>::const_iterator i = s.
variables.begin(); i != s.
variables.end(); ++i, ++k) {
1541 for (
const auto& v :** k) {
1547 ok &=
myExecutors[getCommandId](*
this, message, tmpOutput);
1548 }
else if (!
processGet(getCommandId, message, tmpOutput)) {
1554 }
catch (
const std::invalid_argument&) {
1561 while (--length > 0) {
1564 int lengthLength = 1;
1576 length -= (lengthLength + 1 + 4 + (int)
id.length());
1577 while (--length > 0) {
1592 errors = errors + msg;
1597 int length = (1 + 4) + 1 + (4 + (
int)s.
id.length()) + 1 + (
int)outputStorage.
size();
1611 writeInto.
writeInt((
int)objIDs.size() - skipped);
1630 range = std::numeric_limits<double>::max();
1633 std::vector<int> variables;
1634 std::vector<std::shared_ptr<tcpip::Storage> > parameters;
1635 for (
int i = 0; i < num; ++i) {
1637 variables.push_back(varID);
1638 parameters.push_back(std::make_shared<tcpip::Storage>());
1645 while (count-- > 0) {
1647 parameters.back()->writeUnsignedByte(parType);
1683 parameters.back()->writeInt(count);
1692 if (variables.empty()) {
1706 bool success =
true;
1712 "No previous vehicle context subscription exists to apply filter type " +
toHex(filterType, 2));
1717 switch (filterType) {
1725 std::vector<int> lanes;
1726 for (
int i = 0; i < nrLanes; ++i) {
1768 std::set<std::string> vTypesSet;
1769 vTypesSet.insert(vTypesVector.begin(), vTypesVector.end());
1787 "'" +
toString(filterType) +
"' is no valid filter type code.");
1802#ifdef DEBUG_SUBSCRIPTION_FILTERS
1803 std::cout <<
"Removing filters" << std::endl;
1810#ifdef DEBUG_SUBSCRIPTION_FILTERS
1811 std::cout <<
"Adding lane filter (lanes=" <<
toString(lanes) <<
")" << std::endl;
1819#ifdef DEBUG_SUBSCRIPTION_FILTERS
1820 std::cout <<
"Adding no opposite filter" << std::endl;
1827#ifdef DEBUG_SUBSCRIPTION_FILTERS
1828 std::cout <<
"Adding downstream dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1836#ifdef DEBUG_SUBSCRIPTION_FILTERS
1837 std::cout <<
"Adding upstream dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1845#ifdef DEBUG_SUBSCRIPTION_FILTERS
1846 std::cout <<
"Adding Lead/Follow-maneuver filter" << std::endl;
1853#ifdef DEBUG_SUBSCRIPTION_FILTERS
1854 std::cout <<
"Adding turn-maneuver filter" << std::endl;
1862#ifdef DEBUG_SUBSCRIPTION_FILTERS
1863 std::cout <<
"Adding vClass filter (vClasses=" <<
toString(vClasses) <<
")" << std::endl;
1871#ifdef DEBUG_SUBSCRIPTION_FILTERS
1872 std::cout <<
"Adding vType filter (vTypes=" <<
toString(vTypes) <<
")" << std::endl;
1880#ifdef DEBUG_SUBSCRIPTION_FILTERS
1881 std::cout <<
"Adding FieldOfVision filter (openingAngle=" <<
toString(openingAngle) <<
")" << std::endl;
1889#ifdef DEBUG_SUBSCRIPTION_FILTERS
1890 std::cout <<
"Adding lateral dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1898 if (tempMsg.
size() < 254) {
1912 s.second->targetTime = targetTime;
1913 s.second->executeMove =
false;
1914 for (
auto& stateChange : s.second->vehicleStateChanges) {
1915 stateChange.second.clear();
1917 for (
auto& stateChange : s.second->transportableStateChanges) {
1918 stateChange.second.clear();
#define WRITE_MESSAGEF(...)
#define WRITE_MESSAGE(msg)
#define WRITE_WARNING(msg)
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
constexpr SUMOTime TIME2STEPS(double x)
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
long long 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.
@ ENDING_PARKING
The vehicle ends to park.
@ STARTING_STOP
The vehicles starts to stop.
@ BUILT
The vehicle was built, but has not yet departed.
@ STARTING_PARKING
The vehicles starts to park.
@ NEWROUTE
The vehicle got a new route.
@ STARTING_TELEPORT
The vehicle started to teleport.
@ ENDING_STOP
The vehicle ends to stop.
@ ENDING_TELEPORT
The vehicle ended being teleported.
@ ARRIVED
The vehicle arrived at his destination (is deleted)
@ DEPARTED
The vehicle has departed (was inserted into the network)
@ COLLISION
The vehicle is involved in a collision.
@ EMERGENCYSTOP
The vehicle had to brake harder than permitted.
@ MANEUVERING
Vehicle maneuvering either entering or exiting a parking space.
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.
void addTransportableStateListener(TransportableStateListener *listener)
Adds a transportable states listener.
TransportableState
Definition of a transportable state.
@ CONTAINER_DEPARTED
The transportable container has departed (was inserted into the network)
@ PERSON_DEPARTED
The transportable person has departed (was inserted into the network)
@ PERSON_ARRIVED
The transportable person arrived at his destination (is deleted)
@ CONTAINER_ARRIVED
The transportable container arrived at his destination (is deleted)
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.
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 processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change Calibrator State)
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 processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc0: Set Induction Loop Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc9: Set Junction Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xcd: Set AreaDetector Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc3: Change Lane State)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc1: Set MeMeDetector 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 processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change ParkingArea State)
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 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 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, const std::string &objID, const int variable)
Processes a get value command (Command 0xab: Get Simulation Variable)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xcb: Set Simulation 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 processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc4: Change Vehicle State)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc5: Change Vehicle Type State)
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.
bool wrapStringDoublePair(const std::string &objID, const int variable, const std::pair< std::string, double > &value)
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
void addSubscriptionFilterTurn(double dist)
bool wrapIntPair(const std::string &objID, const int variable, const std::pair< int, int > &value)
bool wrapReservationVector(const std::string &objID, const int variable, const std::vector< libsumo::TraCIReservation > &value)
bool centralObject(const libsumo::Subscription &s, const std::string &objID)
check whether a found objID refers to the central object of a context subscription
bool wrapPositionVector(const std::string &objID, const int variable, const libsumo::TraCIPositionVector &value)
void addSubscriptionFilterVType(std::set< std::string > vTypes)
bool wrapInt(const std::string &objID, const int variable, const int value)
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
std::map< MSNet::TransportableState, std::vector< std::string > > myTransportableStateChanges
Changes in the states of simulated transportables.
void removeSubscription(int commandId, const std::string &identity, int domain)
bool wrapStage(const std::string &objID, const int variable, const libsumo::TraCIStage &value)
bool wrapDouble(const std::string &objID, const int variable, const double value)
tcpip::Storage mySubscriptionCache
The last timestep's subscription results.
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.
bool wrapConnectionVector(const std::string &objID, const int variable, const std::vector< libsumo::TraCIConnection > &value)
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.
bool wrapDoubleList(const std::string &objID, const int variable, const std::vector< double > &value)
void checkClientOrdering()
Called once after connection of all clients for executing SET_ORDER (and possibly prior GET_VERSION) ...
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...
bool wrapSignalConstraintVector(const std::string &objID, const int variable, const std::vector< libsumo::TraCISignalConstraint > &value)
void cleanup()
clean up subscriptions
static void close()
request termination of connection
void postProcessSimulationStep()
Handles subscriptions to send after a simstep2 command.
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 processGet(const int commandID, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command.
int processCommands(const SUMOTime step, const bool afterMove=false)
process all commands until the next SUMO simulation step. It is guaranteed that t->getTargetTime() >=...
SUMOTime myTargetTime
The time step to reach until processing the next commands.
virtual ~TraCIServer()
Destructor.
bool wrapNextStopDataVector(const std::string &objID, const int variable, const std::vector< libsumo::TraCINextStopData > &value)
bool wrapStringPair(const std::string &objID, const int variable, const std::pair< std::string, std::string > &value)
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)
bool wrapStringDoublePairList(const std::string &objID, const int variable, const std::vector< std::pair< std::string, double > > &value)
TraCIServer(const SUMOTime begin, const int port, const int numClients)
Constructor.
tcpip::Storage myInputStorage
The storage to read from.
bool wrapLogicVector(const std::string &objID, const int variable, const std::vector< libsumo::TraCILogic > &value)
bool wrapNextTLSDataVector(const std::string &objID, const int variable, const std::vector< libsumo::TraCINextTLSData > &value)
libsumo::Subscription * myLastContextSubscription
The last modified context subscription (the one to add a filter to, see @addSubscriptionFilter(),...
std::map< int, SocketInfo * >::iterator myCurrentSocket
The currently active client socket.
bool wrapVehicleDataVector(const std::string &objID, const int variable, const std::vector< libsumo::TraCIVehicleData > &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()
std::set< std::pair< int, int > > myParameterized
Set of variables which have parameters.
void transportableStateChanged(const MSTransportable *const transportable, MSNet::TransportableState to, const std::string &info="")
Called if a transportable changes its state.
bool processSingleSubscription(const libsumo::Subscription &s, tcpip::Storage &writeInto, std::string &errors)
void initialiseSubscription(libsumo::Subscription &s)
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 wrapBestLanesDataVector(const std::string &objID, const int variable, const std::vector< libsumo::TraCIBestLanesData > &value)
bool wrapLinkVectorVector(const std::string &objID, const int variable, const std::vector< std::vector< libsumo::TraCILink > > &value)
bool wrapJunctionFoeVector(const std::string &objID, const int variable, const std::vector< libsumo::TraCIJunctionFoe > &value)
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)
static void writeConstraint(tcpip::Storage &content, const libsumo::TraCISignalConstraint &c)
static void writeTypedDouble(tcpip::Storage &content, double value)
static int readCompound(tcpip::Storage &ret, int expectedSize=-1, const std::string &error="")
static std::vector< std::string > readTypedStringList(tcpip::Storage &ret, const std::string &error="")
static void writeStage(tcpip::Storage &content, const libsumo::TraCIStage &stage)
static void writeTypedUnsignedByte(tcpip::Storage &content, int value)
static void writeCompound(tcpip::Storage &content, int size)
static std::string readTypedString(tcpip::Storage &ret, const std::string &error="")
static void writeTypedInt(tcpip::Storage &content, int value)
static void writeTypedStringList(tcpip::Storage &content, const std::vector< std::string > &value)
static void writeTypedByte(tcpip::Storage &content, int value)
static void writeTypedString(tcpip::Storage &content, const std::string &value)
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.
SUMOTime endTime
The end time of the subscription.
int contextDomain
The domain ID of the context.
double filterFoeDistToJunction
Foe distance to junction specified by the turn filter.
bool isVehicleToVehicleContextSubscription() const
SUMOTime beginTime
The begin time of the subscription.
std::vector< int > variables
The subscribed variables.
SVCPermissions filterVClasses
vClasses specified by the vClasses filter,
bool isVehicleToPersonContextSubscription() const
double filterDownstreamDist
Downstream distance specified by the downstream distance filter.
double filterLateralDist
Lateral distance specified by the lateral distance filter.
int activeFilters
Active filters for the subscription (bitset,.
double range
The range of the context.
std::vector< std::shared_ptr< tcpip::Storage > > parameters
The parameters for the subscribed variables.
An error which allows to continue.
Socket * accept(const bool create=false)
Wait for a incoming connection to port_.
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 writeChar(unsigned char)
virtual void writeUnsignedByte(int)
StorageType::size_type size() const
virtual void writeDoubleList(const std::vector< double > &s)
virtual void writeByte(int)
virtual void writeStorage(tcpip::Storage &store)
virtual std::vector< std::string > readStringList()
virtual double readDouble()
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 VAR_EDGES
TRACI_CONST int CMD_SET_JUNCTION_VARIABLE
TRACI_CONST int POSITION_3D
TRACI_CONST int CMD_GET_CHARGINGSTATION_VARIABLE
TRACI_CONST int POSITION_ROADMAP
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 CMD_SUBSCRIBE_BUSSTOP_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_PARKINGAREA_VARIABLE
TRACI_CONST int TL_BLOCKING_VEHICLES
TRACI_CONST int VAR_SECURE_GAP
TRACI_CONST int CMD_SUBSCRIBE_JUNCTION_VARIABLE
TRACI_CONST int TL_CONSTRAINT_SWAP
TRACI_CONST int CMD_SUBSCRIBE_VEHICLE_CONTEXT
TRACI_CONST int VAR_EDGE_TRAVELTIME
TRACI_CONST int CMD_GET_REROUTER_VARIABLE
TRACI_CONST int LANE_CHANGES
TRACI_CONST int CMD_GET_VEHICLE_VARIABLE
TRACI_CONST int VAR_TAXI_RESERVATIONS
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 VAR_FOLLOW_SPEED
TRACI_CONST int TL_PRIORITY_VEHICLES
TRACI_CONST int CMD_EXECUTEMOVE
TRACI_CONST int CMD_SUBSCRIBE_TL_CONTEXT
TRACI_CONST int FILTER_TYPE_FIELD_OF_VISION
TRACI_CONST int VAR_ANGLE
TRACI_CONST int TYPE_COMPOUND
TRACI_CONST int CMD_SUBSCRIBE_ROUTEPROBE_VARIABLE
TRACI_CONST int CMD_SET_REROUTER_VARIABLE
TRACI_CONST int VAR_EDGE_EFFORT
TRACI_CONST int CMD_SUBSCRIBE_MEANDATA_CONTEXT
TRACI_CONST int CMD_GET_PERSON_VARIABLE
TRACI_CONST int VAR_MEANDATA_VALUES
TRACI_CONST int CMD_SUBSCRIBE_REROUTER_CONTEXT
TRACI_CONST int CMD_SET_VARIABLESPEEDSIGN_VARIABLE
TRACI_CONST int TYPE_UBYTE
TRACI_CONST int CMD_SUBSCRIBE_GUI_VARIABLE
TRACI_CONST int VAR_STAGE
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_SUBSCRIBE_OVERHEADWIRE_VARIABLE
TRACI_CONST int VAR_PERSON_NUMBER
TRACI_CONST int CMD_SET_POLYGON_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_BUSSTOP_CONTEXT
TRACI_CONST int VAR_STOP_PARAMETER
TRACI_CONST int POSITION_2D
TRACI_CONST int CMD_GET_BUSSTOP_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_ROUTEPROBE_CONTEXT
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 VAR_TAXI_FLEET
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_SUBSCRIBE_OVERHEADWIRE_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_CALIBRATOR_CONTEXT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int CMD_SET_VEHICLETYPE_VARIABLE
TRACI_CONST int CMD_SET_PERSON_VARIABLE
TRACI_CONST int CMD_GET_SIM_VARIABLE
TRACI_CONST int TL_CONSTRAINT_BYFOE
TRACI_CONST int CMD_SET_MULTIENTRYEXIT_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_POLYGON_VARIABLE
TRACI_CONST int VAR_STOP_SPEED
TRACI_CONST int CMD_SUBSCRIBE_PERSON_CONTEXT
TRACI_CONST int CMD_GET_VEHICLETYPE_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_CHARGINGSTATION_CONTEXT
TRACI_CONST int TL_CONSTRAINT
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 VAR_MEANDATA_LANE
TRACI_CONST int CMD_SET_PARKINGAREA_VARIABLE
TRACI_CONST int CMD_GET_LANE_VARIABLE
TRACI_CONST int CMD_SET_LANEAREA_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 CMD_SUBSCRIBE_PARKINGAREA_CONTEXT
TRACI_CONST int TYPE_DOUBLELIST
TRACI_CONST int CMD_GET_POLYGON_VARIABLE
TRACI_CONST int VAR_NEXT_STOPS2
TRACI_CONST int FILTER_TYPE_TURN
TRACI_CONST int CMD_SUBSCRIBE_MULTIENTRYEXIT_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_REROUTER_VARIABLE
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
TRACI_CONST int DISTANCE_REQUEST
@ 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_SUBSCRIBE_CALIBRATOR_VARIABLE
TRACI_CONST int CMD_SET_INDUCTIONLOOP_VARIABLE
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_CHANGELANE
TRACI_CONST int CMD_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE
TRACI_CONST int CMD_SUBSCRIBE_CHARGINGSTATION_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 VAR_NEIGHBORS
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 VAR_FOLLOWER
TRACI_CONST int CMD_SUBSCRIBE_LANEAREA_CONTEXT
TRACI_CONST int CMD_SUBSCRIBE_VARIABLESPEEDSIGN_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 SPLIT_TAXI_RESERVATIONS
TRACI_CONST int CMD_SUBSCRIBE_MEANDATA_VARIABLE
TRACI_CONST int FILTER_TYPE_LATERAL_DIST
TRACI_CONST int CMD_SUBSCRIBE_EDGE_VARIABLE
TRACI_CONST int TYPE_STRING
TRACI_CONST int TL_RIVAL_VEHICLES
TRACI_CONST int VAR_NEXT_STOPS
TRACI_CONST int CMD_SUBSCRIBE_VARIABLESPEEDSIGN_VARIABLE
A 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE.
std::vector< TraCIPosition > value
mirrors MSInductLoop::VehicleData