LibPkg
download.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 // Copyright © 2003-2005 Graham Shaw.
3 // Distribution and use are subject to the GNU Lesser General Public License,
4 // a copy of which may be found in the file !LibPkg.Copyright.
5 
6 #ifndef LIBPKG_DOWNLOAD
7 #define LIBPKG_DOWNLOAD
8 
9 #include <string>
10 #include <fstream>
11 
12 #include "curl/curl.h"
13 
14 namespace pkg {
15 
16 using std::string;
17 
19 class download
20 {
21 public:
23  typedef unsigned long long size_type;
24 
26  static const size_type npos=static_cast<size_type>(-1);
27 
28  // An enumeration for describing the state of the download. */
30  {
38  };
39 private:
41  state_type _state;
42 
44  CURL* _ceasy;
45 
47  CURLcode _result;
48 
50  char* _error_buffer;
51 
53  string _url;
54 
56  std::ofstream _out;
57 
59  size_type _bytes_done;
60 
62  size_type _bytes_total;
63 public:
68  download(const string& url,const string& pathname);
69 
71  ~download();
72 
76  state_type state() const
77  { return _state; }
78 
82  CURLcode result() const
83  { return _result; }
84 
88  string message() const
89  { return _error_buffer; }
90 
95  { return _bytes_done; }
96 
101  { return _bytes_total; }
102 
109  size_t write_callback(char* buffer,size_t size,size_t nitems);
110 
116  int progress_callback(double dltotal,double dlnow);
117 
121  void message_callback(CURLMsg* msg);
122 private:
129  static CURLM* _cmulti;
130 
133  static unsigned int _cmulti_refcount;
134 public:
136  static void poll_all();
137 };
138 
139 }; /* namespace pkg */
140 
141 #endif
The state in which the download has been successfully completed.
Definition: download.h:35
The state in which the download is in progress.
Definition: download.h:32
static const size_type npos
A null value for use in place of a byte count.
Definition: download.h:26
size_type bytes_done()
Get number of bytes downloaded.
Definition: download.h:94
string message() const
Get libcurl error message.
Definition: download.h:88
~download()
Destroy download action.
Definition: download.cc:78
static void poll_all()
Poll all download operations.
Definition: download.cc:122
int progress_callback(double dltotal, double dlnow)
Handler for CURLOPT_PROGRESSFUNCTION callbacks.
Definition: download.cc:101
download(const string &url, const string &pathname)
Construct download action.
Definition: download.cc:44
unsigned long long size_type
A type for representing byte counts.
Definition: download.h:23
void message_callback(CURLMsg *msg)
Handler for Curl messages.
Definition: download.cc:109
size_t write_callback(char *buffer, size_t size, size_t nitems)
Handler for CURLOPT_WRITEFUNCTION callbacks.
Definition: download.cc:95
state_type state() const
Get current state of the download.
Definition: download.h:76
CURLcode result() const
Get libcurl result code.
Definition: download.h:82
A class for downloading a file from a URL.
Definition: download.h:19
state_type
Definition: download.h:29
The state in which the download has failed.
Definition: download.h:37
size_type bytes_total()
Get total number of bytes to download.
Definition: download.h:100

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)