2010-04-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added aria2.pause and aria2.unpause XML-RPC method.  aria2.pause
	pauses the download denoted by gid. gid is of type string.  The
	status of paused download becomes "paused" and the download is
	placed on the first position of waiting queue. As long as the
	status is "paused", the download is not started. To change status
	to "waiting", use aria2.unpause method. This method returns GID of
	paused download.  aria2.unpause changes the status of the download
	denoted by gid from "paused" to "waiting". This makes the download
	eligible to restart. gid is of type string. This method returns
	GID of unpaused download.
	* doc/aria2c.1.txt
	* src/DownloadContext.cc
	* src/FileEntry.cc
	* src/OptionHandlerFactory.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/RequestGroupMan.cc
	* src/XmlRpcMethodFactory.cc
	* src/XmlRpcMethodImpl.cc
	* src/XmlRpcMethodImpl.h
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
pull/1/head
Tatsuhiro Tsujikawa 2010-04-08 16:02:22 +00:00
parent 5cd0108f93
commit bf0cf1f5d9
16 changed files with 274 additions and 42 deletions

View File

@ -1,3 +1,29 @@
2010-04-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added aria2.pause and aria2.unpause XML-RPC method. aria2.pause
pauses the download denoted by gid. gid is of type string. The
status of paused download becomes "paused" and the download is
placed on the first position of waiting queue. As long as the
status is "paused", the download is not started. To change status
to "waiting", use aria2.unpause method. This method returns GID of
paused download. aria2.unpause changes the status of the download
denoted by gid from "paused" to "waiting". This makes the download
eligible to restart. gid is of type string. This method returns
GID of unpaused download.
* doc/aria2c.1.txt
* src/DownloadContext.cc
* src/FileEntry.cc
* src/OptionHandlerFactory.cc
* src/RequestGroup.cc
* src/RequestGroup.h
* src/RequestGroupMan.cc
* src/XmlRpcMethodFactory.cc
* src/XmlRpcMethodImpl.cc
* src/XmlRpcMethodImpl.h
* src/prefs.cc
* src/prefs.h
* src/usage_text.h
2010-04-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added --save-session=FILE option. This option saves

View File

