SharedFile Class Reference

#include <sharedfile.h>

Inheritance diagram for SharedFile:

Inheritance graph
[legend]
Collaboration diagram for SharedFile:

Collaboration graph
[legend]
List of all members.

Detailed Description

SharedFile object represents a file which is currently being shared.

It may be partial or complete or completely empty. SharedFile objects are owned by FilesList class - the destructor of SharedFile has been protected to avoid unwanted deletion of SharedFile objects.

Definition at line 50 of file sharedfile.h.


Public Member Functions

 DECLARE_EVENT_TABLE (SharedFile *, int)
 SharedFile (boost::filesystem::path location, MetaData *metaData=0)
 Construct SharedFile object.
 SharedFile (PartData *partData, MetaData *metaData=0)
 Construct SharedFile from existing PartData.
void destroy ()
 Schedule for destruction.
void verify ()
 Order the SharedFile to re-check the integrity of the physical file, and up2date metadata.
std::string read (uint64_t begin, uint64_t end)
 Read data from disk from location and return it.
Accessors
std::string getLocation () const
std::string getName () const
 Retrieve the name of this object.
boost::filesystem::path getPath () const
MetaDatagetMetaData () const
PartDatagetPartData () const
uint64_t getUploaded () const
uint64_t getSize () const
bool hasMetaData () const
bool isComplete () const
bool isPartial () const
Setters
void setMetaData (MetaData *md)
void setPartData (PartData *pd)
void addUploaded (uint64_t sum)

Private Member Functions

 ~SharedFile ()
 Allowed by FilesList.
 SharedFile ()
 Forbidden.
 SharedFile (SharedFile &)
 Forbidden.
SharedFileoperator= (const SharedFile &)
 Forbidden.
void onPartEvent (PartData *pd, int evt)
 Event handler for PartData events.
void onMoveEvent (MoveWorkPtr ptr, int evt)
 Event handler for file moving events.
void checkFileSize (MetaData *md)
 Verifies our current m_fileSize against what is stored in MetaData.
void onHashEvent (boost::shared_ptr< HashWork > hw, HashEvent evt)
 Event handler for hash events.
void updateModDate ()
 Updates the files modification date that is stored in MetaDb.
bool isDuplicate ()
 Check if there are any other SharedFiles which match the specs of this file.
void setLocation (const boost::filesystem::path &loc)
 Change the location for this file.
void addLocation (const boost::filesystem::path &loc)
 Add an alternative location.

Static Private Member Functions

static MetaDatafindMetaData (boost::filesystem::path loc, const std::string &name, PartData *pd=0)
 Locate MetaData for a file.

Private Attributes

boost::filesystem::path m_location
 (primary) Physical location
MetaDatam_metaData
 May be null.
PartDatam_partData
 May be null.
uint64_t m_uploaded
 Amount uploaded.
uint64_t m_size
 Size of file.
boost::weak_ptr< HashWorkm_pendingJob
 Pending job (if any).
boost::signals::connection m_pdSigHandler
 If we have PartData, this is connected to PartData events.
std::vector< std::pair< uint32_t,
boost::filesystem::path > > 
m_locations
 Vector of alternative locations, with timestamps.

Friends

class FilesList
std::ostream & operator<< (std::ostream &o, const SharedFile &sf)

Constructor & Destructor Documentation

SharedFile::SharedFile boost::filesystem::path  location,
MetaData metaData = 0
 

Construct SharedFile object.

Parameters:
location Location of the physical file.
metaData Optional MetaData pointer corresponding to this SharedFile object.

Definition at line 110 of file sharedfile.cpp.

References getName(), logTrace(), m_metaData, m_size, Object::setName(), SF_ADDED, SF_METADATA_ADDED, TRACE_SHAREDFILE, and verify().

Here is the call graph for this function:

SharedFile::SharedFile PartData partData,
MetaData metaData = 0
 

Construct SharedFile from existing PartData.

Parameters:
partData Pointer to PartData object.
metaData Optional pointer to MetaData object.

Definition at line 156 of file sharedfile.cpp.

References CHECK_THROW, PartData::deleteFiles(), PartData::getMetaData(), getName(), isDuplicate(), m_metaData, m_partData, m_size, PartData::setMetaData(), Object::setName(), setPartData(), SF_ADDED, and verify().

Here is the call graph for this function:

SharedFile::~SharedFile  )  [private]
 

Allowed by FilesList.

Definition at line 212 of file sharedfile.cpp.

References m_partData, and m_pendingJob.

SharedFile::SharedFile  )  [private]
 

Forbidden.

SharedFile::SharedFile SharedFile  )  [private]
 

Forbidden.


Member Function Documentation

void SharedFile::addLocation const boost::filesystem::path &  loc  )  [private]
 

Add an alternative location.

Parameters:
loc New location
This can be used when we detect an identical file shared from multiple folders.

Definition at line 534 of file sharedfile.cpp.

References m_locations.

Referenced by isDuplicate().

