libzypp 17.31.23
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
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; }
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
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
84 std::vector<zypp::Url> _mirrors;
85 std::vector<zypp::Url> _pastRedirects;
86 std::optional<zypp::Url> _activeUrl;
87 ProvideQueueWeakRef _myQueue;
88 };
89
91 {
92 public:
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
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
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;
139
140 void setMediaRef ( Provide::MediaHandle &&hdl );
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
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
165 };
166
167
172 {
173 public:
175 static AttachMediaItemRef create ( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request, ProvidePrivate &parent );
176 SignalProxy< void( const zyppng::expected<AttachedMediaInfo *> & ) > sigReady ();
177
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
187 void finishReq ( ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg ) override;
188 void cancelWithError( std::exception_ptr error ) override;
189 void finishWithSuccess (AttachedMediaInfo &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;
202 MediaDataVerifierRef _verifier;
203 };
204}
205
206#endif
Store and operate with byte count.
Definition: ByteCount.h:31
Url manipulation class.
Definition: Url.h:92
void initialize() override
Definition: provideitem.cc:828
Signal< void(const zyppng::expected< AttachedMediaInfo * > &)> _sigReady
void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg) override
ProvidePromiseRef< Provide::MediaHandle > promise()
Definition: provideitem.cc:817
SignalProxy< void(const zyppng::expected< AttachedMediaInfo * > &) > sigReady()
MediaDataVerifierRef _verifier
ProvidePromiseWeakRef< Provide::MediaHandle > _promise
ProvideQueue::Config::WorkerType _workerType
ProvideMediaSpec _initialSpec
void finishWithSuccess(AttachedMediaInfo &medium)
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)
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:760
zypp::Pathname _stagingFile
void cancelWithError(std::exception_ptr error) override
Definition: provideitem.cc:738
zypp::ByteCount bytesExpected() const override
Definition: provideitem.cc:801
void setMediaRef(Provide::MediaHandle &&hdl)
Definition: provideitem.cc:602
Provide::MediaHandle & mediaRef()
Definition: provideitem.cc:607
void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg) override
Provide::MediaHandle _handleRef
void initialize() override
Definition: provideitem.cc:569
static ProvideFileItemRef create(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request, ProvidePrivate &parent)
Definition: provideitem.cc:564
ProvideFileSpec _initialSpec
ProvidePromiseRef< ProvideRes > promise()
Definition: provideitem.cc:591
std::vector< zypp::Url > _mirrorList
zypp::ByteCount _expectedBytes
zypp::Pathname _targetFile
ItemStats makeStats() override
Definition: provideitem.cc:776
void informalMessage(ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg) override
Definition: provideitem.cc:612
ProvidePromiseWeakRef< ProvideRes > _promise
Signal< void(ProvideItem &item, ProvideItem::State oldState, ProvideItem::State newState)> _sigStateChanged
std::chrono::steady_clock::time_point _itemFinished
Definition: provideitem_p.h:97
std::optional< ProvideItem::ItemStats > _currStats
Definition: provideitem_p.h:99
ProvidePrivate & _parent
Definition: provideitem_p.h:94
ProvideItemPrivate(ProvidePrivate &parent, ProvideItem &pub)
Definition: provideitem_p.h:93
ProvideItem::State _itemState
Definition: provideitem_p.h:95
std::chrono::steady_clock::time_point _itemStarted
Definition: provideitem_p.h:96
std::optional< ProvideItem::ItemStats > _prevStats
Definition: provideitem_p.h:98
virtual void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg)
Definition: provideitem.cc:190
ProvideItemWeakRef _myProvide
ProvidePromise(ProvideItemRef provideItem)
std::vector< zypp::Url > _pastRedirects
Definition: provideitem_p.h:85
void setActiveUrl(const zypp::Url &urlToUse)
Definition: provideitem.cc:540
ProvideQueueWeakRef _myQueue
Definition: provideitem_p.h:87
const std::vector< zypp::Url > & urls() const
Definition: provideitem_p.h:62
std::optional< zypp::Url > _activeUrl
Definition: provideitem_p.h:86
std::vector< zypp::Url > _mirrors
Definition: provideitem_p.h:84
static expected< ProvideRequestRef > createDetach(const zypp::Url &url)
Definition: provideitem.cc:75
ProvideMessage & provideMessage()
Definition: provideitem_p.h:53
static expected< ProvideRequestRef > create(ProvideItem &owner, const std::vector< zypp::Url > &urls, const std::string &id, ProvideMediaSpec &spec)
Definition: provideitem.cc:27
const ProvideMessage & provideMessage() const
Definition: provideitem_p.h:52
ProvideMessage _message
Definition: provideitem_p.h:83
zypp::Url url() const
Definition: provideitem_p.h:66
void setCurrentQueue(ProvideQueueRef ref)
Definition: provideitem.cc:499
void setUrls(const std::vector< zypp::Url > &urls)
Definition: provideitem_p.h:58
ProvideItem * owner()
Definition: provideitem_p.h:45
ProvideQueueRef currentQueue()
Definition: provideitem.cc:504
const std::optional< zypp::Url > activeUrl() const
Definition: provideitem.cc:509
void setUrl(const zypp::Url &url)
Definition: provideitem_p.h:70
ProvideItem * _owner
Definition: provideitem_p.h:82
ProvideRequest(ProvideItem *owner, const std::vector< zypp::Url > &urls, ProvideMessage &&msg)
Definition: provideitem_p.h:81
Definition: Arch.h:361
std::shared_ptr< ProvidePromise< T > > ProvidePromiseRef
Definition: providefwd_p.h:31
std::weak_ptr< ProvidePromise< T > > ProvidePromiseWeakRef
Definition: providefwd_p.h:33