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) {
269 }
catch (std::invalid_argument& e) {
291 traciemb_execute(PyObject* , PyObject* args) {
294 if (!PyArg_ParseTuple(args,
"s#", &msg, &size)) {
297 std::string result = traci::TraCIServer::execute(std::string(msg, size));
298 return Py_BuildValue(
"s#", result.c_str(), result.size());
301 static PyMethodDef EmbMethods[] = {
303 "execute", traciemb_execute, METH_VARARGS,
304 "Execute the given TraCI command and return the result."
306 {NULL, NULL, 0, NULL}
311 TraCIServer::execute(std::string cmd) {
322 for (std::string::iterator i = cmd.begin(); i != cmd.end(); ++i) {
327 }
catch (std::invalid_argument& e) {
338 TraCIServer::runEmbedded(std::string pyFile) {
339 PyObject* pName, *pModule;
341 Py_InitModule(
"traciemb", EmbMethods);
342 if (pyFile.length() > 3 && !pyFile.compare(pyFile.length() - 3, 3,
".py")) {
343 FILE* pFile = fopen(pyFile.c_str(),
"r");
344 PyRun_SimpleFile(pFile, pyFile.c_str());
347 pName = PyString_FromString(pyFile.c_str());
349 pModule = PyImport_Import(pName);
351 if (pModule == NULL) {
353 throw ProcessError(
"Failed to load \"" + pyFile +
"\"!");
365 if (commandLength == 0) {
370 bool success =
false;
398 WRITE_WARNING(
"Using old TraCI API, please update your client!");
443 std::ostringstream msg;
444 msg <<
"Wrong position in requestMessage after dispatching command.";
445 msg <<
" Expected command length was " << commandLength;
461 answerTmp.
writeString(std::string(
"SUMO ") + sumoVersion);
491 if ((s.
endTime < t) || isArrivedVehicle) {
549 lane = route->
getEdges()[0]->getLanes()[0];
563 vehicleParams->
id = vehicleId;
566 if (vehicle == NULL) {
572 float clippedInsertionSpeed;
573 if (insertionSpeed < 0) {
586 if (!lane->
isInsertionSuccess(vehicle, clippedInsertionSpeed, insertionPosition,
true)) {
613 WRITE_ERROR(
"Requested command not implemented (" +
toString(commandId) +
"): " + description);
615 outputStorage.
writeUnsignedByte(1 + 1 + 1 + 4 + static_cast<int>(description.length()));
644 if ((*j).id ==
id && (*j).commandId == commandId && (domain < 0 || (*j).contextDomain == domain)) {
781 if (shape.
size() == 1) {
782 for (std::set<std::string>::iterator i = into.begin(); i != into.end();) {
794 std::set<std::string> tmp;
797 for (std::set<std::string>::const_iterator i = tmp.begin(); i != tmp.end(); ++i) {
801 for (std::deque<MSVehicle*>::const_iterator j = vehs.begin(); j != vehs.end(); ++j) {
802 if (shape.
distance((*j)->getPosition()) <= range) {
803 into.insert((*j)->getID());
847 std::string& errors) {
851 std::set<std::string> objIDs;
864 for (std::set<std::string>::iterator j = objIDs.begin(); j != objIDs.end(); ++j) {
868 for (std::vector<int>::const_iterator i = s.
variables.begin(); i != s.
variables.end(); ++i) {
874 ok &=
myExecutors[getCommandId](*
this, message, tmpOutput);
882 while (--length > 0) {
885 int lengthLength = 1;
897 length -= (lengthLength + 1 + 4 + (
int)
id.length());
898 while (--length > 0) {
913 errors = errors + msg;
917 unsigned int length = (1 + 4) + 1 + (4 + (
int)(s.
id.length())) + 1 + (
int)outputStorage.
size();
930 writeInto.
writeInt((
int)objIDs.size());
945 std::vector<int> variables;
946 for (
int i = 0; i < no; ++i) {
950 if (variables.size() == 0) {
955 Subscription s(commandId,
id, variables, beginTime, endTime,
false, 0, 0);
969 std::vector<int> variables;
970 for (
int i = 0; i < no; ++i) {
974 if (variables.size() == 0) {
978 Subscription s(commandId,
id, variables, beginTime, endTime,
true, domain, range);
986 if (tempMsg.
size() < 254) {