rippled
Loading...
Searching...
No Matches
InfoSub.cpp
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#include <xrpld/rpc/InfoSub.h>
21
22namespace ripple {
23
24// This is the primary interface into the "client" portion of the program.
25// Code that wants to do normal operations on the network such as
26// creating and monitoring accounts, creating transactions, and so on
27// should use this interface. The RPC code will primarily be a light wrapper
28// over this code.
29
30// Eventually, it will check the node's operating mode (synched, unsynched,
31// etectera) and defer to the correct means of processing. The current
32// code assumes this node is synched (and will continue to do so until
33// there's a functional network.
34
35InfoSub::InfoSub(Source& source) : m_source(source), mSeq(assign_id())
36{
37}
38
40 : m_consumer(consumer), m_source(source), mSeq(assign_id())
41{
42}
43
45{
54
55 // Use the internal unsubscribe so that it won't call
56 // back to us and modify its own parameter
57 if (!realTimeSubscriptions_.empty())
59
60 if (!normalSubscriptions_.empty())
62
63 for (auto const& account : accountHistorySubscriptions_)
65}
66
69{
70 return m_consumer;
71}
72
75{
76 return mSeq;
77}
78
79void
83
84void
86{
88
89 if (rt)
90 realTimeSubscriptions_.insert(account);
91 else
92 normalSubscriptions_.insert(account);
93}
94
95void
97{
99
100 if (rt)
101 realTimeSubscriptions_.erase(account);
102 else
103 normalSubscriptions_.erase(account);
104}
105
106bool
108{
110 return accountHistorySubscriptions_.insert(account).second;
111}
112
113void
119
120void
122{
123 request_.reset();
124}
125
126void
131
134{
135 return request_;
136}
137
138void
139InfoSub::setApiVersion(unsigned int apiVersion)
140{
141 apiVersion_ = apiVersion;
142}
143
144unsigned int
146{
147 XRPL_ASSERT(
148 apiVersion_ > 0, "ripple::InfoSub::getApiVersion : valid API version");
149 return apiVersion_;
150}
151
152} // namespace ripple
Abstracts the source of subscription data.
Definition InfoSub.h:68
virtual bool unsubValidations(std::uint64_t uListener)=0
virtual bool unsubServer(std::uint64_t uListener)=0
virtual bool unsubPeerStatus(std::uint64_t uListener)=0
virtual bool unsubConsensus(std::uint64_t uListener)=0
virtual void unsubAccountInternal(std::uint64_t uListener, hash_set< AccountID > const &vnaAccountIDs, bool realTime)=0
virtual bool unsubLedger(std::uint64_t uListener)=0
virtual bool unsubTransactions(std::uint64_t uListener)=0
virtual bool unsubManifests(std::uint64_t uListener)=0
virtual void unsubAccountHistoryInternal(std::uint64_t uListener, AccountID const &account, bool historyOnly)=0
virtual bool unsubRTTransactions(std::uint64_t uListener)=0
std::uint64_t getSeq()
Definition InfoSub.cpp:74
Source & m_source
Definition InfoSub.h:243
std::mutex mLock
Definition InfoSub.h:239
std::shared_ptr< InfoSubRequest > const & getRequest()
Definition InfoSub.cpp:133
hash_set< AccountID > realTimeSubscriptions_
Definition InfoSub.h:244
unsigned int getApiVersion() const noexcept
Definition InfoSub.cpp:145
Consumer m_consumer
Definition InfoSub.h:242
bool insertSubAccountHistory(AccountID const &account)
Definition InfoSub.cpp:107
hash_set< AccountID > normalSubscriptions_
Definition InfoSub.h:245
void deleteSubAccountInfo(AccountID const &account, bool rt)
Definition InfoSub.cpp:96
hash_set< AccountID > accountHistorySubscriptions_
Definition InfoSub.h:248
void setApiVersion(unsigned int apiVersion)
Definition InfoSub.cpp:139
InfoSub(Source &source)
Definition InfoSub.cpp:35
void onSendEmpty()
Definition InfoSub.cpp:80
void insertSubAccountInfo(AccountID const &account, bool rt)
Definition InfoSub.cpp:85
void deleteSubAccountHistory(AccountID const &account)
Definition InfoSub.cpp:114
std::uint64_t mSeq
Definition InfoSub.h:247
void clearRequest()
Definition InfoSub.cpp:121
unsigned int apiVersion_
Definition InfoSub.h:249
std::shared_ptr< InfoSubRequest > request_
Definition InfoSub.h:246
virtual ~InfoSub()
Definition InfoSub.cpp:44
void setRequest(std::shared_ptr< InfoSubRequest > const &req)
Definition InfoSub.cpp:127
Consumer & getConsumer()
Definition InfoSub.cpp:68
An endpoint that consumes resources.
Definition Consumer.h:35
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25