Skip to content

Commit

Permalink
Removed ConstrainedInteger.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen committed Dec 5, 2024
1 parent b6b66b2 commit b7a4bec
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 109 deletions.
13 changes: 1 addition & 12 deletions doc/rst/configuration/runtime_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The corresponding structure reflects the configuration file (:ref:`configuration
Custom types
============

In order to rule out configuration errors, custom datatypes for IP addresses (IpAddressV4) and sizes (ConstrainedInteger) are introduced.
In order to rule out configuration errors, a custom datatype for IP addresses (IpAddressV4) is introduced.

**IpAddressV4:** For assigning an IP address simply assign a string with the desired address.
Decimal and hexadecimal format is supported.
Expand All @@ -25,17 +25,6 @@ The IP address can be used like a normal string object. For example:
eCAL::Types::IpAddressV4 ip_address = "192.168.7.1"; // in hex: "C0.A8.7.1"
std::cout << ip_address << "\n";

**ConstrainedInteger**: ConstrainedInteger are specified with a minimum (default: 0), step (default: 1) and maximum (default: maximum of int) value.
In case the assigned value does not fit into the specified limitation, the type will throw a std::invalid_argument exception.

The size object can be used like a normal integer.

.. code-block:: c++

eCAL::Types::ConstrainedInteger<1024, 512, 8192> size_4mb = 1024 + 6 * 512;
std::cout << size_4mb << "\n";

For specifying sizes in the ecal configuration object, refer to the .yaml file or "ecal/config/configuration.h" for the limitations.

Global configuration initialization
===================================
Expand Down
14 changes: 7 additions & 7 deletions ecal/core/include/ecal/config/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ namespace eCAL
{
struct Configuration
{
bool enable { true }; //!< enable layer
bool enable { true }; //!< enable layer

bool zero_copy_mode { false }; //!< Enable zero copy shared memory transport mode
unsigned int acknowledge_timeout_ms { 0U }; /*!< Force connected subscribers to send acknowledge event after processing the message.
The publisher send call is blocked on this event with this timeout (0 == no handshake).*/
unsigned int memfile_buffer_count { 1U }; /*!< Maximum number of used buffers (needs to be greater than 1, default = 1) */
Types::ConstrainedInteger<4096, 4096> memfile_min_size_bytes { 4096 }; //!< Default memory file size for new publisher (Default: 4096)
Types::ConstrainedInteger<50, 1, 100> memfile_reserve_percent { 50 }; //!< Dynamic file size reserve before recreating memory file if topic size changes (Default: 50)
bool zero_copy_mode { false }; //!< Enable zero copy shared memory transport mode
unsigned int acknowledge_timeout_ms { 0U }; /*!< Force connected subscribers to send acknowledge event after processing the message.
The publisher send call is blocked on this event with this timeout (0 == no handshake).*/
unsigned int memfile_buffer_count { 1U }; /*!< Maximum number of used buffers (needs to be greater than 1, default = 1) */
unsigned int memfile_min_size_bytes { 4096 }; //!< Default memory file size for new publisher (Default: 4096)
unsigned int memfile_reserve_percent { 50 }; //!< Dynamic file size reserve before recreating memory file if topic size changes (Default: 50)
};
}

Expand Down
33 changes: 16 additions & 17 deletions ecal/core/include/ecal/config/transport_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,23 @@ namespace eCAL

struct Configuration
{
Types::UdpConfigVersion config_version { Types::UdpConfigVersion::V2 }; /*!< UDP configuration version (Since eCAL 5.12.)
v1: default behavior
v2: new behavior, comes with a bit more intuitive handling regarding masking of the groups (Default: v2) */
unsigned int port { 14002 }; /*!< UDP multicast port number (Default: 14002) */
Types::UDPMode mode { Types::UDPMode::LOCAL }; /*!< Valid modes: local, network (Default: local)*/
Types::IpAddressV4 mask { "255.255.255.240" }; /*!< v1: Mask maximum number of dynamic multicast group (Default: 0.0.0.1-0.0.0.255)
v2: masks are now considered like routes masking (Default: 255.0.0.0-255.255.255.255)*/

// TODO PG: are these minimum limits correct?
Types::ConstrainedInteger<5242880, 1024> send_buffer { 5242880 }; //!< UDP send buffer in bytes (Default: 5242880)
Types::ConstrainedInteger<5242880, 1024> receive_buffer { 5242880 }; //!< UDP receive buffer in bytes (Default: 5242880)
bool join_all_interfaces { false }; /*!< Linux specific setting to enable joining multicast groups on all network interfacs
independent of their link state. Enabling this makes sure that eCAL processes
receive data if they are started before network devices are up and running. (Default: false)*/
bool npcap_enabled { false }; //!< Enable to receive UDP traffic with the Npcap based receiver (Default: false)
Types::UdpConfigVersion config_version { Types::UdpConfigVersion::V2 }; /*!< UDP configuration version (Since eCAL 5.12.)
v1: default behavior
v2: new behavior, comes with a bit more intuitive handling regarding masking of the groups (Default: v2) */
unsigned int port { 14002 }; /*!< UDP multicast port number (Default: 14002) */
Types::UDPMode mode { Types::UDPMode::LOCAL }; /*!< Valid modes: local, network (Default: local)*/
Types::IpAddressV4 mask { "255.255.255.240" }; /*!< v1: Mask maximum number of dynamic multicast group (Default: 0.0.0.1-0.0.0.255)
v2: masks are now considered like routes masking (Default: 255.0.0.0-255.255.255.255)*/

unsigned int send_buffer { 5242880 }; //!< UDP send buffer in bytes (Default: 5242880)
unsigned int receive_buffer { 5242880 }; //!< UDP receive buffer in bytes (Default: 5242880)
bool join_all_interfaces { false }; /*!< Linux specific setting to enable joining multicast groups on all network interfacs
independent of their link state. Enabling this makes sure that eCAL processes
receive data if they are started before network devices are up and running. (Default: false)*/
bool npcap_enabled { false }; //!< Enable to receive UDP traffic with the Npcap based receiver (Default: false)

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

ECAL_API Configuration& operator=(const Configuration& other);
};
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/include/ecal/config/user_arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace eCAL
struct Configuration
{
std::string user_yaml { "" }; //!< The used eCAL yaml file (Default: "")
bool dump_config { false }; //!< If specified, output configuration via standart output (Default: false)
bool dump_config { false }; //!< If specified, output configuration via standard output (Default: false)
};
}
}
37 changes: 0 additions & 37 deletions ecal/core/include/ecal/types/ecal_custom_data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,43 +66,6 @@ namespace eCAL
std::string m_ip_address{};
};

/**
* @brief Template class to specify sizes with a concrete minimum, maximum and step size definition.
*
* @tparam MIN Optional minimum possible size. Default: 0
* @tparam STEP Optional step size. Default: 1
* @tparam MAX Optional maximum possible size. Default: std::numeric_limits<int>::max()
*
* @param size_ Optional size value. If not set, ConstrainedInteger will return the MIN value.
*
* @throws std::invalid_argument exception.
**/
template<int MIN = 0, int STEP = 1, int MAX = std::numeric_limits<int>::max()>
class ConstrainedInteger
{
public:
ConstrainedInteger(int size_ = MIN)
{
if (size_ >= MIN && size_ <= MAX && size_ % STEP == 0 && MAX >= MIN)
{
m_size = size_;
}
else
{
throw std::invalid_argument("[ConstrainedInteger] Faulty size configuration or assignment. MIN: " + std::to_string(MIN) + " MAX: " + std::to_string(MAX) + " STEP: " + std::to_string(STEP) + " VALUE:" + std::to_string(size_));
}
};

operator int() const { return m_size; };
bool operator==(const ConstrainedInteger<MIN, STEP, MAX>& other) const { return this->m_size == other; };
bool operator==(const unsigned int value) const { return this->m_size == static_cast<int>(value); };
bool operator==(const int value) const { return this->m_size == value; };


private:
int m_size{};
};

enum class UdpConfigVersion
{
V1 = 1,
Expand Down
16 changes: 4 additions & 12 deletions ecal/core/src/config/configuration_to_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ namespace YAML
member = node_[key].as<AS>();
}

// Operator overload for assigning a ConstrainedInteger to a YAML::Node
template<int MIN, int STEP, int MAX>
YAML::Node operator<<(YAML::Node node, const eCAL::Types::ConstrainedInteger<MIN, STEP, MAX>& constrainedInt)
{
node = static_cast<int>(constrainedInt);
return node;
}

eCAL_Logging_Filter ParseLogLevel(const std::vector<std::string>& filter_)
{
// create excluding filter list
Expand Down Expand Up @@ -250,8 +242,8 @@ namespace YAML
node["mode"] = config_.mode == eCAL::Types::UDPMode::LOCAL ? "local" : "network";
node["port"] = config_.port;
node["mask"] = config_.mask.Get();
node["send_buffer"] << config_.send_buffer;
node["receive_buffer"] << config_.receive_buffer;
node["send_buffer"] = config_.send_buffer;
node["receive_buffer"] = config_.receive_buffer;
node["join_all_interfaces"] = config_.join_all_interfaces;
node["npcap_enabled"] = config_.npcap_enabled;
node["network"] = config_.network;
Expand Down Expand Up @@ -308,8 +300,8 @@ namespace YAML
node["zero_copy_mode"] = config_.zero_copy_mode;
node["acknowledge_timeout_ms"] = config_.acknowledge_timeout_ms;
node["memfile_buffer_count"] = config_.memfile_buffer_count;
node["memfile_min_size_bytes"] << config_.memfile_min_size_bytes;
node["memfile_reserve_percent"] << config_.memfile_reserve_percent;
node["memfile_min_size_bytes"] = config_.memfile_min_size_bytes;
node["memfile_reserve_percent"] = config_.memfile_reserve_percent;
return node;
}

Expand Down
23 changes: 0 additions & 23 deletions ecal/tests/cpp/config_test/src/config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,6 @@ TEST(core_cpp_config /*unused*/, user_config_death_test /*unused*/)
ASSERT_THROW(
SetValue(custom_config.transport_layer.udp.network.group, "0.00.000.0"),
std::invalid_argument);

// Test the ConstrainedInteger class with wrong values. Default are MIN = 5242880, STEP = 1024
// Value below MIN
ASSERT_THROW(
SetValue(custom_config.transport_layer.udp.send_buffer, 42),
std::invalid_argument);

// Wrong step. Default STEP = 1024
ASSERT_THROW(
SetValue(custom_config.transport_layer.udp.send_buffer, (5242880 + 512)),
std::invalid_argument);

}

TEST(core_cpp_config /*unused*/, config_custom_datatypes_tests /*unused*/)
Expand All @@ -181,14 +169,6 @@ TEST(core_cpp_config /*unused*/, config_custom_datatypes_tests /*unused*/)
ip2 = ip1;
EXPECT_EQ(ip1, ip2);

eCAL::Types::ConstrainedInteger<0,1,10> s1;
eCAL::Types::ConstrainedInteger<0,1,10> s2;
EXPECT_EQ(s1, s2);

s1 = 5;
s2 = s1;
EXPECT_EQ(s1, s2);

// test copy method for config structure
eCAL::Configuration config1(0, nullptr);
eCAL::Configuration config2(0, nullptr);
Expand Down Expand Up @@ -262,9 +242,6 @@ TEST(core_cpp_config /*unused*/, parse_values_test /*unused*/)
// Check equality of IpAddressV4
EXPECT_EQ(config.transport_layer.udp.network.group, "239.5.0.1");

// Check constrained Integer
EXPECT_EQ(config.transport_layer.udp.port, 14010);

// Check boolean
EXPECT_EQ(config.transport_layer.udp.npcap_enabled, true);

Expand Down

0 comments on commit b7a4bec

Please sign in to comment.