mirror of https://github.com/kiwix/libkiwix.git
Make libaria2 an optional dependency.
We don't compile libaria2 on Windows.
This commit is contained in:
parent
182be5d124
commit
3cf58b5f5b
|
@ -21,7 +21,9 @@
|
|||
#define KIWIX_DOWNLOADER_H
|
||||
|
||||
#include <string>
|
||||
#ifdef ENABLE_LIBARIA2
|
||||
# include <aria2/aria2.h>
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
|
||||
namespace kiwix
|
||||
|
@ -56,14 +58,15 @@ class Downloader
|
|||
private:
|
||||
static pthread_mutex_t globalLock;
|
||||
|
||||
aria2::Session* session;
|
||||
DownloadedFile* fileHandle;
|
||||
std::string tmpDir;
|
||||
|
||||
#ifdef ENABLE_LIBARIA2
|
||||
DownloadedFile* fileHandle;
|
||||
aria2::Session* session;
|
||||
static int downloadEventCallback(aria2::Session* session,
|
||||
aria2::DownloadEvent event,
|
||||
aria2::A2Gid gid,
|
||||
void* userData);
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ thread_dep = dependency('threads')
|
|||
libicu_dep = dependency('icu-i18n', static:static_deps)
|
||||
libzim_dep = dependency('libzim', version : '>=4.0.0', static:static_deps)
|
||||
pugixml_dep = dependency('pugixml', static:static_deps)
|
||||
libaria2_dep = dependency('libaria2', static:static_deps)
|
||||
libaria2_dep = dependency('libaria2', static:static_deps, required:false)
|
||||
|
||||
ctpp2_include_path = ''
|
||||
has_ctpp2_dep = false
|
||||
|
@ -88,6 +88,7 @@ inc = include_directories('include')
|
|||
conf = configuration_data()
|
||||
conf.set('VERSION', '"@0@"'.format(meson.project_version()))
|
||||
conf.set('ENABLE_CTPP2', has_ctpp2_dep)
|
||||
conf.set('ENABLE_LIBARIA2', libaria2_dep.found())
|
||||
|
||||
subdir('include')
|
||||
subdir('scripts')
|
||||
|
@ -95,7 +96,10 @@ subdir('static')
|
|||
subdir('src')
|
||||
subdir('test')
|
||||
|
||||
pkg_requires = ['libzim', 'icu-i18n', 'pugixml', 'libaria2']
|
||||
pkg_requires = ['libzim', 'icu-i18n', 'pugixml']
|
||||
if libaria2_dep.found()
|
||||
pkg_requires += ['libaria2']
|
||||
endif
|
||||
if xapian_dep.found()
|
||||
pkg_requires += ['xapian-core']
|
||||
endif
|
||||
|
|
|
@ -2,3 +2,5 @@
|
|||
#mesondefine VERSION
|
||||
|
||||
#mesondefine ENABLE_CTPP2
|
||||
|
||||
#mesondefine ENABLE_LIBARIA2
|
||||
|
|
|
@ -32,6 +32,7 @@ pthread_mutex_t Downloader::globalLock = PTHREAD_MUTEX_INITIALIZER;
|
|||
/* Constructor */
|
||||
Downloader::Downloader()
|
||||
{
|
||||
#ifdef ENABLE_LIBARIA2
|
||||
aria2::SessionConfig config;
|
||||
config.downloadEventCallback = Downloader::downloadEventCallback;
|
||||
config.userData = this;
|
||||
|
@ -39,17 +40,20 @@ Downloader::Downloader()
|
|||
aria2::KeyVals options;
|
||||
options.push_back(std::pair<std::string, std::string>("dir", tmpDir));
|
||||
session = aria2::sessionNew(options, config);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
Downloader::~Downloader()
|
||||
{
|
||||
#ifdef ENABLE_LIBARIA2
|
||||
aria2::sessionFinal(session);
|
||||
#endif
|
||||
rmdir(tmpDir.c_str());
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_LIBARIA2
|
||||
int Downloader::downloadEventCallback(aria2::Session* session,
|
||||
aria2::DownloadEvent event,
|
||||
aria2::A2Gid gid,
|
||||
|
@ -85,10 +89,12 @@ int Downloader::downloadEventCallback(aria2::Session* session,
|
|||
aria2::deleteDownloadHandle(dh);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
DownloadedFile Downloader::download(const std::string& url) {
|
||||
pthread_mutex_lock(&globalLock);
|
||||
DownloadedFile fileHandle;
|
||||
#ifdef ENABLE_LIBARIA2
|
||||
try {
|
||||
std::vector<std::string> uris = {url};
|
||||
aria2::KeyVals options;
|
||||
|
@ -106,6 +112,7 @@ DownloadedFile Downloader::download(const std::string& url) {
|
|||
} catch (...) {};
|
||||
this->fileHandle = nullptr;
|
||||
pthread_mutex_unlock(&globalLock);
|
||||
#endif
|
||||
return fileHandle;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue