Files
edgetx-gx12/companion/src/simulation/debugoutput.h
T
Max PapernoandBertrand Songis 4aa0c1bbe4 [simulation] Fix some potential crashes & 26 memory leaks, improve LCD redraws. (#4634)
* [simulation] Hardening: Fix some potential crashes & 26 memory leaks, improve LCD performance.
  * [simpgmspace] Init trims; Make sure `REa` is really defined (to match board files).
  * [simpgmspace][opentxsimulator] Verify current running state before start/stop; Move rotary enc. init.
  * [simpgmspace][LcdWidget] Improve performance by moving LCD content change check to lcdRefresh() & limiting LcdWidget refresh time to 60 fps max.
  * [simueeprom] Ensure thread could be started, set default running state to false.
  * [simufatfs] Fix paths report trace.
  * [eepromimportexport] Fix memory leaks resulting from import debugging scheme being used.
  * [customdebug] Introduce new scheme for custom debug output in compliance with Qt recommendations (see docs for QLoggingCategory).
  * [opentxeeprom] Fix extra conversion table cache elements being created and also not properly deleted (and hence leaking).
  * [opentxinterface] Unregister EEpromInterfaces in unregisterOpenTxFirmwares();
  * [storage] Unregister storage factories on exit (fixes leak); create virtual StorageFormat/StorageFactory destructors (prevents warnings).
  * [helpers] GVarGroup now emits own signal, no need to pass ModelPanel pointer (removes dependency on modeledit.h)
  * [DebugOutput] Clear simulator trace hook before exiting (prevent possible issues); Fix leak and possible bad QString allocations when reading from buffer; Fix leak with combo box event filter.
  * [TelemetrySimulator] Fix leak by deleting LogPlaybackController object on exit; Only set up data fields once; convert timers to static.
  * [build] Consolidate all Companion/Simulator shared items in `common` library to reduce build time/etc (node & edge still remain awkward).

* [simulatorwidget] Delete removed spacer object (previously-forgotten "26th" leak).

* [DebugOutput] Fix stray trailing characters issue with new text buffer allocation (from previous commit); Increase maximum buffer sizes to better accommodate slower systems.

* Cosmetics.
2017-03-21 07:43:40 +01:00

113 lines
3.4 KiB
C++

/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _DEBUGOUTPUT_H_
#define _DEBUGOUTPUT_H_
#include "simulator.h"
#include "simulatorinterface.h"
#include <QMutex>
#include <QTimer>
#include <QValidator>
#include <QWidget>
// NOTE : The buffer sizes need to be large enough to handle the flood of data when X12/X10 simulator starts up with TRACE_SIMPGMSPACE=1 (> 40K!).
// These are maximum sizes, not necessarily allocated sizes.
#ifndef DEBUG_OUTPUT_WIDGET_OUT_BUFF_SIZE
// This buffer holds received and processed data until it can be printed to our console.
#define DEBUG_OUTPUT_WIDGET_OUT_BUFF_SIZE (50 * 1024) // [bytes]
#endif
#ifndef DEBUG_OUTPUT_WIDGET_INP_BUFF_SIZE
// This buffer is active if line filter is enabled and holds received data until it can be filtered and placed in output buffer.
#define DEBUG_OUTPUT_WIDGET_INP_BUFF_SIZE (50 * 1024) // [bytes]
#endif
namespace Ui {
class DebugOutput;
}
class QAbstractButton;
class QMessageLogContext;
class FilteredTextBuffer;
using namespace Simulator;
class DebugOutput : public QWidget
{
Q_OBJECT
public:
explicit DebugOutput(QWidget * parent, SimulatorInterface * simulator);
virtual ~DebugOutput();
static QRegularExpression makeRegEx(const QString & input, bool * isExlusive = NULL);
static FilteredTextBuffer * m_dataBufferDevice;
signals:
void filterExprChanged(const QRegularExpression & expr);
void filterEnabledChanged(const bool enabled);
void filterExclusiveChanged(const bool exlusive);
void filterChanged(bool enable, bool exclusive, const QRegularExpression & expr);
protected slots:
void saveState();
void restoreState();
void processBytesReceived();
void onDataBufferOverflow(const qint64 len);
void onAppDebugMessage(quint8 level, const QString & msg, const QMessageLogContext & context);
void onFilterStateChanged();
void onFilterTextChanged(const QString &);
void onFilterToggled(bool enable);
void on_bufferSize_editingFinished();
void on_actionWordWrap_toggled(bool checked);
void on_actionClearScr_triggered();
void on_actionShowFilterHelp_triggered();
protected:
Ui::DebugOutput * ui;
SimulatorInterface * m_simulator;
int m_radioProfileId;
bool m_filterEnable;
bool m_filterExclude;
const static quint16 m_savedViewStateVersion;
};
class DebugOutputFilterValidator : public QValidator
{
public:
DebugOutputFilterValidator(QObject *parent = Q_NULLPTR) : QValidator(parent) { }
virtual State validate(QString & input, int &) const;
};
class DeleteComboBoxItemEventFilter : public QObject
{
Q_OBJECT
public:
DeleteComboBoxItemEventFilter(QObject *parent = Q_NULLPTR) : QObject(parent) { }
protected:
bool eventFilter(QObject *obj, QEvent *event);
};
#endif // _DEBUGOUTPUT_H_