This repository was archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathchangecontroller_p.h
94 lines (70 loc) · 2.3 KB
/
changecontroller_p.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef QTDATASYNC_CHANGECONTROLLER_P_H
#define QTDATASYNC_CHANGECONTROLLER_P_H
#include <QtCore/QObject>
#include <QtCore/QMutex>
#include <QtCore/QUuid>
#include "qtdatasync_global.h"
#include "objectkey.h"
#include "controller_p.h"
#include "localstore_p.h"
namespace QtDataSync {
class ChangeEmitter;
class Q_DATASYNC_EXPORT ChangeController : public Controller
{
Q_OBJECT
public:
struct Q_DATASYNC_EXPORT ChangeInfo {
ObjectKey key;
quint64 version = 0;
QByteArray checksum;
ChangeInfo();
ChangeInfo(ObjectKey key, quint64 version, QByteArray checksum = {});
};
//not exported, because of "cheating" api. Declared public because of qHash
class CachedObjectKey : public ObjectKey {
public:
CachedObjectKey();
CachedObjectKey(ObjectKey other, QUuid deviceId = {});
CachedObjectKey(QByteArray hash, QUuid deviceId = {});
QByteArray hashed() const;
QUuid optionalDevice;
bool operator==(const CachedObjectKey &other) const;
bool operator!=(const CachedObjectKey &other) const;
private:
mutable QByteArray _hash;
};
explicit ChangeController(const Defaults &defaults, QObject *parent = nullptr);
void initialize(const QVariantHash ¶ms) final;
public Q_SLOTS:
void setUploadingEnabled(bool uploading);
void clearUploads();
void updateUploadLimit(quint32 limit);
void uploadDone(const QByteArray &key);
void deviceUploadDone(const QByteArray &key, QUuid deviceId);
Q_SIGNALS:
void uploadingChanged(bool uploading);
void uploadChange(const QByteArray &key, const QByteArray &changeData);
void uploadDeviceChange(const QByteArray &key, const QUuid &deviceId, const QByteArray &changeData);
private Q_SLOTS:
void changeTriggered();
void uploadNext(bool emitStarted = false);
private:
//unexported private member
struct UploadInfo {
ObjectKey key;
quint64 version;
bool isDelete;
};
LocalStore *_store = nullptr;
ChangeEmitter *_emitter = nullptr;
bool _uploadingEnabled = false;
int _uploadLimit = 10;
QHash<CachedObjectKey, UploadInfo> _activeUploads;
quint32 _changeEstimate = 0;
};
//not exported, just like the class
uint qHash(const ChangeController::CachedObjectKey &key, uint seed);
}
Q_DECLARE_METATYPE(QtDataSync::ChangeController::ChangeInfo)
Q_DECLARE_TYPEINFO(QtDataSync::ChangeController::ChangeInfo, Q_MOVABLE_TYPE);
#endif // QTDATASYNC_CHANGECONTROLLER_P_H