Ardour  8.12
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 #ifndef __libpbd_downloader_h__
20 #define __libpbd_downloader_h__
21 
22 #include <atomic>
23 #include <string>
24 
25 #include <curl/curl.h>
26 
27 #include "pbd/libpbd_visibility.h"
28 
29 namespace PBD {
30 
31 class Thread;
32 
34  public:
35  Downloader (std::string const & url, std::string const & destdir);
37 
38  int start ();
39  void cleanup ();
40  void cancel ();
41  double progress() const;
42 
43  uint64_t download_size() const { return _download_size; }
44  uint64_t downloaded () const { return _downloaded; }
45 
46  /* public so it can be called from a static C function */
47  size_t write (void *contents, size_t size, size_t nmemb);
48 
49  int status() const { return _status; }
50  std::string download_path() const;
51 
52  private:
53  std::string url;
54  std::string destdir;
55  std::string file_path;
57  CURL* curl;
58  bool _cancel;
59  std::atomic<uint64_t> _download_size; /* read-only from requestor thread */
60  std::atomic<uint64_t> _downloaded; /* read-only from requestor thread */
61  std::atomic<int> _status;
63 
64  void download ();
65 };
66 
67 } /* namespace */
68 
69 #endif
double progress() const
uint64_t downloaded() const
Definition: downloader.h:44
std::string url
Definition: downloader.h:53
std::string file_path
Definition: downloader.h:55
uint64_t download_size() const
Definition: downloader.h:43
int status() const
Definition: downloader.h:49
std::atomic< int > _status
Definition: downloader.h:61
PBD::Thread * thread
Definition: downloader.h:62
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:59
std::atomic< uint64_t > _downloaded
Definition: downloader.h:60
Downloader(std::string const &url, std::string const &destdir)
std::string destdir
Definition: downloader.h:54
#define LIBPBD_API
PBD::PropertyDescriptor< bool > contents
GTKMM_API const Gtk::BuiltinStockID FILE
Definition: axis_view.h:42