Replace InstanceCounter with CountedObject

This commit is contained in:
Vinnie Falco
2013-06-17 17:45:33 -07:00
parent abce930b8b
commit 2abec05b5b
53 changed files with 321 additions and 334 deletions

View File

@@ -6,8 +6,6 @@
SETUP_LOG (Ledger)
DECLARE_INSTANCE (Ledger);
Ledger::Ledger (const RippleAddress& masterID, uint64 startAmount)
: mTotCoins (startAmount)
, mLedgerSeq (1)

View File

@@ -29,8 +29,6 @@ enum LedgerStateParms
#define LEDGER_JSON_EXPAND 0x40000000
#define LEDGER_JSON_FULL 0x80000000
DEFINE_INSTANCE (Ledger);
class SqliteStatement;
// VFALCO TODO figure out exactly how this thing works.
@@ -38,12 +36,10 @@ class SqliteStatement;
// class. But then what is the meaning of a Ledger object? Is this
// really two classes in one? StoreOfAllLedgers + SingleLedgerObject?
//
class Ledger : public boost::enable_shared_from_this<Ledger>, public IS_INSTANCE (Ledger)
class Ledger
: public boost::enable_shared_from_this <Ledger>
, public CountedObject <Ledger>
{
// The basic Ledger structure, can be opened, closed, or synching
// VFALCO TODO eliminate the need for friends
friend class TransactionEngine;
friend class Transactor;
public:
typedef boost::shared_ptr<Ledger> pointer;
typedef const boost::shared_ptr<Ledger>& ref;
@@ -428,6 +424,11 @@ protected:
void updateFees ();
private:
// The basic Ledger structure, can be opened, closed, or synching
// VFALCO TODO eliminate the need for friends
friend class TransactionEngine;
friend class Transactor;
void initializeFees ();
private:

View File

@@ -4,8 +4,6 @@
*/
//==============================================================================
DECLARE_INSTANCE (LedgerProposal);
LedgerProposal::LedgerProposal (uint256 const& pLgr, uint32 seq, uint256 const& tx, uint32 closeTime,
const RippleAddress& naPeerPublic, uint256 const& suppression) :
mPreviousLedger (pLgr), mCurrentHash (tx), mSuppression (suppression), mCloseTime (closeTime),

View File

@@ -7,9 +7,8 @@
#ifndef __PROPOSELEDGER__
#define __PROPOSELEDGER__
DEFINE_INSTANCE (LedgerProposal);
class LedgerProposal : private IS_INSTANCE (LedgerProposal)
class LedgerProposal
: public CountedObject <LedgerProposal>
{
public:
static const uint32 seqLeave = 0xffffffff; // leaving the consensus process

View File

@@ -2401,12 +2401,14 @@ Json::Value RPCHandler::doGetCounts (Json::Value jvRequest, int& cost, ScopedLoc
if (jvRequest.isMember ("min_count"))
minCount = jvRequest["min_count"].asUInt ();
std::vector<InstanceType::InstanceCount> count = InstanceType::getInstanceCounts (minCount);
CountedObjects::List objectCounts = CountedObjects::getInstance ().getCounts (minCount);
Json::Value ret (Json::objectValue);
BOOST_FOREACH (InstanceType::InstanceCount & it, count)
ret[it.first] = it.second;
BOOST_FOREACH (CountedObjects::Entry& it, objectCounts)
{
ret [it.first] = it.second;
}
int dbKB = theApp->getLedgerDB ()->getDB ()->getKBUsedAll ();

View File

@@ -4,9 +4,6 @@
*/
//==============================================================================
DECLARE_INSTANCE (SerializedValidation);
SerializedValidation::SerializedValidation (SerializerIterator& sit, bool checkSignature)
: STObject (getFormat (), sit, sfValidation)
, mTrusted (false)

View File

@@ -7,11 +7,9 @@
#ifndef RIPPLE_SERIALIZEDVALIDATION_H
#define RIPPLE_SERIALIZEDVALIDATION_H
DEFINE_INSTANCE (SerializedValidation);
class SerializedValidation
: public STObject
, private IS_INSTANCE (SerializedValidation)
, public CountedObject <SerializedValidation>
{
public:
typedef boost::shared_ptr<SerializedValidation> pointer;

View File

@@ -4,9 +4,6 @@
*/
//==============================================================================
DECLARE_INSTANCE (Transaction);
Transaction::Transaction (SerializedTransaction::ref sit, bool bValidate)
: mInLedger (0), mStatus (INVALID), mResult (temUNCERTAIN), mTransaction (sit)
{

View File

@@ -26,10 +26,10 @@ enum TransStatus
INCOMPLETE = 8 // needs more signatures
};
DEFINE_INSTANCE (Transaction);
// This class is for constructing and examining transactions. Transactions are static so manipulation functions are unnecessary.
class Transaction : public boost::enable_shared_from_this<Transaction>, private IS_INSTANCE (Transaction)
class Transaction
: public boost::enable_shared_from_this<Transaction>
, public CountedObject <Transaction>
{
public:
typedef boost::shared_ptr<Transaction> pointer;

View File

@@ -10,9 +10,6 @@
SETUP_LOG (TransactionEngine)
DECLARE_INSTANCE (TransactionEngine);
void TransactionEngine::txnWrite ()
{
// Write back the account states

View File

@@ -7,14 +7,13 @@
#ifndef __TRANSACTIONENGINE__
#define __TRANSACTIONENGINE__
DEFINE_INSTANCE (TransactionEngine);
// A TransactionEngine applies serialized transactions to a ledger
// It can also, verify signatures, verify fees, and give rejection reasons
// One instance per ledger.
// Only one transaction applied at a time.
class TransactionEngine : private IS_INSTANCE (TransactionEngine)
class TransactionEngine
: public CountedObject <TransactionEngine>
{
private:
LedgerEntrySet mNodes;

View File

@@ -11,8 +11,6 @@
#include "../websocketpp/src/sockets/autotls.hpp"
#include "../websocketpp/src/websocketpp.hpp"
DEFINE_INSTANCE (WebSocketConnection);
// This is for logging
struct WSConnectionLog;
@@ -23,8 +21,10 @@ class WSServerHandler;
// - Subscriptions
//
template <typename endpoint_type>
class WSConnection : public InfoSub, public IS_INSTANCE (WebSocketConnection),
public boost::enable_shared_from_this< WSConnection<endpoint_type> >
class WSConnection
: public InfoSub
, public boost::enable_shared_from_this< WSConnection<endpoint_type> >
, public CountedObject <WSConnection <endpoint_type> >
{
public:
typedef typename endpoint_type::connection_type connection;

View File

@@ -24,8 +24,6 @@
SETUP_LOG (WSDoor)
DECLARE_INSTANCE (WebSocketConnection);
//
// This is a light weight, untrusted interface for web clients.
// For now we don't provide proof. Later we will.

View File

@@ -208,8 +208,6 @@ int main (int argc, char* argv[])
else
Log::setMinSeverity (lsINFO, true);
InstanceType::multiThread ();
// VFALCO TODO make these singletons that initialize statically
TFInit ();
LEFInit ();
@@ -218,7 +216,6 @@ int main (int argc, char* argv[])
{
unit_test_main (init_unit_test, argc, argv);
InstanceType::shutdown ();
return 0;
}
@@ -267,7 +264,6 @@ int main (int argc, char* argv[])
setupServer ();
setCallingThreadName ("io");
startServer ();
InstanceType::shutdown ();
}
else
{
@@ -281,7 +277,6 @@ int main (int argc, char* argv[])
if (1 == iResult && !vm.count ("quiet"))
printHelp (desc);
InstanceType::shutdown ();
return iResult;
}
// vim:ts=4

View File

@@ -304,7 +304,6 @@ extern const char* RpcDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[],
*NetNodeDBInit[], *PathFindDBInit[];
extern int RpcDBCount, TxnDBCount, LedgerDBCount, WalletDBCount, HashNodeDBCount,
NetNodeDBCount, PathFindDBCount;
bool Instance::running = true;
void Application::stop ()
{
@@ -324,7 +323,6 @@ void Application::stop ()
mEphemeralLDB = NULL;
WriteLog (lsINFO, Application) << "Stopped: " << mIOService.stopped ();
Instance::shutdown ();
}
static void InitDB (DatabaseCon** dbCon, const char* fileName, const char* dbInit[], int dbCount)

View File

@@ -4,8 +4,6 @@
*/
//==============================================================================
DECLARE_INSTANCE (HashRouterEntry);
// VFALCO TODO Inline the function definitions
class HashRouter : public IHashRouter
{

View File

@@ -6,8 +6,6 @@
SETUP_LOG (HashedObject)
DECLARE_INSTANCE (HashedObject);
HashedObject::HashedObject (
HashedObjectType type,
LedgerIndex ledgerIndex,

View File

@@ -18,8 +18,6 @@ enum HashedObjectType
hotTRANSACTION_NODE = 4
};
DEFINE_INSTANCE (HashedObject);
/** A blob of data with associated metadata, referenced by hash.
The metadata includes the following:
@@ -34,7 +32,8 @@ DEFINE_INSTANCE (HashedObject);
// VFALCO TODO consider making the instance a private member of SHAMap
// since its the primary user.
//
class HashedObject : private IS_INSTANCE (HashedObject)
class HashedObject
: public CountedObject <HashedObject>
{
public:
typedef boost::shared_ptr <HashedObject> pointer;

View File

@@ -7,8 +7,6 @@
#ifndef RIPPLE_HASHROUTER_H
#define RIPPLE_HASHROUTER_H
DEFINE_INSTANCE (HashRouterEntry);
// VFALCO TODO convert these macros to int constants
#define SF_RELAYED 0x01 // Has already been relayed to other nodes
#define SF_BAD 0x02 // Signature/format is bad
@@ -18,7 +16,8 @@ DEFINE_INSTANCE (HashRouterEntry);
#define SF_TRUSTED 0x20 // comes from trusted source
// VFALCO TODO move this class into the scope of class HashRouter
class HashRouterEntry : private IS_INSTANCE (HashRouterEntry)
class HashRouterEntry
: public CountedObject <HashRouterEntry>
{
public:
HashRouterEntry () : mFlags (0)

View File

@@ -6,8 +6,6 @@
SETUP_LOG (InboundLedger)
DECLARE_INSTANCE (InboundLedger);
// VFALCO TODO replace macros
#define LA_DEBUG
#define LEDGER_ACQUIRE_TIMEOUT 2000 // millisecond for each ledger timeout

View File

@@ -7,13 +7,12 @@
#ifndef RIPPLE_INBOUNDLEDGER_H
#define RIPPLE_INBOUNDLEDGER_H
DEFINE_INSTANCE (InboundLedger);
// VFALCO TODO Rename to InboundLedger
// A ledger we are trying to acquire
class InboundLedger : private IS_INSTANCE (InboundLedger)
, public PeerSet
class InboundLedger
: public PeerSet
, public boost::enable_shared_from_this <InboundLedger>
, public CountedObject <InboundLedger>
{
public:
typedef boost::shared_ptr <InboundLedger> pointer;

View File

@@ -15,8 +15,6 @@
// code assumes this node is synched (and will continue to do so until
// there's a functional network.
DECLARE_INSTANCE (InfoSub);
// VFALCO TODO Figure out how to clean up these globals
uint64 InfoSub::sSeq = 0;
boost::mutex InfoSub::sSeqLock;

View File

@@ -12,9 +12,8 @@
class PathRequest;
DEFINE_INSTANCE (InfoSub);
class InfoSub : public IS_INSTANCE (InfoSub)
class InfoSub
: public CountedObject <InfoSub>
{
public:
typedef boost::shared_ptr<InfoSub> pointer;

View File

@@ -10,8 +10,6 @@
SETUP_LOG (LedgerConsensus)
DECLARE_INSTANCE (LedgerConsensus);
LedgerConsensus::LedgerConsensus (uint256 const& prevLCLHash, Ledger::ref previousLedger, uint32 closeTime)
: mState (lcsPRE_CLOSE), mCloseTime (closeTime), mPrevLedgerHash (prevLCLHash), mPreviousLedger (previousLedger),
mValPublic (theConfig.VALIDATION_PUB), mValPrivate (theConfig.VALIDATION_PRIV), mConsensusFail (false),

View File

@@ -7,14 +7,14 @@
#ifndef RIPPLE_LEDGERCONSENSUS_H
#define RIPPLE_LEDGERCONSENSUS_H
DEFINE_INSTANCE (LedgerConsensus);
/** Manager for achieving consensus on the next ledger.
This object is created when the consensus process starts, and
is destroyed when the process is complete.
*/
class LedgerConsensus : public boost::enable_shared_from_this<LedgerConsensus>, IS_INSTANCE (LedgerConsensus)
class LedgerConsensus
: public boost::enable_shared_from_this <LedgerConsensus>
, public CountedObject <LedgerConsensus>
{
public:
LedgerConsensus (LedgerHash const & prevLCLHash, Ledger::ref previousLedger, uint32 closeTime);

View File

@@ -6,9 +6,6 @@
SETUP_LOG (LedgerEntrySet)
DECLARE_INSTANCE (LedgerEntrySetEntry);
DECLARE_INSTANCE (LedgerEntrySet)
// #define META_DEBUG
// VFALCO TODO Replace this macro with a documented language constant

View File

@@ -7,9 +7,6 @@
#ifndef RIPPLE_LEDGERENTRYSET_H
#define RIPPLE_LEDGERENTRYSET_H
DEFINE_INSTANCE (LedgerEntrySetEntry);
DEFINE_INSTANCE (LedgerEntrySet);
enum TransactionEngineParams
{
tapNONE = 0x00,
@@ -35,7 +32,8 @@ enum LedgerEntryAction
taaCREATE, // Newly created.
};
class LedgerEntrySetEntry : private IS_INSTANCE (LedgerEntrySetEntry)
class LedgerEntrySetEntry
: public CountedObject <LedgerEntrySetEntry>
{
public:
SLE::pointer mEntry;
@@ -58,7 +56,8 @@ public:
transaction finishes, the LES is committed into the ledger to make
the modifications. The transaction metadata is built from the LES too.
*/
class LedgerEntrySet : private IS_INSTANCE (LedgerEntrySet)
class LedgerEntrySet
: public CountedObject <LedgerEntrySet>
{
public:
LedgerEntrySet (Ledger::ref ledger, TransactionEngineParams tep, bool immutable = false) :

View File

@@ -11,10 +11,6 @@ SETUP_LOG (Peer)
class PeerImp;
DEFINE_INSTANCE (PeerImp);
DECLARE_INSTANCE (PeerImp);
// Don't try to run past receiving nonsense from a peer
#define TRUST_NETWORK
@@ -25,7 +21,7 @@ DECLARE_INSTANCE (PeerImp);
#define NODE_IDLE_SECONDS 120
class PeerImp : public Peer
, public IS_INSTANCE (PeerImp)
, public CountedObject <PeerImp>
{
public:
PeerImp (boost::asio::io_service & io_service,

View File

@@ -10,8 +10,6 @@
SETUP_LOG (SHAMap)
DECLARE_INSTANCE (SHAMap);
void SHAMapNode::setMHash () const
{
using namespace std;

View File

@@ -7,8 +7,6 @@
#ifndef RIPPLE_SHAMAP_H
#define RIPPLE_SHAMAP_H
DEFINE_INSTANCE (SHAMap);
enum SHAMapState
{
smsModifying = 0, // Objects can be added and removed (like an open ledger)
@@ -18,7 +16,8 @@ enum SHAMapState
smsInvalid = 4, // Map is known not to be valid (usually synching a corrupt ledger)
};
class SHAMap : public IS_INSTANCE (SHAMap)
class SHAMap
: public CountedObject <SHAMap>
{
public:
typedef boost::shared_ptr<SHAMap> pointer;

View File

@@ -6,8 +6,6 @@
class SHAMap;
DECLARE_INSTANCE (SHAMapItem);
SHAMapItem::SHAMapItem (uint256 const& tag, Blob const& data)
: mTag (tag)
, mData (data)

View File

@@ -7,10 +7,9 @@
#ifndef RIPPLE_SHAMAPITEM_H
#define RIPPLE_SHAMAPITEM_H
DEFINE_INSTANCE (SHAMapItem);
// an item stored in a SHAMap
class SHAMapItem : public IS_INSTANCE (SHAMapItem)
class SHAMapItem
: public CountedObject <SHAMapItem>
{
public:
typedef boost::shared_ptr<SHAMapItem> pointer;

View File

@@ -4,8 +4,6 @@
*/
//==============================================================================
DECLARE_INSTANCE (SHAMapTreeNode);
SHAMapTreeNode::SHAMapTreeNode (uint32 seq, const SHAMapNode& nodeID) : SHAMapNode (nodeID), mHash (0),
mSeq (seq), mAccessSeq (seq), mType (tnERROR), mIsBranch (0), mFullBelow (false)
{

View File

@@ -7,8 +7,6 @@
#ifndef RIPPLE_SHAMAPTREENODE_H
#define RIPPLE_SHAMAPTREENODE_H
DEFINE_INSTANCE (SHAMapTreeNode);
class SHAMap;
enum SHANodeFormat
@@ -18,7 +16,9 @@ enum SHANodeFormat
snfHASH = 3, // just the hash
};
class SHAMapTreeNode : public SHAMapNode, public IS_INSTANCE (SHAMapTreeNode)
class SHAMapTreeNode
: public SHAMapNode
, public CountedObject <SHAMapTreeNode>
{
public:
typedef boost::shared_ptr<SHAMapTreeNode> pointer;

View File

@@ -4,8 +4,6 @@
*/
//==============================================================================
DECLARE_INSTANCE (SerializedLedgerEntry)
// For logging
struct SerializedLedgerLog;

View File

@@ -7,8 +7,6 @@
#ifndef RIPPLE_SERIALIZEDLEDGER_H
#define RIPPLE_SERIALIZEDLEDGER_H
DEFINE_INSTANCE (SerializedLedgerEntry);
// VFALCO NOTE
//
// This looks like a central class for Ripple. Almost everything that
@@ -24,7 +22,9 @@ DEFINE_INSTANCE (SerializedLedgerEntry);
//
// Can we just call this LedgerEntry?
//
class SerializedLedgerEntry : public STObject, private IS_INSTANCE (SerializedLedgerEntry)
class SerializedLedgerEntry
: public STObject
, public CountedObject <SerializedLedgerEntry>
{
public:
typedef boost::shared_ptr<SerializedLedgerEntry> pointer;

View File

@@ -6,8 +6,6 @@
SETUP_LOG (SerializedTransaction)
DECLARE_INSTANCE (SerializedTransaction);
SerializedTransaction::SerializedTransaction (TransactionType type)
: STObject (sfTransaction)
, mType (type)

View File

@@ -16,9 +16,9 @@
#define TXN_SQL_INCLUDED 'I'
#define TXN_SQL_UNKNOWN 'U'
DEFINE_INSTANCE (SerializedTransaction);
class SerializedTransaction : public STObject, private IS_INSTANCE (SerializedTransaction)
class SerializedTransaction
: public STObject
, public CountedObject <SerializedTransaction>
{
public:
typedef boost::shared_ptr<SerializedTransaction> pointer;

View File

@@ -11,8 +11,6 @@ SETUP_LOG (TransactionAcquire)
typedef std::map<uint160, LedgerProposal::pointer>::value_type u160_prop_pair;
typedef std::map<uint256, DisputedTx::pointer>::value_type u256_lct_pair;
DECLARE_INSTANCE (TransactionAcquire);
TransactionAcquire::TransactionAcquire (uint256 const& hash) : PeerSet (hash, TX_ACQUIRE_TIMEOUT), mHaveRoot (false)
{
mMap = boost::make_shared<SHAMap> (smtTRANSACTION, hash);

View File

@@ -7,14 +7,12 @@
#ifndef RIPPLE_TRANSACTIONACQUIRE_H
#define RIPPLE_TRANSACTIONACQUIRE_H
DEFINE_INSTANCE (TransactionAcquire);
// VFALCO TODO rename to PeerTxRequest
// A transaction set we are trying to acquire
class TransactionAcquire
: private IS_INSTANCE (TransactionAcquire)
, public PeerSet
: public PeerSet
, public boost::enable_shared_from_this <TransactionAcquire>
, public CountedObject <TransactionAcquire>
{
public:
typedef boost::shared_ptr<TransactionAcquire> pointer;