Skip to content

Commit

Permalink
complete udp communication/(de)fragmentation logic removed (as prepar…
Browse files Browse the repository at this point in the history
…ation for new udp library)
  • Loading branch information
rex-schilasky committed Jan 11, 2024
1 parent 0f16b39 commit c19a723
Show file tree
Hide file tree
Showing 26 changed files with 44 additions and 1,991 deletions.
52 changes: 2 additions & 50 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,48 +132,6 @@ endif()
######################################
# io/udp
######################################
# io/udp/fragmentation
set(ecal_io_udp_fragmentation_src
src/io/udp/fragmentation/msg_type.h
src/io/udp/fragmentation/rcv_fragments.cpp
src/io/udp/fragmentation/rcv_fragments.h
src/io/udp/fragmentation/snd_fragments.cpp
src/io/udp/fragmentation/snd_fragments.h
)

# io/udp/sendreceive (npcap)
if(ECAL_NPCAP_SUPPORT)
set(ecal_io_udp_sendreceive_src_npcap
src/io/udp/sendreceive/udp_receiver_npcap.cpp
src/io/udp/sendreceive/udp_receiver_npcap.h
)
endif()

# io/udp/sendreceive
set(ecal_io_udp_sendreceive_src
src/io/udp/sendreceive/udp_receiver.cpp
src/io/udp/sendreceive/udp_receiver.h
src/io/udp/sendreceive/udp_receiver_asio.cpp
src/io/udp/sendreceive/udp_receiver_asio.h
src/io/udp/sendreceive/udp_sender.cpp
src/io/udp/sendreceive/udp_sender.h
${ecal_io_udp_sendreceive_src_npcap}
)

# io/udp/sendreceive/linux
if(UNIX)
set(ecal_io_udp_sendreceive_linux_src
src/io/udp/sendreceive/linux/socket_os.h
)
endif()

# io/udp/sendreceive/win32
if (WIN32)
set(ecal_io_udp_sendreceive_win_src
src/io/udp/sendreceive/win32/socket_os.h
)
endif()

