Compare commits

...

4 Commits

Author SHA1 Message Date
Matthieu Gautier
45b3cfca16 Merge pull request #999 from kiwix/const-abi 2023-09-14 13:42:43 +02:00
Kunal Mehta
65b3c8442f Revert ABI breakage in kiwix::Downloader::getDownloadIds()
Changing it to be `const` is an ABI change since the symbol changes from
`_ZN5...` to `_ZNK5...` (addition of "K").

The other changes made in 18b7b5f27 are probably fine to keep since they
don't appear to be used from what I can tell.

Fixes https://github.com/kiwix/libkiwix/issues/998.
2023-09-14 13:20:41 +02:00
Matthieu Gautier
e461f2b437 New version 12.1.1 2023-07-31 16:50:30 +02:00
Matthieu Gautier
313ecc3f19 Revert "Make Downloader return shared_ptr instead of raw pointer."
This reverts commit 0e612de4d1.
2023-07-27 15:31:07 +02:00
4 changed files with 21 additions and 16 deletions

View File

@@ -1,3 +1,8 @@
libkiwix 12.1.1
===============
* Revert API break introduced in libkiwix 12.1.0
libkiwix 12.1.0
===============

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.
*/
std::shared_ptr<Download> startDownload(const std::string& uri, const std::vector<std::pair<std::string, std::string>>& options = {});
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.
*/
std::shared_ptr<Download> getDownload(const std::string& did);
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() const;
std::vector<std::string> getDownloadIds();
private:
mutable std::mutex m_lock;
std::map<std::string, std::shared_ptr<Download>> m_knownDownloads;
std::map<std::string, std::unique_ptr<Download>> m_knownDownloads;
std::shared_ptr<Aria2> mp_aria;
};
}

View File

@@ -1,5 +1,5 @@
project('libkiwix', 'cpp',
version : '12.1.0',
version : '12.1.1',
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() const {
std::vector<std::string> Downloader::getDownloadIds() {
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() const {
return ret;
}
std::shared_ptr<Download> Downloader::startDownload(const std::string& uri, const std::vector<std::pair<std::string, std::string>>& options)
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;
return d.get();
}
std::vector<std::string> uris = {uri};
auto gid = mp_aria->addUri(uris, options);
m_knownDownloads[gid] = std::make_shared<Download>(mp_aria, gid);
return m_knownDownloads[gid];
m_knownDownloads[gid] = std::unique_ptr<Download>(new Download(mp_aria, gid));
return m_knownDownloads[gid].get();
}
std::shared_ptr<Download> Downloader::getDownload(const std::string& did)
Download* Downloader::getDownload(const std::string& did)
{
std::unique_lock<std::mutex> lock(m_lock);
try {
return m_knownDownloads.at(did);
return m_knownDownloads.at(did).get();
} catch(std::exception& e) {
for (auto gid : mp_aria->tellWaiting()) {
if (gid == did) {
m_knownDownloads[gid] = std::make_shared<Download>(mp_aria, gid);
return m_knownDownloads[gid];
m_knownDownloads[gid] = std::unique_ptr<Download>(new Download(mp_aria, gid));
return m_knownDownloads[gid].get();
}
}
for (auto gid : mp_aria->tellActive()) {
if (gid == did) {
m_knownDownloads[gid] = std::make_shared<Download>(mp_aria, gid);
return m_knownDownloads[gid];
m_knownDownloads[gid] = std::unique_ptr<Download>(new Download(mp_aria, gid));
return m_knownDownloads[gid].get();
}
}
throw e;