trait inheritance is strange

This commit is contained in:
Ulrich Mohr 2023-12-11 15:34:09 +01:00
parent 59f4a82da9
commit bae91a61d4
3 changed files with 9 additions and 3 deletions

View File

@ -1,3 +1,5 @@
use super::objectmanager::SystemObjectIF;
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
pub struct TypeId { pub struct TypeId {
id: usize, id: usize,
@ -14,7 +16,7 @@ pub trait Reflection {
} }
pub trait DatapoolOwnerIF { pub trait DatapoolOwnerIF {
fn get_set(&self, type_id: TypeId) -> Option<&dyn DataSetIF> { fn get_set(&self, _type_id: TypeId) -> Option<&dyn DataSetIF> {
None None
} }
} }
@ -75,7 +77,7 @@ impl<T: Reflection + Copy + Default> ReferencedDataset<T> {
} }
} }
pub fn initialize(&mut self, owner: &dyn DatapoolOwnerIF) -> Result<(), ()> { pub fn initialize(&mut self, owner: &dyn SystemObjectIF) -> Result<(), ()> {
let temp: T = T::default(); //TODO find nicer solution whithout local instance and trait bound to Default let temp: T = T::default(); //TODO find nicer solution whithout local instance and trait bound to Default
let type_id = temp.get_type_id(); let type_id = temp.get_type_id();
let other_set: &dyn DataSetIF; let other_set: &dyn DataSetIF;
@ -88,6 +90,7 @@ impl<T: Reflection + Copy + Default> ReferencedDataset<T> {
} }
} }
//pointer cast is safe because we checked the type_id //pointer cast is safe because we checked the type_id
//getting pointer to avoid lifetime check
self.actual_data = Some(other_set.get_actual_data() as *const dyn Reflection as *const T); self.actual_data = Some(other_set.get_actual_data() as *const dyn Reflection as *const T);
//self.mutex = other.mutex //self.mutex = other.mutex
Ok(()) Ok(())

View File

@ -90,6 +90,7 @@ pub struct TaskExecutor<'a> {
impl<'a> TaskExecutor<'a> { impl<'a> TaskExecutor<'a> {
pub fn init_and_run(&mut self) { pub fn init_and_run(&mut self) {
//TODO unlock global multitasking mutex
let object_manager = TaskObjectManager { let object_manager = TaskObjectManager {
tasks: unsafe { slice::from_raw_parts(self.tasks.as_ptr(), self.tasks.len()) }, tasks: unsafe { slice::from_raw_parts(self.tasks.as_ptr(), self.tasks.len()) },
}; };
@ -140,6 +141,7 @@ impl<'a> crate::objectmanager::ObjectManager<'a> for TaskObjectManager<'a> {
impl<'a> Drop for TaskExecutor<'a> { impl<'a> Drop for TaskExecutor<'a> {
fn drop(&mut self) { fn drop(&mut self) {
//TODO lock global multitasking mutex
for task in self.tasks.iter_mut() { for task in self.tasks.iter_mut() {
unsafe { unsafe {
crate::fsrc::osal::delete_task(task.get_handle()); crate::fsrc::osal::delete_task(task.get_handle());

View File

@ -162,7 +162,8 @@ impl SystemObjectIF for HandlerSender {
Err(_) => return Err(()), Err(_) => return Err(()),
}; };
self.other_handler_queue = other_handler.get_command_queue(); self.other_handler_queue = other_handler.get_command_queue();
//TODO self.other_data.initialize(other_handler); // oh come on :/
self.other_data.initialize(other_handler)?;
Ok(()) Ok(())
} }
} }