90 #ifdef CHECK_MEMORY_LEAKS
92 #endif // CHECK_MEMORY_LEAKS
116 for (std::map<int, CmdExecutor>::const_iterator i = execs.begin(); i != execs.end(); ++i) {
126 : mySocket(0), myTargetTime(0), myDoingSimStep(false), myHaveWarnedDeprecation(false), myAmEmbedded(port == 0) {
160 WRITE_WARNING(
"Starting TraCI without using internal lanes!");
249 }
catch (std::invalid_argument& e) {
287 traciemb_execute(PyObject*
self, PyObject* args) {
290 if (!PyArg_ParseTuple(args,
"s#", &msg, &size)) {
293 std::string result = traci::TraCIServer::execute(std::string(msg, size));
294 return Py_BuildValue(
"s#", result.c_str(), result.size());
297 static PyMethodDef EmbMethods[] = {
299 "execute", traciemb_execute, METH_VARARGS,
300 "Execute the given TraCI command and return the result."
302 {NULL, NULL, 0, NULL}
307 TraCIServer::execute(std::string cmd) {
318 for (std::string::iterator i = cmd.begin(); i != cmd.end(); ++i) {
323 }
catch (std::invalid_argument& e) {
334 TraCIServer::runEmbedded(std::string pyFile) {
335 PyObject* pName, *pModule;
337 Py_InitModule(
"traciemb", EmbMethods);
338 if (pyFile.length() > 3 && !pyFile.compare(pyFile.length() - 3, 3,
".py")) {
339 FILE* pFile = fopen(pyFile.c_str(),
"r");
340 PyRun_SimpleFile(pFile, pyFile.c_str());
343 pName = PyString_FromString(pyFile.c_str());
345 pModule = PyImport_Import(pName);
347 if (pModule == NULL) {
349 throw ProcessError(
"Failed to load \"" + pyFile +
"\"!");
362 if (commandLength == 0) {
367 bool success =
false;
395 WRITE_WARNING(
"Using old TraCI API, please update your client!");
408 WRITE_WARNING(
"Using old TraCI API, please update your client!");
415 WRITE_WARNING(
"Using old TraCI API, please update your client!");
451 std::ostringstream msg;
452 msg <<
"Wrong position in requestMessage after dispatching command.";
453 msg <<
" Expected command length was " << commandLength;
471 if ((s.
endTime < t) || isArrivedVehicle) {
505 answerTmp.
writeString(std::string(
"SUMO ") + sumoVersion);
565 lane = route->
getEdges()[0]->getLanes()[0];
579 vehicleParams->
id = vehicleId;
582 if (vehicle == NULL) {
588 float clippedInsertionSpeed;
589 if (insertionSpeed < 0) {
602 if (!lane->
isInsertionSuccess(vehicle, clippedInsertionSpeed, insertionPosition,
true)) {
631 WRITE_ERROR(
"Requested command not implemented (" +
toString(commandId) +
"): " + description);
633 outputStorage.
writeUnsignedByte(1 + 1 + 1 + 4 + static_cast<int>(description.length()));
647 std::vector<int> variables;
648 for (
int i = 0; i < no; ++i) {
653 if (variables.size() == 0) {
657 if ((*j).id ==
id && (*j).commandId == commandId) {
671 Subscription s(commandId,
id, variables, beginTime, endTime);
693 std::string& errors) {
696 for (std::vector<int>::const_iterator i = s.
variables.begin(); i != s.
variables.end(); ++i) {
703 ok &=
myExecutors[getId](*
this, message, tmpOutput);
711 while (--length > 0) {
714 int lengthLength = 1;
726 length -= (lengthLength + 1 + 4 + (
int)
id.length());
727 while (--length > 0) {
742 errors = errors + msg;
746 writeInto.
writeInt((1 + 4) + 1 + (4 + (
int)(s.
id.length())) + 1 + (
int)outputStorage.
size());
756 if (tempMsg.
size() < 254) {