|
1 |
| -pub struct NodeBuilder { |
| 1 | +use crate::rcl_bindings::*; |
| 2 | +use crate::{Context, RclrsError}; |
| 3 | +use std::ffi::CString; |
| 4 | +use std::os::raw::c_char; |
| 5 | +use parking_lot::Mutex; |
2 | 6 |
|
| 7 | +pub struct ContextBuilder { |
| 8 | + cstring_args: Vec<CString>, |
| 9 | + c_args: Option<Vec<*const c_char>>, |
| 10 | + context_mtx: Mutex<rcl_context_t>, |
| 11 | + allocator: rcl_allocator_t, |
| 12 | + init_options_mtx: Mutex<rcl_init_options_t>, |
| 13 | +} |
| 14 | + |
| 15 | +impl ContextBuilder { |
| 16 | + |
| 17 | + /// Build a new ContextBuilder instance |
| 18 | + pub fn new(args: impl IntoIterator<Item = String>) -> Result<ContextBuilder, RclrsError> { |
| 19 | + unsafe { |
| 20 | + Ok(ContextBuilder { |
| 21 | + cstring_args: args.into_iter().map(|arg| { |
| 22 | + CString::new(arg.as_str()).map_err(|err| RclrsError::StringContainsNul{ |
| 23 | + err, |
| 24 | + s: arg.clone(), |
| 25 | + }) |
| 26 | + }).collect::<Result<_, _>>()?, |
| 27 | + c_args: None, // to be built in the build function |
| 28 | + context_mtx: Mutex::new(rcl_get_zero_initialized_context()), |
| 29 | + allocator: rcutils_get_default_allocator(), |
| 30 | + init_options_mtx: Mutex::new(rcl_get_zero_initialized_init_options()) |
| 31 | + }) |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + pub fn build(&self) -> Result<Context, RclrsError> { |
| 36 | + todo!("call build here"); |
| 37 | + } |
3 | 38 | }
|
0 commit comments