@@ -26,13 +26,13 @@ namespace Everest {
26
26
const auto mqtt_keep_alive = 600 ;
27
27
28
28
MessageWithQOS::MessageWithQOS (const std::string& topic, const std::string& payload, QOS qos) :
29
- Message ( topic, payload) , qos(qos) {
29
+ Message{ topic, payload} , qos(qos) {
30
30
}
31
31
32
32
MQTTAbstractionImpl::MQTTAbstractionImpl (const std::string& mqtt_server_address, const std::string& mqtt_server_port,
33
33
const std::string& mqtt_everest_prefix,
34
34
const std::string& mqtt_external_prefix) :
35
- message_queue (([this ](std::shared_ptr< Message> message) { this ->on_mqtt_message (message); })),
35
+ message_queue (([this ](const Message& message) { this ->on_mqtt_message (message); })),
36
36
mqtt_server_address (mqtt_server_address),
37
37
mqtt_server_port (mqtt_server_port),
38
38
mqtt_everest_prefix (mqtt_everest_prefix),
@@ -57,7 +57,7 @@ MQTTAbstractionImpl::MQTTAbstractionImpl(const std::string& mqtt_server_address,
57
57
MQTTAbstractionImpl::MQTTAbstractionImpl (const std::string& mqtt_server_socket_path,
58
58
const std::string& mqtt_everest_prefix,
59
59
const std::string& mqtt_external_prefix) :
60
- message_queue (([this ](std::shared_ptr< Message> message) { this ->on_mqtt_message (message); })),
60
+ message_queue (([this ](const Message& message) { this ->on_mqtt_message (message); })),
61
61
mqtt_server_socket_path (mqtt_server_socket_path),
62
62
mqtt_everest_prefix (mqtt_everest_prefix),
63
63
mqtt_external_prefix (mqtt_external_prefix),
@@ -265,28 +265,28 @@ std::future<void> MQTTAbstractionImpl::spawn_main_loop_thread() {
265
265
return future;
266
266
}
267
267
268
- void MQTTAbstractionImpl::on_mqtt_message (std::shared_ptr< Message> message) {
268
+ void MQTTAbstractionImpl::on_mqtt_message (const Message& message) {
269
269
BOOST_LOG_FUNCTION ();
270
270
271
- const std::string & topic = message-> topic ;
272
- const std::string & payload = message-> payload ;
271
+ const auto & topic = message. topic ;
272
+ const auto & payload = message. payload ;
273
273
274
274
try {
275
- std::shared_ptr< json> data;
275
+ json data;
276
276
bool is_everest_topic = false ;
277
277
if (topic.find (mqtt_everest_prefix) == 0 ) {
278
278
EVLOG_verbose << fmt::format (" topic {} starts with {}" , topic, mqtt_everest_prefix);
279
279
is_everest_topic = true ;
280
280
try {
281
- data = std::make_shared< json>( json ::parse (payload) );
281
+ data = json::parse (payload);
282
282
} catch (nlohmann::detail::parse_error& e) {
283
283
EVLOG_warning << fmt::format (" Could not decode json for incoming topic '{}': {}" , topic, payload);
284
284
return ;
285
285
}
286
286
} else {
287
287
EVLOG_debug << fmt::format (" Message parsing for topic '{}' not implemented. Wrapping in json object." ,
288
288
topic);
289
- data = std::make_shared< json>( json ( payload) );
289
+ data = json ( payload);
290
290
}
291
291
292
292
bool found = false ;
@@ -306,7 +306,7 @@ void MQTTAbstractionImpl::on_mqtt_message(std::shared_ptr<Message> message) {
306
306
307
307
if (topic_matches) {
308
308
found = true ;
309
- handler.add ({topic, data} );
309
+ handler.add (std::unique_ptr<ParsedMessage>( new ParsedMessage {topic, std::move ( data)}) );
310
310
}
311
311
}
312
312
lock.unlock ();
@@ -642,9 +642,9 @@ void MQTTAbstractionImpl::publish_callback(void** state, struct mqtt_response_pu
642
642
auto message_queue = static_cast <MessageQueue*>(*state);
643
643
644
644
// topic_name and application_message are NOT null-terminated, hence copy construct strings
645
- message_queue->add (std::make_shared <Message>(
645
+ message_queue->add (std::unique_ptr <Message>(new Message{
646
646
std::string (static_cast <const char *>(published->topic_name ), published->topic_name_size ),
647
- std::string (static_cast <const char *>(published->application_message ), published->application_message_size )));
647
+ std::string (static_cast <const char *>(published->application_message ), published->application_message_size )} ));
648
648
}
649
649
650
650
} // namespace Everest
0 commit comments