Skip to content

Commit e41c316

Browse files
committed
Add Message ctor and use make_unique
Use topic available at subscribe time instead of receive time to better handle wildcards Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
1 parent 9992496 commit e41c316

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/everest/framework/include/utils/message_queue.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace Everest {
2222
struct Message {
2323
std::string topic; ///< The MQTT topic where this message originated from
2424
std::string payload; ///< The message payload
25+
26+
Message(const std::string& topic_, const std::string& payload_) : topic(topic_), payload(payload_) {}
2527
};
2628

2729
struct ParsedMessage {

lib/everest/framework/lib/mqtt_abstraction_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ void MQTTAbstractionImpl::subscribe(const std::string& topic, QOS qos) {
203203

204204
const auto result = this->mqtt_client->subscribe(
205205
topic,
206-
[this](everest::lib::io::mqtt::mosquitto_cpp& client,
206+
[this, topic](everest::lib::io::mqtt::mosquitto_cpp& client,
207207
everest::lib::io::mqtt::mosquitto_cpp::message const& message) {
208-
this->message_queue.add(std::unique_ptr<Message>(new Message{message.topic, message.payload}));
208+
this->message_queue.add(std::make_unique<Message>(topic, message.payload));
209209
},
210210
max_qos_level);
211211
}

0 commit comments

Comments
 (0)