Add PropertyStream

This commit is contained in:
Vinnie Falco
2013-10-06 11:07:25 -07:00
parent b9e0208aee
commit 1ae3328642
24 changed files with 839 additions and 157 deletions

View File

@@ -406,72 +406,6 @@ public:
return n;
}
//----------------------------------------------------------------------
//
// RPC Handlers
//
// Return the current ChosenList as JSON
Json::Value rpcPrint (Json::Value const& args, int cpuPercent)
{
Json::Value results (Json::objectValue);
Json::Value entries (Json::arrayValue);
{
results ["cpu"] = cpuPercent;
results ["count"] = int(m_validators.size());
for (ValidatorTable::const_iterator iter (m_validators.begin());
iter != m_validators.end(); ++iter)
{
Validator const& v (iter->second);
Json::Value entry (Json::objectValue);
Count const count (v.count ());
entry ["public"] = iter->first.to_string();
entry ["received"] = int(count.received);
entry ["expected"] = int(count.expected);
entry ["closed"] = int(count.closed);
entry ["percent"] = count.percent();
entries.append (entry);
}
}
results ["validators"] = entries;
return results;
}
// Returns the list of sources
Json::Value rpcSources (Json::Value const& arg)
{
Json::Value results (Json::objectValue);
Json::Value entries (Json::arrayValue);
for (SourceTable::const_iterator iter (m_sources.begin());
iter != m_sources.end(); ++iter)
{
Json::Value entry (Json::objectValue);
SourceDesc const& desc (*iter);
entry ["name"] = desc.source->name();
entry ["param"] = desc.source->createParam();
Json::Value results (Json::arrayValue);
for (int i = 0; i < desc.results.list.size(); ++i)
{
Json::Value info (Json::objectValue);
info ["key"] = "publicKey";
info ["label"] = desc.results.list[i].label;
results.append (info);
}
entry ["results"] = results;
entries.append (entry);
}
results ["sources"] = entries;
return results;
}
//----------------------------------------------------------------------
//
// Ripple interface

View File

@@ -167,42 +167,6 @@ public:
stopThread ();
}
//--------------------------------------------------------------------------
//
// RPC::Service
//
Json::Value rpcPrint (Json::Value const& args)
{
int const cpuPercent (std::ceil (m_queue.getUtilizaton() * 100));
return m_logic.rpcPrint (args, cpuPercent);
}
Json::Value rpcRebuild (Json::Value const& args)
{
m_queue.dispatch (bind (&Logic::buildChosen, &m_logic));
Json::Value result;
result ["chosen_list"] = "rebuilding";
return result;
}
Json::Value rpcSources (Json::Value const& args)
{
return m_logic.rpcSources(args);
}
void addRPCHandlers()
{
addRPCHandler ("validators_print", beast::bind (
&ManagerImp::rpcPrint, this, beast::_1));
addRPCHandler ("validators_rebuild", beast::bind (
&ManagerImp::rpcRebuild, this, beast::_1));
addRPCHandler ("validators_sources", beast::bind (
&ManagerImp::rpcSources, this, beast::_1));
}
//--------------------------------------------------------------------------
//
// Manager
@@ -234,7 +198,7 @@ public:
addStaticSource (SourceFile::New (file));
}
void addStaticSource (Source* source)
void addStaticSource (Validators::Source* source)
{
#if RIPPLE_USE_VALIDATORS
m_queue.dispatch (bind (&Logic::addStatic, &m_logic, source));
@@ -248,7 +212,7 @@ public:
addSource (SourceURL::New (url));
}
void addSource (Source* source)
void addSource (Validators::Source* source)
{
#if RIPPLE_USE_VALIDATORS
m_queue.dispatch (bind (&Logic::add, &m_logic, source));
@@ -286,8 +250,6 @@ public:
{
#if RIPPLE_USE_VALIDATORS
m_journal.info << "Validators preparing";
addRPCHandlers();
#endif
}
@@ -402,6 +364,11 @@ public:
//------------------------------------------------------------------------------
Manager::Manager ()
: PropertyStream::Source ("validators")
{
}
Validators::Manager* Validators::Manager::New (Stoppable& parent, Journal journal)
{
return new Validators::ManagerImp (parent, journal);