@ -2,12 +2,12 @@
.\" Title: aria2c
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
.\" Date: 04/08/2010
.\" Date: 04/09/2010
.\" Manual: Aria2 Manual
.\" Source: Aria2 1.9.1a
.\" Language: English
.\"
.TH "ARIA2C" "1" "04/08/2010" "Aria2 1\&.9\&.1a" "Aria2 Manual"
.TH "ARIA2C" "1" "04/09/2010" "Aria2 1\&.9\&.1a" "Aria2 Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@ -1225,6 +1225,14 @@ option\&. Possible Values:
\fI/path/to/command\fR
.RE
.PP
\fB\-\-on\-download\-pause\fR=COMMAND
.RS 4
Set the command to be executed when download is paused\&. See
\fB\-\-on\-download\-start\fR
option for the requirement of COMMAND\&. Possible Values:
\fI/path/to/command\fR
.RE
.PP
\fB\-\-on\-download\-start\fR=COMMAND
.RS 4
Set the command to be executed when download starts up\&. COMMAND must take just one argument and GID is passed to COMMAND as a first argument\&. Possible Values:
@ -2607,11 +2615,11 @@ This method adds new HTTP(S)/FTP/BitTorrent Magnet URI\&. \fIuris\fR is of type
.sp
\fBaria2\&.addTorrent\fR \fItorrent[, uris[, options[, position]]]\fR
.sp
This method adds BitTorrent download by uploading \&.torrent file\&. If you want to add BitTorrent Magnet URI, use \fBaria2\&.addUri\fR method instead\&. \fItorrent\fR is of type base64 which contains Base64\-encoded \&.torrent file\&. \fIuris\fR is of type array and its element is URI which is of type string\&. \fIuris\fR is used for Web\-seeding\&. For single file torrents, URI can be a complete URI pointing to the resource or if URI ends with /, name in torrent file is added\&. For multi\-file torrents, name and path in torrent are added to form a URI for each file\&. \fIoptions\fR is of type struct and its members are a pair of option name and value\&. See \fBOptions\fR below for more details\&. If \fIposition\fR is given as an integer starting from 0, the new download is inserted at \fIposition\fR in the waiting queue\&. If \fIposition\fR is not given or \fIposition\fR is larger than the size of the queue, it is appended at the end of the queue\&. This method returns GID of registered download\&.
This method adds BitTorrent download by uploading \&.torrent file\&. If you want to add BitTorrent Magnet URI, use \fBaria2\&.addUri\fR method instead\&. \fItorrent\fR is of type base64 which contains Base64\-encoded \&.torrent file\&. \fIuris\fR is of type array and its element is URI which is of type string\&. \fIuris\fR is used for Web\-seeding\&. For single file torrents, URI can be a complete URI pointing to the resource or if URI ends with /, name in torrent file is added\&. For multi\-file torrents, name and path in torrent are added to form a URI for each file\&. \fIoptions\fR is of type struct and its members are a pair of option name and value\&. See \fBOptions\fR below for more details\&. If \fIposition\fR is given as an integer starting from 0, the new download is inserted at \fIposition\fR in the waiting queue\&. If \fIposition\fR is not given or \fIposition\fR is larger than the size of the queue, it is appended at the end of the queue\&. This method returns GID of registered download\&. Please note that the downloads added by this method are not saved by \fB\-\-save\-session\fR\&.
.sp
\fBaria2\&.addMetalink\fR \fImetalink[, options[, position]]\fR
.sp
This method adds Metalink download by uploading \&.metalink file\&. \fImetalink\fR is of type base64 which contains Base64\-encoded \&.metalink file\&. \fIoptions\fR is of type struct and its members are a pair of option name and value\&. See \fBOptions\fR below for more details\&. If \fIposition\fR is given as an integer starting from 0, the new download is inserted at \fIposition\fR in the waiting queue\&. If \fIposition\fR is not given or \fIposition\fR is larger than the size of the queue, it is appended at the end of the queue\&. This method returns array of GID of registered download\&.
This method adds Metalink download by uploading \&.metalink file\&. \fImetalink\fR is of type base64 which contains Base64\-encoded \&.metalink file\&. \fIoptions\fR is of type struct and its members are a pair of option name and value\&. See \fBOptions\fR below for more details\&. If \fIposition\fR is given as an integer starting from 0, the new download is inserted at \fIposition\fR in the waiting queue\&. If \fIposition\fR is not given or \fIposition\fR is larger than the size of the queue, it is appended at the end of the queue\&. This method returns array of GID of registered download\&. Please note that the downloads added by this method are not saved by \fB\-\-save\-session\fR\&.
.sp
\fBaria2\&.remove\fR \fIgid\fR
.sp
@ -2621,6 +2629,14 @@ This method removes the download denoted by \fIgid\fR\&. \fIgid\fR is of type st
.sp
This method removes the download denoted by \fIgid\fR\&. This method behaves just like \fBaria2\&.remove\fR except that this method removes download without any action which takes time such as contacting BitTorrent tracker\&.
.sp
\fBaria2\&.pause\fR \fIgid\fR
.sp
This method pauses the download denoted by \fIgid\fR\&. \fIgid\fR is of type string\&. The status of paused download becomes "paused" and the download is placed on the first position of waiting queue\&. As long as the status is "paused", the download is not started\&. To change status to "waiting", use \fBaria2\&.unpause\fR method\&. This method returns GID of paused download\&.
.sp
\fBaria2\&.unpause\fR \fIgid\fR
.sp
This method changes the status of the download denoted by \fIgid\fR from "paused" to "waiting"\&. This makes the download eligible to restart\&. \fIgid\fR is of type string\&. This method returns GID of unpaused download\&.
.sp
\fBaria2\&.tellStatus\fR \fIgid\fR
.sp
This method returns download progress of the download denoted by \fIgid\fR\&. \fIgid\fR is of type string\&. The response is of type struct and it contains following keys\&. The value type is string\&.
@ -2632,7 +2648,7 @@ GID of this download\&.
.PP
status
.RS 4
"active" for currently downloading/seeding entry\&. "waiting" for the entry in the queue; download is not started\&. "error" for the stopped download because of error\&. "complete" for the stopped and completed download\&. "removed" for the download removed by user\&.
"active" for currently downloading/seeding entry\&. "waiting" for the entry in the queue; download is not started\&. "paused" for the paused entry\&. "error" for the stopped download because of error\&. "complete" for the stopped and completed download\&. "removed" for the download removed by user\&.
.RE
.PP
totalLength
@ -2894,7 +2910,7 @@ This method returns the list of active downloads\&. The response is of type arra
.sp
\fBaria2\&.tellWaiting\fR \fIoffset, num\fR
.sp
This method returns the list of waiting download\&. \fIoffset\fR is of type integer and specifies the offset from the download waiting at the front\&. \fInum\fR is of type integer and specifies the number of downloads to be returned\&.
This method returns the list of waiting download, including paused downloads\&. \fIoffset\fR is of type integer and specifies the offset from the download waiting at the front\&. \fInum\fR is of type integer and specifies the number of downloads to be returned\&.
.sp
If offset is a positive integer, this method returns downloads in the range of [\fIoffset\fR, \fIoffset\fR+\fInum\fR)\&.
.sp

