Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TokenBucket.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * TokenBucket.h
17  * Header file for the token bucket class
18  * Copyright (C) 2010 Simon Newton
19  */
20 
21 #ifndef INCLUDE_OLAD_TOKENBUCKET_H_
22 #define INCLUDE_OLAD_TOKENBUCKET_H_
23 
24 #include <ola/Clock.h>
25 
26 namespace ola {
27 
28 class TokenBucket {
29  public:
30  TokenBucket(unsigned int initial,
31  unsigned int rate_per_second,
32  unsigned int max,
33  const TimeStamp &now):
34  m_count(initial),
35  m_rate(rate_per_second),
36  m_max(max),
37  m_last(now) {
38  }
39 
40  bool GetToken(const TimeStamp &now);
41  unsigned int Count(const TimeStamp &now);
42 
43  private:
44  unsigned int m_count;
45  unsigned int m_rate;
46  unsigned int m_max;
47  TimeStamp m_last;
48 
49  TokenBucket(const TokenBucket&);
50  TokenBucket& operator=(const TokenBucket&);
51 };
52 } // namespace ola
53 #endif // INCLUDE_OLAD_TOKENBUCKET_H_