Skip to content

Commit

Permalink
Adapted all dynamic subscribers.
Browse files Browse the repository at this point in the history
  • Loading branch information
KerstinKeller committed May 14, 2024
1 parent 0b411e5 commit 2b4d506
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/mon/mon_cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_cli/src/ecal_mon_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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<google::protobuf::Message>& 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void PluginWidget::updatePublishTimeLabel()
////////////////////////////////////////////////////////////////////////////////

// eCAL Callback
void PluginWidget::onProtoMessageCallback(const std::shared_ptr<google::protobuf::Message> message, long long send_time_usecs)
void PluginWidget::onProtoMessageCallback(const std::shared_ptr<google::protobuf::Message>& message, long long send_time_usecs)
{

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private slots:
bool new_msg_available_;
int received_message_counter_;

void onProtoMessageCallback(const std::shared_ptr<google::protobuf::Message> message, long long send_time_usecs);
void onProtoMessageCallback(const std::shared_ptr<google::protobuf::Message>& message, long long send_time_usecs);
void onProtoErrorCallback(const std::string& error);
void updatePublishTimeLabel();

Expand Down
2 changes: 1 addition & 1 deletion app/mon/mon_plugins/signals_plotting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down
10 changes: 3 additions & 7 deletions app/mon/mon_plugins/signals_plotting/src/plugin_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ PluginWidget::~PluginWidget()

{
std::lock_guard<std::mutex> lock(proto_message_mutex_);
delete last_proto_message_;
last_proto_message_.reset();
}
}

Expand Down Expand Up @@ -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<google::protobuf::Message>& message, long long send_time_usecs)
{

{
// Lock the mutex
std::lock_guard<std::mutex> 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<eCAL::Time::ecal_clock::duration>(std::chrono::microseconds(send_time_usecs)));

Expand Down
8 changes: 4 additions & 4 deletions app/mon/mon_plugins/signals_plotting/src/plugin_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ private slots:
eCAL::protobuf::CProtoDecoder protobuf_decoder;
std::shared_ptr<ProtobufTreeBuilder> 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<google::protobuf::Message> 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_;
Expand All @@ -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<google::protobuf::Message>& message, long long send_time_usecs);
void onProtoErrorCallback(const std::string& error);
void updatePublishTimeLabel();
bool find_items(QAbstractTreeItem* tree_item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class TreeMessageVisitor : public MessageVisitor

}

void PopulateProtoTree(ftxui::TreeNode &root, google::protobuf::Message *message, const std::shared_ptr<StyleSheet> style)
void PopulateProtoTree(ftxui::TreeNode &root, const std::shared_ptr<google::protobuf::Message>& message, const std::shared_ptr<StyleSheet> style)
{
auto tree_builder = std::make_shared<eCAL::protobuf::TreeMessageVisitor>(root, style);
if(message)
Expand All @@ -272,7 +272,7 @@ void PopulateProtoTree(ftxui::TreeNode &root, google::protobuf::Message *message
}
}

ftxui::TreeNodePtr ProtoTree(google::protobuf::Message *message, const std::shared_ptr<StyleSheet> style)
ftxui::TreeNodePtr ProtoTree(const std::shared_ptr<google::protobuf::Message>& message, const std::shared_ptr<StyleSheet> style)
{
using namespace ftxui;
auto root = std::make_shared<TreeNode>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <string>
#include <functional>
#include <memory>
#include <mutex>

#include <ecal/ecal.h>
Expand All @@ -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<google::protobuf::Message> latest_message = nullptr;

void OnMessage(const google::protobuf::Message& message, long long send_time_usecs)
void OnMessage(const std::shared_ptr<google::protobuf::Message>& message, long long send_time_usecs)
{
{
std::lock_guard<std::mutex> lock(message_mtx);
delete latest_message;
latest_message = message.New();
latest_message->CopyFrom(message);
latest_message = message;

message_timestamp = send_time_usecs;
}
Expand All @@ -56,7 +55,7 @@ class ProtoMessageVisualizationViewModel : public MessageVisualizationViewModel
//NOTE: Use with caution!
struct ProtectedMessage
{
google::protobuf::Message *message;
std::shared_ptr<google::protobuf::Message> message;
std::unique_lock<std::mutex> lock;
};

Expand Down
3 changes: 0 additions & 3 deletions ecal/core/include/ecal/msg/protobuf/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@

#include <ecal/ecal_deprecate.h>
#include <ecal/ecal_client.h>
#include <ecal/msg/dynamic.h>
#include <ecal/msg/protobuf/ecal_proto_dyn.h>



// protobuf includes
#ifdef _MSC_VER
#pragma warning(push, 0) // disable proto warnings
Expand Down
1 change: 0 additions & 1 deletion ecal/core/include/ecal/msg/protobuf/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#pragma once

#include <ecal/ecal_server.h>
#include <ecal/msg/dynamic.h>
#include <ecal/msg/protobuf/ecal_proto_dyn.h>
#include <functional>

Expand Down

0 comments on commit 2b4d506

Please sign in to comment.