libzypp  17.22.0
request.h
Go to the documentation of this file.
1 #ifndef ZYPP_NG_MEDIA_CURL_REQUEST_H_INCLUDED
2 #define ZYPP_NG_MEDIA_CURL_REQUEST_H_INCLUDED
3 
5 #include <zypp/zyppng/media/network/TransferSettings>
6 #include <zypp/zyppng/base/Base>
7 #include <zypp/zyppng/core/Url>
10 #include <zypp/base/Flags.h>
11 #include <vector>
12 
13 namespace zypp {
14  class Digest;
15 
16  namespace media {
17  class AuthData;
18  }
19 }
20 
21 namespace zyppng {
22 
24 
25  class NetworkRequestDispatcher;
26  class NetworkRequestPrivate;
27 
36  {
37  public:
38 
39  using Ptr = std::shared_ptr<NetworkRequest>;
40  using WeakPtr = std::weak_ptr<NetworkRequest>;
41 
42  enum State {
43  Pending, //< waiting to be dispatched
44  Running, //< currently running
45  Finished, //< finished successfully
46  Error, //< Error, use error function to figure out the issue
47  };
48 
49  enum Priority {
50  Normal, //< Requests with normal priority will be enqueued at the end
51  High //< Request with high priority will be moved to the front of the queue
52  };
53 
54  enum FileMode {
55  WriteExclusive, //< the request will create its own file, overwriting anything that already exists
56  WriteShared //< the request will create or open the file in shared mode and only write between \a start and \a len
57  };
58 
59  enum OptionBits {
60  HeadRequest = 0x01 //< only request the header part of the file
61  };
62  ZYPP_DECLARE_FLAGS(Options, OptionBits);
63 
71  NetworkRequest( Url url, zypp::Pathname targetFile, off_t start = -1, off_t len = 0, FileMode fMode = WriteExclusive );
72  virtual ~NetworkRequest();
73 
79  void setPriority ( Priority prio );
80 
84  Priority priority ( ) const;
85 
91  void setOptions ( Options opt );
92 
96  Options options () const;
97 
104  void setRequestRange ( off_t start = -1, off_t len = 0 );
105 
109  const std::string &lastRedirectInfo() const;
110 
117  void *nativeHandle () const;
118 
123  std::vector<char> peekData ( off_t offset, size_t count ) const;
124 
128  Url url () const;
129 
134  void setUrl ( const Url & url );
135 
139  const zypp::Pathname & targetFilePath () const;
140 
145  std::string contentType () const;
146 
150  off_t downloadOffset () const;
151 
156  off_t reportedByteCount () const;
157 
162  off_t expectedByteCount () const;
163 
167  off_t downloadedByteCount () const;
168 
173  void setDigest ( std::shared_ptr<zypp::Digest> dig );
174 
178  std::shared_ptr<zypp::Digest> digest () const;
179 
186  void setExpectedChecksum (std::vector<unsigned char> checksum );
187 
188 
193  TransferSettings &transferSettings ();
194 
198  State state () const;
199 
203  const NetworkRequestError &error () const;
204 
209  std::string extendedErrorString() const;
210 
214  bool hasError () const;
215 
220  bool addRequestHeader(const std::string &header );
221 
225  SignalProxy<void ( NetworkRequest &req )> sigStarted ();
226 
230  SignalProxy<void ( NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow )> sigProgress ();
231 
238  SignalProxy<void ( NetworkRequest &req, const NetworkRequestError &err)> sigFinished ( );
239 
240  private:
241  friend class NetworkRequestDispatcher;
244  };
245 
246 }
247 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(zyppng::NetworkRequest::Options);
248 
249 #endif
LIBZYPP_NG_EXPORT
#define LIBZYPP_NG_EXPORT
Definition: zyppglobal.h:7
zyppng::NetworkRequest::State
State
Definition: request.h:42
zyppng::NetworkRequest::Pending
Definition: request.h:43
zypp::media::TransferSettings
Holds transfer setting.
Definition: TransferSettings.h:20
zyppng::Base
Definition: base.h:32
zyppng::NetworkRequest::OptionBits
OptionBits
Definition: request.h:59
zyppng::NetworkRequest::Normal
Definition: request.h:50
zypp::media::state
state
Definition: MetaLinkParser.cc:34
zyppng::SignalProxy
Definition: signals.h:28
networkrequesterror.h
zypp::filesystem::checksum
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
Definition: PathInfo.cc:999
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zyppng::AuthData
zypp::media::AuthData AuthData
Definition: authdata.h:21
signals.h
ZYPP_DECLARE_FLAGS
#define ZYPP_DECLARE_FLAGS(Name, Enum)
Definition: Flags.h:174
zyppng::NetworkRequest::Priority
Priority
Definition: request.h:49
zyppng::NetworkRequestError
The NetworkRequestError class Represents a error that occured in.
Definition: networkrequesterror.h:20
zyppng::NetworkRequest::Finished
Definition: request.h:45
zyppglobal.h
zyppng::Base::Ptr
std::shared_ptr< Base > Ptr
Definition: base.h:38
zyppng::NetworkRequest::Running
Definition: request.h:44
ZYPP_DECLARE_PRIVATE
#define ZYPP_DECLARE_PRIVATE(Class)
Definition: zyppglobal.h:21
zyppng::NetworkRequest::FileMode
FileMode
Definition: request.h:54
zyppng::NetworkRequest::Error
Definition: request.h:46
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:44
zyppng::Base::WeakPtr
std::weak_ptr< Base > WeakPtr
Definition: base.h:39
zyppng::NetworkRequest::WriteExclusive
Definition: request.h:55
ZYPP_DECLARE_OPERATORS_FOR_FLAGS
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(zyppng::NetworkRequest::Options)
Flags.h
zyppng
Definition: abstracteventsource.cc:8
zyppng::NetworkRequest
Definition: request.h:35
url
Url url
Definition: MediaCurl.cc:65
zypp::Url
Url manipulation class.
Definition: Url.h:87
zyppng::NetworkRequestDispatcherPrivate
Definition: networkrequestdispatcher_p.h:15