Files Management Subsystem Overview

The three main classes in Files Management Subsystem are PartData, SharedFile and FilesList. They are supported by MetaData data structures, which contain useful information about these objects. PartData object is owned by SharedFile, which in turn is owned by FilesList. Various ***MetaData objects are owned by MetaData, which in turn is owned by MetaDb. The usage of the subsystem goes as follows:

Starting a new download.


 SharedFile *sf = MetaDb::instance().findSharedFile(hash);
 if (sf && sf->isPartial()) {
     boost::format("You are already attempting to download %s")
     % sf->getName()
 } else if (sf) {
   logMsg(boost::format("You already have %s") % sf->getName());
 } else {
   MetaData *md = new MetaData(size);
   FilesList::instance().createDownload(name, md);

Continueing an existing download.

When the application restarts, the plugins want to continue downloading existing partial files. In order to do so, plugins must locate all the files they are capable of downloading from FilesList. Here's the hard part. We don't want to force plugins to keep internal list of their part files - after all, its (a) our job, (b) de-centralizes this stuff, (c) its our job. So, we need to provide the plugins with a list of files they can attempt to download. Consider this example: We have been downloading files from various networks for quite some time now, having large amount of partial files. Now, a new plugin for a new network gets released. Naturally, the new plugin joins the show and wants to catch up to things - e.g. what needs to be done. So the plugin does what? Takes up FilesList and iterates on it. Only the plugin itself can know what kind of files its looking for - for example, some plugins might need a specific hash in order to download a file, others might want http or ftp url ... god knows what. So - in short - FilesList provides access to begin() and end() iterators, just as any standard c++ container, and let plugins do the hard part.

Ok - enough discussion - so what do you do to get your files ? Call FilesList::begin() to retrieve iterator to begin of list, and start iterating on the list. The only guarantee I can give you at this point is that if you dereference the iterator, you get a pointer to a SharedFile object. You don't even know that its partial - use the SharedFile member functions to check it. Where we go from here is up to you to decide. The iterators are constant, so you can't modify them. And don't store them - they are std::map iterators, and will become invalid when the integrity of the map changes.