1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use anyhow::{Context, Result};
use crate::error::ToRclRustResult;
use crate::log::Logger;
use crate::rclrust_error;
#[derive(Debug)]
pub(crate) struct RclInitOptions(rcl_sys::rcl_init_options_t);
unsafe impl Send for RclInitOptions {}
impl RclInitOptions {
pub fn new() -> Result<Self> {
let mut options = unsafe { rcl_sys::rcl_get_zero_initialized_init_options() };
unsafe {
rcl_sys::rcl_init_options_init(&mut options, rcl_sys::rcutils_get_default_allocator())
.to_result()
.with_context(|| "rcl_sys::rcl_init_options_init in RclInitOptions::new")?;
}
Ok(Self(options))
}
pub const fn raw(&self) -> &rcl_sys::rcl_init_options_t {
&self.0
}
}
impl Drop for RclInitOptions {
fn drop(&mut self) {
if let Err(e) = unsafe { rcl_sys::rcl_init_options_fini(&mut self.0).to_result() } {
rclrust_error!(
Logger::new("rclrust"),
"Failed to clean up rcl init options handle: {}",
e
)
}
}
}
#[derive(Debug)]
pub struct InitOptions {
options: RclInitOptions,
// shutdown_on_sigint: bool,
// initialize_logging: bool,
}
impl InitOptions {
pub fn new() -> Result<Self> {
Ok(Self {
options: RclInitOptions::new()?,
// shutdown_on_sigint: true,
// initialize_logging: true,
})
}
pub(crate) const fn raw(&self) -> &rcl_sys::rcl_init_options_t {
self.options.raw()
}
// / # Examples
// / ```
// / use rclrust::InitOptions;
// /
// / let init_options = InitOptions::new().unwrap();
// / assert_eq!(init_options.initialize_logging(), true);
// / ```
// pub const fn initialize_logging(&self) -> bool {
// self.initialize_logging
// }
// / # Examples
// / ```
// / use rclrust::InitOptions;
// /
// / let init_options = InitOptions::new().unwrap().set_initialize_logging(false);
// / assert_eq!(init_options.initialize_logging(), false);
// / ```
// #[allow(clippy::missing_const_for_fn)]
// pub fn set_initialize_logging(self, initialize_logging: bool) -> Self {
// Self {
// initialize_logging,
// ..self
// }
// }
// pub const fn shutdown_on_sigint(&self) -> bool {
// self.shutdown_on_sigint
// }
// #[allow(clippy::missing_const_for_fn)]
// pub fn set_shutdown_on_sigint(self, shutdown_on_sigint: bool) -> Self {
// Self {
// shutdown_on_sigint,
// ..self
// }
// }
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn init_options_new() -> Result<()> {
let _init_options = InitOptions::new()?;
Ok(())
}
}