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::Manager Class Reference

#include <vsnet_dloadmgr.h>

Public Member Functions

 Manager (SocketSet &set, const char **local_search_paths)
 
 Manager (SocketSet &set)
 
void addItem (Item *item)
 
void addItems (std::list< Item * > &items)
 
void processCmdDownload (SOCKETALT sock, NetBuffer &buffer)
 
void lower_check_queues ()
 

Detailed Description

The download manager works in the networking thread. New requests are added from all threads, and notifications may interfere with the Items that are owned by other threads, but the management of files and buffers is handled entirely in the networking threads.

Definition at line 53 of file vsnet_dloadmgr.h.

Constructor & Destructor Documentation

VsnetDownload::Client::Manager::Manager ( SocketSet set,
const char **  local_search_paths 
)

Definition at line 59 of file vsnet_dloadmgr.cpp.

References c, and COUT.

59  :
60  _set( sets )
61 {
62  COUT<<"Enter "<<__PRETTY_FUNCTION__<<endl;
63 
64  const char **c = local_search_paths;
65  while (*c != NULL) {
66  _local_search_paths.push_back( *c );
67  c++;
68  }
69 }
VsnetDownload::Client::Manager::Manager ( SocketSet set)

Definition at line 71 of file vsnet_dloadmgr.cpp.

References COUT, and VSFileSystem::datadir.

71  :
72  _set( sets )
73 {
74  COUT<<"Enter "<<__PRETTY_FUNCTION__<<endl;
75 
76  _local_search_paths.push_back( VSFileSystem::datadir );
77 }

Member Function Documentation

void VsnetDownload::Client::Manager::addItem ( Item item)

Definition at line 79 of file vsnet_dloadmgr.cpp.

References addItems().

80 {
81  list< Item* >l;
82  l.push_back( item );
83  addItems( l );
84 }
void VsnetDownload::Client::Manager::addItems ( std::list< Item * > &  items)

Definition at line 86 of file vsnet_dloadmgr.cpp.

References VsnetDownload::Client::Item::changeState(), VsnetDownload::Client::Completed, COUT, VSFileSystem::FileNotFound, VsnetDownload::Client::Item::getFilename(), VSMutex::lock(), VsnetDownload::Client::Queued, VSMutex::unlock(), and SocketSet::wakeup().

Referenced by addItem().

87 {
88  COUT<<"Enter "<<__PRETTY_FUNCTION__<<endl;
89 
90  list< Item* >::iterator it;
91 
92  _pending_mx.lock();
93  for (it = items.begin(); it != items.end(); it++) {
94  Item *item = (*it);
95  if (item->getFilename() != "") {
96  COUT<<"adding item: "<<item->getFilename()<<endl;
97  _pending.push( item );
98  }
99  }
100  _pending_mx.unlock();
101  for (it = items.begin(); it != items.end(); it++) {
102  Item *item = (*it);
103  if (item->getFilename() == "")
105  else
106  item->changeState( Queued );
107  }
108  _set.wakeup();
109 }
void VsnetDownload::Client::Manager::lower_check_queues ( )

Called by SocketSet after each round.

Definition at line 140 of file vsnet_dloadmgr.cpp.

141 {
142  private_lower_poll();
143 }
void VsnetDownload::Client::Manager::processCmdDownload ( SOCKETALT  sock,
NetBuffer buffer 
)

NetClient::recvMsg calls this for answers from a server mgr (currently only from the server because no other socket is checked).

Definition at line 111 of file vsnet_dloadmgr.cpp.

References c, COUT, VsnetDownload::Download, VsnetDownload::DownloadError, VsnetDownload::DownloadFirstFragment, VsnetDownload::DownloadFragment, VsnetDownload::DownloadLastFragment, VsnetDownload::DownloadRequest, NetBuffer::getChar(), VsnetDownload::ResolveRequest, VsnetDownload::ResolveResponse, and VsnetDownload::UnexpectedSubcommand.

112 {
113  COUT<<"Enter "<<__PRETTY_FUNCTION__<<endl;
114 
115  char c = buffer.getChar();
116  Subcommand sc = (Subcommand) c;
117  switch (sc)
118  {
119  case ResolveResponse:
120  private_eval_resolve_response( sock, buffer );
121  break;
122  case DownloadError:
123  private_eval_download_error( sock, buffer );
124  break;
125  case Download:
127  case DownloadFragment:
129  private_eval_download( sock, buffer, sc );
130  break;
131  case DownloadRequest:
133  case ResolveRequest:
134  default:
135  COUT<<"unexpected subcommand "<<sc<<", ignoring"<<endl;
136  break;
137  }
138 }

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