Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template class for CMessageSubscriber (instead of CMsgSubscriber) #1582

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/mon/mon_cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down 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
4 changes: 2 additions & 2 deletions app/mon/mon_cli/src/ecal_mon_cli.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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
4 changes: 3 additions & 1 deletion app/mon/mon_plugins/capnproto_reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,6 +67,8 @@ target_link_libraries (${PROJECT_NAME}
eCAL::mon_plugin_lib
MonitorTreeView
)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)

target_link_options(${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/ignore:4099>)

target_include_directories(${PROJECT_NAME} PRIVATE src)
Expand Down
4 changes: 2 additions & 2 deletions app/mon/mon_plugins/protobuf_reflection/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,7 +69,7 @@ target_link_libraries (${PROJECT_NAME}
MonitorTreeView
eCAL::mon_plugin_lib
)
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
12 changes: 4 additions & 8 deletions app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -110,7 +110,7 @@ PluginWidget::~PluginWidget()

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

Expand Down Expand Up @@ -157,19 +157,15 @@ void PluginWidget::updatePublishTimeLabel()
////////////////////////////////////////////////////////////////////////////////

// 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
14 changes: 7 additions & 7 deletions app/mon/mon_plugins/protobuf_reflection/src/plugin_widget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -68,11 +68,11 @@ 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_;
QString last_error_string_;
bool last_message_was_error_;
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_;

bool currently_showing_error_item_;
int error_counter_;
Expand All @@ -83,7 +83,7 @@ private slots:
bool new_msg_available_;
int received_message_counter_;

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();

Expand Down
4 changes: 2 additions & 2 deletions app/mon/mon_plugins/signals_plotting/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down 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
12 changes: 4 additions & 8 deletions app/mon/mon_plugins/signals_plotting/src/plugin_widget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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
10 changes: 5 additions & 5 deletions app/mon/mon_plugins/signals_plotting/src/plugin_widget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'PopulateProtoTree' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]

void PopulateProtoTree(ftxui::TreeNode &root, const std::shared_ptr<google::protobuf::Message>& message, const std::shared_ptr<StyleSheet> style)
     ^
Additional context

app/mon/mon_tui/src/tui/view/message_visualization/proto_tree.hpp:263: make as 'inline'

void PopulateProtoTree(ftxui::TreeNode &root, const std::shared_ptr<google::protobuf::Message>& message, const std::shared_ptr<StyleSheet> style)
     ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the const qualified parameter 'style' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param]

Suggested change
void PopulateProtoTree(ftxui::TreeNode &root, const std::shared_ptr<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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'ProtoTree' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]

ftxui::TreeNodePtr ProtoTree(const std::shared_ptr<google::protobuf::Message>& message, const std::shared_ptr<StyleSheet> style)
                   ^
Additional context

app/mon/mon_tui/src/tui/view/message_visualization/proto_tree.hpp:274: make as 'inline'

ftxui::TreeNodePtr ProtoTree(const std::shared_ptr<google::protobuf::Message>& message, const std::shared_ptr<StyleSheet> style)
                   ^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the const qualified parameter 'style' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param]

Suggested change
ftxui::TreeNodePtr ProtoTree(const std::shared_ptr<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
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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
13 changes: 12 additions & 1 deletion ecal/core/include/ecal/ecal_types.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@

#pragma once
#include <string>
#include <tuple>

namespace eCAL
{
Expand All @@ -47,6 +48,11 @@ namespace eCAL
{
return !(*this == other);
}

bool operator<(const SDataTypeInformation& rhs) const
{
return std::tie(name, encoding, descriptor) < std::tie(rhs.name, rhs.encoding, rhs.descriptor);
}
//!< @endcond
};

Expand All @@ -69,6 +75,11 @@ namespace eCAL
{
return !(*this == other);
}

bool operator<(const SServiceMethodInformation& rhs) const
{
return std::tie(request_type, response_type) < std::tie(rhs.request_type, rhs.response_type);
}
//!< @endcond
};
}
Loading
Loading