Skip to content

Commit 42cd70f

Browse files
Cleanup
Signed-off-by: Luca Della Vedova <[email protected]>
1 parent 83cf32c commit 42cd70f

File tree

7 files changed

+26
-57
lines changed

7 files changed

+26
-57
lines changed

examples/dynamic_pub_sub/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
rclrs = { version = "0.3", features = ["dyn_msg"] }
9+
# TODO(luca) change this to a version once dynamic message support is released on crates.io
10+
rclrs = { path = "../../rclrs", features = ["dyn_msg"] }
1011
anyhow = {version = "1", features = ["backtrace"]}

examples/dynamic_pub_sub/src/main.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
use anyhow::{Error, Result};
2-
use std::env;
2+
use rclrs::*;
33

44
fn main() -> Result<(), Error> {
5-
let context = rclrs::Context::new(env::args())?;
5+
let context = Context::default_from_env()?;
6+
let mut executor = context.create_basic_executor();
67

7-
let mut node = rclrs::create_node(&context, "dynamic_subscriber")?;
8+
let node = executor.create_node("dynamic_subscriber")?;
89

9-
let mut num_messages: usize = 0;
10-
11-
let _subscription = node.create_dynamic_subscription(
10+
let worker = node.create_worker::<usize>(0);
11+
let _subscription = worker.create_dynamic_subscription(
12+
"rclrs_example_msgs/msg/VariousTypes".try_into()?,
1213
"topic",
13-
"rclrs_example_msgs/msg/VariousTypes",
14-
rclrs::QOS_PROFILE_DEFAULT,
15-
move |msg| {
16-
num_messages += 1;
17-
println!("I heard: '{:#?}'", msg.structure());
14+
move |num_messages: &mut usize, msg, _msg_info| {
15+
*num_messages += 1;
16+
println!("#{} | I heard: '{:#?}'", *num_messages, msg.structure());
1817
},
1918
)?;
2019

21-
rclrs::spin(&node).map_err(|err| err.into())
20+
println!("Waiting for messages...");
21+
executor.spin(SpinOptions::default()).first_error()?;
22+
Ok(())
2223
}

examples/rclrs_example_msgs/msg/VariousTypes.msg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ bool bool_member true
33
int8 int8_member 1
44
uint8 uint8_member 2
55
byte byte_member 3
6-
char char_member 3
76
float32 float32_member 1e-2
87

98
# Array/sequence of primitive type

rclrs/src/dynamic_message/dynamic_publisher.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,9 @@ use crate::{NodeHandle, PublisherHandle, PublisherOptions, ENTITY_LIFECYCLE_MUTE
1717
/// [1]: crate::NodeState::create_dynamic_publisher
1818
pub type DynamicPublisher = Arc<DynamicPublisherState>;
1919

20-
/// Struct for sending messages of type `T`.
20+
/// The inner state of a dynamic publisher.
2121
///
22-
/// Multiple publishers can be created for the same topic, in different nodes or the same node.
23-
///
24-
/// The underlying RMW will decide on the concrete delivery mechanism (network stack, shared
25-
/// memory, or intraprocess).
26-
///
27-
/// Sending messages does not require calling [`spin`][1] on the publisher's node.
28-
///
29-
/// [1]: crate::spin
22+
/// Refer to [`crate::PublisherState`] for details of the behavior.
3023
pub struct DynamicPublisherState {
3124
handle: PublisherHandle,
3225
metadata: DynamicMessageMetadata,

rclrs/src/node.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,12 @@ impl NodeState {
408408

409409
/// Creates a [`DynamicPublisher`], a publisher whose type is only known at runtime.
410410
///
411-
/// Refer to [`Node::create_publisher`] for the API, the only key difference is that the
411+
/// Refer to [`Node::create_publisher`][1] for the API, the only key difference is that the
412412
/// publisher's message type is passed as a [`crate::MessageTypeName`] parameter.
413413
///
414414
/// Pass in only the topic name for the `options` argument to use all default publisher options:
415+
///
416+
/// [1]: crate::NodeState::create_publisher
415417
/// ```
416418
/// # use rclrs::*;
417419
/// # let executor = Context::default().create_basic_executor();
@@ -824,7 +826,7 @@ impl NodeState {
824826

825827
/// Creates a [`DynamicSubscription`] with an ordinary callback.
826828
///
827-
/// For the behavior and API refer to [`Node::create_subscription`], except two key
829+
/// For the behavior and API refer to [`Node::create_subscription`][1], except two key
828830
/// differences:
829831
///
830832
/// - The message type is determined at runtime through the `topic_type` function parameter.
@@ -834,6 +836,8 @@ impl NodeState {
834836
/// # Message type passing
835837
///
836838
/// The message type can be passed as a [`crate::MessageTypeName`] struct. The struct also implements `TryFrom<&str>`
839+
///
840+
/// [1]: crate::NodeState::create_publisher
837841
/// ```
838842
/// # use rclrs::*;
839843
/// # let executor = Context::default().create_basic_executor();
@@ -879,7 +883,7 @@ impl NodeState {
879883

880884
/// Creates a [`DynamicSubscription`] with an async callback.
881885
///
882-
/// For the behavior and API refer to [`Node::create_async_subscription`], except two key
886+
/// For the behavior and API refer to [`Node::create_async_subscription`][1], except two key
883887
/// differences:
884888
///
885889
/// - The message type is determined at runtime through the `topic_type` function parameter.
@@ -889,6 +893,8 @@ impl NodeState {
889893
/// # Message type passing
890894
///
891895
/// The message type can be passed as a [`crate::MessageTypeName`] struct. The struct also implements `TryFrom<&str>`
896+
///
897+
/// [1]: crate::NodeState::create_async_subscription
892898
/// ```
893899
/// # use rclrs::*;
894900
/// # let executor = Context::default().create_basic_executor();

rclrs/src/subscription.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -244,32 +244,6 @@ impl<'a, T: IntoPrimitiveOptions<'a>> From<T> for SubscriptionOptions<'a> {
244244
}
245245
}
246246

247-
/// `SubscriptionOptions` are used by [`Node::create_subscription`][1] to initialize
248-
/// a [`Subscription`].
249-
///
250-
/// [1]: crate::NodeState::create_subscription
251-
#[derive(Debug, Clone)]
252-
#[non_exhaustive]
253-
pub struct DynamicSubscriptionOptions<'a> {
254-
/// The topic name for the subscription.
255-
pub topic: &'a str,
256-
/// The topic type for the subscription.
257-
pub topic_type: &'a str,
258-
/// The quality of service settings for the subscription.
259-
pub qos: QoSProfile,
260-
}
261-
262-
impl<'a> DynamicSubscriptionOptions<'a> {
263-
/// Initialize a new [`SubscriptionOptions`] with default settings.
264-
pub fn new(topic: &'a str, topic_type: &'a str) -> Self {
265-
Self {
266-
topic,
267-
topic_type,
268-
qos: QoSProfile::topics_default(),
269-
}
270-
}
271-
}
272-
273247
struct SubscriptionExecutable<T: Message, Payload> {
274248
handle: Arc<SubscriptionHandle>,
275249
callback: Arc<Mutex<AnySubscriptionCallback<T, Payload>>>,

rclrs/test_header.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)