Skip to content

Commit

Permalink
cleanup file structure
Browse files Browse the repository at this point in the history
cleanup naming
add IO::UDP namespace for internal (IO) UDP logic
  • Loading branch information
rex-schilasky committed Dec 6, 2023
1 parent 94eca56 commit f406a3f
Show file tree
Hide file tree
Showing 51 changed files with 1,780 additions and 1,664 deletions.
90 changes: 48 additions & 42 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,61 +137,63 @@ endif()
######################################
# io/udp
######################################
if(ECAL_NPCAP_SUPPORT)
set(ecal_io_udp_src_npcap
src/io/udp/udp_receiver_npcap.cpp
src/io/udp/udp_receiver_npcap.h
)
endif()

# 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
)

set(ecal_io_udp_protobuf_src
src/io/udp/protobuf/rcv_logging.cpp
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
# 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()

set(ecal_io_udp_src
src/io/udp/msg_type.h
src/io/udp/topic2mcast.h
src/io/udp/udp_configurations.cpp
src/io/udp/udp_configurations.h
src/io/udp/udp_init.cpp
src/io/udp/udp_init.h
src/io/udp/udp_receiver.cpp
src/io/udp/udp_receiver.h
src/io/udp/udp_receiver_asio.cpp
src/io/udp/udp_receiver_asio.h
src/io/udp/udp_sender.cpp
src/io/udp/udp_sender.h
${ecal_io_udp_src_npcap}
)

# io/udp/linux
# 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_linux_src
src/io/udp/linux/ecal_socket_os.h
set(ecal_io_udp_sendreceive_linux_src
src/io/udp/sendreceive/linux/socket_os.h
)
endif()

# io/udp/win32
# io/udp/sendreceive/win32
if (WIN32)
set(ecal_io_udp_win_src
src/io/udp/win32/ecal_socket_os.h
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
src/io/udp/ecal_udp_configurations.h
src/io/udp/ecal_udp_logging_receiver.cpp
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_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_topic2mcast.h
)

######################################
# logging
######################################
Expand Down Expand Up @@ -343,6 +345,8 @@ if (WIN32)
list (APPEND
ecal_cmn_src
src/ecal_win_main.h
src/ecal_win_network.cpp
src/ecal_win_network.h
)
endif()

Expand Down Expand Up @@ -462,10 +466,10 @@ ecal_add_ecal_shared_library(${PROJECT_NAME}
${ecal_io_shm_linux_src}
${ecal_io_shm_win_src}
${ecal_io_udp_fragmentation_src}
${ecal_io_udp_protobuf_src}
${ecal_io_udp_sendreceive_src}
${ecal_io_udp_src}
${ecal_io_udp_linux_src}
${ecal_io_udp_win_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 @@ -584,8 +588,10 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS "3.8.0")
${ecal_io_shm_linux_src}
${ecal_io_shm_win_src}
${ecal_io_udp_fragmentation_src}
${ecal_io_udp_protobuf_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
11 changes: 8 additions & 3 deletions ecal/core/src/ecal_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
**/

#include "ecal_globals.h"
#include "io/udp/udp_init.h"
#include "ecal_win_network.h"

#include "config/ecal_config_reader.h"

#include <stdexcept>
Expand All @@ -44,8 +45,10 @@ namespace eCAL
// will be set if any new module was initialized
bool new_initialization(false);

// this is needed here for functions like "GetHostName" on windows
#ifdef ECAL_OS_WINDOWS
// windows network startup
Net::Initialize();
#endif /* ECAL_OS_WINDOWS */

/////////////////////
// CONFIG
Expand Down Expand Up @@ -297,8 +300,10 @@ namespace eCAL
log_instance = nullptr;
config_instance = nullptr;

// last not least we close all
#ifdef ECAL_OS_WINDOWS
// windows network cleanup
Net::Finalize();
#endif /* ECAL_OS_WINDOWS */

initialized = false;

Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/ecal_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "registration/ecal_registration_receiver.h"
#include "ecal_globals.h"
#include "ecal_process.h"
#include "io/udp/udp_configurations.h"
#include "io/udp/ecal_udp_configurations.h"

#include <array>
#include <chrono>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@
*/

/**
* @brief UDP initialization
* @brief Win32 network initialization
**/

#include <ecal/ecal_os.h>

#include <cstdio>
#include <atomic>

#ifdef ECAL_OS_WINDOWS
#include "win32/ecal_socket_os.h"
#endif /* ECAL_OS_WINDOWS */
#if defined(_MSC_VER) && defined(__clang__) && !defined(CINTERFACE)
#define CINTERFACE
#endif

#ifndef NOMINMAX
#define NOMINMAX
#endif

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

#undef CINTERFACE

static std::atomic<int> g_socket_init_refcnt(0);

Expand All @@ -41,7 +48,6 @@ namespace eCAL
g_socket_init_refcnt++;
if(g_socket_init_refcnt == 1)
{
#ifdef ECAL_OS_WINDOWS
const WORD wVersionRequested = MAKEWORD(2, 2);

WSADATA wsaData;
Expand All @@ -67,7 +73,6 @@ namespace eCAL
printf("Could not find a usable version of Winsock.dll\n");
WSACleanup();
}
#endif /* ECAL_OS_WINDOWS */
}
return(0);
}
Expand All @@ -79,11 +84,8 @@ namespace eCAL
g_socket_init_refcnt--;
if(g_socket_init_refcnt == 0)
{
#ifdef ECAL_OS_WINDOWS
WSACleanup();
#endif /* ECAL_OS_WINDOWS */
}

return(0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/**
* @brief UDP initialization
* @brief Win32 network initialization
**/

#pragma once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* ========================= eCAL LICENSE =================================
*/

#include "io/udp/udp_configurations.h"
#include "ecal_udp_configurations.h"
#include "ecal_udp_topic2mcast.h"

#include <ecal/ecal_config.h>

#include "ecal_def.h"
#include "topic2mcast.h"

namespace eCAL
{
Expand All @@ -38,6 +38,16 @@ namespace eCAL
return !Config::IsNetworkEnabled();
}

/**
* @brief IsNpcapEnabled() retrieves if we use the npcap UDP receiver (windows only).
*
* @return True if npcap mode is active.
*/
bool IsNpcapEnabled()
{
return Config::IsNpcapEnabled();
}

/**
* @brief GetLocalBroadcastAddress retrieves the broadcast address within the loopback range.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ namespace eCAL
*/
bool IsBroadcast();

/**
* @brief IsNpcapEnabled() retrieves if we use the npcap UDP receiver (windows only).
*
* @return True if npcap mode is active.
*/
bool IsNpcapEnabled();

/**
* @brief GetRegistrationAddress retrieves the UDP registration address based on network configuration.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

#include <ecal/ecal_process.h>

#include "rcv_logging.h"
#include "io/udp/msg_type.h"
#include "ecal_udp_logging_receiver.h"
#include "io/udp/fragmentation/msg_type.h"

namespace
{
Expand All @@ -39,36 +39,39 @@ namespace

namespace eCAL
{
CUDPLoggingReceiver::CUDPLoggingReceiver(const eCAL::SReceiverAttr& attr_, LogMessageCallbackT log_message_callback_) :
m_network_mode(!attr_.broadcast), m_log_message_callback(log_message_callback_)
namespace UDP
{
// create udp receiver
m_udp_receiver.Create(attr_);
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);
// allocate receive buffer
m_msg_buffer.resize(MSG_BUFFER_SIZE);

// start receiver thread
m_udp_receiver_thread = std::make_shared<CCallbackThread>(std::bind(&CUDPLoggingReceiver::ReceiveThread, this));
m_udp_receiver_thread->start(std::chrono::milliseconds(0));
}
// 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));
}

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

void CUDPLoggingReceiver::ReceiveThread()
{
// 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)
void CLoggingReceiver::ReceiveThread()
{
if (m_log_message.ParseFromArray(m_msg_buffer.data(), static_cast<int>(recv_len)))
// 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 (IsLocalHost(m_log_message) || m_network_mode)
if (m_log_message.ParseFromArray(m_msg_buffer.data(), static_cast<int>(recv_len)))
{
m_log_message_callback(m_log_message);
if (IsLocalHost(m_log_message) || m_network_mode)
{
m_log_message_callback(m_log_message);
}
}
}
}
Expand Down
Loading

0 comments on commit f406a3f

Please sign in to comment.