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

Domain id init #223

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8e9393d
add time.rs to src as well as to lib.rs (#121)
DS3a Jun 14, 2022
efe7010
added the Time struct
DS3a Jun 14, 2022
f024ad6
add duration.rs to lib and src
DS3a Jun 14, 2022
92e55a1
added the Duration struct
DS3a Jun 14, 2022
c332adb
complete duration.rs
DS3a Jun 15, 2022
68d6df6
add function to return Duration object
DS3a Jun 15, 2022
7eceafe
implemented clone for Duration
DS3a Jun 15, 2022
9c29dee
changes made to time.rs and lib.rs
DS3a Jun 15, 2022
dc66c3c
Merge branch 'ros2-rust:main' into main
DS3a Jun 15, 2022
7f9a6a7
implement Add for time.rs
DS3a Jun 15, 2022
15c9914
add max implementation for Duration
DS3a Jun 15, 2022
49fe3ed
complete time.rs
DS3a Jun 15, 2022
607a201
add clock.rs to src and lib.rs
DS3a Jun 15, 2022
a0d288b
adjusted duration.rs to accomodate negative values as well
DS3a Jun 15, 2022
4260124
refactor time.rs
DS3a Jun 16, 2022
bd356cb
add initial functionality to clock.rs
DS3a Jun 16, 2022
0fce763
add todos to finish after review
DS3a Jun 16, 2022
48a5543
made get_lock publich
DS3a Jun 16, 2022
7853af4
added now to clock.rs
DS3a Jun 16, 2022
c432746
refined duration.rs
DS3a Jun 17, 2022
3a9d90c
implement ord and eq for Tie
DS3a Jun 17, 2022
e5c194d
added some more functions
DS3a Jun 17, 2022
6920fda
Merge branch 'ros2-rust:main' into main
DS3a Jun 23, 2022
4dc0d00
adding ContextBuildr
DS3a Jun 26, 2022
c35dbfd
Merge branch 'ros2-rust:main' into main
DS3a Jul 10, 2022
dc17ed9
Merge branch 'main' of github.com:DS3a/ros2_rust into domain_id_init
DS3a Jul 10, 2022
7adb4f6
implemented new in context/builder.rs
DS3a Jul 10, 2022
3f0360f
add context builder (#206)
DS3a Jul 10, 2022
2f69b60
remove unwanted dependencies
DS3a Jul 10, 2022
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
Prev Previous commit
Next Next commit
add initial functionality to clock.rs
  • Loading branch information
DS3a committed Jun 16, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit bd356cba2a83e1089efd37532ef1e6610ecbe391
100 changes: 100 additions & 0 deletions rclrs/src/clock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use crate::error::RclrsError;
use crate::rcl_bindings::*;
use crate::RclReturnCode;
use crate::duration;
use parking_lot::Mutex;
use std::os::raw::{c_void, c_int};

impl std::default::Default for rcl_allocator_t {
fn default() -> Self {
let empty: c_int = 0;
rcl_allocator_t {
allocate: None,
deallocate: None,
reallocate: None,
zero_allocate: None,
state: empty as *mut c_void,
}
}
}

impl std::default::Default for rcl_clock_t {
fn default() -> Self {
let mut threshold_ = rcl_jump_callback_info_t {
callback: None,
threshold: rcl_jump_threshold_t {
on_clock_change: false,
min_forward: rcl_duration_t {
nanoseconds: 1 as rcl_duration_value_t
},
min_backward: rcl_duration_t {
nanoseconds: -1 as rcl_duration_value_t,
},
} ,
user_data: 0 as *mut c_void,
};

rcl_clock_t {
type_: rcl_clock_type_t::RCL_CLOCK_UNINITIALIZED,
jump_callbacks: &mut threshold_,
num_jump_callbacks: usize::default(),
get_now: None,
data: 0 as *mut c_void,
allocator: rcl_allocator_t::default(),
}
}
}

struct JumpHandler {
pre_callback: &'static dyn Fn() -> (),
post_callback: &'static dyn Fn() -> Mutex<rcl_time_jump_t>,
threshold: rcl_jump_threshold_t,
}

impl JumpHandler {
fn new(pre_callback: &dyn Fn() -> (),
post_callback: &dyn Fn() -> Mutex<rcl_time_jump_t>,
threshold: rcl_jump_threshold_t) -> Self {
todo!("implement it");
}
}

struct Impl {
rcl_clock_: Mutex<rcl_clock_t>,
allocator_: Mutex<rcl_allocator_t>,
//clock_mutex_: Mutex<_>,
}

/// The Clock struct
pub struct Clock {
impl_: Impl,
}

#[allow(dead_code)]
impl Clock {
/// Function to create a new Clock instance
pub fn new(clock_type: rcl_clock_type_t) -> Result<Self, RclrsError> {
let mut impl_ = Impl {
rcl_clock_: Mutex::new(rcl_clock_t::default()),
allocator_: Mutex::new(rcl_allocator_t::default())
};
// Safety: variables are wrapped in Mutex
// raw pointer get converted back to safe types once `get_mut` goes out of scope
let ret: rcl_ret_t = unsafe {
rcl_clock_init(clock_type,
impl_.rcl_clock_.get_mut() as *mut rcl_clock_t,
impl_.allocator_.get_mut() as *mut rcl_allocator_t)
};

if ret != 0 {
return Err(RclrsError::RclError {
code: RclReturnCode::Error,
msg: None,
});
}

Ok(Self{
impl_,
})
}
}