FilesList Class Reference

#include <fileslist.h>

Inheritance diagram for FilesList:

Inheritance graph
[legend]
Collaboration diagram for FilesList:

Collaboration graph
[legend]
List of all members.

Detailed Description

FilesList class owns all SharedFile objects and provides accessors for managing shared files / directories as well as temporary files / directories.

Definition at line 113 of file fileslist.h.


Public Types

typedef boost::multi_index_container<
SharedFile *, boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<
boost::multi_index::identity<
SharedFile * > >, boost::multi_index::ordered_unique<
PathExtractor >, boost::multi_index::ordered_non_unique<
PartExtractor > > > 
MIFilesList
typedef MIFilesList::nth_index<
0 >::type::iterator 
SFIter
typedef MIFilesList::nth_index<
0 >::type::const_iterator 
CSFIter
typedef MIFilesList::nth_index<
1 >::type::iterator 
NIter
typedef MIFilesList::nth_index<
1 >::type::const_iterator 
CNIter

Public Member Functions

void push (SharedFile *file)
 Add new SharedFile to this list.
void addSharedDir (const std::string &path, bool recurse=false)
 Scan a folder for shared files.
void addTempDir (const std::string &path)
 Scan a temporary folder for shared files.
void remSharedDir (const std::string &path, bool recurse=false)
 Remove a shared folder, un-sharing all files found in there.
void remTempDir (const std::string &path)
 Remove a temporary folder.
void createDownload (std::string name, MetaData *info)
 Add a new download, constructed from the passed MetaData info.
void savePartFiles ()
 Instructs FilesList to save the state of all SharedFiles which have PartData member.
uint32_t getPartialCount () const
 Returns number of files with PartData member.
uint32_t getSharedCount () const
 Returns number of total entries in this list; equal to size().
Generic accessors
size_t size () const
CSFIter begin () const
 Iterator to the beginning of our internal map.
CSFIter end () const
 Iterator to the one-past-end of our internal map.
std::pair< CNIter, CNIterequal_range (const std::string &name) const
template<size_t N>
MIFilesList::nth_index< N
>::type::const_iterator 
end ()

Static Public Member Functions

static FilesListinstance ()
 Access to the single instance of this class.

Private Types

typedef std::map< std::string,
bool >::iterator 
SDIter
typedef std::set< std::string
>::iterator 
TDIter

Private Member Functions

void scanSharedDir (const std::string &path, bool recurse=false)
 Directories scanning, optionally recursing.
void scanTempDir (const std::string &path)
void onSharedFileEvent (SharedFile *sf, int evt)
 Event handler for SharedFile events.
bool loadTempFile (const boost::filesystem::path &file)
 Attempts to load a temp file from designated path.
Singleton class - constructors/destructors hidden
 FilesList ()
 ~FilesList ()
 FilesList (FilesList &)
FilesList operator= (const FilesList &)
Make operations/data available for Object hierarcy
virtual uint8_t getOperCount () const
 Retrieve the number of operations for this object.
virtual Object::Operation getOper (uint8_t n) const
 Retrieve a specific operation description.
virtual void doOper (const Operation &oper)
 Perform an operation with this object.

Static Private Member Functions

static void verifyPath (const std::string &path)
 Verify that the string contains a valid existing path.

Private Attributes

MIFilesList m_list
 Main list.
std::map< std::string, bool > m_sharedDirs
 Map of shared directories. boolean indicates recursion.
std::set< std::string > m_tempDirs
 Temporary directories.

Friends

std::ostream & operator<< (std::ostream &o, const FilesList &fl)
 Output operator to streams.

Classes

struct  PartExtractor
struct  PathExtractor

Member Typedef Documentation

typedef MIFilesList::nth_index<1>::type::const_iterator FilesList::CNIter
 

Definition at line 140 of file fileslist.h.

typedef MIFilesList::nth_index<0>::type::const_iterator FilesList::CSFIter
 

Definition at line 138 of file fileslist.h.

typedef boost::multi_index_container< SharedFile*, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::identity<SharedFile*> >, boost::multi_index::ordered_unique<PathExtractor>, boost::multi_index::ordered_non_unique<PartExtractor> > > FilesList::MIFilesList
 

