libzypp  11.13.5
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 
109  static
111  { return url.schemeIsDownloading(); }
112 
114  static
116  { return url.schemeIsVolatile(); }
117 
121  std::string protocol() const;
122 
126  Url url() const;
127 
134  void close();
135 
136  public:
137 
148  void attach(bool next = false);
149 
156  bool isAttached() const;
157 
158  bool hasMoreDevices() const;
159 
168  virtual void
169  getDetectedDevices(std::vector<std::string> & devices,
170  unsigned int & index) const;
171 
172 
181  Pathname localRoot() const;
182 
189  Pathname localPath( const Pathname & pathname ) const;
190 
204  void disconnect();
205 
213  void release( const std::string & ejectDev = "" );
214 
232  void provideFile( const Pathname & filename ) const;
233 
241  void releaseFile( const Pathname & filename ) const;
242 
252  void provideDir( const Pathname & dirname ) const;
253 
263  void provideDirTree( const Pathname & dirname ) const;
264 
272  void releaseDir( const Pathname & dirname ) const;
273 
285  void releasePath( const Pathname & pathname ) const;
286 
290  void setDeltafile( const Pathname & filename ) const;
291 
292  public:
293 
307  void dirInfo( std::list<std::string> & retlist,
308  const Pathname & dirname, bool dots = true ) const;
309 
322  void dirInfo( filesystem::DirContent & retlist,
323  const Pathname & dirname, bool dots = true ) const;
324 
333  bool doesFileExist( const Pathname & filename ) const;
334 
338  virtual ~MediaAccess();
339 
340  public:
341 
342  virtual std::ostream & dumpOn( std::ostream & str ) const;
343 
344  public:
355  void getFile( const Url &from, const Pathname &to );
356 
357  public:
358 
379  class FileProvider {
380  FileProvider( const FileProvider & ); // no copy
381  FileProvider & operator=( const FileProvider & ); // no assign
382  private:
384  Pathname _file;
385  Pathname _local_file;
386  public:
390  FileProvider( MediaAccess::constPtr media_r, const Pathname & file_r )
391  : _media( media_r )
392  , _file( file_r )
393  , _local_file( "" )
394  {
395  if ( _file.empty() ) {
397  } else if ( _media ) {
398  try {
399  _media->provideFile( _file );
400  _local_file = _media->localPath( _file );
401  }
402  catch (const MediaException & excpt_r)
403  {
404  ZYPP_CAUGHT(excpt_r);
405  _media = NULL;
406  ZYPP_RETHROW(excpt_r);
407  }
408  }
409  }
410 
412  if ( _media )
413  {
414  try {
415  _media->releaseFile( _file );
416  }
417  catch (const MediaException &excpt_r)
418  {
419  ZYPP_CAUGHT(excpt_r);
420  }
421  catch(...) {} // No exception from dtor!
422  }
423  }
424 
425  public:
426 
431  Pathname localFile() const { return _local_file; }
432 
437  Pathname operator()() const {
438  if ( _media )
439  return _media->localPath( _file );
440  return Pathname();
441  }
442  };
443  };
444 
445  std::ostream & operator<<( std::ostream & str, const MediaAccess & obj );
446 
448 
449  } // namespace media
450 } // namespace zypp
451 
452 #endif // ZYPP_MEDIA_MEDIAACCESS_H
453