Skip to content

Commit 27bc355

Browse files
Add default implementation and builder pattern for QoS (#361)
* Add default implementation and builder pattern for QoS Signed-off-by: Luca Della Vedova <[email protected]> * Add method that take a duration Signed-off-by: Luca Della Vedova <[email protected]> * Add comment to default implementation Signed-off-by: Luca Della Vedova <[email protected]> --------- Signed-off-by: Luca Della Vedova <[email protected]>
1 parent aa779c7 commit 27bc355

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

rclrs/src/qos.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ pub struct QoSProfile {
179179
pub avoid_ros_namespace_conventions: bool,
180180
}
181181

182+
/// Sets the `QoSProfile` to the RCL default.
183+
impl Default for QoSProfile {
184+
fn default() -> Self {
185+
QOS_PROFILE_DEFAULT
186+
}
187+
}
188+
182189
impl From<QoSProfile> for rmw_qos_profile_t {
183190
fn from(qos: QoSProfile) -> Self {
184191
Self {
@@ -199,6 +206,62 @@ impl From<QoSProfile> for rmw_qos_profile_t {
199206
}
200207
}
201208

209+
impl QoSProfile {
210+
/// Sets the QoS profile history to [QoSHistoryPolicy::KeepLast] with the specified depth.
211+
pub fn keep_last(mut self, depth: u32) -> Self {
212+
self.history = QoSHistoryPolicy::KeepLast { depth };
213+
self
214+
}
215+
216+
/// Sets the QoS profile history to [QoSHistoryPolicy::KeepAll].
217+
pub fn keep_all(mut self) -> Self {
218+
self.history = QoSHistoryPolicy::KeepAll;
219+
self
220+
}
221+
222+
/// Sets the QoS profile reliability to [QoSReliabilityPolicy::Reliable].
223+
pub fn reliable(mut self) -> Self {
224+
self.reliability = QoSReliabilityPolicy::Reliable;
225+
self
226+
}
227+
228+
/// Sets the QoS profile reliability to [QoSReliabilityPolicy::BestEffort].
229+
pub fn best_effort(mut self) -> Self {
230+
self.reliability = QoSReliabilityPolicy::BestEffort;
231+
self
232+
}
233+
234+
/// Sets the QoS profile durability to [QoSDurabilityPolicy::Volatile].
235+
pub fn volatile(mut self) -> Self {
236+
self.durability = QoSDurabilityPolicy::Volatile;
237+
self
238+
}
239+
240+
/// Sets the QoS profile durability to [QoSDurabilityPolicy::TransientLocal].
241+
pub fn transient_local(mut self) -> Self {
242+
self.durability = QoSDurabilityPolicy::TransientLocal;
243+
self
244+
}
245+
246+
/// Sets the QoS profile deadline to the specified `Duration`.
247+
pub fn deadline(mut self, deadline: Duration) -> Self {
248+
self.deadline = QoSDuration::Custom(deadline);
249+
self
250+
}
251+
252+
/// Sets the QoS profile liveliness lease duration to the specified `Duration`.
253+
pub fn liveliness_lease_duration(mut self, lease_duration: Duration) -> Self {
254+
self.liveliness_lease_duration = QoSDuration::Custom(lease_duration);
255+
self
256+
}
257+
258+
/// Sets the QoS profile lifespan to the specified `Duration`.
259+
pub fn lifespan(mut self, lifespan: Duration) -> Self {
260+
self.lifespan = QoSDuration::Custom(lifespan);
261+
self
262+
}
263+
}
264+
202265
impl From<QoSHistoryPolicy> for rmw_qos_history_policy_t {
203266
fn from(policy: QoSHistoryPolicy) -> Self {
204267
match policy {

0 commit comments

Comments
 (0)