-
Notifications
You must be signed in to change notification settings - Fork 44
/
quainmemoryhistorizer.h
149 lines (138 loc) · 4.91 KB
/
quainmemoryhistorizer.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef QUAINMEMORYHISTORIZER_H
#define QUAINMEMORYHISTORIZER_H
#include <QUaHistoryBackend>
#ifdef UA_ENABLE_HISTORIZING
class QUaInMemoryHistorizer
{
public:
// required API for QUaServer::setHistorizer
// write data point to backend, return true on success
bool writeHistoryData(
const QUaNodeId &nodeId,
const QUaHistoryDataPoint& dataPoint,
QQueue<QUaLog>& logOut
);
// required API for QUaServer::setHistorizer
// update an existing node's data point in backend, return true on success
bool updateHistoryData(
const QUaNodeId &nodeId,
const QUaHistoryDataPoint& dataPoint,
QQueue<QUaLog>& logOut
);
// required API for QUaServer::setHistorizer
// remove an existing node's data points within a range, return true on success
bool removeHistoryData(
const QUaNodeId &nodeId,
const QDateTime& timeStart,
const QDateTime& timeEnd,
QQueue<QUaLog>& logOut
);
// required API for QUaServer::setHistorizer
// return the timestamp of the first sample available for the given node
QDateTime firstTimestamp(
const QUaNodeId &nodeId,
QQueue<QUaLog>& logOut
) const;
// required API for QUaServer::setHistorizer
// return the timestamp of the latest sample available for the given node
QDateTime lastTimestamp(
const QUaNodeId &nodeId,
QQueue<QUaLog>& logOut
) const;
// required API for QUaServer::setHistorizer
// return true if given timestamp is available for the given node
bool hasTimestamp(
const QUaNodeId &nodeId,
const QDateTime& timestamp,
QQueue<QUaLog>& logOut
) const;
// required API for QUaServer::setHistorizer
// return a timestamp matching the criteria for the given node
QDateTime findTimestamp(
const QUaNodeId &nodeId,
const QDateTime& timestamp,
const QUaHistoryBackend::TimeMatch& match,
QQueue<QUaLog>& logOut
) const;
// required API for QUaServer::setHistorizer
// return the number for data points within a time range for the given node
quint64 numDataPointsInRange(
const QUaNodeId &nodeId,
const QDateTime& timeStart,
const QDateTime& timeEnd,
QQueue<QUaLog>& logOut
) const;
// required API for QUaServer::setHistorizer
// return the numPointsToRead data points for the given node from the given start time
QVector<QUaHistoryDataPoint> readHistoryData(
const QUaNodeId & nodeId,
const QDateTime &timeStart,
const quint64 &numPointsOffset,
const quint64 &numPointsToRead,
QQueue<QUaLog> &logOut
) const;
// event history support
#ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS
// write a event's data to backend
bool writeHistoryEventsOfType(
const QUaNodeId &eventTypeNodeId,
const QList<QUaNodeId> &emittersNodeIds,
const QUaHistoryEventPoint &eventPoint,
QQueue<QUaLog> &logOut
);
// get event types (node ids) for which there are events stored for the
// given emitter
QVector<QUaNodeId> eventTypesOfEmitter(
const QUaNodeId &emitterNodeId,
QQueue<QUaLog> &logOut
);
// find a timestamp matching the criteria for the emitter and event type
QDateTime findTimestampEventOfType(
const QUaNodeId &emitterNodeId,
const QUaNodeId &eventTypeNodeId,
const QDateTime ×tamp,
const QUaHistoryBackend::TimeMatch &match,
QQueue<QUaLog> &logOut
);
// get the number for events within a time range for the given emitter and event type
quint64 numEventsOfTypeInRange(
const QUaNodeId &emitterNodeId,
const QUaNodeId &eventTypeNodeId,
const QDateTime &timeStart,
const QDateTime &timeEnd,
QQueue<QUaLog> &logOut
);
// return the numPointsToRead events for the given emitter and event type,
// starting from the numPointsOffset offset after given start time (pagination)
QVector<QUaHistoryEventPoint> readHistoryEventsOfType(
const QUaNodeId &emitterNodeId,
const QUaNodeId &eventTypeNodeId,
const QDateTime &timeStart,
const quint64 &numPointsOffset,
const quint64 &numPointsToRead,
const QList<QUaBrowsePath> &columnsToRead,
QQueue<QUaLog> &logOut
);
#endif // UA_ENABLE_SUBSCRIPTIONS_EVENTS
private:
struct DataPoint
{
QVariant value;
quint32 status;
};
// NOTE : use a map to store the data points of a single node, ordered by time
typedef QMap<QDateTime, DataPoint> DataPointTable;
QHash<QUaNodeId, DataPointTable> m_database;
// event history support
#ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS
typedef QHash<uint /*EventKey*/, QUaHistoryEventPoint> QUaEventTypeTable;
typedef QHash<QUaNodeId /*TypeNodeId*/, QUaEventTypeTable > QUaEventTypeDatabase;
QUaEventTypeDatabase m_eventTypeDatabase;
typedef QMultiMap <QDateTime, uint /*EventKey*/> QUaEventEmitterTable;
typedef QHash <QUaNodeId /*TypeNodeId*/, QUaEventEmitterTable > QUaEventTypeIndex;
typedef QHash <QUaNodeId /*EmitterId*/, QUaEventTypeIndex > QUaEventEmitterDatabase;
QUaEventEmitterDatabase m_eventEmitterDatabase;
#endif // UA_ENABLE_SUBSCRIPTIONS_EVENTS
};
#endif // UA_ENABLE_HISTORIZING
#endif // QUAINMEMORYHISTORIZER_H