2007-05-20 13:57:56 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-05-20 13:57:56 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#ifndef _D_REQUEST_GROUP_MAN_H_
|
|
|
|
#define _D_REQUEST_GROUP_MAN_H_
|
|
|
|
|
|
|
|
#include "common.h"
|
2009-01-12 12:27:34 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <string>
|
|
|
|
#include <deque>
|
|
|
|
#include <iosfwd>
|
2010-02-28 12:30:11 +00:00
|
|
|
#include <vector>
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2009-01-12 12:27:34 +00:00
|
|
|
#include "SharedHandle.h"
|
|
|
|
#include "DownloadResult.h"
|
|
|
|
#include "TransferStat.h"
|
2010-03-20 15:01:56 +00:00
|
|
|
#include "RequestGroup.h"
|
2009-01-12 12:27:34 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-05-20 13:57:56 +00:00
|
|
|
|
|
|
|
class DownloadEngine;
|
2007-10-11 16:58:24 +00:00
|
|
|
class Command;
|
|
|
|
class Logger;
|
2010-06-13 02:21:40 +00:00
|
|
|
struct DownloadResult;
|
2008-08-04 17:06:47 +00:00
|
|
|
class ServerStatMan;
|
|
|
|
class ServerStat;
|
|
|
|
class Option;
|
2007-05-20 13:57:56 +00:00
|
|
|
|
|
|
|
class RequestGroupMan {
|
|
|
|
private:
|
2010-06-21 13:51:56 +00:00
|
|
|
std::deque<SharedHandle<RequestGroup> > requestGroups_;
|
|
|
|
std::deque<SharedHandle<RequestGroup> > reservedGroups_;
|
|
|
|
std::deque<SharedHandle<DownloadResult> > downloadResults_;
|
|
|
|
Logger* logger_;
|
|
|
|
unsigned int maxSimultaneousDownloads_;
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
const Option* option_;
|
2008-08-04 17:06:47 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
SharedHandle<ServerStatMan> serverStatMan_;
|
2008-08-04 17:06:47 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
unsigned int maxOverallDownloadSpeedLimit_;
|
2009-02-28 11:48:26 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
unsigned int maxOverallUploadSpeedLimit_;
|
2009-02-28 11:48:26 +00:00
|
|
|
|
2009-06-20 03:19:23 +00:00
|
|
|
// truf if XML-RPC is enabled.
|
2010-06-21 13:51:56 +00:00
|
|
|
bool xmlRpc_;
|
2009-06-20 03:19:23 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
bool queueCheck_;
|
2010-03-05 14:02:23 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string
|
|
|
|
formatDownloadResult(const std::string& status,
|
2010-01-05 16:01:46 +00:00
|
|
|
const SharedHandle<DownloadResult>& downloadResult) const;
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-08-04 17:06:47 +00:00
|
|
|
void configureRequestGroup
|
|
|
|
(const SharedHandle<RequestGroup>& requestGroup) const;
|
2007-05-20 13:57:56 +00:00
|
|
|
public:
|
2010-02-28 12:30:11 +00:00
|
|
|
RequestGroupMan(const std::vector<SharedHandle<RequestGroup> >& requestGroups,
|
2010-01-05 16:01:46 +00:00
|
|
|
unsigned int maxSimultaneousDownloads,
|
|
|
|
const Option* option);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
bool downloadFinished();
|
|
|
|
|
|
|
|
void save();
|
|
|
|
|
|
|
|
void closeFile();
|
2007-05-20 13:57:56 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void halt();
|
2007-05-20 13:57:56 +00:00
|
|
|
|
2007-12-07 13:33:59 +00:00
|
|
|
void forceHalt();
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
void removeStoppedGroup(DownloadEngine* e);
|
2007-05-20 13:57:56 +00:00
|
|
|
|
|
|
|
void fillRequestGroupFromReserver(DownloadEngine* e);
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void addRequestGroup(const SharedHandle<RequestGroup>& group);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
void addReservedGroup(const std::vector<SharedHandle<RequestGroup> >& groups);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void addReservedGroup(const SharedHandle<RequestGroup>& group);
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2009-05-30 13:55:14 +00:00
|
|
|
void insertReservedGroup
|
2010-02-28 12:30:11 +00:00
|
|
|
(size_t pos, const std::vector<SharedHandle<RequestGroup> >& groups);
|
2009-05-30 13:55:14 +00:00
|
|
|
|
|
|
|
void insertReservedGroup(size_t pos, const SharedHandle<RequestGroup>& group);
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
size_t countRequestGroup() const;
|
2010-01-05 16:01:46 +00:00
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
SharedHandle<RequestGroup> getRequestGroup(size_t index) const;
|
2008-05-15 14:37:02 +00:00
|
|
|
|
2009-05-29 12:12:22 +00:00
|
|
|
const std::deque<SharedHandle<RequestGroup> >& getRequestGroups() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return requestGroups_;
|
2009-05-29 12:12:22 +00:00
|
|
|
}
|
2008-05-15 14:37:02 +00:00
|
|
|
|
2010-03-20 15:01:56 +00:00
|
|
|
SharedHandle<RequestGroup> findRequestGroup(gid_t gid) const;
|
2009-05-08 08:36:52 +00:00
|
|
|
|
2009-05-29 12:12:22 +00:00
|
|
|
const std::deque<SharedHandle<RequestGroup> >& getReservedGroups() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return reservedGroups_;
|
2009-05-29 12:12:22 +00:00
|
|
|
}
|
2009-05-08 07:58:50 +00:00
|
|
|
|
2010-03-20 15:01:56 +00:00
|
|
|
SharedHandle<RequestGroup> findReservedGroup(gid_t gid) const;
|
2009-05-09 12:41:37 +00:00
|
|
|
|
2009-12-21 15:17:34 +00:00
|
|
|
enum HOW {
|
|
|
|
POS_SET,
|
|
|
|
POS_CUR,
|
|
|
|
POS_END
|
|
|
|
};
|
|
|
|
|
|
|
|
// Changes the position of download denoted by gid. If how is
|
|
|
|
// POS_SET, it moves the download to a position relative to the
|
|
|
|
// beginning of the queue. If how is POS_CUR, it moves the download
|
|
|
|
// to a position relative to the current position. If how is
|
|
|
|
// POS_END, it moves the download to a position relative to the end
|
|
|
|
// of the queue. If the destination position is less than 0 or
|
|
|
|
// beyond the end of the queue, it moves the download to the
|
|
|
|
// beginning or the end of the queue respectively. Returns the
|
|
|
|
// destination position.
|
2010-03-20 15:01:56 +00:00
|
|
|
size_t changeReservedGroupPosition(gid_t gid, int pos, HOW how);
|
2009-12-21 15:17:34 +00:00
|
|
|
|
2010-03-20 15:01:56 +00:00
|
|
|
bool removeReservedGroup(gid_t gid);
|
2009-05-09 12:41:37 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void showDownloadResults(std::ostream& o) const;
|
2007-05-20 13:57:56 +00:00
|
|
|
|
2007-06-03 14:24:37 +00:00
|
|
|
bool isSameFileBeingDownloaded(RequestGroup* requestGroup) const;
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
TransferStat calculateStat();
|
2008-02-20 16:46:56 +00:00
|
|
|
|
|
|
|
class DownloadStat {
|
|
|
|
private:
|
2010-06-21 13:51:56 +00:00
|
|
|
size_t completed_;
|
|
|
|
size_t error_;
|
|
|
|
size_t inProgress_;
|
|
|
|
size_t waiting_;
|
|
|
|
downloadresultcode::RESULT lastErrorResult_;
|
2008-02-20 16:46:56 +00:00
|
|
|
public:
|
2009-01-12 12:27:34 +00:00
|
|
|
DownloadStat(size_t completed,
|
2010-01-05 16:01:46 +00:00
|
|
|
size_t error,
|
|
|
|
size_t inProgress,
|
|
|
|
size_t waiting,
|
|
|
|
downloadresultcode::RESULT lastErrorResult =
|
|
|
|
downloadresultcode::FINISHED):
|
2010-06-21 13:51:56 +00:00
|
|
|
completed_(completed),
|
|
|
|
error_(error),
|
|
|
|
inProgress_(inProgress),
|
|
|
|
waiting_(waiting),
|
|
|
|
lastErrorResult_(lastErrorResult) {}
|
2009-01-12 12:27:34 +00:00
|
|
|
|
2009-06-29 08:42:58 +00:00
|
|
|
downloadresultcode::RESULT getLastErrorResult() const
|
2009-01-12 12:27:34 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return lastErrorResult_;
|
2009-01-12 12:27:34 +00:00
|
|
|
}
|
2008-02-20 16:46:56 +00:00
|
|
|
|
|
|
|
bool allCompleted() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return error_ == 0 && inProgress_ == 0 && waiting_ == 0;
|
2008-02-20 16:46:56 +00:00
|
|
|
}
|
2009-01-12 12:27:34 +00:00
|
|
|
|
|
|
|
size_t getInProgress() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return inProgress_;
|
2009-01-12 12:27:34 +00:00
|
|
|
}
|
2008-02-20 16:46:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DownloadStat getDownloadStat() const;
|
2008-04-23 10:28:56 +00:00
|
|
|
|
2009-05-29 12:12:22 +00:00
|
|
|
const std::deque<SharedHandle<DownloadResult> >& getDownloadResults() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return downloadResults_;
|
2009-05-29 12:12:22 +00:00
|
|
|
}
|
2008-04-23 10:28:56 +00:00
|
|
|
|
2010-03-20 15:01:56 +00:00
|
|
|
SharedHandle<DownloadResult> findDownloadResult(gid_t gid) const;
|
2009-05-09 12:41:37 +00:00
|
|
|
|
2009-05-14 13:48:26 +00:00
|
|
|
// Removes all download results.
|
|
|
|
void purgeDownloadResult();
|
|
|
|
|
2008-08-04 17:06:47 +00:00
|
|
|
SharedHandle<ServerStat> findServerStat(const std::string& hostname,
|
2010-01-05 16:01:46 +00:00
|
|
|
const std::string& protocol) const;
|
2008-08-04 17:06:47 +00:00
|
|
|
|
2008-09-14 14:25:16 +00:00
|
|
|
SharedHandle<ServerStat> getOrCreateServerStat(const std::string& hostname,
|
2010-01-05 16:01:46 +00:00
|
|
|
const std::string& protocol);
|
2008-08-04 17:06:47 +00:00
|
|
|
|
2008-09-14 14:25:16 +00:00
|
|
|
bool addServerStat(const SharedHandle<ServerStat>& serverStat);
|
2008-08-04 17:06:47 +00:00
|
|
|
|
|
|
|
void updateServerStat();
|
2008-08-10 15:22:55 +00:00
|
|
|
|
|
|
|
bool loadServerStat(const std::string& filename);
|
|
|
|
|
|
|
|
bool saveServerStat(const std::string& filename) const;
|
|
|
|
|
|
|
|
void removeStaleServerStat(time_t timeout);
|
2009-02-28 11:48:26 +00:00
|
|
|
|
|
|
|
// Returns true if current download speed exceeds
|
2010-06-21 13:51:56 +00:00
|
|
|
// maxOverallDownloadSpeedLimit_. Always returns false if
|
|
|
|
// maxOverallDownloadSpeedLimit_ == 0. Otherwise returns false.
|
2009-02-28 11:48:26 +00:00
|
|
|
bool doesOverallDownloadSpeedExceed();
|
|
|
|
|
2009-05-14 15:44:59 +00:00
|
|
|
void setMaxOverallDownloadSpeedLimit(unsigned int speed)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
maxOverallDownloadSpeedLimit_ = speed;
|
2009-05-14 15:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int getMaxOverallDownloadSpeedLimit() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return maxOverallDownloadSpeedLimit_;
|
2009-05-14 15:44:59 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 11:48:26 +00:00
|
|
|
// Returns true if current upload speed exceeds
|
2010-06-21 13:51:56 +00:00
|
|
|
// maxOverallUploadSpeedLimit_. Always returns false if
|
|
|
|
// maxOverallUploadSpeedLimit_ == 0. Otherwise returns false.
|
2009-02-28 11:48:26 +00:00
|
|
|
bool doesOverallUploadSpeedExceed();
|
2009-05-14 15:44:59 +00:00
|
|
|
|
|
|
|
void setMaxOverallUploadSpeedLimit(unsigned int speed)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
maxOverallUploadSpeedLimit_ = speed;
|
2009-05-14 15:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int getMaxOverallUploadSpeedLimit() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return maxOverallUploadSpeedLimit_;
|
2009-05-14 15:44:59 +00:00
|
|
|
}
|
2009-05-30 14:28:18 +00:00
|
|
|
|
|
|
|
void setMaxSimultaneousDownloads(unsigned int max)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
maxSimultaneousDownloads_ = max;
|
2009-05-30 14:28:18 +00:00
|
|
|
}
|
2010-03-05 14:02:23 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
// Call this function if requestGroups_ queue should be maintained.
|
2010-03-05 14:02:23 +00:00
|
|
|
// This function is added to reduce the call of maintenance, but at
|
|
|
|
// the same time, it provides fast maintenance reaction.
|
|
|
|
void requestQueueCheck()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
queueCheck_ = true;
|
2010-03-05 14:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void clearQueueCheck()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
queueCheck_ = false;
|
2010-03-05 14:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool queueCheckRequested() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return queueCheck_;
|
2010-03-05 14:02:23 +00:00
|
|
|
}
|
2010-07-14 14:10:33 +00:00
|
|
|
|
2010-07-15 13:49:02 +00:00
|
|
|
// Returns currently used hosts and its use count.
|
|
|
|
void getUsedHosts(std::vector<std::pair<size_t, std::string> >& usedHosts);
|
2007-05-20 13:57:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef SharedHandle<RequestGroupMan> RequestGroupManHandle;
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|
|
|
|
|
2007-05-20 13:57:56 +00:00
|
|
|
#endif // _D_REQUEST_GROUP_MAN_H_
|