libzypp: zypp-media/ng/private/provideitem_p.h Source File

libzypp 17.36.6

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
29namespace zyppng {
30
36 class ProvideRequest {
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 );
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
55 const std::optional<zypp::Url> activeUrl() const;
56 void setActiveUrl ( const zypp::Url &urlToUse );
57
58 void setUrls( const std::vector<zypp::Url> & urls ) {
59 _mirrors = urls;
60 }
61
62 const std::vector<zypp::Url> &urls() const {
63 return _mirrors;
64 }
65
66 zypp::Url url() const {
67 return _mirrors.front();
68 }
69
70 void setUrl( const zypp::Url & url ) {
71 _mirrors = {url};
72 }
73
74 void clearForRestart () {
75 _pastRedirects.clear();
76 _activeUrl.reset();
77 _myQueue.reset();
78 }
79
80 private:
81 ProvideRequest( ProvideItem *owner, const std::vector<zypp::Url> &urls, ProvideMessage &&msg ) : _owner(owner), _message(std::move(msg) ), _mirrors(urls) {}
82 ProvideItem *_owner = nullptr; // destructor of ProvideItem will dequeue the item, so no need to do refcount here
83 ProvideMessage _message;
84 std::vector<zypp::Url> _mirrors;
85 std::vector<zypp::Url> _pastRedirects;
86 std::optional<zypp::Url> _activeUrl;
87 ProvideQueueWeakRef _myQueue;
88 };
89
90 class ProvideItemPrivate : public BasePrivate
91 {
92 public:
93 ProvideItemPrivate( ProvidePrivate & parent, ProvideItem &pub ) : BasePrivate(pub), _parent(parent) {}
94 ProvidePrivate &_parent;
95 ProvideItem::State _itemState = ProvideItem::Uninitialized;
96 std::chrono::steady_clock::time_point _itemStarted;
97 std::chrono::steady_clock::time_point _itemFinished;
98 std::optional<ProvideItem::ItemStats> _prevStats;
99 std::optional<ProvideItem::ItemStats> _currStats;
100 Signal<void( ProvideItem &item, ProvideItem::State oldState, ProvideItem::State newState )> _sigStateChanged;
101 };
102
108 template< typename T >
109 class ProvidePromise : public AsyncOp<expected<T>>
110 {
111 public:
112 ProvidePromise( ProvideItemRef provideItem )
113 : _myProvide( provideItem )
114 {}
115
116 ~ProvidePromise()
117 {
118 auto prov = _myProvide.lock();
119 if ( prov )
120 prov->released();
121 }
122
123 private:
124 ProvideItemWeakRef _myProvide; //weak reference to the internal item so we can cancel the op on desctruction
125 };
126
130 class ProvideFileItem : public ProvideItem
131 {
132 public:
133
134 static ProvideFileItemRef create ( const std::vector<zypp::Url> &urls,const ProvideFileSpec &request, ProvidePrivate &parent );
135
136 // ProvideItem interface
137 void initialize () override;
138 ProvidePromiseRef<ProvideRes> promise();
139
140 void setMediaRef ( Provide::MediaHandle &&hdl );
141 Provide::MediaHandle & mediaRef ();
142
143 ItemStats makeStats () override;
144 zypp::ByteCount bytesExpected () const override;
145
146 protected:
147 ProvideFileItem ( const std::vector<zypp::Url> &urls,const ProvideFileSpec &request, ProvidePrivate &parent );
148
149 void informalMessage ( ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg ) override;
150
151 using ProvideItem::finishReq;
152 void finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg ) override;
153 void cancelWithError ( std::exception_ptr error ) override;
154 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;
155
156 private:
157 Provide::MediaHandle _handleRef; //< If we are using a attached media, this will keep the reference around
158 bool _promiseCreated = false;
159 std::vector<zypp::Url> _mirrorList; //< All available URLs, first one is the primary
160 ProvideFileSpec _initialSpec; //< The initial spec as defined by the user code
161 zypp::Pathname _targetFile; //< The target file as reported by the worker
162 zypp::Pathname _stagingFile; //< The staging file as reported by the worker
163 zypp::ByteCount _expectedBytes; //< The nr of bytes we want to provide
164 ProvidePromiseWeakRef<ProvideRes> _promise;
165 };
166
167
171 class AttachMediaItem : public ProvideItem
172 {
173 public:
174 ~AttachMediaItem();
175 static AttachMediaItemRef create ( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent );
176 SignalProxy< void( const zyppng::expected<AttachedMediaInfo *> & ) > sigReady ();
177
178 ProvidePromiseRef<Provide::MediaHandle> promise();
179
180 protected:
181 AttachMediaItem ( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent );
182
183 // ProvideItem interface
184 void initialize () override;
185
186 using ProvideItem::finishReq;
187 void finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg ) override;
188 void cancelWithError( std::exception_ptr error ) override;
189 void finishWithSuccess (AttachedMediaInfo_Ptr medium );
190 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;
191
192 void onMasterItemReady ( const zyppng::expected<AttachedMediaInfo *>& result );
193
194 private:
195 Signal< void( const zyppng::expected<AttachedMediaInfo *> & )> _sigReady;
196 bool _promiseCreated = false;
197 connection _masterItemConn;
198 std::vector<zypp::Url> _mirrorList; //< All available URLs, first one is the primary
199 ProvideMediaSpec _initialSpec; //< The initial spec as defined by the user code
200 ProvideQueue::Config::WorkerType _workerType = ProvideQueue::Config::Invalid;
201 ProvidePromiseWeakRef<Provide::MediaHandle> _promise;
202 MediaDataVerifierRef _verifier;
203 };
204}
205
206#endif
attachedmediainfo_p.h
base_p.h
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zyppng::AttachMediaItem::initialize
void initialize() override
Definition provideitem.cc:846
zyppng::AttachMediaItem::_sigReady
Signal< void(const zyppng::expected< AttachedMediaInfo * > &)> _sigReady
Definition provideitem_p.h:195
zyppng::AttachMediaItem::_promiseCreated
bool _promiseCreated
Definition provideitem_p.h:196
zyppng::AttachMediaItem::finishReq
void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg) override
Definition provideitem.cc:1115
zyppng::AttachMediaItem::promise
ProvidePromiseRef< Provide::MediaHandle > promise()
Definition provideitem.cc:835
zyppng::AttachMediaItem::sigReady
SignalProxy< void(const zyppng::expected< AttachedMediaInfo * > &) > sigReady()
Definition provideitem.cc:1110
zyppng::AttachMediaItem::finishWithSuccess
void finishWithSuccess(AttachedMediaInfo_Ptr medium)
Definition provideitem.cc:1020
zyppng::AttachMediaItem::_verifier
MediaDataVerifierRef _verifier
Definition provideitem_p.h:202
zyppng::AttachMediaItem::_promise
ProvidePromiseWeakRef< Provide::MediaHandle > _promise
Definition provideitem_p.h:201
zyppng::AttachMediaItem::AttachMediaItem
AttachMediaItem(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request, ProvidePrivate &parent)
Definition provideitem.cc:824
zyppng::AttachMediaItem::_workerType
ProvideQueue::Config::WorkerType _workerType
Definition provideitem_p.h:200
zyppng::AttachMediaItem::~AttachMediaItem
~AttachMediaItem()
Definition provideitem.cc:830
zyppng::AttachMediaItem::_initialSpec
ProvideMediaSpec _initialSpec
Definition provideitem_p.h:199
zyppng::AttachMediaItem::create
static AttachMediaItemRef create(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request, ProvidePrivate &parent)
Definition provideitem.cc:1105
zyppng::AttachMediaItem::_masterItemConn
connection _masterItemConn
Definition provideitem_p.h:197
zyppng::AttachMediaItem::_mirrorList
std::vector< zypp::Url > _mirrorList
Definition provideitem_p.h:198
zyppng::AttachMediaItem::cancelWithError
void cancelWithError(std::exception_ptr error) override
Definition provideitem.cc:1050
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:1198
zyppng::AttachMediaItem::onMasterItemReady
void onMasterItemReady(const zyppng::expected< AttachedMediaInfo * > &result)
Definition provideitem.cc:1081
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:780
zyppng::ProvideFileItem::_stagingFile
zypp::Pathname _stagingFile
Definition provideitem_p.h:162
zyppng::ProvideFileItem::cancelWithError
void cancelWithError(std::exception_ptr error) override
Definition provideitem.cc:758
zyppng::ProvideFileItem::bytesExpected
zypp::ByteCount bytesExpected() const override
Definition provideitem.cc:819
zyppng::ProvideFileItem::setMediaRef
void setMediaRef(Provide::MediaHandle &&hdl)
Definition provideitem.cc:603
zyppng::ProvideFileItem::mediaRef
Provide::MediaHandle & mediaRef()
Definition provideitem.cc:608
zyppng::ProvideFileItem::finishReq
void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg) override
zyppng::ProvideFileItem::_promiseCreated
bool _promiseCreated
Definition provideitem_p.h:158
zyppng::ProvideFileItem::_handleRef
Provide::MediaHandle _handleRef
Definition provideitem_p.h:157
zyppng::ProvideFileItem::initialize
void initialize() override
Definition provideitem.cc:570
zyppng::ProvideFileItem::create
static ProvideFileItemRef create(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
Definition provideitem.cc:565
zyppng::ProvideFileItem::ProvideFileItem
ProvideFileItem(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
Definition provideitem.cc:559
zyppng::ProvideFileItem::_initialSpec
ProvideFileSpec _initialSpec
Definition provideitem_p.h:160
zyppng::ProvideFileItem::promise
ProvidePromiseRef< ProvideRes > promise()
Definition provideitem.cc:592
zyppng::ProvideFileItem::_mirrorList
std::vector< zypp::Url > _mirrorList
Definition provideitem_p.h:159
zyppng::ProvideFileItem::_expectedBytes
zypp::ByteCount _expectedBytes
Definition provideitem_p.h:163
zyppng::ProvideFileItem::_targetFile
zypp::Pathname _targetFile
Definition provideitem_p.h:161
zyppng::ProvideFileItem::makeStats
ItemStats makeStats() override
Definition provideitem.cc:794
zyppng::ProvideFileItem::informalMessage
void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg) override
Definition provideitem.cc:613
zyppng::ProvideFileItem::_promise
ProvidePromiseWeakRef< ProvideRes > _promise
Definition provideitem_p.h:164
zyppng::ProvideFileSpec
Definition providespec.h:92
zyppng::ProvideItemPrivate::_sigStateChanged
Signal< void(ProvideItem &item, ProvideItem::State oldState, ProvideItem::State newState)> _sigStateChanged
Definition provideitem_p.h:100
zyppng::ProvideItemPrivate::_itemFinished
std::chrono::steady_clock::time_point _itemFinished
Definition provideitem_p.h:97
zyppng::ProvideItemPrivate::_currStats
std::optional< ProvideItem::ItemStats > _currStats
Definition provideitem_p.h:99
zyppng::ProvideItemPrivate::_parent
ProvidePrivate & _parent
Definition provideitem_p.h:94
zyppng::ProvideItemPrivate::ProvideItemPrivate
ProvideItemPrivate(ProvidePrivate &parent, ProvideItem &pub)
Definition provideitem_p.h:93
zyppng::ProvideItemPrivate::_itemState
ProvideItem::State _itemState
Definition provideitem_p.h:95
zyppng::ProvideItemPrivate::_itemStarted
std::chrono::steady_clock::time_point _itemStarted
Definition provideitem_p.h:96
zyppng::ProvideItemPrivate::_prevStats
std::optional< ProvideItem::ItemStats > _prevStats
Definition provideitem_p.h:98
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:116
zyppng::ProvidePromise::_myProvide
ProvideItemWeakRef _myProvide
Definition provideitem_p.h:124
zyppng::ProvidePromise::ProvidePromise
ProvidePromise(ProvideItemRef provideItem)
Definition provideitem_p.h:112
zyppng::ProvideRequest::_pastRedirects
std::vector< zypp::Url > _pastRedirects
Definition provideitem_p.h:85
zyppng::ProvideRequest::setActiveUrl
void setActiveUrl(const zypp::Url &urlToUse)
Definition provideitem.cc:541
zyppng::ProvideRequest::_myQueue
ProvideQueueWeakRef _myQueue
Definition provideitem_p.h:87
zyppng::ProvideRequest::urls
const std::vector< zypp::Url > & urls() const
Definition provideitem_p.h:62
zyppng::ProvideRequest::_activeUrl
std::optional< zypp::Url > _activeUrl
Definition provideitem_p.h:86
zyppng::ProvideRequest::_mirrors
std::vector< zypp::Url > _mirrors
Definition provideitem_p.h:84
zyppng::ProvideRequest::createDetach
static expected< ProvideRequestRef > createDetach(const zypp::Url &url)
Definition provideitem.cc:75
zyppng::ProvideRequest::clearForRestart
void clearForRestart()
Definition provideitem_p.h:74
zyppng::ProvideRequest::provideMessage
ProvideMessage & provideMessage()
Definition provideitem_p.h:53
zyppng::ProvideRequest::create
static expected< ProvideRequestRef > create(ProvideItem &owner, const std::vector< zypp::Url > &urls, const std::string &id, ProvideMediaSpec &spec)
Definition provideitem.cc:27
zyppng::ProvideRequest::provideMessage
const ProvideMessage & provideMessage() const
Definition provideitem_p.h:52
zyppng::ProvideRequest::_message
ProvideMessage _message
Definition provideitem_p.h:83
zyppng::ProvideRequest::url
zypp::Url url() const
Definition provideitem_p.h:66
zyppng::ProvideRequest::setCurrentQueue
void setCurrentQueue(ProvideQueueRef ref)
Definition provideitem.cc:500
zyppng::ProvideRequest::setUrls
void setUrls(const std::vector< zypp::Url > &urls)
Definition provideitem_p.h:58
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:505
zyppng::ProvideRequest::ProvideItem
friend class ProvideItem
Definition provideitem_p.h:39
zyppng::ProvideRequest::activeUrl
const std::optional< zypp::Url > activeUrl() const
Definition provideitem.cc:510
zyppng::ProvideRequest::setUrl
void setUrl(const zypp::Url &url)
Definition provideitem_p.h:70
zyppng::ProvideRequest::_owner
ProvideItem * _owner
Definition provideitem_p.h:82
zyppng::ProvideRequest::ProvideRequest
ProvideRequest(ProvideItem *owner, const std::vector< zypp::Url > &urls, ProvideMessage &&msg)
Definition provideitem_p.h:81
zyppng::Provide::MediaHandle
ProvideMediaHandle MediaHandle
Definition provide.h:120
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 MediaCurl2.h:22
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