162 lines
4.5 KiB
Java
162 lines
4.5 KiB
Java
package a6;
|
|
|
|
public class Timer {
|
|
|
|
@FunctionalInterface
|
|
public interface ITimerFunc
|
|
{
|
|
public void OnTimer(XParams param);
|
|
}
|
|
|
|
@FunctionalInterface
|
|
public interface ITimerAfterFunc
|
|
{
|
|
public void OnTimerAfter(XParams param);
|
|
}
|
|
|
|
@FunctionalInterface
|
|
public interface IGetTickCountFunc
|
|
{
|
|
public long GetTickCount(Object context);
|
|
}
|
|
|
|
public class TimerList
|
|
{
|
|
private ListHead entry = new ListHead();
|
|
private ListHead attachEntry;
|
|
private int timerType = 0;
|
|
private int milli_seconds = 0;
|
|
private long expires = 0;
|
|
|
|
private ITimerFunc timerFunc;
|
|
private ITimerAfterFunc timerAfterFunc;
|
|
private XParams param;
|
|
|
|
private void initTimerList(Timer timer, int timer_type, int milli_seconds,
|
|
XParams param, ITimerFunc timerFunc, ITimerAfterFunc afterFunc)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
private int freeTimerNum = 0;
|
|
private ListHead freeTimer = new ListHead();
|
|
private TimerList runningTimer;
|
|
private long timerTick = 0;
|
|
private IGetTickCountFunc getTickCount;
|
|
private Object content;
|
|
private int gcTime = 0;
|
|
private int cacheTimerNum = 0;
|
|
|
|
public void init(IGetTickCountFunc func, Object content, int gc_time, int cache_timer_num) {
|
|
this.getTickCount = func;
|
|
this.content = content;
|
|
this.gcTime = gc_time;
|
|
this.cacheTimerNum = cache_timer_num;
|
|
}
|
|
|
|
public void unInit() {
|
|
|
|
}
|
|
|
|
public void update() {
|
|
|
|
}
|
|
|
|
public TimerList addDeadLineTimer(int expire_time, XParams param, ITimerFunc timer_func) {
|
|
return addDeadLineTimer(expire_time, param, timer_func, null);
|
|
}
|
|
|
|
public TimerList addDeadLineTimer(int expire_time, XParams param, ITimerFunc timer_func,
|
|
ITimerAfterFunc after_func) {
|
|
TimerList timer = newTimerList();
|
|
timer.initTimerList(this, 0, expire_time, param, timer_func, after_func);
|
|
return timer;
|
|
}
|
|
|
|
public TimerList addDeadLineTimerAndAttach(int expire_time, XParams param, ITimerFunc timer_func,
|
|
TimerAttacher timer_attacher) {
|
|
return addDeadLineTimerAndAttach(expire_time, param, timer_func, timer_attacher, null);
|
|
}
|
|
|
|
public TimerList addDeadLineTimerAndAttach(int expire_time, XParams param, ITimerFunc timer_func,
|
|
TimerAttacher timer_attacher, ITimerAfterFunc after_func) {
|
|
TimerList timer = addDeadLineTimer(expire_time, param, timer_func, after_func);
|
|
timer_attacher.addTimer(timer.attachEntry);
|
|
return timer;
|
|
}
|
|
|
|
public TimerList addRepeatTimer(int expire_time, XParams param, ITimerFunc timer_func) {
|
|
TimerList timer = newTimerList();
|
|
timer.initTimerList(this, 1, expire_time, param, timer_func, null);
|
|
modifyTimer(timer, expire_time);
|
|
return timer;
|
|
}
|
|
|
|
public TimerList addFixedTimer(int expire_time, XParams param, ITimerFunc timer_func) {
|
|
TimerList timer = newTimerList();
|
|
timer.initTimerList(this, 2, expire_time, param, timer_func, null);
|
|
modifyTimer(timer, expire_time);
|
|
return timer;
|
|
}
|
|
|
|
public void modifyTimer(TimerList timer_list, int expire_time) {
|
|
|
|
}
|
|
|
|
public TimerList getTimerByAttach(ListHead attach_entry) {
|
|
return null;
|
|
}
|
|
|
|
public XParams getMutableParams(TimerList timer_list) {
|
|
return null;
|
|
}
|
|
|
|
public long getRemainTime(TimerList timer_list) {
|
|
return 0;
|
|
}
|
|
|
|
public TimerList getRunningTimer() {
|
|
return null;
|
|
}
|
|
|
|
public int getIdleableMillSeconds() {
|
|
return 0;
|
|
}
|
|
|
|
public void deleteTimer(TimerList timer_list) {
|
|
if (timer_list.timerAfterFunc != null) {
|
|
timer_list.timerAfterFunc.OnTimerAfter(timer_list.param);
|
|
}
|
|
detachTimer(timer_list);
|
|
if (timer_list.attachEntry != null && !timer_list.attachEntry.empty()) {
|
|
timer_list.attachEntry.del();
|
|
}
|
|
addToFreeList(timer_list);
|
|
}
|
|
|
|
public void detachTimer(TimerList timer_list) {
|
|
if (timer_list.entry != null && !timer_list.entry.empty()) {
|
|
timer_list.entry.delInit();
|
|
}
|
|
}
|
|
|
|
private TimerList newTimerList() {
|
|
return null;
|
|
}
|
|
|
|
private void clear() {
|
|
|
|
}
|
|
|
|
private void addToFreeList(TimerList timer_list) {
|
|
freeTimer.addTail(timer_list.entry);
|
|
++freeTimerNum;
|
|
}
|
|
|
|
private void gcTimerFunc() {
|
|
|
|
}
|
|
|
|
}
|