Skip to content

Commit

Permalink
Added additional config to registration objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen committed Aug 8, 2024
1 parent 2b1ea99 commit 927c57d
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 32 deletions.
1 change: 1 addition & 0 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ set(ecal_config_src
src/config/ecal_cmd_parser.cpp
src/config/ecal_config.cpp
src/config/ecal_config_initializer.cpp
src/config/transport_layer.cpp
src/types/ecal_custom_data_types.cpp
)
if (ECAL_CORE_CONFIGURATION)
Expand Down
14 changes: 14 additions & 0 deletions ecal/core/include/ecal/config/transport_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include <ecal/types/ecal_custom_data_types.h>
#include <ecal/ecal_os.h>

namespace eCAL
{
Expand All @@ -42,6 +43,16 @@ namespace eCAL
};
}

namespace Local
{
struct Configuration
{
Types::IpAddressV4 group { "127.255.255.255" }; //!< UDP multicast group base (Default: 127.255.255.255)
unsigned int ttl { 1U }; /*!< UDP ttl value, also known as hop limit, is used in determining
the intermediate routers being traversed towards the destination (Default: 1) */
};
}

struct Configuration
{
Types::UdpConfigVersion config_version { Types::UdpConfigVersion::V2 }; /*!< UDP configuration version (Since eCAL 5.12.)
Expand All @@ -61,6 +72,9 @@ namespace eCAL
bool npcap_enabled { false }; //!< Enable to receive UDP traffic with the Npcap based receiver (Default: false)

Network::Configuration network;
const Local::Configuration local;

ECAL_API Configuration& operator=(const Configuration& other);
};
}

Expand Down
1 change: 1 addition & 0 deletions ecal/core/include/ecal/types/ecal_custom_data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace eCAL
ECAL_API IpAddressV4& operator=(const std::string& ip_string_);
ECAL_API IpAddressV4& operator=(const char* ip_string_);
ECAL_API operator std::string();
ECAL_API operator std::string() const;
ECAL_API bool operator==(const eCAL::Types::IpAddressV4& rhs) const;
ECAL_API friend bool operator==(eCAL::Types::IpAddressV4 lhs, const char* ip_string_);
ECAL_API friend bool operator==(const char* ip_string_, eCAL::Types::IpAddressV4 rhs);
Expand Down
44 changes: 44 additions & 0 deletions ecal/core/src/config/transport_layer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* =========================== LICENSE =================================
*
* 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.
* 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.
*
* =========================== LICENSE =================================
*/

#include "ecal/config/transport_layer.h"

namespace eCAL
{
namespace TransportLayer
{
namespace UDP
{
Configuration& Configuration::operator=(const Configuration& other)
{
config_version = other.config_version;
join_all_interfaces = other.join_all_interfaces;
mask = other.mask;
mode = other.mode;
network = other.network;
npcap_enabled = other.npcap_enabled;
port = other.port;
receive_buffer = other.receive_buffer;
send_buffer = other.send_buffer;

return *this;
}
}
}
}
4 changes: 2 additions & 2 deletions ecal/core/src/ecal_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace eCAL
/////////////////////
if (registration_provider_instance == nullptr)
{
registration_provider_instance = std::make_unique<CRegistrationProvider>();
registration_provider_instance = std::make_unique<CRegistrationProvider>(eCAL::GetConfiguration().registration);
new_initialization = true;
}

Expand All @@ -63,7 +63,7 @@ namespace eCAL
/////////////////////
if(registration_receiver_instance == nullptr)
{
registration_receiver_instance = std::make_unique<CRegistrationReceiver>();
registration_receiver_instance = std::make_unique<CRegistrationReceiver>(eCAL::GetConfiguration().registration);
new_initialization = true;
}
#endif // ECAL_CORE_REGISTRATION
Expand Down
31 changes: 30 additions & 1 deletion ecal/core/src/registration/ecal_registration_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,42 @@
#include <ecal/ecal_config.h>
#include <ecal_globals.h>
#include "ecal_def.h"
#include "io/udp/ecal_udp_sender_attr.h"

#include <registration/ecal_process_registration.h>
#include <registration/udp/ecal_registration_sender_udp.h>
#if ECAL_CORE_REGISTRATION_SHM
#include <registration/shm/ecal_registration_sender_shm.h>
#endif

namespace
{
using namespace eCAL;
UDP::SSenderAttr CreateAttributes(const Registration::Configuration& config_)
{
UDP::SSenderAttr attr;
attr.broadcast = !config_.network_enabled;
attr.port = config_.layer.udp.port;

auto& config = GetConfiguration();
attr.loopback = true;
attr.sndbuf = config.transport_layer.udp.send_buffer;

if (config.transport_layer.udp.mode == Types::UDPMode::NETWORK)
{
attr.address = config.transport_layer.udp.network.group;
attr.ttl = config.transport_layer.udp.network.ttl;
} else
{
attr.address = config.transport_layer.udp.local.group;
attr.ttl = config.transport_layer.udp.local.ttl;
}

return attr;
}

}

namespace eCAL
{
std::atomic<bool> CRegistrationProvider::m_created;
Expand Down Expand Up @@ -71,7 +100,7 @@ namespace eCAL
#endif
if (m_config.layer.udp.enable)
{
m_reg_sender = std::make_unique<CRegistrationSenderUDP>(m_config.layer.udp);
m_reg_sender = std::make_unique<CRegistrationSenderUDP>(CreateAttributes(m_config));
}
else
{
Expand Down
22 changes: 9 additions & 13 deletions ecal/core/src/registration/ecal_registration_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ namespace eCAL
//////////////////////////////////////////////////////////////////
std::atomic<bool> CRegistrationReceiver::m_created;

CRegistrationReceiver::CRegistrationReceiver()
: m_use_registration_udp(false)
, m_use_registration_shm(false)
, m_sample_applier(Config::IsNetworkEnabled(), false, Process::GetHostGroupName(), Process::GetProcessID())
CRegistrationReceiver::CRegistrationReceiver(const Registration::Configuration& config_)
: m_config(config_)
, m_sample_applier(config_.network_enabled, config_.loopback, config_.host_group_name, Process::GetProcessID())
{
// Connect User registration callback and gates callback with the sample applier
m_sample_applier.SetCustomApplySampleCallback("gates", [](const eCAL::Registration::Sample& sample_)
Expand All @@ -75,19 +74,16 @@ namespace eCAL
{
if(m_created) return;

// receive registration via udp or shared memory
m_use_registration_shm = Config::IsShmRegistrationEnabled();
m_use_registration_udp = !m_use_registration_shm;

if (m_use_registration_udp)
// Why do we have here different behaviour than in the registration provider?
if (m_config.layer.udp.enable)
{
m_registration_receiver_udp = std::make_unique<CRegistrationReceiverUDP>([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_); });
}

#if ECAL_CORE_REGISTRATION_SHM
if (m_use_registration_shm)
if (m_config.layer.shm.enable)
{
m_registration_receiver_shm = std::make_unique<CRegistrationReceiverSHM>([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_); });
m_registration_receiver_shm = std::make_unique<CRegistrationReceiverSHM>([this](const Registration::Sample& sample_) {return m_sample_applier.ApplySample(sample_); }, m_config.layer.shm);
}
#endif

Expand All @@ -99,13 +95,13 @@ namespace eCAL
if(!m_created) return;

// stop network registration receive thread
if (m_use_registration_udp)
if (m_config.layer.udp.enable)
{
m_registration_receiver_udp = nullptr;
}

#if ECAL_CORE_REGISTRATION_SHM
if (m_use_registration_shm)
if (m_config.layer.shm.enable)
{
m_registration_receiver_shm = nullptr;
}
Expand Down
8 changes: 4 additions & 4 deletions ecal/core/src/registration/ecal_registration_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "registration/ecal_registration_sample_applier.h"
#include "registration/ecal_registration_sample_applier_gates.h"
#include "registration/ecal_registration_sample_applier_user.h"
#include "ecal/config/registration.h"

#include <atomic>
#include <functional>
Expand All @@ -51,7 +52,7 @@ namespace eCAL
class CRegistrationReceiver
{
public:
CRegistrationReceiver();
CRegistrationReceiver(const Registration::Configuration& config_);
~CRegistrationReceiver();

//what about the rest of the rule of 5?
Expand All @@ -77,15 +78,14 @@ namespace eCAL
std::unique_ptr<CRegistrationReceiverSHM> m_registration_receiver_shm;
#endif

bool m_use_registration_udp;
bool m_use_registration_shm;

// This class distributes samples to all everyone who is interested in being notified about samples
Registration::CSampleApplier m_sample_applier;

// These classes are interested in being notified about samples
// Possibly remove these from this class
// The custom user callbacks (who receive serialized samples), e.g. registration events.
Registration::CSampleApplierUser m_user_applier;

Registration::Configuration m_config;
};
}
11 changes: 6 additions & 5 deletions ecal/core/src/registration/shm/ecal_memfile_broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ namespace eCAL
{
if (m_created) return false;

m_config = config_;

const auto presumably_memfile_size =
RelocatableCircularQueue<SMemfileBroadcastEvent>::PresumablyOccupiedMemorySize(m_max_queue_size) +
RelocatableCircularQueue<SMemfileBroadcastEvent>::PresumablyOccupiedMemorySize(m_config.queue_size) +
sizeof(SMemfileBroadcastHeader);
if (!m_broadcast_memfile->Create(name.c_str(), true, presumably_memfile_size, true))
if (!m_broadcast_memfile->Create(m_config.domain.c_str(), true, presumably_memfile_size, true))
{
#ifndef NDEBUG
std::cerr << "Unable to access broadcast memory file." << std::endl;
Expand Down Expand Up @@ -134,7 +136,7 @@ namespace eCAL

std::string CMemoryFileBroadcast::GetName() const
{
return m_name;
return m_config.domain;
}

bool CMemoryFileBroadcast::IsMemfileVersionCompatible(const void *memfile_address) const
Expand All @@ -148,7 +150,7 @@ namespace eCAL
auto *header = GetMemfileHeader(memfile_address);
*header = SMemfileBroadcastHeader();
m_event_queue.SetBaseAddress(GetEventQueueAddress(memfile_address));
m_event_queue.Reset(m_max_queue_size);
m_event_queue.Reset(m_config.queue_size);
#ifndef NDEBUG
std::cout << "Broadcast memory file has been resetted" << std::endl;
#endif
Expand Down Expand Up @@ -244,7 +246,6 @@ namespace eCAL
}
}


bool CMemoryFileBroadcast::ReceiveEvents(MemfileBroadcastEventListT &event_list, std::int64_t timeout, bool enable_loopback)
{
if (m_broadcast_memfile->GetReadAccess(EXP_MEMFILE_ACCESS_TIMEOUT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ namespace eCAL
// CMemfileRegistrationReceiver
//////////////////////////////////////////////////////////////////

CRegistrationReceiverSHM::CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback)
CRegistrationReceiverSHM::CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback, const Registration::Layer::SHM::Configuration& config_)
: m_apply_sample_callback(apply_sample_callback)
{
m_memfile_broadcast = std::make_unique<CMemoryFileBroadcast>();
m_memfile_broadcast->Create(Config::Experimental::GetShmMonitoringDomain(), Config::Experimental::GetShmMonitoringQueueSize());
m_memfile_broadcast->Create(config_);
m_memfile_broadcast->FlushLocalEventQueue();

m_memfile_broadcast_reader = std::make_unique<CMemoryFileBroadcastReader>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace eCAL
class CRegistrationReceiverSHM
{
public:
CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback);
CRegistrationReceiverSHM(RegistrationApplySampleCallbackT apply_sample_callback, const Registration::Layer::SHM::Configuration& config_);
~CRegistrationReceiverSHM();

// default copy constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace eCAL
class CRegistrationSenderSHM : public CRegistrationSender
{
public:
CRegistrationSenderSHM(const Registration::Layer::SHM::Configuration& config_ = {});
CRegistrationSenderSHM(const Registration::Layer::SHM::Configuration& config_);
~CRegistrationSenderSHM() override;

// Special member functionss
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ namespace

namespace eCAL
{
CRegistrationSenderUDP::CRegistrationSenderUDP(const Registration::Layer::UDP::Configuration& config_ = {})
: m_reg_sample_snd(CreateAttributes())
CRegistrationSenderUDP::CRegistrationSenderUDP(const eCAL::UDP::SSenderAttr& config_)
: m_reg_sample_snd(config_)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "registration/ecal_registration_sender.h"

#include "io/udp/ecal_udp_sample_sender.h"
#include "io/udp/ecal_udp_sender_attr.h"

#include <ecal/config/registration.h>

Expand All @@ -37,7 +38,7 @@ namespace eCAL
class CRegistrationSenderUDP : public CRegistrationSender
{
public:
CRegistrationSenderUDP(const Registration::Layer::UDP::Configuration& config_ = {});
CRegistrationSenderUDP(const eCAL::UDP::SSenderAttr& config_);
~CRegistrationSenderUDP() override;

// Special member functionss
Expand Down
1 change: 1 addition & 0 deletions ecal/core/src/types/ecal_custom_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace eCAL
IpAddressV4& IpAddressV4::operator=(const std::string& ip_string_) { this->validateIpString(ip_string_); return *this; };
IpAddressV4& IpAddressV4::operator=(const char* ip_string_) { this->validateIpString(ip_string_); return *this; };
IpAddressV4::operator std::string() { return m_ip_address; };
IpAddressV4::operator std::string() const { return m_ip_address; };

std::ostream& operator<<(std::ostream& os, const IpAddressV4& ipv4) { os << ipv4.Get(); return os; };

Expand Down

0 comments on commit 927c57d

Please sign in to comment.