Commit 2390c393 authored by Leander Schulten's avatar Leander Schulten

Fixed fucking dangling reference due to copy paste error

parent 1e0c8069
Pipeline #272777 passed with stage
in 12 minutes and 18 seconds
......@@ -8,14 +8,11 @@ Modules::MqttImpl::MqttImpl() {
ModuleManager::singletone()->controller().runInController([this]() {
client = std::make_unique<QMqttClient>();
QObject::connect(client.get(), &QMqttClient::connected, [this] {
qDebug() << this << " gets connected";
qDebug() << "finished from " << QThread::currentThread();
for (const auto &i : queried) {
if (client->state() != QMqttClient::Connected) {
// maybe we lose connection. Then we don't want to crash (subscribe adds than to queried)
return;
}
qDebug() << "topic " << i.first.c_str();
subscribe(i.first, i.second);
}
queried.clear();
......@@ -35,7 +32,6 @@ Modules::MqttImpl::MqttImpl() {
Modules::MqttImpl::~MqttImpl() {
ModuleManager::singletone()->controller().runInController([c = client.release()] { delete c; });
qDebug() << this << " gets destroyed";
}
void Modules::MqttImpl::setLastWillMessage(const std::string &topic, const std::string &message, bool retain) {
......@@ -62,19 +58,12 @@ void Modules::MqttImpl::publishMessage(const std::string &topic, const std::stri
void Modules::MqttImpl::publishValue(const std::string &topic, const std::string &message) { publish(topic, message, true); }
void Modules::MqttImpl::subscribe(const std::string &topic, std::function<void(std::string)> callback) {
qDebug() << "sub from " << QThread::currentThread() << this << test;
if (!client || client->state() != QMqttClient::Connected) {
// when not yet connected, wait for a connection and add than
qDebug() << "topic : " << topic.c_str();
queried.emplace_back(topic, callback);
for (auto i : queried) {
qDebug() << "topic : " << i.first.c_str();
}
test = 200;
return;
}
auto funcPointer = callback.target_type().name();
qDebug() << "topic : " << topic.c_str();
if (callbacks.find(std::make_pair(topic, funcPointer)) != callbacks.end()) {
// prevent double registrations of callbacks for the same topic
return;
......
......@@ -16,8 +16,7 @@ class MqttImpl : public detail::IMqttClientImpl {
std::optional<std::tuple<QString, QByteArray, bool>> lastWillDelayed;
std::optional<std::tuple<QString, int>> connectDelayed;
std::set<std::pair<std::string, const char *>> callbacks;
std::vector<std::pair<const std::string &, std::function<void(std::string)>>> queried;
int test = -1;
std::vector<std::pair<std::string, std::function<void(std::string)>>> queried;
public:
MqttImpl();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment