00001 #ifndef TIMER_H
00002 #define TIMER_H 1
00003
00004 #include <omnetpp.h>
00005
00006 #include "TimerCore.h"
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class Timer
00040 {
00041 friend class TimerCore;
00042 protected:
00043 TimerCore *ct;
00044 cModule *owner;
00045
00046 public:
00047 Timer(){ct = NULL;owner=NULL;}
00048 virtual ~Timer(){delete ct;}
00049
00054 virtual void init(cModule *parent);
00055
00061 void setTimer(unsigned int index, simtime_t when){checkCT();ct->setTimer(index,when);}
00062
00069 unsigned int setTimer(simtime_t when){checkCT();return ct->setTimer(when);}
00070
00076 void cancelTimer(unsigned int index){checkCT();ct->cancelTimer(index);}
00077
00082 float remainingTimer(unsigned int index) {checkCT();return ct->remainingTimer(index);}
00083
00084
00085
00086
00087 virtual void handleTimer(unsigned int index)=0;
00088
00093 void setContextPointer(unsigned int index,void * data) {checkCT();ct->setContextPointer(index,data);}
00094
00099 void * contextPointer(unsigned int index) {checkCT();return ct->contextPointer(index);}
00100
00106 void setContextDestructor(unsigned int index, void (*func)(void * data)){checkCT();ct->setContextDestructor(index,func);}
00107
00108
00109
00110
00111
00112 void allocateTimers(unsigned int count) {checkCT();ct->allocateTimers(count);}
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 void deleteTimer(unsigned int index) {checkCT();ct->deleteTimer(index);}
00125
00126 private:
00127
00128 void checkCT()
00129 {
00130 if (ct == NULL)
00131 opp_error("init() must be called before using Timer functions");
00132 }
00133
00134 };
00135
00136 #endif