Ardour  9.0-pre0-350-gf17a656217
downloader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include <atomic>
22 #include <string>
23 
24 #include <curl/curl.h>
25 
26 #include "pbd/libpbd_visibility.h"
27 
28 namespace PBD {
29 
30 class Thread;
31 
33  public:
34  Downloader (std::string const & url, std::string const & destdir);
36 
37  int start ();
38  void cleanup ();
39  void cancel ();
40  double progress() const;
41 
42  uint64_t download_size() const { return _download_size; }
43  uint64_t downloaded () const { return _downloaded; }
44 
45  /* public so it can be called from a static C function */
46  size_t write (void *contents, size_t size, size_t nmemb);
47 
48  int status() const { return _status; }
49  std::string download_path() const;
50 
51  private:
52  std::string url;
53  std::string destdir;
54  std::string file_path;
56  CURL* curl;
57  bool _cancel;
58  std::atomic<uint64_t> _download_size; /* read-only from requestor thread */
59  std::atomic<uint64_t> _downloaded; /* read-only from requestor thread */
60  std::atomic<int> _status;
62 
63  void download ();
64 };
65 
66 } /* namespace */
67 
double progress() const
uint64_t downloaded() const
Definition: downloader.h:43
std::string url
Definition: downloader.h:52
std::string file_path
Definition: downloader.h:54
uint64_t download_size() const
Definition: downloader.h:42
int status() const
Definition: downloader.h:48
std::atomic< int > _status
Definition: downloader.h:60
PBD::Thread * thread
Definition: downloader.h:61
std::string download_path() const
size_t write(void *contents, size_t size, size_t nmemb)
std::atomic< uint64_t > _download_size
Definition: downloader.h:58
std::atomic< uint64_t > _downloaded
Definition: downloader.h:59
Downloader(std::string const &url, std::string const &destdir)
std::string destdir
Definition: downloader.h:53
#define LIBPBD_API
PBD::PropertyDescriptor< bool > contents
GTKMM_API const Gtk::BuiltinStockID FILE
Definition: axis_view.h:42