diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-04-02 14:50:33 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-04-02 14:50:33 +0000 |
| commit | 919255b4db38c67ea79d67646daf8670fb2f0be3 (patch) | |
| tree | 1dbb2437bee73b987a3613e5f5ddc731213db780 | |
| parent | 730f7449aefd5537709dcec64a2ef9973a2bc595 (diff) | |
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
| -rw-r--r-- | ChangeLog | 11 | ||||
| -rw-r--r-- | doc/aria2c.1 | 8 | ||||
| -rw-r--r-- | doc/aria2c.1.html | 8 | ||||
| -rw-r--r-- | doc/aria2c.1.txt | 10 | ||||
| -rw-r--r-- | src/TimedHaltCommand.cc | 1 | ||||
| -rw-r--r-- | src/XmlRpcMethodFactory.cc | 4 | ||||
| -rw-r--r-- | src/XmlRpcMethodImpl.cc | 23 | ||||
| -rw-r--r-- | src/XmlRpcMethodImpl.h | 22 |
8 files changed, 86 insertions, 1 deletions
@@ -1,5 +1,16 @@ 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. Added requestForceHalt() to DownloadEngine. * src/DownloadEngine.cc diff --git a/doc/aria2c.1 b/doc/aria2c.1 index 74ff51ac..f8255184 100644 --- a/doc/aria2c.1 +++ b/doc/aria2c.1 @@ -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\&. diff --git a/doc/aria2c.1.html b/doc/aria2c.1.html index a60137e8..6e21262b 100644 --- a/doc/aria2c.1.html +++ b/doc/aria2c.1.html @@ -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>
diff --git a/doc/aria2c.1.txt b/doc/aria2c.1.txt index acb344f2..1f431700 100644 --- a/doc/aria2c.1.txt +++ b/doc/aria2c.1.txt @@ -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. diff --git a/src/TimedHaltCommand.cc b/src/TimedHaltCommand.cc index 25f1deaf..6013cd2a 100644 --- a/src/TimedHaltCommand.cc +++ b/src/TimedHaltCommand.cc @@ -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(); diff --git a/src/XmlRpcMethodFactory.cc b/src/XmlRpcMethodFactory.cc index 2a5a5f73..45f174aa 100644 --- a/src/XmlRpcMethodFactory.cc +++ b/src/XmlRpcMethodFactory.cc @@ -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 { diff --git a/src/XmlRpcMethodImpl.cc b/src/XmlRpcMethodImpl.cc index ef9325ab..ed364ef7 100644 --- a/src/XmlRpcMethodImpl.cc +++ b/src/XmlRpcMethodImpl.cc @@ -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) { diff --git a/src/XmlRpcMethodImpl.h b/src/XmlRpcMethodImpl.h index cd393910..69fa7f36 100644 --- a/src/XmlRpcMethodImpl.h +++ b/src/XmlRpcMethodImpl.h @@ -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); |
