libzypp  17.14.0
MediaAccess.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_MEDIA_MEDIAACCESS_H
13 #define ZYPP_MEDIA_MEDIAACCESS_H
14 
15 #include <iosfwd>
16 #include <map>
17 #include <list>
18 #include <string>
19 
21 #include "zypp/base/NonCopyable.h"
22 #include "zypp/base/PtrTypes.h"
23 #include "zypp/APIConfig.h"
24 
25 #include "zypp/Pathname.h"
26 #include "zypp/PathInfo.h"
27 
29 #include "zypp/media/MediaSource.h"
30 
31 #include "zypp/Url.h"
32 
33 namespace zypp {
34  namespace media {
35 
36  class MediaHandler;
37 
39  //
40  // CLASS NAME : MediaAccess
51  {
52  public:
53  typedef intrusive_ptr<MediaAccess> Ptr;
54  typedef intrusive_ptr<const MediaAccess> constPtr;
55 
56  private:
57 
58  static const Pathname _noPath;
59 
65 
66  friend class MediaManager;
67  friend class MediaManager_Impl;
68 
70 
71  bool isSharedMedia() const;
72 
73  void resetParentId();
74  bool dependsOnParent() const;
75 
76  bool dependsOnParent(MediaAccessId parentId,
77  bool exactIdMatch) const;
78  public:
79 
83  MediaAccess();
84 
95  void open( const Url& url, const Pathname & preferred_attach_point = "" );
96 
100  bool isOpen() const { return( _handler != 0 ); }
101 
106  bool downloads() const;
107 
111  std::string protocol() const;
112 
116  Url url() const;
117 
124  void close();
125 
126  public:
127 
138  void attach(bool next = false);
139 
146  bool isAttached() const;
147 
148  bool hasMoreDevices() const;
149 
158  virtual void
159  getDetectedDevices(std::vector<std::string> & devices,
160  unsigned int & index) const;
161 
162 
171  Pathname localRoot() const;
172 
179  Pathname localPath( const Pathname & pathname ) const;
180 
194  void disconnect();
195 
203  void release( const std::string & ejectDev = "" );
204 
222  void provideFile( const Pathname & filename, const ByteCount &expectedFileSize ) const;
223 
231  void releaseFile( const Pathname & filename ) const;
232 
242  void provideDir( const Pathname & dirname ) const;
243 
253  void provideDirTree( const Pathname & dirname ) const;
254 
262  void releaseDir( const Pathname & dirname ) const;
263 
275  void releasePath( const Pathname & pathname ) const;
276 
280  void setDeltafile( const Pathname & filename ) const;
281 
282  public:
283 
297  void dirInfo( std::list<std::string> & retlist,
298  const Pathname & dirname, bool dots = true ) const;
299 
312  void dirInfo( filesystem::DirContent & retlist,
313  const Pathname & dirname, bool dots = true ) const;
314 
323  bool doesFileExist( const Pathname & filename ) const;
324 
328  virtual ~MediaAccess();
329 
330  public:
331 
332  virtual std::ostream & dumpOn( std::ostream & str ) const;
333 
334  public:
345  void getFile( const Url &from, const Pathname &to );
346 
347  public:
348 
369  class FileProvider {
370  FileProvider( const FileProvider & ); // no copy
371  FileProvider & operator=( const FileProvider & ); // no assign
372  private:
374  Pathname _file;
375  Pathname _local_file;
376  public:
380  FileProvider( MediaAccess::constPtr media_r, const Pathname & file_r )
381  : _media( media_r )
382  , _file( file_r )
383  , _local_file( "" )
384  {
385  if ( _file.empty() ) {
387  } else if ( _media ) {
388  try {
389  _media->provideFile( _file, 0 );
390  _local_file = _media->localPath( _file );
391  }
392  catch (const MediaException & excpt_r)
393  {
394  ZYPP_CAUGHT(excpt_r);
395  _media = NULL;
396  ZYPP_RETHROW(excpt_r);
397  }
398  }
399  }
400 
402  if ( _media )
403  {
404  try {
405  _media->releaseFile( _file );
406  }
407  catch (const MediaException &excpt_r)
408  {
409  ZYPP_CAUGHT(excpt_r);
410  }
411  catch(...) {} // No exception from dtor!
412  }
413  }
414 
415  public:
416 
421  Pathname localFile() const { return _local_file; }
422 
427  Pathname operator()() const {
428  if ( _media )
429  return _media->localPath( _file );
430  return Pathname();
431  }
432  };
433  };
434 
435  std::ostream & operator<<( std::ostream & str, const MediaAccess & obj );
436 
438 
439  } // namespace media
440 } // namespace zypp
441 
442 #endif // ZYPP_MEDIA_MEDIAACCESS_H
443