176 #ifdef DEBUG_MULTI_CLIENTS 177 std::cout <<
"Creating new TraCIServer for " << numClients <<
" clients on port " << port <<
"." << std::endl;
224 WRITE_WARNING(
"Starting TraCI without using internal lanes!");
233 while ((
int)
mySockets.size() < numClients) {
250 if (numClients > 1) {
282 for (std::map<int, CmdExecutor>::const_iterator i = execs.begin(); i != execs.end(); ++i) {
319 for (std::map<int, SocketInfo*>::iterator i =
mySockets.begin(); i !=
mySockets.end(); ++i) {
320 i->second->vehicleStateChanges[to].push_back(vehicle->
getID());
329 #ifdef DEBUG_MULTI_CLIENTS 330 std::cout <<
"Checking client order requests." << std::endl;
336 #ifdef DEBUG_MULTI_CLIENTS 337 std::cout <<
" Socket " <<
myCurrentSocket->second->socket <<
":" << std::endl;
341 #pragma warning(push) 342 #pragma warning(disable: 4127) // do not warn about constant conditional expression 350 int commandStart, commandLength;
352 #ifdef DEBUG_MULTI_CLIENTS 353 std::cout <<
" received command " << commandId << std::endl;
359 #ifdef DEBUG_MULTI_CLIENTS 360 std::cout <<
" Init command. Sending response." << std::endl;
377 #ifdef DEBUG_MULTI_CLIENTS 378 std::cout <<
" Client " <<
myCurrentSocket->second->socket <<
" did not set order initially." << std::endl;
380 throw ProcessError(
"Execution order (CMD_SETORDER) was not set for all TraCI clients in pre-execution phase.");
398 std::map<int, SocketInfo*>::iterator j;
399 #ifdef DEBUG_MULTI_CLIENTS 400 std::cout <<
SIMTIME <<
" Current socket ordering:\n";
402 std::cout <<
" " << j->first <<
": " << j->second->socket <<
"\n";
404 std::cout <<
"Reordering requests:\n";
406 std::cout <<
" Socket " << i->second->socket <<
" -> " << i->first <<
"\n";
413 if (j->second->socket == i->second->socket) {
425 #ifdef DEBUG_MULTI_CLIENTS 426 std::cout <<
"New socket ordering:\n";
428 std::cout <<
" " << j->first <<
": " << j->second->socket <<
"\n";
430 std::cout << std::endl;
438 #ifdef DEBUG_MULTI_CLIENTS 439 std::cout <<
"\n Determining new target time..." << std::endl;
441 std::cout <<
" All clients have disconnected." << std::endl;
444 std::map<int, SocketInfo*>::const_iterator i;
445 SUMOTime targetTime = std::numeric_limits<SUMOTime>::max();
447 #ifdef DEBUG_MULTI_CLIENTS 448 std::cout <<
" target time for client " << i->second->socket <<
": " << i->second->targetTime <<
"\n";
450 targetTime =
MIN2(targetTime, i->second->targetTime);
452 #ifdef DEBUG_MULTI_CLIENTS 453 std::cout << std::endl;
462 #ifdef DEBUG_MULTI_CLIENTS 463 std::cout <<
"\n Sending subscription results to clients:\n";
465 std::map<int, SocketInfo*>::const_iterator i =
mySockets.begin();
470 #ifdef DEBUG_MULTI_CLIENTS 471 std::cout << i->second->socket <<
"\n";
476 #ifdef DEBUG_MULTI_CLIENTS 477 std::cout << std::endl;
484 #ifdef DEBUG_MULTI_CLIENTS 485 std::cout <<
SIMTIME <<
" processCommandsUntilSimStep(step = " << step <<
"):\n" << std::endl;
504 #ifdef DEBUG_MULTI_CLIENTS 506 std::cout <<
" next target time is larger than next SUMO simstep (" << step <<
"). Returning from processCommandsUntilSimStep()." << std::endl;
518 #ifdef DEBUG_MULTI_CLIENTS 519 std::cout <<
" Next target time: " <<
myTargetTime << std::endl;
524 #ifdef DEBUG_MULTI_CLIENTS 532 #ifdef DEBUG_MULTI_CLIENTS 534 <<
" with target time " <<
myCurrentSocket->second->targetTime << std::endl;
542 while (!done && !closed && !load) {
546 #ifdef DEBUG_MULTI_CLIENTS 547 std::cout <<
" sending response..." << std::endl;
553 #ifdef DEBUG_MULTI_CLIENTS 554 std::cout <<
" No input and no output stored (This is the next client)." << std::endl;
557 #ifdef DEBUG_MULTI_CLIENTS 558 std::cout <<
" resetting input storage and reading next command..." << std::endl;
568 #ifdef DEBUG_MULTI_CLIENTS 569 std::cout <<
" Received command " << cmd << std::endl;
572 #ifdef DEBUG_MULTI_CLIENTS 573 std::cout <<
" Received command SIM_STEP, end turn for client " <<
myCurrentSocket->second->socket << std::endl;
577 #ifdef DEBUG_MULTI_CLIENTS 578 std::cout <<
" Received command LOAD." << std::endl;
582 #ifdef DEBUG_MULTI_CLIENTS 583 std::cout <<
" Received command CLOSE." << std::endl;
606 #ifdef DEBUG_MULTI_CLIENTS 607 std::cout <<
" Breaking loop to load new simulation." << std::endl;
611 #ifdef DEBUG_MULTI_CLIENTS 612 std::cout <<
" Breaking loop because last client closed connection." << std::endl;
630 }
catch (std::invalid_argument& e) {
650 std::map<MSNet::VehicleState, std::vector<std::string> >::iterator i;
663 traciemb_execute(PyObject* , PyObject* args) {
666 if (!PyArg_ParseTuple(args,
"s#", &msg, &size)) {
669 std::string result = TraCIServer::execute(std::string(msg, size));
670 return Py_BuildValue(
"s#", result.c_str(), result.size());
673 static PyMethodDef EmbMethods[] = {
675 "execute", traciemb_execute, METH_VARARGS,
676 "Execute the given TraCI command and return the result." 678 {NULL, NULL, 0, NULL}
683 TraCIServer::execute(std::string cmd) {
688 for (std::string::iterator i = cmd.begin(); i != cmd.end(); ++i) {
693 }
catch (std::invalid_argument& e) {
704 TraCIServer::runEmbedded(std::string pyFile) {
705 PyObject* pName, *pModule;
707 Py_InitModule(
"traciemb", EmbMethods);
708 if (pyFile.length() > 3 && !pyFile.compare(pyFile.length() - 3, 3,
".py")) {
709 PyObject* sys_path, *path;
710 char pathstr[] =
"path";
711 sys_path = PySys_GetObject(pathstr);
712 if (sys_path == NULL || !PyList_Check(sys_path)) {
713 throw ProcessError(
"Could not access python sys.path!");
716 PyList_Insert(sys_path, 0, path);
718 FILE* pFile = fopen(pyFile.c_str(),
"r");
720 throw ProcessError(
"Failed to load \"" + pyFile +
"\"!");
722 PyRun_SimpleFile(pFile, pyFile.c_str());
725 pName = PyString_FromString(pyFile.c_str());
727 pModule = PyImport_Import(pName);
729 if (pModule == NULL) {
731 throw ProcessError(
"Failed to load \"" + pyFile +
"\"!");
739 std::map<int, TraCIServer::SocketInfo*>::iterator
741 #ifdef DEBUG_MULTI_CLIENTS 773 if (commandLength == 0) {
782 int commandStart, commandLength;
784 #ifdef DEBUG_MULTI_CLIENTS 785 std::cout <<
" dispatchCommand() called for client " <<
myCurrentSocket->second->socket
786 <<
", commandId = " << commandId << std::endl;
788 bool success =
false;
798 std::vector<std::string> args;
802 #ifdef DEBUG_MULTI_CLIENTS 803 std::cout <<
" commandId == CMD_LOAD" 804 <<
", args = " <<
toString(args) << std::endl;
840 #ifdef DEBUG_MULTI_CLIENTS 841 std::cout <<
" commandId == CMD_SIMSTEP" 842 <<
", next target time for client is " <<
myCurrentSocket->second->targetTime << std::endl;
864 #ifdef DEBUG_MULTI_CLIENTS 865 std::cout <<
" commandId == CMD_SETORDER" 866 <<
", order index is " << order << std::endl;
931 std::ostringstream msg;
932 msg <<
"Wrong position in requestMessage after dispatching command.";
933 msg <<
" Expected command length was " << commandLength;
949 answerTmp.
writeString(std::string(
"SUMO ") + sumoVersion);
965 #ifdef DEBUG_MULTI_CLIENTS 966 std::cout <<
" postProcessSimulationStep() at time " << t << std::endl;
975 if ((s.
endTime < t) || isArrivedVehicle || isArrivedPerson) {
986 #ifdef DEBUG_SUBSCRIPTIONS 988 <<
"\n Nr. of active subscriptions = " << noActive << std::endl;
991 #ifdef DEBUG_SUBSCRIPTIONS 1003 #ifdef DEBUG_SUBSCRIPTIONS 1004 std::cout <<
" Size of into-store for subscription " << s.
id 1005 <<
": " << into.
size() << std::endl;
1015 #ifdef DEBUG_SUBSCRIPTIONS 1023 #ifdef DEBUG_MULTI_CLIENTS 1024 std::cout <<
" Sending cached simstep response to current client " <<
myCurrentSocket->second->socket
1025 <<
" (-> intermediate TraCI step)." 1051 WRITE_ERROR(
"Answered with error to command " +
toHex(commandId, 2) +
": " + description);
1053 WRITE_ERROR(
"Requested command not implemented (" +
toHex(commandId, 2) +
"): " + description);
1055 outputStorage.
writeUnsignedByte(1 + 1 + 1 + 4 + static_cast<int>(description.length()));
1078 bool needNewSubscription =
true;
1083 std::vector<std::vector<unsigned char> >::const_iterator k = s.
parameters.begin();
1084 for (std::vector<int>::const_iterator j = s.
variables.begin(); j != s.
variables.end(); ++j, ++k) {
1085 const int offset = (int)(std::find(o.variables.begin(), o.variables.end(), *j) - o.variables.begin());
1086 if (offset == (
int)o.variables.size() || o.parameters[offset] != *k) {
1087 o.variables.push_back(*j);
1088 o.parameters.push_back(*k);
1091 needNewSubscription =
false;
1092 modifiedSubscription = &o;
1096 if (needNewSubscription) {
1097 mySubscriptions.push_back(s);
1098 modifiedSubscription = &mySubscriptions.back();
1132 std::vector<libsumo::Subscription>::iterator j;
1134 if (j->id ==
id && j->commandId == commandId && (domain < 0 || j->contextDomain == domain)) {
1161 std::string& errors) {
1165 std::set<std::string> objIDs;
1171 objIDs.insert(s.
id);
1175 for (std::set<std::string>::iterator j = objIDs.begin(); j != objIDs.end(); ++j) {
1184 std::vector<std::vector<unsigned char> >::const_iterator k = s.
parameters.begin();
1185 for (std::vector<int>::const_iterator i = s.
variables.begin(); i != s.
variables.end(); ++i, ++k) {
1192 ok &=
myExecutors[getCommandId](*
this, message, tmpOutput);
1200 while (--length > 0) {
1203 int lengthLength = 1;
1215 length -= (lengthLength + 1 + 4 + (int)
id.length());
1216 while (--length > 0) {
1231 errors = errors + msg;
1236 int length = (1 + 4) + 1 + (4 + (
int)(s.
id.length())) + 1 + (int)outputStorage.
size();
1249 writeInto.
writeInt((
int)objIDs.size() - skipped);
1268 std::vector<int> variables;
1269 std::vector<std::vector<unsigned char> > parameters;
1270 for (
int i = 0; i < num; ++i) {
1272 variables.push_back(varID);
1273 parameters.push_back(std::vector<unsigned char>());
1279 if (variables.size() == 0) {
1293 bool success =
true;
1298 switch (filterType) {
1306 std::vector<int> lanes;
1307 for (
int i = 0; i < nrLanes; ++i) {
1363 std::cout <<
"Removing filters" << std::endl;
1371 std::cout <<
"Adding lane filter (lanes=" <<
toString(lanes) <<
")" << std::endl;
1380 std::cout <<
"Adding no opposite filter" << std::endl;
1388 std::cout <<
"Adding downstream dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1397 std::cout <<
"Adding upstream dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1406 std::cout <<
"Adding CF-maneuver filter" << std::endl;
1414 std::cout <<
"Adding LC-maneuver filter" << std::endl;
1422 std::cout <<
"Adding turn-maneuver filter" << std::endl;
1430 std::cout <<
"Adding vClass filter (vClasses=" <<
toString(vClasses) <<
")" << std::endl;
1439 std::cout <<
"Adding vType filter (vTypes=" <<
toString(vTypes) <<
")" << std::endl;
1448 if (tempMsg.
size() < 254) {
1462 into = inputStorage.
readInt();
1550 for (
int i = 0; i < noEntries; ++i) {
1563 s.second->targetTime = targetTime;
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa3: Get Lane Variable)
The vehicle has departed (was inserted into the network)
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
void addSubscriptionFilterDownstreamDistance(double dist)
#define CMD_SUBSCRIBE_VEHICLE_CONTEXT
#define CMD_SUBSCRIBE_LANE_VARIABLE
#define FILTER_TYPE_LC_MANEUVER
tcpip::Storage mySubscriptionCache
The last timestep's subscription results.
bool readTypeCheckingColor(tcpip::Storage &inputStorage, libsumo::TraCIColor &into)
Reads the value type and a color, verifying the type.
#define FILTER_TYPE_VCLASS
#define CMD_SUBSCRIBE_LANEAREA_VARIABLE
Representation of a subscription.
double range
The range of the context.
#define CMD_GET_TL_VARIABLE
#define CMD_SUBSCRIBE_JUNCTION_CONTEXT
StorageType::const_iterator end() const
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc3: Change Lane State)
bool wrapString(const std::string &objID, const int variable, const std::string &value)
#define CMD_GET_VEHICLE_VARIABLE
bool processSingleSubscription(const libsumo::Subscription &s, tcpip::Storage &writeInto, std::string &errors)
virtual ~TraCIServer()
Destructor.
#define CMD_SUBSCRIBE_SIM_CONTEXT
#define FILTER_TYPE_CF_MANEUVER
bool commandGetVersion()
Returns the TraCI-version.
#define CMD_SUBSCRIBE_VEHICLETYPE_CONTEXT
virtual std::vector< std::string > readStringList()
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc4: Change Vehicle State)
void addSubscriptionFilterVType(std::vector< std::string > vTypes)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc7: Change PoI State)
#define CMD_GET_INDUCTIONLOOP_VARIABLE
#define CMD_SUBSCRIBE_INDUCTIONLOOP_VARIABLE
bool wrapInt(const std::string &objID, const int variable, const int value)
void addSubscriptionFilterTurnManeuver()
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa9: Get Junction Variable)
#define CMD_GET_LANEAREA_VARIABLE
#define CMD_GET_PERSON_VARIABLE
virtual double readDouble()
tcpip::Storage myOutputStorage
The storage to write to.
#define FILTER_TYPE_TURN_MANEUVER
void initialiseSubscription(libsumo::Subscription &s)
void postProcessSimulationStep()
Handles subscriptions to send after a simstep2 command.
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc2: Change Traffic Lights State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xab: Get Simulation Variable)
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).
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change Route State)
std::vector< std::string > myLoadArgs
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
#define CMD_SUBSCRIBE_POLYGON_CONTEXT
tcpip::Storage myInputStorage
The storage to read from.
SUMOTime beginTime
The begin time of the subscription.
#define CMD_GET_POLYGON_VARIABLE
virtual void writePacket(unsigned char *packet, int length)
#define CMD_SUBSCRIBE_JUNCTION_VARIABLE
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 cleanup()
clean up subscriptions
#define CMD_SUBSCRIBE_ROUTE_CONTEXT
bool readTypeCheckingPolygon(tcpip::Storage &inputStorage, PositionVector &into)
Reads the value type and a polygon, verifying the type.
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xca: Change Edge State)
virtual void writeUnsignedByte(int)
#define CMD_SET_EDGE_VARIABLE
#define CMD_SET_GUI_VARIABLE
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
#define CMD_SUBSCRIBE_EDGE_VARIABLE
virtual unsigned char readChar()
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
#define CMD_GET_ROUTE_VARIABLE
#define CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT
virtual void writeInt(int)
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
virtual int readUnsignedByte()
SUMOTime endTime
The end time of the subscription.
virtual void writeChar(unsigned char)
#define CMD_SUBSCRIBE_POI_VARIABLE
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa4: Get Vehicle Variable)
std::string id
The id of the object that is subscribed.
static bool myDoCloseConnection
Whether the connection was set to be to close.
std::map< int, SocketInfo * >::iterator removeCurrentSocket()
removes myCurrentSocket from mySockets and returns an iterator pointing to the next member according ...
void addSubscriptionFilterVClass(SVCPermissions vClasses)
The vehicles starts to stop.
std::map< int, CmdExecutor > myExecutors
Map of commandIds -> their executors; applicable if the executor applies to the method footprint...
#define CMD_SET_TL_VARIABLE
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get AreaDetector Variable)
int commandId
commandIdArg The command id of the subscription
#define CMD_SUBSCRIBE_LANE_CONTEXT
#define CMD_SUBSCRIBE_SIM_VARIABLE
void removeSubscription(int commandId, const std::string &identity, int domain)
#define CMD_GET_VEHICLETYPE_VARIABLE
int activeFilters
Active filters for the subscription (bitset,.
static void close()
request termination of connection
bool addObjectVariableSubscription(const int commandId, const bool hasContext)
#define CMD_SET_ROUTE_VARIABLE
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xcb: Set Simulation Variable)
#define CMD_SUBSCRIBE_GUI_CONTEXT
#define FILTER_TYPE_UPSTREAM_DIST
The vehicle got a new route.
The vehicle arrived at his destination (is deleted)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
The vehicles starts to park.
The vehicle is involved in a collision.
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xce: Change Person State)
#define FILTER_TYPE_LANES
void addSubscriptionFilterCFManeuver()
Representation of a vehicle.
int contextDomain
The domain ID of the context.
void addSubscriptionFilterNoOpposite()
double filterDownstreamDist
Downstream distance specified by the downstream distance filter.
The vehicle had to brake harder than permitted.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
A point in 2D or 3D with translation and scaling methods.
#define CMD_GET_POI_VARIABLE
int filterVClasses
vClasses specified by the vClasses filter,
#define CMD_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE
void addSubscriptionFilterLCManeuver()
#define CMD_SUBSCRIBE_MULTIENTRYEXIT_CONTEXT
#define CMD_SET_VEHICLETYPE_VARIABLE
virtual void writeByte(int)
bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
virtual void writeStringList(const std::vector< std::string > &s)
#define CMD_SUBSCRIBE_GUI_VARIABLE
#define CMD_GET_LANE_VARIABLE
#define CMD_SUBSCRIBE_LANEAREA_CONTEXT
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
#define FILTER_TYPE_NOOPPOSITE
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa5: Get Vehicle Type Variable)
#define CMD_SET_VEHICLE_VARIABLE
SUMOTime string2time(const std::string &r)
void addSubscriptionFilterUpstreamDistance(double dist)
bool addSubscriptionFilter()
The vehicle started to teleport.
tcpip::Storage & getWrapperStorage()
#define CMD_GET_SIM_VARIABLE
virtual std::string readString()
#define CMD_GET_EDGE_VARIABLE
libsumo::Subscription * myLastContextSubscription
The last modified context subscription (the one to add a filter to, see (), currently only for vehicl...
virtual unsigned int position() const
#define CMD_GET_GUI_VARIABLE
bool isVehicleToVehicleContextSubscription(const libsumo::Subscription &s)
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
#define CMD_SET_POI_VARIABLE
int readCommandID(int &commandStart, int &commandLength)
Reads the next command ID from the input storage.
#define CMD_SUBSCRIBE_POLYGON_VARIABLE
static TraCIServer * myInstance
Singleton instance of the server.
#define CMD_SUBSCRIBE_TL_CONTEXT
The vehicle ends to park.
#define CMD_SUBSCRIBE_EDGE_CONTEXT
#define FILTER_TYPE_VTYPE
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa0: Get Induction Loop Variable)
#define CMD_GET_JUNCTION_VARIABLE
Socket * accept(const bool create=false)
Wait for a incoming connection to port_.
#define CMD_SUBSCRIBE_PERSON_VARIABLE
bool readTypeCheckingUnsignedByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and an unsigned byte, verifying the type.
TraCI server used to control sumo by a remote TraCI client.
void sendOutputToAll() const
send out subscription results (actually just the content of myOutputStorage) to clients which will ac...
TraCIServer(const SUMOTime begin, const int port, const int numClients)
Constructor.
virtual void writeStorage(tcpip::Storage &store)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xae: Get Person Variable)
void sendSingleSimStepResponse()
sends an empty response to a simstep command to the current client. (This applies to a situation wher...
#define CMD_SET_SIM_VARIABLE
double filterUpstreamDist
Upstream distance specified by the upstream distance filter.
std::vector< std::vector< unsigned char > > parameters
The parameters for the subscribed variables.
StorageType::size_type size() const
#define INVALID_DOUBLE_VALUE
#define CMD_SUBSCRIBE_VEHICLETYPE_VARIABLE
bool wrapColor(const std::string &objID, const int variable, const libsumo::TraCIColor &value)
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
#define FILTER_TYPE_DOWNSTREAM_DIST
VehicleState
Definition of a vehicle state.
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa7: Get PoI Variable)
const bool myAmEmbedded
Whether the server runs in embedded mode.
The vehicle was built, but has not yet departed.
void processCommandsUntilSimStep(SUMOTime step)
process all commands until the next SUMO simulation step. It is guaranteed that t->getTargetTime() >=...
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 0xc5: Change Vehicle Type State)
void processReorderingRequests()
checks for and processes reordering requests (relevant for multiple clients)
#define CMD_SET_POLYGON_VARIABLE
static void openSocket(const std::map< int, CmdExecutor > &execs)
Initialises the server.
virtual void writeString(const std::string &s)
#define RTYPE_NOTIMPLEMENTED
#define CMD_ADD_SUBSCRIPTION_FILTER
std::string toHex(const T i, std::streamsize numDigits=0)
#define CMD_SUBSCRIBE_VEHICLE_VARIABLE
bool wrapPosition(const std::string &objID, const int variable, const libsumo::TraCIPosition &value)
#define CMD_SUBSCRIBE_PERSON_CONTEXT
static void collectObjectsInRange(int domain, const PositionVector &shape, double range, std::set< std::string > &into)
std::map< int, SocketInfo * >::iterator myCurrentSocket
The currently active client socket.
std::vector< int > variables
The subscribed variables.
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
SUMOTime nextTargetTime() const
get the minimal next target time among all clients
StorageType::const_iterator begin() const
#define CMD_SET_LANE_VARIABLE
void setTargetTime(SUMOTime targetTime)
Sets myTargetTime on server and sockets to the given value.
#define CMD_GET_MULTIENTRYEXIT_VARIABLE
void inform(std::string msg, bool addType=true)
adds a new error to the list
SUMOTime myTargetTime
The time step to reach until processing the next commands.
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get Route Variable)
std::vector< libsumo::Subscription > mySubscriptions
The list of known, still valid subscriptions.
The vehicle ends to stop.
bool readTypeCheckingPosition2D(tcpip::Storage &inputStorage, libsumo::TraCIPosition &into)
Reads the value type and a 2D position, verifying the type.
virtual void writeDouble(double)
MSTransportable * get(const std::string &id) const
Returns the named transportable, if existing.
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get MeMeDetector Variable)
void addSubscriptionFilterLanes(std::vector< int > lanes)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa8: Get Polygon Variable)
int dispatchCommand()
Handles command, writes response to myOutputStorage.
#define CMD_SUBSCRIBE_TL_VARIABLE
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 writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
std::map< int, SocketInfo * > mySocketReorderRequests
This stores the setOrder(int) requests of the clients.
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
void initWrapper(const int domainID, const int variable, const std::string &objID)
#define CMD_SET_PERSON_VARIABLE
static void findObjectShape(int domain, const std::string &id, PositionVector &shape)
void simulationStep()
Performs a single simulation step.
#define WRITE_MESSAGE(msg)
std::vector< std::string > filterVTypes
vTypes specified by the vTypes filter
#define CMD_SUBSCRIBE_POI_CONTEXT
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xaa: Get Edge Variable)
static bool wasClosed()
check whether close was requested
std::map< MSNet::VehicleState, std::vector< std::string > > myVehicleStateChanges
Changes in the states of simulated vehicles.
The vehicle ended being teleported.
virtual const std::string & getID() const =0
Get the vehicle's ID.
bool readTypeCheckingByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and a byte, verifying the type.
bool wrapDouble(const std::string &objID, const int variable, const double value)
tcpip::Socket * myServerSocket
The server socket.
#define CMD_SUBSCRIBE_ROUTE_VARIABLE
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
std::map< int, int > myParameterSizes
Map of variable ids to the size of the parameter in bytes.
void checkClientOrdering()
Called once after connection of all clients for executing SET_ORDER (and possibly prior GET_VERSION) ...