Skip to content
Merged
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
67 changes: 34 additions & 33 deletions rosidl_generator_rs/resource/action.rs.em
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ for subfolder, action in action_specs:
}@

pub mod rmw {
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@{
TEMPLATE(
'msg_rmw.rs.em',
Expand All @@ -47,6 +49,9 @@ TEMPLATE(
}@
} // mod rmw

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

@{
TEMPLATE(
'msg_idiomatic.rs.em',
Expand Down Expand Up @@ -84,24 +89,23 @@ extern "C" {
pub struct @(type_name);

impl rosidl_runtime_rs::Action for @(type_name) {
// --- Associated types for client library users ---
type Goal = crate::@(subfolder)::@(type_name)@(ACTION_GOAL_SUFFIX);
type Result = crate::@(subfolder)::@(type_name)@(ACTION_RESULT_SUFFIX);
type Feedback = crate::@(subfolder)::@(type_name)@(ACTION_FEEDBACK_SUFFIX);

fn get_type_support() -> *const std::ffi::c_void {
// SAFETY: No preconditions for this function.
unsafe { rosidl_typesupport_c__get_action_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() }
}
}

impl rosidl_runtime_rs::ActionImpl for @(type_name) {
type GoalStatusMessage = action_msgs::msg::rmw::GoalStatusArray;
// --- Associated types for client library implementation ---
type FeedbackMessage = crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_MESSAGE_SUFFIX);

type SendGoalService = crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SERVICE_SUFFIX);
type CancelGoalService = action_msgs::srv::rmw::CancelGoal;
type GetResultService = crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SERVICE_SUFFIX);

// --- Methods for client library implementation ---
fn get_type_support() -> *const std::ffi::c_void {
// SAFETY: No preconditions for this function.
unsafe { rosidl_typesupport_c__get_action_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() }
}

fn create_goal_request(
goal_id: &[u8; 16],
goal: crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SUFFIX),
Expand All @@ -112,10 +116,13 @@ impl rosidl_runtime_rs::ActionImpl for @(type_name) {
}
}

fn get_goal_request_uuid(
request: &crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SERVICE_SUFFIX)@(SERVICE_REQUEST_MESSAGE_SUFFIX),
) -> &[u8; 16] {
&request.goal_id.uuid
fn split_goal_request(
request: crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SERVICE_SUFFIX)@(SERVICE_REQUEST_MESSAGE_SUFFIX),
) -> (
[u8; 16],
crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SUFFIX),
) {
(request.goal_id.uuid, request.goal)
}

fn create_goal_response(
Expand Down Expand Up @@ -153,16 +160,13 @@ impl rosidl_runtime_rs::ActionImpl for @(type_name) {
message
}

fn get_feedback_message_uuid(
feedback: &crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_MESSAGE_SUFFIX),
) -> &[u8; 16] {
&feedback.goal_id.uuid
}

fn get_feedback_message_feedback(
feedback: &crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_MESSAGE_SUFFIX),
) -> &crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_SUFFIX) {
&feedback.feedback
fn split_feedback_message(
feedback: crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_MESSAGE_SUFFIX),
) -> (
[u8; 16],
crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_SUFFIX),
) {
(feedback.goal_id.uuid, feedback.feedback)
}

fn create_result_request(
Expand All @@ -189,16 +193,13 @@ impl rosidl_runtime_rs::ActionImpl for @(type_name) {
}
}

fn get_result_response_result(
response: &crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SERVICE_SUFFIX)@(SERVICE_RESPONSE_MESSAGE_SUFFIX),
) -> &crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SUFFIX) {
&response.result
}

fn get_result_response_status(
response: &crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SERVICE_SUFFIX)@(SERVICE_RESPONSE_MESSAGE_SUFFIX),
) -> i8 {
response.status
fn split_result_response(
response: crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SERVICE_SUFFIX)@(SERVICE_RESPONSE_MESSAGE_SUFFIX)
) -> (
i8,
crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SUFFIX),
) {
(response.status, response.result)
}
}

Expand Down
5 changes: 5 additions & 0 deletions rosidl_generator_rs/resource/msg.rs.em
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod rmw {
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@{
TEMPLATE(
'msg_rmw.rs.em',
Expand All @@ -11,6 +13,9 @@ TEMPLATE(
}@
} // mod rmw

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

@{
TEMPLATE(
'msg_idiomatic.rs.em',
Expand Down
2 changes: 0 additions & 2 deletions rosidl_generator_rs/resource/msg_idiomatic.rs.em
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ from rosidl_parser.definition import UnboundedWString
@# ############ Idiomatic message types ############
@# #################################################
@# These types use standard Rust containers where possible.
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@[for subfolder, msg_spec in msg_specs]@
@{
type_name = msg_spec.structure.namespaced_type.name
Expand Down
2 changes: 0 additions & 2 deletions rosidl_generator_rs/resource/msg_rmw.rs.em
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ from rosidl_parser.definition import UnboundedSequence
from rosidl_parser.definition import UnboundedString
from rosidl_parser.definition import UnboundedWString
}@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@[for subfolder, msg_spec in msg_specs]@
@{
type_name = msg_spec.structure.namespaced_type.name
Expand Down