Skip to content

Commit

Permalink
[core] ecaludp based - udp send/receive handling (#1538)
Browse files Browse the repository at this point in the history
new - ecaludp based - udp send/receive handling
  • Loading branch information
rex-schilasky authored Apr 18, 2024
1 parent 5cf9edf commit 5ecb809
Show file tree
Hide file tree
Showing 34 changed files with 846 additions and 1,789 deletions.
75 changes: 23 additions & 52 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ project(core VERSION ${eCAL_VERSION_STRING})

find_package(asio REQUIRED)
find_package(Threads REQUIRED)
find_package(ecaludp REQUIRED)

if (ECAL_CORE_CONFIG_INIFILE)
find_package(simpleini REQUIRED)
Expand All @@ -33,10 +34,6 @@ if (ECAL_CORE_TRANSPORT_TCP)
find_package(tcp_pubsub REQUIRED)
endif()

if (ECAL_CORE_NPCAP_SUPPORT)
find_package(udpcap REQUIRED)
endif()

# If we're currently doing a build within a git repository, we will configure the header files.
# Else, (e.g. for source packages such as debian source packages) we will use a preconfigured file.
# If there is really no information available, it will generate a dummy version file 0.0.0
Expand Down Expand Up @@ -139,59 +136,38 @@ 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)
# io/udp (npcap)
if(ECAL_CORE_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
set(ecal_io_udp_src_npcap
src/io/udp/ecal_udp_sample_receiver_npcap.cpp
src/io/udp/ecal_udp_sample_receiver_npcap.h
)
endif()

# io/udp
set(ecal_io_udp_src
src/io/udp/ecal_udp_configurations.cpp
src/io/udp/ecal_udp_configurations.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_receiver_asio.cpp
src/io/udp/ecal_udp_sample_receiver_asio.h
src/io/udp/ecal_udp_sample_receiver_base.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
${ecal_io_udp_src_npcap}
)

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

######################################
# logging
######################################
Expand Down Expand Up @@ -538,11 +514,8 @@ set(ecal_sources
${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_io_udp_linux_src}
${ecal_logging_src}
${ecal_monitoring_src}
${ecal_pub_src}
Expand Down Expand Up @@ -658,12 +631,10 @@ if(ECAL_CORE_TRANSPORT_TCP)
)
endif()

if(ECAL_CORE_NPCAP_SUPPORT)
target_link_libraries(${PROJECT_NAME}
PRIVATE
udpcap::udpcap
)
endif()
target_link_libraries(${PROJECT_NAME}
PRIVATE
ecaludp::ecaludp
)

target_include_directories(${PROJECT_NAME}
PRIVATE
Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/ecal_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include "ecal_process_stub.h"
#include "ecal_utils/command_line.h"
#include "ecal_utils/ecal_utils.h"
#include "ecal_utils/str_convert.h"

#include "config/ecal_config_reader_hlp.h"
Expand Down Expand Up @@ -68,6 +67,7 @@
#include <sys/select.h>
#include <limits.h>
#include <netinet/in.h>
#include <ecal_utils/ecal_utils.h>
#endif /* ECAL_OS_LINUX */

#ifdef ECAL_OS_MACOS
Expand All @@ -82,7 +82,7 @@
#endif

#ifdef ECAL_CORE_NPCAP_SUPPORT
#include <udpcap/npcap_helpers.h>
#include <ecaludp/npcap_helpers.h>
#endif // ECAL_CORE_NPCAP_SUPPORT

#ifndef NDEBUG
Expand Down Expand Up @@ -213,7 +213,7 @@ namespace eCAL
#endif
#ifdef ECAL_CORE_NPCAP_SUPPORT
sstream << "Npcap UDP Reciever : " << LayerMode(Config::IsNpcapEnabled());
if(Config::IsNpcapEnabled() && !Udpcap::Initialize())
if(Config::IsNpcapEnabled() && !ecaludp::npcap::is_initialized())
{
sstream << " (Init FAILED!)";
}
Expand Down
10 changes: 10 additions & 0 deletions ecal/core/src/io/udp/ecal_udp_configurations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ namespace eCAL
{
namespace UDP
{
/**
* @brief Create eCAL specific UDP datagram header.
*
* @return The four magic letters :).
*/
std::array<char, 4> GeteCALDatagramHeader()
{
return std::array<char, 4>{ 'E', 'C', 'A', 'L' };
}

/**
* @brief IsBroadcast() retrieves if we communicate via UDP Broadcast or UDP Multicast.
*
Expand Down
8 changes: 8 additions & 0 deletions ecal/core/src/io/udp/ecal_udp_configurations.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@

#pragma once

#include <array>
#include <string>

namespace eCAL
{
namespace UDP
{
/**
* @brief Create eCAL specific UDP datagram header.
*
* @return The four magic letters :).
*/
std::array<char, 4> GeteCALDatagramHeader();

/**
* @brief IsBroadcast() retrieves if we communicate via UDP Broadcast or UDP Multicast.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,28 @@
*/

/**
* @brief raw message buffer handling
* @brief UDP receiver attributes
**/

#include <cstddef>
#pragma once

#include <functional>
#include <string>
#include <vector>

namespace IO
namespace eCAL
{
namespace UDP
{
size_t CreateSampleBuffer(const std::string& sample_name_, const std::vector<char>& serialized_sample_, std::vector<char>& payload_);
struct SReceiverAttr
{
std::string address;
int port = 0;
bool broadcast = false;
bool loopback = true;
int rcvbuf = 1024 * 1024;
};

using TransmitCallbackT = std::function<size_t(const void*, const size_t)>;
size_t SendFragmentedMessage(char* buf_, size_t buf_len_, const TransmitCallbackT& transmit_cb_);
using HasSampleCallbackT = std::function<bool(const std::string& sample_name_)>;
using ApplySampleCallbackT = std::function<void(const char* serialized_sample_data_, size_t serialized_sample_size_)>;
}
}
Loading

0 comments on commit 5ecb809

Please sign in to comment.