libzypp  17.32.4
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/ProvideFwd>
20 #include <zypp-media/ng/ProvideRes>
21 #include <zypp-media/auth/AuthData>
22 #include <boost/any.hpp>
23 
24 namespace zypp {
25  class Url;
26  namespace media {
27  struct CredManagerOptions;
28  }
29 }
30 
41 namespace 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;
63  zyppng::AttachedMediaInfo_constPtr mediaInfo() 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 
120  using Res = ProvideRes;
121 
122  static ProvideRef create( const zypp::Pathname &workDir = "" );
123 
124  AsyncOpRef<expected<MediaHandle>> attachMedia( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request );
125  AsyncOpRef<expected<MediaHandle>> attachMedia( const zypp::Url &url, const ProvideMediaSpec &request );
126 
127  AsyncOpRef<expected<ProvideRes>> provide( const std::vector<zypp::Url> &urls, const ProvideFileSpec &request );
128  AsyncOpRef<expected<ProvideRes>> provide( const zypp::Url &url, const ProvideFileSpec &request );
129  AsyncOpRef<expected<ProvideRes>> provide( const MediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
130 
131 
135  AsyncOpRef<expected<zypp::CheckSum>> checksumForFile ( const zypp::Pathname &p, const std::string &algorithm );
136 
140  AsyncOpRef<expected<zypp::ManagedFile>> copyFile ( const zypp::Pathname &source, const zypp::Pathname &target );
141  AsyncOpRef<expected<zypp::ManagedFile>> copyFile ( ProvideRes &&source, const zypp::Pathname &target );
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 
155  SignalProxy<void()> sigIdle();
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:
188  Provide( const zypp::Pathname &workDir );
189  };
190 
191 }
192 #endif
int assert_dir(const Pathname &path, unsigned mode)
Like &#39;mkdir -p&#39;.
Definition: PathInfo.cc:320
SignalProxy< void()> sigIdle()
Definition: provide.cc:1160
const zypp::Pathname & providerWorkdir() const
Definition: provide.cc:1144
constexpr std::string_view Url("url")
zypp::ByteCount _finishedBytes
Definition: provide.h:82
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
virtual void pulse()
Definition: provide.cc:1211
ProvideStatus(ProvideRef parent)
Definition: provide.cc:1177
virtual void requestDone(ProvideItem &item, uint32_t reqId, const AnyMap &extraData={})
Definition: provide.h:98
Store and operate with byte count.
Definition: ByteCount.h:30
A ProvideRes object is a reference counted ownership of a resource in the cache provided by a Provide...
Definition: provideres.h:35
virtual void itemStart(ProvideItem &item)
Definition: provide.h:94
AsyncOpRef< expected< zypp::CheckSum > > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
Definition: provide.cc:1071
ZYPP_DECLARE_PRIVATE(Provide)
AttachedMediaInfo_Ptr _mediaRef
Definition: provide.h:66
virtual void itemFailed(ProvideItem &item)
Definition: provide.cc:1201
virtual void requestFailed(ProvideItem &item, uint32_t reqId, const std::exception_ptr &err, const AnyMap &requestData={})
Definition: provide.h:100
DEFINE_PTR_TYPE(AttachedSyncMediaInfo)
virtual void provideDone()
Definition: provide.h:93
virtual ~ProvideStatus()
Definition: provide.h:90
static ProvideRef create(const zypp::Pathname &workDir="")
Definition: provide.cc:972
zypp::ByteCount _perSecond
Definition: provide.h:86
std::chrono::steady_clock::time_point _lastPulseTime
Definition: provide.h:79
zyppng::AttachedMediaInfo_constPtr mediaInfo() const
Definition: provide.cc:960
const std::optional< zypp::Pathname > & localPath() const
Definition: provide.cc:952
void setCredManagerOptions(const zypp::media::CredManagerOptions &opt)
Definition: provide.cc:1155
bool isRunning() const
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:1165
virtual void requestRedirect(ProvideItem &item, uint32_t reqId, const zypp::Url &toUrl, const AnyMap &extraData={})
Definition: provide.h:99
zypp::ByteCount _expectedBytes
Definition: provide.h:83
virtual void itemDone(ProvideItem &item)
Definition: provide.cc:1188
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:124
bool ejectDevice(const std::string &queueRef, const std::string &device)
Definition: provide.cc:1131
void setWorkerPath(const zypp::Pathname &path)
Definition: provide.cc:1126
ProvideWeakRef _provider
Definition: provide.h:107
std::optional< Action > MediaChangeAction
Definition: provide.h:162
friend class ProvideMediaHandle
Definition: provide.h:115
virtual void provideStart()
Definition: provide.cc:1181
zypp::ByteCount _partialBytes
Definition: provide.h:84
Provide(const zypp::Pathname &workDir)
Definition: provide.cc:966
AsyncOpRef< expected< MediaHandle > > attachMedia(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request)
Definition: provide.cc:982
const zypp::Url & baseUrl() const
Definition: provide.cc:944
zypp::ByteCount _perSecondSinceLastPulse
Definition: provide.h:85
ProvideWeakRef _parent
Definition: provide.h:65
void setStatusTracker(ProvideStatusRef tracker)
Definition: provide.cc:1139
std::chrono::steady_clock::time_point _startTime
Definition: provide.h:78
const Stats & stats() const
Definition: provide.cc:1206
AsyncOpRef< expected< zypp::ManagedFile > > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
Definition: provide.cc:1091
constexpr std::string_view device("device")
std::string handle() const
Definition: provide.cc:937
std::unordered_map< std::string, boost::any > AnyMap
Definition: provide.h:44
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
std::shared_ptr< Provide > parent() const
Definition: provide.cc:927
static auto copyResultToDest(ProvideRef provider, const zypp::Pathname &targetPath)
Definition: provide.h:179
Url manipulation class.
Definition: Url.h:91
virtual void requestStart(ProvideItem &item, uint32_t reqId, const zypp::Url &url, const AnyMap &extraData={})
Definition: provide.h:97
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:1170