Browse Source

Add gidToString and getActiveDownload API functions

Tatsuhiro Tsujikawa 12 năm trước cách đây
mục cha
commit
28849e3ddf
2 tập tin đã thay đổi với 24 bổ sung1 xóa
  1. 18 0
      src/aria2api.cc
  2. 6 1
      src/includes/aria2/aria2.h

+ 18 - 0
src/aria2api.cc

@@ -107,6 +107,11 @@ int run(Session* session, RUN_MODE mode)
   return e->run(mode == RUN_ONCE);
 }
 
+std::string gidToString(const A2Gid& gid)
+{
+  return GroupId::toHex(gid);
+}
+
 namespace {
 template<typename InputIterator, typename Pred>
 void apiGatherOption
@@ -182,6 +187,19 @@ int addUri(Session* session,
   return 0;
 }
 
+std::vector<A2Gid> getActiveDownload(Session* session)
+{
+  const SharedHandle<DownloadEngine>& e =
+    session->context->reqinfo->getDownloadEngine();
+  const RequestGroupList& groups = e->getRequestGroupMan()->getRequestGroups();
+  std::vector<A2Gid> res;
+  for(RequestGroupList::const_iterator i = groups.begin(),
+        eoi = groups.end(); i != eoi; ++i) {
+    res.push_back((*i)->getGID());
+  }
+  return res;
+}
+
 namespace {
 struct RequestGroupDH : public DownloadHandle {
   RequestGroupDH(const SharedHandle<RequestGroup>& group)

+ 6 - 1
src/includes/aria2/aria2.h

@@ -106,6 +106,9 @@ enum RUN_MODE {
 // function one or more time to complete downloads.
 int run(Session* session, RUN_MODE mode);
 
+// Returns textual representation of the |gid|.
+std::string gidToString(const A2Gid& gid);
+
 // This method adds new HTTP(S)/FTP/BitTorrent Magnet URI.  On
 // successful return, the |gid| includes the GID of newly added
 // download.  The |uris| includes URI to be downloaded.  For
@@ -124,7 +127,9 @@ int addUri(Session* session,
            const KeyVals& options,
            int position = -1);
 
-// Query download
+// Returns the array of active download GID.
+std::vector<A2Gid> getActiveDownload(Session* session);
+
 enum DOWNLOAD_STATUS {
   DOWNLOAD_ACTIVE,
   DOWNLOAD_WAITING,