Skip to content

Commit 317f473

Browse files
authored
Improve Action trait (#15)
* Fixes for Action trait Signed-off-by: Michael X. Grey <greyxmike@gmail.com> * Introduce split_ API Signed-off-by: Michael X. Grey <greyxmike@gmail.com> --------- Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
1 parent 2637d8f commit 317f473

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

rosidl_runtime_rs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ mod string;
99
pub use string::{BoundedString, BoundedWString, String, StringExceedsBoundsError, WString};
1010

1111
mod traits;
12-
pub use traits::{Action, ActionImpl, Message, RmwMessage, SequenceAlloc, Service};
12+
pub use traits::*;

rosidl_runtime_rs/src/traits.rs

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,6 @@ pub trait Action: 'static {
174174
/// The feedback message associated with this action.
175175
type Feedback: Message;
176176

177-
/// Get a pointer to the correct `rosidl_action_type_support_t` structure.
178-
fn get_type_support() -> *const std::ffi::c_void;
179-
}
180-
181-
/// Trait for action implementation details.
182-
///
183-
/// User code never needs to implement this trait, nor use its associated types.
184-
pub trait ActionImpl: 'static + Action {
185-
/// The goal_status message associated with this action.
186-
type GoalStatusMessage: Message;
187-
188177
/// The feedback message associated with this action.
189178
type FeedbackMessage: Message;
190179

@@ -197,11 +186,16 @@ pub trait ActionImpl: 'static + Action {
197186
/// The get_result service associated with this action.
198187
type GetResultService: Service;
199188

189+
/// Get a pointer to the correct `rosidl_action_type_support_t` structure.
190+
fn get_type_support() -> *const std::ffi::c_void;
191+
200192
/// Create a goal request message with the given UUID and goal.
201193
fn create_goal_request(goal_id: &[u8; 16], goal: RmwGoalData<Self>) -> RmwGoalRequest<Self>;
202194

203-
/// Get the UUID of a goal request.
204-
fn get_goal_request_uuid(request: &RmwGoalRequest<Self>) -> &[u8; 16];
195+
/// Split a goal request message into its two parts:
196+
/// * The UUID of the goal
197+
/// * The message that describes the goal
198+
fn split_goal_request(request: RmwGoalRequest<Self>) -> ([u8; 16], RmwGoalData<Self>);
205199

206200
/// Create a goal response message with the given acceptance and timestamp.
207201
fn create_goal_response(accepted: bool, stamp: (i32, u32)) -> RmwGoalResponse<Self>;
@@ -218,12 +212,10 @@ pub trait ActionImpl: 'static + Action {
218212
feedback: RmwFeedbackData<Self>,
219213
) -> RmwFeedbackMessage<Self>;
220214

221-
/// Get the UUID of a feedback message.
222-
fn get_feedback_message_uuid(feedback: &RmwFeedbackMessage<Self>) -> &[u8; 16];
223-
224-
/// Get the feedback of a feedback message.
225-
fn get_feedback_message_feedback(feedback: &RmwFeedbackMessage<Self>)
226-
-> &RmwFeedbackData<Self>;
215+
/// Split a feedback message into its two parts:
216+
/// * The UUID of the goal that the feedback is for
217+
/// * The message the describes the feedback data
218+
fn split_feedback_message(feedback: RmwFeedbackMessage<Self>) -> ([u8; 16], RmwFeedbackData<Self>);
227219

228220
/// Create a result request message with the given goal ID.
229221
fn create_result_request(goal_id: &[u8; 16]) -> RmwResultRequest<Self>;
@@ -234,21 +226,40 @@ pub trait ActionImpl: 'static + Action {
234226
/// Create a result response message with the given status and contents.
235227
fn create_result_response(status: i8, result: RmwResultData<Self>) -> RmwResultResponse<Self>;
236228

237-
/// Get the result of a result response.
238-
fn get_result_response_result(response: &RmwResultResponse<Self>) -> &RmwResultData<Self>;
239-
240-
/// Get the status of a result response.
241-
fn get_result_response_status(response: &RmwResultResponse<Self>) -> i8;
229+
/// Split a result response into its two parts:
230+
/// * The status of the result (e.g. Succeeded, Aborted, Cancelled)
231+
/// * The message that describes the final result of the action
232+
fn split_result_response(response: RmwResultResponse<Self>) -> (i8, RmwResultData<Self>);
242233
}
243234

244-
// Type definitions to simplify the ActionImpl trait
235+
// ---- Type definitions to simplify the Action trait -----
236+
237+
/// RMW-compatible request message for a service
245238
pub type RmwServiceRequest<S> = <<S as Service>::Request as Message>::RmwMsg;
239+
240+
/// RMW-compatible response message for a service
246241
pub type RmwServiceResponse<S> = <<S as Service>::Response as Message>::RmwMsg;
247-
pub type RmwGoalRequest<A> = RmwServiceRequest<<A as ActionImpl>::SendGoalService>;
248-
pub type RmwGoalResponse<A> = RmwServiceResponse<<A as ActionImpl>::SendGoalService>;
242+
243+
/// RMW-compatible request message for an action send goal service
244+
pub type RmwGoalRequest<A> = RmwServiceRequest<<A as Action>::SendGoalService>;
245+
246+
/// RMW-compatible response message for an action send goal service
247+
pub type RmwGoalResponse<A> = RmwServiceResponse<<A as Action>::SendGoalService>;
248+
249+
/// RMW-compatible message describing a goal for an action
249250
pub type RmwGoalData<A> = <<A as Action>::Goal as Message>::RmwMsg;
251+
252+
/// RMW-compatible message describing feedback data for an action
250253
pub type RmwFeedbackData<A> = <<A as Action>::Feedback as Message>::RmwMsg;
251-
pub type RmwFeedbackMessage<A> = <<A as ActionImpl>::FeedbackMessage as Message>::RmwMsg;
252-
pub type RmwResultRequest<A> = RmwServiceRequest<<A as ActionImpl>::GetResultService>;
253-
pub type RmwResultResponse<A> = RmwServiceResponse<<A as ActionImpl>::GetResultService>;
254+
255+
/// RMW-compatible message that can be published to an action feedback topic
256+
pub type RmwFeedbackMessage<A> = <<A as Action>::FeedbackMessage as Message>::RmwMsg;
257+
258+
/// RMW-compatible request message for obtaining the result of an action
259+
pub type RmwResultRequest<A> = RmwServiceRequest<<A as Action>::GetResultService>;
260+
261+
/// RMW-compatible response message for obtaining the result of an action
262+
pub type RmwResultResponse<A> = RmwServiceResponse<<A as Action>::GetResultService>;
263+
264+
/// RMW-compatible message describing the result data for an action
254265
pub type RmwResultData<A> = <<A as Action>::Result as Message>::RmwMsg;

0 commit comments

Comments
 (0)