rippled
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 <ripple/basics/Log.h>
24 #include <ripple/resource/Charge.h>
25 #include <ripple/resource/Disposition.h>
26 
27 namespace ripple {
28 namespace Resource {
29 
30 struct Entry;
31 class Logic;
32 
34 class Consumer
35 {
36 private:
37  friend class Logic;
38  Consumer(Logic& logic, Entry& entry);
39 
40 public:
41  Consumer();
42  ~Consumer();
43  Consumer(Consumer const& other);
44  Consumer&
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);
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 
90 private:
93 };
94 
96 operator<<(std::ostream& os, Consumer const& v);
97 
98 } // namespace Resource
99 } // namespace ripple
100 
101 #endif
ripple::Resource::Consumer::warn
bool warn()
Returns true if the consumer should be warned.
Definition: Consumer.cpp:110
std::string
STL class.
ripple::Resource::Consumer::disconnect
bool disconnect(beast::Journal const &j)
Returns true if the consumer should be disconnected.
Definition: Consumer.cpp:117
ripple::Resource::Consumer::entry
Entry & entry()
Definition: Consumer.cpp:136
ripple::Resource::Consumer::elevate
void elevate(std::string const &name)
Raise the Consumer's privilege level to a Named endpoint.
ripple::Resource::Logic
Definition: resource/impl/Logic.h:40
ripple::Resource::Consumer::disposition
Disposition disposition() const
Returns the current disposition of this consumer.
Definition: Consumer.cpp:89
ripple::Resource::operator<<
std::ostream & operator<<(std::ostream &os, Charge const &v)
Definition: Charge.cpp:52
ripple::Resource::Consumer::to_string
std::string to_string() const
Return a human readable string uniquely identifying this consumer.
Definition: Consumer.cpp:71
std::ostream
STL class.
ripple::Resource::Consumer::balance
int balance()
Returns the credit balance representing consumption.
Definition: Consumer.cpp:129
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::Resource::Consumer::m_entry
Entry * m_entry
Definition: Consumer.h:92
ripple::Resource::Entry
Definition: Entry.h:37
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition: Consumer.h:34
ripple::Resource::Charge
A consumption charge.
Definition: Charge.h:30
ripple::Resource::Consumer::isUnlimited
bool isUnlimited() const
Returns true if this is a privileged endpoint.
Definition: Consumer.cpp:80
ripple::Resource::Consumer::operator=
Consumer & operator=(Consumer const &other)
Definition: Consumer.cpp:54
ripple::Resource::Disposition
Disposition
The disposition of a consumer after applying a load charge.
Definition: Disposition.h:27
ripple::Resource::Consumer::charge
Disposition charge(Charge const &fee)
Apply a load charge to the consumer.
Definition: Consumer.cpp:99
ripple::Resource::Consumer::m_logic
Logic * m_logic
Definition: Consumer.h:91
ripple::Resource::Consumer::Consumer
Consumer()
Definition: Consumer.cpp:33
ripple::Resource::Consumer::~Consumer
~Consumer()
Definition: Consumer.cpp:47