libzypp 17.35.13
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
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;
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 );
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_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
193
194 private:
196 bool _promiseCreated = false;
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
202 MediaDataVerifierRef _verifier;
203 };
204}
205
206#endif
Store and operate with byte count.
Definition ByteCount.h:32
Url manipulation class.
Definition Url.h:92
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
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
virtual void finishReq(ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg)
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
void setUrl(const zypp::Url &url)
ProvideRequest(ProvideItem *owner, const std::vector< zypp::Url > &urls, ProvideMessage &&msg)
Definition Arch.h:364
std::shared_ptr< ProvidePromise< T > > ProvidePromiseRef
sigc::connection connection
Definition signals.h:180
std::weak_ptr< ProvidePromise< T > > ProvidePromiseWeakRef