Compare commits

..

2 Commits

Author SHA1 Message Date
Matthieu Gautier
c092759185 New version 13.0.0 2023-07-31 16:58:17 +02:00
Matthieu Gautier
8c2c46ab0a Update Changelog and meson.build with changes from version 12.1.1 2023-07-31 16:58:17 +02:00
4 changed files with 22 additions and 16 deletions

View File

@@ -1,3 +1,9 @@
libkiwix 13.0.0
===============
* This version is mainly a re-releasing of 12.1.0 with a new major version
as there is a API break in this version.
libkiwix 12.1.1
===============

View File

@@ -184,7 +184,7 @@ class Downloader
* @param options: A series of pair <option_name, option_value> to pass to aria.
* @return: The newly created Download.
*/
Download* startDownload(const std::string& uri, const std::vector<std::pair<std::string, std::string>>& options = {});
std::shared_ptr<Download> startDownload(const std::string& uri, const std::vector<std::pair<std::string, std::string>>& options = {});
/**
* Get a download corrsponding to a download id (did)
@@ -194,7 +194,7 @@ class Downloader
* @return: The Download corresponding to did.
* @throw: Throw std::out_of_range if did is not found.
*/
Download* getDownload(const std::string& did);
std::shared_ptr<Download> getDownload(const std::string& did);
/**
* Get the number of downloads currently managed.
@@ -204,11 +204,11 @@ class Downloader
/**
* Get the ids of the managed downloads.
*/
std::vector<std::string> getDownloadIds();
std::vector<std::string> getDownloadIds() const;
private:
mutable std::mutex m_lock;
std::map<std::string, std::unique_ptr<Download>> m_knownDownloads;
std::map<std::string, std::shared_ptr<Download>> m_knownDownloads;
std::shared_ptr<Aria2> mp_aria;
};
}

View File

@@ -1,5 +1,5 @@
project('libkiwix', 'cpp',
version : '12.1.1',
version : '13.0.0',
license : 'GPLv3+',
default_options : ['c_std=c11', 'cpp_std=c++11', 'werror=true'])

View File

@@ -157,7 +157,7 @@ void Downloader::close()
mp_aria->close();
}
std::vector<std::string> Downloader::getDownloadIds() {
std::vector<std::string> Downloader::getDownloadIds() const {
std::unique_lock<std::mutex> lock(m_lock);
std::vector<std::string> ret;
for(auto& p:m_knownDownloads) {
@@ -166,37 +166,37 @@ std::vector<std::string> Downloader::getDownloadIds() {
return ret;
}
Download* Downloader::startDownload(const std::string& uri, const std::vector<std::pair<std::string, std::string>>& options)
std::shared_ptr<Download> Downloader::startDownload(const std::string& uri, const std::vector<std::pair<std::string, std::string>>& options)
{
std::unique_lock<std::mutex> lock(m_lock);
for (auto& p: m_knownDownloads) {
auto& d = p.second;
auto& uris = d->getUris();
if (std::find(uris.begin(), uris.end(), uri) != uris.end())
return d.get();
return d;
}
std::vector<std::string> uris = {uri};
auto gid = mp_aria->addUri(uris, options);
m_knownDownloads[gid] = std::unique_ptr<Download>(new Download(mp_aria, gid));
return m_knownDownloads[gid].get();
m_knownDownloads[gid] = std::make_shared<Download>(mp_aria, gid);
return m_knownDownloads[gid];
}
Download* Downloader::getDownload(const std::string& did)
std::shared_ptr<Download> Downloader::getDownload(const std::string& did)
{
std::unique_lock<std::mutex> lock(m_lock);
try {
return m_knownDownloads.at(did).get();
return m_knownDownloads.at(did);
} catch(std::exception& e) {
for (auto gid : mp_aria->tellWaiting()) {
if (gid == did) {
m_knownDownloads[gid] = std::unique_ptr<Download>(new Download(mp_aria, gid));
return m_knownDownloads[gid].get();
m_knownDownloads[gid] = std::make_shared<Download>(mp_aria, gid);
return m_knownDownloads[gid];
}
}
for (auto gid : mp_aria->tellActive()) {
if (gid == did) {
m_knownDownloads[gid] = std::unique_ptr<Download>(new Download(mp_aria, gid));
return m_knownDownloads[gid].get();
m_knownDownloads[gid] = std::make_shared<Download>(mp_aria, gid);
return m_knownDownloads[gid];
}
}
throw e;