libzypp 17.36.7

provide.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_MEDIA_PROVIDE_H_INCLUDED
10#define ZYPP_MEDIA_PROVIDE_H_INCLUDED
11
12#include <zypp-core/fs/PathInfo.h>
13#include <zypp-core/ManagedFile.h>
14#include <zypp-core/zyppng/base/zyppglobal.h>
15#include <zypp-core/zyppng/base/Base>
16#include <zypp-core/zyppng/async/AsyncOp>
17#include <zypp-core/zyppng/pipelines/expected.h>
18#include <zypp-core/ByteCount.h>
19#include <zypp-media/ng/LazyMediaHandle>
20#include <zypp-media/ng/ProvideFwd>
21#include <zypp-media/ng/ProvideRes>
22#include <zypp-media/auth/AuthData>
23#include <boost/any.hpp>
24
25 namespace zypp {
26 class Url;
27 namespace media {
28 struct CredManagerOptions;
29 }
30}
31
42 namespace zyppng {
43
44 class ProvidePrivate;
45 using AnyMap = std::unordered_map<std::string, boost::any>;
46 DEFINE_PTR_TYPE(AttachedMediaInfo);
47
51 class ProvideMediaHandle
52 {
53 public:
54
55 using ParentType = Provide;
56
57 ProvideMediaHandle () = default;
58 ProvideMediaHandle ( Provide &parent, AttachedMediaInfo_Ptr mediaInfoRef );
59 std::shared_ptr<Provide> parent() const;
60 bool isValid () const;
61 std::string handle() const;
62 const zypp::Url &baseUrl() const;
63 const std::optional<zypp::Pathname> &localPath() const;
64 zyppng::AttachedMediaInfo_constPtr mediaInfo() const;
65 private:
66 ProvideWeakRef _parent;
67 AttachedMediaInfo_Ptr _mediaRef;
68 };
69
74 class ProvideStatus
75 {
76 public:
77
78 struct Stats {
79 std::chrono::steady_clock::time_point _startTime;
80 std::chrono::steady_clock::time_point _lastPulseTime;
81 uint _itemsSinceStart = 0; //< How many items have been started since Provide::start() was called
82 uint _runningItems = 0; //< How many items are currently running
83 zypp::ByteCount _finishedBytes; //< The number of bytes that were finished completely
84 zypp::ByteCount _expectedBytes; //< The number of currently expected bytes
85 zypp::ByteCount _partialBytes; //< The number of bytes of items that were already partially downloaded but the item they belong to is not finished
86 zypp::ByteCount _perSecondSinceLastPulse; //< The download speed since the last pulse
87 zypp::ByteCount _perSecond; //< The download speed we are currently operating with
88 };
89
90 ProvideStatus( ProvideRef parent );
91 virtual ~ProvideStatus(){}
92
93 virtual void provideStart ();
94 virtual void provideDone (){}
95 virtual void itemStart ( ProvideItem &item ){}
96 virtual void itemDone ( ProvideItem &item );
97 virtual void itemFailed ( ProvideItem &item );
98 virtual void requestStart ( ProvideItem &item, uint32_t reqId, const zypp::Url &url, const AnyMap &extraData = {} ){}
99 virtual void requestDone ( ProvideItem &item, uint32_t reqId, const AnyMap &extraData = {} ){}
100 virtual void requestRedirect ( ProvideItem &item, uint32_t reqId, const zypp::Url &toUrl, const AnyMap &extraData = {} ){}
101 virtual void requestFailed ( ProvideItem &item, uint32_t reqId, const std::exception_ptr &err, const AnyMap &requestData = {} ){}
102 virtual void pulse ( );
103
104 const Stats &stats() const;
105
106 private:
107 Stats _stats;
108 ProvideWeakRef _provider;
109 };
110
111 class Provide : public Base
112 {
113 ZYPP_DECLARE_PRIVATE(Provide)
114 template<class T> friend class ProvidePromise;
115 friend class ProvideItem;
116 friend class ProvideMediaHandle;
117 friend class ProvideStatus;
118 public:
119
120 using MediaHandle = ProvideMediaHandle;
121 using LazyMediaHandle = zyppng::LazyMediaHandle<Provide>;
122 using Res = ProvideRes;
123
124 static ProvideRef create( const zypp::Pathname &workDir = "" );
125
130 expected<LazyMediaHandle> prepareMedia ( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request );
131 expected<LazyMediaHandle> prepareMedia ( const zypp::Url &url, const ProvideMediaSpec &request );
132
133 AsyncOpRef<expected<MediaHandle>> attachMediaIfNeeded( LazyMediaHandle lazyHandle );
134 AsyncOpRef<expected<MediaHandle>> attachMedia( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request );
135 AsyncOpRef<expected<MediaHandle>> attachMedia( const zypp::Url &url, const ProvideMediaSpec &request );
136
137 AsyncOpRef<expected<ProvideRes>> provide( const std::vector<zypp::Url> &urls, const ProvideFileSpec &request );
138 AsyncOpRef<expected<ProvideRes>> provide( const zypp::Url &url, const ProvideFileSpec &request );
139 AsyncOpRef<expected<ProvideRes>> provide( const MediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
140 AsyncOpRef<expected<ProvideRes>> provide( const LazyMediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
141
142
146 AsyncOpRef<expected<zypp::CheckSum>> checksumForFile ( const zypp::Pathname &p, const std::string &algorithm );
147
151 AsyncOpRef<expected<zypp::ManagedFile>> copyFile ( const zypp::Pathname &source, const zypp::Pathname &target );
152 AsyncOpRef<expected<zypp::ManagedFile>> copyFile ( ProvideRes &&source, const zypp::Pathname &target );
153
154 void start();
155 void setWorkerPath( const zypp::Pathname &path );
156 bool isRunning() const;
157 bool ejectDevice ( const std::string &queueRef, const std::string &device );
158
159 void setStatusTracker( ProvideStatusRef tracker );
160
161 const zypp::Pathname &providerWorkdir () const;
162
163 const zypp::media::CredManagerOptions &credManangerOptions () const;
164 void setCredManagerOptions( const zypp::media::CredManagerOptions & opt );
165
166 SignalProxy<void()> sigIdle();
167
168 enum Action {
169 ABORT, // abort and return error
170 RETRY, // retry
171 SKIP // abort and set skip request
172 };
173 using MediaChangeAction = std::optional<Action>;
174
181 SignalProxy<MediaChangeAction( const std::string &queueRef, const std::string &label, const int32_t mediaNr, const std::vector<std::string> &devices, const std::optional<std::string> &desc )> sigMediaChangeRequested( );
182
187 SignalProxy< std::optional<zypp::media::AuthData> ( const zypp::Url &reqUrl, const std::string &triedUsername, const std::map<std::string, std::string> &extraValues ) > sigAuthRequired();
188
189
190 static auto copyResultToDest ( ProvideRef provider, const zypp::Pathname &targetPath ) {
191 return [ providerRef=std::move(provider), targetPath = targetPath ]( ProvideRes &&file ){
192 zypp::filesystem::assert_dir( targetPath.dirname () );
193 return providerRef->copyFile( std::move(file), targetPath );
194 };
195 }
196
197
198 private:
199 Provide( const zypp::Pathname &workDir );
200 };
201
202}
203#endif
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::CheckSum
Definition CheckSum.h:34
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::filesystem::Pathname::dirname
Pathname dirname() const
Return all but the last component od this path.
Definition Pathname.h:126
zyppng::AttachedMediaInfo
Definition attachedmediainfo_p.h:31
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::ProvideFileSpec
Definition providespec.h:92
zyppng::ProvideItem
Definition provideitem.h:29
zyppng::ProvideMediaHandle::ParentType
Provide ParentType
Definition provide.h:55
zyppng::ProvideMediaHandle::_mediaRef
AttachedMediaInfo_Ptr _mediaRef
Definition provide.h:67
zyppng::ProvideMediaHandle::baseUrl
const zypp::Url & baseUrl() const
Definition provide.cc:974
zyppng::ProvideMediaHandle::mediaInfo
zyppng::AttachedMediaInfo_constPtr mediaInfo() const
Definition provide.cc:990
zyppng::ProvideMediaHandle::isValid
bool isValid() const
Definition provide.cc:962
zyppng::ProvideMediaHandle::_parent
ProvideWeakRef _parent
Definition provide.h:66
zyppng::ProvideMediaHandle::localPath
const std::optional< zypp::Pathname > & localPath() const
Definition provide.cc:982
zyppng::ProvideMediaHandle::handle
std::string handle() const
Definition provide.cc:967
zyppng::ProvideMediaHandle::ProvideMediaHandle
ProvideMediaHandle()=default
zyppng::ProvideMediaHandle::parent
std::shared_ptr< Provide > parent() const
Definition provide.cc:957
zyppng::ProvideMediaSpec
Definition providespec.h:29
zyppng::ProvidePrivate
Definition provide_p.h:42
zyppng::ProvideRes
A ProvideRes object is a reference counted ownership of a resource in the cache provided by a Provide...
Definition provideres.h:36
zyppng::ProvideStatus::requestFailed
virtual void requestFailed(ProvideItem &item, uint32_t reqId, const std::exception_ptr &err, const AnyMap &requestData={})
Definition provide.h:101
zyppng::ProvideStatus::_stats
Stats _stats
Definition provide.h:107
zyppng::ProvideStatus::provideDone
virtual void provideDone()
Definition provide.h:94
zyppng::ProvideStatus::requestDone
virtual void requestDone(ProvideItem &item, uint32_t reqId, const AnyMap &extraData={})
Definition provide.h:99
zyppng::ProvideStatus::itemStart
virtual void itemStart(ProvideItem &item)
Definition provide.h:95
zyppng::ProvideStatus::provideStart
virtual void provideStart()
Definition provide.cc:1230
zyppng::ProvideStatus::stats
const Stats & stats() const
Definition provide.cc:1255
zyppng::ProvideStatus::requestStart
virtual void requestStart(ProvideItem &item, uint32_t reqId, const zypp::Url &url, const AnyMap &extraData={})
Definition provide.h:98
zyppng::ProvideStatus::pulse
virtual void pulse()
Definition provide.cc:1260
zyppng::ProvideStatus::_provider
ProvideWeakRef _provider
Definition provide.h:108
zyppng::ProvideStatus::ProvideStatus
ProvideStatus(ProvideRef parent)
Definition provide.cc:1226
zyppng::ProvideStatus::itemFailed
virtual void itemFailed(ProvideItem &item)
Definition provide.cc:1250
zyppng::ProvideStatus::requestRedirect
virtual void requestRedirect(ProvideItem &item, uint32_t reqId, const zypp::Url &toUrl, const AnyMap &extraData={})
Definition provide.h:100
zyppng::ProvideStatus::itemDone
virtual void itemDone(ProvideItem &item)
Definition provide.cc:1237
zyppng::ProvideStatus::~ProvideStatus
virtual ~ProvideStatus()
Definition provide.h:91
zyppng::Provide
Definition provide.h:112
zyppng::Provide::isRunning
bool isRunning() const
zyppng::Provide::Action
Action
Definition provide.h:168
zyppng::Provide::SKIP
@ SKIP
Definition provide.h:171
zyppng::Provide::ABORT
@ ABORT
Definition provide.h:169
zyppng::Provide::RETRY
@ RETRY
Definition provide.h:170
zyppng::Provide::provide
AsyncOpRef< expected< ProvideRes > > provide(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request)
Definition provide.cc:1066
zyppng::Provide::credManangerOptions
const zypp::media::CredManagerOptions & credManangerOptions() const
Definition provide.cc:1198
zyppng::Provide::sigAuthRequired
SignalProxy< std::optional< zypp::media::AuthData >(const zypp::Url &reqUrl, const std::string &triedUsername, const std::map< std::string, std::string > &extraValues) > sigAuthRequired()
Definition provide.cc:1219
zyppng::Provide::create
static ProvideRef create(const zypp::Pathname &workDir="")
Definition provide.cc:1002
zyppng::Provide::attachMedia
AsyncOpRef< expected< MediaHandle > > attachMedia(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request)
Definition provide.cc:1043
zyppng::Provide::ProvideMediaHandle
friend class ProvideMediaHandle
Definition provide.h:116
zyppng::Provide::setWorkerPath
void setWorkerPath(const zypp::Pathname &path)
Definition provide.cc:1175
zyppng::Provide::sigIdle
SignalProxy< void()> sigIdle()
Definition provide.cc:1209
zyppng::Provide::setCredManagerOptions
void setCredManagerOptions(const zypp::media::CredManagerOptions &opt)
Definition provide.cc:1204
zyppng::Provide::Provide
Provide(const zypp::Pathname &workDir)
Definition provide.cc:996
zyppng::Provide::Res
ProvideRes Res
Definition provide.h:122
zyppng::Provide::checksumForFile
AsyncOpRef< expected< zypp::CheckSum > > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
Definition provide.cc:1120
zyppng::Provide::setStatusTracker
void setStatusTracker(ProvideStatusRef tracker)
Definition provide.cc:1188
zyppng::Provide::attachMediaIfNeeded
AsyncOpRef< expected< MediaHandle > > attachMediaIfNeeded(LazyMediaHandle lazyHandle)
Definition provide.cc:1023
zyppng::Provide::LazyMediaHandle
zyppng::LazyMediaHandle< Provide > LazyMediaHandle
Definition provide.h:121
zyppng::Provide::ProvidePromise
friend class ProvidePromise
Definition provide.h:114
zyppng::Provide::ejectDevice
bool ejectDevice(const std::string &queueRef, const std::string &device)
Definition provide.cc:1180
zyppng::Provide::prepareMedia
expected< LazyMediaHandle > prepareMedia(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request)
Definition provide.cc:1007
zyppng::Provide::copyFile
AsyncOpRef< expected< zypp::ManagedFile > > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
Definition provide.cc:1140
zyppng::Provide::sigMediaChangeRequested
SignalProxy< MediaChangeAction(const std::string &queueRef, const std::string &label, const int32_t mediaNr, const std::vector< std::string > &devices, const std::optional< std::string > &desc)> sigMediaChangeRequested()
Definition provide.cc:1214
zyppng::Provide::MediaChangeAction
std::optional< Action > MediaChangeAction
Definition provide.h:173
zyppng::Provide::copyResultToDest
static auto copyResultToDest(ProvideRef provider, const zypp::Pathname &targetPath)
Definition provide.h:190
zyppng::Provide::start
void start()
Definition provide.cc:1166
zyppng::Provide::ProvideItem
friend class ProvideItem
Definition provide.h:115
zyppng::Provide::providerWorkdir
const zypp::Pathname & providerWorkdir() const
Definition provide.cc:1193
zyppng::Provide::ProvideStatus
friend class ProvideStatus
Definition provide.h:117
zyppng::Provide::MediaHandle
ProvideMediaHandle MediaHandle
Definition provide.h:120
zyppng::SignalProxy
Definition signals.h:325
zyppng::expected
Definition expected.h:27
expected.h
std
Definition Arch.h:364
zypp::filesystem::assert_dir
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition PathInfo.cc:324
zypp::media
Definition MediaCD.cc:47
zypp::target
Definition KeyRing.h:325
zypp::url
Url details namespace.
Definition UrlBase.cc:58
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::ManagedFile
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition ManagedFile.h:27
zyppng
Definition MediaCurl2.h:22
zyppng::AsyncOpRef
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Definition asyncop.h:255
zyppng::AnyMap
std::unordered_map< std::string, boost::any > AnyMap
Definition provide.h:45
zypp::media::CredManagerOptions
Definition credentialmanager.h:40
zyppng::ProvideStatus::Stats
Definition provide.h:78
zyppng::ProvideStatus::Stats::_itemsSinceStart
uint _itemsSinceStart
Definition provide.h:81
zyppng::ProvideStatus::Stats::_partialBytes
zypp::ByteCount _partialBytes
Definition provide.h:85
zyppng::ProvideStatus::Stats::_perSecondSinceLastPulse
zypp::ByteCount _perSecondSinceLastPulse
Definition provide.h:86
zyppng::ProvideStatus::Stats::_perSecond
zypp::ByteCount _perSecond
Definition provide.h:87
zyppng::ProvideStatus::Stats::_expectedBytes
zypp::ByteCount _expectedBytes
Definition provide.h:84
zyppng::ProvideStatus::Stats::_startTime
std::chrono::steady_clock::time_point _startTime
Definition provide.h:79
zyppng::ProvideStatus::Stats::_runningItems
uint _runningItems
Definition provide.h:82
zyppng::ProvideStatus::Stats::_finishedBytes
zypp::ByteCount _finishedBytes
Definition provide.h:83
zyppng::ProvideStatus::Stats::_lastPulseTime
std::chrono::steady_clock::time_point _lastPulseTime
Definition provide.h:80
ByteCount.h
ManagedFile.h
DEFINE_PTR_TYPE
#define DEFINE_PTR_TYPE(NAME)
Forward declaration of Ptr types.
Definition PtrTypes.h:639
PathInfo.h
zyppglobal.h
ZYPP_DECLARE_PRIVATE
#define ZYPP_DECLARE_PRIVATE(Class)
Definition zyppglobal.h:87