179 #ifdef DEBUG_MULTI_CLIENTS 180 std::cout <<
"Creating new TraCIServer for " << numClients <<
" clients on port " << port <<
"." << std::endl;
227 WRITE_WARNING(
"Starting TraCI without using internal lanes!");
236 while ((
int)
mySockets.size() < numClients) {
253 if (numClients > 1) {
285 for (std::map<int, CmdExecutor>::const_iterator i = execs.begin(); i != execs.end(); ++i) {
322 for (std::map<int, SocketInfo*>::iterator i =
mySockets.begin(); i !=
mySockets.end(); ++i) {
323 i->second->vehicleStateChanges[to].push_back(vehicle->
getID());
332 #ifdef DEBUG_MULTI_CLIENTS 333 std::cout <<
"Checking client order requests." << std::endl;
339 #ifdef DEBUG_MULTI_CLIENTS 340 std::cout <<
" Socket " <<
myCurrentSocket->second->socket <<
":" << std::endl;
344 #pragma warning(push) 345 #pragma warning(disable: 4127) // do not warn about constant conditional expression 353 int commandStart, commandLength;
355 #ifdef DEBUG_MULTI_CLIENTS 356 std::cout <<
" received command " << commandId << std::endl;
362 #ifdef DEBUG_MULTI_CLIENTS 363 std::cout <<
" Init command. Sending response." << std::endl;
380 #ifdef DEBUG_MULTI_CLIENTS 381 std::cout <<
" Client " <<
myCurrentSocket->second->socket <<
" did not set order initially." << std::endl;
383 throw ProcessError(
"Execution order (CMD_SETORDER) was not set for all TraCI clients in pre-execution phase.");
401 std::map<int, SocketInfo*>::iterator j;
402 #ifdef DEBUG_MULTI_CLIENTS 403 std::cout <<
SIMTIME <<
" Current socket ordering:\n";
405 std::cout <<
" " << j->first <<
": " << j->second->socket <<
"\n";
407 std::cout <<
"Reordering requests:\n";
409 std::cout <<
" Socket " << i->second->socket <<
" -> " << i->first <<
"\n";
416 if (j->second->socket == i->second->socket) {
428 #ifdef DEBUG_MULTI_CLIENTS 429 std::cout <<
"New socket ordering:\n";
431 std::cout <<
" " << j->first <<
": " << j->second->socket <<
"\n";
433 std::cout << std::endl;
441 #ifdef DEBUG_MULTI_CLIENTS 442 std::cout <<
"\n Determining new target time..." << std::endl;
444 std::cout <<
" All clients have disconnected." << std::endl;
447 std::map<int, SocketInfo*>::const_iterator i;
448 SUMOTime targetTime = std::numeric_limits<SUMOTime>::max();
450 #ifdef DEBUG_MULTI_CLIENTS 451 std::cout <<
" target time for client " << i->second->socket <<
": " << i->second->targetTime <<
"\n";
453 targetTime =
MIN2(targetTime, i->second->targetTime);
455 #ifdef DEBUG_MULTI_CLIENTS 456 std::cout << std::endl;
465 #ifdef DEBUG_MULTI_CLIENTS 466 std::cout <<
"\n Sending subscription results to clients:\n";
468 std::map<int, SocketInfo*>::const_iterator i =
mySockets.begin();
473 #ifdef DEBUG_MULTI_CLIENTS 474 std::cout << i->second->socket <<
"\n";
479 #ifdef DEBUG_MULTI_CLIENTS 480 std::cout << std::endl;
487 #ifdef DEBUG_MULTI_CLIENTS 488 std::cout <<
SIMTIME <<
" processCommandsUntilSimStep(step = " << step <<
"):\n" << std::endl;
507 #ifdef DEBUG_MULTI_CLIENTS 509 std::cout <<
" next target time is larger than next SUMO simstep (" << step <<
"). Returning from processCommandsUntilSimStep()." << std::endl;
521 #ifdef DEBUG_MULTI_CLIENTS 522 std::cout <<
" Next target time: " <<
myTargetTime << std::endl;
527 #ifdef DEBUG_MULTI_CLIENTS 535 #ifdef DEBUG_MULTI_CLIENTS 537 <<
" with target time " <<
myCurrentSocket->second->targetTime << std::endl;
545 while (!done && !closed && !load) {
549 #ifdef DEBUG_MULTI_CLIENTS 550 std::cout <<
" sending response..." << std::endl;
556 #ifdef DEBUG_MULTI_CLIENTS 557 std::cout <<
" No input and no output stored (This is the next client)." << std::endl;
560 #ifdef DEBUG_MULTI_CLIENTS 561 std::cout <<
" resetting input storage and reading next command..." << std::endl;
571 #ifdef DEBUG_MULTI_CLIENTS 572 std::cout <<
" Received command " << cmd << std::endl;
575 #ifdef DEBUG_MULTI_CLIENTS 576 std::cout <<
" Received command SIM_STEP, end turn for client " <<
myCurrentSocket->second->socket << std::endl;
580 #ifdef DEBUG_MULTI_CLIENTS 581 std::cout <<
" Received command LOAD." << std::endl;
585 #ifdef DEBUG_MULTI_CLIENTS 586 std::cout <<
" Received command CLOSE." << std::endl;
609 #ifdef DEBUG_MULTI_CLIENTS 610 std::cout <<
" Breaking loop to load new simulation." << std::endl;
614 #ifdef DEBUG_MULTI_CLIENTS 615 std::cout <<
" Breaking loop because last client closed connection." << std::endl;
633 }
catch (std::invalid_argument& e) {
653 std::map<MSNet::VehicleState, std::vector<std::string> >::iterator i;
666 traciemb_execute(PyObject* , PyObject* args) {
669 if (!PyArg_ParseTuple(args,
"s#", &msg, &size)) {
672 std::string result = TraCIServer::execute(std::string(msg, size));
673 return Py_BuildValue(
"s#", result.c_str(), result.size());
676 static PyMethodDef EmbMethods[] = {
678 "execute", traciemb_execute, METH_VARARGS,
679 "Execute the given TraCI command and return the result." 681 {NULL, NULL, 0, NULL}
686 TraCIServer::execute(std::string cmd) {
691 for (std::string::iterator i = cmd.begin(); i != cmd.end(); ++i) {
696 }
catch (std::invalid_argument& e) {
707 TraCIServer::runEmbedded(std::string pyFile) {
708 PyObject* pName, *pModule;
710 Py_InitModule(
"traciemb", EmbMethods);
711 if (pyFile.length() > 3 && !pyFile.compare(pyFile.length() - 3, 3,
".py")) {
712 PyObject* sys_path, *path;
713 char pathstr[] =
"path";
714 sys_path = PySys_GetObject(pathstr);
715 if (sys_path == NULL || !PyList_Check(sys_path)) {
716 throw ProcessError(
"Could not access python sys.path!");
719 PyList_Insert(sys_path, 0, path);
721 FILE* pFile = fopen(pyFile.c_str(),
"r");
723 throw ProcessError(
"Failed to load \"" + pyFile +
"\"!");
725 PyRun_SimpleFile(pFile, pyFile.c_str());
728 pName = PyString_FromString(pyFile.c_str());
730 pModule = PyImport_Import(pName);
732 if (pModule == NULL) {
734 throw ProcessError(
"Failed to load \"" + pyFile +
"\"!");
742 std::map<int, TraCIServer::SocketInfo*>::iterator
744 #ifdef DEBUG_MULTI_CLIENTS 776 if (commandLength == 0) {
785 int commandStart, commandLength;
787 #ifdef DEBUG_MULTI_CLIENTS 788 std::cout <<
" dispatchCommand() called for client " <<
myCurrentSocket->second->socket
789 <<
", commandId = " << commandId << std::endl;
791 bool success =
false;
801 std::vector<std::string> args;
805 #ifdef DEBUG_MULTI_CLIENTS 806 std::cout <<
" commandId == CMD_LOAD" 807 <<
", args = " <<
toString(args) << std::endl;
843 #ifdef DEBUG_MULTI_CLIENTS 844 std::cout <<
" commandId == CMD_SIMSTEP" 845 <<
", next target time for client is " <<
myCurrentSocket->second->targetTime << std::endl;
867 #ifdef DEBUG_MULTI_CLIENTS 868 std::cout <<
" commandId == CMD_SETORDER" 869 <<
", order index is " << order << std::endl;
934 std::ostringstream msg;
935 msg <<
"Wrong position in requestMessage after dispatching command.";
936 msg <<
" Expected command length was " << commandLength;
952 answerTmp.
writeString(std::string(
"SUMO ") + sumoVersion);
968 #ifdef DEBUG_MULTI_CLIENTS 969 std::cout <<
" postProcessSimulationStep() at time " << t << std::endl;
978 if ((s.
endTime < t) || isArrivedVehicle || isArrivedPerson) {
989 #ifdef DEBUG_SUBSCRIPTIONS 991 <<
"\n Nr. of active subscriptions = " << noActive << std::endl;
994 #ifdef DEBUG_SUBSCRIPTIONS 1006 #ifdef DEBUG_SUBSCRIPTIONS 1007 std::cout <<
" Size of into-store for subscription " << s.
id 1008 <<
": " << into.
size() << std::endl;
1018 #ifdef DEBUG_SUBSCRIPTIONS 1026 #ifdef DEBUG_MULTI_CLIENTS 1027 std::cout <<
" Sending cached simstep response to current client " <<
myCurrentSocket->second->socket
1028 <<
" (-> intermediate TraCI step)." 1054 WRITE_ERROR(
"Answered with error to command " +
toHex(commandId, 2) +
": " + description);
1056 WRITE_ERROR(
"Requested command not implemented (" +
toHex(commandId, 2) +
"): " + description);
1058 outputStorage.
writeUnsignedByte(1 + 1 + 1 + 4 + static_cast<int>(description.length()));
1081 bool needNewSubscription =
true;
1086 std::vector<std::vector<unsigned char> >::const_iterator k = s.
parameters.begin();
1087 for (std::vector<int>::const_iterator j = s.
variables.begin(); j != s.
variables.end(); ++j, ++k) {
1088 const int offset = (int)(std::find(o.variables.begin(), o.variables.end(), *j) - o.variables.begin());
1089 if (offset == (
int)o.variables.size() || o.parameters[offset] != *k) {
1090 o.variables.push_back(*j);
1091 o.parameters.push_back(*k);
1094 needNewSubscription =
false;
1095 modifiedSubscription = &o;
1099 if (needNewSubscription) {
1100 mySubscriptions.push_back(s);
1101 modifiedSubscription = &mySubscriptions.back();
1135 std::vector<libsumo::Subscription>::iterator j;
1137 if (j->id ==
id && j->commandId == commandId && (domain < 0 || j->contextDomain == domain)) {
1164 std::string& errors) {
1168 std::set<std::string> objIDs;
1177 objIDs.insert(s.
id);
1181 for (std::set<std::string>::iterator j = objIDs.begin(); j != objIDs.end(); ++j) {
1190 std::vector<std::vector<unsigned char> >::const_iterator k = s.
parameters.begin();
1191 for (std::vector<int>::const_iterator i = s.
variables.begin(); i != s.
variables.end(); ++i, ++k) {
1198 ok &=
myExecutors[getCommandId](*
this, message, tmpOutput);
1206 while (--length > 0) {
1209 int lengthLength = 1;
1221 length -= (lengthLength + 1 + 4 + (int)
id.length());
1222 while (--length > 0) {
1237 errors = errors + msg;
1242 int length = (1 + 4) + 1 + (4 + (
int)(s.
id.length())) + 1 + (int)outputStorage.
size();
1255 writeInto.
writeInt((
int)objIDs.size() - skipped);
1274 std::vector<int> variables;
1275 std::vector<std::vector<unsigned char> > parameters;
1276 for (
int i = 0; i < num; ++i) {
1278 variables.push_back(varID);
1279 parameters.push_back(std::vector<unsigned char>());
1285 if (variables.size() == 0) {
1299 bool success =
true;
1301 WRITE_WARNING(
"addSubscriptionFilter: No previous vehicle context subscription exists to apply the context filter.");
1308 switch (filterType) {
1316 std::vector<int> lanes;
1317 for (
int i = 0; i < nrLanes; ++i) {
1356 std::set<std::string> vTypesSet;
1357 vTypesSet.insert(vTypesVector.begin(), vTypesVector.end());
1377 #ifdef DEBUG_SUBSCRIPTION_FILTERS 1378 std::cout <<
"Removing filters" << std::endl;
1385 #ifdef DEBUG_SUBSCRIPTION_FILTERS 1386 std::cout <<
"Adding lane filter (lanes=" <<
toString(lanes) <<
")" << std::endl;
1394 #ifdef DEBUG_SUBSCRIPTION_FILTERS 1395 std::cout <<
"Adding no opposite filter" << std::endl;
1402 #ifdef DEBUG_SUBSCRIPTION_FILTERS 1403 std::cout <<
"Adding downstream dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1411 #ifdef DEBUG_SUBSCRIPTION_FILTERS 1412 std::cout <<
"Adding upstream dist filter (dist=" <<
toString(dist) <<
")" << std::endl;
1420 #ifdef DEBUG_SUBSCRIPTION_FILTERS 1421 std::cout <<
"Adding Lead/Follow-maneuver filter" << std::endl;
1428 #ifdef DEBUG_SUBSCRIPTION_FILTERS 1429 std::cout <<
"Adding turn-maneuver filter" << std::endl;
1436 #ifdef DEBUG_SUBSCRIPTION_FILTERS 1437 std::cout <<
"Adding vClass filter (vClasses=" <<
toString(vClasses) <<
")" << std::endl;
1445 #ifdef DEBUG_SUBSCRIPTION_FILTERS 1446 std::cout <<
"Adding vType filter (vTypes=" <<
toString(vTypes) <<
")" << std::endl;
1454 if (tempMsg.
size() < 254) {
1467 if (shape.size() < 256) {
1471 outputStorage.
writeInt((
int)shape.size());
1485 into = inputStorage.
readInt();
1573 size = inputStorage.
readInt();
1576 for (
int i = 0; i < size; ++i) {
1579 if (std::isnan(x) || std::isnan(y)) {
1592 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
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.
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...
#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
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)
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)
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.
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
#define INVALID_DOUBLE_VALUE
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
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
#define CMD_SUBSCRIBE_MULTIENTRYEXIT_CONTEXT
#define FILTER_TYPE_LEAD_FOLLOW
#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
void addSubscriptionFilterTurn()
#define CMD_GET_GUI_VARIABLE
void addSubscriptionFilterLeadFollow()
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
std::set< std::string > filterVTypes
vTypes specified by the vTypes filter
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 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.
void writePositionVector(tcpip::Storage &outputStorage, const libsumo::TraCIPositionVector &shape)
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)
std::vector< TraCIPosition > TraCIPositionVector
#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)
#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)
void addSubscriptionFilterVType(std::set< std::string > vTypes)
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) ...