Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / logging / loggingplugin.h
blob7a1925ad08a2060fa2c8c740378e61d50d99c683
1 /**
2 ******************************************************************************
3 * @file loggingplugin.h
4 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
5 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @see The GNU Public License (GPL) Version 3
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup loggingplugin
10 * @{
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef LOGGINGPLUGIN_H_
29 #define LOGGINGPLUGIN_H_
31 #include <coreplugin/icore.h>
32 #include <coreplugin/coreconstants.h>
33 #include <coreplugin/iconnection.h>
34 #include <extensionsystem/iplugin.h>
35 #include <utils/logfile.h>
37 #include <QThread>
38 #include <QQueue>
39 #include <QReadWriteLock>
41 class UAVObject;
42 class UAVDataObject;
43 class UAVTalk;
44 class LoggingPlugin;
45 class LoggingGadgetFactory;
47 namespace Core {
48 class Command;
51 /**
52 * Define a connection via the IConnection interface
53 * Plugin will add a instance of this class to the pool,
54 * so the connection manager can use it.
56 class LoggingConnection : public Core::IConnection {
57 Q_OBJECT
58 public:
59 LoggingConnection();
60 virtual ~LoggingConnection();
62 virtual QList <Core::IConnection::device> availableDevices();
64 virtual QIODevice *openDevice(const QString &deviceName);
65 virtual void closeDevice(const QString &deviceName);
67 virtual QString connectionName();
68 virtual QString shortName();
70 bool deviceOpened()
72 return m_deviceOpened;
74 LogFile *getLogfile()
76 return &logFile;
79 private:
80 bool m_deviceOpened;
81 LogFile logFile;
84 class LoggingThread : public QThread {
85 Q_OBJECT
86 public:
87 LoggingThread();
88 virtual ~LoggingThread();
90 bool openFile(QString file);
92 public slots:
93 void startLogging();
94 void stopLogging();
96 protected:
97 void run();
99 private slots:
100 void objectUpdated(UAVObject *obj);
101 void transactionCompleted(UAVObject *obj, bool success);
103 private:
104 QReadWriteLock lock;
105 QQueue<UAVDataObject *> queue;
106 LogFile logFile;
107 UAVTalk *uavTalk;
109 void retrieveSettings();
110 void retrieveNextObject();
113 class LoggingPlugin : public ExtensionSystem::IPlugin {
114 Q_OBJECT
115 Q_PLUGIN_METADATA(IID "OpenPilot.Logging")
117 friend class LoggingConnection;
119 public:
120 enum State { IDLE, LOGGING, REPLAY };
122 LoggingPlugin();
123 ~LoggingPlugin();
125 void extensionsInitialized();
126 bool initialize(const QStringList & arguments, QString *errorString);
127 void shutdown();
129 LogFile *getLogfile()
131 return logConnection->getLogfile();
134 State getState()
136 return state;
139 signals:
140 void stateChanged(State);
142 private slots:
143 void toggleLogging();
144 void startLogging(QString file);
145 void stopLogging();
146 void loggingStarted();
147 void loggingStopped();
148 void replayStarted();
149 void replayStopped();
151 private:
152 Core::Command *loggingCommand;
153 State state;
154 // These are used for replay, logging in its own thread
155 LoggingThread *loggingThread;
156 LoggingConnection *logConnection;
158 #endif /* LoggingPLUGIN_H_ */
160 * @}
161 * @}