Skip to content

Commit c048a8a

Browse files
committed
Options pattern (spin-off of #427) (#429)
* Migrate to SubscriptionOptions Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Migrate to PublisherOptions Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Migrate to ServiceOptions Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Migrate to ClientOptions Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Enable direct creation of the _Options for all primitive types Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Fix example formatting Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Fix docs Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Make deadline, liveliness_lease, and lifespan all symmetric Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Add an API to the primitive options builder for avoiding ROS namespace conventions Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Retrigger CI Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Fix: Override all profile options when using .qos Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Reword the warning for system_qos Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Reword the warning for QoSProfile::system_default Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Rename PrimitiveOptions::apply to apply_to Signed-off-by: Michael X. Grey <greyxmike@gmail.com> --------- Signed-off-by: Michael X. Grey <greyxmike@gmail.com> Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>
1 parent bfceba9 commit c048a8a

File tree

8 files changed

+12
-27
lines changed

8 files changed

+12
-27
lines changed

rclrs/message_demo/src/message_demo.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,19 @@ fn demonstrate_pubsub() -> Result<(), Error> {
143143
let mut executor = Context::default_from_env()?.create_basic_executor();
144144
let node = executor.create_node("message_demo")?;
145145

146-
let idiomatic_publisher = node
147-
.create_publisher::<rclrs_example_msgs::msg::VariousTypes>("topic", QOS_PROFILE_DEFAULT)?;
148-
let direct_publisher = node.create_publisher::<rclrs_example_msgs::msg::rmw::VariousTypes>(
149-
"topic",
150-
QOS_PROFILE_DEFAULT,
151-
)?;
146+
let idiomatic_publisher =
147+
node.create_publisher::<rclrs_example_msgs::msg::VariousTypes>("topic")?;
148+
let direct_publisher =
149+
node.create_publisher::<rclrs_example_msgs::msg::rmw::VariousTypes>("topic")?;
152150

153151
let _idiomatic_subscription = node
154152
.create_subscription::<rclrs_example_msgs::msg::VariousTypes, _>(
155153
"topic",
156-
QOS_PROFILE_DEFAULT,
157154
move |_msg: rclrs_example_msgs::msg::VariousTypes| println!("Got idiomatic message!"),
158155
)?;
159156
let _direct_subscription = node
160157
.create_subscription::<rclrs_example_msgs::msg::rmw::VariousTypes, _>(
161158
"topic",
162-
QOS_PROFILE_DEFAULT,
163159
move |_msg: rclrs_example_msgs::msg::rmw::VariousTypes| {
164160
println!("Got RMW-native message!")
165161
},

rclrs/minimal_pub_sub/src/minimal_publisher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() -> Result<(), Error> {
77

88
let node = executor.create_node("minimal_publisher")?;
99

10-
let publisher = node.create_publisher::<std_msgs::msg::String>("topic", QOS_PROFILE_DEFAULT)?;
10+
let publisher = node.create_publisher::<std_msgs::msg::String>("topic")?;
1111

1212
let mut message = std_msgs::msg::String::default();
1313

rclrs/minimal_pub_sub/src/minimal_subscriber.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn main() -> Result<(), Error> {
1111

1212
let _subscription = node.create_subscription::<std_msgs::msg::String, _>(
1313
"topic",
14-
QOS_PROFILE_DEFAULT,
1514
move |msg: std_msgs::msg::String| {
1615
num_messages += 1;
1716
println!("I heard: '{}'", msg.data);

rclrs/minimal_pub_sub/src/minimal_two_nodes.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ impl MinimalSubscriber {
2626
.node
2727
.create_subscription::<std_msgs::msg::String, _>(
2828
topic,
29-
QOS_PROFILE_DEFAULT,
3029
move |msg: std_msgs::msg::String| {
3130
minimal_subscriber_aux.callback(msg);
3231
},
@@ -55,8 +54,7 @@ fn main() -> Result<(), Error> {
5554
let _subscriber_node_two =
5655
MinimalSubscriber::new(&executor, "minimal_subscriber_two", "topic")?;
5756

58-
let publisher =
59-
publisher_node.create_publisher::<std_msgs::msg::String>("topic", QOS_PROFILE_DEFAULT)?;
57+
let publisher = publisher_node.create_publisher::<std_msgs::msg::String>("topic")?;
6058

6159
std::thread::spawn(move || -> Result<(), RclrsError> {
6260
let mut message = std_msgs::msg::String::default();

rclrs/minimal_pub_sub/src/zero_copy_publisher.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ fn main() -> Result<(), Error> {
77

88
let node = executor.create_node("minimal_publisher")?;
99

10-
let publisher =
11-
node.create_publisher::<std_msgs::msg::rmw::UInt32>("topic", QOS_PROFILE_DEFAULT)?;
10+
let publisher = node.create_publisher::<std_msgs::msg::rmw::UInt32>("topic")?;
1211

1312
let mut publish_count: u32 = 1;
1413

rclrs/minimal_pub_sub/src/zero_copy_subscriber.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ fn main() -> Result<(), Error> {
1010

1111
let _subscription = node.create_subscription::<std_msgs::msg::UInt32, _>(
1212
"topic",
13-
QOS_PROFILE_DEFAULT,
14-
move |msg: ReadOnlyLoanedMessage<'_, std_msgs::msg::UInt32>| {
13+
move |msg: rclrs::ReadOnlyLoanedMessage<'_, std_msgs::msg::UInt32>| {
1514
num_messages += 1;
1615
println!("I heard: '{}'", msg.data);
1716
println!("(Got {} messages so far)", num_messages);

rclrs/rust_pubsub/src/simple_publisher.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ struct SimplePublisher {
99
impl SimplePublisher {
1010
fn new(executor: &Executor) -> Result<Self, RclrsError> {
1111
let node = executor.create_node("simple_publisher").unwrap();
12-
let publisher = node
13-
.create_publisher("publish_hello", QOS_PROFILE_DEFAULT)
14-
.unwrap();
12+
let publisher = node.create_publisher("publish_hello").unwrap();
1513
Ok(Self { publisher })
1614
}
1715

rclrs/rust_pubsub/src/simple_subscriber.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ impl SimpleSubscriptionNode {
1717
let data: Arc<Mutex<Option<StringMsg>>> = Arc::new(Mutex::new(None));
1818
let data_mut: Arc<Mutex<Option<StringMsg>>> = Arc::clone(&data);
1919
let _subscriber = node
20-
.create_subscription::<StringMsg, _>(
21-
"publish_hello",
22-
QOS_PROFILE_DEFAULT,
23-
move |msg: StringMsg| {
24-
*data_mut.lock().unwrap() = Some(msg);
25-
},
26-
)
20+
.create_subscription::<StringMsg, _>("publish_hello", move |msg: StringMsg| {
21+
*data_mut.lock().unwrap() = Some(msg);
22+
})
2723
.unwrap();
2824
Ok(Self { _subscriber, data })
2925
}

0 commit comments

Comments
 (0)