From 2b4d5062f22474cc9442fccc4ca4f9c8eb279c11 Mon Sep 17 00:00:00 2001 From: Kerstin Keller Date: Tue, 14 May 2024 19:40:02 +0200 Subject: [PATCH] Adapted all dynamic subscribers. --- app/mon/mon_cli/CMakeLists.txt | 2 +- app/mon/mon_cli/src/ecal_mon_cli.cpp | 2 +- .../protobuf_reflection/src/plugin_widget.cpp | 2 +- .../protobuf_reflection/src/plugin_widget.h | 2 +- app/mon/mon_plugins/signals_plotting/CMakeLists.txt | 2 +- .../signals_plotting/src/plugin_widget.cpp | 10 +++------- .../mon_plugins/signals_plotting/src/plugin_widget.h | 8 ++++---- .../src/tui/view/message_visualization/proto_tree.hpp | 4 ++-- .../src/tui/viewmodel/message_visualization/proto.hpp | 11 +++++------ ecal/core/include/ecal/msg/protobuf/client.h | 3 --- ecal/core/include/ecal/msg/protobuf/server.h | 1 - 11 files changed, 19 insertions(+), 28 deletions(-) diff --git a/app/mon/mon_cli/CMakeLists.txt b/app/mon/mon_cli/CMakeLists.txt index 3b99c47dae..c93e12f3a5 100644 --- a/app/mon/mon_cli/CMakeLists.txt +++ b/app/mon/mon_cli/CMakeLists.txt @@ -45,7 +45,7 @@ target_link_libraries(${PROJECT_NAME} tclap::tclap eCAL::core_protobuf eCAL::core_pb) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) ecal_install_app(${PROJECT_NAME}) diff --git a/app/mon/mon_cli/src/ecal_mon_cli.cpp b/app/mon/mon_cli/src/ecal_mon_cli.cpp index afa6727f04..ec5c39f5c9 100644 --- a/app/mon/mon_cli/src/ecal_mon_cli.cpp +++ b/app/mon/mon_cli/src/ecal_mon_cli.cpp @@ -363,7 +363,7 @@ void ProcProto(const std::string& topic_name, int msg_count) // create dynamic subscribers for receiving and decoding messages and assign callback eCAL::protobuf::CDynamicSubscriber sub(topic_name); std::atomic cnt(msg_count); - auto msg_cb = [&cnt](const google::protobuf::Message& msg_) { if (cnt != 0) { std::cout << msg_.DebugString() << std::endl; if (cnt > 0) cnt--; } }; + auto msg_cb = [&cnt](const std::shared_ptr& msg_) { if (cnt != 0) { std::cout << msg_->DebugString() << std::endl; if (cnt > 0) cnt--; } }; sub.AddReceiveCallback(std::bind(msg_cb, std::placeholders::_2)); // enter main loop diff --git a/app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.cpp b/app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.cpp index a743291133..3c932da04a 100644 --- a/app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.cpp +++ b/app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.cpp @@ -157,7 +157,7 @@ void PluginWidget::updatePublishTimeLabel() //////////////////////////////////////////////////////////////////////////////// // eCAL Callback -void PluginWidget::onProtoMessageCallback(const std::shared_ptr message, long long send_time_usecs) +void PluginWidget::onProtoMessageCallback(const std::shared_ptr& message, long long send_time_usecs) { { diff --git a/app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.h b/app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.h index 4b303282d0..98e63c4c02 100644 --- a/app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.h +++ b/app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.h @@ -83,7 +83,7 @@ private slots: bool new_msg_available_; int received_message_counter_; - void onProtoMessageCallback(const std::shared_ptr message, long long send_time_usecs); + void onProtoMessageCallback(const std::shared_ptr& message, long long send_time_usecs); void onProtoErrorCallback(const std::string& error); void updatePublishTimeLabel(); diff --git a/app/mon/mon_plugins/signals_plotting/CMakeLists.txt b/app/mon/mon_plugins/signals_plotting/CMakeLists.txt index e668f0bcef..bbdd4de7cb 100644 --- a/app/mon/mon_plugins/signals_plotting/CMakeLists.txt +++ b/app/mon/mon_plugins/signals_plotting/CMakeLists.txt @@ -84,7 +84,7 @@ target_link_libraries (${PROJECT_NAME} CustomQt ) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) if(MSVC) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/wd4127 /wd4714" ) diff --git a/app/mon/mon_plugins/signals_plotting/src/plugin_widget.cpp b/app/mon/mon_plugins/signals_plotting/src/plugin_widget.cpp index 80f8347b47..f51b403503 100644 --- a/app/mon/mon_plugins/signals_plotting/src/plugin_widget.cpp +++ b/app/mon/mon_plugins/signals_plotting/src/plugin_widget.cpp @@ -132,7 +132,7 @@ PluginWidget::~PluginWidget() { std::lock_guard lock(proto_message_mutex_); - delete last_proto_message_; + last_proto_message_.reset(); } } @@ -256,19 +256,15 @@ void PluginWidget::setVisibleSplitterHandle(bool state) //////////////////////////////////////////////////////////////////////////////// // eCAL Callback -void PluginWidget::onProtoMessageCallback(const google::protobuf::Message& message, long long send_time_usecs) +void PluginWidget::onProtoMessageCallback(const std::shared_ptr& message, long long send_time_usecs) { { // Lock the mutex std::lock_guard lock(proto_message_mutex_); - // Delete the old message - delete last_proto_message_; - // Create a copy of the new message as member variable. We cannot use a reference here, as this may cause a deadlock with the GUI thread - last_proto_message_ = message.New(); - last_proto_message_->CopyFrom(message); + last_proto_message_ = message; last_message_publish_timestamp_ = eCAL::Time::ecal_clock::time_point(std::chrono::duration_cast(std::chrono::microseconds(send_time_usecs))); diff --git a/app/mon/mon_plugins/signals_plotting/src/plugin_widget.h b/app/mon/mon_plugins/signals_plotting/src/plugin_widget.h index e10787c4ee..5925162420 100644 --- a/app/mon/mon_plugins/signals_plotting/src/plugin_widget.h +++ b/app/mon/mon_plugins/signals_plotting/src/plugin_widget.h @@ -102,9 +102,9 @@ private slots: eCAL::protobuf::CProtoDecoder protobuf_decoder; std::shared_ptr protobuf_tree_builder; - std::mutex proto_message_mutex_; - google::protobuf::Message* last_proto_message_; - eCAL::Time::ecal_clock::time_point last_message_publish_timestamp_; + std::mutex proto_message_mutex_; + std::shared_ptr last_proto_message_; + eCAL::Time::ecal_clock::time_point last_message_publish_timestamp_; QString last_error_string_; bool last_message_was_error_; int error_counter_; @@ -119,7 +119,7 @@ private slots: QString key_to_close_; - void onProtoMessageCallback(const google::protobuf::Message& message, long long send_time_usecs); + void onProtoMessageCallback(const std::shared_ptr& message, long long send_time_usecs); void onProtoErrorCallback(const std::string& error); void updatePublishTimeLabel(); bool find_items(QAbstractTreeItem* tree_item); diff --git a/app/mon/mon_tui/src/tui/view/message_visualization/proto_tree.hpp b/app/mon/mon_tui/src/tui/view/message_visualization/proto_tree.hpp index 9864bafff7..b65d7eaddc 100644 --- a/app/mon/mon_tui/src/tui/view/message_visualization/proto_tree.hpp +++ b/app/mon/mon_tui/src/tui/view/message_visualization/proto_tree.hpp @@ -261,7 +261,7 @@ class TreeMessageVisitor : public MessageVisitor } -void PopulateProtoTree(ftxui::TreeNode &root, google::protobuf::Message *message, const std::shared_ptr style) +void PopulateProtoTree(ftxui::TreeNode &root, const std::shared_ptr& message, const std::shared_ptr style) { auto tree_builder = std::make_shared(root, style); if(message) @@ -272,7 +272,7 @@ void PopulateProtoTree(ftxui::TreeNode &root, google::protobuf::Message *message } } -ftxui::TreeNodePtr ProtoTree(google::protobuf::Message *message, const std::shared_ptr style) +ftxui::TreeNodePtr ProtoTree(const std::shared_ptr& message, const std::shared_ptr style) { using namespace ftxui; auto root = std::make_shared(); diff --git a/app/mon/mon_tui/src/tui/viewmodel/message_visualization/proto.hpp b/app/mon/mon_tui/src/tui/viewmodel/message_visualization/proto.hpp index 1a170baf1d..7208280893 100644 --- a/app/mon/mon_tui/src/tui/viewmodel/message_visualization/proto.hpp +++ b/app/mon/mon_tui/src/tui/viewmodel/message_visualization/proto.hpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -35,15 +36,13 @@ class ProtoMessageVisualizationViewModel : public MessageVisualizationViewModel eCAL::protobuf::CDynamicSubscriber subscriber; mutable std::mutex message_mtx; - google::protobuf::Message *latest_message = nullptr; + std::shared_ptr latest_message = nullptr; - void OnMessage(const google::protobuf::Message& message, long long send_time_usecs) + void OnMessage(const std::shared_ptr& message, long long send_time_usecs) { { std::lock_guard lock(message_mtx); - delete latest_message; - latest_message = message.New(); - latest_message->CopyFrom(message); + latest_message = message; message_timestamp = send_time_usecs; } @@ -56,7 +55,7 @@ class ProtoMessageVisualizationViewModel : public MessageVisualizationViewModel //NOTE: Use with caution! struct ProtectedMessage { - google::protobuf::Message *message; + std::shared_ptr message; std::unique_lock lock; }; diff --git a/ecal/core/include/ecal/msg/protobuf/client.h b/ecal/core/include/ecal/msg/protobuf/client.h index 66c4c7db0f..785f100219 100644 --- a/ecal/core/include/ecal/msg/protobuf/client.h +++ b/ecal/core/include/ecal/msg/protobuf/client.h @@ -26,11 +26,8 @@ #include #include -#include #include - - // protobuf includes #ifdef _MSC_VER #pragma warning(push, 0) // disable proto warnings diff --git a/ecal/core/include/ecal/msg/protobuf/server.h b/ecal/core/include/ecal/msg/protobuf/server.h index cb0eb87a73..fb905055fc 100644 --- a/ecal/core/include/ecal/msg/protobuf/server.h +++ b/ecal/core/include/ecal/msg/protobuf/server.h @@ -25,7 +25,6 @@ #pragma once #include -#include #include #include