mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 19:45:53 +00:00
Simplify Application shared singleton
This commit is contained in:
@@ -8,7 +8,7 @@ SETUP_LOG (Ledger)
|
|||||||
|
|
||||||
Ledger::Ledger (const RippleAddress& masterID, uint64 startAmount)
|
Ledger::Ledger (const RippleAddress& masterID, uint64 startAmount)
|
||||||
: mTotCoins (startAmount)
|
: mTotCoins (startAmount)
|
||||||
, mLedgerSeq (1)
|
, mLedgerSeq (1) // First Ledger
|
||||||
, mCloseTime (0)
|
, mCloseTime (0)
|
||||||
, mParentCloseTime (0)
|
, mParentCloseTime (0)
|
||||||
, mCloseResolution (LEDGER_TIME_ACCURACY)
|
, mCloseResolution (LEDGER_TIME_ACCURACY)
|
||||||
@@ -194,6 +194,7 @@ void Ledger::updateHash ()
|
|||||||
mAccountHash.zero ();
|
mAccountHash.zero ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VFALCO TODO Fix this hard coded magic number 118
|
||||||
Serializer s (118);
|
Serializer s (118);
|
||||||
s.add32 (HashPrefix::ledgerMaster);
|
s.add32 (HashPrefix::ledgerMaster);
|
||||||
addRaw (s);
|
addRaw (s);
|
||||||
@@ -205,7 +206,8 @@ void Ledger::setRaw (Serializer& s, bool hasPrefix)
|
|||||||
{
|
{
|
||||||
SerializerIterator sit (s);
|
SerializerIterator sit (s);
|
||||||
|
|
||||||
if (hasPrefix) sit.get32 ();
|
if (hasPrefix)
|
||||||
|
sit.get32 ();
|
||||||
|
|
||||||
mLedgerSeq = sit.get32 ();
|
mLedgerSeq = sit.get32 ();
|
||||||
mTotCoins = sit.get64 ();
|
mTotCoins = sit.get64 ();
|
||||||
@@ -597,6 +599,7 @@ void Ledger::saveAcceptedLedger (Job&, bool fromConsensus)
|
|||||||
|
|
||||||
{
|
{
|
||||||
ScopedLock sl (getApp().getLedgerDB ()->getDBLock ());
|
ScopedLock sl (getApp().getLedgerDB ()->getDBLock ());
|
||||||
|
|
||||||
getApp().getLedgerDB ()->getDB ()->executeSQL (boost::str (addLedger %
|
getApp().getLedgerDB ()->getDB ()->executeSQL (boost::str (addLedger %
|
||||||
getHash ().GetHex () % mLedgerSeq % mParentHash.GetHex () %
|
getHash ().GetHex () % mLedgerSeq % mParentHash.GetHex () %
|
||||||
boost::lexical_cast<std::string> (mTotCoins) % mCloseTime % mParentCloseTime %
|
boost::lexical_cast<std::string> (mTotCoins) % mCloseTime % mParentCloseTime %
|
||||||
@@ -1488,7 +1491,10 @@ uint256 Ledger::getLedgerHash (uint32 ledgerIndex)
|
|||||||
WriteLog (lsWARNING, Ledger) << "Ledger " << mLedgerSeq << " missing hash for " << ledgerIndex
|
WriteLog (lsWARNING, Ledger) << "Ledger " << mLedgerSeq << " missing hash for " << ledgerIndex
|
||||||
<< " (" << vec.size () << "," << diff << ")";
|
<< " (" << vec.size () << "," << diff << ")";
|
||||||
}
|
}
|
||||||
else WriteLog (lsWARNING, Ledger) << "Ledger " << mLedgerSeq << ":" << getHash () << " missing normal list";
|
else
|
||||||
|
{
|
||||||
|
WriteLog (lsWARNING, Ledger) << "Ledger " << mLedgerSeq << ":" << getHash () << " missing normal list";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ledgerIndex & 0xff) != 0)
|
if ((ledgerIndex & 0xff) != 0)
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ public:
|
|||||||
uint32 ledgerSeq, bool & loaded); // used for database ledgers
|
uint32 ledgerSeq, bool & loaded); // used for database ledgers
|
||||||
|
|
||||||
Ledger (Blob const & rawLedger, bool hasPrefix);
|
Ledger (Blob const & rawLedger, bool hasPrefix);
|
||||||
|
|
||||||
Ledger (const std::string & rawLedger, bool hasPrefix);
|
Ledger (const std::string & rawLedger, bool hasPrefix);
|
||||||
|
|
||||||
Ledger (bool dummy, Ledger & previous); // ledger after this one
|
Ledger (bool dummy, Ledger & previous); // ledger after this one
|
||||||
@@ -232,6 +233,9 @@ public:
|
|||||||
// next/prev function
|
// next/prev function
|
||||||
SLE::pointer getSLE (uint256 const & uHash); // SLE is mutable
|
SLE::pointer getSLE (uint256 const & uHash); // SLE is mutable
|
||||||
SLE::pointer getSLEi (uint256 const & uHash); // SLE is immutable
|
SLE::pointer getSLEi (uint256 const & uHash); // SLE is immutable
|
||||||
|
|
||||||
|
// VFALCO NOTE These seem to let you walk the list of ledgers
|
||||||
|
//
|
||||||
uint256 getFirstLedgerIndex ();
|
uint256 getFirstLedgerIndex ();
|
||||||
uint256 getLastLedgerIndex ();
|
uint256 getLastLedgerIndex ();
|
||||||
uint256 getNextLedgerIndex (uint256 const & uHash); // first node >hash
|
uint256 getNextLedgerIndex (uint256 const & uHash); // first node >hash
|
||||||
|
|||||||
@@ -14,9 +14,15 @@ SETUP_LOG (Application)
|
|||||||
// VFALCO TODO Move the function definitions into the class declaration
|
// VFALCO TODO Move the function definitions into the class declaration
|
||||||
class Application
|
class Application
|
||||||
: public IApplication
|
: public IApplication
|
||||||
|
, public SharedSingleton <Application>
|
||||||
, LeakChecked <Application>
|
, LeakChecked <Application>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static Application* createInstance ()
|
||||||
|
{
|
||||||
|
return new Application;
|
||||||
|
}
|
||||||
|
|
||||||
class Holder;
|
class Holder;
|
||||||
|
|
||||||
Application ();
|
Application ();
|
||||||
@@ -260,7 +266,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Application::Application ()
|
Application::Application ()
|
||||||
: mIOService ((theConfig.NODE_SIZE >= 2) ? 2 : 1)
|
: SharedSingleton <Application> (SingletonLifetime::persistAfterCreation)
|
||||||
|
, mIOService ((theConfig.NODE_SIZE >= 2) ? 2 : 1)
|
||||||
, mIOWork (mIOService)
|
, mIOWork (mIOService)
|
||||||
, mAuxWork (mAuxService)
|
, mAuxWork (mAuxService)
|
||||||
, mNetOps (mIOService, &mLedgerMaster)
|
, mNetOps (mIOService, &mLedgerMaster)
|
||||||
@@ -995,37 +1002,7 @@ void Application::updateTables (bool ldbImport)
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Since its an global with static storage duration
|
|
||||||
// it has to be wrapped in a SharedSingleton.
|
|
||||||
//
|
|
||||||
class Application::Holder : public SharedSingleton <Application::Holder>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Holder ()
|
|
||||||
: SharedSingleton <Holder> (SingletonLifetime::persistAfterCreation)
|
|
||||||
, m_application (new Application)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~Holder ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static Holder* createInstance ()
|
|
||||||
{
|
|
||||||
return new Holder;
|
|
||||||
}
|
|
||||||
|
|
||||||
IApplication& getApp ()
|
|
||||||
{
|
|
||||||
return *m_application;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
ScopedPointer <IApplication> m_application;
|
|
||||||
};
|
|
||||||
|
|
||||||
IApplication& getApp ()
|
IApplication& getApp ()
|
||||||
{
|
{
|
||||||
return Application::Holder::getInstance ()->getApp ();
|
return *Application::getInstance ();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user