Skip to content

Commit

Permalink
separate send module for log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Dec 5, 2023
1 parent 82c4237 commit 94eca56
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 15 deletions.
2 changes: 2 additions & 0 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ set(ecal_io_udp_protobuf_src
src/io/udp/protobuf/rcv_logging.h
src/io/udp/protobuf/rcv_sample.cpp
src/io/udp/protobuf/rcv_sample.h
src/io/udp/protobuf/snd_logging.cpp
src/io/udp/protobuf/snd_logging.h
src/io/udp/protobuf/snd_sample.cpp
src/io/udp/protobuf/snd_sample.h
)
Expand Down
45 changes: 45 additions & 0 deletions ecal/core/src/io/udp/protobuf/snd_logging.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================= eCAL LICENSE =================================
*/

/**
* @brief UDP logging sender to send messages of type eCAL::pb::LogMessage
**/

#include "snd_logging.h"

namespace eCAL
{
CLoggingSender::CLoggingSender(const SSenderAttr& attr_)
{
m_udp_sender = std::make_shared<CUDPSender>(attr_);
}

size_t CLoggingSender::Send(const eCAL::pb::LogMessage& ecal_log_message_)
{
if (!m_udp_sender) return(0);

std::string ecal_log_message_s = ecal_log_message_.SerializeAsString();
if (!ecal_log_message_s.empty())
{
return m_udp_sender->Send((void*)ecal_log_message_s.data(), ecal_log_message_s.size());
}

return 0;
}
}
50 changes: 50 additions & 0 deletions ecal/core/src/io/udp/protobuf/snd_logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ========================= eCAL LICENSE =================================
*/

/**
* @brief UDP logging sender to send messages of type eCAL::pb::LogMessage
**/

#pragma once

#include <memory>

#include "io/udp/udp_sender.h"

#ifdef _MSC_VER
#pragma warning(push, 0) // disable proto warnings
#endif
#include <ecal/core/pb/monitoring.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

namespace eCAL
{
class CLoggingSender
{
public:
CLoggingSender(const SSenderAttr& attr_);
size_t Send(const eCAL::pb::LogMessage& ecal_log_message_);

private:
SSenderAttr m_attr;
std::shared_ptr<eCAL::CUDPSender> m_udp_sender;
};
}
2 changes: 1 addition & 1 deletion ecal/core/src/io/udp/protobuf/snd_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace eCAL
m_udp_sender = std::make_shared<CUDPSender>(attr_);
}

size_t CSampleSender::SendSample(const std::string& sample_name_, const eCAL::pb::Sample& ecal_sample_, long bandwidth_)
size_t CSampleSender::Send(const std::string& sample_name_, const eCAL::pb::Sample& ecal_sample_, long bandwidth_)
{
if (!m_udp_sender) return(0);

Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/io/udp/protobuf/snd_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace eCAL
{
public:
CSampleSender(const SSenderAttr& attr_);
size_t SendSample(const std::string& sample_name_, const eCAL::pb::Sample& ecal_sample_, long bandwidth_);
size_t Send(const std::string& sample_name_, const eCAL::pb::Sample& ecal_sample_, long bandwidth_);

private:
SSenderAttr m_attr;
Expand Down
2 changes: 2 additions & 0 deletions ecal/core/src/io/udp/udp_receiver_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/


#include <ecal/ecal_config.h>

#include "io/udp/udp_receiver_asio.h"

#ifdef __linux__
Expand Down
14 changes: 6 additions & 8 deletions ecal/core/src/logging/ecal_log_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace eCAL
attr.sndbuf = Config::GetUdpMulticastSndBufSizeBytes();

// create udp logging sender
m_udp_sender = std::make_unique<CUDPSender>(attr);
m_udp_logging_sender = std::make_unique<CLoggingSender>(attr);
}

// set logging receive network attributes
Expand All @@ -181,7 +181,7 @@ namespace eCAL

const std::lock_guard<std::mutex> lock(m_log_sync);

m_udp_sender.reset();
m_udp_logging_sender.reset();

if(m_logfile != nullptr) fclose(m_logfile);
m_logfile = nullptr;
Expand Down Expand Up @@ -271,8 +271,9 @@ namespace eCAL
fflush(m_logfile);
}

if((log_udp != 0) && m_udp_sender)
if((log_udp != 0) && m_udp_logging_sender)
{
// set up log message
ecal_msg.Clear();
ecal_msg.set_time(std::chrono::duration_cast<std::chrono::microseconds>(log_time.time_since_epoch()).count());
ecal_msg.set_hname(m_hname);
Expand All @@ -282,11 +283,8 @@ namespace eCAL
ecal_msg.set_level(level_);
ecal_msg.set_content(msg_);

ecal_msg_s = ecal_msg.SerializeAsString();
if(!ecal_msg_s.empty())
{
m_udp_sender->Send((void*)ecal_msg_s.data(), ecal_msg_s.size());
}
// sent it
m_udp_logging_sender->Send(ecal_msg);
}
}

Expand Down
4 changes: 2 additions & 2 deletions ecal/core/src/logging/ecal_log_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

#pragma once

#include "io/udp/udp_sender.h"
#include "io/udp/protobuf/rcv_logging.h"
#include "io/udp/protobuf/snd_logging.h"

#include <ecal/ecal.h>
#include <ecal/ecal_os.h>
Expand Down Expand Up @@ -128,7 +128,7 @@ namespace eCAL
std::mutex m_log_sync;

std::atomic<bool> m_created;
std::unique_ptr<CUDPSender> m_udp_sender;
std::unique_ptr<CLoggingSender> m_udp_logging_sender;

// log messages
using LogMessageListT = std::list<eCAL::pb::LogMessage>;
Expand Down
4 changes: 2 additions & 2 deletions ecal/core/src/readwrite/udp/ecal_writer_udp_mc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ namespace eCAL
{
if (m_sample_sender_loopback)
{
sent = m_sample_sender_loopback->SendSample(m_ecal_sample.topic().tname(), m_ecal_sample, attr_.bandwidth);
sent = m_sample_sender_loopback->Send(m_ecal_sample.topic().tname(), m_ecal_sample, attr_.bandwidth);
}
}
else
{
if (m_sample_sender_no_loopback)
{
sent = m_sample_sender_no_loopback->SendSample(m_ecal_sample.topic().tname(), m_ecal_sample, attr_.bandwidth);
sent = m_sample_sender_no_loopback->Send(m_ecal_sample.topic().tname(), m_ecal_sample, attr_.bandwidth);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/registration/ecal_registration_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ namespace eCAL
bool return_value {true};

if (m_use_network_monitoring && m_reg_sample_snd)
return_value &= (m_reg_sample_snd->SendSample(sample_name_, sample_, -1) != 0);
return_value &= (m_reg_sample_snd->Send(sample_name_, sample_, -1) != 0);

if(m_use_shm_monitoring)
{
Expand Down

0 comments on commit 94eca56

Please sign in to comment.