forked from wklenk/lmic-rpi-lora-gps-hat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMQTTDataStreamer.hpp
77 lines (68 loc) · 2.17 KB
/
MQTTDataStreamer.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
76
77
/**
* @file MQTTDataStreamer.hpp
* @author Dominik Kuhn ([email protected])
* @brief
* @version 0.1
* @date 2021-08-23
*
* @copyright Copyright (c) 2021
*
*/
#ifndef MQTTDataStreamer_MQTTDATASTREAMER_HH
#define MQTTDataStreamer_MQTTDATASTREAMER_HH
#include <string>
#include <mutex>
#include <cstdint>
#include <chrono>
#include <tuple>
#include "mqtt/async_client.h"
#include "HelperClasses.hpp"
/*
* This is much simpler way of combining client and
* its corresponding callback. Refer to HelperClasses.hh
* to learn more about Callback class.
*/
using MqttAsyncTuple = std::tuple<mqtt::async_client_ptr,
mqtt::callback_ptr>;
class MQTTDataStreamer {
/*
* This classes acts as an wrapper for the mqtt_async_client
* class provided by the paho.mqtt.cpp library. It is meant
* to make usage of paho.mqtt.cpp library easier. I(Nirmal) dunno
* if that goal has been acheived though.
*/
MqttAsyncTuple mqtt_async_tuple;
std::chrono::milliseconds timeout;
/*
* All the meaning in the following functions
* have a predefinied meaning that are borrowed directly
* from the paho.mqtt.cpp library. Besides the name of the
* variables are pretty descriptive enough
*/
mqtt::message_ptr createMessage(const void* payload,
std::size_t len, const std::string& topic,
uint8_t QoS, bool retain_msg = false);
mqtt::connect_options buildConnectOptions();
public:
MQTTDataStreamer() = delete;
// the default value of timeout is chosen from experiments
// DO NOT TRUST IT.
MQTTDataStreamer(
MqttAsyncTuple mqtt_async_tuple_,
std::chrono::milliseconds timeout_ = std::chrono::milliseconds(500));
~MQTTDataStreamer();
/*
* The mutex here is used to make sure that
* this function is thread-safe. Refer to test.cc
* in OpenCVImageSender project to learn more about why
* this might be needed.
*/
void publishMessage(
const void* payload,
std::size_t len,
std::string topic,
uint8_t QoS,
std::mutex* mut,
const std::string& debug_info);
};
#endif