From f905004906f8729abe91538975f8d555bd0777af Mon Sep 17 00:00:00 2001 From: Yadunund Date: Mon, 15 Jan 2024 10:23:07 +0800 Subject: [PATCH] Explictly map qos settings Signed-off-by: Yadunund --- rmw_zenoh_cpp/src/detail/liveliness_utils.cpp | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp index 726bacb6..f44a6e74 100644 --- a/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp +++ b/rmw_zenoh_cpp/src/detail/liveliness_utils.cpp @@ -86,6 +86,31 @@ static const std::unordered_map str_to_entity = { {CLI_STR, EntityType::Client} }; +static const std::unordered_map str_to_qos_history = { + {std::to_string(RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT), RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT}, + {std::to_string(RMW_QOS_POLICY_HISTORY_KEEP_LAST), RMW_QOS_POLICY_HISTORY_KEEP_LAST}, + {std::to_string(RMW_QOS_POLICY_HISTORY_KEEP_ALL), RMW_QOS_POLICY_HISTORY_KEEP_ALL}, + {std::to_string(RMW_QOS_POLICY_HISTORY_UNKNOWN), RMW_QOS_POLICY_HISTORY_UNKNOWN} +}; + +static const std::unordered_map str_to_qos_reliability = { + {std::to_string(RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT), + RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT}, + {std::to_string(RMW_QOS_POLICY_RELIABILITY_RELIABLE), RMW_QOS_POLICY_RELIABILITY_RELIABLE}, + {std::to_string(RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT), RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT}, + {std::to_string(RMW_QOS_POLICY_RELIABILITY_UNKNOWN), RMW_QOS_POLICY_RELIABILITY_UNKNOWN} +}; + +static const std::unordered_map str_to_qos_durability = { + {std::to_string(RMW_QOS_POLICY_DURABILITY_SYSTEM_DEFAULT), + RMW_QOS_POLICY_DURABILITY_SYSTEM_DEFAULT}, + {std::to_string(RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL), + RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL}, + {std::to_string(RMW_QOS_POLICY_DURABILITY_VOLATILE), RMW_QOS_POLICY_DURABILITY_VOLATILE}, + {std::to_string(RMW_QOS_POLICY_DURABILITY_UNKNOWN), RMW_QOS_POLICY_DURABILITY_UNKNOWN} +}; + std::string zid_to_str(z_id_t id) { std::stringstream ss; @@ -163,11 +188,23 @@ std::optional keyexpr_to_qos(const std::string & keyexpr) if (history_parts.size() < 2) { return std::nullopt; } - sscanf(parts[0].c_str(), "%zu", &qos.reliability); - sscanf(parts[1].c_str(), "%zu", &qos.durability); - sscanf(history_parts[0].c_str(), "%zu", &qos.history); + + try { + qos.history = str_to_qos_history.at(history_parts[0]); + qos.reliability = str_to_qos_reliability.at(parts[0]); + qos.durability = str_to_qos_durability.at(parts[1]); + } catch (const std::exception & e) { + return std::nullopt; + } sscanf(history_parts[1].c_str(), "%zu", &qos.depth); + // Liveliness is always automatic given liveliness tokens. + qos.liveliness = RMW_QOS_POLICY_LIVELINESS_AUTOMATIC; + qos.liveliness_lease_duration = RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT; + + // TODO(Yadunund): Update once we support these settings. + qos.deadline = RMW_QOS_DEADLINE_DEFAULT; + qos.lifespan = RMW_QOS_LIFESPAN_DEFAULT; return qos; }