Skip to content

Commit 339ea3f

Browse files
committed
Add ActionImpl trait with internal messages and services
This is incomplete, since the service types aren't yet being generated.
1 parent 0325921 commit 339ea3f

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

rosidl_generator_rs/resource/action.rs.em

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
@{
2+
from rosidl_parser.definition import (
3+
ACTION_FEEDBACK_MESSAGE_SUFFIX,
4+
ACTION_FEEDBACK_SUFFIX,
5+
ACTION_GOAL_SERVICE_SUFFIX,
6+
ACTION_GOAL_SUFFIX,
7+
ACTION_RESULT_SERVICE_SUFFIX,
8+
ACTION_RESULT_SUFFIX,
9+
)
10+
211
action_msg_specs = []
312

413
for subfolder, action in action_specs:
@@ -53,14 +62,23 @@ extern "C" {
5362
pub struct @(type_name);
5463

5564
impl rosidl_runtime_rs::Action for @(type_name) {
56-
type Goal = crate::@(subfolder)::rmw::@(type_name)_Goal;
57-
type Result = crate::@(subfolder)::rmw::@(type_name)_Result;
58-
type Feedback = crate::@(subfolder)::rmw::@(type_name)_Feedback;
65+
type Goal = crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SUFFIX);
66+
type Result = crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SUFFIX);
67+
type Feedback = crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_SUFFIX);
5968

6069
fn get_type_support() -> *const std::os::raw::c_void {
6170
// SAFETY: No preconditions for this function.
6271
unsafe { rosidl_typesupport_c__get_action_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() }
6372
}
6473
}
6574

75+
impl rosidl_runtime_rs::ActionImpl for @(type_name) {
76+
type GoalStatusMessage = action_msgs::msg::rmw::GoalStatusArray;
77+
type FeedbackMessage = crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_MESSAGE_SUFFIX);
78+
79+
type SendGoalService = crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SERVICE_SUFFIX);
80+
type CancelGoalService = action_msgs::srv::rmw::CancelGoal;
81+
type GetResultService = crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SERVICE_SUFFIX);
82+
}
83+
6684
@[end for]

rosidl_runtime_rs/src/traits.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,36 @@ 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 {
167-
/// The goal message associated with this service.
166+
pub trait Action: 'static + ActionImpl {
167+
/// The goal message associated with this action.
168168
type Goal: Message;
169169

170-
/// The result message associated with this service.
170+
/// The result message associated with this action.
171171
type Result: Message;
172172

173-
/// The feedback message associated with this service.
173+
/// The feedback message associated with this action.
174174
type Feedback: Message;
175175

176176
/// Get a pointer to the correct `rosidl_action_type_support_t` structure.
177177
fn get_type_support() -> *const std::os::raw::c_void;
178178
}
179+
180+
/// Trait for action implementation details.
181+
///
182+
/// User code never needs to implement this trait, nor use its associated types.
183+
pub trait ActionImpl: 'static {
184+
/// The goal_status message associated with this action.
185+
type GoalStatusMessage: Message;
186+
187+
/// The feedback message associated with this action.
188+
type FeedbackMessage: Message;
189+
190+
/// The send_goal service associated with this action.
191+
type SendGoalService: Service;
192+
193+
/// The cancel_goal service associated with this action.
194+
type CancelGoalService: Service;
195+
196+
/// The get_result service associated with this action.
197+
type GetResultService: Service;
198+
}

0 commit comments

Comments
 (0)