libzypp 17.31.23
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/ManagedFile.h>
13#include <zypp-core/zyppng/base/zyppglobal.h>
14#include <zypp-core/zyppng/base/Base>
15#include <zypp-core/zyppng/async/AsyncOp>
16#include <zypp-core/zyppng/pipelines/expected.h>
17#include <zypp-core/ByteCount.h>
18#include <zypp-media/ng/ProvideFwd>
19#include <zypp-media/ng/ProvideRes>
20#include <zypp-media/auth/AuthData>
21#include <boost/any.hpp>
22
23namespace zypp {
24 class Url;
25 namespace media {
26 struct CredManagerOptions;
27 }
28}
29
38namespace zyppng {
39
40 class ProvidePrivate;
41 using AnyMap = std::unordered_map<std::string, boost::any>;
42
47 {
48 public:
49 ProvideMediaHandle () = default;
50 ProvideMediaHandle ( Provide &parent, const std::string &hdl );
51 std::shared_ptr<Provide> parent() const;
52 bool isValid () const;
53 std::string handle() const;
54 private:
55 struct Data;
56 std::shared_ptr<Data> _ref;
57 };
58
64 {
65 public:
66
67 struct Stats {
68 std::chrono::steady_clock::time_point _startTime;
69 std::chrono::steady_clock::time_point _lastPulseTime;
70 uint _itemsSinceStart = 0; //< How many items have been started since Provide::start() was called
71 uint _runningItems = 0; //< How many items are currently running
72 zypp::ByteCount _finishedBytes; //< The number of bytes that were finished completely
73 zypp::ByteCount _expectedBytes; //< The number of currently expected bytes
74 zypp::ByteCount _partialBytes; //< The number of bytes of items that were already partially downloaded but the item they belong to is not finished
75 zypp::ByteCount _perSecondSinceLastPulse; //< The download speed since the last pulse
76 zypp::ByteCount _perSecond; //< The download speed we are currently operating with
77 };
78
79 ProvideStatus( ProvideRef parent );
80 virtual ~ProvideStatus(){}
81
82 virtual void provideStart ();
83 virtual void provideDone (){}
84 virtual void itemStart ( ProvideItem &item ){}
85 virtual void itemDone ( ProvideItem &item );
86 virtual void itemFailed ( ProvideItem &item );
87 virtual void requestStart ( ProvideItem &item, uint32_t reqId, const zypp::Url &url, const AnyMap &extraData = {} ){}
88 virtual void requestDone ( ProvideItem &item, uint32_t reqId, const AnyMap &extraData = {} ){}
89 virtual void requestRedirect ( ProvideItem &item, uint32_t reqId, const zypp::Url &toUrl, const AnyMap &extraData = {} ){}
90 virtual void requestFailed ( ProvideItem &item, uint32_t reqId, const std::exception_ptr err, const AnyMap &requestData = {} ){}
91 virtual void pulse ( );
92
93 const Stats &stats() const;
94
95 private:
97 ProvideWeakRef _provider;
98 };
99
100 class Provide : public Base
101 {
103 template<class T> friend class ProvidePromise;
104 friend class ProvideItem;
105 friend class ProvideMediaHandle;
106 friend class ProvideStatus;
107 public:
108
110
111 static ProvideRef create( const zypp::Pathname &workDir = "" );
112
113 AsyncOpRef<expected<MediaHandle>> attachMedia( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request );
114 AsyncOpRef<expected<MediaHandle>> attachMedia( const zypp::Url &url, const ProvideMediaSpec &request );
115
116 AsyncOpRef<expected<ProvideRes>> provide( const std::vector<zypp::Url> &urls, const ProvideFileSpec &request );
117 AsyncOpRef<expected<ProvideRes>> provide( const zypp::Url &url, const ProvideFileSpec &request );
118 AsyncOpRef<expected<ProvideRes>> provide( const MediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
119
123 AsyncOpRef<expected<std::string>> checksumForFile ( const zypp::Pathname &p, const std::string &algorithm );
124
128 AsyncOpRef<expected<zypp::ManagedFile>> copyFile ( const zypp::Pathname &source, const zypp::Pathname &target );
129
130 void start();
131 void setWorkerPath( const zypp::Pathname &path );
132 bool isRunning() const;
133 bool ejectDevice ( const std::string &queueRef, const std::string &device );
134
135 void setStatusTracker( ProvideStatusRef tracker );
136
137 const zypp::Pathname &providerWorkdir () const;
138
141
142 SignalProxy<void()> sigIdle();
143
144 enum Action {
145 ABORT, // abort and return error
146 RETRY, // retry
147 SKIP // abort and set skip request
148 };
149 using MediaChangeAction = std::optional<Action>;
150
157 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( );
158
163 SignalProxy< std::optional<zypp::media::AuthData> ( const zypp::Url &reqUrl, const std::string &triedUsername, const std::map<std::string, std::string> &extraValues ) > sigAuthRequired();
164
165 private:
166 Provide( const zypp::Pathname &workDir );
167 void releaseMedia( const std::string &mediaRef );
168 };
169
170}
171#endif
Store and operate with byte count.
Definition: ByteCount.h:31
Url manipulation class.
Definition: Url.h:92
std::string handle() const
Definition: provide.cc:951
std::shared_ptr< Provide > parent() const
Definition: provide.cc:941
std::shared_ptr< Data > _ref
Definition: provide.h:56
virtual void provideDone()
Definition: provide.h:83
virtual void requestDone(ProvideItem &item, uint32_t reqId, const AnyMap &extraData={})
Definition: provide.h:88
virtual void itemStart(ProvideItem &item)
Definition: provide.h:84
virtual void provideStart()
Definition: provide.cc:1174
const Stats & stats() const
Definition: provide.cc:1199
virtual void requestStart(ProvideItem &item, uint32_t reqId, const zypp::Url &url, const AnyMap &extraData={})
Definition: provide.h:87
virtual void pulse()
Definition: provide.cc:1204
ProvideWeakRef _provider
Definition: provide.h:97
virtual void requestFailed(ProvideItem &item, uint32_t reqId, const std::exception_ptr err, const AnyMap &requestData={})
Definition: provide.h:90
virtual void itemFailed(ProvideItem &item)
Definition: provide.cc:1194
virtual void requestRedirect(ProvideItem &item, uint32_t reqId, const zypp::Url &toUrl, const AnyMap &extraData={})
Definition: provide.h:89
virtual void itemDone(ProvideItem &item)
Definition: provide.cc:1181
virtual ~ProvideStatus()
Definition: provide.h:80
bool isRunning() const
AsyncOpRef< expected< ProvideRes > > provide(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request)
Definition: provide.cc:1038
const zypp::media::CredManagerOptions & credManangerOptions() const
Definition: provide.cc:1142
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:1163
static ProvideRef create(const zypp::Pathname &workDir="")
Definition: provide.cc:963
AsyncOpRef< expected< MediaHandle > > attachMedia(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request)
Definition: provide.cc:973
friend class ProvideMediaHandle
Definition: provide.h:105
void setWorkerPath(const zypp::Pathname &path)
Definition: provide.cc:1119
SignalProxy< void()> sigIdle()
Definition: provide.cc:1153
void setCredManagerOptions(const zypp::media::CredManagerOptions &opt)
Definition: provide.cc:1148
void setStatusTracker(ProvideStatusRef tracker)
Definition: provide.cc:1132
bool ejectDevice(const std::string &queueRef, const std::string &device)
Definition: provide.cc:1124
ZYPP_DECLARE_PRIVATE(Provide)
AsyncOpRef< expected< std::string > > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
Definition: provide.cc:1082
AsyncOpRef< expected< zypp::ManagedFile > > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
Definition: provide.cc:1097
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:1158
std::optional< Action > MediaChangeAction
Definition: provide.h:149
const zypp::Pathname & providerWorkdir() const
Definition: provide.cc:1137
void releaseMedia(const std::string &mediaRef)
Definition: provide.cc:1021
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
constexpr std::string_view Url("url")
std::unordered_map< std::string, boost::any > AnyMap
Definition: provide.h:41
zypp::ByteCount _partialBytes
Definition: provide.h:74
zypp::ByteCount _perSecondSinceLastPulse
Definition: provide.h:75
zypp::ByteCount _perSecond
Definition: provide.h:76
zypp::ByteCount _expectedBytes
Definition: provide.h:73
std::chrono::steady_clock::time_point _startTime
Definition: provide.h:68
zypp::ByteCount _finishedBytes
Definition: provide.h:72
std::chrono::steady_clock::time_point _lastPulseTime
Definition: provide.h:69