Definition at line 136 of file fileslist.h.

typedef MIFilesList::nth_index<1>::type::iterator FilesList::NIter
 

Definition at line 139 of file fileslist.h.

typedef std::map<std::string, bool>::iterator FilesList::SDIter [private]
 

Definition at line 241 of file fileslist.h.

typedef MIFilesList::nth_index<0>::type::iterator FilesList::SFIter
 

Definition at line 137 of file fileslist.h.

typedef std::set<std::string>::iterator FilesList::TDIter [private]
 

Definition at line 245 of file fileslist.h.


Constructor & Destructor Documentation

FilesList::FilesList  )  [private]
 

Definition at line 44 of file fileslist.cpp.

FilesList::~FilesList  )  [private]
 

Definition at line 47 of file fileslist.cpp.

References Utils::bytesToString(), HashWork::getHashed(), HashWork::getTime(), logMsg(), and m_list.

Here is the call graph for this function:

FilesList::FilesList FilesList  )  [private]
 


Member Function Documentation

void FilesList::addSharedDir const std::string &  path,
bool  recurse = false
 

Scan a folder for shared files.

Parameters:
path Path to folder to be scanned
recurse If true, the path will be scanned recursivly

Definition at line 77 of file fileslist.cpp.

References CHECK_THROW.

Referenced by HydraNode::initFiles().

void FilesList::addTempDir const std::string &  path  ) 
 

Scan a temporary folder for shared files.

Parameters:
path Path to the folder to be scanned
recurse If true, the path will be scanned recurisvly

Definition at line 85 of file fileslist.cpp.

References CHECK_RET, m_tempDirs, scanTempDir(), and verifyPath().

Referenced by HydraNode::initFiles().

Here is the call graph for this function:

CSFIter FilesList::begin  )  const [inline]
 

Iterator to the beginning of our internal map.

Reimplemented from Object.

Definition at line 202 of file fileslist.h.

void FilesList::createDownload std::string  name,
MetaData info
 

Add a new download, constructed from the passed MetaData info.

Parameters:
name Name of the expected resulting file
info Information about the new download

Definition at line 389 of file fileslist.cpp.

References getRandom, MetaDb::instance(), Prefs::instance(), logDebug(), logMsg(), push(), MetaDb::push(), Config::read(), PartData::save(), and Config::setPath().

Here is the call graph for this function:

void FilesList::doOper const Operation &  oper  )  [private, virtual]
 

Perform an operation with this object.

Reimplemented from Object.

Definition at line 329 of file fileslist.cpp.

References Object::Operation::getArg(), Object::Operation::getArgCount(), logDebug(), logError(), and scanSharedDir().

Here is the call graph for this function:

template<size_t N>
MIFilesList::nth_index<N>::type::const_iterator FilesList::end  )  [inline]
 

Definition at line 208 of file fileslist.h.

CSFIter FilesList::end  )  const [inline]
 

Iterator to the one-past-end of our internal map.

Reimplemented from Object.

Definition at line 203 of file fileslist.h.

std::pair<CNIter, CNIter> FilesList::equal_range const std::string &  name  )  const [inline]
 

Definition at line 204 of file fileslist.h.

Object::Operation FilesList::getOper uint8_t  n  )  const [private, virtual]
 

Retrieve a specific operation description.

Reimplemented from Object.

Definition at line 308 of file fileslist.cpp.

References Object::Operation::addArg(), ODT_BOOL, and ODT_STRING.

Here is the call graph for this function:

uint8_t FilesList::getOperCount  )  const [private, virtual]
 

Retrieve the number of operations for this object.

Reimplemented from Object.

Definition at line 304 of file fileslist.cpp.

uint32_t FilesList::getPartialCount  )  const [inline]
 

Returns number of files with PartData member.

Definition at line 218 of file fileslist.h.

uint32_t FilesList::getSharedCount  )  const [inline]
 

Returns number of total entries in this list; equal to size().

Definition at line 223 of file fileslist.h.

