F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
TokenBucket.hpp
Go to the documentation of this file.
1
// ======================================================================
2
// \title TokenBucket.hpp
3
// \author vwong
4
// \brief hpp file for a rate limiter utility class
5
//
6
// \copyright
7
//
8
// Copyright (C) 2009-2020 California Institute of Technology.
9
//
10
// ALL RIGHTS RESERVED. United States Government Sponsorship
11
// acknowledged.
12
// ======================================================================
13
14
#ifndef TokenBucket_HPP
15
#define TokenBucket_HPP
16
17
#include <
FpConfig.hpp
>
18
#include <
Fw/Time/Time.hpp
>
19
20
#define MAX_TOKEN_BUCKET_TOKENS 1000
21
22
namespace
Utils
{
23
24
class
TokenBucket
25
{
26
27
public
:
28
29
// Full constructor
30
//
31
// replenishInterval is in microseconds
32
//
33
TokenBucket
(U32 replenishInterval, U32 maxTokens, U32 replenishRate, U32 startTokens,
Fw::Time
startTime);
34
35
// replenishRate=1, startTokens=maxTokens, startTime=0
36
TokenBucket
(U32 replenishInterval, U32 maxTokens);
37
38
public
:
39
40
// Adjust settings at runtime
41
void
setMaxTokens
(U32 maxTokens);
42
void
setReplenishInterval
(U32 replenishInterval);
43
void
setReplenishRate
(U32 replenishRate);
44
45
U32
getMaxTokens
()
const
;
46
U32
getReplenishInterval
()
const
;
47
U32
getReplenishRate
()
const
;
48
U32
getTokens
()
const
;
49
50
// Manual replenish
51
void
replenish
();
52
53
// Main point of entry
54
//
55
// Evaluates time since last trigger to determine number of tokens to
56
// replenish. If time moved backwards, always returns false.
57
//
58
// If number of tokens is not zero, consumes one and returns true.
59
// Otherwise, returns false.
60
//
61
bool
trigger
(
const
Fw::Time
time);
62
63
private
:
64
65
// parameters
66
U32 m_replenishInterval;
67
U32 m_maxTokens;
68
U32 m_replenishRate;
69
70
// state
71
U32 m_tokens;
72
Fw::Time
m_time;
73
};
74
75
}
// end namespace Utils
76
77
#endif
FpConfig.hpp
C++-compatible configuration header for fprime configuration.
Time.hpp
Fw::Time
Definition
Time.hpp:9
Utils::TokenBucket
Definition
TokenBucket.hpp:25
Utils::TokenBucket::setMaxTokens
void setMaxTokens(U32 maxTokens)
Definition
TokenBucket.cpp:57
Utils::TokenBucket::getMaxTokens
U32 getMaxTokens() const
Definition
TokenBucket.cpp:87
Utils::TokenBucket::setReplenishRate
void setReplenishRate(U32 replenishRate)
Definition
TokenBucket.cpp:65
Utils::TokenBucket::getReplenishInterval
U32 getReplenishInterval() const
Definition
TokenBucket.cpp:81
Utils::TokenBucket::replenish
void replenish()
Definition
TokenBucket.cpp:73
Utils::TokenBucket::trigger
bool trigger(const Fw::Time time)
Definition
TokenBucket.cpp:105
Utils::TokenBucket::getTokens
U32 getTokens() const
Definition
TokenBucket.cpp:99
Utils::TokenBucket::getReplenishRate
U32 getReplenishRate() const
Definition
TokenBucket.cpp:93
Utils::TokenBucket::setReplenishInterval
void setReplenishInterval(U32 replenishInterval)
Definition
TokenBucket.cpp:49
Utils
Definition
CRCChecker.cpp:20
Utils
TokenBucket.hpp
Generated by
1.9.8