mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
85392343fa
This tries to make our fingerprinting code work better, by avoiding using the "deviceid" field that has always been unreliable because we've calculated it multiple different ways, and even for the same version of subsurface, it ends up changing in the middle (ie we calculate one value initially, then re-calculate it when we have a proper serial number string). So instead, the fingerprinting code will look up and save the fingerprint file using purely "stable" information that is available early during the download: - the device model name (which is a string with vendor and product name separated by a space) - the DC_EVENT_DEVINFO 32-bit 'serial' number (which is not necessarily a real serial number at all, but hopefully at least a unique number for the particular product) but because the model name is not necessarily a good filename (think slashes and other possibly invalid characters), we hash that model name and use the resulting hex number in the fingerprint file name. This way the fingerprint file is unambiguous at load and save time, and depends purely on libdivecomputer data. But because we also need to verify that we have the actual _dive_ associated with that fingerprint, we also need to save the final deviceid and diveid when saving the fingerprint file, so that when we load it again we can look up the dive and verify that we have it before we use the fingerprint data. To do that, the fingerprint file itself contains not just the fingerprint data from libdivecomputer, but the last 8 bytes of the file are the (subsurface) deviceid and the diveid of the dive that is associated with the fingerprint. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
106 lines
2.6 KiB
C++
106 lines
2.6 KiB
C++
#ifndef DOWNLOADFROMDCTHREAD_H
|
|
#define DOWNLOADFROMDCTHREAD_H
|
|
|
|
#include <QThread>
|
|
#include <QMap>
|
|
#include <QHash>
|
|
#include <QLoggingCategory>
|
|
|
|
#include "divesite.h"
|
|
#include "device.h"
|
|
#include "libdivecomputer.h"
|
|
#include "connectionlistmodel.h"
|
|
#if BT_SUPPORT
|
|
#include "core/btdiscovery.h"
|
|
#endif
|
|
#if defined(Q_OS_ANDROID)
|
|
#include "core/serial_usb_android.h"
|
|
#endif
|
|
|
|
/* Helper object for access of Device Data in QML */
|
|
class DCDeviceData {
|
|
public:
|
|
DCDeviceData();
|
|
static DCDeviceData *instance();
|
|
|
|
QString vendor() const;
|
|
QString product() const;
|
|
QString devName() const;
|
|
bool bluetoothMode() const;
|
|
bool saveDump() const;
|
|
QString devBluetoothName() const;
|
|
QString descriptor() const;
|
|
bool forceDownload() const;
|
|
bool saveLog() const;
|
|
int diveId() const;
|
|
|
|
/* this needs to be a pointer to make the C-API happy */
|
|
device_data_t *internalData();
|
|
|
|
QStringList getProductListFromVendor(const QString& vendor);
|
|
int getMatchingAddress(const QString &vendor, const QString &product);
|
|
|
|
int getDetectedVendorIndex();
|
|
int getDetectedProductIndex(const QString ¤tVendorText);
|
|
|
|
void setDiveId(int diveId);
|
|
void setVendor(const QString& vendor);
|
|
void setProduct(const QString& product);
|
|
void setDevName(const QString& devName);
|
|
void setDevBluetoothName(const QString& devBluetoothName);
|
|
void setBluetoothMode(bool mode);
|
|
void setForceDownload(bool force);
|
|
void setSaveDump(bool dumpMode);
|
|
void setSaveLog(bool saveLog);
|
|
#if defined(Q_OS_ANDROID)
|
|
void setUsbDevice(const android_usb_serial_device_descriptor &usbDescriptor);
|
|
#endif
|
|
private:
|
|
#if defined(Q_OS_ANDROID)
|
|
struct android_usb_serial_device_descriptor androidUsbDescriptor;
|
|
#endif
|
|
device_data_t data;
|
|
|
|
// Bluetooth name is managed outside of libdivecomputer
|
|
QString m_devBluetoothName;
|
|
};
|
|
|
|
class DownloadThread : public QThread {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
DownloadThread();
|
|
void run() override;
|
|
|
|
DCDeviceData *data();
|
|
QString error;
|
|
struct dive_table downloadTable;
|
|
struct dive_site_table diveSiteTable;
|
|
struct device_table deviceTable;
|
|
|
|
private:
|
|
DCDeviceData *m_data;
|
|
};
|
|
|
|
//TODO: C++ify descriptor?
|
|
struct mydescriptor {
|
|
const char *vendor;
|
|
const char *product;
|
|
dc_family_t type;
|
|
unsigned int model;
|
|
unsigned int transports;
|
|
};
|
|
|
|
/* This fills the vendor list QStringList and related members.
|
|
* this code needs to be reworked to be less ugly, but it will
|
|
* stay like this for now.
|
|
*/
|
|
void fill_computer_list();
|
|
extern "C" {
|
|
void show_computer_list();
|
|
}
|
|
extern QStringList vendorList;
|
|
extern QHash<QString, QStringList> productList;
|
|
extern QMap<QString, dc_descriptor_t *> descriptorLookup;
|
|
extern ConnectionListModel connectionListModel;
|
|
#endif
|