Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 #include <ola/base/Macro.h>
26 
27 namespace ola {
28 
29 class TokenBucket {
30  public:
31  TokenBucket(unsigned int initial,
32  unsigned int rate_per_second,
33  unsigned int max,
34  const TimeStamp &now):
35  m_count(initial),
36  m_rate(rate_per_second),
37  m_max(max),
38  m_last(now) {
39  }
40 
41  bool GetToken(const TimeStamp &now);
42  unsigned int Count(const TimeStamp &now);
43 
44  private:
45  unsigned int m_count;
46  unsigned int m_rate;
47  unsigned int m_max;
48  TimeStamp m_last;
49 
50  DISALLOW_COPY_AND_ASSIGN(TokenBucket);
51 };
52 } // namespace ola
53 #endif // INCLUDE_OLAD_TOKENBUCKET_H_
Definition: TokenBucket.h:29
Helper macros.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: Clock.h:171