4
* 2003-October-9 Jason Rohrer
7
* 2003-October-12 Jason Rohrer
8
* Switched to a floating point limit.
10
* 2004-January-2 Jason Rohrer
11
* Added seprate mutex for transmission function to prevent UI freeze.
16
#ifndef MESSAGE_PER_SECOND_LIMITER_INCLUDED_H
17
#define MESSAGE_PER_SECOND_LIMITER_INCLUDED_H
21
#include "minorGems/system/MutexLock.h"
26
* Class that limits the number of messages transmitted per second.
28
* @author Jason Rohrer
30
class MessagePerSecondLimiter {
39
* Constructs a limiter.
41
* @param inLimitPerSecond the maximum number of messages
42
* transmitted per second, or -1 for no limit.
45
MessagePerSecondLimiter( double inLimitPerSecond = -1 );
49
~MessagePerSecondLimiter();
58
* @param inLimitPerSecond the maximum number of messages
59
* transmitted per second, or -1 for no limit.
61
void setLimit( double inLimitPerSecond );
70
* @return the maximum number of messages
71
* transmitted per second, or -1 if no limit set.
78
* Called by a message transmitter to indicate that a message
79
* is about to be transmitted. Will block if messages
80
* are being transmitted too frequently.
84
void messageTransmitted();
90
MutexLock *mTransmitLock;
92
double mLimitPerSecond;
93
unsigned long mMillisecondsBetweenMessages;
95
unsigned long mSecondTimeOfLastMessage;
96
unsigned long mMillisecondTimeOfLastMessage;