Skip to content

Commit 53ebbbe

Browse files
committed
Implement client-side trait methods for action messages
This adds methods to ActionImpl for creating and accessing action-specific message types. These are needed by the rclrs ActionClient to generically read and write RMW messages. Due to issues with qualified paths in certain places (rust-lang/rust#86935), the generator now refers directly to its service and message types rather than going through associated types of the various traits. This also makes the generated code a little easier to read, with the trait method signatures from rosidl_runtime_rs still enforcing type-safety.
1 parent 94b517c commit 53ebbbe

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

rclrs/src/action/server.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ where
197197
mut request_id: rmw_request_id_t,
198198
accepted: bool,
199199
) -> Result<(), RclrsError> {
200-
type RmwResponse<T> = <<<T as ActionImpl>::SendGoalService as Service>::Response as Message>::RmwMsg;
201-
let mut response_rmw = RmwResponse::<T>::default();
202-
<T as ActionImpl>::set_goal_response_accepted(&mut response_rmw, accepted);
200+
let mut response_rmw = <T as ActionImpl>::create_goal_response(accepted, (0, 0));
203201
let handle = &*self.handle.lock();
204202
let result = unsafe {
205203
// SAFETY: The action server handle is locked and so synchronized with other
@@ -210,7 +208,7 @@ where
210208
rcl_action_send_goal_response(
211209
handle,
212210
&mut request_id,
213-
&mut response_rmw as *mut RmwResponse<T> as *mut _,
211+
&mut response_rmw as *mut _ as *mut _,
214212
)
215213
}
216214
.ok();
@@ -242,7 +240,7 @@ where
242240
Err(err) => return Err(err),
243241
};
244242

245-
let uuid = GoalUuid(<T as ActionImpl>::get_goal_request_uuid(&request));
243+
let uuid = GoalUuid(*<T as ActionImpl>::get_goal_request_uuid(&request));
246244

247245
let response: GoalResponse = {
248246
todo!("Optionally convert request to an idiomatic type for the user's callback.");
@@ -522,7 +520,7 @@ where
522520
Err(err) => return Err(err),
523521
};
524522

525-
let uuid = GoalUuid(<T as ActionImpl>::get_result_request_uuid(&request));
523+
let uuid = GoalUuid(*<T as ActionImpl>::get_result_request_uuid(&request));
526524

527525
let goal_exists = unsafe {
528526
// SAFETY: No preconditions
@@ -640,7 +638,7 @@ where
640638

641639
pub(crate) fn publish_feedback(&self, goal_id: &GoalUuid, feedback: &<T as rosidl_runtime_rs::Action>::Feedback) -> Result<(), RclrsError> {
642640
let feedback_rmw = <<T as rosidl_runtime_rs::Action>::Feedback as Message>::into_rmw_message(std::borrow::Cow::Borrowed(feedback));
643-
let mut feedback_msg = <T as rosidl_runtime_rs::ActionImpl>::create_feedback_message(&goal_id.0, &*feedback_rmw);
641+
let mut feedback_msg = <T as rosidl_runtime_rs::ActionImpl>::create_feedback_message(&goal_id.0, feedback_rmw.into_owned());
644642
unsafe {
645643
// SAFETY: The action server is locked through the handle, meaning that no other
646644
// non-thread-safe functions can be called on it at the same time. The feedback_msg is

0 commit comments

Comments
 (0)