Skip to content

Commit

Permalink
Use the File* instead of QFile & QTextStream.
Browse files Browse the repository at this point in the history
Flush all streams when opening the CrashReportDialog so we get full logs.
  • Loading branch information
adeas31 committed Jan 12, 2017
1 parent 12d09da commit a49d9f5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/CrashReport/CrashReportDialog.cpp
Expand Up @@ -48,6 +48,8 @@
CrashReportDialog::CrashReportDialog()
: QDialog(0)
{
// flush all streams before making a crash report so we get full logs.
fflush(NULL);
setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::crashReport));
setAttribute(Qt::WA_DeleteOnClose);
// set heading
Expand Down
49 changes: 23 additions & 26 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -183,19 +183,11 @@ bool OMCProxy::initializeOMC()
/* create the tmp path */
QString& tmpPath = Utilities::tempDirectory();
/* create a file to write OMEdit communication log */
mCommunicationLogFile.setFileName(QString("%1omeditcommunication.log").arg(tmpPath));
if (mCommunicationLogFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
mCommunicationLogFileTextStream.setDevice(&mCommunicationLogFile);
mCommunicationLogFileTextStream.setCodec(Helper::utf8.toStdString().data());
mCommunicationLogFileTextStream.setGenerateByteOrderMark(false);
}
QString communicationLogFilePath = QString("%1omeditcommunication.log").arg(tmpPath);
mpCommunicationLogFile = fopen(communicationLogFilePath.toStdString().c_str(), "w");
/* create a file to write OMEdit commands */
mCommandsMosFile.setFileName(QString("%1omeditcommands.mos").arg(tmpPath));
if (mCommandsMosFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
mCommandsLogFileTextStream.setDevice(&mCommandsMosFile);
mCommandsLogFileTextStream.setCodec(Helper::utf8.toStdString().data());
mCommandsLogFileTextStream.setGenerateByteOrderMark(false);
}
QString commandsLogFilePath = QString("%1omeditcommands.mos").arg(tmpPath);
mpCommandsLogFile = fopen(commandsLogFilePath.toStdString().c_str(), "w");
// read the locale
QSettings *pSettings = Utilities::getApplicationSettings();
QLocale settingsLocale = QLocale(pSettings->value("language").toString());
Expand Down Expand Up @@ -237,14 +229,20 @@ bool OMCProxy::initializeOMC()
}

/*!
Stops the OpenModelica Compiler. Kill the process omc and also deletes the CORBA reference file.
\see startServer
*/
* \brief OMCProxy::quitOMC
* Quits the OpenModelica Compiler.\n
* Closes the log files.
* \see startServer
*/
void OMCProxy::quitOMC()
{
sendCommand("quit()");
mCommunicationLogFile.close();
mCommandsMosFile.close();
if (mpCommunicationLogFile) {
fclose(mpCommunicationLogFile);
}
if (mpCommandsLogFile) {
fclose(mpCommandsLogFile);
}
}

/*!
Expand Down Expand Up @@ -331,15 +329,15 @@ void OMCProxy::logCommand(QString command, QTime *commandTime)
mCurrentCommandIndex = mCommandsList.count();
mpExpressionTextBox->setText("");
// write the log to communication log file
if (mCommunicationLogFileTextStream.device()) {
mCommunicationLogFileTextStream << QString("%1 %2\n").arg(command).arg(commandTime->currentTime().toString("hh:mm:ss:zzz"));
if (mpCommunicationLogFile) {
fputs(QString("%1 %2\n").arg(command, commandTime->currentTime().toString("hh:mm:ss:zzz")).toStdString().c_str(), mpCommunicationLogFile);
}
// write commands mos file
if (mCommandsLogFileTextStream.device()) {
if (mpCommandsLogFile) {
if (command.compare("quit()") == 0) {
mCommandsLogFileTextStream << QString("%1;\n").arg(command);
fputs(QString("%1;\n").arg(command).toStdString().c_str(), mpCommandsLogFile);
} else {
mCommandsLogFileTextStream << QString("%1; getErrorString();\n").arg(command);
fputs(QString("%1; getErrorString();\n").arg(command).toStdString().c_str(), mpCommandsLogFile);
}
}
}
Expand All @@ -359,11 +357,10 @@ void OMCProxy::logResponse(QString response, QTime *responseTime)
format.setFont(font);
Utilities::insertText(mpOMCLoggerTextBox, response + "\n\n", format);
// write the log to communication log file
if (mCommunicationLogFileTextStream.device()) {
mCommunicationLogFileTextStream << QString("%1 %2\n").arg(response).arg(responseTime->currentTime().toString("hh:mm:ss:zzz"));
if (mpCommunicationLogFile) {
fputs(QString("%1 %2\n").arg(response).arg(responseTime->currentTime().toString("hh:mm:ss:zzz")).toStdString().c_str(), mpCommunicationLogFile);
mTotalOMCCallsTime += (double)responseTime->elapsed() / 1000;
mCommunicationLogFileTextStream << QString("%1 secs (%2 secs)\n\n").arg(QString::number((double)responseTime->elapsed() / 1000))
.arg(QString::number(mTotalOMCCallsTime));
fputs(QString("%1 secs (%2 secs)\n\n").arg(QString::number((double)responseTime->elapsed() / 1000)).arg(QString::number(mTotalOMCCallsTime)).toStdString().c_str(), mpCommunicationLogFile);
}
}

Expand Down
6 changes: 2 additions & 4 deletions OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -74,10 +74,8 @@ class OMCProxy : public QObject
QString mObjectRefFile;
QList<QString> mCommandsList;
int mCurrentCommandIndex;
QFile mCommunicationLogFile;
QTextStream mCommunicationLogFileTextStream;
QFile mCommandsMosFile;
QTextStream mCommandsLogFileTextStream;
FILE *mpCommunicationLogFile;
FILE *mpCommandsLogFile;
double mTotalOMCCallsTime;
QList<UnitConverion> mUnitConversionList;
QMap<QString, QList<QString> > mDerivedUnitsMap;
Expand Down

0 comments on commit a49d9f5

Please sign in to comment.