diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-04-30 22:42:23 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-04-30 22:42:23 +0900 |
| commit | 1df4adefb58cf904caa1fea55ca35944b847a820 (patch) | |
| tree | d7e12d76177eb8fb15c5ec9625d5e56610ead10c | |
| parent | d1252dcc5f7ff889f1bb6e331f214a1f30049693 (diff) | |
Add accessors for DownloadHandle
Added downloadGetBitfield, downloadGetNumPieces,
downloadGetConnections, downloadGetErrorCode,
downloadGetFollowedBy, downloadGetBelongsTo and
downloadGetDir functions.
| -rw-r--r-- | src/aria2api.cc | 99 | ||||
| -rw-r--r-- | src/aria2api.h | 7 | ||||
| -rw-r--r-- | src/includes/aria2/aria2.h | 7 |
3 files changed, 113 insertions, 0 deletions
diff --git a/src/aria2api.cc b/src/aria2api.cc index e1d70e13..f42ca5ed 100644 --- a/src/aria2api.cc +++ b/src/aria2api.cc @@ -50,6 +50,8 @@ #include "prefs.h" #include "download_helper.h" #include "LogFactory.h" +#include "PieceStorage.h" +#include "DownloadContext.h" namespace aria2 { @@ -231,6 +233,16 @@ struct RequestGroupDH : public DownloadHandle { { return ts.allTimeUploadLength; } + virtual std::string getBitfield() + { + const SharedHandle<PieceStorage>& ps = group->getPieceStorage(); + if(ps) { + return std::string(reinterpret_cast<const char*>(ps->getBitfield()), + ps->getBitfieldLength()); + } else { + return ""; + } + } virtual int getDownloadSpeed() { return ts.downloadSpeed; @@ -239,6 +251,30 @@ struct RequestGroupDH : public DownloadHandle { { return ts.uploadSpeed; } + virtual size_t getNumPieces() + { + return group->getDownloadContext()->getNumPieces(); + } + virtual int getConnections() + { + return group->getNumConnection(); + } + virtual int getErrorCode() + { + return 0; + } + virtual const std::vector<A2Gid>& getFollowedBy() + { + return group->followedBy(); + } + virtual A2Gid getBelongsTo() + { + return group->belongsTo(); + } + virtual const std::string& getDir() + { + return group->getOption()->get(PREF_DIR); + } SharedHandle<RequestGroup> group; TransferStat ts; }; @@ -273,6 +309,10 @@ struct DownloadResultDH : public DownloadHandle { { return dr->uploadLength; } + virtual std::string getBitfield() + { + return dr->bitfield; + } virtual int getDownloadSpeed() { return 0; @@ -281,6 +321,30 @@ struct DownloadResultDH : public DownloadHandle { { return 0; } + virtual size_t getNumPieces() + { + return dr->numPieces; + } + virtual int getConnections() + { + return 0; + } + virtual int getErrorCode() + { + return dr->result; + } + virtual const std::vector<A2Gid>& getFollowedBy() + { + return dr->followedBy; + } + virtual A2Gid getBelongsTo() + { + return dr->belongsTo; + } + virtual const std::string& getDir() + { + return dr->dir; + } SharedHandle<DownloadResult> dr; }; } // namespace @@ -327,6 +391,11 @@ int64_t downloadGetUploadLength(DownloadHandle* dh) return dh->getUploadLength(); } +std::string downloadGetBitfield(DownloadHandle* dh) +{ + return dh->getBitfield(); +} + int downloadGetDownloadSpeed(DownloadHandle* dh) { return dh->getDownloadSpeed(); @@ -337,4 +406,34 @@ int downloadGetUploadSpeed(DownloadHandle* dh) return dh->getUploadSpeed(); } +size_t downloadGetNumPieces(DownloadHandle* dh) +{ + return dh->getNumPieces(); +} + +int downloadGetConnections(DownloadHandle* dh) +{ + return dh->getConnections(); +} + +int downloadGetErrorCode(DownloadHandle* dh) +{ + return dh->getErrorCode(); +} + +const std::vector<A2Gid>& downloadGetFollowedBy(DownloadHandle* dh) +{ + return dh->getFollowedBy(); +} + +A2Gid downloadGetBelongsTo(DownloadHandle* dh) +{ + return dh->getBelongsTo(); +} + +const std::string& downloadGetDir(DownloadHandle* dh) +{ + return dh->getDir(); +} + } // namespace aria2 diff --git a/src/aria2api.h b/src/aria2api.h index 82fb7436..51217d49 100644 --- a/src/aria2api.h +++ b/src/aria2api.h @@ -56,8 +56,15 @@ struct DownloadHandle { virtual int64_t getTotalLength() = 0; virtual int64_t getCompletedLength() = 0; virtual int64_t getUploadLength() = 0; + virtual std::string getBitfield() = 0; virtual int getDownloadSpeed() = 0; virtual int getUploadSpeed() = 0; + virtual size_t getNumPieces() = 0; + virtual int getConnections() = 0; + virtual int getErrorCode() = 0; + virtual const std::vector<A2Gid>& getFollowedBy() = 0; + virtual A2Gid getBelongsTo() = 0; + virtual const std::string& getDir() = 0; }; } // namespace aria2 diff --git a/src/includes/aria2/aria2.h b/src/includes/aria2/aria2.h index 881b3974..63b952fd 100644 --- a/src/includes/aria2/aria2.h +++ b/src/includes/aria2/aria2.h @@ -156,8 +156,15 @@ DOWNLOAD_STATUS downloadGetStatus(DownloadHandle* dh); int64_t downloadGetTotalLength(DownloadHandle* dh); int64_t downloadGetCompletedLength(DownloadHandle* dh); int64_t downloadGetUploadLength(DownloadHandle* dh); +std::string downloadGetBitfield(DownloadHandle* dh); int downloadGetDownloadSpeed(DownloadHandle* dh); int downloadGetUploadSpeed(DownloadHandle* dh); +size_t downloadGetNumPieces(DownloadHandle* dh); +int downloadGetConnections(DownloadHandle* dh); +int downloadGetErrorCode(DownloadHandle* dh); +const std::vector<A2Gid>& downloadGetFollowedBy(DownloadHandle* dh); +A2Gid downloadGetBelongsTo(DownloadHandle* dh); +const std::string& downloadGetDir(DownloadHandle* dh); } // namespace aria2 |
