ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
kbfirmware.h
Go to the documentation of this file.
1 #ifndef KBFIRMWARE_H
2 #define KBFIRMWARE_H
3 
4 #include "kb.h"
5 #include <QObject>
6 #include <QtNetwork/QtNetwork>
7 
8 // Class for managing/updating firmware on a device
9 
10 class KbFirmware : public QObject
11 {
12  Q_OBJECT
13 public:
14  // Checks for firmware updates. Maximum of once per hour. Returns true if it actually checked or false if not.
15  static inline bool checkUpdates() { return instance._checkUpdates(); }
16 
17  // Whether or not the firmware table has been downloaded at all.
18  static inline bool hasDownloaded() { return instance.lastFinished != 0; }
19 
20  // Latest firmware version for a keyboard model. Will check for updates automatically and return the latest known version.
21  // Zero if version unknown, -1.0 if ckb needs to be upgraded.
22  static inline float versionForBoard(const QString& features, bool waitForComplete = false) { return instance._latestForBoard(features, waitForComplete); }
23 
24  // Downloads and extracts the latest firmware for a keyboard. Returns an empty array on failure.
25  static inline QByteArray dataForBoard(const QString& features) { return instance._fileForBoard(features); }
26 
27  // Network manager object to use with QtNetwork
28  QNetworkAccessManager* networkManager;
29 
30 private:
31  KbFirmware();
32  ~KbFirmware();
33 
34  // Time initiated
36  // Model -> firmware table
37  struct FW {
38  QString url, fileName;
39  QByteArray hash;
41 
42  FW();
43  };
44  QMap<QString, FW> fwTable;
45  // SHA256 of last downloaded table (redundancy check)
46  QByteArray fwTableHash;
47 
48  // Current FW table download (null if nothing downloading)
49  QNetworkReply* tableDownload;
50 
51  // Can GPG be used to verify signatures?
52  enum { UNKNOWN = -1, NO, YES } hasGPG :2;
53 
54  // Singleton instance
55  bool _checkUpdates();
56  float _latestForBoard(const QString& features, bool waitForComplete);
57  QByteArray _fileForBoard(const QString& features);
59 
60 signals:
61  void downloaded();
62 
63 private slots:
64  void processDownload(QNetworkReply* reply);
65  void downloadFinished();
66 };
67 
68 #endif // KBFIRMWARE_H
static KbFirmware instance
Definition: kbfirmware.h:58
QNetworkAccessManager * networkManager
Definition: kbfirmware.h:28
void processDownload(QNetworkReply *reply)
Definition: kbfirmware.cpp:41
bool _checkUpdates()
Definition: kbfirmware.cpp:28
QString fileName
Definition: kbfirmware.h:38
static QByteArray dataForBoard(const QString &features)
Definition: kbfirmware.h:25
float fwVersion
Definition: kbfirmware.h:40
QByteArray fwTableHash
Definition: kbfirmware.h:46
QString url
Definition: kbfirmware.h:38
quint64 lastFinished
Definition: kbfirmware.h:35
float _latestForBoard(const QString &features, bool waitForComplete)
Definition: kbfirmware.cpp:162
quint64 lastCheck
Definition: kbfirmware.h:35
enum KbFirmware::@1 hasGPG
QMap< QString, FW > fwTable
Definition: kbfirmware.h:44
static bool checkUpdates()
Definition: kbfirmware.h:15
static bool hasDownloaded()
Definition: kbfirmware.h:18
QNetworkReply * tableDownload
Definition: kbfirmware.h:49
float ckbVersion
Definition: kbfirmware.h:40
void downloadFinished()
Definition: kbfirmware.cpp:141
QByteArray hash
Definition: kbfirmware.h:39
static float versionForBoard(const QString &features, bool waitForComplete=false)
Definition: kbfirmware.h:22
QByteArray _fileForBoard(const QString &features)
Definition: kbfirmware.cpp:180