libzypp 17.32.5
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
15#include <zypp-core/zyppng/base/Base>
16#include <zypp-core/zyppng/async/AsyncOp>
18#include <zypp-core/ByteCount.h>
19#include <zypp-media/ng/ProvideFwd>
20#include <zypp-media/ng/ProvideRes>
21#include <zypp-media/auth/AuthData>
22#include <boost/any.hpp>
23
24namespace zypp {
25 class Url;
26 namespace media {
27 struct CredManagerOptions;
28 }
29}
30
41namespace zyppng {
42
43 class ProvidePrivate;
44 using AnyMap = std::unordered_map<std::string, boost::any>;
46
51 {
52 public:
53
55
56 ProvideMediaHandle () = default;
57 ProvideMediaHandle ( Provide &parent, AttachedMediaInfo_Ptr mediaInfoRef );
58 std::shared_ptr<Provide> parent() const;
59 bool isValid () const;
60 std::string handle() const;
61 const zypp::Url &baseUrl() const;
62 const std::optional<zypp::Pathname> &localPath() const;
64 private:
65 ProvideWeakRef _parent;
66 AttachedMediaInfo_Ptr _mediaRef;
67 };
68
74 {
75 public:
76
77 struct Stats {
78 std::chrono::steady_clock::time_point _startTime;
79 std::chrono::steady_clock::time_point _lastPulseTime;
80 uint _itemsSinceStart = 0; //< How many items have been started since Provide::start() was called
81 uint _runningItems = 0; //< How many items are currently running
82 zypp::ByteCount _finishedBytes; //< The number of bytes that were finished completely
83 zypp::ByteCount _expectedBytes; //< The number of currently expected bytes
84 zypp::ByteCount _partialBytes; //< The number of bytes of items that were already partially downloaded but the item they belong to is not finished
85 zypp::ByteCount _perSecondSinceLastPulse; //< The download speed since the last pulse
86 zypp::ByteCount _perSecond; //< The download speed we are currently operating with
87 };
88
89 ProvideStatus( ProvideRef parent );
90 virtual ~ProvideStatus(){}
91
92 virtual void provideStart ();
93 virtual void provideDone (){}
94 virtual void itemStart ( ProvideItem &item ){}
95 virtual void itemDone ( ProvideItem &item );
96 virtual void itemFailed ( ProvideItem &item );
97 virtual void requestStart ( ProvideItem &item, uint32_t reqId, const zypp::Url &url, const AnyMap &extraData = {} ){}
98 virtual void requestDone ( ProvideItem &item, uint32_t reqId, const AnyMap &extraData = {} ){}
99 virtual void requestRedirect ( ProvideItem &item, uint32_t reqId, const zypp::Url &toUrl, const AnyMap &extraData = {} ){}
100 virtual void requestFailed ( ProvideItem &item, uint32_t reqId, const std::exception_ptr &err, const AnyMap &requestData = {} ){}
101 virtual void pulse ( );
102
103 const Stats &stats() const;
104
105 private:
107 ProvideWeakRef _provider;
108 };
109
110 class Provide : public Base
111 {
113 template<class T> friend class ProvidePromise;
114 friend class ProvideItem;
115 friend class ProvideMediaHandle;
116 friend class ProvideStatus;
117 public:
118
121
122 static ProvideRef create( const zypp::Pathname &workDir = "" );
123
124 AsyncOpRef<expected<MediaHandle>> attachMedia( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request );
126
127 AsyncOpRef<expected<ProvideRes>> provide( const std::vector<zypp::Url> &urls, const ProvideFileSpec &request );
130
131
136
142
143 void start();
144 void setWorkerPath( const zypp::Pathname &path );
145 bool isRunning() const;
146 bool ejectDevice ( const std::string &queueRef, const std::string &device );
147
148 void setStatusTracker( ProvideStatusRef tracker );
149
150 const zypp::Pathname &providerWorkdir () const;
151
154
156
157 enum Action {
158 ABORT, // abort and return error
159 RETRY, // retry
160 SKIP // abort and set skip request
161 };
162 using MediaChangeAction = std::optional<Action>;
163
170 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( );
171
176 SignalProxy< std::optional<zypp::media::AuthData> ( const zypp::Url &reqUrl, const std::string &triedUsername, const std::map<std::string, std::string> &extraValues ) > sigAuthRequired();
177
178
179 static auto copyResultToDest ( ProvideRef provider, const zypp::Pathname &targetPath ) {
180 return [ providerRef=std::move(provider), targetPath = targetPath ]( ProvideRes &&file ){
181 zypp::filesystem::assert_dir( targetPath.dirname () );
182 return providerRef->copyFile( std::move(file), targetPath );
183 };
184 }
185
186
187 private:
189 };
190
191}
192#endif
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
Store and operate with byte count.
Definition ByteCount.h:31
Url manipulation class.
Definition Url.h:92
Pathname dirname() const
Return all but the last component od this path.
Definition Pathname.h:124
AttachedMediaInfo_Ptr _mediaRef
Definition provide.h:66
const zypp::Url & baseUrl() const
Definition provide.cc:944
zyppng::AttachedMediaInfo_constPtr mediaInfo() const
Definition provide.cc:960
ProvideWeakRef _parent
Definition provide.h:65
const std::optional< zypp::Pathname > & localPath() const
Definition provide.cc:952
std::string handle() const
Definition provide.cc:937
std::shared_ptr< Provide > parent() const
Definition provide.cc:927
A ProvideRes object is a reference counted ownership of a resource in the cache provided by a Provide...
Definition provideres.h:36
virtual void requestFailed(ProvideItem &item, uint32_t reqId, const std::exception_ptr &err, const AnyMap &requestData={})
Definition provide.h:100
virtual void provideDone()
Definition provide.h:93
virtual void requestDone(ProvideItem &item, uint32_t reqId, const AnyMap &extraData={})
Definition provide.h:98
virtual void itemStart(ProvideItem &item)
Definition provide.h:94
virtual void provideStart()
Definition provide.cc:1181
const Stats & stats() const
Definition provide.cc:1206
virtual void requestStart(ProvideItem &item, uint32_t reqId, const zypp::Url &url, const AnyMap &extraData={})
Definition provide.h:97
virtual void pulse()
Definition provide.cc:1211
ProvideWeakRef _provider
Definition provide.h:107
ProvideStatus(ProvideRef parent)
Definition provide.cc:1177
virtual void itemFailed(ProvideItem &item)
Definition provide.cc:1201
virtual void requestRedirect(ProvideItem &item, uint32_t reqId, const zypp::Url &toUrl, const AnyMap &extraData={})
Definition provide.h:99
virtual void itemDone(ProvideItem &item)
Definition provide.cc:1188
virtual ~ProvideStatus()
Definition provide.h:90
bool isRunning() const
AsyncOpRef< expected< ProvideRes > > provide(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request)
Definition provide.cc:1029
const zypp::media::CredManagerOptions & credManangerOptions() const
Definition provide.cc:1149
static ProvideRef create(const zypp::Pathname &workDir="")
Definition provide.cc:972
AsyncOpRef< expected< MediaHandle > > attachMedia(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request)
Definition provide.cc:982
friend class ProvideMediaHandle
Definition provide.h:115
void setWorkerPath(const zypp::Pathname &path)
Definition provide.cc:1126
SignalProxy< std::optional< zypp::media::AuthData >(const zypp::Url &reqUrl, const std::string &triedUsername, const std::map< std::string, std::string > &extraValues) sigAuthRequired)()
SignalProxy< void()> sigIdle()
Definition provide.cc:1160
void setCredManagerOptions(const zypp::media::CredManagerOptions &opt)
Definition provide.cc:1155
Provide(const zypp::Pathname &workDir)
Definition provide.cc:966
AsyncOpRef< expected< zypp::CheckSum > > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
Definition provide.cc:1071
void setStatusTracker(ProvideStatusRef tracker)
Definition provide.cc:1139
bool ejectDevice(const std::string &queueRef, const std::string &device)
Definition provide.cc:1131
ZYPP_DECLARE_PRIVATE(Provide)
AsyncOpRef< expected< zypp::ManagedFile > > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
Definition provide.cc:1091
std::optional< Action > MediaChangeAction
Definition provide.h:162
static auto copyResultToDest(ProvideRef provider, const zypp::Pathname &targetPath)
Definition provide.h:179
const zypp::Pathname & providerWorkdir() const
Definition provide.cc:1144
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)()
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition PathInfo.cc:320
Easy-to use interface to the ZYPP dependency resolver.
zypp::Url Url
Definition url.h:15
std::unordered_map< std::string, boost::any > AnyMap
Definition provide.h:44
zypp::ByteCount _partialBytes
Definition provide.h:84
zypp::ByteCount _perSecondSinceLastPulse
Definition provide.h:85
zypp::ByteCount _perSecond
Definition provide.h:86
zypp::ByteCount _expectedBytes
Definition provide.h:83
std::chrono::steady_clock::time_point _startTime
Definition provide.h:78
zypp::ByteCount _finishedBytes
Definition provide.h:82
std::chrono::steady_clock::time_point _lastPulseTime
Definition provide.h:79
#define DEFINE_PTR_TYPE(NAME)
Forward declaration of Ptr types.
Definition PtrTypes.h:638