diff --git a/src/aria2api.cc b/src/aria2api.cc index e1d70e13e..f42ca5ed2 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& ps = group->getPieceStorage(); + if(ps) { + return std::string(reinterpret_cast(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& getFollowedBy() + { + return group->followedBy(); + } + virtual A2Gid getBelongsTo() + { + return group->belongsTo(); + } + virtual const std::string& getDir() + { + return group->getOption()->get(PREF_DIR); + } SharedHandle 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& getFollowedBy() + { + return dr->followedBy; + } + virtual A2Gid getBelongsTo() + { + return dr->belongsTo; + } + virtual const std::string& getDir() + { + return dr->dir; + } SharedHandle 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& 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 82fb7436a..51217d49d 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& 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 881b3974c..63b952fd0 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& downloadGetFollowedBy(DownloadHandle* dh); +A2Gid downloadGetBelongsTo(DownloadHandle* dh); +const std::string& downloadGetDir(DownloadHandle* dh); } // namespace aria2