-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathqos.cpp
152 lines (134 loc) · 5.47 KB
/
qos.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// 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_VOLATILE;
#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_;
}
///=============================================================================
bool QoS::is_supported(const rmw_qos_profile_t & qos_profile)
{
if (qos_profile.history == RMW_QOS_POLICY_HISTORY_UNKNOWN ||
qos_profile.reliability == RMW_QOS_POLICY_RELIABILITY_UNKNOWN ||
qos_profile.durability == RMW_QOS_POLICY_DURABILITY_UNKNOWN ||
qos_profile.liveliness == RMW_QOS_POLICY_LIVELINESS_UNKNOWN)
{
return false;
}
return true;
}
///=============================================================================
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);
if (!is_supported(*qos_profile)) {
return RMW_RET_UNSUPPORTED;
}
switch (qos_profile->history) {
case RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT:
case RMW_QOS_POLICY_HISTORY_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