-
Notifications
You must be signed in to change notification settings - Fork 0
/
zeropublisher.h
55 lines (46 loc) · 1.25 KB
/
zeropublisher.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
#pragma once
#include "avtukccu.h"
#include <QMutex>
#include <QObject>
#include <QWaitCondition>
#include <gen/datatypes.h>
#include <queue>
#include <vector>
#include <zmq.hpp>
#define LOG_PROTOBUF
Q_DECLARE_METATYPE(AVTUK_CCU::Main);
Q_DECLARE_METATYPE(AVTUK_CCU::Indication);
class ZeroPublisher : public QObject
{
Q_OBJECT
public:
using itemType = std::pair<std::string, std::string>;
using queueType = std::queue<itemType>;
explicit ZeroPublisher(const QString &type, zmq::context_t &ctx, int sock_type, QObject *parent = nullptr);
void work();
void stop()
{
is_active = false;
}
signals:
public slots:
void publishTime(const timespec &time);
void publishPowerStatus(const AVTUK_CCU::Main powerStatus);
void publishBlock(const DataTypes::BlockStruct blk);
void publishHello();
void publishNtpStatus(bool status);
void publishHealthQuery();
void publishPingReply();
private:
zmq::context_t &_ctx;
zmq::socket_t _worker;
QMutex _mutex;
QWaitCondition _waiter;
bool is_active = true;
queueType _queue;
QString m_typeString;
std::string m_type;
void send(itemType &str);
void checkQueue();
template <typename T> void appendToQueue(const T &paylod);
};