diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2014-02-19 22:02:50 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2014-02-19 22:02:50 +0900 |
| commit | a8319a8b7893601f88fb03c896ce1163211815e7 (patch) | |
| tree | 3097c41bbab46b7c2d7cabec1199359dfa4abff4 | |
| parent | 1a24020e6371f6ee43b75bfb8372faf57d8487b9 (diff) | |
Add aria2.saveSession RPC method
This method saves the current session to a file specified by
--save-session option. This method returns "OK" if it succeeds.
| -rw-r--r-- | doc/manual-src/en/aria2c.rst | 6 | ||||
| -rwxr-xr-x | doc/xmlrpc/aria2rpc | 3 | ||||
| -rw-r--r-- | src/RpcMethodFactory.cc | 2 | ||||
| -rw-r--r-- | src/RpcMethodImpl.cc | 18 | ||||
| -rw-r--r-- | src/RpcMethodImpl.h | 11 |
5 files changed, 40 insertions, 0 deletions
diff --git a/doc/manual-src/en/aria2c.rst b/doc/manual-src/en/aria2c.rst index e595ff24..8e56600d 100644 --- a/doc/manual-src/en/aria2c.rst +++ b/doc/manual-src/en/aria2c.rst @@ -3209,6 +3209,12 @@ For *secret* parameter, see :ref:`rpc_auth`. except that any actions which takes time such as contacting BitTorrent tracker are skipped. This method returns ``OK``. +.. function:: aria2.saveSession([secret]) + + This method saves the current session to a file specified by + :option:`--save-session` option. This method returns ``OK`` if it + succeeds. + .. function:: system.multicall(methods) This methods encapsulates multiple method calls in a single request. diff --git a/doc/xmlrpc/aria2rpc b/doc/xmlrpc/aria2rpc index 646d5df7..cc5bd2b6 100755 --- a/doc/xmlrpc/aria2rpc +++ b/doc/xmlrpc/aria2rpc @@ -273,6 +273,7 @@ Usage: #{program_name} addUri URI... [options] #{program_name} shutdown [options] #{program_name} forceShutdown [options] #{program_name} getGlobalStat [options] + #{program_name} saveSession [options] #{program_name} appendUri GID fileIndex URI... [options] This command calls aria2.changeUri(GID, fileIndex, [], [URI,...]) internally. @@ -394,6 +395,8 @@ elsif command == "forceShutdown" then result=client_call(client, secret, "aria2."+command) elsif command == "getGlobalStat" then result=client_call(client, secret, "aria2."+command) +elsif command == "saveSession" then + result=client_call(client, secret, "aria2."+command) elsif command == "appendUri" then result=client_call(client, secret, "aria2.changeUri", resources[0], resources[1].to_i(), [], resources[2..-1]) diff --git a/src/RpcMethodFactory.cc b/src/RpcMethodFactory.cc index 8813a17b..7cc919de 100644 --- a/src/RpcMethodFactory.cc +++ b/src/RpcMethodFactory.cc @@ -126,6 +126,8 @@ createMethod(const std::string& methodName) return make_unique<ForceShutdownRpcMethod>(); } else if(methodName == GetGlobalStatRpcMethod::getMethodName()) { return make_unique<GetGlobalStatRpcMethod>(); + } else if(methodName == SaveSessionRpcMethod::getMethodName()) { + return make_unique<SaveSessionRpcMethod>(); } else if(methodName == SystemMulticallRpcMethod::getMethodName()) { return make_unique<SystemMulticallRpcMethod>(); } else { diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index 00cdcb27..824ab2a1 100644 --- a/src/RpcMethodImpl.cc +++ b/src/RpcMethodImpl.cc @@ -65,6 +65,7 @@ #include "PeerStat.h" #include "base64.h" #include "BitfieldMan.h" +#include "SessionSerializer.h" #ifdef ENABLE_MESSAGE_DIGEST # include "MessageDigest.h" # include "message_digest_helper.h" @@ -1347,6 +1348,23 @@ std::unique_ptr<ValueBase> GetGlobalStatRpcMethod::process return std::move(res); } +std::unique_ptr<ValueBase> SaveSessionRpcMethod::process +(const RpcRequest& req, DownloadEngine* e) +{ + const std::string& filename = e->getOption()->get(PREF_SAVE_SESSION); + if(filename.empty()) { + throw DL_ABORT_EX("Filename is not given."); + } + SessionSerializer sessionSerializer(e->getRequestGroupMan().get()); + if(sessionSerializer.save(filename)) { + A2_LOG_NOTICE(fmt(_("Serialized session to '%s' successfully."), + filename.c_str())); + return createOKResponse(); + } + throw DL_ABORT_EX(fmt("Failed to serialize session to '%s'.", + filename.c_str())); +} + std::unique_ptr<ValueBase> SystemMulticallRpcMethod::process (const RpcRequest& req, DownloadEngine* e) { diff --git a/src/RpcMethodImpl.h b/src/RpcMethodImpl.h index b20087ae..ac349896 100644 --- a/src/RpcMethodImpl.h +++ b/src/RpcMethodImpl.h @@ -567,6 +567,17 @@ public: } }; +class SaveSessionRpcMethod:public RpcMethod { +protected: + virtual std::unique_ptr<ValueBase> process + (const RpcRequest& req, DownloadEngine* e) CXX11_OVERRIDE; +public: + static const char* getMethodName() + { + return "aria2.saveSession"; + } +}; + class SystemMulticallRpcMethod:public RpcMethod { protected: virtual std::unique_ptr<ValueBase> process |