View File

@ -2050,6 +2050,16 @@ name.</td>
</p>
</dd>
<dt class="hdlist1">
<strong>--on-download-pause</strong>=COMMAND
</dt>
<dd>
<p>
Set the command to be executed when download is paused. See
<strong>--on-download-start</strong> option for the requirement of COMMAND.
Possible Values: <em>/path/to/command</em>
</p>
</dd>
<dt class="hdlist1">
<strong>--on-download-start</strong>=COMMAND
</dt>
<dd>
@ -3066,7 +3076,9 @@ and value. See <strong>Options</strong> below for more details. If <em>position
given as an integer starting from 0, the new download is inserted at
<em>position</em> in the waiting queue. If <em>position</em> is not given or
<em>position</em> is larger than the size of the queue, it is appended at the
end of the queue. This method returns GID of registered download.</p></div>
end of the queue. This method returns GID of registered download.
Please note that the downloads added by this method are not saved by
<strong>--save-session</strong>.</p></div>
<div class="paragraph"><p><strong>aria2.addMetalink</strong> <em>metalink[, options[, position]]</em></p></div>
<div class="paragraph"><p>This method adds Metalink download by uploading .metalink file.
<em>metalink</em> is of type base64 which contains Base64-encoded .metalink
@ -3076,7 +3088,8 @@ option name and value. See <strong>Options</strong> below for more details. If
inserted at <em>position</em> in the waiting queue. If <em>position</em> is not
given or <em>position</em> is larger than the size of the queue, it is
appended at the end of the queue. This method returns array of GID of
registered download.</p></div>
registered download. Please note that the downloads added by this
method are not saved by <strong>--save-session</strong>.</p></div>
<div class="paragraph"><p><strong>aria2.remove</strong> <em>gid</em></p></div>
<div class="paragraph"><p>This method removes the download denoted by <em>gid</em>. <em>gid</em> is of type
string. If specified download is in progress, it is stopped at
@ -3087,6 +3100,18 @@ returns GID of removed download.</p></div>
behaves just like <strong>aria2.remove</strong> except that this method removes
download without any action which takes time such as contacting
BitTorrent tracker.</p></div>
<div class="paragraph"><p><strong>aria2.pause</strong> <em>gid</em></p></div>
<div class="paragraph"><p>This method pauses the download denoted by <em>gid</em>. <em>gid</em> is of type
string. The status of paused download becomes "paused" and the
download is placed on the first position of waiting queue. As long as
the status is "paused", the download is not started. To change status
to "waiting", use <strong>aria2.unpause</strong> method.
This method returns GID of paused download.</p></div>
<div class="paragraph"><p><strong>aria2.unpause</strong> <em>gid</em></p></div>
<div class="paragraph"><p>This method changes the status of the download denoted by <em>gid</em> from
"paused" to "waiting". This makes the download eligible to restart.
<em>gid</em> is of type string. This method returns GID of unpaused
download.</p></div>
<div class="paragraph"><p><strong>aria2.tellStatus</strong> <em>gid</em></p></div>
<div class="paragraph"><p>This method returns download progress of the download denoted by
<em>gid</em>. <em>gid</em> is of type string. The response is of type struct and it
@ -3106,9 +3131,10 @@ status
<dd>
<p>
"active" for currently downloading/seeding entry. "waiting" for the
entry in the queue; download is not started. "error" for the stopped
download because of error. "complete" for the stopped and completed
download. "removed" for the download removed by user.
entry in the queue; download is not started. "paused" for the
paused entry. "error" for the stopped download because of
error. "complete" for the stopped and completed download. "removed"
for the download removed by user.
</p>
</dd>
<dt class="hdlist1">
@ -3531,10 +3557,10 @@ downloadSpeed
type array and its element is the same struct returned by
<strong>aria2.tellStatus</strong> method.</p></div>
<div class="paragraph"><p><strong>aria2.tellWaiting</strong> <em>offset, num</em></p></div>
<div class="paragraph"><p>This method returns the list of waiting download. <em>offset</em> is of type
integer and specifies the offset from the download waiting at the
front. <em>num</em> is of type integer and specifies the number of downloads
to be returned.</p></div>
<div class="paragraph"><p>This method returns the list of waiting download, including paused
downloads. <em>offset</em> is of type integer and specifies the offset from
the download waiting at the front. <em>num</em> is of type integer and
specifies the number of downloads to be returned.</p></div>
<div class="paragraph"><p>If offset is a positive integer, this method returns downloads in the
range of [<em>offset</em>, <em>offset</em>+<em>num</em>).</p></div>
<div class="paragraph"><p><em>offset</em> can be a negative integer. <em>offset</em> == -1 points last
@ -4148,7 +4174,7 @@ files in the program, then also delete it here.</p></div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
Last updated 2010-04-08 21:48:17 JST
Last updated 2010-04-09 00:32:31 JST
</div>
</div>
</body>

