libzypp 17.37.10

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>
25#include <zypp-core/zyppng/base/private/base_p.h>
26#include <set>
27#include <variant>
28
29 namespace zyppng {
30
36 class ProvideRequest {
37 public:
38
39 friend class ProvideItem;
40
41 static expected<ProvideRequestRef> create( ProvideItem &owner, const zypp::MirroredOrigin &origin, const std::string &id, ProvideMediaSpec &spec );
42 static expected<ProvideRequestRef> create ( ProvideItem &owner, const zypp::MirroredOrigin &origin, ProvideFileSpec &spec );
43 static expected<ProvideRequestRef> createDetach( const zypp::Url &url );
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; }
53 ProvideMessage &provideMessage () { return _message; }
54
58 const std::optional<zypp::Url> activeUrl() const;
59 void setActiveUrl ( const zypp::Url &urlToUse );
60
61 void setOrigin( zypp::MirroredOrigin origin ) {
62 _origin = std::move(origin);
63 }
64
65 const zypp::MirroredOrigin &origin() const {
66 return _origin;
67 }
68
69 zypp::Url url() const {
70 return _origin.authority().url();
71 }
72
73 void setUrl( const zypp::Url & url ) {
74 _origin.setAuthority (url);
75 _origin.clearMirrors ();
76 }
77
78 void clearForRestart () {
79 _pastRedirects.clear();
80 _activeUrl.reset();
81 _myQueue.reset();
82 }
83
84 private:
85 ProvideRequest( ProvideItem *owner, zypp::MirroredOrigin origin, ProvideMessage &&msg ) : _owner(owner), _message(std::move(msg) ), _origin ( std::move(origin) ) {}
86 ProvideItem *_owner = nullptr; // destructor of ProvideItem will dequeue the item, so no need to do refcount here
87 ProvideMessage _message;
88 zypp::MirroredOrigin _origin;
89 std::vector<zypp::Url> _pastRedirects;
90 std::optional<zypp::Url> _activeUrl;
91 ProvideQueueWeakRef _myQueue;
92 };
93
94 class ProvideItemPrivate : public BasePrivate
95 {
96 public:
97 ProvideItemPrivate( ProvidePrivate & parent, ProvideItem &pub ) : BasePrivate(pub), _parent(parent) {}
98 ProvidePrivate &_parent;
99 ProvideItem::State _itemState = ProvideItem::Uninitialized;
100 std::chrono::steady_clock::time_point _itemStarted;
101 std::chrono::steady_clock::time_point _itemFinished;
102 std::optional<ProvideItem::ItemStats> _prevStats;
103 std::optional<ProvideItem::ItemStats> _currStats;
104 Signal<void( ProvideItem &item, ProvideItem::State oldState, ProvideItem::State newState )> _sigStateChanged;
105 };
106
112 template< typename T >
113 class ProvidePromise : public AsyncOp<expected<T>>
114 {
115 public:
116 ProvidePromise( ProvideItemRef provideItem )
117 : _myProvide( provideItem )
118 {}
119
120 ~ProvidePromise()
121 {
122 auto prov = _myProvide.lock();
123 if ( prov )
124 prov->released();
125 }
126
127 private:
128 ProvideItemWeakRef _myProvide; //weak reference to the internal item so we can cancel the op on desctruction
129 };
130
134 class ProvideFileItem : public ProvideItem
135 {
136 public:
137
138 static ProvideFileItemRef create ( zypp::MirroredOrigin origin,const ProvideFileSpec &request, ProvidePrivate &parent );
139
140 // ProvideItem interface
141 void initialize () override;
142 ProvidePromiseRef<ProvideRes> promise();
143
144 void setMediaRef ( Provide::MediaHandle &&hdl );
145 Provide::MediaHandle & mediaRef ();
146
147 ItemStats makeStats () override;
148 zypp::ByteCount bytesExpected () const override;
149
150 protected:
151 ProvideFileItem ( zypp::MirroredOrigin origin,const ProvideFileSpec &request, ProvidePrivate &parent );
152
153 void informalMessage ( ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg ) override;
154
155 using ProvideItem::finishReq;
156 void finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg ) override;
157 void cancelWithError ( std::exception_ptr error ) override;
158 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;
159
160 private:
161 Provide::MediaHandle _handleRef; //< If we are using a attached media, this will keep the reference around
162 bool _promiseCreated = false;
163 zypp::MirroredOrigin _origin; //< All available URLs
164 ProvideFileSpec _initialSpec; //< The initial spec as defined by the user code
165 zypp::Pathname _targetFile; //< The target file as reported by the worker
166 zypp::Pathname _stagingFile; //< The staging file as reported by the worker
167 zypp::ByteCount _expectedBytes; //< The nr of bytes we want to provide
168 ProvidePromiseWeakRef<ProvideRes> _promise;
169 };
170
171
175 class AttachMediaItem : public ProvideItem
176 {
177 public:
178 ~AttachMediaItem();
179 static AttachMediaItemRef create ( const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request, ProvidePrivate &parent );
180 SignalProxy< void( const zyppng::expected<AttachedMediaInfo *> & ) > sigReady ();
181
182 ProvidePromiseRef<Provide::MediaHandle> promise();
183
184 protected:
185 AttachMediaItem ( const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request, ProvidePrivate &parent );
186
187 // ProvideItem interface
188 void initialize () override;
189
190 using ProvideItem::finishReq;
191 void finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg ) override;
192 void cancelWithError( std::exception_ptr error ) override;
193 void finishWithSuccess (AttachedMediaInfo_Ptr medium );
194 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;
195
196 void onMasterItemReady ( const zyppng::expected<AttachedMediaInfo *>& result );
197
198 private:
199 Signal< void( const zyppng::expected<AttachedMediaInfo *> & )> _sigReady;
200 bool _promiseCreated = false;
201 connection _masterItemConn;
202 zypp::MirroredOrigin _origin; //< All available URLs
203 ProvideMediaSpec _initialSpec; //< The initial spec as defined by the user code
204 ProvideQueue::Config::WorkerType _workerType = ProvideQueue::Config::Invalid;
205 ProvidePromiseWeakRef<Provide::MediaHandle> _promise;
206 MediaDataVerifierRef _verifier;
207 };
208}
209
210#endif
attachedmediainfo_p.h
base_p.h
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::MirroredOrigin
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Definition MirroredOrigin.h:170
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zyppng::AttachMediaItem::create
static AttachMediaItemRef create(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request, ProvidePrivate &parent)
Definition provideitem.cc:1113
zyppng::AttachMediaItem::AttachMediaItem
AttachMediaItem(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request, ProvidePrivate &parent)
Definition provideitem.cc:858
zyppng::AttachMediaItem::initialize
void initialize() override
Definition provideitem.cc:880
zyppng::AttachMediaItem::_sigReady
Signal< void(const zyppng::expected< AttachedMediaInfo * > &)> _sigReady
Definition provideitem_p.h:199
zyppng::AttachMediaItem::_promiseCreated
bool _promiseCreated
Definition provideitem_p.h:200
zyppng::AttachMediaItem::finishReq
void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg) override
Definition provideitem.cc:1123
zyppng::AttachMediaItem::promise
ProvidePromiseRef< Provide::MediaHandle > promise()
Definition provideitem.cc:869
zyppng::AttachMediaItem::sigReady
SignalProxy< void(const zyppng::expected< AttachedMediaInfo * > &) > sigReady()
Definition provideitem.cc:1118
zyppng::AttachMediaItem::finishWithSuccess
void finishWithSuccess(AttachedMediaInfo_Ptr medium)
Definition provideitem.cc:1028
zyppng::AttachMediaItem::_verifier
MediaDataVerifierRef _verifier
Definition provideitem_p.h:206
zyppng::AttachMediaItem::_promise
ProvidePromiseWeakRef< Provide::MediaHandle > _promise
Definition provideitem_p.h:205
zyppng::AttachMediaItem::_workerType
ProvideQueue::Config::WorkerType _workerType
Definition provideitem_p.h:204
zyppng::AttachMediaItem::~AttachMediaItem
~AttachMediaItem()
Definition provideitem.cc:864
zyppng::AttachMediaItem::_initialSpec
ProvideMediaSpec _initialSpec
Definition provideitem_p.h:203
zyppng::AttachMediaItem::_masterItemConn
connection _masterItemConn
Definition provideitem_p.h:201
zyppng::AttachMediaItem::_origin
zypp::MirroredOrigin _origin
Definition provideitem_p.h:202
zyppng::AttachMediaItem::cancelWithError
void cancelWithError(std::exception_ptr error) override
Definition provideitem.cc:1058
zyppng::AttachMediaItem::authenticationRequired
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
Definition provideitem.cc:1203
zyppng::AttachMediaItem::onMasterItemReady
void onMasterItemReady(const zyppng::expected< AttachedMediaInfo * > &result)
Definition provideitem.cc:1089
zyppng::BasePrivate::parent
Base::WeakPtr parent
Definition base_p.h:22
zyppng::BasePrivate::BasePrivate
BasePrivate(Base &b)
Definition base_p.h:17
zyppng::Base::parent
WeakPtr parent() const
Definition base.cc:26
zyppng::ProvideFileItem::authenticationRequired
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
Definition provideitem.cc:814
zyppng::ProvideFileItem::ProvideFileItem
ProvideFileItem(zypp::MirroredOrigin origin, const ProvideFileSpec &request, ProvidePrivate &parent)
Definition provideitem.cc:562
zyppng::ProvideFileItem::_stagingFile
zypp::Pathname _stagingFile
Definition provideitem_p.h:166
zyppng::ProvideFileItem::cancelWithError
void cancelWithError(std::exception_ptr error) override
Definition provideitem.cc:792
zyppng::ProvideFileItem::bytesExpected
zypp::ByteCount bytesExpected() const override
Definition provideitem.cc:853
zyppng::ProvideFileItem::setMediaRef
void setMediaRef(Provide::MediaHandle &&hdl)
Definition provideitem.cc:606
zyppng::ProvideFileItem::mediaRef
Provide::MediaHandle & mediaRef()
Definition provideitem.cc:611
zyppng::ProvideFileItem::finishReq
void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg) override
zyppng::ProvideFileItem::_promiseCreated
bool _promiseCreated
Definition provideitem_p.h:162
zyppng::ProvideFileItem::_handleRef
Provide::MediaHandle _handleRef
Definition provideitem_p.h:161
zyppng::ProvideFileItem::initialize
void initialize() override
Definition provideitem.cc:573
zyppng::ProvideFileItem::_origin
zypp::MirroredOrigin _origin
Definition provideitem_p.h:163
zyppng::ProvideFileItem::_initialSpec
ProvideFileSpec _initialSpec
Definition provideitem_p.h:164
zyppng::ProvideFileItem::create
static ProvideFileItemRef create(zypp::MirroredOrigin origin, const ProvideFileSpec &request, ProvidePrivate &parent)
Definition provideitem.cc:568
zyppng::ProvideFileItem::promise
ProvidePromiseRef< ProvideRes > promise()
Definition provideitem.cc:595
zyppng::ProvideFileItem::_expectedBytes
zypp::ByteCount _expectedBytes
Definition provideitem_p.h:167
zyppng::ProvideFileItem::_targetFile
zypp::Pathname _targetFile
Definition provideitem_p.h:165
zyppng::ProvideFileItem::makeStats
ItemStats makeStats() override
Definition provideitem.cc:828
zyppng::ProvideFileItem::informalMessage
void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg) override
Definition provideitem.cc:616
zyppng::ProvideFileItem::_promise
ProvidePromiseWeakRef< ProvideRes > _promise
Definition provideitem_p.h:168
zyppng::ProvideFileSpec
Definition providespec.h:92
zyppng::ProvideItemPrivate::_sigStateChanged
Signal< void(ProvideItem &item, ProvideItem::State oldState, ProvideItem::State newState)> _sigStateChanged
Definition provideitem_p.h:104
zyppng::ProvideItemPrivate::_itemFinished
std::chrono::steady_clock::time_point _itemFinished
Definition provideitem_p.h:101
zyppng::ProvideItemPrivate::_currStats
std::optional< ProvideItem::ItemStats > _currStats
Definition provideitem_p.h:103
zyppng::ProvideItemPrivate::_parent
ProvidePrivate & _parent
Definition provideitem_p.h:98
zyppng::ProvideItemPrivate::ProvideItemPrivate
ProvideItemPrivate(ProvidePrivate &parent, ProvideItem &pub)
Definition provideitem_p.h:97
zyppng::ProvideItemPrivate::_itemState
ProvideItem::State _itemState
Definition provideitem_p.h:99
zyppng::ProvideItemPrivate::_itemStarted
std::chrono::steady_clock::time_point _itemStarted
Definition provideitem_p.h:100
zyppng::ProvideItemPrivate::_prevStats
std::optional< ProvideItem::ItemStats > _prevStats
Definition provideitem_p.h:102
zyppng::ProvideItem
Definition provideitem.h:29
zyppng::ProvideItem::ProvideItem
ProvideItem(ProvidePrivate &parent)
Definition provideitem.cc:83
zyppng::ProvideItem::State
State
Definition provideitem.h:35
zyppng::ProvideItem::Uninitialized
@ Uninitialized
Definition provideitem.h:36
zyppng::ProvideItem::ProvidePrivate
friend class ProvidePrivate
Definition provideitem.h:32
zyppng::ProvideItem::finishReq
virtual void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg)
Definition provideitem.cc:190
zyppng::ProvideItem::ProvideQueue
friend class ProvideQueue
Definition provideitem.h:33
zyppng::ProvideMediaSpec
Definition providespec.h:29
zyppng::ProvideMessage
Definition providemessage_p.h:521
zyppng::ProvidePrivate
Definition provide_p.h:42
zyppng::ProvidePromise::~ProvidePromise
~ProvidePromise()
Definition provideitem_p.h:120
zyppng::ProvidePromise::_myProvide
ProvideItemWeakRef _myProvide
Definition provideitem_p.h:128
zyppng::ProvidePromise::ProvidePromise
ProvidePromise(ProvideItemRef provideItem)
Definition provideitem_p.h:116
zyppng::ProvideRequest::_pastRedirects
std::vector< zypp::Url > _pastRedirects
Definition provideitem_p.h:89
zyppng::ProvideRequest::setActiveUrl
void setActiveUrl(const zypp::Url &urlToUse)
Definition provideitem.cc:544
zyppng::ProvideRequest::setOrigin
void setOrigin(zypp::MirroredOrigin origin)
Definition provideitem_p.h:61
zyppng::ProvideRequest::_myQueue
ProvideQueueWeakRef _myQueue
Definition provideitem_p.h:91
zyppng::ProvideRequest::_activeUrl
std::optional< zypp::Url > _activeUrl
Definition provideitem_p.h:90
zyppng::ProvideRequest::createDetach
static expected< ProvideRequestRef > createDetach(const zypp::Url &url)
Definition provideitem.cc:75
zyppng::ProvideRequest::clearForRestart
void clearForRestart()
Definition provideitem_p.h:78
zyppng::ProvideRequest::provideMessage
ProvideMessage & provideMessage()
Definition provideitem_p.h:53
zyppng::ProvideRequest::provideMessage
const ProvideMessage & provideMessage() const
Definition provideitem_p.h:52
zyppng::ProvideRequest::_message
ProvideMessage _message
Definition provideitem_p.h:87
zyppng::ProvideRequest::url
zypp::Url url() const
Definition provideitem_p.h:69
zyppng::ProvideRequest::setCurrentQueue
void setCurrentQueue(ProvideQueueRef ref)
Definition provideitem.cc:503
zyppng::ProvideRequest::code
uint code() const
Definition provideitem_p.h:47
zyppng::ProvideRequest::owner
ProvideItem * owner()
Definition provideitem_p.h:45
zyppng::ProvideRequest::currentQueue
ProvideQueueRef currentQueue()
Definition provideitem.cc:508
zyppng::ProvideRequest::ProvideItem
friend class ProvideItem
Definition provideitem_p.h:39
zyppng::ProvideRequest::origin
const zypp::MirroredOrigin & origin() const
Definition provideitem_p.h:65
zyppng::ProvideRequest::activeUrl
const std::optional< zypp::Url > activeUrl() const
Returns the currenty active URL as set by the scheduler.
Definition provideitem.cc:513
zyppng::ProvideRequest::setUrl
void setUrl(const zypp::Url &url)
Definition provideitem_p.h:73
zyppng::ProvideRequest::_origin
zypp::MirroredOrigin _origin
Definition provideitem_p.h:88
zyppng::ProvideRequest::_owner
ProvideItem * _owner
Definition provideitem_p.h:86
zyppng::ProvideRequest::create
static expected< ProvideRequestRef > create(ProvideItem &owner, const zypp::MirroredOrigin &origin, const std::string &id, ProvideMediaSpec &spec)
Definition provideitem.cc:27
zyppng::ProvideRequest::ProvideRequest
ProvideRequest(ProvideItem *owner, zypp::MirroredOrigin origin, ProvideMessage &&msg)
Definition provideitem_p.h:85
zyppng::Provide::MediaHandle
ProvideMediaHandle MediaHandle
Definition provide.h:124
zyppng::SignalProxy
Definition signals.h:325
zyppng::Signal
Definition signals.h:151
zyppng::WorkerCaps::WorkerType
WorkerType
Definition providemessage_p.h:379
zyppng::WorkerCaps::Invalid
@ Invalid
Definition providemessage_p.h:380
zyppng::expected
Definition expected.h:27
std
Definition Arch.h:364
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::ProvidePromiseRef
std::shared_ptr< ProvidePromise< T > > ProvidePromiseRef
Definition providefwd_p.h:31
zyppng::connection
sigc::connection connection
Definition signals.h:180
zyppng::ProvidePromiseWeakRef
std::weak_ptr< ProvidePromise< T > > ProvidePromiseWeakRef
Definition providefwd_p.h:33
providefwd_p.h
providemessage_p.h
providequeue_p.h
zyppng::AsyncOp< expected< T > >::AsyncOp
AsyncOp()=default
zyppng::ProvideItem::ItemStats
Definition provideitem.h:45