diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-03-07 08:30:19 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-03-07 08:30:19 +0000 |
| commit | 6ce44b001de112ee1fb08ea77ed9dc7f045cf4c8 (patch) | |
| tree | 59c1ec330f70dd46da5731f5b7fcac613a4153d2 /src | |
| parent | 5fb7197a0828aaeb996e6054a50ebdc35d8653f0 (diff) | |
2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added getServers XML-RPC method.
* doc/aria2c.1.txt
* src/FileEntry.h
* src/XmlRpcMethodFactory.cc
* src/XmlRpcMethodImpl.cc
* src/XmlRpcMethodImpl.h
Diffstat (limited to 'src')
| -rw-r--r-- | src/FileEntry.h | 5 | ||||
| -rw-r--r-- | src/XmlRpcMethodFactory.cc | 2 | ||||
| -rw-r--r-- | src/XmlRpcMethodImpl.cc | 45 | ||||
| -rw-r--r-- | src/XmlRpcMethodImpl.h | 11 |
4 files changed, 63 insertions, 0 deletions
diff --git a/src/FileEntry.h b/src/FileEntry.h index 0017c925..ab4b4f51 100644 --- a/src/FileEntry.h +++ b/src/FileEntry.h @@ -212,6 +212,11 @@ public: return _requestPool.size(); } + const std::deque<SharedHandle<Request> >& getInFlightRequests() const + { + return _inFlightRequests; + } + bool operator<(const FileEntry& fileEntry) const; bool exists() const; diff --git a/src/XmlRpcMethodFactory.cc b/src/XmlRpcMethodFactory.cc index 0374f2da..2a5a5f73 100644 --- a/src/XmlRpcMethodFactory.cc +++ b/src/XmlRpcMethodFactory.cc @@ -73,6 +73,8 @@ XmlRpcMethodFactory::create(const std::string& methodName) else if(methodName == GetPeersXmlRpcMethod::getMethodName()) { return SharedHandle<XmlRpcMethod>(new GetPeersXmlRpcMethod()); #endif // ENABLE_BITTORRENT + } else if(methodName == GetServersXmlRpcMethod::getMethodName()) { + return SharedHandle<XmlRpcMethod>(new GetServersXmlRpcMethod()); } else if(methodName == TellActiveXmlRpcMethod::getMethodName()) { return SharedHandle<XmlRpcMethod>(new TellActiveXmlRpcMethod()); } else if(methodName == TellWaitingXmlRpcMethod::getMethodName()) { diff --git a/src/XmlRpcMethodImpl.cc b/src/XmlRpcMethodImpl.cc index facc4ada..a2663ce8 100644 --- a/src/XmlRpcMethodImpl.cc +++ b/src/XmlRpcMethodImpl.cc @@ -112,6 +112,7 @@ const std::string KEY_PATH = "path"; const std::string KEY_SELECTED = "selected"; const std::string KEY_LENGTH = "length"; const std::string KEY_URI = "uri"; +const std::string KEY_CURRENT_URI = "currentUri"; const std::string KEY_VERSION = "version"; const std::string KEY_ENABLED_FEATURES = "enabledFeatures"; const std::string KEY_METHOD_NAME = "methodName"; @@ -127,6 +128,7 @@ const std::string KEY_ANNOUNCE_LIST = "announceList"; const std::string KEY_COMMENT = "comment"; const std::string KEY_CREATION_DATE = "creationDate"; const std::string KEY_MODE = "mode"; +const std::string KEY_SERVERS = "servers"; } static BDE createGIDResponse(int32_t gid) @@ -880,6 +882,49 @@ BDE GetSessionInfoXmlRpcMethod::process return result; } +BDE GetServersXmlRpcMethod::process +(const XmlRpcRequest& req, DownloadEngine* e) +{ + const BDE& params = req._params; + assert(params.isList()); + + if(params.empty() || !params[0].isString()) { + throw DL_ABORT_EX("Bad request"); + } + int32_t gid = util::parseInt(params[0].s()); + SharedHandle<RequestGroup> group = e->_requestGroupMan->findRequestGroup(gid); + if(group.isNull()) { + throw DL_ABORT_EX(StringFormat("No active download for GID#%d", gid).str()); + } + SharedHandle<DownloadContext> dctx = group->getDownloadContext(); + const std::vector<SharedHandle<FileEntry> >& files = dctx->getFileEntries(); + BDE result = BDE::list(); + size_t index = 1; + for(std::vector<SharedHandle<FileEntry> >::const_iterator fi = files.begin(), + eoi = files.end(); fi != eoi; ++fi, ++index) { + BDE fileEntry = BDE::dict(); + fileEntry[KEY_INDEX] = util::uitos(index); + BDE servers = BDE::list(); + const std::deque<SharedHandle<Request> >& requests = + (*fi)->getInFlightRequests(); + for(std::deque<SharedHandle<Request> >::const_iterator ri =requests.begin(), + eoi = requests.end(); ri != eoi; ++ri) { + SharedHandle<PeerStat> ps = (*ri)->getPeerStat(); + if(!ps.isNull()) { + BDE serverEntry = BDE::dict(); + serverEntry[KEY_URI] = (*ri)->getUrl(); + serverEntry[KEY_CURRENT_URI] = (*ri)->getCurrentUrl(); + serverEntry[KEY_DOWNLOAD_SPEED] = + util::uitos(ps->calculateDownloadSpeed()); + servers << serverEntry; + } + } + fileEntry[KEY_SERVERS] = servers; + result << fileEntry; + } + return result; +} + BDE ChangeUriXmlRpcMethod::process (const XmlRpcRequest& req, DownloadEngine* e) { diff --git a/src/XmlRpcMethodImpl.h b/src/XmlRpcMethodImpl.h index fe10ea7f..cd393910 100644 --- a/src/XmlRpcMethodImpl.h +++ b/src/XmlRpcMethodImpl.h @@ -156,6 +156,17 @@ public: }; #endif // ENABLE_BITTORRENT +class GetServersXmlRpcMethod:public XmlRpcMethod { +protected: + virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e); +public: + static const std::string& getMethodName() + { + static std::string methodName = "aria2.getServers"; + return methodName; + } +}; + class TellStatusXmlRpcMethod:public XmlRpcMethod { protected: virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e); |
