libzypp 17.37.5
provideitem_p.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* You have been warned!
12*
13*/
14#ifndef ZYPP_MEDIA_PRIVATE_PROVIDE_ITEM_P_H_INCLUDED
15#define ZYPP_MEDIA_PRIVATE_PROVIDE_ITEM_P_H_INCLUDED
16
17#include "providefwd_p.h"
18#include "providequeue_p.h"
19#include "attachedmediainfo_p.h"
20#include "providemessage_p.h"
21#include <zypp-media/ng/Provide>
22#include <zypp-media/ng/ProvideItem>
23#include <zypp-media/ng/ProvideRes>
24#include <zypp-media/ng/ProvideSpec>
26#include <set>
27#include <variant>
28
29namespace zyppng {
30
37 public:
38
39 friend class ProvideItem;
40
41 static expected<ProvideRequestRef> create( ProvideItem &owner, const std::vector<zypp::Url> &urls, const std::string &id, ProvideMediaSpec &spec );
42 static expected<ProvideRequestRef> create ( ProvideItem &owner, const std::vector<zypp::Url> &urls, ProvideFileSpec &spec );
44
45 ProvideItem * owner() { return _owner; }
46
47 uint code () const { return _message.code(); }
48
49 void setCurrentQueue ( ProvideQueueRef ref );
50 ProvideQueueRef currentQueue ();
51
52 const ProvideMessage &provideMessage () const { return _message; }
54
58 const std::optional<zypp::Url> activeUrl() const;
59 void setActiveUrl ( const zypp::Url &urlToUse );
60
61 void setUrls( const std::vector<zypp::Url> & urls ) {
62 _mirrors = urls;
63 }
64
65 const std::vector<zypp::Url> &urls() const {
66 return _mirrors;
67 }
68
69 zypp::Url url() const {
70 return _mirrors.front();
71 }
72
73 void setUrl( const zypp::Url & url ) {
74 _mirrors = {url};
75 }
76
78 _pastRedirects.clear();
79 _activeUrl.reset();
80 _myQueue.reset();
81 }
82
83 private:
84 ProvideRequest( ProvideItem *owner, const std::vector<zypp::Url> &urls, ProvideMessage &&msg ) : _owner(owner), _message(std::move(msg) ), _mirrors(urls) {}
85 ProvideItem *_owner = nullptr; // destructor of ProvideItem will dequeue the item, so no need to do refcount here
87 std::vector<zypp::Url> _mirrors;
88 std::vector<zypp::Url> _pastRedirects;
89 std::optional<zypp::Url> _activeUrl;
90 ProvideQueueWeakRef _myQueue;
91 };
92
94 {
95 public:
99 std::chrono::steady_clock::time_point _itemStarted;
100 std::chrono::steady_clock::time_point _itemFinished;
101 std::optional<ProvideItem::ItemStats> _prevStats;
102 std::optional<ProvideItem::ItemStats> _currStats;
104 };
105
111 template< typename T >
112 class ProvidePromise : public AsyncOp<expected<T>>
113 {
114 public:
115 ProvidePromise( ProvideItemRef provideItem )
116 : _myProvide( provideItem )
117 {}
118
120 {
121 auto prov = _myProvide.lock();
122 if ( prov )
123 prov->released();
124 }
125
126 private:
127 ProvideItemWeakRef _myProvide; //weak reference to the internal item so we can cancel the op on desctruction
128 };
129
134 {
135 public:
136
137 static ProvideFileItemRef create ( const std::vector<zypp::Url> &urls,const ProvideFileSpec &request, ProvidePrivate &parent );
138
139 // ProvideItem interface
140 void initialize () override;
142
143 void setMediaRef ( Provide::MediaHandle &&hdl );
145
146 ItemStats makeStats () override;
147 zypp::ByteCount bytesExpected () const override;
148
149 protected:
150 ProvideFileItem ( const std::vector<zypp::Url> &urls,const ProvideFileSpec &request, ProvidePrivate &parent );
151
152 void informalMessage ( ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg ) override;
153
155 void finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg ) override;
156 void cancelWithError ( std::exception_ptr error ) override;
157 expected<zypp::media::AuthData> authenticationRequired ( ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map<std::string, std::string> &extraFields ) override;
158
159 private:
160 Provide::MediaHandle _handleRef; //< If we are using a attached media, this will keep the reference around
161 bool _promiseCreated = false;
162 std::vector<zypp::Url> _mirrorList; //< All available URLs, first one is the primary
163 ProvideFileSpec _initialSpec; //< The initial spec as defined by the user code
164 zypp::Pathname _targetFile; //< The target file as reported by the worker
165 zypp::Pathname _stagingFile; //< The staging file as reported by the worker
166 zypp::ByteCount _expectedBytes; //< The nr of bytes we want to provide
168 };
169
170
175 {
176 public:
178 static AttachMediaItemRef create ( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent );
180
182
183 protected:
184 AttachMediaItem ( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent );
185
186 // ProvideItem interface
187 void initialize () override;
188
190 void finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg ) override;
191 void cancelWithError( std::exception_ptr error ) override;
192 void finishWithSuccess (AttachedMediaInfo_Ptr medium );
193 expected<zypp::media::AuthData> authenticationRequired ( ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map<std::string, std::string> &extraFields ) override;
194
196
197 private:
199 bool _promiseCreated = false;
201 std::vector<zypp::Url> _mirrorList; //< All available URLs, first one is the primary
202 ProvideMediaSpec _initialSpec; //< The initial spec as defined by the user code
205 MediaDataVerifierRef _verifier;
206 };
207}
208
209#endif
Store and operate with byte count.
Definition ByteCount.h:32
Url manipulation class.
Definition Url.h:93
void initialize() override
Signal< void(const zyppng::expected< AttachedMediaInfo * > &)> _sigReady
void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg) override
ProvidePromiseRef< Provide::MediaHandle > promise()
SignalProxy< void(const zyppng::expected< AttachedMediaInfo * > &) > sigReady()
void finishWithSuccess(AttachedMediaInfo_Ptr medium)
MediaDataVerifierRef _verifier
ProvidePromiseWeakRef< Provide::MediaHandle > _promise
AttachMediaItem(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request, ProvidePrivate &parent)
ProvideQueue::Config::WorkerType _workerType
ProvideMediaSpec _initialSpec
static AttachMediaItemRef create(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request, ProvidePrivate &parent)
std::vector< zypp::Url > _mirrorList
void cancelWithError(std::exception_ptr error) override
expected< zypp::media::AuthData > authenticationRequired(ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map< std::string, std::string > &extraFields) override
void onMasterItemReady(const zyppng::expected< AttachedMediaInfo * > &result)
Base::WeakPtr parent
Definition base_p.h:22
BasePrivate(Base &b)
Definition base_p.h:17
WeakPtr parent() const
Definition base.cc:26
expected< zypp::media::AuthData > authenticationRequired(ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map< std::string, std::string > &extraFields) override
zypp::Pathname _stagingFile
void cancelWithError(std::exception_ptr error) override
zypp::ByteCount bytesExpected() const override
void setMediaRef(Provide::MediaHandle &&hdl)
Provide::MediaHandle & mediaRef()
void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg) override
Provide::MediaHandle _handleRef
void initialize() override
static ProvideFileItemRef create(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
ProvideFileItem(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
ProvideFileSpec _initialSpec
ProvidePromiseRef< ProvideRes > promise()
std::vector< zypp::Url > _mirrorList
zypp::ByteCount _expectedBytes
zypp::Pathname _targetFile
ItemStats makeStats() override
void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg) override
ProvidePromiseWeakRef< ProvideRes > _promise
Signal< void(ProvideItem &item, ProvideItem::State oldState, ProvideItem::State newState)> _sigStateChanged
std::chrono::steady_clock::time_point _itemFinished
std::optional< ProvideItem::ItemStats > _currStats
ProvideItemPrivate(ProvidePrivate &parent, ProvideItem &pub)
ProvideItem::State _itemState
std::chrono::steady_clock::time_point _itemStarted
std::optional< ProvideItem::ItemStats > _prevStats
ProvideItem(ProvidePrivate &parent)
friend class ProvidePrivate
Definition provideitem.h:32
virtual void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg)
friend class ProvideQueue
Definition provideitem.h:33
ProvideItemWeakRef _myProvide
ProvidePromise(ProvideItemRef provideItem)
std::vector< zypp::Url > _pastRedirects
void setActiveUrl(const zypp::Url &urlToUse)
ProvideQueueWeakRef _myQueue
const std::vector< zypp::Url > & urls() const
std::optional< zypp::Url > _activeUrl
std::vector< zypp::Url > _mirrors
static expected< ProvideRequestRef > createDetach(const zypp::Url &url)
ProvideMessage & provideMessage()
static expected< ProvideRequestRef > create(ProvideItem &owner, const std::vector< zypp::Url > &urls, const std::string &id, ProvideMediaSpec &spec)
const ProvideMessage & provideMessage() const
ProvideMessage _message
zypp::Url url() const
void setCurrentQueue(ProvideQueueRef ref)
void setUrls(const std::vector< zypp::Url > &urls)
ProvideItem * owner()
ProvideQueueRef currentQueue()
const std::optional< zypp::Url > activeUrl() const
Returns the currenty active URL as set by the scheduler.
void setUrl(const zypp::Url &url)
ProvideRequest(ProvideItem *owner, const std::vector< zypp::Url > &urls, ProvideMessage &&msg)
ProvideMediaHandle MediaHandle
Definition provide.h:123
Definition Arch.h:364
std::shared_ptr< ProvidePromise< T > > ProvidePromiseRef
sigc::connection connection
Definition signals.h:180
std::weak_ptr< ProvidePromise< T > > ProvidePromiseWeakRef