rippled
Loading...
Searching...
No Matches
Consumer.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_RESOURCE_CONSUMER_H_INCLUDED
21#define RIPPLE_RESOURCE_CONSUMER_H_INCLUDED
22
23#include <xrpl/basics/Log.h>
24#include <xrpl/resource/Charge.h>
25#include <xrpl/resource/Disposition.h>
26
27namespace ripple {
28namespace Resource {
29
30struct Entry;
31class Logic;
32
35{
36private:
37 friend class Logic;
38 Consumer(Logic& logic, Entry& entry);
39
40public:
41 Consumer();
42 ~Consumer();
43 Consumer(Consumer const& other);
45 operator=(Consumer const& other);
46
49 to_string() const;
50
52 bool
53 isUnlimited() const;
54
58 void
59 elevate(std::string const& name);
60
66 disposition() const;
67
70 charge(Charge const& fee, std::string const& context = {});
71
75 bool
76 warn();
77
79 bool
80 disconnect(beast::Journal const& j);
81
83 int
84 balance();
85
86 // Private: Retrieve the entry associated with the consumer
87 Entry&
88 entry();
89
90private:
93};
94
96operator<<(std::ostream& os, Consumer const& v);
97
98} // namespace Resource
99} // namespace ripple
100
101#endif
A generic endpoint for log messages.
Definition: Journal.h:60
A consumption charge.
Definition: Charge.h:31
An endpoint that consumes resources.
Definition: Consumer.h:35
bool warn()
Returns true if the consumer should be warned.
Definition: Consumer.cpp:117
Consumer & operator=(Consumer const &other)
Definition: Consumer.cpp:61
int balance()
Returns the credit balance representing consumption.
Definition: Consumer.cpp:137
std::string to_string() const
Return a human readable string uniquely identifying this consumer.
Definition: Consumer.cpp:78
bool disconnect(beast::Journal const &j)
Returns true if the consumer should be disconnected.
Definition: Consumer.cpp:124
Disposition charge(Charge const &fee, std::string const &context={})
Apply a load charge to the consumer.
Definition: Consumer.cpp:106
bool isUnlimited() const
Returns true if this is a privileged endpoint.
Definition: Consumer.cpp:87
Disposition disposition() const
Returns the current disposition of this consumer.
Definition: Consumer.cpp:96
void elevate(std::string const &name)
Raise the Consumer's privilege level to a Named endpoint.
std::ostream & operator<<(std::ostream &os, Charge const &v)
Definition: Charge.cpp:56
Disposition
The disposition of a consumer after applying a load charge.
Definition: Disposition.h:27
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26