SUMO - Simulation of Urban MObility
TraCIServer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
17 /****************************************************************************/
18 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
19 // Copyright (C) 2007-2017 DLR (http://www.dlr.de/) and contributors
20 /****************************************************************************/
21 //
22 // This file is part of SUMO.
23 // SUMO is free software: you can redistribute it and/or modify
24 // it under the terms of the GNU General Public License as published by
25 // the Free Software Foundation, either version 3 of the License, or
26 // (at your option) any later version.
27 //
28 /****************************************************************************/
29 
30 // ===========================================================================
31 // included modules
32 // ===========================================================================
33 #ifdef _MSC_VER
34 #include <windows_config.h>
35 #else
36 #include <config.h>
37 #endif
38 
39 #ifdef HAVE_VERSION_H
40 #include <version.h>
41 #endif
42 
43 #ifndef NO_TRACI
44 
45 #ifdef HAVE_PYTHON
46 #include <Python.h>
47 #endif
48 
49 #include <string>
50 #include <map>
51 #include <iostream>
52 #include <algorithm>
53 #include <foreign/tcpip/socket.h>
54 #include <foreign/tcpip/storage.h>
55 #include <utils/common/SUMOTime.h>
63 #include <utils/shapes/Polygon.h>
64 #include <utils/xml/XMLSubSys.h>
65 #include <microsim/MSNet.h>
67 #include <microsim/MSVehicle.h>
68 #include <microsim/MSEdge.h>
70 #include <microsim/MSJunction.h>
71 #include <microsim/MSEdgeControl.h>
72 #include <microsim/MSLane.h>
73 #include <microsim/MSGlobals.h>
75 #include "lib/TraCI.h"
76 #include "TraCIConstants.h"
77 #include "TraCIServer.h"
80 #include "TraCIServerAPI_Lane.h"
83 #include "TraCIServerAPI_TLS.h"
84 #include "TraCIServerAPI_Vehicle.h"
86 #include "TraCIServerAPI_Route.h"
87 #include "TraCIServerAPI_POI.h"
88 #include "TraCIServerAPI_Polygon.h"
89 #include "TraCIServerAPI_Edge.h"
91 #include "TraCIServerAPI_Person.h"
92 
93 
94 // ===========================================================================
95 // static member definitions
96 // ===========================================================================
99 
100 
101 // ===========================================================================
102 // method definitions
103 // ===========================================================================
104 TraCIServer::TraCIServer(const SUMOTime begin, const int port)
105  : mySocket(0), myTargetTime(begin), myDoingSimStep(false), myAmEmbedded(port == 0), myLaneTree(0) {
106 
107  myVehicleStateChanges[MSNet::VEHICLE_STATE_BUILT] = std::vector<std::string>();
108  myVehicleStateChanges[MSNet::VEHICLE_STATE_DEPARTED] = std::vector<std::string>();
109  myVehicleStateChanges[MSNet::VEHICLE_STATE_STARTING_TELEPORT] = std::vector<std::string>();
110  myVehicleStateChanges[MSNet::VEHICLE_STATE_ENDING_TELEPORT] = std::vector<std::string>();
111  myVehicleStateChanges[MSNet::VEHICLE_STATE_ARRIVED] = std::vector<std::string>();
112  myVehicleStateChanges[MSNet::VEHICLE_STATE_NEWROUTE] = std::vector<std::string>();
113  myVehicleStateChanges[MSNet::VEHICLE_STATE_STARTING_PARKING] = std::vector<std::string>();
114  myVehicleStateChanges[MSNet::VEHICLE_STATE_ENDING_PARKING] = std::vector<std::string>();
115  myVehicleStateChanges[MSNet::VEHICLE_STATE_STARTING_STOP] = std::vector<std::string>();
116  myVehicleStateChanges[MSNet::VEHICLE_STATE_ENDING_STOP] = std::vector<std::string>();
118 
122 
144 
146 
147  myDoCloseConnection = false;
148 
149  // display warning if internal lanes are not used
151  WRITE_WARNING("Starting TraCI without using internal lanes!");
152  MsgHandler::getWarningInstance()->inform("Vehicles will jump over junctions.", false);
153  MsgHandler::getWarningInstance()->inform("Use without option --no-internal-links to avoid unexpected behavior", false);
154  }
155 
156  if (!myAmEmbedded) {
157  try {
158  WRITE_MESSAGE("***Starting server on port " + toString(port) + " ***");
159  mySocket = new tcpip::Socket(port);
160  mySocket->accept();
161  // When got here, a client has connected
162  } catch (tcpip::SocketException& e) {
163  throw ProcessError(e.what());
164  }
165  }
166 }
167 
168 
170  if (mySocket != NULL) {
171  mySocket->close();
172  delete mySocket;
173  }
174  cleanup();
175 }
176 
177 
178 // ---------- Initialisation and Shutdown
179 void
180 TraCIServer::openSocket(const std::map<int, CmdExecutor>& execs) {
181  if (myInstance != 0) {
182  return;
183  }
184  if (!myDoCloseConnection && OptionsCont::getOptions().getInt("remote-port") != 0) {
185  myInstance = new TraCIServer(string2time(OptionsCont::getOptions().getString("begin")),
186  OptionsCont::getOptions().getInt("remote-port"));
187  for (std::map<int, CmdExecutor>::const_iterator i = execs.begin(); i != execs.end(); ++i) {
188  myInstance->myExecutors[i->first] = i->second;
189  }
190  }
191 }
192 
193 
194 void
196  if (myInstance == 0) {
197  return;
198  }
199  if (myDoCloseConnection) {
202  }
203  delete myInstance;
204  myInstance = 0;
205  myDoCloseConnection = true;
206 }
207 
208 
209 bool
211  return myDoCloseConnection;
212 }
213 
214 
215 void
216 TraCIServer::setVTDControlled(MSVehicle* v, Position xyPos, MSLane* l, double pos, double posLat, double angle,
217  int edgeOffset, ConstMSEdgeVector route, SUMOTime t) {
218  myVTDControlledVehicles[v->getID()] = v;
219  v->getInfluencer().setVTDControlled(xyPos, l, pos, posLat, angle, edgeOffset, route, t);
220 }
221 
222 
223 void
225  for (std::map<std::string, MSVehicle*>::const_iterator i = myVTDControlledVehicles.begin(); i != myVTDControlledVehicles.end(); ++i) {
226  if (MSNet::getInstance()->getVehicleControl().getVehicle((*i).first) != 0) {
227  (*i).second->getInfluencer().postProcessVTD((*i).second);
228  } else {
229  WRITE_WARNING("Vehicle '" + (*i).first + "' was removed though being controlled by VTD");
230  }
231  }
232  myVTDControlledVehicles.clear();
233 }
234 
235 
236 // ---------- Initialisation and Shutdown
237 
238 
239 void
241  if (!myDoCloseConnection) {
242  myVehicleStateChanges[to].push_back(vehicle->getID());
243  }
244 }
245 
246 
247 void
249  if (myInstance == 0) {
250  return;
251  }
252  try {
253  if (myInstance->myAmEmbedded || step < myInstance->myTargetTime) {
254  return;
255  }
256  // Simulation should run until
257  // 1. end time reached or
258  // 2. got CMD_CLOSE or
259  // 3. got CMD_LOAD or
260  // 4. Client closes socket connection
261  if (myInstance->myDoingSimStep) {
263  myInstance->myDoingSimStep = false;
264  }
265  while (!myDoCloseConnection) {
267  if (myInstance->myOutputStorage.size() > 0) {
268  // send out all answers as one storage
270  }
273  // Read a message
275  }
277  // dispatch each command
278  int cmd = myInstance->dispatchCommand();
279  if (cmd == CMD_SIMSTEP) {
280  myInstance->myDoingSimStep = true;
281  for (std::map<MSNet::VehicleState, std::vector<std::string> >::iterator i = myInstance->myVehicleStateChanges.begin(); i != myInstance->myVehicleStateChanges.end(); ++i) {
282  (*i).second.clear();
283  }
284  return;
285  }
286  if (cmd == CMD_LOAD) {
287  return;
288  }
289  }
290  }
292  // send out all answers as one storage
294  }
295  for (std::map<MSNet::VehicleState, std::vector<std::string> >::iterator i = myInstance->myVehicleStateChanges.begin(); i != myInstance->myVehicleStateChanges.end(); ++i) {
296  (*i).second.clear();
297  }
298  } catch (std::invalid_argument& e) {
299  throw ProcessError(e.what());
300  } catch (TraCIException& e) {
301  throw ProcessError(e.what());
302  } catch (tcpip::SocketException& e) {
303  throw ProcessError(e.what());
304  }
305 }
306 
307 
308 void
310  mySubscriptions.clear();
311  for (std::map<int, NamedRTree*>::const_iterator i = myObjects.begin(); i != myObjects.end(); ++i) {
312  delete(*i).second;
313  }
314  myObjects.clear();
315  delete myLaneTree;
316  myLaneTree = 0;
317  myTargetTime = string2time(OptionsCont::getOptions().getString("begin"));
318 }
319 
320 
321 
322 #ifdef HAVE_PYTHON
323 // ===========================================================================
324 // python functions (traciemb module)
325 // ===========================================================================
326 static PyObject*
327 traciemb_execute(PyObject* /* self */, PyObject* args) {
328  const char* msg;
329  int size;
330  if (!PyArg_ParseTuple(args, "s#", &msg, &size)) {
331  return NULL;
332  }
333  std::string result = TraCIServer::execute(std::string(msg, size));
334  return Py_BuildValue("s#", result.c_str(), result.size());
335 }
336 
337 static PyMethodDef EmbMethods[] = {
338  {
339  "execute", traciemb_execute, METH_VARARGS,
340  "Execute the given TraCI command and return the result."
341  },
342  {NULL, NULL, 0, NULL}
343 };
344 
345 
346 std::string
347 TraCIServer::execute(std::string cmd) {
348  try {
349  if (myInstance == 0) {
350  if (!myDoCloseConnection) {
351  myInstance = new TraCIServer(string2time(OptionsCont::getOptions().getString("begin")));
352  } else {
353  return "";
354  }
355  }
358  for (std::string::iterator i = cmd.begin(); i != cmd.end(); ++i) {
360  }
362  return std::string(myInstance->myOutputStorage.begin(), myInstance->myOutputStorage.end());
363  } catch (std::invalid_argument& e) {
364  throw ProcessError(e.what());
365  } catch (TraCIException& e) {
366  throw ProcessError(e.what());
367  } catch (tcpip::SocketException& e) {
368  throw ProcessError(e.what());
369  }
370 }
371 
372 
373 void
374 TraCIServer::runEmbedded(std::string pyFile) {
375  PyObject* pName, *pModule;
376  Py_Initialize();
377  Py_InitModule("traciemb", EmbMethods);
378  if (pyFile.length() > 3 && !pyFile.compare(pyFile.length() - 3, 3, ".py")) {
379  PyObject* sys_path, *path;
380  char pathstr[] = "path";
381  sys_path = PySys_GetObject(pathstr);
382  if (sys_path == NULL || !PyList_Check(sys_path)) {
383  throw ProcessError("Could not access python sys.path!");
384  }
385  path = PyString_FromString(FileHelpers::getFilePath(pyFile).c_str());
386  PyList_Insert(sys_path, 0, path);
387  Py_DECREF(path);
388  FILE* pFile = fopen(pyFile.c_str(), "r");
389  if (pFile == NULL) {
390  throw ProcessError("Failed to load \"" + pyFile + "\"!");
391  }
392  PyRun_SimpleFile(pFile, pyFile.c_str());
393  fclose(pFile);
394  } else {
395  pName = PyString_FromString(pyFile.c_str());
396  /* Error checking of pName left out */
397  pModule = PyImport_Import(pName);
398  Py_DECREF(pName);
399  if (pModule == NULL) {
400  PyErr_Print();
401  throw ProcessError("Failed to load \"" + pyFile + "\"!");
402  }
403  }
404  Py_Finalize();
405 }
406 #endif
407 
408 
409 int
411  int commandStart = myInputStorage.position();
412  int commandLength = myInputStorage.readUnsignedByte();
413  if (commandLength == 0) {
414  commandLength = myInputStorage.readInt();
415  }
416 
417  int commandId = myInputStorage.readUnsignedByte();
418  bool success = false;
419  // dispatch commands
420  if (myExecutors.find(commandId) != myExecutors.end()) {
421  success = myExecutors[commandId](*this, myInputStorage, myOutputStorage);
422  } else {
423  switch (commandId) {
424  case CMD_GETVERSION:
425  success = commandGetVersion();
426  break;
427  case CMD_LOAD: {
428  std::vector<std::string> args;
430  return writeErrorStatusCmd(CMD_LOAD, "A load command needs a list of string arguments.", myOutputStorage);
431  }
432  try {
433  TraCI::load(args);
434  success = true;
436  } catch (TraCIException& e) {
437  return writeErrorStatusCmd(CMD_LOAD, e.what(), myOutputStorage);
438  }
439  break;
440  }
441  case CMD_SIMSTEP: {
442  SUMOTime nextT = myInputStorage.readInt();
443  success = true;
444  if (nextT != 0) {
445  myTargetTime = nextT;
446  } else {
448  }
449  if (myAmEmbedded) {
450  for (std::map<MSNet::VehicleState, std::vector<std::string> >::iterator i = myInstance->myVehicleStateChanges.begin(); i != myInstance->myVehicleStateChanges.end(); ++i) {
451  (*i).second.clear();
452  }
453  while (MSNet::getInstance()->getCurrentTimeStep() < myTargetTime) {
455  }
457  }
458  return commandId;
459  }
460  case CMD_CLOSE:
461  myDoCloseConnection = true;
462  success = true;
463  break;
479  success = addObjectVariableSubscription(commandId, false);
480  break;
496  success = addObjectVariableSubscription(commandId, true);
497  break;
498  default:
499  writeStatusCmd(commandId, RTYPE_NOTIMPLEMENTED, "Command not implemented in sumo");
500  }
501  }
502  if (!success) {
503  while (myInputStorage.valid_pos() && (int)myInputStorage.position() < commandStart + commandLength) {
505  }
506  }
507  if ((int)myInputStorage.position() != commandStart + commandLength) {
508  std::ostringstream msg;
509  msg << "Wrong position in requestMessage after dispatching command.";
510  msg << " Expected command length was " << commandLength;
511  msg << " but " << myInputStorage.position() - commandStart << " Bytes were read.";
512  writeStatusCmd(commandId, RTYPE_ERR, msg.str());
513  myDoCloseConnection = true;
514  }
515  return commandId;
516 }
517 
518 
519 // ---------- Server-internal command handling
520 bool
522  std::string sumoVersion = VERSION_STRING;
523  // Prepare response
524  tcpip::Storage answerTmp;
525  answerTmp.writeInt(TRACI_VERSION);
526  answerTmp.writeString(std::string("SUMO ") + sumoVersion);
527  // When we get here, the response is stored in answerTmp -> put into myOutputStorage
529  // command length
530  myOutputStorage.writeUnsignedByte(1 + 1 + static_cast<int>(answerTmp.size()));
531  // command type
533  // and the parameter dependant part
534  myOutputStorage.writeStorage(answerTmp);
535  return true;
536 }
537 
538 
539 void
543  int noActive = 0;
544  for (std::vector<Subscription>::iterator i = mySubscriptions.begin(); i != mySubscriptions.end();) {
545  const Subscription& s = *i;
548  if ((s.endTime < t) || isArrivedVehicle) {
549  i = mySubscriptions.erase(i);
550  continue;
551  }
552  ++i;
553  if (s.beginTime > t) {
554  continue;
555  }
556  ++noActive;
557  }
558  myOutputStorage.writeInt(noActive);
559  for (std::vector<Subscription>::iterator i = mySubscriptions.begin(); i != mySubscriptions.end();) {
560  const Subscription& s = *i;
561  if (s.beginTime > t) {
562  ++i;
563  continue;
564  }
565  tcpip::Storage into;
566  std::string errors;
567  bool ok = processSingleSubscription(s, into, errors);
569  if (ok) {
570  ++i;
571  } else {
572  i = mySubscriptions.erase(i);
573  }
574  }
575 }
576 
577 
578 void
579 TraCIServer::writeStatusCmd(int commandId, int status, const std::string& description) {
580  writeStatusCmd(commandId, status, description, myOutputStorage);
581 }
582 
583 
584 void
585 TraCIServer::writeStatusCmd(int commandId, int status, const std::string& description, tcpip::Storage& outputStorage) {
586  if (status == RTYPE_ERR) {
587  WRITE_ERROR("Answered with error to command " + toHex(commandId, 2) + ": " + description);
588  } else if (status == RTYPE_NOTIMPLEMENTED) {
589  WRITE_ERROR("Requested command not implemented (" + toHex(commandId, 2) + "): " + description);
590  }
591  outputStorage.writeUnsignedByte(1 + 1 + 1 + 4 + static_cast<int>(description.length())); // command length
592  outputStorage.writeUnsignedByte(commandId); // command type
593  outputStorage.writeUnsignedByte(status); // status
594  outputStorage.writeString(description); // description
595 }
596 
597 
598 bool
599 TraCIServer::writeErrorStatusCmd(int commandId, const std::string& description, tcpip::Storage& outputStorage) {
600  writeStatusCmd(commandId, RTYPE_ERR, description, outputStorage);
601  return false;
602 }
603 
604 
605 void
607  tcpip::Storage writeInto;
608  std::string errors;
609  if (processSingleSubscription(s, writeInto, errors)) {
611  writeStatusCmd(s.commandId, RTYPE_ERR, "Subscription has ended.");
612  } else {
613  bool needNewSubscription = true;
614  for (std::vector<Subscription>::iterator i = mySubscriptions.begin(); i != mySubscriptions.end(); ++i) {
615  if (s.commandId == i->commandId && s.id == i->id &&
616  s.beginTime == i->beginTime && s.endTime == i->endTime &&
617  s.contextVars == i->contextVars && s.contextDomain == i->contextDomain && s.range == i->range) {
618  std::vector<std::vector<unsigned char> >::const_iterator k = s.parameters.begin();
619  for (std::vector<int>::const_iterator j = s.variables.begin(); j != s.variables.end(); ++j, ++k) {
620  const int offset = (int)(std::find(i->variables.begin(), i->variables.end(), *j) - i->variables.begin());
621  if (offset == (int)i->variables.size() || i->parameters[offset] != *k) {
622  i->variables.push_back(*j);
623  i->parameters.push_back(*k);
624  }
625  }
626  needNewSubscription = false;
627  break;
628  }
629  }
630  if (needNewSubscription) {
631  mySubscriptions.push_back(s);
632  }
634  }
635  } else {
636  writeStatusCmd(s.commandId, RTYPE_ERR, "Could not add subscription (" + errors + ").");
637  }
638  myOutputStorage.writeStorage(writeInto);
639 }
640 
641 
642 void
643 TraCIServer::removeSubscription(int commandId, const std::string& id, int domain) {
644  bool found = false;
645  for (std::vector<Subscription>::iterator j = mySubscriptions.begin(); j != mySubscriptions.end();) {
646  if ((*j).id == id && (*j).commandId == commandId && (domain < 0 || (*j).contextDomain == domain)) {
647  j = mySubscriptions.erase(j);
648  found = true;
649  continue;
650  }
651  ++j;
652  }
653  // try unsubscribe
654  if (found) {
655  writeStatusCmd(commandId, RTYPE_OK, "");
656  } else {
657  writeStatusCmd(commandId, RTYPE_OK, "The subscription to remove was not found.");
658  }
659 }
660 
661 
662 bool
663 TraCIServer::findObjectShape(int domain, const std::string& id, PositionVector& shape) {
664  Position p;
665  switch (domain) {
668  shape.push_back(p);
669  return true;
670  }
671  break;
673  break;
675  break;
677  if (TraCIServerAPI_Lane::getShape(id, shape)) {
678  return true;
679  }
680  break;
683  shape.push_back(p);
684  return true;
685  }
686  break;
689  shape.push_back(p);
690  return true;
691  }
692  break;
694  break;
696  break;
698  if (TraCIServerAPI_POI::getPosition(id, p)) {
699  shape.push_back(p);
700  return true;
701  }
702  return false;
704  if (TraCIServerAPI_Polygon::getShape(id, shape)) {
705  return true;
706  }
707  break;
710  shape.push_back(p);
711  return true;
712  }
713  break;
715  if (TraCIServerAPI_Edge::getShape(id, shape)) {
716  return true;
717  }
718  break;
720  return false;
722  break;
723  default:
724  break;
725  }
726  return false;
727 }
728 
729 void
730 TraCIServer::collectObjectsInRange(int domain, const PositionVector& shape, double range, std::set<std::string>& into) {
731  // build the look-up tree if not yet existing
732  if (myObjects.find(domain) == myObjects.end()) {
733  switch (domain) {
736  break;
745  break;
748  break;
751  break;
754  break;
755  default:
756  break;
757  }
758  }
759  const Boundary b = shape.getBoxBoundary().grow(range);
760  const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
761  const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
762  switch (domain) {
767  Named::StoringVisitor sv(into);
768  myObjects[domain]->Search(cmin, cmax, sv);
769  }
770  break;
774  TraCIServerAPI_Lane::StoringVisitor sv(into, shape, range, domain);
775  myLaneTree->Search(cmin, cmax, sv);
776  }
777  break;
778  default:
779  break;
780  }
781 }
782 
783 
784 bool
786  std::string& errors) {
787  bool ok = true;
788  tcpip::Storage outputStorage;
789  const int getCommandId = s.contextVars ? s.contextDomain : s.commandId - 0x30;
790  std::set<std::string> objIDs;
791  if (s.contextVars) {
792  PositionVector shape;
793  if (!findObjectShape(s.commandId, s.id, shape)) {
794  return false;
795  }
796  collectObjectsInRange(s.contextDomain, shape, s.range, objIDs);
797  } else {
798  objIDs.insert(s.id);
799  }
800  const int numVars = s.contextVars && s.variables.size() == 1 && s.variables[0] == ID_LIST ? 0 : (int)s.variables.size();
801  for (std::set<std::string>::iterator j = objIDs.begin(); j != objIDs.end(); ++j) {
802  if (s.contextVars) {
803  outputStorage.writeString(*j);
804  }
805  if (numVars > 0) {
806  std::vector<std::vector<unsigned char> >::const_iterator k = s.parameters.begin();
807  for (std::vector<int>::const_iterator i = s.variables.begin(); i != s.variables.end(); ++i, ++k) {
808  tcpip::Storage message;
809  message.writeUnsignedByte(*i);
810  message.writeString(*j);
811  message.writePacket(*k);
812  tcpip::Storage tmpOutput;
813  if (myExecutors.find(getCommandId) != myExecutors.end()) {
814  ok &= myExecutors[getCommandId](*this, message, tmpOutput);
815  } else {
816  writeStatusCmd(s.commandId, RTYPE_NOTIMPLEMENTED, "Unsupported command specified", tmpOutput);
817  ok = false;
818  }
819  // copy response part
820  if (ok) {
821  int length = tmpOutput.readUnsignedByte();
822  while (--length > 0) {
823  tmpOutput.readUnsignedByte();
824  }
825  int lengthLength = 1;
826  length = tmpOutput.readUnsignedByte();
827  if (length == 0) {
828  lengthLength = 5;
829  length = tmpOutput.readInt();
830  }
831  //read responseType
832  tmpOutput.readUnsignedByte();
833  int variable = tmpOutput.readUnsignedByte();
834  std::string id = tmpOutput.readString();
835  outputStorage.writeUnsignedByte(variable);
836  outputStorage.writeUnsignedByte(RTYPE_OK);
837  length -= (lengthLength + 1 + 4 + (int)id.length());
838  while (--length > 0) {
839  outputStorage.writeUnsignedByte(tmpOutput.readUnsignedByte());
840  }
841  } else {
842  //read length
843  tmpOutput.readUnsignedByte();
844  //read cmd
845  tmpOutput.readUnsignedByte();
846  //read status
847  tmpOutput.readUnsignedByte();
848  std::string msg = tmpOutput.readString();
849  outputStorage.writeUnsignedByte(*i);
850  outputStorage.writeUnsignedByte(RTYPE_ERR);
851  outputStorage.writeUnsignedByte(TYPE_STRING);
852  outputStorage.writeString(msg);
853  errors = errors + msg;
854  }
855  }
856  }
857  }
858  int length = (1 + 4) + 1 + (4 + (int)(s.id.length())) + 1 + (int)outputStorage.size();
859  if (s.contextVars) {
860  length += 4;
861  }
862  writeInto.writeUnsignedByte(0); // command length -> extended
863  writeInto.writeInt(length);
864  writeInto.writeUnsignedByte(s.commandId + 0x10);
865  writeInto.writeString(s.id);
866  if (s.contextVars) {
867  writeInto.writeUnsignedByte(s.contextDomain);
868  }
869  writeInto.writeUnsignedByte(numVars);
870  if (s.contextVars) {
871  writeInto.writeInt((int)objIDs.size());
872  }
873  if (!s.contextVars || objIDs.size() != 0) {
874  writeInto.writeStorage(outputStorage);
875  }
876  return ok;
877 }
878 
879 
880 bool
881 TraCIServer::addObjectVariableSubscription(const int commandId, const bool hasContext) {
882  const SUMOTime beginTime = myInputStorage.readInt();
883  const SUMOTime endTime = myInputStorage.readInt();
884  const std::string id = myInputStorage.readString();
885  const int domain = hasContext ? myInputStorage.readUnsignedByte() : 0;
886  const double range = hasContext ? myInputStorage.readDouble() : 0.;
887  const int num = myInputStorage.readUnsignedByte();
888  std::vector<int> variables;
889  std::vector<std::vector<unsigned char> > parameters;
890  for (int i = 0; i < num; ++i) {
891  const int varID = myInputStorage.readUnsignedByte();
892  variables.push_back(varID);
893  parameters.push_back(std::vector<unsigned char>());
894  for (int j = 0; j < myParameterSizes[varID]; j++) {
895  parameters.back().push_back(myInputStorage.readChar());
896  }
897  }
898  // check subscribe/unsubscribe
899  if (variables.size() == 0) {
900  removeSubscription(commandId, id, -1);
901  return true;
902  }
903  // process subscription
904  Subscription s(commandId, id, variables, parameters, beginTime, endTime, hasContext, domain, range);
906  return true;
907 }
908 
909 
910 void
912  if (tempMsg.size() < 254) {
913  outputStorage.writeUnsignedByte(1 + (int)tempMsg.size()); // command length -> short
914  } else {
915  outputStorage.writeUnsignedByte(0); // command length -> extended
916  outputStorage.writeInt(1 + 4 + (int)tempMsg.size());
917  }
918  outputStorage.writeStorage(tempMsg);
919 }
920 
921 
922 bool
924  if (inputStorage.readUnsignedByte() != TYPE_INTEGER) {
925  return false;
926  }
927  into = inputStorage.readInt();
928  return true;
929 }
930 
931 
932 bool
934  if (inputStorage.readUnsignedByte() != TYPE_DOUBLE) {
935  return false;
936  }
937  into = inputStorage.readDouble();
938  return true;
939 }
940 
941 
942 bool
943 TraCIServer::readTypeCheckingString(tcpip::Storage& inputStorage, std::string& into) {
944  if (inputStorage.readUnsignedByte() != TYPE_STRING) {
945  return false;
946  }
947  into = inputStorage.readString();
948  return true;
949 }
950 
951 
952 bool
953 TraCIServer::readTypeCheckingStringList(tcpip::Storage& inputStorage, std::vector<std::string>& into) {
954  if (inputStorage.readUnsignedByte() != TYPE_STRINGLIST) {
955  return false;
956  }
957  into = inputStorage.readStringList();
958  return true;
959 }
960 
961 
962 bool
964  if (inputStorage.readUnsignedByte() != TYPE_COLOR) {
965  return false;
966  }
967  into.r = static_cast<unsigned char>(inputStorage.readUnsignedByte());
968  into.g = static_cast<unsigned char>(inputStorage.readUnsignedByte());
969  into.b = static_cast<unsigned char>(inputStorage.readUnsignedByte());
970  into.a = static_cast<unsigned char>(inputStorage.readUnsignedByte());
971  return true;
972 }
973 
974 
975 bool
977  if (inputStorage.readUnsignedByte() != POSITION_2D) {
978  return false;
979  }
980  into.x = inputStorage.readDouble();
981  into.y = inputStorage.readDouble();
982  into.z = 0;
983  return true;
984 }
985 
986 
987 bool
989  if (inputStorage.readUnsignedByte() != TYPE_BOUNDINGBOX) {
990  return false;
991  }
992  const double xmin = inputStorage.readDouble();
993  const double ymin = inputStorage.readDouble();
994  const double xmax = inputStorage.readDouble();
995  const double ymax = inputStorage.readDouble();
996  into.set(xmin, ymin, xmax, ymax);
997  return true;
998 }
999 
1000 
1001 bool
1003  if (inputStorage.readUnsignedByte() != TYPE_BYTE) {
1004  return false;
1005  }
1006  into = inputStorage.readByte();
1007  return true;
1008 }
1009 
1010 
1011 bool
1013  if (inputStorage.readUnsignedByte() != TYPE_UBYTE) {
1014  return false;
1015  }
1016  into = inputStorage.readUnsignedByte();
1017  return true;
1018 }
1019 
1020 
1021 bool
1023  if (inputStorage.readUnsignedByte() != TYPE_POLYGON) {
1024  return false;
1025  }
1026  into.clear();
1027  int noEntries = inputStorage.readUnsignedByte();
1028  PositionVector shape;
1029  for (int i = 0; i < noEntries; ++i) {
1030  double x = inputStorage.readDouble();
1031  double y = inputStorage.readDouble();
1032  into.push_back(Position(x, y));
1033  }
1034  return true;
1035 }
1036 
1037 #endif
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa3: Get Lane Variable)
bool processSingleSubscription(const TraCIServer::Subscription &s, tcpip::Storage &writeInto, std::string &errors)
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:580
bool myDoingSimStep
Whether a step is currently done.
Definition: TraCIServer.h:316
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
double x
Definition: TraCIDefs.h:72
tcpip::Socket * mySocket
The socket on which server is listening on.
Definition: TraCIServer.h:303
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:138
#define CMD_SUBSCRIBE_VEHICLE_CONTEXT
#define CMD_SUBSCRIBE_LANE_VARIABLE
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:132
bool readTypeCheckingColor(tcpip::Storage &inputStorage, TraCIColor &into)
Reads the value type and a color, verifying the type.
bool findObjectShape(int domain, const std::string &id, PositionVector &shape)
#define CMD_SUBSCRIBE_LANEAREA_VARIABLE
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
bool contextVars
Whether the subscription is a context subscription (variable subscription otherwise) ...
Definition: TraCIServer.h:364
double range
The range of the context.
Definition: TraCIServer.h:368
#define CMD_GET_TL_VARIABLE
#define CMD_SUBSCRIBE_JUNCTION_CONTEXT
StorageType::const_iterator end() const
Definition: storage.h:118
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc3: Change Lane State)
#define CMD_GET_VEHICLE_VARIABLE
virtual ~TraCIServer()
Destructor.
#define CMD_SUBSCRIBE_SIM_CONTEXT
bool commandGetVersion()
Returns the TraCI-version.
#define CMD_SUBSCRIBE_VEHICLETYPE_CONTEXT
#define CMD_CLOSE
virtual std::vector< std::string > readStringList()
#define POSITION_2D
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc4: Change Vehicle State)
std::vector< std::vector< unsigned char > > parameters
The parameters for the subscribed variables.
Definition: TraCIServer.h:358
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc7: Change PoI State)
bool receiveExact(Storage &)
Receive a complete TraCI message from Socket::socket_.
Definition: socket.cpp:497
#define CMD_GET_INDUCTIONLOOP_VARIABLE
static NamedRTree * getTree()
Returns a tree filled with junction instances.
static NamedRTree * getTree()
Returns a tree filled with polygon instances.
static void fill(RTREE &into)
Fills the given RTree with lane instances.
Definition: MSLane.cpp:1411
#define CMD_SUBSCRIBE_INDUCTIONLOOP_VARIABLE
#define TYPE_UBYTE
#define RTYPE_OK
SUMOTime beginTime
The begin time of the subscription.
Definition: TraCIServer.h:360
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 writeto.
Definition: TraCIServer.h:312
#define TYPE_POLYGON
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
void accept()
Wait for a incoming connection to port_.
Definition: socket.cpp:231
unsigned char g
Definition: TraCIDefs.h:79
#define TRACI_VERSION
static bool getPosition(const std::string &id, Position &p)
Returns the named vehicle&#39;s position.
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xab: Get Simulation Variable)
void set(double xmin, double ymin, double xmax, double ymax)
Sets the boundary to the given values.
Definition: Boundary.cpp:274
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).
Definition: MSNet.cpp:158
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc6: Change Route State)
static void load(const std::vector< std::string > &args)
load a simulation with the given arguments
Definition: TraCI.cpp:61
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
#define TYPE_COLOR
#define TYPE_STRINGLIST
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
virtual bool valid_pos()
#define CMD_SUBSCRIBE_POLYGON_CONTEXT
unsigned char r
Definition: TraCIDefs.h:79
tcpip::Storage myInputStorage
The storage to read from.
Definition: TraCIServer.h:309
#define CMD_GET_POLYGON_VARIABLE
virtual void writePacket(unsigned char *packet, int length)
#define CMD_SUBSCRIBE_JUNCTION_VARIABLE
Representation of a subscription.
Definition: TraCIServer.h:333
void cleanup()
clean up subscriptions
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
#define CMD_SUBSCRIBE_ROUTE_CONTEXT
void setVTDControlled(Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector &route, SUMOTime t)
Definition: MSVehicle.cpp:435
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
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
unsigned char a
Definition: TraCIDefs.h:79
#define CMD_SUBSCRIBE_EDGE_VARIABLE
virtual unsigned char readChar()
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:794
#define CMD_GET_ROUTE_VARIABLE
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
#define CMD_SUBSCRIBE_INDUCTIONLOOP_CONTEXT
virtual void writeInt(int)
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
#define TYPE_STRING
virtual int readUnsignedByte()
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)
static bool getPosition(const std::string &id, Position &p)
Returns the named inductive loop&#39;s position.
static bool getPosition(const std::string &id, Position &p)
Returns the named persons&#39;s position.
static bool myDoCloseConnection
Whether the connection was set to be to close.
Definition: TraCIServer.h:300
void postProcessVTD()
The vehicles starts to stop.
Definition: MSNet.h:594
std::map< int, CmdExecutor > myExecutors
Map of commandIds -> their executors; applicable if the executor applies to the method footprint...
Definition: TraCIServer.h:322
#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)
double z
Definition: TraCIDefs.h:72
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to)
Called if a vehicle changes its state.
bool readTypeCheckingBoundary(tcpip::Storage &inputStorage, Boundary &into)
Reads the value type and a 2D bounding box, verifying the type.
static NamedRTree * getTree()
Returns a tree filled with PoI instances.
#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
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_GETVERSION
#define CMD_SUBSCRIBE_GUI_CONTEXT
#define CMD_LOAD
Allows to store the object; used as context while traveling the rtree in TraCI.
The vehicle got a new route.
Definition: MSNet.h:588
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:586
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
The vehicles starts to park.
Definition: MSNet.h:590
int commandId
commandIdArg The command id of the subscription
Definition: TraCIServer.h:352
std::vector< Subscription > mySubscriptions
The list of known, still valid subscriptions.
Definition: TraCIServer.h:373
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xce: Change Person State)
Representation of a vehicle.
Definition: SUMOVehicle.h:67
virtual int readInt()
A 3D-position.
Definition: TraCIDefs.h:71
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
std::string id
The id of the object that is subscribed.
Definition: TraCIServer.h:354
#define CMD_GET_POI_VARIABLE
#define CMD_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE
A list of positions.
std::vector< int > variables
The subscribed variables.
Definition: TraCIServer.h:356
#define CMD_SUBSCRIBE_MULTIENTRYEXIT_CONTEXT
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:310
#define CMD_SET_VEHICLETYPE_VARIABLE
void setVTDControlled(MSVehicle *v, Position xyPos, MSLane *l, double pos, double posLat, double angle, int edgeOffset, ConstMSEdgeVector route, SUMOTime t)
#define TYPE_BOUNDINGBOX
virtual const char * what() const
Definition: socket.h:70
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
#define CMD_SUBSCRIBE_GUI_VARIABLE
#define CMD_GET_LANE_VARIABLE
#define CMD_SUBSCRIBE_LANEAREA_CONTEXT
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:257
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)
Definition: SUMOTime.cpp:47
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:126
void postProcessSimulationStep2()
Handles subscriptions to send after a simstep2 command.
The vehicle started to teleport.
Definition: MSNet.h:582
#define CMD_GET_SIM_VARIABLE
virtual std::string readString()
#define CMD_GET_EDGE_VARIABLE
virtual unsigned int position() const
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:234
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:76
#define CMD_SET_POI_VARIABLE
#define CMD_SUBSCRIBE_POLYGON_VARIABLE
static TraCIServer * myInstance
Singleton instance of the server.
Definition: TraCIServer.h:297
static bool getPosition(const std::string &id, Position &p)
Returns the named PoI&#39;s position.
TraCIServer(const SUMOTime begin, const int port=0)
Constructor.
#define CMD_SUBSCRIBE_TL_CONTEXT
The vehicle ends to park.
Definition: MSNet.h:592
#define CMD_SUBSCRIBE_EDGE_CONTEXT
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
#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.
Definition: TraCIServer.h:74
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)
#define VAR_LEADER
#define CMD_SET_SIM_VARIABLE
StorageType::size_type size() const
Definition: storage.h:115
#define CMD_SUBSCRIBE_VEHICLETYPE_VARIABLE
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
#define VERSION_STRING
Definition: config.h:210
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:576
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.
Definition: TraCIServer.h:319
The vehicle was built, but has not yet departed.
Definition: MSNet.h:578
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
static void processCommandsUntilSimStep(SUMOTime step)
process all commands until a simulation step is wanted
LANE_RTREE_QUAL * myLaneTree
A storage of lanes.
Definition: TraCIServer.h:382
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc5: Change Vehicle Type State)
Allows to store the object; used as context while traveling the rtree in TraCI.
Definition: Named.h:100
#define CMD_SET_POLYGON_VARIABLE
static void openSocket(const std::map< int, CmdExecutor > &execs)
Initialises the server.
static bool getShape(const std::string &id, PositionVector &shape)
Returns the named edge&#39;s shape.
virtual void writeString(const std::string &s)
#define RTYPE_NOTIMPLEMENTED
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:3993
void collectObjectsInRange(int domain, const PositionVector &shape, double range, std::set< std::string > &into)
#define TYPE_DOUBLE
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:66
static bool getPosition(const std::string &id, Position &p)
Returns the named junction&#39;s position.
#define CMD_SUBSCRIBE_VEHICLE_VARIABLE
#define CMD_SUBSCRIBE_PERSON_CONTEXT
void sendExact(const Storage &)
Definition: socket.cpp:398
void visit(const TraCIServerAPI_Lane::StoringVisitor &cont) const
Callback for visiting the lane when traversing an RTree.
Definition: MSLane.h:1004
#define TYPE_BYTE
StorageType::const_iterator begin() const
Definition: storage.h:117
#define CMD_SET_LANE_VARIABLE
#define CMD_GET_MULTIENTRYEXIT_VARIABLE
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:85
SUMOTime myTargetTime
The time step to reach until processing the next commands.
Definition: TraCIServer.h:306
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa6: Get Route Variable)
static NamedRTree * getTree()
Returns a tree filled with inductive loop instances.
The vehicle ends to stop.
Definition: MSNet.h:596
#define LANE_RTREE_QUAL
std::map< int, NamedRTree * > myObjects
A storage of objects.
Definition: TraCIServer.h:379
bool readTypeCheckingPosition2D(tcpip::Storage &inputStorage, TraCIPosition &into)
Reads the value type and a 2D position, verifying the type.
std::map< std::string, MSVehicle * > myVTDControlledVehicles
Definition: TraCIServer.h:327
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get MeMeDetector Variable)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa8: Get Polygon Variable)
int dispatchCommand()
unsigned char b
Definition: TraCIDefs.h:79
#define CMD_SUBSCRIBE_TL_VARIABLE
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc2: Change Traffic Lights State)
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
long long int SUMOTime
Definition: TraCIDefs.h:52
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
Definition: FileHelpers.cpp:72
double y
Definition: TraCIDefs.h:72
#define CMD_SET_PERSON_VARIABLE
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:425
int contextDomain
The domain ID of the context.
Definition: TraCIServer.h:366
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:144
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
#define RTYPE_ERR
void initialiseSubscription(const Subscription &s)
#define TYPE_INTEGER
#define ID_LIST
const std::string & getID() const
Returns the name of the vehicle.
#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)
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
static bool wasClosed()
check whether close was requested
std::map< MSNet::VehicleState, std::vector< std::string > > myVehicleStateChanges
Changes in the states of simulated vehicles.
Definition: TraCIServer.h:376
The vehicle ended being teleported.
Definition: MSNet.h:584
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
#define CMD_SIMSTEP
virtual int readByte()
static bool getShape(const std::string &id, PositionVector &shape)
Returns the named polygons&#39;s shape.
bool readTypeCheckingByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and a byte, verifying the type.
void close()
Definition: socket.cpp:349
SUMOTime endTime
The end time of the subscription.
Definition: TraCIServer.h:362
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa2: Get Traffic Lights Variable)
#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)
static bool getShape(const std::string &id, PositionVector &shape)
Returns the named lane&#39;s shape.
std::map< int, int > myParameterSizes
Map of variable ids to the size of the parameter in bytes.
Definition: TraCIServer.h:325