libzypp 17.37.10

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/MirroredOrigin.h>
15#include <zypp-core/zyppng/base/zyppglobal.h>
16#include <zypp-core/zyppng/base/Base>
17#include <zypp-core/zyppng/async/AsyncOp>
18#include <zypp-core/zyppng/pipelines/expected.h>
19#include <zypp-core/ByteCount.h>
20#include <zypp-media/ng/LazyMediaHandle>
21#include <zypp-media/ng/ProvideFwd>
22#include <zypp-media/ng/ProvideRes>
23#include <zypp-media/auth/AuthData>
24#include <boost/any.hpp>
25
26 namespace zypp {
27 class Url;
28 namespace media {
29 struct CredManagerOptions;
30 }
31}
32
45 namespace zyppng {
46
47 class ProvidePrivate;
48 using AnyMap = std::unordered_map<std::string, boost::any>;
49 DEFINE_PTR_TYPE(AttachedMediaInfo);
50
54 class ProvideMediaHandle
55 {
56 public:
57
58 using ParentType = Provide;
59
60 ProvideMediaHandle () = default;
61 ProvideMediaHandle ( Provide &parent, AttachedMediaInfo_Ptr mediaInfoRef );
62 std::shared_ptr<Provide> parent() const;
63 bool isValid () const;
64 std::string handle() const;
65 const zypp::Url &baseUrl() const;
66 const zypp::MirroredOrigin &origin() const;
67 const std::optional<zypp::Pathname> &localPath() const;
68 zyppng::AttachedMediaInfo_constPtr mediaInfo() const;
69 private:
70 ProvideWeakRef _parent;
71 AttachedMediaInfo_Ptr _mediaRef;
72 };
73
78 class ProvideStatus
79 {
80 public:
81
82 struct Stats {
83 std::chrono::steady_clock::time_point _startTime;
84 std::chrono::steady_clock::time_point _lastPulseTime;
85 uint _itemsSinceStart = 0; //< How many items have been started since Provide::start() was called
86 uint _runningItems = 0; //< How many items are currently running
87 zypp::ByteCount _finishedBytes; //< The number of bytes that were finished completely
88 zypp::ByteCount _expectedBytes; //< The number of currently expected bytes
89 zypp::ByteCount _partialBytes; //< The number of bytes of items that were already partially downloaded but the item they belong to is not finished
90 zypp::ByteCount _perSecondSinceLastPulse; //< The download speed since the last pulse
91 zypp::ByteCount _perSecond; //< The download speed we are currently operating with
92 };
93
94 ProvideStatus( ProvideRef parent );
95 virtual ~ProvideStatus(){}
96
97 virtual void provideStart ();
98 virtual void provideDone (){}
99 virtual void itemStart ( ProvideItem &item ){}
100 virtual void itemDone ( ProvideItem &item );
101 virtual void itemFailed ( ProvideItem &item );
102 virtual void requestStart ( ProvideItem &item, uint32_t reqId, const zypp::Url &url, const AnyMap &extraData = {} ){}
103 virtual void requestDone ( ProvideItem &item, uint32_t reqId, const AnyMap &extraData = {} ){}
104 virtual void requestRedirect ( ProvideItem &item, uint32_t reqId, const zypp::Url &toUrl, const AnyMap &extraData = {} ){}
105 virtual void requestFailed ( ProvideItem &item, uint32_t reqId, const std::exception_ptr &err, const AnyMap &requestData = {} ){}
106 virtual void pulse ( );
107
108 const Stats &stats() const;
109
110 private:
111 Stats _stats;
112 ProvideWeakRef _provider;
113 };
114
115 class Provide : public Base
116 {
117 ZYPP_DECLARE_PRIVATE(Provide)
118 template<class T> friend class ProvidePromise;
119 friend class ProvideItem;
120 friend class ProvideMediaHandle;
121 friend class ProvideStatus;
122 public:
123
124 using MediaHandle = ProvideMediaHandle;
125 using LazyMediaHandle = zyppng::LazyMediaHandle<Provide>;
126 using Res = ProvideRes;
127
128 static ProvideRef create( const zypp::Pathname &workDir = "" );
129
134 expected<LazyMediaHandle> prepareMedia ( const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request );
135 expected<LazyMediaHandle> prepareMedia ( const zypp::Url &url, const ProvideMediaSpec &request );
136
137 AsyncOpRef<expected<MediaHandle>> attachMediaIfNeeded( LazyMediaHandle lazyHandle );
138 AsyncOpRef<expected<MediaHandle>> attachMedia( const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request );
139 AsyncOpRef<expected<MediaHandle>> attachMedia( const zypp::Url &url, const ProvideMediaSpec &request );
140
141 AsyncOpRef<expected<ProvideRes>> provide( const zypp::MirroredOrigin &origin, const ProvideFileSpec &request );
142 AsyncOpRef<expected<ProvideRes>> provide( const zypp::Url &url, const ProvideFileSpec &request );
143 AsyncOpRef<expected<ProvideRes>> provide( const MediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
144 AsyncOpRef<expected<ProvideRes>> provide( const LazyMediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
145
146
150 AsyncOpRef<expected<zypp::CheckSum>> checksumForFile ( const zypp::Pathname &p, const std::string &algorithm );
151
155 AsyncOpRef<expected<zypp::ManagedFile>> copyFile ( const zypp::Pathname &source, const zypp::Pathname &target );
156 AsyncOpRef<expected<zypp::ManagedFile>> copyFile ( ProvideRes &&source, const zypp::Pathname &target );
157
158 void start();
159 void setWorkerPath( const zypp::Pathname &path );
160 bool isRunning() const;
161 bool ejectDevice ( const std::string &queueRef, const std::string &device );
162
163 void setStatusTracker( ProvideStatusRef tracker );
164
165 const zypp::Pathname &providerWorkdir () const;
166
167 const zypp::media::CredManagerOptions &credManangerOptions () const;
168 void setCredManagerOptions( const zypp::media::CredManagerOptions & opt );
169
170 SignalProxy<void()> sigIdle();
171
172 enum Action {
173 ABORT, // abort and return error
174 RETRY, // retry
175 SKIP // abort and set skip request
176 };
177 using MediaChangeAction = std::optional<Action>;
178
185 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( );
186
191 SignalProxy< std::optional<zypp::media::AuthData> ( const zypp::Url &reqUrl, const std::string &triedUsername, const std::map<std::string, std::string> &extraValues ) > sigAuthRequired();
192
193
194 static auto copyResultToDest ( ProvideRef provider, const zypp::Pathname &targetPath ) {
195 return [ providerRef=std::move(provider), targetPath = targetPath ]( ProvideRes &&file ){
196 zypp::filesystem::assert_dir( targetPath.dirname () );
197 return providerRef->copyFile( std::move(file), targetPath );
198 };
199 }
200
201
202 private:
203 Provide( const zypp::Pathname &workDir );
204 };
205
206}
207#endif
MirroredOrigin.h
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::CheckSum
Definition CheckSum.h:34
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
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:58
zyppng::ProvideMediaHandle::_mediaRef
AttachedMediaInfo_Ptr _mediaRef
Definition provide.h:71
zyppng::ProvideMediaHandle::baseUrl
const zypp::Url & baseUrl() const
Definition provide.cc:969
zyppng::ProvideMediaHandle::mediaInfo
zyppng::AttachedMediaInfo_constPtr mediaInfo() const
Definition provide.cc:993
zyppng::ProvideMediaHandle::isValid
bool isValid() const
Definition provide.cc:957
zyppng::ProvideMediaHandle::_parent
ProvideWeakRef _parent
Definition provide.h:70
zyppng::ProvideMediaHandle::localPath
const std::optional< zypp::Pathname > & localPath() const
Definition provide.cc:985
zyppng::ProvideMediaHandle::handle
std::string handle() const
Definition provide.cc:962
zyppng::ProvideMediaHandle::ProvideMediaHandle
ProvideMediaHandle()=default
zyppng::ProvideMediaHandle::parent
std::shared_ptr< Provide > parent() const
Definition provide.cc:952
zyppng::ProvideMediaHandle::origin
const zypp::MirroredOrigin & origin() const
Definition provide.cc:977
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:105
zyppng::ProvideStatus::_stats
Stats _stats
Definition provide.h:111
zyppng::ProvideStatus::provideDone
virtual void provideDone()
Definition provide.h:98
zyppng::ProvideStatus::requestDone
virtual void requestDone(ProvideItem &item, uint32_t reqId, const AnyMap &extraData={})
Definition provide.h:103
zyppng::ProvideStatus::itemStart
virtual void itemStart(ProvideItem &item)
Definition provide.h:99
zyppng::ProvideStatus::provideStart
virtual void provideStart()
Definition provide.cc:1245
zyppng::ProvideStatus::stats
const Stats & stats() const
Definition provide.cc:1270
zyppng::ProvideStatus::requestStart
virtual void requestStart(ProvideItem &item, uint32_t reqId, const zypp::Url &url, const AnyMap &extraData={})
Definition provide.h:102
zyppng::ProvideStatus::pulse
virtual void pulse()
Definition provide.cc:1275
zyppng::ProvideStatus::_provider
ProvideWeakRef _provider
Definition provide.h:112
zyppng::ProvideStatus::ProvideStatus
ProvideStatus(ProvideRef parent)
Definition provide.cc:1241
zyppng::ProvideStatus::itemFailed
virtual void itemFailed(ProvideItem &item)
Definition provide.cc:1265
zyppng::ProvideStatus::requestRedirect
virtual void requestRedirect(ProvideItem &item, uint32_t reqId, const zypp::Url &toUrl, const AnyMap &extraData={})
Definition provide.h:104
zyppng::ProvideStatus::itemDone
virtual void itemDone(ProvideItem &item)
Definition provide.cc:1252
zyppng::ProvideStatus::~ProvideStatus
virtual ~ProvideStatus()
Definition provide.h:95
zyppng::Provide
Definition provide.h:116
zyppng::Provide::isRunning
bool isRunning() const
zyppng::Provide::Action
Action
Definition provide.h:172
zyppng::Provide::SKIP
@ SKIP
Definition provide.h:175
zyppng::Provide::ABORT
@ ABORT
Definition provide.h:173
zyppng::Provide::RETRY
@ RETRY
Definition provide.h:174
zyppng::Provide::credManangerOptions
const zypp::media::CredManagerOptions & credManangerOptions() const
Definition provide.cc:1213
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:1234
zyppng::Provide::create
static ProvideRef create(const zypp::Pathname &workDir="")
Definition provide.cc:1005
zyppng::Provide::ProvideMediaHandle
friend class ProvideMediaHandle
Definition provide.h:120
zyppng::Provide::setWorkerPath
void setWorkerPath(const zypp::Pathname &path)
Definition provide.cc:1190
zyppng::Provide::sigIdle
SignalProxy< void()> sigIdle()
Definition provide.cc:1224
zyppng::Provide::prepareMedia
expected< LazyMediaHandle > prepareMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
Definition provide.cc:1010
zyppng::Provide::setCredManagerOptions
void setCredManagerOptions(const zypp::media::CredManagerOptions &opt)
Definition provide.cc:1219
zyppng::Provide::Provide
Provide(const zypp::Pathname &workDir)
Definition provide.cc:999
zyppng::Provide::Res
ProvideRes Res
Definition provide.h:126
zyppng::Provide::checksumForFile
AsyncOpRef< expected< zypp::CheckSum > > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
Definition provide.cc:1135
zyppng::Provide::setStatusTracker
void setStatusTracker(ProvideStatusRef tracker)
Definition provide.cc:1203
zyppng::Provide::attachMediaIfNeeded
AsyncOpRef< expected< MediaHandle > > attachMediaIfNeeded(LazyMediaHandle lazyHandle)
Definition provide.cc:1026
zyppng::Provide::LazyMediaHandle
zyppng::LazyMediaHandle< Provide > LazyMediaHandle
Definition provide.h:125
zyppng::Provide::ProvidePromise
friend class ProvidePromise
Definition provide.h:118
zyppng::Provide::ejectDevice
bool ejectDevice(const std::string &queueRef, const std::string &device)
Definition provide.cc:1195
zyppng::Provide::attachMedia
AsyncOpRef< expected< MediaHandle > > attachMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
Definition provide.cc:1046
zyppng::Provide::copyFile
AsyncOpRef< expected< zypp::ManagedFile > > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
Definition provide.cc:1155
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:1229
zyppng::Provide::MediaChangeAction
std::optional< Action > MediaChangeAction
Definition provide.h:177
zyppng::Provide::copyResultToDest
static auto copyResultToDest(ProvideRef provider, const zypp::Pathname &targetPath)
Definition provide.h:194
zyppng::Provide::start
void start()
Definition provide.cc:1181
zyppng::Provide::ProvideItem
friend class ProvideItem
Definition provide.h:119
zyppng::Provide::providerWorkdir
const zypp::Pathname & providerWorkdir() const
Definition provide.cc:1208
zyppng::Provide::ProvideStatus
friend class ProvideStatus
Definition provide.h:121
zyppng::Provide::MediaHandle
ProvideMediaHandle MediaHandle
Definition provide.h:124
zyppng::Provide::provide
AsyncOpRef< expected< ProvideRes > > provide(const zypp::MirroredOrigin &origin, const ProvideFileSpec &request)
Definition provide.cc:1069
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 MediaNetworkRequestExecutor.h:22
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 MediaNetworkRequestExecutor.h:16
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:48
zypp::media::CredManagerOptions
Definition credentialmanager.h:40
zyppng::ProvideStatus::Stats
Definition provide.h:82
zyppng::ProvideStatus::Stats::_itemsSinceStart
uint _itemsSinceStart
Definition provide.h:85
zyppng::ProvideStatus::Stats::_partialBytes
zypp::ByteCount _partialBytes
Definition provide.h:89
zyppng::ProvideStatus::Stats::_perSecondSinceLastPulse
zypp::ByteCount _perSecondSinceLastPulse
Definition provide.h:90
zyppng::ProvideStatus::Stats::_perSecond
zypp::ByteCount _perSecond
Definition provide.h:91
zyppng::ProvideStatus::Stats::_expectedBytes
zypp::ByteCount _expectedBytes
Definition provide.h:88
zyppng::ProvideStatus::Stats::_startTime
std::chrono::steady_clock::time_point _startTime
Definition provide.h:83
zyppng::ProvideStatus::Stats::_runningItems
uint _runningItems
Definition provide.h:86
zyppng::ProvideStatus::Stats::_finishedBytes
zypp::ByteCount _finishedBytes
Definition provide.h:87
zyppng::ProvideStatus::Stats::_lastPulseTime
std::chrono::steady_clock::time_point _lastPulseTime
Definition provide.h:84
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