void SharedFile::addUploaded uint64_t  sum  )  [inline]
 

Definition at line 91 of file sharedfile.h.

void SharedFile::checkFileSize MetaData md  )  [private]
 

Verifies our current m_fileSize against what is stored in MetaData.

Parameters:
md Pointer to MetaData to verify against. May not be NULL
Preconditions: m_location points to current file location m_filesize is set to correct file size. Sideeffects: md->filesize may be modified/fixed if it does not match the actual file size.

Definition at line 197 of file sharedfile.cpp.

References CHECK_THROW, getSize(), logWarning(), and MetaData::setFileSize().

Referenced by verify().

Here is the call graph for this function:

SharedFile::DECLARE_EVENT_TABLE SharedFile ,
int 
 

void SharedFile::destroy  ) 
 

Schedule for destruction.

Definition at line 340 of file sharedfile.cpp.

References PartData::destroy(), m_partData, m_pdSigHandler, and SF_DESTROY.

Referenced by isDuplicate(), onHashEvent(), onPartEvent(), and read().

Here is the call graph for this function:

MetaData * SharedFile::findMetaData boost::filesystem::path  loc,
const std::string &  name,
PartData pd = 0
[static, private]
 

Locate MetaData for a file.

Parameters:
loc Path to file to inspect.
name Name of the file (useful if dealing with tmp files)
pd If set, indicates that we'r dealing with a partial file, thus the size on the disk cannot be trusted, and filesize should be retrieved from PartData object instead.
Returns:
MetaData object found. May be null if not found.

Definition at line 226 of file sharedfile.cpp.

References MetaDb::find(), Utils::getFileSize(), Utils::getModDate(), MetaDb::instance(), logTrace(), and TRACE_SHAREDFILE.

Referenced by verify().

Here is the call graph for this function:

std::string SharedFile::getLocation  )  const [inline]
 

Definition at line 73 of file sharedfile.h.

Referenced by verify().

MetaData* SharedFile::getMetaData  )  const [inline]
 

Definition at line 78 of file sharedfile.h.

Referenced by FilesList::loadTempFile().

std::string SharedFile::getName  )  const
 

Retrieve the name of this object.

Reimplemented from Object.

Definition at line 506 of file sharedfile.cpp.

References PartData::getDestination(), m_location, and m_partData.

Referenced by isDuplicate(), onMoveEvent(), read(), SharedFile(), and verify().

Here is the call graph for this function:

PartData* SharedFile::getPartData  )  const [inline]
 

Definition at line 79 of file sharedfile.h.

Referenced by isDuplicate().

boost::filesystem::path SharedFile::getPath  )  const [inline]
 

Definition at line 77 of file sharedfile.h.

Referenced by read().

uint64_t SharedFile::getSize  )  const [inline]
 

Definition at line 81 of file sharedfile.h.

Referenced by checkFileSize().

uint64_t SharedFile::getUploaded  )  const [inline]
 

Definition at line 80 of file sharedfile.h.

bool SharedFile::hasMetaData  )  const [inline]
 

Definition at line 82 of file sharedfile.h.

bool SharedFile::isComplete  )  const
 

Definition at line 524 of file sharedfile.cpp.

References m_partData.

bool SharedFile::isDuplicate  )  [private]
 

Check if there are any other SharedFiles which match the specs of this file.

Returns:
True if a duplicate was found, and handled appropriately, false otherwise.
Note that the behaviour when duplicate is found is to destroy this one, not the duplicate.

Definition at line 407 of file sharedfile.cpp.

References addLocation(), CHECK_THROW, destroy(), PartData::destroy(), MetaDb::findSharedFile(), HashSetBase::getFileHash(), MetaData::getHashSet(), getName(), getPartData(), MetaDb::instance(), isPartial(), logMsg(), m_location, m_metaData, setLocation(), and setMetaData().

Referenced by onHashEvent(), and SharedFile().

Here is the call graph for this function:

bool SharedFile::isPartial  )  const
 

Definition at line 521 of file sharedfile.cpp.

References m_partData.

Referenced by isDuplicate(), and read().

void SharedFile::onHashEvent boost::shared_ptr< HashWork hw,
HashEvent  evt
[private]
 

Event handler for hash events.

Definition at line 380 of file sharedfile.cpp.

References CHECK_THROW, destroy(), HASH_FATAL_ERROR, MetaDb::instance(), isDuplicate(), logDebug(), logError(), m_metaData, MetaDb::push(), and SF_METADATA_ADDED.

Referenced by verify().

Here is the call graph for this function:

void SharedFile::onMoveEvent MoveWorkPtr  ptr,
int  evt
[private]
 

Event handler for file moving events.

Definition at line 311 of file sharedfile.cpp.

References COL_BBLUE, COL_BYELLOW, COL_NONE, PartData::deleteFiles(), PartData::destroy(), getName(), logMsg(), m_partData, and setLocation().

Referenced by onPartEvent().

Here is the call graph for this function:

