HashWork Class Reference

#include <hasher.h>

Inheritance diagram for HashWork:

Inheritance graph
[legend]
Collaboration diagram for HashWork:

Collaboration graph
[legend]
List of all members.

Detailed Description

Represents a job entry to be performed by WorkThread.

Always wrap this class into boost::shared_ptr<>, because it is a 'loose' object - it is not contained anywhere, however needs to stay alive through various different containers/classes. As such, there is no specific 'destroyer' assigned to this class - it will need to be cleaned up once nobody really needs it anymore. The path through which this object goes is generally this:

Definition at line 52 of file hasher.h.


Public Member Functions

 DECLARE_EVENT_TABLE (boost::shared_ptr< HashWork >, HashEvent)
 HashWork (const boost::filesystem::path &filename)
 Constructor for full hash work.
 HashWork (const boost::filesystem::path &filename, uint64_t begin, uint64_t end, const HashBase *ref)
 Construct a range hash work.
 ~HashWork ()
 Destructor.
void setMetaData (MetaData *md)
 For implementation use only - set metadata.
virtual bool process ()
 Process this job.
Accessors
Note:
We can't have these as const since scoped_lock is non-const


bool isFull ()
 Whether this job is a full job.
uint64_t begin ()
 In case of partial job, retrieves job range begin.
uint64_t end ()
 In case of partial job, retrieves job range end.
boost::filesystem::path getFileName ()
 Retrieves file name to be hashed.
CGComm::HashTypeId getType ()
 Retrieves type of hash to be generated in case of range verification.
const HashBasegetRef ()
 In case of range hash work, retrieves reference/control hash.
MetaDatagetMetaData ()
 Retrieves metaData pointer (filled after full hash job).
bool isValid ()
 Check if this job is valid, e.g.
void invalidate ()
 This method should be called by the original job poster to abort this job, and remove from pending jobs queue.

Static Public Member Functions

static uint64_t getHashed ()
static double getTime ()

Private Member Functions

void initState ()
void doProcess ()
void finish ()

Private Attributes

const boost::filesystem::path m_filename
 File to be hashed. Must include full path to the file.
MetaDatam_md
 After completing full hash job, contains full metadata about the file.
uint64_t m_begin
 In case of range hash, this specifies range begin bytes.
uint64_t m_end
 In case of range hash, this specifies range end bytes.
const HashBasem_ref
 In case of range hash, this specifies reference/control hash.
bool m_valid
 Indicates valditiy of this job.
bool m_full
 Whether this job is a "full" hash job.
boost::mutex m_lock
 Protects all members of this object.
int m_file
boost::scoped_array< char > m_buf
std::vector< boost::shared_ptr<
HashSetMaker > > 
m_makers
bool m_inProgress

Static Private Attributes

static uint64_t s_dataCnt = 0
static double s_timeCnt = 0.0
static boost::mutex s_statsLock

Constructor & Destructor Documentation

HashWork::HashWork const boost::filesystem::path &  filename  ) 
 

Constructor for full hash work.

Parameters:
filename Full path to file to be hashed.
Submitting this job to Hasher will result in HASH_COMPLETE or HASH_FATAL_ERROR events to be submitted when the job is completed, as well as the resulting data being submitted to MetaDb.

Definition at line 47 of file hasher.cpp.

HashWork::HashWork const boost::filesystem::path &  filename,
uint64_t  begin,
uint64_t  end,
const HashBase ref
 

Construct a range hash work.

Parameters:
filename Full path to file to be hashed.
begin Begin location to begin hashing.
end End location until what to hash.
ref Reference hash to check against.
Submitting this job to Hasher will result in HASH_VERIFIED or HASH_FAILED event being submitted when the job is completed.

Definition at line 52 of file hasher.cpp.

References CHECK_THROW.

HashWork::~HashWork  ) 
 

Destructor.

Definition at line 60 of file hasher.cpp.

References m_file.


Member Function Documentation

uint64_t HashWork::begin  )  [inline]
 

In case of partial job, retrieves job range begin.

Definition at line 98 of file hasher.h.

HashWork::DECLARE_EVENT_TABLE boost::shared_ptr< HashWork ,
HashEvent 
 

void HashWork::doProcess  )  [private]
 

Definition at line 138 of file hasher.cpp.

References finish(), m_buf, m_end, m_file, m_makers, s_bufSize, s_dataCnt, and s_statsLock.

Referenced by process().

Here is the call graph for this function:

uint64_t HashWork::end  )  [inline]
 

In case of partial job, retrieves job range end.

Definition at line 103 of file hasher.h.

void HashWork::finish  )  [private]
 

Definition at line 161 of file hasher.cpp.

References MetaData::addFileName(), MetaData::addHashSet(), CHECK_THROW, HashBase::decode(), HashSetBase::getFileHash(), HashSetBase::getFileHashType(), Utils::getFileSize(), MetaData::getHashSet(), Utils::getModDate(), HASH_COMPLETE, HASH_FAILED, HASH_VERIFIED, isFull(), logDebug(), m_file, m_filename, m_makers, m_md, m_ref, ThreadWork::setComplete(), and MetaData::setModDate().

