From cbedefb0f92411fa66bcb0ccedd7b83cbc49c607 Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Mon, 12 Apr 2021 10:23:38 +0200 Subject: [PATCH] qos: add a way of merging service level options In order to combine multiple service level options coming from multiple roles, a helper function is provided to merge two of them. The semantics depend on each parameter, but for timeouts, which are the only parameters at the time of writing this message, the minimum value of the two is taken. That in particular means that when service level A has timeout = 50ms and service level B has timeout = 1s, the resulting service level options would set the timeout to 50ms. --- service/qos/qos_common.cc | 18 ++++++++++++++++++ service/qos/qos_common.hh | 3 +++ 2 files changed, 21 insertions(+) diff --git a/service/qos/qos_common.cc b/service/qos/qos_common.cc index a56a8c5cf5..26be4391da 100644 --- a/service/qos/qos_common.cc +++ b/service/qos/qos_common.cc @@ -41,4 +41,22 @@ service_level_options service_level_options::replace_defaults(const service_leve return ret; } +service_level_options service_level_options::merge_with(const service_level_options& other) const { + service_level_options ret = *this; + std::visit(overloaded_functor { + [&] (const unset_marker& um) { + ret.timeout = other.timeout; + }, + [&] (const delete_marker& dm) { + ret.timeout = other.timeout; + }, + [&] (const lowres_clock::duration& d) { + if (auto* other_timeout = std::get_if(&other.timeout)) { + ret.timeout = std::min(d, *other_timeout); + } + }, + }, ret.timeout); + return ret; +} + } diff --git a/service/qos/qos_common.hh b/service/qos/qos_common.hh index b4b79f8568..54845a17c5 100644 --- a/service/qos/qos_common.hh +++ b/service/qos/qos_common.hh @@ -49,6 +49,9 @@ struct service_level_options { timeout_type timeout = unset_marker{}; service_level_options replace_defaults(const service_level_options& other) const; + // Merges the values of two service level options. The semantics depends + // on the type of the parameter - e.g. for timeouts, a min value is preferred. + service_level_options merge_with(const service_level_options& other) const; bool operator==(const service_level_options& other) const = default; bool operator!=(const service_level_options& other) const = default;