RepeatTimerCore.h

00001 #ifndef REPEATTIMER_CORE_H
00002 #define REPEATTIMER_CORE_H 1
00003 
00004 #include "BaseModule.h"
00005 #include <omnetpp.h>
00006 
00007 class RepeatTimer;
00008 
00009 class RepeatTimerCore: public BaseModule
00010 {
00011   public:
00012     typedef void (cleanup)(void * data);
00013     typedef struct {
00014       cMessage * timer;
00015       cleanup * destructor;
00016       int repeats, count;
00017       double when;
00018     } TInfo;
00019   protected:
00020     void checkExists(unsigned int index);
00021     RepeatTimer *timer;
00022 
00023     std::map <unsigned int, TInfo> *timer_map;
00024 
00026     virtual void handleMessage(cMessage* msg);
00027 
00028   public:
00029     //Module_Class_Members(RepeatTimerCore, BaseModule, 0);
00030     ~RepeatTimerCore();
00031 
00032     void init (RepeatTimer* t);
00033 
00039     void setRepeatTimer(unsigned int index, double when, int repeats = 1);
00040 
00047     unsigned int setRepeatTimer(double when, int repeats = 1);
00048 
00054     void cancelRepeatTimer(unsigned int index);
00055 
00056     void resetRepeatTimer(unsigned int index);
00057 
00058     void resetAllRepeatTimers(void);
00059 
00060     bool timerExists(unsigned int index);
00061 
00066     float remainingRepeatTimer(unsigned int index);
00067 
00072     void setContextPointer(unsigned int index,void * data);
00073 
00078     void * contextPointer(unsigned int index);
00079 
00085     void setContextDestructor(unsigned int index, cleanup *);
00086 
00087     /* Mark the first @count pointer ids (from 0 to @count-1) as allocated, so they don't get
00088      * auto-allocated by setRepeatTimer
00089      * @param count Number of timers to allocate
00090      */
00091     void allocateRepeatTimers(unsigned int count);
00092 
00093     /* Delete a timer. Useful for auto-allocated timers that you don't need any more to 
00094      * reduce memory usage. Does nothing if the timer doesn't exist
00095      * @param index RepeatTimer to wipe
00096      */
00097     void deleteRepeatTimer(unsigned int index);
00098 };
00099 
00100 #endif