@@ -22,11 +22,23 @@ FASTLIB_LOG_SET_LEVEL_GLOBAL(comm_log, trace);
2222namespace fast {
2323
2424// / Helper function to make error codes human readable.
25- std::string mosq_err_string (const std::string &str, int code)
25+ static std::string mosq_err_string (const std::string &str, int code)
2626{
2727 return str + mosqpp::strerror (code);
2828}
2929
30+ // / Helper function to convert a given topic into a regular expression
31+ static std::regex topic_to_regex (const std::string &topic)
32+ {
33+ // Replace "+" by "[^/]*"
34+ auto regex_topic = std::regex_replace (topic, std::regex (R"( (\+))" ), R"( [^/]*)" );
35+ // Replace "#" by "[^/]*(?:/[^/]*)*$"
36+ regex_topic = std::regex_replace (regex_topic, std::regex (R"( (#))" ), R"( [^/]*(?:/[^/]*)*$)" );
37+ return std::regex (regex_topic);
38+ }
39+
40+
41+
3042class MQTT_subscription
3143{
3244public:
@@ -249,15 +261,6 @@ void MQTT_communicator::on_disconnect(int rc)
249261}
250262
251263
252- std::regex topic_to_regex (const std::string &topic)
253- {
254- // Replace "+" by "[^/]*"
255- auto regex_topic = std::regex_replace (topic, std::regex (R"( (\+))" ), R"( [^/]*)" );
256- // Replace "#" by "[^/]*(?:/[^/]*)*$"
257- regex_topic = std::regex_replace (regex_topic, std::regex (R"( (#))" ), R"( [^/]*(?:/[^/]*)*$)" );
258- return std::regex (regex_topic);
259- }
260-
261264void MQTT_communicator::on_message (const mosquitto_message *msg)
262265{
263266 FASTLIB_LOG (comm_log, trace) << " Callback: on_message with topic: " << msg->topic ;
@@ -294,7 +297,7 @@ void MQTT_communicator::send_message(const std::string &message, const std::stri
294297 // Use default topic if empty string is passed.
295298 auto &real_topic = topic == " " ? default_publish_topic : topic;
296299 // Publish message to topic.
297- int ret = publish (nullptr , real_topic.c_str (), message.size (), message.c_str (), qos, false );
300+ int ret = publish (nullptr , real_topic.c_str (), static_cast < int >( message.size () ), message.c_str (), qos, false );
298301 if (ret != MOSQ_ERR_SUCCESS)
299302 throw std::runtime_error (mosq_err_string (" Error sending message: " , ret));
300303 FASTLIB_LOG (comm_log, trace) << " Message sent to topic " << real_topic << " ." ;
@@ -325,10 +328,9 @@ std::string MQTT_communicator::get_message(const std::string &topic, const std::
325328 auto &subscription = subscriptions.at (topic);
326329 lock.unlock ();
327330 return subscription->get_message (duration, actual_topic);
328- } catch (const std::out_of_range &e ) {
331+ } catch (const std::out_of_range /* &e */ ) {
329332 throw std::out_of_range (" Topic not found in subscriptions." );
330333 }
331- FASTLIB_LOG (comm_log, trace) << " Message got." ;
332334}
333335
334336
0 commit comments