Change the way to receive resulting gids in addUri, addMetalink

pull/89/head
Tatsuhiro Tsujikawa 2013-05-09 21:28:24 +09:00
parent e4996e563b
commit 8940d2aafd
4 changed files with 32 additions and 30 deletions

View File

@ -54,8 +54,7 @@ int main()
// Download files are stored in the current directory // Download files are stored in the current directory
aria2::KeyVals options = { std::make_pair("dir", ".") }; aria2::KeyVals options = { std::make_pair("dir", ".") };
// Add URI // Add URI
aria2::A2Gid gid; aria2::addUri(session, 0, uris, options);
aria2::addUri(session, gid, uris, options);
auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now();
for(;;) { for(;;) {
int rv = aria2::run(session, aria2::RUN_ONCE); int rv = aria2::run(session, aria2::RUN_ONCE);

View File

@ -113,9 +113,8 @@ struct AddUriJob : public Job {
{} {}
virtual void execute(aria2::Session* session) virtual void execute(aria2::Session* session)
{ {
aria2::A2Gid gid;
// TODO check return value // TODO check return value
aria2::addUri(session, gid, uris, options); aria2::addUri(session, 0, uris, options);
} }
std::vector<std::string> uris; std::vector<std::string> uris;
aria2::KeyVals options; aria2::KeyVals options;

View File

@ -226,7 +226,7 @@ void addRequestGroup(const SharedHandle<RequestGroup>& group,
} // namespace } // namespace
int addUri(Session* session, int addUri(Session* session,
A2Gid& gid, A2Gid* gid,
const std::vector<std::string>& uris, const std::vector<std::string>& uris,
const KeyVals& options, const KeyVals& options,
int position) int position)
@ -246,14 +246,16 @@ int addUri(Session* session,
/* ignoreForceSeq = */ true, /* ignoreForceSeq = */ true,
/* ignoreLocalPath = */ true); /* ignoreLocalPath = */ true);
if(!result.empty()) { if(!result.empty()) {
gid = result.front()->getGID();
addRequestGroup(result.front(), e, position); addRequestGroup(result.front(), e, position);
if(gid) {
*gid = result.front()->getGID();
}
} }
return 0; return 0;
} }
int addMetalink(Session* session, int addMetalink(Session* session,
std::vector<A2Gid>& gids, std::vector<A2Gid>* gids,
const std::string& metalinkFile, const std::string& metalinkFile,
const KeyVals& options, const KeyVals& options,
int position) int position)
@ -278,9 +280,11 @@ int addMetalink(Session* session,
} else { } else {
e->getRequestGroupMan()->addReservedGroup(result); e->getRequestGroupMan()->addReservedGroup(result);
} }
for(std::vector<SharedHandle<RequestGroup> >::const_iterator i = if(gids) {
result.begin(), eoi = result.end(); i != eoi; ++i) { for(std::vector<SharedHandle<RequestGroup> >::const_iterator i =
gids.push_back((*i)->getGID()); result.begin(), eoi = result.end(); i != eoi; ++i) {
(*gids).push_back((*i)->getGID());
}
} }
} }
return 0; return 0;

View File

@ -138,33 +138,33 @@ A2Gid hexToGid(const std::string& hex);
bool isNull(const A2Gid& gid); bool isNull(const A2Gid& gid);
// Adds new HTTP(S)/FTP/BitTorrent Magnet URI. On successful return, // Adds new HTTP(S)/FTP/BitTorrent Magnet URI. On successful return,
// the |gid| includes the GID of newly added download. The |uris| // if the |gid| is not NULL, the GID of added download will be
// includes URI to be downloaded. For BitTorrent Magnet URI, the // assigned to the |*gid|. The |uris| includes URI to be downloaded.
// |uris| must have only one element and it should be BitTorrent // For BitTorrent Magnet URI, the |uris| must have only one element
// Magnet URI. URIs in uris must point to the same file. If you mix // and it should be BitTorrent Magnet URI. URIs in uris must point to
// other URIs which point to another file, aria2 does not complain but // the same file. If you mix other URIs which point to another file,
// download may fail. The |options| is a pair of option name and // aria2 does not complain but download may fail. The |options| is a
// value. If the |position| is not negative integer, the new download // pair of option name and value. If the |position| is not negative
// is inserted at position in the waiting queue. If the |position| is // integer, the new download is inserted at position in the waiting
// negative or the |position| is larger than the size of the queue, it // queue. If the |position| is negative or the |position| is larger
// is appended at the end of the queue. This function returns 0 if it // than the size of the queue, it is appended at the end of the queue.
// succeeds, or -1. // This function returns 0 if it succeeds, or -1.
int addUri(Session* session, int addUri(Session* session,
A2Gid& gid, A2Gid* gid,
const std::vector<std::string>& uris, const std::vector<std::string>& uris,
const KeyVals& options, const KeyVals& options,
int position = -1); int position = -1);
// Adds Metalink download. The path to Metalink file is specified by // Adds Metalink download. The path to Metalink file is specified by
// the |metalinkFile|. On successful return, the GID of added // the |metalinkFile|. On successful return, if the |gids| is not
// download is appended to the |gids|. The |options| is a pair of // NULL, the GIDs of added downloads are appended to the |*gids|. The
// option name and value. If the |position| is not negative integer, // |options| is a pair of option name and value. If the |position| is
// the new download is inserted at position in the waiting queue. If // not negative integer, the new download is inserted at position in
// the |position| is negative or the |position| is larger than the // the waiting queue. If the |position| is negative or the |position|
// size of the queue, it is appended at the end of the queue. This // is larger than the size of the queue, it is appended at the end of
// function returns 0 if it succeeds, or -1. // the queue. This function returns 0 if it succeeds, or -1.
int addMetalink(Session* session, int addMetalink(Session* session,
std::vector<A2Gid>& gids, std::vector<A2Gid>* gids,
const std::string& metalinkFile, const std::string& metalinkFile,
const KeyVals& options, const KeyVals& options,
int position = -1); int position = -1);