-
Notifications
You must be signed in to change notification settings - Fork 505
/
database.h
135 lines (110 loc) · 3.19 KB
/
database.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Copyright (c) 2016-2024 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
*/
#ifndef DATABASE_H
#define DATABASE_H
#include <string>
#include <cinttypes>
#include <vector>
#include <cstddef>
#include <QString>
#include <QVariant>
#include <utils/bufstring.h>
#define DB_MAX_UNIQUEID_SIZE 31
namespace deCONZ {
class Address;
}
struct DB_Secret
{
std::string uniqueId;
std::string secret;
int state = 0;
};
struct DB_AlarmSystem
{
int id;
uint64_t timestamp;
};
struct DB_AlarmSystemResourceItem
{
int alarmSystemId;
const char *suffix;
std::string value;
uint64_t timestamp;
};
struct DB_AlarmSystemDevice
{
char uniqueid[DB_MAX_UNIQUEID_SIZE + 1];
uint64_t timestamp;
uint32_t flags;
int alarmSystemId;
};
bool DB_StoreSecret(const DB_Secret &secret);
bool DB_LoadSecret(DB_Secret &secret);
bool DB_StoreAlarmSystem(const DB_AlarmSystem &alarmSys);
bool DB_StoreAlarmSystemResourceItem(const DB_AlarmSystemResourceItem &item);
std::vector<DB_AlarmSystemResourceItem> DB_LoadAlarmSystemResourceItems(int alarmSystemId);
bool DB_StoreAlarmSystemDevice(const DB_AlarmSystemDevice &dev);
std::vector<DB_AlarmSystemDevice> DB_LoadAlarmSystemDevices();
bool DB_DeleteAlarmSystemDevice(const std::string &uniqueId);
// DDF specific
class Resource;
class ResourceItem;
// TODO(mpi) deprecated for DB_ResourceItem2
struct DB_ResourceItem
{
BufString<64> name;
QVariant value;
qint64 timestampMs = 0; // milliseconds since Epoch
};
struct DB_ResourceItem2
{
BufString<64> name;
unsigned valueSize;
char value[160];
qint64 timestampMs = 0; // milliseconds since Epoch
};
struct DB_LegacyItem
{
BufString<64> column;
BufString<64> uniqueId;
BufString<128> value;
};
struct DB_ZclValue
{
int64_t data;
int deviceId;
uint16_t clusterId;
uint16_t attrId;
uint8_t endpoint;
// internal
uint8_t loaded;
};
struct DB_IdentifierPair
{
unsigned modelIdAtomIndex;
unsigned mfnameAtomIndex;
};
int DB_StoreDevice(const deCONZ::Address &addr);
int DB_GetSubDeviceItemCount(QLatin1String uniqueId);
bool DB_LoadZclValue(DB_ZclValue *val);
bool DB_StoreZclValue(const DB_ZclValue *val);
bool DB_StoreSubDevice(const char *uniqueId);
bool DB_StoreDeviceItem(int deviceId, const DB_ResourceItem2 &item);
bool DB_LoadDeviceItems(int deviceId, std::vector<DB_ResourceItem2> &items);
bool DB_ResourceItem2DbItem(const ResourceItem *rItem, DB_ResourceItem2 *dbItem);
std::vector<DB_IdentifierPair> DB_LoadIdentifierPairs();
bool DB_StoreSubDeviceItem(const Resource *sub, ResourceItem *item);
bool DB_StoreSubDeviceItems(Resource *sub);
std::vector<DB_ResourceItem> DB_LoadSubDeviceItemsOfDevice(QLatin1String deviceUniqueId);
std::vector<DB_ResourceItem> DB_LoadSubDeviceItems(QLatin1String uniqueId);
bool DB_LoadLegacySensorValue(DB_LegacyItem *litem);
std::vector<std::string> DB_LoadLegacySensorUniqueIds(QLatin1String deviceUniqueId, const char *type);
bool DB_LoadLegacyLightValue(DB_LegacyItem *litem);
#endif // DATABASE_H