# io/udp
set(ecal_io_udp_src
src/io/udp/ecal_udp_configurations.cpp
Expand All @@ -182,10 +140,12 @@ set(ecal_io_udp_src
src/io/udp/ecal_udp_logging_receiver.h
src/io/udp/ecal_udp_logging_sender.cpp
src/io/udp/ecal_udp_logging_sender.h
src/io/udp/ecal_udp_receiver_attr.h
src/io/udp/ecal_udp_sample_receiver.cpp
src/io/udp/ecal_udp_sample_receiver.h
src/io/udp/ecal_udp_sample_sender.cpp
src/io/udp/ecal_udp_sample_sender.h
src/io/udp/ecal_udp_sender_attr.h
src/io/udp/ecal_udp_topic2mcast.h
)

Expand Down Expand Up @@ -458,11 +418,7 @@ ecal_add_ecal_shared_library(${PROJECT_NAME}
${ecal_io_shm_src}
${ecal_io_shm_linux_src}
${ecal_io_shm_win_src}
${ecal_io_udp_fragmentation_src}
${ecal_io_udp_sendreceive_src}
${ecal_io_udp_src}
${ecal_io_udp_sendreceive_linux_src}
${ecal_io_udp_sendreceive_win_src}
${ecal_logging_src}
${ecal_monitoring_src}
${ecal_pubsub_src}
Expand Down Expand Up @@ -580,11 +536,7 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS "3.8.0")
${ecal_io_shm_src}
${ecal_io_shm_linux_src}
${ecal_io_shm_win_src}
${ecal_io_udp_fragmentation_src}
${ecal_io_udp_sendreceive_src}
${ecal_io_udp_src}
${ecal_io_udp_sendreceive_linux_src}
${ecal_io_udp_sendreceive_win_src}
${ecal_logging_src}
${ecal_monitoring_src}
${ecal_pubsub_src}
Expand Down
7 changes: 7 additions & 0 deletions ecal/core/src/ecal_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@

#pragma once

// TODO: Remove this thing ..
// ugly extra include to avoid strange windows behaviour "WinSock.h has already been included"
#include <ecal/ecal_os.h>
#ifdef ECAL_OS_WINDOWS
#include <winsock2.h>
#endif

#include "ecal_global_accessors.h"
#include "registration/ecal_registration_provider.h"
#include "registration/ecal_registration_receiver.h"
Expand Down
32 changes: 1 addition & 31 deletions ecal/core/src/io/udp/ecal_udp_logging_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,13 @@

#include "ecal_udp_logging_receiver.h"

#include "ecal_def.h"
#include "io/udp/fragmentation/msg_type.h"

namespace eCAL
{
namespace UDP
{
CLoggingReceiver::CLoggingReceiver(const IO::UDP::SReceiverAttr& attr_, LogMessageCallbackT log_message_callback_) :
m_network_mode(!attr_.broadcast), m_log_message_callback(log_message_callback_)
{
// create udp receiver
m_udp_receiver.Create(attr_);

// allocate receive buffer
m_msg_buffer.resize(MSG_BUFFER_SIZE);

// start receiver thread
m_udp_receiver_thread = std::make_shared<CCallbackThread>(std::bind(&CLoggingReceiver::ReceiveThread, this));
m_udp_receiver_thread->start(std::chrono::milliseconds(0));
}

CLoggingReceiver::~CLoggingReceiver()
{
m_udp_receiver_thread->stop();
}

void CLoggingReceiver::ReceiveThread()
m_log_message_callback(log_message_callback_)
{
// wait for any incoming message
const size_t recv_len = m_udp_receiver.Receive(m_msg_buffer.data(), m_msg_buffer.size(), CMN_UDP_RECEIVE_THREAD_CYCLE_TIME_MS);
if (recv_len > 0)
{
if (m_log_message.ParseFromArray(m_msg_buffer.data(), static_cast<int>(recv_len)))
{
m_log_message_callback(m_log_message);
}
}
}
}
}
25 changes: 5 additions & 20 deletions ecal/core/src/io/udp/ecal_udp_logging_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@

#pragma once

#include "io/udp/sendreceive/udp_receiver.h"
#include "util/ecal_thread.h"

#include <functional>
#include <memory>
#include <string>
#include <vector>
#include "ecal_udp_receiver_attr.h"

#ifdef _MSC_VER
#pragma warning(push, 0) // disable proto warnings
Expand All @@ -39,6 +33,8 @@
#pragma warning(pop)
#endif

#include <functional>

namespace eCAL
{
namespace UDP
Expand All @@ -49,20 +45,9 @@ namespace eCAL
using LogMessageCallbackT = std::function<void(const eCAL::pb::LogMessage&)>;

CLoggingReceiver(const IO::UDP::SReceiverAttr& attr_, LogMessageCallbackT log_message_callback_);
virtual ~CLoggingReceiver();

protected:
void ReceiveThread();

bool m_network_mode;

LogMessageCallbackT m_log_message_callback;

IO::UDP::CUDPReceiver m_udp_receiver;
std::shared_ptr<CCallbackThread> m_udp_receiver_thread;

std::vector<char> m_msg_buffer;
eCAL::pb::LogMessage m_log_message;
LogMessageCallbackT m_log_message_callback;
};
}
}
}
9 changes: 0 additions & 9 deletions ecal/core/src/io/udp/ecal_udp_logging_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,10 @@ namespace eCAL
{
CLoggingSender::CLoggingSender(const IO::UDP::SSenderAttr& attr_)
{
m_udp_sender = std::make_shared<IO::UDP::CUDPSender>(attr_);
}

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

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

return 0;
}
}
Expand Down
11 changes: 1 addition & 10 deletions ecal/core/src/io/udp/ecal_udp_logging_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#pragma once

#include "io/udp/sendreceive/udp_sender.h"
#include "ecal_udp_sender_attr.h"

#ifdef _MSC_VER
#pragma warning(push, 0) // disable proto warnings
Expand All @@ -33,9 +33,6 @@
#pragma warning(pop)
#endif

#include <memory>
#include <string>

namespace eCAL
{
namespace UDP
Expand All @@ -45,12 +42,6 @@ namespace eCAL
public:
CLoggingSender(const IO::UDP::SSenderAttr& attr_);
size_t Send(const eCAL::pb::LogMessage& ecal_log_message_);

private:
IO::UDP::SSenderAttr m_attr;
std::shared_ptr<IO::UDP::CUDPSender> m_udp_sender;

std::string m_logmessage_s;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@
*/

/**
* @brief eCAL windows includes
* @brief UDP receiver attributes
**/

#pragma once

#if defined(_MSC_VER) && defined(__clang__) && !defined(CINTERFACE)
#define CINTERFACE
#endif
#include <string>

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <winsock2.h> //NOLINT
#include <Ws2tcpip.h> //NOLINT

#undef CINTERFACE
namespace IO
{
namespace UDP
{
struct SReceiverAttr
{
std::string address;
int port = 0;
bool broadcast = false;
bool loopback = true;
int rcvbuf = 1024 * 1024;
};
}
}
Loading

0 comments on commit c19a723

Please sign in to comment.