Files
rippled/modules/ripple_core/functional/ripple_Job.cpp
2013-07-24 17:44:58 -07:00

203 lines
3.4 KiB
C++

//------------------------------------------------------------------------------
/*
Copyright (c) 2011-2013, OpenCoin, Inc.
*/
//==============================================================================
Job::Job ()
: mType (jtINVALID)
, mJobIndex (0)
, m_limit (0)
{
}
Job::Job (JobType type, uint64 index)
: mType (type)
, mJobIndex (index)
, m_limit (0)
{
}
Job::Job (JobType type,
std::string const& name,
int limit,
uint64 index,
LoadMonitor& lm,
FUNCTION_TYPE <void (Job&)> const& job)
: mType (type)
, mJobIndex (index)
, mJob (job)
, mName (name)
, m_limit(limit)
{
m_loadEvent = boost::make_shared <LoadEvent> (boost::ref (lm), name, false);
}
JobType Job::getType () const
{
return mType;
}
void Job::doJob ()
{
m_loadEvent->reName (mName);
mJob (*this);
}
void Job::rename (std::string const& newName)
{
mName = newName;
}
int Job::getLimit () const
{
return m_limit;
}
LoadEvent& Job::peekEvent() const
{
return *m_loadEvent;
}
const char* Job::toString (JobType t)
{
switch (t)
{
case jtINVALID:
return "invalid";
case jtPACK:
return "makeFetchPack";
case jtPUBOLDLEDGER:
return "publishAcqLedger";
case jtVALIDATION_ut:
return "untrustedValidation";
case jtPROOFWORK:
return "proofOfWork";
case jtPROPOSAL_ut:
return "untrustedProposal";
case jtLEDGER_DATA:
return "ledgerData";
case jtUPDATE_PF:
return "updatePaths";
case jtCLIENT:
return "clientCommand";
case jtTRANSACTION:
return "transaction";
case jtPUBLEDGER:
return "publishNewLedger";
case jtVALIDATION_t:
return "trustedValidation";
case jtWAL:
return "writeAhead";
case jtWRITE:
return "writeObjects";
case jtTRANSACTION_l:
return "localTransaction";
case jtPROPOSAL_t:
return "trustedProposal";
case jtADMIN:
return "administration";
case jtDEATH:
return "jobOfDeath";
case jtPEER:
return "peerCommand";
case jtDISK:
return "diskAccess";
case jtACCEPTLEDGER:
return "acceptLedger";
case jtTXN_PROC:
return "processTransaction";
case jtTXN_DATA:
return "fetchTxnData";
case jtOB_SETUP:
return "orderBookSetup";
case jtPATH_FIND:
return "pathFind";
case jtHO_READ:
return "nodeRead";
case jtHO_WRITE:
return "nodeWrite";
case jtSWEEP:
return "sweep";
case jtGENERIC:
return "generic";
default:
assert (false);
return "unknown";
}
}
bool Job::operator> (const Job& j) const
{
if (mType < j.mType)
return true;
if (mType > j.mType)
return false;
return mJobIndex > j.mJobIndex;
}
bool Job::operator>= (const Job& j) const
{
if (mType < j.mType)
return true;
if (mType > j.mType)
return false;
return mJobIndex >= j.mJobIndex;
}
bool Job::operator< (const Job& j) const
{
if (mType < j.mType)
return false;
if (mType > j.mType)
return true;
return mJobIndex < j.mJobIndex;
}
bool Job::operator<= (const Job& j) const
{
if (mType < j.mType)
return false;
if (mType > j.mType)
return true;
return mJobIndex <= j.mJobIndex;
}