فهرست منبع

Add accessors for DownloadHandle

Added downloadGetBitfield, downloadGetNumPieces,
downloadGetConnections, downloadGetErrorCode,
downloadGetFollowedBy, downloadGetBelongsTo and
downloadGetDir functions.
Tatsuhiro Tsujikawa 12 سال پیش
والد
کامیت
1df4adefb5
3فایلهای تغییر یافته به همراه113 افزوده شده و 0 حذف شده
  1. 99 0
      src/aria2api.cc
  2. 7 0
      src/aria2api.h
  3. 7 0
      src/includes/aria2/aria2.h

+ 99 - 0
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

+ 7 - 0
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

+ 7 - 0
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