-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.h
53 lines (43 loc) · 1.17 KB
/
output.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
#ifndef OUTPUT_H
#define OUTPUT_H
#include <QString>
#include <QQueue>
#include <QThread>
#include <QMutex>
#include <QWaitCondition>
#include <QJsonObject>
typedef struct {
QString name;
QString value;
quint16 id;
quint32 enterpriseId;
QByteArray raw;
}output_field_t;
typedef struct {
QString templateId;
QList<output_field_t> fields;
} output_row_t;
class Filter : public QObject {
public:
Filter(const QJsonObject params);
//need to be implemented in subclasses ... return true if record is ready to output
virtual bool next(output_row_t &row) = 0;
};
class Output : public QThread {
public:
Output(int queueLimit, QList<Filter*> filterList);
~Output();
void enqueue(const output_row_t &row);
void run();
//helper
QString row2json(const output_row_t &row, bool pretty = false, QHash<QString, QString> *compressTable = nullptr, bool autoAdd = false, QHash<QString,QString> *addedKeys = nullptr);
//need to be implemented in subclasses
virtual void next(const output_row_t &row) = 0;
protected:
int queueLimit;
QQueue<output_row_t> queue;
QMutex mutex;
QWaitCondition waitCondition;
QList<Filter*> filterList;
};
#endif