FilesList & FilesList::instance  )  [static]
 

Access to the single instance of this class.

Definition at line 63 of file fileslist.cpp.

Referenced by HydraNode::cleanup(), HydraNode::initFiles(), and HydraNode::onEvent().

bool FilesList::loadTempFile const boost::filesystem::path &  file  )  [private]
 

Attempts to load a temp file from designated path.

Parameters:
file Path to the file
Returns:
True if load was successful, false otherwise

Definition at line 251 of file fileslist.cpp.

References SharedFile::getMetaData(), PartData::getMetaData(), MetaDb::instance(), logDebug(), logError(), m_list, and MetaDb::push().

Here is the call graph for this function:

void FilesList::onSharedFileEvent SharedFile sf,
int  evt
[private]
 

Event handler for SharedFile events.

Parameters:
sf SharedFile triggering the event.
evt Event type.

Definition at line 295 of file fileslist.cpp.

References m_list, and SF_DESTROY.

FilesList FilesList::operator= const FilesList  )  [private]
 

void FilesList::push SharedFile file  ) 
 

Add new SharedFile to this list.

Parameters:
file File to be added

Definition at line 68 of file fileslist.cpp.

References CHECK_THROW, and m_list.

Referenced by createDownload().

void FilesList::remSharedDir const std::string &  path,
bool  recurse = false
 

Remove a shared folder, un-sharing all files found in there.

Parameters:
path Path to be un-shared
recurse If all sub-dirs should be un-shared too

Definition at line 96 of file fileslist.cpp.

References CHECK_RET, logDebug(), m_list, m_sharedDirs, and verifyPath().

Here is the call graph for this function:

void FilesList::remTempDir const std::string &  path  ) 
 

Remove a temporary folder.

Parameters:
path Path to be removed
The files in the temporary folder will not be modified; existing downloads will be saved and then destroyed, the data on disk is kept, so the path can be re-added later on to resume those downloads.

Definition at line 118 of file fileslist.cpp.

References CHECK_RET, logDebug(), m_list, m_tempDirs, and verifyPath().

Here is the call graph for this function:

void FilesList::savePartFiles  ) 
 

Instructs FilesList to save the state of all SharedFiles which have PartData member.

Definition at line 426 of file fileslist.cpp.

References m_list, and PartData::save().

Referenced by HydraNode::cleanup(), and HydraNode::onEvent().

Here is the call graph for this function:

void FilesList::scanSharedDir const std::string &  path,
bool  recurse = false
[private]
 

Directories scanning, optionally recursing.

Definition at line 168 of file fileslist.cpp.

References Prefs::instance(), logMsg(), recursion, size(), and Config::write().

Referenced by doOper().

Here is the call graph for this function:

void FilesList::scanTempDir const std::string &  path  )  [private]
 

Definition at line 227 of file fileslist.cpp.

References logDebug(), and logMsg().

Referenced by addTempDir().

Here is the call graph for this function:

size_t FilesList::size  )  const [inline]
 

Definition at line 201 of file fileslist.h.

Referenced by scanSharedDir().

void FilesList::verifyPath const std::string &  path  )  [static, private]
 

Verify that the string contains a valid existing path.

Parameters:
path Path to verify.
Exceptions:
std::runtime_error if verification fails.

Definition at line 141 of file fileslist.cpp.

Referenced by addTempDir(), remSharedDir(), and remTempDir().


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &  o,
const FilesList fl
[friend]
 

Output operator to streams.


Member Data Documentation

MIFilesList FilesList::m_list [private]
 

Main list.

Definition at line 237 of file fileslist.h.

Referenced by loadTempFile(), onSharedFileEvent(), push(), remSharedDir(), remTempDir(), savePartFiles(), and ~FilesList().

std::map<std::string, bool> FilesList::m_sharedDirs [private]
 

Map of shared directories. boolean indicates recursion.

Definition at line 240 of file fileslist.h.

Referenced by remSharedDir().

std::set<std::string> FilesList::m_tempDirs [private]
 

Temporary directories.

Definition at line 244 of file fileslist.h.

Referenced by addTempDir(), and remTempDir().


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