2 #include "ui_datastream_mqtt.h"
7 #include <QIntValidator>
15 QMessageBox::warning(
nullptr,
"MQTT error",
26 _mosq = std::make_shared<MQTTClient>();
49 QMessageBox::warning(
nullptr, tr(
"MQTT Client"), tr(
"No available MessageParsers"),
55 bool first_start =
_dialog->
ui->comboBoxProtocol->count() == 0;
62 _dialog->
ui->comboBoxProtocol->addItem(it.first);
64 if (
auto widget = it.second->optionsWidget())
66 widget->setVisible(
false);
67 _dialog->
ui->layoutOptions->addWidget(widget);
72 qOverload<const QString&>(&QComboBox::currentIndexChanged),
this,
79 _protocol = settings.value(
"MosquittoMQTT::serialization_protocol",
"JSON").toString();
82 if (
_dialog->exec() == QDialog::Rejected)
89 for (
const auto&
topic :
_mosq->config().topics)
94 for (
const auto& item :
_dialog->
ui->listWidget->selectedItems())
100 std::string topic_name = item->text().toStdString();
101 _mosq->subscribe(topic_name,
_mosq->config().qos);
102 _mosq->addMessageCallback(topic_name, callback);
131 prev_widget->setVisible(
false);
138 widget->setVisible(
true);
144 std::unique_lock<std::mutex> lk(
mutex());
146 auto it =
_parsers.find(message->topic);
150 auto parser = parser_factory->createParser({ message->topic }, {}, {},
dataMap());
153 auto&
parser = it->second;
158 MessageRef msg(
static_cast<uint8_t*
>(message->payload), message->payloadlen);
160 using namespace std::chrono;
161 auto ts = high_resolution_clock::now().time_since_epoch();
162 double timestamp = 1e-6 * double(duration_cast<microseconds>(ts).
count());
164 result =
parser->parseMessage(
msg, timestamp);
166 catch (std::exception&)