Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VsnetDownload::Client::FileSet Class Reference

#include <vsnet_notify.h>

Classes

class  NotifyConclusion
 

Public Member Functions

 FileSet (boost::shared_ptr< Manager >mgr, SOCKETALT sock, std::list< std::string >filesnames, std::string localbasepath)
 
bool isDone () const
 
void update (std::string s, bool v)
 

Detailed Description

We can't really support blocking until a set of files has been downloaded inside this class. The problem is that the variables that we must wait for exist in netserver, netclient and accountserver, and they are called in several places and potentially several threads. Therefore the waiting itself should be handled in those classes. This helper class allows a simple check.

Create a FileSet with the appropriate Manager, the socket to the remote side that you want to use, the list of filenames as string, and the existing(!) directory where you want to store the files. Then call isDone() a couple of times. If it returns true, the downloads are all completed (but they may have failed - if you need to check that, add a function for reading the int values from the member variable _files, 1 success, 0 failure).

Definition at line 369 of file vsnet_notify.h.

Constructor & Destructor Documentation

VsnetDownload::Client::FileSet::FileSet ( boost::shared_ptr< Manager mgr,
SOCKETALT  sock,
std::list< std::string >  filesnames,
std::string  localbasepath 
)

Definition at line 309 of file vsnet_notify.cpp.

References VSFileSystem::UnknownFile.

309  :
310  _to_go( 0 )
311 {
312  std::list< std::string >::const_iterator cit;
313  std::list< Item* >items;
314  for (cit = filenames.begin(); cit != filenames.end(); cit++) {
315  _files.insert( std::pair< std::string, int > ( *cit, -1 ) );
316  NotifyPtr ptr( new NotifyConclusion( this, *cit ) );
317  items.push_back( new File( sock, *cit, path, VSFileSystem::UnknownFile, ptr ) );
318  _to_go++;
319  }
320  mgr->addItems( items );
321 }

Member Function Documentation

bool VsnetDownload::Client::FileSet::isDone ( ) const

Definition at line 323 of file vsnet_notify.cpp.

324 {
325  return _to_go == 0;
326 }
void VsnetDownload::Client::FileSet::update ( std::string  s,
bool  v 
)

Definition at line 328 of file vsnet_notify.cpp.

329 {
330  std::map< std::string, int >::iterator it;
331  it = _files.find( s );
332  if (it != _files.end() && it->second == -1) {
333  it->second = (v ? 1 : 0);
334  _to_go--;
335  }
336 }

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