-
Notifications
You must be signed in to change notification settings - Fork 9
/
MqttPublisher_Paho.hpp
75 lines (60 loc) · 2.27 KB
/
MqttPublisher_Paho.hpp
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2019-2023 (c) Christian von Arnim, ISW University of Stuttgart (for umati and VDW e.V.)
* Copyright 2020 (c) Dominik Basner, Sotec GmbH (for VDW e.V.)
* Copyright 2023 (c) Marc Fischer, ISW University of Stuttgart (for umati and VDW e.V.)
*/
#pragma once
#include <random>
#include <string>
#include <thread>
#include <chrono>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <IPublisher.hpp>
#include <mqtt/async_client.h>
namespace Umati {
namespace MqttPublisher_Paho {
class MqttPublisher_Paho : public Umati::Dashboard::IPublisher {
public:
MqttPublisher_Paho(
const std::string &protocol,
const std::string &host,
std::uint16_t port,
const std::string &CaCertPath,
const std::string &CaTrustStorePath,
const std::string &onlineTopic = std::string(),
const std::string &versionTopic = std::string(),
const std::string &gitClientVersion = std::string(),
const std::string &username = std::string(),
const std::string &password = std::string(),
const std::string &httpProxy = std::string(),
const std::string &httpsProxy = std::string());
virtual ~MqttPublisher_Paho();
// Inherit from IPublisher
void Publish(std::string channel, std::string message) override;
private:
static std::string getClientId();
mqtt::will_options getLastWill() const;
static mqtt::connect_options getOptions(const std::string &username, const std::string &password);
static std::string getUri(std::string protocol, std::string host, std::uint16_t port);
class MqttCallbacks : public mqtt::callback {
friend class MqttPublisher_Paho;
public:
MqttCallbacks(MqttPublisher_Paho *mqttPublisher_paho);
void connected(const std::string &cause) override;
void connection_lost(const std::string &cause) override;
MqttPublisher_Paho *m_mqttPublisher_paho;
};
mqtt::async_client m_cli;
MqttCallbacks m_callbacks;
const std::string m_onlineTopic;
const std::string m_versionTopic;
const std::string m_gitClientVersion;
};
} // namespace MqttPublisher_Paho
} // namespace Umati