Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] Added config object to registration. #1709

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 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 Expand Up @@ -443,6 +444,17 @@ if (WIN32)
)
endif()

######################################
# builder
######################################
set (ecal_builder_src
src/builder/registration_attribute_builder.cpp
src/registration/builder/udp_shm_attribute_builder.cpp
src/registration/builder/sample_applier_attribute_builder.cpp
src/registration/udp/builder/udp_attribute_builder.cpp
)


######################################
# c interface
######################################
Expand Down Expand Up @@ -564,6 +576,7 @@ set(ecal_sources
${ecal_time_src}
${ecal_util_src}
${ecal_cmn_src}
${ecal_builder_src}
${ecal_header_cmn}
${ecal_header_msg}
)
Expand Down
15 changes: 8 additions & 7 deletions ecal/core/include/ecal/config/registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include "ecal/ecal_os.h"
#include "ecal/ecal_process.h"

#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -63,14 +64,14 @@ namespace eCAL

struct Configuration
{
unsigned int registration_timeout { 60000U }; //!< Timeout for topic registration in ms (internal) (Default: 60000)
unsigned int registration_refresh { 1000U }; //!< Topic registration refresh cylce (has to be smaller then registration timeout!) (Default: 1000)
unsigned int registration_timeout { 60000U }; //!< Timeout for topic registration in ms (internal) (Default: 60000)
unsigned int registration_refresh { 1000U }; //!< Topic registration refresh cylce (has to be smaller then registration timeout!) (Default: 1000)

bool network_enabled { false }; /*!< true = all eCAL components communicate over network boundaries
false = local host only communication (Default: false) */
bool loopback { true }; //!< enable to receive udp messages on the same local machine (Default: true)
std::string host_group_name { "" }; /*!< Common host group name that enables interprocess mechanisms across
(virtual) host borders (e.g, Docker); by default equivalent to local host name (Default: "") */
bool network_enabled { false }; /*!< true = all eCAL components communicate over network boundaries
false = local host only communication (Default: false) */
bool loopback { true }; //!< enable to receive udp messages on the same local machine (Default: true)
std::string host_group_name { eCAL::Process::GetHostName() }; /*!< Common host group name that enables interprocess mechanisms across
(virtual) host borders (e.g, Docker); by default equivalent to local host name (Default: CurrentHostName) */
Layer::Configuration layer;
};
}
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
19 changes: 10 additions & 9 deletions ecal/core/include/ecal/ecal_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@
//@{
namespace eCAL
{
ECAL_API Configuration& GetConfiguration();

ECAL_API Configuration& GetConfiguration ();
ECAL_API Registration::Configuration& GetRegistrationConfiguration ();
ECAL_API Monitoring::Configuration& GetMonitoringConfiguration ();
ECAL_API Logging::Configuration& GetLoggingConfiguration ();
ECAL_API Subscriber::Configuration& GetSubscriberConfiguration ();
ECAL_API Publisher::Configuration& GetPublisherConfiguration ();
ECAL_API Time::Configuration& GetTimesyncConfiguration ();
ECAL_API Service::Configuration& GetServiceConfiguration ();
ECAL_API Application::Configuration& GetApplicationConfiguration ();

namespace Config
{
/////////////////////////////////////
Expand Down Expand Up @@ -69,13 +77,6 @@ namespace eCAL
ECAL_API size_t GetTcpPubsubWriterThreadpoolSize ();
ECAL_API size_t GetTcpPubsubMaxReconnectionAttemps ();

ECAL_API int GetTcpPubReaderThreadpoolSize ();
ECAL_API int GetTcpPubWriterThreadpoolSize ();

ECAL_API int GetTcpSubReaderThreadpoolSize ();
ECAL_API int GetTcpSubWriterThreadpoolSize ();
ECAL_API int GetTcpSubMaxReconnectionAttemps ();

ECAL_API std::string GetHostGroupName ();

/////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/include/ecal/types/ecal_custom_data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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
53 changes: 53 additions & 0 deletions ecal/core/src/builder/registration_attribute_builder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* ========================= eCAL 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.
*
* ========================= eCAL LICENSE =================================
*/

#include "registration_attribute_builder.h"

namespace eCAL
{
Registration::SAttributes BuildRegistrationAttributes(const eCAL::Registration::Configuration& reg_config_, const eCAL::TransportLayer::UDP::Configuration& tl_udp_confi_, int process_id_)
{
Registration::SAttributes attr;

attr.refresh = reg_config_.registration_refresh;
attr.network_enabled = reg_config_.network_enabled;
attr.loopback = reg_config_.loopback;
attr.host_group_name = reg_config_.host_group_name;
attr.process_id = process_id_;

attr.shm_enabled = reg_config_.layer.shm.enable;
attr.udp_enabled = reg_config_.layer.udp.enable;

attr.shm.domain = reg_config_.layer.shm.domain;
attr.shm.queue_size = reg_config_.layer.shm.queue_size;

attr.udp.port = reg_config_.layer.udp.port;
attr.udp.sendbuffer = tl_udp_confi_.send_buffer;
attr.udp.receivebuffer = tl_udp_confi_.receive_buffer;
attr.udp.mode = tl_udp_confi_.mode;

attr.udp.network.group = tl_udp_confi_.network.group;
attr.udp.network.ttl = tl_udp_confi_.network.ttl;

attr.udp.local.group = tl_udp_confi_.local.group;
attr.udp.local.ttl = tl_udp_confi_.local.ttl;

return attr;
}
}
29 changes: 29 additions & 0 deletions ecal/core/src/builder/registration_attribute_builder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* ========================= eCAL 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.
*
* ========================= eCAL LICENSE =================================
*/

#pragma once

#include "registration/attributes/registration_attributes.h"

#include <ecal/ecal_config.h>

namespace eCAL
{
Registration::SAttributes BuildRegistrationAttributes(const eCAL::Registration::Configuration& reg_config_, const eCAL::TransportLayer::UDP::Configuration& tl_udp_confi_, int process_id_);
}
10 changes: 8 additions & 2 deletions ecal/core/src/config/configuration_to_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@ namespace YAML
AssignValue<unsigned int>(config_.registration_timeout, node_, "registration_timeout");
AssignValue<unsigned int>(config_.registration_refresh, node_, "registration_refresh");
AssignValue<bool>(config_.network_enabled, node_, "network_enabled");
AssignValue<bool>(config_.loopback, node_, "loopback");
AssignValue<std::string>(config_.host_group_name, node_, "host_group_name");
AssignValue<bool>(config_.loopback, node_, "loopback");
AssignValue<eCAL::Registration::Layer::Configuration>(config_.layer, node_, "layer");

// By default the host_group_name is set with the current host name.
// If the user does not specify the host group name in the yaml, leave it like it is.
std::string host_group_name;
AssignValue<std::string>(host_group_name, node_, "host_group_name");
if (!host_group_name.empty()) config_.host_group_name = host_group_name;

return true;
}

Expand Down
44 changes: 42 additions & 2 deletions ecal/core/src/config/ecal_config_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ namespace eCAL
{
eCAL::Logging::Log(log_level_warning, "Specified yaml configuration path not valid:\"" + yaml_path_ + "\". Using default configuration.");
}
};
}

