Parcourir la source

Implement DownloadResultDH::getOption()/getOptions()

Tatsuhiro Tsujikawa il y a 12 ans
Parent
commit
e4bf9b9cc5
2 fichiers modifiés avec 27 ajouts et 16 suppressions
  1. 27 12
      src/aria2api.cc
  2. 0 4
      src/includes/aria2/aria2.h

+ 27 - 12
src/aria2api.cc

@@ -661,6 +661,29 @@ void pushRequestOption
 }
 } // namespace
 
+namespace {
+const std::string& getRequestOption(const SharedHandle<Option>& option,
+                                    const std::string& name)
+{
+  const Pref* pref = option::k2p(name);
+  if(OptionParser::getInstance()->find(pref)) {
+    return option->get(pref);
+  } else {
+    return A2STR::NIL;
+  }
+}
+} // namespace
+
+namespace {
+KeyVals getRequestOptions(const SharedHandle<Option>& option)
+{
+  KeyVals res;
+  pushRequestOption(std::back_inserter(res), option,
+                    OptionParser::getInstance());
+  return res;
+}
+} // namespace
+
 namespace {
 struct RequestGroupDH : public DownloadHandle {
   RequestGroupDH(const SharedHandle<RequestGroup>& group)
@@ -800,19 +823,11 @@ struct RequestGroupDH : public DownloadHandle {
   }
   virtual const std::string& getOption(const std::string& name)
   {
-    const Pref* pref = option::k2p(name);
-    if(OptionParser::getInstance()->find(pref)) {
-      return group->getOption()->get(pref);
-    } else {
-      return A2STR::NIL;
-    }
+    return getRequestOption(group->getOption(), name);
   }
   virtual KeyVals getOptions()
   {
-    KeyVals res;
-    pushRequestOption(std::back_inserter(res), group->getOption(),
-                      OptionParser::getInstance());
-    return res;
+    return getRequestOptions(group->getOption());
   }
   SharedHandle<RequestGroup> group;
   TransferStat ts;
@@ -917,11 +932,11 @@ struct DownloadResultDH : public DownloadHandle {
   }
   virtual const std::string& getOption(const std::string& name)
   {
-    return A2STR::NIL;
+    return getRequestOption(dr->option, name);
   }
   virtual KeyVals getOptions()
   {
-    return KeyVals();
+    return getRequestOptions(dr->option);
   }
   SharedHandle<DownloadResult> dr;
 };

+ 0 - 4
src/includes/aria2/aria2.h

@@ -867,10 +867,6 @@ public:
    * not return options which have no default value and have not been
    * set by :func:`sessionNew()`, configuration files or API
    * functions.
-   *
-   * Calling this function for the download which is not in
-   * :c:macro:`DOWNLOAD_ACTIVE`, :c:macro:`DOWNLOAD_PAUSED` or
-   * :c:macro:`DOWNLOAD_WAITING` will return empty array.
    */
   virtual KeyVals getOptions() = 0;
 };