View File

@ -832,6 +832,12 @@ name.
See also *--on-download-stop* option. Possible Values:
'/path/to/command'
*--on-download-pause*=COMMAND::
Set the command to be executed when download is paused. See
*--on-download-start* option for the requirement of COMMAND.
Possible Values: '/path/to/command'
*--on-download-start*=COMMAND::
Set the command to be executed when download starts up. COMMAND must
@ -1332,6 +1338,8 @@ given as an integer starting from 0, the new download is inserted at
'position' in the waiting queue. If 'position' is not given or
'position' is larger than the size of the queue, it is appended at the
end of the queue. This method returns GID of registered download.
Please note that the downloads added by this method are not saved by
*--save-session*.
*aria2.addMetalink* 'metalink[, options[, position]]'
@ -1343,7 +1351,8 @@ option name and value. See *Options* below for more details. If
inserted at 'position' in the waiting queue. If 'position' is not
given or 'position' is larger than the size of the queue, it is
appended at the end of the queue. This method returns array of GID of
registered download.
registered download. Please note that the downloads added by this
method are not saved by *--save-session*.
*aria2.remove* 'gid'
@ -1359,6 +1368,22 @@ behaves just like *aria2.remove* except that this method removes
download without any action which takes time such as contacting
BitTorrent tracker.
*aria2.pause* 'gid'
This method pauses the download denoted by 'gid'. 'gid' is of type
string. The status of paused download becomes "paused" and the
download is placed on the first position of waiting queue. As long as
the status is "paused", the download is not started. To change status
to "waiting", use *aria2.unpause* method.
This method returns GID of paused download.
*aria2.unpause* 'gid'
This method changes the status of the download denoted by 'gid' from
"paused" to "waiting". This makes the download eligible to restart.
'gid' is of type string. This method returns GID of unpaused
download.
*aria2.tellStatus* 'gid'
This method returns download progress of the download denoted by
@ -1372,9 +1397,10 @@ gid::
status::
"active" for currently downloading/seeding entry. "waiting" for the
entry in the queue; download is not started. "error" for the stopped
download because of error. "complete" for the stopped and completed
download. "removed" for the download removed by user.
entry in the queue; download is not started. "paused" for the
paused entry. "error" for the stopped download because of
error. "complete" for the stopped and completed download. "removed"
for the download removed by user.
totalLength::
@ -1617,10 +1643,10 @@ type array and its element is the same struct returned by
*aria2.tellWaiting* 'offset, num'
This method returns the list of waiting download. 'offset' is of type
integer and specifies the offset from the download waiting at the
front. 'num' is of type integer and specifies the number of downloads
to be returned.
This method returns the list of waiting download, including paused
downloads. 'offset' is of type integer and specifies the offset from
the download waiting at the front. 'num' is of type integer and
specifies the number of downloads to be returned.
If offset is a positive integer, this method returns downloads in the
range of ['offset', 'offset'+'num').
@ -1871,7 +1897,7 @@ aria2 uses 5 connections to download 1 file by default.
-s1 limits the number of connections to just 1.
[NOTE]
To pause a download, press Ctrl-C. You can resume the transfer by running aria2c with the same argument in the same directory. You can change URIs as long as they are pointing to the same file.
To stop a download, press Ctrl-C. You can resume the transfer by running aria2c with the same argument in the same directory. You can change URIs as long as they are pointing to the same file.
Download a file from 2 different HTTP servers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -1938,7 +1964,7 @@ Download using a local metalink file
aria2c -p --lowest-speed-limit=4000 file.metalink
----------------------------------------------------------
[NOTE]
To pause a download, press Ctrl-C.
To stop a download, press Ctrl-C.
You can resume the transfer by running aria2c with the same argument in the same
directory.
@ -1979,7 +2005,7 @@ aria2c --max-upload-limit=40K file.torrent
--max-upload-limit specifies the max of upload rate.
[NOTE]
To pause a download, press Ctrl-C. You can resume the transfer by running aria2c with the same argument in the same directory.
To stop a download, press Ctrl-C. You can resume the transfer by running aria2c with the same argument in the same directory.
Download using BitTorrent Magnet URI
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -69,6 +69,7 @@ DownloadContext::DownloadContext(size_t pieceLength,
void DownloadContext::resetDownloadStartTime()
{
_downloadStartTime = global::wallclock;
_downloadStopTime.setTimeInSec(0);
}
void DownloadContext::resetDownloadStopTime()

View File

@ -333,7 +333,6 @@ void FileEntry::releaseRuntimeResource()
{
_requestPool.clear();
_inFlightRequests.clear();
_uriResults.clear();
}
template<typename InputIterator, typename T>

View File

@ -383,6 +383,16 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
op->addTag(TAG_HOOK);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new DefaultOptionHandler
(PREF_ON_DOWNLOAD_PAUSE,
TEXT_ON_DOWNLOAD_PAUSE,
NO_DEFAULT_VALUE,
"/path/to/command"));
op->addTag(TAG_ADVANCED);
op->addTag(TAG_HOOK);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new DefaultOptionHandler
(PREF_ON_DOWNLOAD_START,

View File

@ -122,6 +122,7 @@ RequestGroup::RequestGroup(const SharedHandle<Option>& option):
_haltRequested(false),
_forceHaltRequested(false),
_haltReason(RequestGroup::NONE),
_pauseRequested(false),
_uriSelector(new InOrderURISelector()),
_lastModifiedTime(Time::null()),
_fileNotFoundCount(0),
@ -861,6 +862,7 @@ void RequestGroup::setHaltRequested(bool f, HaltReason haltReason)
{
_haltRequested = f;
if(_haltRequested) {
_pauseRequested = false;
_haltReason = haltReason;
}
#ifdef ENABLE_BITTORRENT
@ -876,6 +878,11 @@ void RequestGroup::setForceHaltRequested(bool f, HaltReason haltReason)
_forceHaltRequested = f;
}
void RequestGroup::setPauseRequested(bool f)
{
_pauseRequested = f;
}
void RequestGroup::releaseRuntimeResource(DownloadEngine* e)
{
#ifdef ENABLE_BITTORRENT
@ -884,6 +891,9 @@ void RequestGroup::releaseRuntimeResource(DownloadEngine* e)
if(!_pieceStorage.isNull()) {
_pieceStorage->removeAdvertisedPiece(0);
}
_segmentMan.reset();
_pieceStorage.reset();
_progressInfoFile.reset();
_downloadContext->releaseRuntimeResource();
}

View File

@ -123,6 +123,8 @@ private:
HaltReason _haltReason;
bool _pauseRequested;
std::vector<SharedHandle<PreDownloadHandler> > _preDownloadHandlers;
std::vector<SharedHandle<PostDownloadHandler> > _postDownloadHandlers;
@ -343,6 +345,13 @@ public:
return _forceHaltRequested;
}
void setPauseRequested(bool f);
bool isPauseRequested() const
{
return _pauseRequested;
}
void dependsOn(const SharedHandle<Dependency>& dep);
bool isDependencyResolved();

