From b5f8d447a0b0e1a747965322ced02433f69ea494 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 9 Nov 2013 12:00:37 -0800 Subject: [PATCH] Tidy up Resource::Manager APIs --- src/ripple/resource/api/Consumer.h | 4 +++- src/ripple/resource/impl/Consumer.cpp | 10 ++++++++-- src/ripple/resource/impl/Entry.h | 8 +++++++- src/ripple/resource/impl/Logic.h | 18 +++++++++--------- src/ripple/resource/impl/Tests.cpp | 4 ++-- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/ripple/resource/api/Consumer.h b/src/ripple/resource/api/Consumer.h index 7fd2717e4..b0e249bba 100644 --- a/src/ripple/resource/api/Consumer.h +++ b/src/ripple/resource/api/Consumer.h @@ -39,7 +39,7 @@ public: Consumer& operator= (Consumer const& other); /** Return a human readable string uniquely identifying this consumer. */ - std::string label (); + std::string to_string () const; /** Returns `true` if this is a privileged endpoint. */ bool admin () const; @@ -77,6 +77,8 @@ private: Entry* m_entry; }; +std::ostream& operator<< (std::ostream& os, Consumer const& v); + } } diff --git a/src/ripple/resource/impl/Consumer.cpp b/src/ripple/resource/impl/Consumer.cpp index 15b9b4acf..62729efea 100644 --- a/src/ripple/resource/impl/Consumer.cpp +++ b/src/ripple/resource/impl/Consumer.cpp @@ -77,12 +77,12 @@ Consumer& Consumer::operator= (Consumer const& other) return *this; } -std::string Consumer::label () +std::string Consumer::to_string () const { if (m_logic == nullptr) return "(none)"; - return m_entry->label(); + return m_entry->to_string(); } bool Consumer::admin () const @@ -125,5 +125,11 @@ Entry& Consumer::entry() return *m_entry; } +std::ostream& operator<< (std::ostream& os, Consumer const& v) +{ + os << v.to_string(); + return os; +} + } } diff --git a/src/ripple/resource/impl/Entry.h b/src/ripple/resource/impl/Entry.h index 09147f526..7167659cf 100644 --- a/src/ripple/resource/impl/Entry.h +++ b/src/ripple/resource/impl/Entry.h @@ -36,7 +36,7 @@ struct Entry : public List ::Node { } - std::string label() const + std::string to_string() const { switch (key->kind) { @@ -91,6 +91,12 @@ struct Entry : public List ::Node DiscreteTime whenExpires; }; +std::ostream& operator<< (std::ostream& os, Entry const& v) +{ + os << v.to_string(); + return os; +} + } } diff --git a/src/ripple/resource/impl/Logic.h b/src/ripple/resource/impl/Logic.h index 5cd8d5db1..6bb0894ad 100644 --- a/src/ripple/resource/impl/Logic.h +++ b/src/ripple/resource/impl/Logic.h @@ -112,7 +112,7 @@ public: } } - m_journal.debug << "New inbound endpoint " << entry->label(); + m_journal.debug << "New inbound endpoint " << entry; return Consumer (*this, *entry); } @@ -144,7 +144,7 @@ public: } } - m_journal.debug << "New outbound endpoint " << entry->label(); + m_journal.debug << "New outbound endpoint " << entry; return Consumer (*this, *entry); } @@ -173,7 +173,7 @@ public: } } - m_journal.debug << "New admin endpoint " << entry->label(); + m_journal.debug << "New admin endpoint " << entry; return Consumer (*this, *entry); } @@ -184,7 +184,7 @@ public: key.kind = kindAdmin; key.name = name; - m_journal.info << "Elevate " << prior.label() << " to " << name; + m_journal.info << "Elevate " << prior << " to " << name; Entry* entry (nullptr); @@ -315,7 +315,7 @@ public: { if (iter->whenExpires <= now) { - m_journal.debug << "Expired " << iter->label(); + m_journal.debug << "Expired " << *iter; Table::iterator table_iter ( state->table.find (*iter->key)); ++iter; @@ -367,7 +367,7 @@ public: { if (--entry.refcount == 0) { - m_journal.debug << "Inactive " << entry.label(); + m_journal.debug << "Inactive " << entry; switch (entry.key->kind) { case kindInbound: @@ -404,7 +404,7 @@ public: { DiscreteTime const now (m_clock()); int const balance (entry.add (fee.cost(), now)); - m_journal.info << "Charging " << entry.label() << " for " << fee; + m_journal.info << "Charging " << entry << " for " << fee; return disposition (balance); } @@ -420,7 +420,7 @@ public: } if (notify) - m_journal.info << "Load warning: " << entry.label(); + m_journal.info << "Load warning: " << entry; return notify; } @@ -499,7 +499,7 @@ public: PropertyStream::Map item (items); if (iter->refcount != 0) item ["count"] = iter->refcount; - item ["name"] = iter->label(); + item ["name"] = iter->to_string(); item ["balance"] = iter->balance(now); if (iter->remote_balance != 0) item ["remote_balance"] = iter->remote_balance; diff --git a/src/ripple/resource/impl/Tests.cpp b/src/ripple/resource/impl/Tests.cpp index 47ac66027..cced99d0a 100644 --- a/src/ripple/resource/impl/Tests.cpp +++ b/src/ripple/resource/impl/Tests.cpp @@ -81,7 +81,7 @@ public: { IPAddress address (IPAddress::from_string ("207.127.82.1")); Consumer c (logic.newInboundEndpoint (address)); - logMessage ("Charging " + c.label() + " 10,000 units"); + logMessage ("Charging " + c.to_string() + " 10,000 units"); c.charge (10000); for (int i = 0; i < 128; ++i) { @@ -95,7 +95,7 @@ public: { IPAddress address (IPAddress::from_string ("207.127.82.2")); Consumer c (logic.newInboundEndpoint (address)); - logMessage ("Charging " + c.label() + " 1000 units per second"); + logMessage ("Charging " + c.to_string() + " 1000 units per second"); for (int i = 0; i < 128; ++i) { c.charge (1000);