Skip to content

Improve Action trait #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rosidl_runtime_rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
71 changes: 41 additions & 30 deletions rosidl_runtime_rs/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +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;

/// The feedback message associated with this action.
type FeedbackMessage: Message;

Expand All @@ -197,11 +186,16 @@ 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<Self>) -> RmwGoalRequest<Self>;

/// Get the UUID of a goal request.
fn get_goal_request_uuid(request: &RmwGoalRequest<Self>) -> &[u8; 16];
/// 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<Self>) -> ([u8; 16], RmwGoalData<Self>);

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

/// Get the UUID of a feedback message.
fn get_feedback_message_uuid(feedback: &RmwFeedbackMessage<Self>) -> &[u8; 16];

/// Get the feedback of a feedback message.
fn get_feedback_message_feedback(feedback: &RmwFeedbackMessage<Self>)
-> &RmwFeedbackData<Self>;
/// 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<Self>) -> ([u8; 16], RmwFeedbackData<Self>);

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

/// Get the result of a result response.
fn get_result_response_result(response: &RmwResultResponse<Self>) -> &RmwResultData<Self>;

/// Get the status of a result response.
fn get_result_response_status(response: &RmwResultResponse<Self>) -> 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<Self>) -> (i8, RmwResultData<Self>);
}

// Type definitions to simplify the ActionImpl trait
// ---- Type definitions to simplify the Action trait -----

/// RMW-compatible request message for a service
pub type RmwServiceRequest<S> = <<S as Service>::Request as Message>::RmwMsg;

/// RMW-compatible response message for a service
pub type RmwServiceResponse<S> = <<S as Service>::Response as Message>::RmwMsg;
pub type RmwGoalRequest<A> = RmwServiceRequest<<A as ActionImpl>::SendGoalService>;
pub type RmwGoalResponse<A> = RmwServiceResponse<<A as ActionImpl>::SendGoalService>;

/// RMW-compatible request message for an action send goal service
pub type RmwGoalRequest<A> = RmwServiceRequest<<A as Action>::SendGoalService>;

/// RMW-compatible response message for an action send goal service
pub type RmwGoalResponse<A> = RmwServiceResponse<<A as Action>::SendGoalService>;

/// RMW-compatible message describing a goal for an action
pub type RmwGoalData<A> = <<A as Action>::Goal as Message>::RmwMsg;

/// RMW-compatible message describing feedback data for an action
pub type RmwFeedbackData<A> = <<A as Action>::Feedback as Message>::RmwMsg;
pub type RmwFeedbackMessage<A> = <<A as ActionImpl>::FeedbackMessage as Message>::RmwMsg;
pub type RmwResultRequest<A> = RmwServiceRequest<<A as ActionImpl>::GetResultService>;
pub type RmwResultResponse<A> = RmwServiceResponse<<A as ActionImpl>::GetResultService>;

/// RMW-compatible message that can be published to an action feedback topic
pub type RmwFeedbackMessage<A> = <<A as Action>::FeedbackMessage as Message>::RmwMsg;

/// RMW-compatible request message for obtaining the result of an action
pub type RmwResultRequest<A> = RmwServiceRequest<<A as Action>::GetResultService>;

/// RMW-compatible response message for obtaining the result of an action
pub type RmwResultResponse<A> = RmwServiceResponse<<A as Action>::GetResultService>;

/// RMW-compatible message describing the result data for an action
pub type RmwResultData<A> = <<A as Action>::Result as Message>::RmwMsg;