libzypp  17.31.31
provideitem.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 #ifndef ZYPP_MEDIA_PROVIDEITEM_H_INCLUDED
10 #define ZYPP_MEDIA_PROVIDEITEM_H_INCLUDED
11 
12 #include <zypp-core/zyppng/base/zyppglobal.h>
13 #include <zypp-core/zyppng/base/Base>
14 #include <zypp-media/ng/ProvideFwd>
15 #include <zypp-core/ByteCount.h>
16 
17 namespace zyppng
18 {
19  class ProvidePrivate;
20  class ProvideItemPrivate;
21 
28  class ProvideItem : public Base
29  {
31  friend class Provide;
32  friend class ProvidePrivate;
33  friend class ProvideQueue;
34  public:
35  enum State {
36  Uninitialized, //< Item was added to the queue but not yet initialized
37  Pending, //< The Item is waiting to be queued and does nothing
38  Downloading, //< The Item is fetching data
39  Processing, //< The Item has fetched all data but is still doing other things
40  Cancelling, //< The Item was cancelled and waits
41  Finalizing, //< The Item has finished all work and is currently cleaning up
42  Finished //< The Item is done and can be dequeued
43  };
44 
45  struct ItemStats {
46  std::chrono::steady_clock::time_point _pulseTime;
50  };
51 
52  ProvideItem( ProvidePrivate &parent );
53  ~ProvideItem ();
54 
58  virtual void initialize () = 0;
59 
63  virtual void released ();
64 
65  State state () const;
66 
70  SignalProxy<void( ProvideItem &item, State oldState, State newState )> sigStateChanged();
71 
73 
78  virtual bool canRedirectTo ( ProvideRequestRef startedReq, const zypp::Url &url );
79 
84  const std::optional<ItemStats> &currentStats() const;
85 
90  const std::optional<ItemStats> &previousStats() const;
91 
96  virtual std::chrono::steady_clock::time_point startTime() const;
97 
102  virtual std::chrono::steady_clock::time_point finishedTime() const;
103 
108  void pulse ();
109 
113  virtual zypp::ByteCount bytesExpected () const;
114 
115  protected:
116  virtual ItemStats makeStats ();
117 
121  virtual void informalMessage ( ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg );
122 
126  virtual void cacheMiss ( ProvideRequestRef req );
127 
135  virtual void finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg );
136 
143  virtual void finishReq ( ProvideQueue *queue, ProvideRequestRef finishedReq, const std::exception_ptr excpt );
144 
149  virtual expected<zypp::media::AuthData> authenticationRequired ( ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map<std::string, std::string> &extraFields );
150 
155  bool safeRedirectTo ( ProvideRequestRef startedReq, const zypp::Url &url );
156 
160  void redirectTo ( ProvideRequestRef startedReq, const zypp::Url &url );
161 
166  virtual bool enqueueRequest( ProvideRequestRef request );
167 
171  virtual void cancelWithError ( std::exception_ptr error ) = 0;
172 
177  bool dequeue ();
178 
184  void updateState( const State newState );
185 
186  void setFinished ();
187 
188  protected:
189  ProvideRequestRef _runningReq;
190  };
191 }
192 #endif // ZYPP_MEDIA_PROVIDEITEM_H_INCLUDED
bool safeRedirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
Definition: provideitem.cc:95
virtual bool enqueueRequest(ProvideRequestRef request)
Definition: provideitem.cc:447
Store and operate with byte count.
Definition: ByteCount.h:30
virtual void cacheMiss(ProvideRequestRef req)
Definition: provideitem.cc:180
virtual void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg)
Definition: provideitem.cc:190
virtual ItemStats makeStats()
Definition: provideitem.cc:159
std::chrono::steady_clock::time_point _pulseTime
Definition: provideitem.h:46
State state() const
Definition: provideitem.cc:494
ProvideItem(ProvidePrivate &parent)
Definition: provideitem.cc:83
void updateState(const State newState)
Definition: provideitem.cc:457
zypp::ByteCount _bytesProvided
Definition: provideitem.h:48
void redirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
Definition: provideitem.cc:104
virtual void initialize()=0
virtual void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg)
Definition: provideitem.cc:167
const std::optional< ItemStats > & currentStats() const
Definition: provideitem.cc:122
ProvidePrivate & provider()
Definition: provideitem.cc:90
virtual bool canRedirectTo(ProvideRequestRef startedReq, const zypp::Url &url)
Definition: provideitem.cc:110
virtual expected< zypp::media::AuthData > authenticationRequired(ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map< std::string, std::string > &extraFields)
Definition: provideitem.cc:398
ZYPP_DECLARE_PRIVATE(ProvideItem)
virtual void released()
Definition: provideitem.cc:485
virtual void cancelWithError(std::exception_ptr error)=0
zypp::ByteCount _bytesExpected
Definition: provideitem.h:49
virtual zypp::ByteCount bytesExpected() const
Definition: provideitem.cc:154
const std::optional< ItemStats > & previousStats() const
Definition: provideitem.cc:127
SignalProxy< void(ProvideItem &item, State oldState, State newState)> sigStateChanged()
virtual std::chrono::steady_clock::time_point startTime() const
Definition: provideitem.cc:132
Url manipulation class.
Definition: Url.h:91
virtual std::chrono::steady_clock::time_point finishedTime() const
Definition: provideitem.cc:137
ProvideRequestRef _runningReq
Definition: provideitem.h:189