Referenced by doProcess().

Here is the call graph for this function:

boost::filesystem::path HashWork::getFileName  )  [inline]
 

Retrieves file name to be hashed.

Definition at line 108 of file hasher.h.

static uint64_t HashWork::getHashed  )  [inline, static]
 

Definition at line 150 of file hasher.h.

Referenced by FilesList::~FilesList().

MetaData* HashWork::getMetaData  )  [inline]
 

Retrieves metaData pointer (filled after full hash job).

Definition at line 124 of file hasher.h.

const HashBase* HashWork::getRef  )  [inline]
 

In case of range hash work, retrieves reference/control hash.

Definition at line 119 of file hasher.h.

static double HashWork::getTime  )  [inline, static]
 

Definition at line 151 of file hasher.h.

Referenced by FilesList::~FilesList().

CGComm::HashTypeId HashWork::getType  )  [inline]
 

Retrieves type of hash to be generated in case of range verification.

Definition at line 113 of file hasher.h.

References CHECK_THROW.

void HashWork::initState  )  [private]
 

Definition at line 84 of file hasher.cpp.

References CHECK_THROW, Utils::getFileSize(), logError(), logMsg(), O_BINARY, CGComm::OP_HT_ED2K, CGComm::OP_HT_MD4, CGComm::OP_HT_MD5, CGComm::OP_HT_SHA1, and s_bufSize.

Referenced by process().

Here is the call graph for this function:

void HashWork::invalidate  )  [inline]
 

This method should be called by the original job poster to abort this job, and remove from pending jobs queue.

If the work is in progress already, it will also be aborted, and no results posted.

Definition at line 138 of file hasher.h.

bool HashWork::isFull  )  [inline]
 

Whether this job is a full job.

Definition at line 93 of file hasher.h.

Referenced by finish().

bool HashWork::isValid  )  [inline]
 

Check if this job is valid, e.g.

still needed to be performed. This is needed to make sure that while the job was waiting in the queue, it hasn't become invalid.

Reimplemented from ThreadWork.

Definition at line 131 of file hasher.h.

bool HashWork::process  )  [virtual]
 

Process this job.

Implements ThreadWork.

Definition at line 66 of file hasher.cpp.

References CHECK_THROW, doProcess(), Utils::StopWatch::elapsed(), initState(), ThreadWork::isComplete(), m_inProgress, and s_timeCnt.

Here is the call graph for this function:

void HashWork::setMetaData MetaData md  )  [inline]
 

For implementation use only - set metadata.

Definition at line 145 of file hasher.h.


Member Data Documentation

uint64_t HashWork::m_begin [private]
 

In case of range hash, this specifies range begin bytes.

Definition at line 164 of file hasher.h.

boost::scoped_array<char> HashWork::m_buf [private]
 

Definition at line 196 of file hasher.h.

Referenced by doProcess().

uint64_t HashWork::m_end [private]
 

In case of range hash, this specifies range end bytes.

Definition at line 167 of file hasher.h.

Referenced by doProcess().

int HashWork::m_file [private]
 

Definition at line 195 of file hasher.h.

Referenced by doProcess(), finish(), and ~HashWork().

const boost::filesystem::path HashWork::m_filename [private]
 

File to be hashed. Must include full path to the file.

Definition at line 157 of file hasher.h.

Referenced by finish().

bool HashWork::m_full [private]
 

Whether this job is a "full" hash job.

Definition at line 183 of file hasher.h.

bool HashWork::m_inProgress [private]
 

Definition at line 198 of file hasher.h.

Referenced by process().

boost::mutex HashWork::m_lock [private]
 

Protects all members of this object.

This lock must be aquired before touching anything in this object.

Definition at line 189 of file hasher.h.

std::vector<boost::shared_ptr<HashSetMaker> > HashWork::m_makers [private]
 

Definition at line 197 of file hasher.h.

Referenced by doProcess(), and finish().

MetaData* HashWork::m_md [private]
 

After completing full hash job, contains full metadata about the file.

Definition at line 161 of file hasher.h.

Referenced by finish().

const HashBase* HashWork::m_ref [private]
 

In case of range hash, this specifies reference/control hash.

Definition at line 170 of file hasher.h.

Referenced by finish().

bool HashWork::m_valid [private]
 

Indicates valditiy of this job.

This variable is set to true as default, and can be set to false using invalidate() member function. The purpose of this is to provide a mechanism to abort hashing jobs which are no longer wanted by the original poster.

Reimplemented from ThreadWork.

Definition at line 180 of file hasher.h.

uint64_t HashWork::s_dataCnt = 0 [static, private]
 

Definition at line 40 of file hasher.cpp.

Referenced by doProcess().

boost::mutex HashWork::s_statsLock [static, private]
 

Definition at line 42 of file hasher.cpp.

Referenced by doProcess().

double HashWork::s_timeCnt = 0.0 [static, private]
 

Definition at line 41 of file hasher.cpp.

Referenced by process().


The documentation for this class was generated from the following files: