Skip to content

Commit 598e066

Browse files
committed
Add rosidl_runtime_rs::ActionImpl::create_feedback_message()
Adds a trait method to create a feedback message given the goal ID and the user-facing feedback message type. Depending on how many times we do this, it may end up valuable to define a GoalUuid type in rosidl_runtime_rs itself. We wouldn't be able to utilize the `RCL_ACTION_UUID_SIZE` constant imported from `rcl_action`, but this is pretty much guaranteed to be 16 forever. Defining this method signature also required inverting the super-trait relationship between Action and ActionImpl. Now ActionImpl is the sub-trait as this gives it access to all of Action's associated types. Action doesn't need to care about anything from ActionImpl (hopefully).
1 parent f6c2ef2 commit 598e066

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

rclrs/src/action/server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ where
8383

8484
impl<T> ActionServer<T>
8585
where
86-
T: rosidl_runtime_rs::Action,
86+
T: rosidl_runtime_rs::Action + rosidl_runtime_rs::ActionImpl,
8787
{
8888
/// Creates a new action server.
8989
pub(crate) fn new(
@@ -95,7 +95,7 @@ where
9595
accepted_callback: impl Fn(ServerGoalHandle<T>) + 'static + Send + Sync,
9696
) -> Result<Self, RclrsError>
9797
where
98-
T: rosidl_runtime_rs::Action,
98+
T: rosidl_runtime_rs::Action + rosidl_runtime_rs::ActionImpl,
9999
{
100100
// SAFETY: Getting a zero-initialized value is always safe.
101101
let mut rcl_action_server = unsafe { rcl_action_get_zero_initialized_server() };
@@ -335,7 +335,7 @@ where
335335

336336
impl<T> ActionServerBase for ActionServer<T>
337337
where
338-
T: rosidl_runtime_rs::Action,
338+
T: rosidl_runtime_rs::Action + rosidl_runtime_rs::ActionImpl,
339339
{
340340
fn handle(&self) -> &ActionServerHandle {
341341
&self.handle

rclrs/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl Node {
244244
handle_accepted: AcceptedCallback,
245245
) -> Result<Arc<ActionServer<ActionT>>, RclrsError>
246246
where
247-
ActionT: rosidl_runtime_rs::Action,
247+
ActionT: rosidl_runtime_rs::Action + rosidl_runtime_rs::ActionImpl,
248248
GoalCallback: Fn(GoalUuid, <ActionT as rosidl_runtime_rs::Action>::Goal) -> GoalResponse + 'static + Send + Sync,
249249
CancelCallback: Fn(ServerGoalHandle<ActionT>) -> CancelResponse + 'static + Send + Sync,
250250
AcceptedCallback: Fn(ServerGoalHandle<ActionT>) + 'static + Send + Sync,

rosidl_runtime_rs/src/traits.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub trait Service: 'static {
163163
/// Trait for actions.
164164
///
165165
/// User code never needs to call this trait's method, much less implement this trait.
166-
pub trait Action: 'static + ActionImpl {
166+
pub trait Action: 'static {
167167
/// The goal message associated with this action.
168168
type Goal: Message;
169169

@@ -180,7 +180,7 @@ pub trait Action: 'static + ActionImpl {
180180
/// Trait for action implementation details.
181181
///
182182
/// User code never needs to implement this trait, nor use its associated types.
183-
pub trait ActionImpl: 'static {
183+
pub trait ActionImpl: 'static + Action {
184184
/// The goal_status message associated with this action.
185185
type GoalStatusMessage: Message;
186186

@@ -201,4 +201,7 @@ pub trait ActionImpl: 'static {
201201

202202
/// Sets the `accepted` field of a goal response.
203203
fn set_goal_response_accepted(response: &mut <<Self::SendGoalService as Service>::Response as Message>::RmwMsg, accepted: bool);
204+
205+
/// Create a feedback message with the given goal ID and contents.
206+
fn create_feedback_message(goal_id: &[u8; 16], feedback: &<<Self as Action>::Feedback as Message>::RmwMsg) -> <Self::FeedbackMessage as Message>::RmwMsg;
204207
}

0 commit comments

Comments
 (0)