LibPkg
update.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 //
3 // Copyright 2003-2020 Graham Shaw
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef LIBPKG_UPDATE
18 #define LIBPKG_UPDATE
19 
20 #include <string>
21 #include <map>
22 #include <set>
23 #include <iosfwd>
24 
25 #include "libpkg/source_table.h"
27 #include "libpkg/thread.h"
28 #include "libpkg/download.h"
29 
30 namespace pkg {
31 
32 using std::string;
33 
34 class pkgbase;
35 class log;
36 
41 class update:
42  public thread
43 {
44 public:
46  typedef unsigned long long size_type;
47 
49  static const size_type npos=static_cast<size_type>(-1);
50 
53  {
69  };
70 private:
72  pkgbase& _pb;
73 
75  state_type _state;
76 
78  string _url;
79 
81  download* _dload;
82 
84  std::set<string> _sources_to_download;
85 
87  std::set<string> _sources_to_build;
88 
91  std::set<binary_control_table::key_type> _packages_written;
92 
94  std::ostream* _out;
95 
97  size_type _bytes_done;
98 
100  size_type _bytes_total;
101 
104  string _message;
105 
106  struct progress;
107 
109  std::map<string,progress> _progress_table;
110 
112  log *_log;
113 
115  download::options *_download_options;
116 
117 public:
121  update(pkgbase& pb);
122 
124  virtual ~update();
125 
130  { return _state; }
131 
135  size_type bytes_done() const
136  { return _bytes_done; }
137 
141  size_type bytes_total() const
142  { return _bytes_total; }
143 
149  string message() const
150  { return _message; }
151 
155  void log_to(log *use_log);
156 
160  void download_options(const download::options &opts);
161 
162 protected:
163  void poll();
164 private:
170  void _poll();
171 
176  void update_progress();
177 };
178 
181 {
192  progress();
193 };
194 
195 }; /* namespace pkg */
196 
197 #endif
The state in which the update operation failed.
Definition: update.h:68
state_type
An enumeration for describing the state of the update operation.
Definition: update.h:52
A class for updating the package database.
Definition: update.h:41
void log_to(log *use_log)
Set the log to add to.
Definition: update.cc:286
Definition: download.h:58
virtual ~update()
Destroy update operation.
Definition: update.cc:40
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
unsigned long long size_type
A type for representing byte counts.
Definition: update.h:46
size_type bytes_done
The number of bytes downloaded.
Definition: update.h:183
The state in which local packages are incorporated into the available list.
Definition: update.h:63
The state in which the package indexes are being downloaded.
Definition: update.h:57
size_type bytes_prev
The total number of bytes when most recently downloaded, or npos if no previous total is available...
Definition: update.h:188
A mixin class to represent a cooperative thread.
Definition: thread.h:23
Class to log actions that occur in LibPkg.
Definition: log.h:226
state_type state() const
Get current state.
Definition: update.h:129
A class for representing the collection of package database tables.
Definition: pkgbase.h:35
The state in which the sources list is being read.
Definition: update.h:55
void download_options(const download::options &opts)
Set extra options used for the downloading of the package lists.
Definition: update.cc:291
A structure for monitoring the progress of one source.
Definition: update.h:180
size_type bytes_done() const
Get number of bytes downloaded.
Definition: update.h:135
A class for downloading a file from a URL.
Definition: download.h:37
size_type bytes_total() const
Get total number of bytes to download.
Definition: update.h:141
string message() const
Get error message.
Definition: update.h:149
The state in which remote sources are incorporated into the available list.
Definition: update.h:60
static const size_type npos
A null value for use in place of a byte count.
Definition: update.h:49
size_type bytes_total
The total number of bytes to download, or npos if not known.
Definition: update.h:185
void poll()
Poll this thread.
Definition: update.cc:45
The state in which the update operation has been successfully completed.
Definition: update.h:66
update(pkgbase &pb)
Construct update operation.
Definition: update.cc:29

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)