View File

@ -291,11 +291,12 @@ static void executeHook(const std::string& command, gid_t gid)
#endif
}
static void executeStartHook
(const SharedHandle<RequestGroup>& group, const Option* option)
static void executeHookByOptName
(const SharedHandle<RequestGroup>& group, const Option* option,
const std::string& opt)
{
if(!option->blank(PREF_ON_DOWNLOAD_START)) {
executeHook(option->get(PREF_ON_DOWNLOAD_START), group->getGID());
if(!option->blank(opt)) {
executeHook(option->get(opt), group->getGID());
}
}
@ -317,6 +318,7 @@ class ProcessStoppedRequestGroup {
private:
DownloadEngine* _e;
std::deque<SharedHandle<DownloadResult> >& _downloadResults;
std::deque<SharedHandle<RequestGroup> >& _reservedGroups;
Logger* _logger;
void saveSignature(const SharedHandle<RequestGroup>& group)
@ -337,9 +339,11 @@ private:
public:
ProcessStoppedRequestGroup
(DownloadEngine* e,
std::deque<SharedHandle<DownloadResult> >& downloadResults):
std::deque<SharedHandle<DownloadResult> >& downloadResults,
std::deque<SharedHandle<RequestGroup> >& reservedGroups):
_e(e),
_downloadResults(downloadResults),
_reservedGroups(reservedGroups),
_logger(LogFactory::getInstance()) {}
void operator()(const SharedHandle<RequestGroup>& group)
@ -358,6 +362,7 @@ public:
try {
group->closeFile();
if(group->downloadFinished()) {
group->setPauseRequested(false);
group->applyLastModifiedTimeToLocalFiles();
group->reportDownloadFinished();
if(group->allDownloadFinished()) {
@ -382,12 +387,22 @@ public:
} catch(RecoverableException& ex) {
_logger->error(EX_EXCEPTION_CAUGHT, ex);
}
group->releaseRuntimeResource(_e);
if(group->isPauseRequested()) {
_reservedGroups.push_front(group);
} else {
_downloadResults.push_back(group->createDownloadResult());
}
group->releaseRuntimeResource(_e);
if(group->isPauseRequested()) {
group->setForceHaltRequested(false);
executeHookByOptName(group, _e->option, PREF_ON_DOWNLOAD_PAUSE);
// TODO Should we have to prepend spend uris to remaining uris
// in case PREF_REUSE_URI is disabed?
} else {
executeStopHook(_downloadResults.back(), _e->option);
}
}
}
};
class CollectServerStat {
@ -452,8 +467,8 @@ void RequestGroupMan::removeStoppedGroup(DownloadEngine* e)
updateServerStat();
std::for_each(_requestGroups.begin(), _requestGroups.end(),
ProcessStoppedRequestGroup(e, _downloadResults));
ProcessStoppedRequestGroup
(e, _downloadResults, _reservedGroups));
std::deque<SharedHandle<RequestGroup> >::iterator i =
std::remove_if(_requestGroups.begin(),
_requestGroups.end(),
@ -509,7 +524,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
_reservedGroups.pop_front();
std::vector<Command*> commands;
try {
if(!groupToAdd->isDependencyResolved()) {
if(groupToAdd->isPauseRequested()||!groupToAdd->isDependencyResolved()) {
temp.push_back(groupToAdd);
continue;
}
@ -523,7 +538,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
++count;
e->addCommand(commands);
commands.clear();
executeStartHook(groupToAdd, e->option);
executeHookByOptName(groupToAdd, e->option, PREF_ON_DOWNLOAD_START);
} catch(RecoverableException& ex) {
_logger->error(EX_EXCEPTION_CAUGHT, ex);
if(_logger->debug()) {
@ -660,6 +675,16 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const
}
o << formatDownloadResult(status, result) << "\n";
}
for(std::deque<SharedHandle<RequestGroup> >::const_iterator itr =
_reservedGroups.begin(), eoi = _reservedGroups.end();
itr != eoi; ++itr) {
if(!(*itr)->isPauseRequested()) {
continue;
}
SharedHandle<DownloadResult> result = (*itr)->createDownloadResult();
++inpr;
o << formatDownloadResult(MARK_INPR, result) << "\n";
}
if(ok > 0 || err > 0 || inpr > 0) {
o << "\n"
<< _("Status Legend:") << "\n";

View File

@ -58,6 +58,10 @@ XmlRpcMethodFactory::create(const std::string& methodName)
}
else if(methodName == RemoveXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new RemoveXmlRpcMethod());
} else if(methodName == PauseXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new PauseXmlRpcMethod());
} else if(methodName == UnpauseXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new UnpauseXmlRpcMethod());
} else if(methodName == ForceRemoveXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ForceRemoveXmlRpcMethod());
} else if(methodName == ChangePositionXmlRpcMethod::getMethodName()) {

View File

@ -83,6 +83,7 @@ const BDE BDE_FALSE = BDE("false");
const BDE BDE_OK = BDE("OK");
const BDE BDE_ACTIVE = BDE("active");
const BDE BDE_WAITING = BDE("waiting");
const BDE BDE_PAUSED = BDE("paused");
const BDE BDE_REMOVED = BDE("removed");
const BDE BDE_ERROR = BDE("error");
const BDE BDE_COMPLETE = BDE("complete");
@ -336,6 +337,48 @@ BDE ForceRemoveXmlRpcMethod::process
return removeDownload(req, e, true);
}
BDE PauseXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
{
const BDE& params = req._params;
assert(params.isList());
if(params.empty() || !params[0].isString()) {
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
}
gid_t gid = util::parseLLInt(params[0].s());
SharedHandle<RequestGroup> group = e->_requestGroupMan->findRequestGroup(gid);
if(group.isNull() || group->isHaltRequested()) {
throw DL_ABORT_EX
(StringFormat("GID#%s cannot be paused now",
util::itos(gid).c_str()).str());
} else {
// Call setHaltRequested before setPauseRequested because
// setHaltRequested calls setPauseRequested(false) internally.
group->setHaltRequested(true, RequestGroup::USER_REQUEST);
group->setPauseRequested(true);
}
return createGIDResponse(gid);
}
BDE UnpauseXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
{
const BDE& params = req._params;
assert(params.isList());
if(params.empty() || !params[0].isString()) {
throw DL_ABORT_EX(MSG_GID_NOT_PROVIDED);
}
gid_t gid = util::parseLLInt(params[0].s());
SharedHandle<RequestGroup> group =e->_requestGroupMan->findReservedGroup(gid);
if(group.isNull() || !group->isPauseRequested()) {
throw DL_ABORT_EX
(StringFormat("GID#%s cannot be unpaused now",
util::itos(gid).c_str()).str());
} else {
group->setPauseRequested(false);
e->_requestGroupMan->requestQueueCheck();
}
return createGIDResponse(gid);
}
static void createUriEntry(BDE& uriList, const SharedHandle<FileEntry>& file)
{
{
@ -668,8 +711,12 @@ BDE TellStatusXmlRpcMethod::process
util::itos(gid).c_str()).str());
}
gatherStoppedDownload(entryDict, ds);
} else {
if(group->isPauseRequested()) {
entryDict[KEY_STATUS] = BDE_PAUSED;
} else {
entryDict[KEY_STATUS] = BDE_WAITING;
}
gatherProgress(entryDict, group, e);
}
} else {
@ -705,7 +752,11 @@ void TellWaitingXmlRpcMethod::createEntry
(BDE& entryDict, const SharedHandle<RequestGroup>& item,
DownloadEngine* e) const
{
if(item->isPauseRequested()) {
entryDict[KEY_STATUS] = BDE_PAUSED;
} else {
entryDict[KEY_STATUS] = BDE_WAITING;
}
gatherProgress(entryDict, item, e);
}

View File

@ -84,6 +84,28 @@ public:
}
};
class PauseXmlRpcMethod:public XmlRpcMethod {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
static std::string methodName = "aria2.pause";
return methodName;
}
};
class UnpauseXmlRpcMethod:public XmlRpcMethod {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
static std::string methodName = "aria2.unpause";
return methodName;
}
};
#ifdef ENABLE_BITTORRENT
class AddTorrentXmlRpcMethod:public XmlRpcMethod {
protected:

View File

@ -167,6 +167,7 @@ const std::string PREF_XML_RPC_PASSWD("xml-rpc-passwd");
const std::string PREF_XML_RPC_MAX_REQUEST_SIZE("xml-rpc-max-request-size");
// value: string
const std::string PREF_ON_DOWNLOAD_START("on-download-start");
const std::string PREF_ON_DOWNLOAD_PAUSE("on-download-pause");
const std::string PREF_ON_DOWNLOAD_STOP("on-download-stop");
const std::string PREF_ON_DOWNLOAD_COMPLETE("on-download-complete");
const std::string PREF_ON_DOWNLOAD_ERROR("on-download-error");

View File

@ -171,6 +171,7 @@ extern const std::string PREF_XML_RPC_PASSWD;
extern const std::string PREF_XML_RPC_MAX_REQUEST_SIZE;
// value: string
extern const std::string PREF_ON_DOWNLOAD_START;
extern const std::string PREF_ON_DOWNLOAD_PAUSE;
extern const std::string PREF_ON_DOWNLOAD_STOP;
extern const std::string PREF_ON_DOWNLOAD_COMPLETE;
extern const std::string PREF_ON_DOWNLOAD_ERROR;

View File

@ -547,6 +547,11 @@
_(" --on-download-start=COMMAND Set the command to be executed when download\n" \
" starts up. COMMAND must take just one argument and\n" \
" GID is passed to COMMAND as a first argument.")
#define TEXT_ON_DOWNLOAD_PAUSE \
_(" --on-download-pause=COMMAND Set the command to be executed when download\n" \
" is paused.\n"\
" See --on-download-start option for the\n" \
" requirement of COMMAND.")
#define TEXT_ON_DOWNLOAD_ERROR \
_(" --on-download-error=COMMAND Set the command to be executed when download\n" \
" aborts due to error.\n" \