diff --git a/src/listhead.rs b/src/listhead.rs index b565dfd..b4c3dcf 100644 --- a/src/listhead.rs +++ b/src/listhead.rs @@ -1,16 +1,39 @@ -pub struct ListHead { - prev: Option>, - next: Option>, +use std::rc::{Rc, Weak}; +use std::cell::RefCell; + +pub struct ListHead { + prev: Weak::>>, + next: Weak::>>, + data: Weak::>, } -impl ListHead { +impl ListHead { - pub fn new() -> Self { - let p = ListHead{ - prev: None, - next: None, - }; - return p; + pub fn new() -> Rc::>> { + let this = Rc::new(RefCell::new(ListHead{ + prev: Weak::>>::new(), + next: Weak::>>::new(), + data: Weak::>::new(), + })); + this.borrow_mut().prev = Rc::downgrade(&this); + this.borrow_mut().next = Rc::downgrade(&this); + return this; + } + + pub fn data(&self) -> &Weak::> { + return &self.data; + } + + pub fn del(&mut self) { + self.next.upgrade().unwrap().borrow_mut().prev = self.prev.clone(); + self.prev.upgrade().unwrap().borrow_mut().next = self.next.clone(); + } + + pub fn add_tail(&mut self, pnew: &mut ListHead) { + let prev = &mut self.prev; + unsafe { + let next = Weak::from_raw(self); + } } } diff --git a/src/metamgr.rs b/src/metamgr.rs index 97155e4..a4cce3c 100644 --- a/src/metamgr.rs +++ b/src/metamgr.rs @@ -1,5 +1,5 @@ use std::rc::Rc; -use std::fs::File; +//use std::fs::File; use std::collections::HashMap; pub trait ProtoMsg { @@ -91,6 +91,7 @@ impl MetaMgr { } pub fn load(&mut self) { + /* for i in 0..self.meta_classes.len() { let meta = &self.meta_classes[i]; match File::open(&meta.file_name) { @@ -124,7 +125,7 @@ impl MetaMgr { } } - } + }*/ } pub fn get_metalist(&mut self, idx: i32) -> Option<&Vec::>> { diff --git a/src/timer.rs b/src/timer.rs index 9e8da6f..067f097 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -1,17 +1,21 @@ +pub struct TimerList { + +} + pub struct Timer { } impl Timer { -/* pub fn init(&mut self, + pub fn init(&mut self, get_tick_count: fn () -> i64, get_fxied_timer_expires: fn (i32, i64) -> i64, context: (), gctime: i32, cache_timer_num: i32) { - }*/ + } pub fn uninit(&mut self) {