This commit is contained in:
aozhiwei 2023-10-25 22:05:55 +08:00
parent 797e1d0184
commit 984d5c3acf

View File

@ -1,6 +1,7 @@
use std::rc::{Rc, Weak};
use std::cell::RefCell;
use std::any::Any;
use std::cmp;
const TVN_BITS: usize = 6;
const TVR_BITS: usize = 8;
@ -367,23 +368,58 @@ impl Timer {
}
pub fn fire_event(&mut self,
_timer_wp: TimerWp,
_e: i32,
_args: Option<Vec<Rc::<dyn Any>>>) {
timer_wp: TimerWp,
e: TimerEvent,
args: Option<Vec<Rc::<dyn Any>>>) {
match timer_wp.upgrade() {
Some(t) => {
match &mut t.borrow_mut().cb {
Some(cb) => {
(*cb)(e, args);
}
None => {
}
}
}
None => {
}
}
}
pub fn modify(&mut self, _timer_wp: TimerWp, _expire_time: i32) {
pub fn modify(&mut self, timer_wp: TimerWp, expire_time: i32) {
match timer_wp.upgrade() {
Some(_) => {
self.modify(timer_wp, expire_time);
}
None => {
}
}
}
pub fn delete_current_timer(&mut self) {
match self.running_timer.upgrade() {
Some(v) => {
self.internal_delete(Rc::downgrade(&v.borrow().wp), false);
}
None => {
}
}
}
pub fn is_running(&self) {
pub fn is_running(&self) -> bool {
match self.running_timer.upgrade() {
Some(_) => {
return true;
}
None => {
return false;
}
}
}
pub fn delete(&mut self, timer_wp: TimerWp) {
match timer_wp.upgrade() {
Some(v) => {
Some(_) => {
self.internal_delete(timer_wp, false);
}
None => {
@ -391,11 +427,16 @@ impl Timer {
}
}
pub fn reset(&mut self, _timer_wp: TimerWp) {
}
pub fn get_remain_time(&mut self, _timer_wp: TimerWp) -> i64 {
return 0;
pub fn get_remain_time(&mut self, timer_wp: TimerWp) -> i64 {
match timer_wp.upgrade() {
Some(t) => {
let remain_time = t.borrow().expires - (self.get_tick_count)();
return cmp::max(remain_time, 0);
}
None => {
return 0;
}
}
}
pub fn get_idle_time(&self) -> i64 {