void SharedFile::onPartEvent PartData pd,
int  evt
[private]
 

Event handler for PartData events.

Optimize this: Don't call second thread when src and dest are on same partition.

Definition at line 281 of file sharedfile.cpp.

References CHECK_THROW, destroy(), WorkThread::instance(), PartData::isComplete(), logDebug(), m_partData, m_pdSigHandler, onMoveEvent(), PD_COMPLETE, PD_DATA_FLUSHED, PD_DESTROY, WorkThread::postWork(), and updateModDate().

Referenced by setPartData().

Here is the call graph for this function:

SharedFile& SharedFile::operator= const SharedFile  )  [private]
 

Forbidden.

std::string SharedFile::read uint64_t  begin,
uint64_t  end
 

Read data from disk from location and return it.

Parameters:
begin Begin offset where to start reading
end End offset where to stop reading (included)
Returns:
Data buffer of the read data

Definition at line 455 of file sharedfile.cpp.

References CHECK_THROW, destroy(), MetaData::getModDate(), Utils::getModDate(), getName(), getPath(), PartData::isComplete(), isPartial(), m_location, m_locations, m_metaData, m_partData, O_BINARY, and setLocation().

Here is the call graph for this function:

void SharedFile::setLocation const boost::filesystem::path &  loc  )  [private]
 

Change the location for this file.

Parameters:
loc New location
Note:
If m_metaData is non-zero, this also updates modification date in m_metaData object.

Definition at line 538 of file sharedfile.cpp.

References m_location, m_metaData, and MetaData::setModDate().

Referenced by isDuplicate(), onMoveEvent(), and read().

Here is the call graph for this function:

void SharedFile::setMetaData MetaData md  ) 
 

Definition at line 529 of file sharedfile.cpp.

References CHECK_THROW, and m_metaData.

Referenced by isDuplicate().

void SharedFile::setPartData PartData pd  ) 
 

Definition at line 325 of file sharedfile.cpp.

References CHECK_THROW, PartData::getLocation(), m_location, m_partData, m_pdSigHandler, and onPartEvent().

Referenced by SharedFile().

Here is the call graph for this function:

void SharedFile::updateModDate  )  [private]
 

Updates the files modification date that is stored in MetaDb.

Definition at line 514 of file sharedfile.cpp.

References logTrace(), m_location, m_metaData, MetaData::setModDate(), and TRACE_SHAREDFILE.

Referenced by onPartEvent().

Here is the call graph for this function:

void SharedFile::verify  ) 
 

Order the SharedFile to re-check the integrity of the physical file, and up2date metadata.

Definition at line 354 of file sharedfile.cpp.

References checkFileSize(), findMetaData(), getLocation(), getName(), MetaDb::instance(), WorkThread::instance(), logTrace(), m_location, m_metaData, m_partData, m_pendingJob, onHashEvent(), WorkThread::postWork(), MetaDb::push(), and TRACE_SHAREDFILE.

Referenced by SharedFile().

Here is the call graph for this function:


Friends And Related Function Documentation

friend class FilesList [friend]
 

Definition at line 110 of file sharedfile.h.

std::ostream& operator<< std::ostream &  o,
const SharedFile sf
[friend]
 

Definition at line 348 of file sharedfile.cpp.


Member Data Documentation

boost::filesystem::path SharedFile::m_location [private]
 

(primary) Physical location

Definition at line 188 of file sharedfile.h.

Referenced by getName(), isDuplicate(), read(), setLocation(), setPartData(), updateModDate(), and verify().

std::vector<std::pair<uint32_t, boost::filesystem::path> > SharedFile::m_locations [private]
 

Vector of alternative locations, with timestamps.

Definition at line 200 of file sharedfile.h.

Referenced by addLocation(), and read().

MetaData* SharedFile::m_metaData [private]
 

May be null.

Definition at line 189 of file sharedfile.h.

Referenced by isDuplicate(), onHashEvent(), read(), setLocation(), setMetaData(), SharedFile(), updateModDate(), and verify().

PartData* SharedFile::m_partData [private]
 

May be null.

Definition at line 190 of file sharedfile.h.

Referenced by destroy(), getName(), isComplete(), isPartial(), onMoveEvent(), onPartEvent(), read(), setPartData(), SharedFile(), verify(), and ~SharedFile().

boost::signals::connection SharedFile::m_pdSigHandler [private]
 

If we have PartData, this is connected to PartData events.

Definition at line 197 of file sharedfile.h.

Referenced by destroy(), onPartEvent(), and setPartData().

boost::weak_ptr<HashWork> SharedFile::m_pendingJob [private]
 

Pending job (if any).

Definition at line 194 of file sharedfile.h.

Referenced by verify(), and ~SharedFile().

uint64_t SharedFile::m_size [private]
 

Size of file.

Definition at line 192 of file sharedfile.h.

Referenced by SharedFile().

uint64_t SharedFile::m_uploaded [private]
 

Amount uploaded.

Definition at line 191 of file sharedfile.h.


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