-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vendor rcl_interfaces as a private module into rclrs
The parameter services require the rcl_interfaces message and service types.
- Loading branch information
Showing
9 changed files
with
3,385 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ mod publisher; | |
mod qos; | ||
mod service; | ||
mod subscription; | ||
mod vendor; | ||
mod wait; | ||
|
||
mod rcl_bindings; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use std::sync::{Arc, Weak, Mutex}; | ||
|
||
use crate::vendor::rcl_interfaces::srv::rmw::*; | ||
use crate::vendor::rcl_interfaces::msg::rmw::*; | ||
use rosidl_runtime_rs::{Sequence, seq}; | ||
|
||
use crate::{rmw_request_id_t, Node, RclrsError, Service, ServiceBase}; | ||
use crate::rcl_bindings::rcl_node_t; | ||
|
||
pub struct ParameterService { | ||
describe_parameters_service: Arc<Service<DescribeParameters>>, | ||
get_parameter_types_service: Arc<Service<GetParameterTypes>>, | ||
get_parameters_service: Arc<Service<GetParameters>>, | ||
list_parameters_service: Arc<Service<ListParameters>>, | ||
set_parameters_service: Arc<Service<SetParameters>>, | ||
set_parameters_atomically_service: Arc<Service<SetParametersAtomically>>, | ||
} | ||
|
||
impl ParameterService { | ||
pub fn new(rcl_node_mtx: Arc<Mutex<rcl_node_t>>) -> Result<Self, RclrsError> { | ||
let describe_parameters_service = Service::new(Arc::clone(&rcl_node_mtx), | ||
"describe_parameters", | ||
|req_id: &rmw_request_id_t, req: DescribeParameters_Request| { | ||
DescribeParameters_Response { | ||
descriptors: seq![] | ||
} | ||
}, | ||
)?; | ||
let get_parameter_types_service = Service::new(Arc::clone(&rcl_node_mtx), | ||
"get_parameter_types", | ||
|req_id: &rmw_request_id_t, req: GetParameterTypes_Request| { | ||
GetParameterTypes_Response { | ||
types: seq![] | ||
} | ||
}, | ||
)?; | ||
let get_parameters_service = Service::new(Arc::clone(&rcl_node_mtx), | ||
"get_parameters", | ||
|req_id: &rmw_request_id_t, req: GetParameters_Request| { | ||
GetParameters_Response { | ||
values: seq![] | ||
} | ||
}, | ||
)?; | ||
let list_parameters_service = Service::new(Arc::clone(&rcl_node_mtx), | ||
"list_parameters", | ||
|req_id: &rmw_request_id_t, req: ListParameters_Request| { | ||
ListParameters_Response { | ||
result: ListParametersResult::default() | ||
} | ||
}, | ||
)?; | ||
let set_parameters_service = Service::new(Arc::clone(&rcl_node_mtx), | ||
"set_parameters", | ||
|req_id: &rmw_request_id_t, req: SetParameters_Request| { | ||
SetParameters_Response { | ||
results: seq![] | ||
} | ||
}, | ||
)?; | ||
let set_parameters_atomically_service = Service::new(Arc::clone(&rcl_node_mtx), | ||
"set_parameters_atomically", | ||
|req_id: &rmw_request_id_t, req: SetParametersAtomically_Request| { | ||
SetParametersAtomically_Response { | ||
result: SetParametersResult::default() | ||
} | ||
}, | ||
)?; | ||
Ok(Self { | ||
describe_parameters_service: Arc::new(describe_parameters_service), | ||
get_parameter_types_service: Arc::new(get_parameter_types_service), | ||
get_parameters_service: Arc::new(get_parameters_service), | ||
list_parameters_service: Arc::new(list_parameters_service), | ||
set_parameters_service: Arc::new(set_parameters_service), | ||
set_parameters_atomically_service: Arc::new(set_parameters_atomically_service), | ||
}) | ||
} | ||
|
||
pub fn services(&self) -> Vec<Weak<dyn ServiceBase>> { | ||
vec![ | ||
Arc::downgrade(&self.describe_parameters_service) as Weak<dyn ServiceBase>, | ||
Arc::downgrade(&self.get_parameter_types_service) as Weak<dyn ServiceBase>, | ||
Arc::downgrade(&self.get_parameters_service) as Weak<dyn ServiceBase>, | ||
Arc::downgrade(&self.list_parameters_service) as Weak<dyn ServiceBase>, | ||
Arc::downgrade(&self.set_parameters_service) as Weak<dyn ServiceBase>, | ||
Arc::downgrade(&self.set_parameters_atomically_service) as Weak<dyn ServiceBase>, | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#![allow(non_camel_case_types)] | ||
|
||
pub mod msg; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
pub mod rmw { | ||
#[cfg(feature = "serde")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[link(name = "builtin_interfaces__rosidl_typesupport_c")] | ||
extern "C" { | ||
fn rosidl_typesupport_c__get_message_type_support_handle__builtin_interfaces__msg__Duration() -> *const std::os::raw::c_void; | ||
} | ||
|
||
#[link(name = "builtin_interfaces__rosidl_generator_c")] | ||
extern "C" { | ||
fn builtin_interfaces__msg__Duration__init(msg: *mut Duration) -> bool; | ||
fn builtin_interfaces__msg__Duration__Sequence__init(seq: *mut rosidl_runtime_rs::Sequence<Duration>, size: usize) -> bool; | ||
fn builtin_interfaces__msg__Duration__Sequence__fini(seq: *mut rosidl_runtime_rs::Sequence<Duration>); | ||
fn builtin_interfaces__msg__Duration__Sequence__copy(in_seq: &rosidl_runtime_rs::Sequence<Duration>, out_seq: *mut rosidl_runtime_rs::Sequence<Duration>) -> bool; | ||
} | ||
|
||
// Corresponds to builtin_interfaces__msg__Duration | ||
#[repr(C)] | ||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] | ||
#[derive(Clone, Debug, PartialEq, PartialOrd)] | ||
pub struct Duration { | ||
pub sec: i32, | ||
pub nanosec: u32, | ||
} | ||
|
||
|
||
|
||
impl Default for Duration { | ||
fn default() -> Self { | ||
unsafe { | ||
let mut msg = std::mem::zeroed(); | ||
if !builtin_interfaces__msg__Duration__init(&mut msg as *mut _) { | ||
panic!("Call to builtin_interfaces__msg__Duration__init() failed"); | ||
} | ||
msg | ||
} | ||
} | ||
} | ||
|
||
impl rosidl_runtime_rs::SequenceAlloc for Duration { | ||
fn sequence_init(seq: &mut rosidl_runtime_rs::Sequence<Self>, size: usize) -> bool { | ||
// SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. | ||
unsafe { builtin_interfaces__msg__Duration__Sequence__init(seq as *mut _, size) } | ||
} | ||
fn sequence_fini(seq: &mut rosidl_runtime_rs::Sequence<Self>) { | ||
// SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. | ||
unsafe { builtin_interfaces__msg__Duration__Sequence__fini(seq as *mut _) } | ||
} | ||
fn sequence_copy(in_seq: &rosidl_runtime_rs::Sequence<Self>, out_seq: &mut rosidl_runtime_rs::Sequence<Self>) -> bool { | ||
// SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. | ||
unsafe { builtin_interfaces__msg__Duration__Sequence__copy(in_seq, out_seq as *mut _) } | ||
} | ||
} | ||
|
||
impl rosidl_runtime_rs::Message for Duration { | ||
type RmwMsg = Self; | ||
fn into_rmw_message(msg_cow: std::borrow::Cow<'_, Self>) -> std::borrow::Cow<'_, Self::RmwMsg> { msg_cow } | ||
fn from_rmw_message(msg: Self::RmwMsg) -> Self { msg } | ||
} | ||
|
||
impl rosidl_runtime_rs::RmwMessage for Duration where Self: Sized { | ||
const TYPE_NAME: &'static str = "builtin_interfaces/msg/Duration"; | ||
fn get_type_support() -> *const std::os::raw::c_void { | ||
// SAFETY: No preconditions for this function. | ||
unsafe { rosidl_typesupport_c__get_message_type_support_handle__builtin_interfaces__msg__Duration() } | ||
} | ||
} | ||
|
||
|
||
#[link(name = "builtin_interfaces__rosidl_typesupport_c")] | ||
extern "C" { | ||
fn rosidl_typesupport_c__get_message_type_support_handle__builtin_interfaces__msg__Time() -> *const std::os::raw::c_void; | ||
} | ||
|
||
#[link(name = "builtin_interfaces__rosidl_generator_c")] | ||
extern "C" { | ||
fn builtin_interfaces__msg__Time__init(msg: *mut Time) -> bool; | ||
fn builtin_interfaces__msg__Time__Sequence__init(seq: *mut rosidl_runtime_rs::Sequence<Time>, size: usize) -> bool; | ||
fn builtin_interfaces__msg__Time__Sequence__fini(seq: *mut rosidl_runtime_rs::Sequence<Time>); | ||
fn builtin_interfaces__msg__Time__Sequence__copy(in_seq: &rosidl_runtime_rs::Sequence<Time>, out_seq: *mut rosidl_runtime_rs::Sequence<Time>) -> bool; | ||
} | ||
|
||
// Corresponds to builtin_interfaces__msg__Time | ||
#[repr(C)] | ||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] | ||
#[derive(Clone, Debug, PartialEq, PartialOrd)] | ||
pub struct Time { | ||
pub sec: i32, | ||
pub nanosec: u32, | ||
} | ||
|
||
|
||
|
||
impl Default for Time { | ||
fn default() -> Self { | ||
unsafe { | ||
let mut msg = std::mem::zeroed(); | ||
if !builtin_interfaces__msg__Time__init(&mut msg as *mut _) { | ||
panic!("Call to builtin_interfaces__msg__Time__init() failed"); | ||
} | ||
msg | ||
} | ||
} | ||
} | ||
|
||
impl rosidl_runtime_rs::SequenceAlloc for Time { | ||
fn sequence_init(seq: &mut rosidl_runtime_rs::Sequence<Self>, size: usize) -> bool { | ||
// SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. | ||
unsafe { builtin_interfaces__msg__Time__Sequence__init(seq as *mut _, size) } | ||
} | ||
fn sequence_fini(seq: &mut rosidl_runtime_rs::Sequence<Self>) { | ||
// SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. | ||
unsafe { builtin_interfaces__msg__Time__Sequence__fini(seq as *mut _) } | ||
} | ||
fn sequence_copy(in_seq: &rosidl_runtime_rs::Sequence<Self>, out_seq: &mut rosidl_runtime_rs::Sequence<Self>) -> bool { | ||
// SAFETY: This is safe since the pointer is guaranteed to be valid/initialized. | ||
unsafe { builtin_interfaces__msg__Time__Sequence__copy(in_seq, out_seq as *mut _) } | ||
} | ||
} | ||
|
||
impl rosidl_runtime_rs::Message for Time { | ||
type RmwMsg = Self; | ||
fn into_rmw_message(msg_cow: std::borrow::Cow<'_, Self>) -> std::borrow::Cow<'_, Self::RmwMsg> { msg_cow } | ||
fn from_rmw_message(msg: Self::RmwMsg) -> Self { msg } | ||
} | ||
|
||
impl rosidl_runtime_rs::RmwMessage for Time where Self: Sized { | ||
const TYPE_NAME: &'static str = "builtin_interfaces/msg/Time"; | ||
fn get_type_support() -> *const std::os::raw::c_void { | ||
// SAFETY: No preconditions for this function. | ||
unsafe { rosidl_typesupport_c__get_message_type_support_handle__builtin_interfaces__msg__Time() } | ||
} | ||
} | ||
|
||
|
||
} // mod rmw | ||
|
||
|
||
#[cfg(feature = "serde")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] | ||
#[derive(Clone, Debug, PartialEq, PartialOrd)] | ||
pub struct Duration { | ||
pub sec: i32, | ||
pub nanosec: u32, | ||
} | ||
|
||
|
||
|
||
impl Default for Duration { | ||
fn default() -> Self { | ||
<Self as rosidl_runtime_rs::Message>::from_rmw_message(crate::vendor::builtin_interfaces::msg::rmw::Duration::default()) | ||
} | ||
} | ||
|
||
impl rosidl_runtime_rs::Message for Duration { | ||
type RmwMsg = crate::vendor::builtin_interfaces::msg::rmw::Duration; | ||
|
||
fn into_rmw_message(msg_cow: std::borrow::Cow<'_, Self>) -> std::borrow::Cow<'_, Self::RmwMsg> { | ||
match msg_cow { | ||
std::borrow::Cow::Owned(msg) => std::borrow::Cow::Owned(Self::RmwMsg { | ||
sec: msg.sec, | ||
nanosec: msg.nanosec, | ||
}), | ||
std::borrow::Cow::Borrowed(msg) => std::borrow::Cow::Owned(Self::RmwMsg { | ||
sec: msg.sec, | ||
nanosec: msg.nanosec, | ||
}) | ||
} | ||
} | ||
|
||
fn from_rmw_message(msg: Self::RmwMsg) -> Self { | ||
Self { | ||
sec: msg.sec, | ||
nanosec: msg.nanosec, | ||
} | ||
} | ||
} | ||
|
||
|
||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] | ||
#[derive(Clone, Debug, PartialEq, PartialOrd)] | ||
pub struct Time { | ||
pub sec: i32, | ||
pub nanosec: u32, | ||
} | ||
|
||
|
||
|
||
impl Default for Time { | ||
fn default() -> Self { | ||
<Self as rosidl_runtime_rs::Message>::from_rmw_message(crate::vendor::builtin_interfaces::msg::rmw::Time::default()) | ||
} | ||
} | ||
|
||
impl rosidl_runtime_rs::Message for Time { | ||
type RmwMsg = crate::vendor::builtin_interfaces::msg::rmw::Time; | ||
|
||
fn into_rmw_message(msg_cow: std::borrow::Cow<'_, Self>) -> std::borrow::Cow<'_, Self::RmwMsg> { | ||
match msg_cow { | ||
std::borrow::Cow::Owned(msg) => std::borrow::Cow::Owned(Self::RmwMsg { | ||
sec: msg.sec, | ||
nanosec: msg.nanosec, | ||
}), | ||
std::borrow::Cow::Borrowed(msg) => std::borrow::Cow::Owned(Self::RmwMsg { | ||
sec: msg.sec, | ||
nanosec: msg.nanosec, | ||
}) | ||
} | ||
} | ||
|
||
fn from_rmw_message(msg: Self::RmwMsg) -> Self { | ||
Self { | ||
sec: msg.sec, | ||
nanosec: msg.nanosec, | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//! Vendored by vendor_interfaces.py | ||
#![allow(dead_code)] | ||
|
||
pub mod builtin_interfaces; | ||
pub mod rcl_interfaces; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#![allow(non_camel_case_types)] | ||
|
||
pub mod msg; | ||
|
||
pub mod srv; |
Oops, something went wrong.