-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement custom functions to adapt qos (#234)
Signed-off-by: Yadunund <[email protected]>
- Loading branch information
Showing
9 changed files
with
223 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright 2024 Open Source Robotics Foundation, Inc. | ||
// | ||
// 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. | ||
|
||
#include "qos.hpp" | ||
|
||
// Define defaults for various QoS settings. | ||
#define RMW_ZENOH_DEFAULT_HISTORY RMW_QOS_POLICY_HISTORY_KEEP_LAST; | ||
// If the depth field in the qos profile is set to 0, the RMW implementation | ||
// has the liberty to assign a default depth. The zenoh transport protocol | ||
// is configured with 256 channels so theoretically, this would be the maximum | ||
// depth we can set before blocking transport. A high depth would increase the | ||
// memory footprint of processes as more messages are stored in memory while a | ||
// very low depth might unintentionally drop messages leading to a poor | ||
// out-of-the-box experience for new users. For now we set the depth to 42, | ||
// a popular "magic number". See https://en.wikipedia.org/wiki/42_(number). | ||
#define RMW_ZENOH_DEFAULT_HISTORY_DEPTH 42; | ||
#define RMW_ZENOH_DEFAULT_RELIABILITY RMW_QOS_POLICY_RELIABILITY_RELIABLE; | ||
#define RMW_ZENOH_DEFAULT_DURABILITY RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL; | ||
#define RMW_ZENOH_DEFAULT_DEADLINE RMW_DURATION_INFINITE; | ||
#define RMW_ZENOH_DEFAULT_LIFESPAN RMW_DURATION_INFINITE; | ||
#define RMW_ZENOH_DEFAULT_LIVELINESS RMW_QOS_POLICY_LIVELINESS_AUTOMATIC; | ||
#define RMW_ZENOH_DEFAULT_LIVELINESS_LEASE_DURATION RMW_DURATION_INFINITE; | ||
|
||
namespace rmw_zenoh_cpp | ||
{ | ||
///============================================================================= | ||
QoS::QoS() | ||
{ | ||
default_qos_.history = RMW_ZENOH_DEFAULT_HISTORY; | ||
default_qos_.depth = RMW_ZENOH_DEFAULT_HISTORY_DEPTH; | ||
default_qos_.reliability = RMW_ZENOH_DEFAULT_RELIABILITY; | ||
default_qos_.durability = RMW_ZENOH_DEFAULT_DURABILITY; | ||
default_qos_.deadline = RMW_ZENOH_DEFAULT_DEADLINE; | ||
default_qos_.lifespan = RMW_ZENOH_DEFAULT_LIFESPAN; | ||
default_qos_.liveliness = RMW_ZENOH_DEFAULT_LIVELINESS; | ||
default_qos_.liveliness_lease_duration = RMW_ZENOH_DEFAULT_LIVELINESS_LEASE_DURATION; | ||
} | ||
|
||
///============================================================================= | ||
QoS & QoS::get() | ||
{ | ||
static QoS qos; | ||
return qos; | ||
} | ||
|
||
///============================================================================= | ||
const rmw_qos_profile_t & QoS::default_qos() const | ||
{ | ||
return default_qos_; | ||
} | ||
|
||
///============================================================================= | ||
rmw_ret_t QoS::best_available_qos( | ||
const rmw_node_t * node, | ||
const char * topic_name, | ||
rmw_qos_profile_t * qos_profile, | ||
const GetEndpointInfoByTopicFunction & get_endpoint_info_for_other) const | ||
{ | ||
// We could rely on the GetEndpointInfoByTopicFunction callback to get | ||
// endpoint information of downstream consumers to match certain QoS settings. | ||
// Practically since Zenoh transport will succeed for any combination of | ||
// settings, this could only be useful to avoid creating transient_local | ||
// subscriptions when there are no transient_local publishers in the graph. | ||
// This will avoid some overhead with having QueryingSubscriber. For now, | ||
// we skip this optimization. | ||
static_cast<void>(node); | ||
static_cast<void>(topic_name); | ||
static_cast<void>(get_endpoint_info_for_other); | ||
|
||
switch (qos_profile->history) { | ||
case RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT: | ||
case RMW_QOS_POLICY_RELIABILITY_UNKNOWN: | ||
qos_profile->history = default_qos_.history; | ||
default: | ||
break; | ||
} | ||
|
||
if (qos_profile->depth == 0) { | ||
qos_profile->depth = default_qos_.depth; | ||
} | ||
|
||
switch (qos_profile->reliability) { | ||
case RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT: | ||
case RMW_QOS_POLICY_RELIABILITY_UNKNOWN: | ||
qos_profile->reliability = default_qos_.reliability; | ||
default: | ||
break; | ||
} | ||
|
||
switch (qos_profile->durability) { | ||
case RMW_QOS_POLICY_DURABILITY_SYSTEM_DEFAULT: | ||
case RMW_QOS_POLICY_DURABILITY_UNKNOWN: | ||
qos_profile->durability = default_qos_.durability; | ||
default: | ||
break; | ||
} | ||
|
||
if (rmw_time_equal(qos_profile->deadline, RMW_QOS_DEADLINE_DEFAULT)) { | ||
qos_profile->deadline = default_qos_.deadline; | ||
} | ||
|
||
if (rmw_time_equal(qos_profile->lifespan, RMW_QOS_LIFESPAN_DEFAULT)) { | ||
qos_profile->lifespan = default_qos_.lifespan; | ||
} | ||
|
||
if (rmw_time_equal( | ||
qos_profile->liveliness_lease_duration, | ||
RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT)) | ||
{ | ||
qos_profile->liveliness_lease_duration = default_qos_.liveliness_lease_duration; | ||
} | ||
|
||
switch (qos_profile->liveliness) { | ||
case RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT: | ||
case RMW_QOS_POLICY_LIVELINESS_UNKNOWN: | ||
qos_profile->liveliness = default_qos_.liveliness; | ||
default: | ||
break; | ||
} | ||
|
||
return RMW_RET_OK; | ||
} | ||
} // namespace rmw_zenoh_cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 Open Source Robotics Foundation, Inc. | ||
// | ||
// 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. | ||
|
||
#ifndef DETAIL__QOS_HPP_ | ||
#define DETAIL__QOS_HPP_ | ||
|
||
#include <rcutils/logging.h> | ||
#include <rmw/topic_endpoint_info_array.h> | ||
#include <rmw/types.h> | ||
|
||
#include <functional> | ||
|
||
namespace rmw_zenoh_cpp | ||
{ | ||
//============================================================================== | ||
/// Signature matching rmw_get_publishers_info_by_topic and rmw_get_subscriptions_info_by_topic | ||
using GetEndpointInfoByTopicFunction = std::function<rmw_ret_t( | ||
const rmw_node_t *, | ||
rcutils_allocator_t *, | ||
const char *, | ||
bool, | ||
rmw_topic_endpoint_info_array_t *)>; | ||
|
||
//============================================================================== | ||
class QoS | ||
{ | ||
public: | ||
static QoS & get(); | ||
|
||
const rmw_qos_profile_t & default_qos() const; | ||
|
||
rmw_ret_t best_available_qos( | ||
const rmw_node_t * node, | ||
const char * topic_name, | ||
rmw_qos_profile_t * qos_profile, | ||
const GetEndpointInfoByTopicFunction & get_endpoint_info_for_other) const; | ||
|
||
private: | ||
// Private constructor which initializes the default qos. | ||
QoS(); | ||
rmw_qos_profile_t default_qos_; | ||
}; | ||
} // namespace rmw_zenoh_cpp | ||
|
||
#endif // DETAIL__QOS_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.