Configuration::Configuration(int argc_ , char **argv_)
: Configuration(ConvertArgcArgvToVector(argc_, argv_))
Expand Down Expand Up @@ -275,7 +275,47 @@ namespace eCAL
Configuration& GetConfiguration()
{
return g_ecal_configuration;
};
}

Registration::Configuration& GetRegistrationConfiguration()
{
return GetConfiguration().registration;
}

Monitoring::Configuration& GetMonitoringConfiguration()
{
return GetConfiguration().monitoring;
}

Logging::Configuration& GetLoggingConfiguration()
{
return GetConfiguration().logging;
}

Subscriber::Configuration& GetSubscriberConfiguration()
{
return GetConfiguration().subscriber;
}

Publisher::Configuration& GetPublisherConfiguration()
{
return GetConfiguration().publisher;
}

Time::Configuration& GetTimesyncConfiguration()
{
return GetConfiguration().timesync;
}

Service::Configuration& GetServiceConfiguration()
{
return GetConfiguration().service;
}

Application::Configuration& GetApplicationConfiguration()
{
return GetConfiguration().application;
}
}


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;
}
}
}
}
9 changes: 6 additions & 3 deletions ecal/core/src/ecal_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "service/ecal_service_singleton_manager.h"
#endif

#include "builder/registration_attribute_builder.h"

namespace eCAL
{
CGlobals::CGlobals() : initialized(false), components(0)
Expand All @@ -49,12 +51,13 @@ namespace eCAL
bool new_initialization(false);

#if ECAL_CORE_REGISTRATION
const Registration::SAttributes registration_attr = BuildRegistrationAttributes(GetConfiguration().registration, GetConfiguration().transport_layer.udp, eCAL::Process::GetProcessID());
/////////////////////
// REGISTRATION PROVIDER
/////////////////////
if (registration_provider_instance == nullptr)
{
registration_provider_instance = std::make_unique<CRegistrationProvider>();
registration_provider_instance = std::make_unique<CRegistrationProvider>(registration_attr);
new_initialization = true;
}

Expand All @@ -63,7 +66,7 @@ namespace eCAL
/////////////////////
if(registration_receiver_instance == nullptr)
{
registration_receiver_instance = std::make_unique<CRegistrationReceiver>();
registration_receiver_instance = std::make_unique<CRegistrationReceiver>(registration_attr);
new_initialization = true;
}
#endif // ECAL_CORE_REGISTRATION
Expand Down Expand Up @@ -174,7 +177,7 @@ namespace eCAL
{
if (monitoring_instance == nullptr)
{
monitoring_instance = std::make_unique<CMonitoring>(eCAL::GetConfiguration().monitoring);
monitoring_instance = std::make_unique<CMonitoring>(eCAL::GetMonitoringConfiguration());
new_initialization = true;
}
}
Expand Down
Loading
Loading