90 #ifdef CHECK_MEMORY_LEAKS
92 #endif // CHECK_MEMORY_LEAKS
111 : mySocket(0), myTargetTime(0), myDoingSimStep(false), myHaveWarnedDeprecation(false), myAmEmbedded(port == 0) {
146 WRITE_WARNING(
"Starting TraCI without using internal lanes!");
170 for (std::map<int, TraCIRTree*>::const_iterator i =
myObjects.begin(); i !=
myObjects.end(); ++i) {
182 for (std::map<int, CmdExecutor>::const_iterator i = execs.begin(); i != execs.end(); ++i) {
216 (*i).second->getInfluencer().postProcessVTD((*i).second);
218 WRITE_WARNING(
"Vehicle '" + (*i).first +
"' was removed though being controlled by VTD");
294 }
catch (std::invalid_argument& e) {
316 traciemb_execute(PyObject* , PyObject* args) {
319 if (!PyArg_ParseTuple(args,
"s#", &msg, &size)) {
322 std::string result = traci::TraCIServer::execute(std::string(msg, size));
323 return Py_BuildValue(
"s#", result.c_str(), result.size());
326 static PyMethodDef EmbMethods[] = {
328 "execute", traciemb_execute, METH_VARARGS,
329 "Execute the given TraCI command and return the result."
331 {NULL, NULL, 0, NULL}
336 TraCIServer::execute(std::string cmd) {
347 for (std::string::iterator i = cmd.begin(); i != cmd.end(); ++i) {
352 }
catch (std::invalid_argument& e) {
363 TraCIServer::runEmbedded(std::string pyFile) {
364 PyObject* pName, *pModule;
366 Py_InitModule(
"traciemb", EmbMethods);
367 if (pyFile.length() > 3 && !pyFile.compare(pyFile.length() - 3, 3,
".py")) {
368 FILE* pFile = fopen(pyFile.c_str(),
"r");
369 PyRun_SimpleFile(pFile, pyFile.c_str());
372 pName = PyString_FromString(pyFile.c_str());
374 pModule = PyImport_Import(pName);
376 if (pModule == NULL) {
378 throw ProcessError(
"Failed to load \"" + pyFile +
"\"!");
390 if (commandLength == 0) {
395 bool success =
false;
423 WRITE_WARNING(
"Using old TraCI API, please update your client!");
468 std::ostringstream msg;
469 msg <<
"Wrong position in requestMessage after dispatching command.";
470 msg <<
" Expected command length was " << commandLength;
486 answerTmp.
writeString(std::string(
"SUMO ") + sumoVersion);
516 if ((s.
endTime < t) || isArrivedVehicle) {
571 lane = route->
getEdges()[0]->getLanes()[0];
583 vehicleParams->
id = vehicleId;
586 if (vehicle == NULL) {
591 float clippedInsertionSpeed;
592 if (insertionSpeed < 0) {
604 if (!lane->
isInsertionSuccess(vehicle, clippedInsertionSpeed, insertionPosition,
true)) {
630 WRITE_ERROR(
"Requested command not implemented (" +
toString(commandId) +
"): " + description);
632 outputStorage.
writeUnsignedByte(1 + 1 + 1 + 4 + static_cast<int>(description.length()));
668 if ((*j).id ==
id && (*j).commandId == commandId && (domain < 0 || (*j).contextDomain == domain)) {
805 if (shape.size() == 1) {
806 for (std::set<std::string>::iterator i = into.begin(); i != into.end();) {
818 std::set<std::string> tmp;
821 for (std::set<std::string>::const_iterator i = tmp.begin(); i != tmp.end(); ++i) {
825 for (std::deque<MSVehicle*>::const_iterator j = vehs.begin(); j != vehs.end(); ++j) {
826 if (shape.
distance((*j)->getPosition()) <= range) {
827 into.insert((*j)->getID());
871 std::string& errors) {
875 std::set<std::string> objIDs;
888 for (std::set<std::string>::iterator j = objIDs.begin(); j != objIDs.end(); ++j) {
892 for (std::vector<int>::const_iterator i = s.
variables.begin(); i != s.
variables.end(); ++i) {
898 ok &=
myExecutors[getCommandId](*
this, message, tmpOutput);
906 while (--length > 0) {
909 int lengthLength = 1;
921 length -= (lengthLength + 1 + 4 + (
int)
id.length());
922 while (--length > 0) {
937 errors = errors + msg;
941 unsigned int length = (1 + 4) + 1 + (4 + (
int)(s.
id.length())) + 1 + (
int)outputStorage.
size();
954 writeInto.
writeInt((
int)objIDs.size());
969 std::vector<int> variables;
970 for (
int i = 0; i < no; ++i) {
974 if (variables.size() == 0) {
979 Subscription s(commandId,
id, variables, beginTime, endTime,
false, 0, 0);
993 std::vector<int> variables;
994 for (
int i = 0; i < no; ++i) {
998 if (variables.size() == 0) {
1002 Subscription s(commandId,
id, variables, beginTime, endTime,
true, domain, range);
1010 if (tempMsg.
size() < 254) {
1025 into = inputStorage.
readInt();
1065 unsigned char r =
static_cast<unsigned char>(inputStorage.
readUnsignedByte());
1066 unsigned char g =
static_cast<unsigned char>(inputStorage.
readUnsignedByte());
1067 unsigned char b =
static_cast<unsigned char>(inputStorage.
readUnsignedByte());
1068 unsigned char a =
static_cast<unsigned char>(inputStorage.
readUnsignedByte());
1069 into.
set(r, g, b, a);
1095 into.
set(xmin, ymin, xmax, ymax);
1128 for (
unsigned int i = 0; i < noEntries; ++i) {