Skip to content

Commit 8112a77

Browse files
Add publisher API
Signed-off-by: Luca Della Vedova <[email protected]>
1 parent a6b5b48 commit 8112a77

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

rclrs/src/dynamic_message/dynamic_publisher.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use super::{
66
DynamicMessageMetadata, MessageTypeName,
77
};
88
use crate::error::{RclrsError, ToResult};
9-
use crate::qos::QoSProfile;
109
use crate::rcl_bindings::*;
11-
use crate::{ENTITY_LIFECYCLE_MUTEX, PublisherHandle, NodeHandle};
10+
use crate::{NodeHandle, PublisherHandle, PublisherOptions, ENTITY_LIFECYCLE_MUTEX};
1211

1312
/// Struct for sending messages of type `T`.
1413
///
@@ -28,25 +27,18 @@ pub struct DynamicPublisher {
2827
type_support_library: Arc<libloading::Library>,
2928
}
3029

31-
// SAFETY: The functions accessing this type, including drop(), shouldn't care about the thread
32-
// they are running in. Therefore, this type can be safely sent to another thread.
33-
// unsafe impl Send for DynamicPublisher {}
34-
// SAFETY: The type_support_ptr prevents the default Sync impl.
35-
// rosidl_message_type_support_t is a read-only type without interior mutability.
36-
// unsafe impl Sync for DynamicPublisher {}
37-
3830
impl DynamicPublisher {
3931
/// Creates a new `DynamicPublisher`.
4032
///
4133
/// Node and namespace changes are always applied _before_ topic remapping.
42-
pub(crate) fn new(
43-
node_handle: Arc<NodeHandle>,
44-
topic: &str,
34+
pub(crate) fn new<'a>(
4535
topic_type: MessageTypeName,
46-
qos: QoSProfile,
36+
options: impl Into<PublisherOptions<'a>>,
37+
node_handle: Arc<NodeHandle>,
4738
) -> Result<Self, RclrsError> {
4839
// This loads the introspection type support library.
4940
let metadata = DynamicMessageMetadata::new(topic_type)?;
41+
let PublisherOptions { topic, qos } = options.into();
5042
// However, we also need the regular type support library –
5143
// the rosidl_typesupport_c one.
5244
let message_type = &metadata.message_type;

rclrs/src/dynamic_message/dynamic_subscription.rs

Lines changed: 3 additions & 3 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, RclPrimitive, RclPrimitiveHandle, RclPrimitiveKind,
16-
RclrsError, SubscriptionHandle, ToResult, Waitable, WaitableLifecycle, WorkScope,
17-
WorkerCommands, ENTITY_LIFECYCLE_MUTEX, SubscriptionOptions,
15+
MessageInfo, NodeHandle, RclPrimitive, RclPrimitiveHandle, RclPrimitiveKind, RclrsError,
16+
SubscriptionHandle, SubscriptionOptions, ToResult, Waitable, WaitableLifecycle, WorkScope,
17+
WorkerCommands, ENTITY_LIFECYCLE_MUTEX,
1818
};
1919

2020
struct DynamicSubscriptionExecutable<Payload> {

rclrs/src/node.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use primitive_options::*;
66

77
mod graph;
88
#[cfg(feature = "dyn_msg")]
9-
use crate::dynamic_message::{DynamicMessage, DynamicSubscription};
9+
use crate::dynamic_message::{DynamicMessage, DynamicPublisher, DynamicSubscription};
1010

1111
pub use graph::*;
1212

@@ -401,6 +401,15 @@ impl NodeState {
401401
PublisherState::<T>::create(options, Arc::clone(&self.handle))
402402
}
403403

404+
#[cfg(feature = "dyn_msg")]
405+
pub fn create_dynamic_publisher<'a>(
406+
&self,
407+
topic_type: MessageTypeName,
408+
options: impl Into<PublisherOptions<'a>>,
409+
) -> Result<DynamicPublisher, RclrsError> {
410+
DynamicPublisher::new(topic_type, options, Arc::clone(&self.handle))
411+
}
412+
404413
/// Creates a [`Service`] with an ordinary callback.
405414
///
406415
/// # Behavior

0 commit comments

Comments
 (0)