TimerCore.h

00001 #ifndef TIMER_CORE_H
00002 #define TIMER_CORE_H 1
00003 
00004 #include "BaseModule.h"
00005 #include <omnetpp.h>
00006 
00007 class Timer;
00008 
00009 class TimerCore: public BaseModule
00010 {
00011   public:
00012     typedef void (cleanup)(void * data);
00013   protected:
00014     void checkExists(unsigned int index);
00015     Timer *timer;
00016 
00017     std::map <unsigned int, cMessage *> *timers;
00018     std::map <unsigned int, cleanup*> *destructors;
00019 
00021     virtual void handleMessage(cMessage* msg);
00022 
00023   public:
00024     //Module_Class_Members(TimerCore, BaseModule, 0);
00025     ~TimerCore();
00026 
00027     void init (Timer* t);
00028 
00034     void setTimer(unsigned int index, simtime_t when);
00035 
00042     unsigned int setTimer(simtime_t when);
00043 
00049     void cancelTimer(unsigned int index);
00050 
00056     float remainingTimer(unsigned int index);
00057 
00062     void setContextPointer(unsigned int index,void * data);
00063 
00068     void * contextPointer(unsigned int index);
00069 
00075     void setContextDestructor(unsigned int index, cleanup *);
00076 
00077     /* Mark the first @count pointer ids (from 0 to @count-1) as allocated, so they don't get
00078      * auto-allocated by setTimer
00079      * @param count Number of timers to allocate
00080      */
00081     void allocateTimers(unsigned int count);
00082 
00083     /* Delete a timer. Useful for auto-allocated timers that you don't need any more to 
00084      * reduce memory usage. Does nothing if the timer doesn't exist
00085      * @param index Timer to wipe
00086      */
00087     void deleteTimer(unsigned int index);
00088 };
00089 
00090 #endif