From eacc6528381f36242a57a3844219a9f09c2fb696 Mon Sep 17 00:00:00 2001 From: "Michael X. Grey" Date: Mon, 28 Jul 2025 15:11:19 +0800 Subject: [PATCH 1/2] Fixes for Action trait Signed-off-by: Michael X. Grey --- rosidl_runtime_rs/src/lib.rs | 2 +- rosidl_runtime_rs/src/traits.rs | 54 ++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/rosidl_runtime_rs/src/lib.rs b/rosidl_runtime_rs/src/lib.rs index 7c5bad4..0d21f12 100644 --- a/rosidl_runtime_rs/src/lib.rs +++ b/rosidl_runtime_rs/src/lib.rs @@ -9,4 +9,4 @@ mod string; pub use string::{BoundedString, BoundedWString, String, StringExceedsBoundsError, WString}; mod traits; -pub use traits::{Action, ActionImpl, Message, RmwMessage, SequenceAlloc, Service}; +pub use traits::*; diff --git a/rosidl_runtime_rs/src/traits.rs b/rosidl_runtime_rs/src/traits.rs index 61d8c23..51e115a 100644 --- a/rosidl_runtime_rs/src/traits.rs +++ b/rosidl_runtime_rs/src/traits.rs @@ -174,14 +174,6 @@ pub trait Action: 'static { /// The feedback message associated with this action. type Feedback: Message; - /// Get a pointer to the correct `rosidl_action_type_support_t` structure. - fn get_type_support() -> *const std::ffi::c_void; -} - -/// Trait for action implementation details. -/// -/// User code never needs to implement this trait, nor use its associated types. -pub trait ActionImpl: 'static + Action { /// The goal_status message associated with this action. type GoalStatusMessage: Message; @@ -197,12 +189,18 @@ pub trait ActionImpl: 'static + Action { /// The get_result service associated with this action. type GetResultService: Service; + /// Get a pointer to the correct `rosidl_action_type_support_t` structure. + fn get_type_support() -> *const std::ffi::c_void; + /// Create a goal request message with the given UUID and goal. fn create_goal_request(goal_id: &[u8; 16], goal: RmwGoalData) -> RmwGoalRequest; - /// Get the UUID of a goal request. + /// Get the UUID of a send goal request. fn get_goal_request_uuid(request: &RmwGoalRequest) -> &[u8; 16]; + /// Get the goal data of a send goal request. + fn get_goal_request_data(request: &RmwGoalRequest) -> &RmwGoalData; + /// Create a goal response message with the given acceptance and timestamp. fn create_goal_response(accepted: bool, stamp: (i32, u32)) -> RmwGoalResponse; @@ -221,8 +219,8 @@ pub trait ActionImpl: 'static + Action { /// Get the UUID of a feedback message. fn get_feedback_message_uuid(feedback: &RmwFeedbackMessage) -> &[u8; 16]; - /// Get the feedback of a feedback message. - fn get_feedback_message_feedback(feedback: &RmwFeedbackMessage) + /// Get the feedback data of a feedback message. + fn get_feedback_message_data(feedback: &RmwFeedbackMessage) -> &RmwFeedbackData; /// Create a result request message with the given goal ID. @@ -235,20 +233,40 @@ pub trait ActionImpl: 'static + Action { fn create_result_response(status: i8, result: RmwResultData) -> RmwResultResponse; /// Get the result of a result response. - fn get_result_response_result(response: &RmwResultResponse) -> &RmwResultData; + fn get_result_response_data(response: &RmwResultResponse) -> &RmwResultData; /// Get the status of a result response. fn get_result_response_status(response: &RmwResultResponse) -> i8; } -// Type definitions to simplify the ActionImpl trait +// ---- Type definitions to simplify the Action trait ----- + +/// RMW-compatible request message for a service pub type RmwServiceRequest = <::Request as Message>::RmwMsg; + +/// RMW-compatible response message for a service pub type RmwServiceResponse = <::Response as Message>::RmwMsg; -pub type RmwGoalRequest = RmwServiceRequest<::SendGoalService>; -pub type RmwGoalResponse = RmwServiceResponse<::SendGoalService>; + +/// RMW-compatible request message for an action send goal service +pub type RmwGoalRequest = RmwServiceRequest<::SendGoalService>; + +/// RMW-compatible response message for an action send goal service +pub type RmwGoalResponse = RmwServiceResponse<::SendGoalService>; + +/// RMW-compatible message describing a goal for an action pub type RmwGoalData = <::Goal as Message>::RmwMsg; + +/// RMW-compatible message describing feedback data for an action pub type RmwFeedbackData = <::Feedback as Message>::RmwMsg; -pub type RmwFeedbackMessage = <::FeedbackMessage as Message>::RmwMsg; -pub type RmwResultRequest = RmwServiceRequest<::GetResultService>; -pub type RmwResultResponse = RmwServiceResponse<::GetResultService>; + +/// RMW-compatible message that can be published to an action feedback topic +pub type RmwFeedbackMessage = <::FeedbackMessage as Message>::RmwMsg; + +/// RMW-compatible request message for obtaining the result of an action +pub type RmwResultRequest = RmwServiceRequest<::GetResultService>; + +/// RMW-compatible response message for obtaining the result of an action +pub type RmwResultResponse = RmwServiceResponse<::GetResultService>; + +/// RMW-compatible message describing the result data for an action pub type RmwResultData = <::Result as Message>::RmwMsg; From e2e043fb931e0196d3749ddb11f5dd848ba18aaa Mon Sep 17 00:00:00 2001 From: "Michael X. Grey" Date: Mon, 28 Jul 2025 17:15:23 +0800 Subject: [PATCH 2/2] Introduce split_ API Signed-off-by: Michael X. Grey --- rosidl_runtime_rs/src/traits.rs | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/rosidl_runtime_rs/src/traits.rs b/rosidl_runtime_rs/src/traits.rs index 51e115a..a934385 100644 --- a/rosidl_runtime_rs/src/traits.rs +++ b/rosidl_runtime_rs/src/traits.rs @@ -174,9 +174,6 @@ pub trait Action: 'static { /// The feedback message associated with this action. type Feedback: Message; - /// The goal_status message associated with this action. - type GoalStatusMessage: Message; - /// The feedback message associated with this action. type FeedbackMessage: Message; @@ -195,11 +192,10 @@ pub trait Action: 'static { /// Create a goal request message with the given UUID and goal. fn create_goal_request(goal_id: &[u8; 16], goal: RmwGoalData) -> RmwGoalRequest; - /// Get the UUID of a send goal request. - fn get_goal_request_uuid(request: &RmwGoalRequest) -> &[u8; 16]; - - /// Get the goal data of a send goal request. - fn get_goal_request_data(request: &RmwGoalRequest) -> &RmwGoalData; + /// Split a goal request message into its two parts: + /// * The UUID of the goal + /// * The message that describes the goal + fn split_goal_request(request: RmwGoalRequest) -> ([u8; 16], RmwGoalData); /// Create a goal response message with the given acceptance and timestamp. fn create_goal_response(accepted: bool, stamp: (i32, u32)) -> RmwGoalResponse; @@ -216,12 +212,10 @@ pub trait Action: 'static { feedback: RmwFeedbackData, ) -> RmwFeedbackMessage; - /// Get the UUID of a feedback message. - fn get_feedback_message_uuid(feedback: &RmwFeedbackMessage) -> &[u8; 16]; - - /// Get the feedback data of a feedback message. - fn get_feedback_message_data(feedback: &RmwFeedbackMessage) - -> &RmwFeedbackData; + /// Split a feedback message into its two parts: + /// * The UUID of the goal that the feedback is for + /// * The message the describes the feedback data + fn split_feedback_message(feedback: RmwFeedbackMessage) -> ([u8; 16], RmwFeedbackData); /// Create a result request message with the given goal ID. fn create_result_request(goal_id: &[u8; 16]) -> RmwResultRequest; @@ -232,11 +226,10 @@ pub trait Action: 'static { /// Create a result response message with the given status and contents. fn create_result_response(status: i8, result: RmwResultData) -> RmwResultResponse; - /// Get the result of a result response. - fn get_result_response_data(response: &RmwResultResponse) -> &RmwResultData; - - /// Get the status of a result response. - fn get_result_response_status(response: &RmwResultResponse) -> i8; + /// Split a result response into its two parts: + /// * The status of the result (e.g. Succeeded, Aborted, Cancelled) + /// * The message that describes the final result of the action + fn split_result_response(response: RmwResultResponse) -> (i8, RmwResultData); } // ---- Type definitions to simplify the Action trait -----