Skip to content

Commit 9ab136b

Browse files
Use SubscriptionOptions
Signed-off-by: Luca Della Vedova <[email protected]>
1 parent 8c216af commit 9ab136b

File tree

2 files changed

+8
-39
lines changed

2 files changed

+8
-39
lines changed

rclrs/src/dynamic_message/dynamic_subscription.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use super::{
1212
};
1313
use crate::rcl_bindings::*;
1414
use crate::{
15-
MessageInfo, NodeHandle, QoSProfile, RclPrimitive, RclPrimitiveHandle, RclPrimitiveKind,
15+
MessageInfo, NodeHandle, RclPrimitive, RclPrimitiveHandle, RclPrimitiveKind,
1616
RclrsError, SubscriptionHandle, ToResult, Waitable, WaitableLifecycle, WorkScope,
17-
WorkerCommands, ENTITY_LIFECYCLE_MUTEX,
17+
WorkerCommands, ENTITY_LIFECYCLE_MUTEX, SubscriptionOptions,
1818
};
1919

2020
struct DynamicSubscriptionExecutable<Payload> {
@@ -181,17 +181,17 @@ where
181181
/// Creates a new dynamic subscription.
182182
///
183183
/// This is not a public function, by the same rationale as `Subscription::new()`.
184-
pub(crate) fn new(
185-
topic: &str,
184+
pub(crate) fn new<'a>(
186185
topic_type: MessageTypeName,
187-
qos: QoSProfile,
186+
options: impl Into<SubscriptionOptions<'a>>,
188187
callback: impl Into<DynamicSubscriptionCallback<Scope::Payload>>,
189188
node_handle: &Arc<NodeHandle>,
190189
commands: &Arc<WorkerCommands>,
191190
) -> Result<Arc<Self>, RclrsError> {
192191
// TODO(luca) a lot of duplication with nomral, refactor
193192
// This loads the introspection type support library.
194193
let metadata = DynamicMessageMetadata::new(topic_type)?;
194+
let SubscriptionOptions { topic, qos } = options.into();
195195
// However, we also need the regular type support library –
196196
// the rosidl_typesupport_c one.
197197
let message_type = &metadata.message_type;

rclrs/src/node.rs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub use primitive_options::*;
77
mod graph;
88
#[cfg(feature = "dyn_msg")]
99
use crate::dynamic_message::{DynamicMessage, DynamicSubscription};
10-
use crate::QoSProfile;
1110

1211
pub use graph::*;
1312

@@ -793,23 +792,19 @@ impl NodeState {
793792
)
794793
}
795794

796-
// TODO(luca) introduce subscription options and perhaps an into callback
797795
#[cfg(feature = "dyn_msg")]
798-
pub fn create_dynamic_subscription<F>(
796+
pub fn create_dynamic_subscription<'a, F>(
799797
&self,
800-
// options: impl Into<DynamicSubscriptionOptions<'a>>,
801-
topic: &str,
802798
topic_type: MessageTypeName,
803-
qos: QoSProfile,
799+
options: impl Into<SubscriptionOptions<'a>>,
804800
callback: F,
805801
) -> Result<Arc<DynamicSubscription<Node>>, RclrsError>
806802
where
807803
F: FnMut(DynamicMessage, MessageInfo) -> BoxFuture<'static, ()> + Send + 'static,
808804
{
809805
let subscription = DynamicSubscription::new(
810-
topic,
811806
topic_type,
812-
qos,
807+
options,
813808
NodeDynamicSubscriptionCallback(Box::new(callback)),
814809
&self.handle,
815810
self.commands.async_worker_commands(),
@@ -818,32 +813,6 @@ impl NodeState {
818813
Ok(subscription)
819814
}
820815

821-
/// Creates a [`DynamicSubscription`][1].
822-
///
823-
/// [1]: crate::dynamic_message::DynamicSubscription
824-
// TODO: make subscription's lifetime depend on node's lifetime
825-
// TODO(luca) convert to subscription options
826-
/*
827-
#[cfg(feature = "dyn_msg")]
828-
pub fn create_dynamic_subscription<F>(
829-
&mut self,
830-
topic: &str,
831-
topic_type: &str,
832-
qos: QoSProfile,
833-
callback: F,
834-
) -> Result<Arc<DynamicSubscription>, RclrsError>
835-
where
836-
F: FnMut(DynamicMessage) + 'static + Send,
837-
{
838-
let subscription = Arc::new(DynamicSubscription::new(
839-
self, topic, topic_type, qos, callback,
840-
)?);
841-
self.subscriptions
842-
.push(Arc::downgrade(&subscription) as Weak<dyn SubscriptionBase>);
843-
Ok(subscription)
844-
}
845-
*/
846-
847816
/// Creates a [`Subscription`] with an async callback.
848817
///
849818
/// # Behavior

0 commit comments

Comments
 (0)