Merged in f5soh/librepilot/LP-575_fedora_package (pull request #491)
[librepilot.git] / ground / gcs / src / libs / utils / logfile.h
blob3c3616e208fd33eb19b6f88c5426d2c9482a1f70
1 /**
2 ******************************************************************************
4 * @file logfile.h
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
7 * @see The GNU Public License (GPL) Version 3
9 *****************************************************************************/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef LOGFILE_H
26 #define LOGFILE_H
28 #include "utils_global.h"
30 #include <QIODevice>
31 #include <QTime>
32 #include <QTimer>
33 #include <QMutexLocker>
34 #include <QDebug>
35 #include <QBuffer>
36 #include <QFile>
38 class QTCREATOR_UTILS_EXPORT LogFile : public QIODevice {
39 Q_OBJECT
40 public:
41 explicit LogFile(QObject *parent = 0);
43 QString fileName() const
45 return m_file.fileName();
47 void setFileName(QString name)
49 m_file.setFileName(name);
52 bool isSequential() const;
54 bool isPlaying() const;
56 bool open(OpenMode mode);
57 void close();
59 qint64 bytesAvailable() const;
60 qint64 bytesToWrite() const
62 return m_file.bytesToWrite();
65 qint64 writeData(const char *data, qint64 dataSize);
66 qint64 readData(char *data, qint64 maxlen);
68 void useProvidedTimeStamp(bool useProvidedTimeStamp)
70 m_useProvidedTimeStamp = useProvidedTimeStamp;
73 void setNextTimeStamp(quint32 providedTimestamp)
75 m_providedTimeStamp = providedTimestamp;
78 public slots:
79 void setReplaySpeed(double val)
81 m_playbackSpeed = val;
82 qDebug() << "Playback speed is now" << m_playbackSpeed;
84 bool startReplay();
85 bool stopReplay();
86 bool pauseReplay();
87 bool resumeReplay();
89 protected slots:
90 void timerFired();
92 signals:
93 void readReady();
94 void replayStarted();
95 void replayFinished();
97 protected:
98 QByteArray m_dataBuffer;
99 QTimer m_timer;
100 QTime m_myTime;
101 QFile m_file;
102 qint32 m_previousTimeStamp;
103 qint32 m_nextTimeStamp;
104 double m_lastPlayed;
105 // QMutex wants to be mutable
106 // http://stackoverflow.com/questions/25521570/can-mutex-locking-function-be-marked-as-const
107 mutable QMutex m_mutex;
109 int m_timeOffset;
110 double m_playbackSpeed;
111 bool paused;
113 private:
114 bool m_useProvidedTimeStamp;
115 qint32 m_providedTimeStamp;
118 #endif // LOGFILE_H