Skip to content
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

Vendor rcl_interfaces as a private module into rclrs #288

Merged
merged 3 commits into from
Oct 31, 2022
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
2 changes: 2 additions & 0 deletions rclrs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<build_depend>libclang-dev</build_depend>
<build_depend>rosidl_runtime_rs</build_depend>
<build_depend>rcl</build_depend>
<depend>builtin_interfaces</depend>
<depend>rcl_interfaces</depend>

<export>
<build_type>ament_cargo</build_type>
Expand Down
1 change: 1 addition & 0 deletions rclrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod publisher;
mod qos;
mod service;
mod subscription;
mod vendor;
mod wait;

mod rcl_bindings;
Expand Down
89 changes: 89 additions & 0 deletions rclrs/src/parameter/service.rs
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>,
]
}
}
3 changes: 3 additions & 0 deletions rclrs/src/vendor/builtin_interfaces/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![allow(non_camel_case_types)]

pub mod msg;
258 changes: 258 additions & 0 deletions rclrs/src/vendor/builtin_interfaces/msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
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,
}
}
}
6 changes: 6 additions & 0 deletions rclrs/src/vendor/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Created by vendor_interfaces.py
#![allow(dead_code)]
#![allow(clippy::derive_partial_eq_without_eq)]

pub mod builtin_interfaces;
pub mod rcl_interfaces;
5 changes: 5 additions & 0 deletions rclrs/src/vendor/rcl_interfaces/mod.rs
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;
Loading