-
Notifications
You must be signed in to change notification settings - Fork 159
Action message support #417
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
Changes from 20 commits
110d965
047c8f1
556a606
dfdcbd3
67c3b8b
b197155
13474d1
3e70087
17cd980
fb9b0e4
5f3373f
562132b
dc90b21
1ed2981
568bb7c
23e9c94
6d7021a
7a39794
c5bd258
2748b5f
507a7af
7d30fb1
3c1663f
0493705
8bedfe0
5dece63
db575ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
@{ | ||
from rosidl_parser.definition import ( | ||
ACTION_FEEDBACK_MESSAGE_SUFFIX, | ||
ACTION_FEEDBACK_SUFFIX, | ||
ACTION_GOAL_SERVICE_SUFFIX, | ||
ACTION_GOAL_SUFFIX, | ||
ACTION_RESULT_SERVICE_SUFFIX, | ||
ACTION_RESULT_SUFFIX, | ||
SERVICE_REQUEST_MESSAGE_SUFFIX, | ||
SERVICE_RESPONSE_MESSAGE_SUFFIX, | ||
) | ||
|
||
action_msg_specs = [] | ||
|
||
for subfolder, action in action_specs: | ||
action_msg_specs.append((subfolder, action.goal)) | ||
action_msg_specs.append((subfolder, action.result)) | ||
action_msg_specs.append((subfolder, action.feedback)) | ||
action_msg_specs.append((subfolder, action.feedback_message)) | ||
|
||
action_srv_specs = [] | ||
|
||
for subfolder, action in action_specs: | ||
action_srv_specs.append((subfolder, action.send_goal_service)) | ||
action_srv_specs.append((subfolder, action.get_result_service)) | ||
}@ | ||
|
||
pub mod rmw { | ||
@{ | ||
TEMPLATE( | ||
'msg_rmw.rs.em', | ||
package_name=package_name, interface_path=interface_path, | ||
msg_specs=action_msg_specs, | ||
get_rs_name=get_rs_name, get_rmw_rs_type=get_rmw_rs_type, | ||
pre_field_serde=pre_field_serde, | ||
get_idiomatic_rs_type=get_idiomatic_rs_type, | ||
constant_value_to_rs=constant_value_to_rs) | ||
|
||
TEMPLATE( | ||
'srv_rmw.rs.em', | ||
package_name=package_name, interface_path=interface_path, | ||
srv_specs=action_srv_specs, | ||
get_rs_name=get_rs_name, get_rmw_rs_type=get_rmw_rs_type, | ||
pre_field_serde=pre_field_serde, | ||
get_idiomatic_rs_type=get_idiomatic_rs_type, | ||
constant_value_to_rs=constant_value_to_rs) | ||
}@ | ||
} // mod rmw | ||
|
||
@{ | ||
TEMPLATE( | ||
'msg_idiomatic.rs.em', | ||
package_name=package_name, interface_path=interface_path, | ||
msg_specs=action_msg_specs, | ||
get_rs_name=get_rs_name, get_rmw_rs_type=get_rmw_rs_type, | ||
pre_field_serde=pre_field_serde, | ||
get_idiomatic_rs_type=get_idiomatic_rs_type, | ||
constant_value_to_rs=constant_value_to_rs) | ||
}@ | ||
|
||
@{ | ||
TEMPLATE( | ||
'srv_idiomatic.rs.em', | ||
package_name=package_name, interface_path=interface_path, | ||
srv_specs=action_srv_specs, | ||
get_rs_name=get_rs_name, get_rmw_rs_type=get_rmw_rs_type, | ||
pre_field_serde=pre_field_serde, | ||
get_idiomatic_rs_type=get_idiomatic_rs_type, | ||
constant_value_to_rs=constant_value_to_rs) | ||
}@ | ||
|
||
@[for subfolder, action_spec in action_specs] | ||
|
||
@{ | ||
type_name = action_spec.namespaced_type.name | ||
}@ | ||
|
||
#[link(name = "@(package_name)__rosidl_typesupport_c")] | ||
extern "C" { | ||
fn rosidl_typesupport_c__get_action_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::os::raw::c_void; | ||
} | ||
|
||
// Corresponds to @(package_name)__@(subfolder)__@(type_name) | ||
pub struct @(type_name); | ||
|
||
impl rosidl_runtime_rs::Action for @(type_name) { | ||
type Goal = crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SUFFIX); | ||
type Result = crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SUFFIX); | ||
type Feedback = crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_SUFFIX); | ||
|
||
fn get_type_support() -> *const std::os::raw::c_void { | ||
// SAFETY: No preconditions for this function. | ||
unsafe { rosidl_typesupport_c__get_action_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little confusing to me. Looking at (what I believe to be) the impl for this typesupport function (link)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
static rosidl_service_type_support_t @(function_prefix)__@(spec.srv_name)_service_type_support_handle = {
0,
&@(function_prefix)__@(spec.srv_name)_service_members,
get_service_typesupport_handle_function,
}; This is outside the scope of this PR though. Just calling attention to it because we've been bitten by global variables we directly interact with via FFI before, see #386 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
impl rosidl_runtime_rs::ActionImpl for @(type_name) { | ||
type GoalStatusMessage = action_msgs::msg::rmw::GoalStatusArray; | ||
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); | ||
|
||
fn create_goal_request(goal_id: &[u8; 16], goal: crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SUFFIX)) -> crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SERVICE_SUFFIX)@(SERVICE_REQUEST_MESSAGE_SUFFIX) { | ||
crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SERVICE_SUFFIX)@(SERVICE_REQUEST_MESSAGE_SUFFIX) { | ||
goal_id: unique_identifier_msgs::msg::rmw::UUID { uuid: *goal_id }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we didn't want to have a dependency on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to avoid creating a dependency on However, the crates generated by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, I see. So the function signature of Yeah, we should explore some of the ideas discussed earlier to simplify this. Not needed for this PR though. |
||
goal, | ||
} | ||
} | ||
|
||
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 create_goal_response(accepted: bool, stamp: (i32, u32)) -> crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SERVICE_SUFFIX)@(SERVICE_RESPONSE_MESSAGE_SUFFIX) { | ||
crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SERVICE_SUFFIX)@(SERVICE_RESPONSE_MESSAGE_SUFFIX) { | ||
accepted, | ||
stamp: builtin_interfaces::msg::rmw::Time { | ||
sec: stamp.0, | ||
nanosec: stamp.1, | ||
}, | ||
} | ||
} | ||
|
||
fn get_goal_response_accepted(response: &crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SERVICE_SUFFIX)@(SERVICE_RESPONSE_MESSAGE_SUFFIX)) -> bool { | ||
response.accepted | ||
} | ||
|
||
fn get_goal_response_stamp(response: &crate::@(subfolder)::rmw::@(type_name)@(ACTION_GOAL_SERVICE_SUFFIX)@(SERVICE_RESPONSE_MESSAGE_SUFFIX)) -> (i32, u32) { | ||
(response.stamp.sec, response.stamp.nanosec) | ||
} | ||
|
||
fn create_feedback_message(goal_id: &[u8; 16], feedback: crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_SUFFIX)) -> crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_MESSAGE_SUFFIX) { | ||
let mut message = crate::@(subfolder)::rmw::@(type_name)@(ACTION_FEEDBACK_MESSAGE_SUFFIX)::default(); | ||
message.goal_id.uuid = *goal_id; | ||
message.feedback = feedback; | ||
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 create_result_request(goal_id: &[u8; 16]) -> crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SERVICE_SUFFIX)@(SERVICE_REQUEST_MESSAGE_SUFFIX) { | ||
crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SERVICE_SUFFIX)@(SERVICE_REQUEST_MESSAGE_SUFFIX) { | ||
goal_id: unique_identifier_msgs::msg::rmw::UUID { uuid: *goal_id }, | ||
} | ||
} | ||
|
||
fn get_result_request_uuid(request: &crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SERVICE_SUFFIX)@(SERVICE_REQUEST_MESSAGE_SUFFIX)) -> &[u8; 16] { | ||
&request.goal_id.uuid | ||
} | ||
|
||
fn create_result_response(status: i8, result: crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SUFFIX)) -> crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SERVICE_SUFFIX)@(SERVICE_RESPONSE_MESSAGE_SUFFIX) { | ||
crate::@(subfolder)::rmw::@(type_name)@(ACTION_RESULT_SERVICE_SUFFIX)@(SERVICE_RESPONSE_MESSAGE_SUFFIX) { | ||
status, | ||
result, | ||
} | ||
} | ||
|
||
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 | ||
} | ||
} | ||
|
||
@[end for] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,23 @@ | ||
@{ | ||
req_res_specs = [] | ||
|
||
for subfolder, service in srv_specs: | ||
req_res_specs.append((subfolder, service.request_message)) | ||
req_res_specs.append((subfolder, service.response_message)) | ||
}@ | ||
|
||
@{ | ||
TEMPLATE( | ||
'msg_idiomatic.rs.em', | ||
'srv_idiomatic.rs.em', | ||
package_name=package_name, interface_path=interface_path, | ||
msg_specs=req_res_specs, | ||
srv_specs=srv_specs, | ||
get_rs_name=get_rs_name, get_rmw_rs_type=get_rmw_rs_type, | ||
pre_field_serde=pre_field_serde, | ||
get_idiomatic_rs_type=get_idiomatic_rs_type, | ||
constant_value_to_rs=constant_value_to_rs) | ||
}@ | ||
|
||
@[for subfolder, srv_spec in srv_specs] | ||
|
||
@{ | ||
type_name = srv_spec.namespaced_type.name | ||
}@ | ||
|
||
#[link(name = "@(package_name)__rosidl_typesupport_c")] | ||
extern "C" { | ||
fn rosidl_typesupport_c__get_service_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::os::raw::c_void; | ||
} | ||
|
||
// Corresponds to @(package_name)__@(subfolder)__@(type_name) | ||
pub struct @(type_name); | ||
|
||
impl rosidl_runtime_rs::Service for @(type_name) { | ||
type Request = crate::@(subfolder)::@(type_name)_Request; | ||
type Response = crate::@(subfolder)::@(type_name)_Response; | ||
|
||
fn get_type_support() -> *const std::os::raw::c_void { | ||
// SAFETY: No preconditions for this function. | ||
unsafe { rosidl_typesupport_c__get_service_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() } | ||
} | ||
} | ||
|
||
@[end for] | ||
|
||
pub mod rmw { | ||
@{ | ||
TEMPLATE( | ||
'msg_rmw.rs.em', | ||
'srv_rmw.rs.em', | ||
package_name=package_name, interface_path=interface_path, | ||
msg_specs=req_res_specs, | ||
srv_specs=srv_specs, | ||
get_rs_name=get_rs_name, get_rmw_rs_type=get_rmw_rs_type, | ||
pre_field_serde=pre_field_serde, | ||
get_idiomatic_rs_type=get_idiomatic_rs_type, | ||
constant_value_to_rs=constant_value_to_rs) | ||
}@ | ||
|
||
@[for subfolder, srv_spec in srv_specs] | ||
|
||
@{ | ||
type_name = srv_spec.namespaced_type.name | ||
}@ | ||
|
||
#[link(name = "@(package_name)__rosidl_typesupport_c")] | ||
extern "C" { | ||
fn rosidl_typesupport_c__get_service_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::os::raw::c_void; | ||
} | ||
|
||
// Corresponds to @(package_name)__@(subfolder)__@(type_name) | ||
pub struct @(type_name); | ||
|
||
impl rosidl_runtime_rs::Service for @(type_name) { | ||
type Request = crate::@(subfolder)::rmw::@(type_name)_Request; | ||
type Response = crate::@(subfolder)::rmw::@(type_name)_Response; | ||
|
||
fn get_type_support() -> *const std::os::raw::c_void { | ||
// SAFETY: No preconditions for this function. | ||
unsafe { rosidl_typesupport_c__get_service_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() } | ||
} | ||
} | ||
|
||
@[end for] | ||
|
||
} // mod rmw |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@{ | ||
req_res_specs = [] | ||
|
||
for subfolder, service in srv_specs: | ||
req_res_specs.append((subfolder, service.request_message)) | ||
req_res_specs.append((subfolder, service.response_message)) | ||
}@ | ||
|
||
@{ | ||
TEMPLATE( | ||
'msg_idiomatic.rs.em', | ||
package_name=package_name, interface_path=interface_path, | ||
msg_specs=req_res_specs, | ||
get_rs_name=get_rs_name, get_rmw_rs_type=get_rmw_rs_type, | ||
pre_field_serde=pre_field_serde, | ||
get_idiomatic_rs_type=get_idiomatic_rs_type, | ||
constant_value_to_rs=constant_value_to_rs) | ||
}@ | ||
|
||
@[for subfolder, srv_spec in srv_specs] | ||
|
||
@{ | ||
type_name = srv_spec.namespaced_type.name | ||
}@ | ||
|
||
#[link(name = "@(package_name)__rosidl_typesupport_c")] | ||
extern "C" { | ||
fn rosidl_typesupport_c__get_service_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() -> *const std::os::raw::c_void; | ||
} | ||
|
||
// Corresponds to @(package_name)__@(subfolder)__@(type_name) | ||
pub struct @(type_name); | ||
|
||
impl rosidl_runtime_rs::Service for @(type_name) { | ||
type Request = crate::@(subfolder)::@(type_name)_Request; | ||
type Response = crate::@(subfolder)::@(type_name)_Response; | ||
|
||
fn get_type_support() -> *const std::os::raw::c_void { | ||
// SAFETY: No preconditions for this function. | ||
unsafe { rosidl_typesupport_c__get_service_type_support_handle__@(package_name)__@(subfolder)__@(type_name)() } | ||
} | ||
} | ||
|
||
@[end for] |
Uh oh!
There was an error while loading. Please reload this page.