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

Added aria2.shutdown and aria2.forceShutdown XML-RPC method.
	These methods, as their name implies, shutdown aria2.  These
	methods are useful for Windows because it lacks signal mechanism.
	* doc/aria2c.1.txt
	* src/TimedHaltCommand.cc
	* src/XmlRpcMethodFactory.cc
	* src/XmlRpcMethodImpl.cc
	* src/XmlRpcMethodImpl.h
pull/1/head
Tatsuhiro Tsujikawa 2010-04-02 14:50:33 +00:00
parent 730f7449ae
commit 919255b4db
8 changed files with 86 additions and 1 deletions

View File

@ -1,3 +1,14 @@
2010-04-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added aria2.shutdown and aria2.forceShutdown XML-RPC method.
These methods, as their name implies, shutdown aria2. These
methods are useful for Windows because it lacks signal mechanism.
* doc/aria2c.1.txt
* src/TimedHaltCommand.cc
* src/XmlRpcMethodFactory.cc
* src/XmlRpcMethodImpl.cc
* src/XmlRpcMethodImpl.h
2010-04-02 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added forceHalt argument to TimedHaltCommand.

View File

@ -2899,6 +2899,14 @@ sessionId
Session ID, which is generated each time when aria2 is invoked\&.
.RE
.sp
\fBaria2\&.shutdown\fR
.sp
This method shutdowns aria2\&. This method returns "OK"\&.
.sp
\fBaria2\&.forceShutdown\fR
.sp
This method shutdowns aria2\&. This method behaves like \fBaria2\&.shutdown\fR except that any actions which takes time such as contacting BitTorrent tracker are skipped\&. This method returns "OK"\&.
.sp
\fBsystem\&.multicall\fR \fImethods\fR
.sp
This methods encapsulates multiple method calls in a single request\&. \fImethods\fR is of type array and its element is struct\&. The struct contains two keys: "methodName" and "params"\&. "methodName" is the method name to call and "params" is array containing parameters to the method\&. This method returns array of responses\&. The element of array will either be a one\-item array containing the return value of each method call or struct of fault element if an encapsulated method call fails\&.

View File

@ -3610,6 +3610,12 @@ sessionId
</p>
</dd>
</dl></div>
<div class="paragraph"><p><strong>aria2.shutdown</strong></p></div>
<div class="paragraph"><p>This method shutdowns aria2. This method returns "OK".</p></div>
<div class="paragraph"><p><strong>aria2.forceShutdown</strong></p></div>
<div class="paragraph"><p>This method shutdowns aria2. This method behaves like <strong>aria2.shutdown</strong>
except that any actions which takes time such as contacting BitTorrent
tracker are skipped. This method returns "OK".</p></div>
<div class="paragraph"><p><strong>system.multicall</strong> <em>methods</em></p></div>
<div class="paragraph"><p>This methods encapsulates multiple method calls in a single request.
<em>methods</em> is of type array and its element is struct. The struct
@ -4106,7 +4112,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-02 23:04:52 JST
Last updated 2010-04-02 23:42:11 JST
</div>
</div>
</body>

View File

@ -1732,6 +1732,16 @@ sessionId::
Session ID, which is generated each time when aria2 is invoked.
*aria2.shutdown*
This method shutdowns aria2. This method returns "OK".
*aria2.forceShutdown*
This method shutdowns aria2. This method behaves like *aria2.shutdown*
except that any actions which takes time such as contacting BitTorrent
tracker are skipped. This method returns "OK".
*system.multicall* 'methods'
This methods encapsulates multiple method calls in a single request.

View File

@ -61,6 +61,7 @@ void TimedHaltCommand::process()
if(!_e->isHaltRequested()) {
logger->notice(MSG_TIME_HAS_PASSED, _interval);
if(_forceHalt) {
logger->notice("This is emergency shutdown.");
_e->requestForceHalt();
} else {
_e->requestHalt();

View File

@ -97,6 +97,10 @@ XmlRpcMethodFactory::create(const std::string& methodName)
return SharedHandle<XmlRpcMethod>(new GetVersionXmlRpcMethod());
} else if(methodName == GetSessionInfoXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new GetSessionInfoXmlRpcMethod());
} else if(methodName == ShutdownXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ShutdownXmlRpcMethod());
} else if(methodName == ForceShutdownXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new ForceShutdownXmlRpcMethod());
} else if(methodName == SystemMulticallXmlRpcMethod::getMethodName()) {
return SharedHandle<XmlRpcMethod>(new SystemMulticallXmlRpcMethod());
} else {

View File

@ -38,6 +38,7 @@
#include <algorithm>
#include "Logger.h"
#include "LogFactory.h"
#include "BDE.h"
#include "DlAbortEx.h"
#include "Option.h"
@ -62,6 +63,7 @@
#include "XmlRpcMethodFactory.h"
#include "XmlRpcResponse.h"
#include "SegmentMan.h"
#include "TimedHaltCommand.h"
#ifdef ENABLE_BITTORRENT
# include "bittorrent_helper.h"
# include "BtRegistry.h"
@ -1008,6 +1010,27 @@ BDE ChangeUriXmlRpcMethod::process
return res;
}
static BDE goingShutdown
(const XmlRpcRequest& req, DownloadEngine* e, bool forceHalt)
{
// Schedule shutdown after 3seconds to give time to client to
// receive XML-RPC response.
e->addRoutineCommand(new TimedHaltCommand(e->newCUID(), e, 3, forceHalt));
LogFactory::getInstance()->info("Scheduled shutdown in 3 seconds.");
return BDE_OK;
}
BDE ShutdownXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
{
return goingShutdown(req, e, false);
}
BDE ForceShutdownXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
{
return goingShutdown(req, e, true);
}
BDE SystemMulticallXmlRpcMethod::process
(const XmlRpcRequest& req, DownloadEngine* e)
{

View File

@ -385,6 +385,28 @@ public:
}
};
class ShutdownXmlRpcMethod:public XmlRpcMethod {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
static std::string methodName = "aria2.shutdown";
return methodName;
}
};
class ForceShutdownXmlRpcMethod:public XmlRpcMethod {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
public:
static const std::string& getMethodName()
{
static std::string methodName = "aria2.forceShutdown";
return methodName;
}
};
class SystemMulticallXmlRpcMethod:public XmlRpcMethod {
protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);