libzypp  17.25.2
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 #include <zypp/OnMediaLocation.h>
31 
32 #include <zypp/Url.h>
33 
34 namespace zypp {
35  namespace media {
36 
37  class MediaHandler;
38 
40  //
41  // CLASS NAME : MediaAccess
52  {
53  public:
54  typedef intrusive_ptr<MediaAccess> Ptr;
55  typedef intrusive_ptr<const MediaAccess> constPtr;
56 
57  private:
58 
59  static const Pathname _noPath;
60 
66 
67  friend class MediaManager;
68  friend class MediaManager_Impl;
69 
71 
72  bool isSharedMedia() const;
73 
74  void resetParentId();
75  bool dependsOnParent() const;
76 
77  bool dependsOnParent(MediaAccessId parentId,
78  bool exactIdMatch) const;
79  public:
80 
84  MediaAccess();
85 
96  void open( const Url& url, const Pathname & preferred_attach_point = "" );
97 
101  bool isOpen() const { return( _handler != 0 ); }
102 
107  bool downloads() const;
108 
112  std::string protocol() const;
113 
117  Url url() const;
118 
125  void close();
126 
127  public:
128 
139  void attach(bool next = false);
140 
147  bool isAttached() const;
148 
149  bool hasMoreDevices() const;
150 
159  virtual void
160  getDetectedDevices(std::vector<std::string> & devices,
161  unsigned int & index) const;
162 
163 
172  Pathname localRoot() const;
173 
180  Pathname localPath( const Pathname & pathname ) const;
181 
195  void disconnect();
196 
204  void release( const std::string & ejectDev = "" );
205 
223  void provideFile( const Pathname & filename, const ByteCount &expectedFileSize ) const;
224 
232  void releaseFile( const Pathname & filename ) const;
233 
243  void provideDir( const Pathname & dirname ) const;
244 
254  void provideDirTree( const Pathname & dirname ) const;
255 
263  void releaseDir( const Pathname & dirname ) const;
264 
276  void releasePath( const Pathname & pathname ) const;
277 
281  void setDeltafile( const Pathname & filename ) const;
282 
283  public:
284 
298  void dirInfo( std::list<std::string> & retlist,
299  const Pathname & dirname, bool dots = true ) const;
300 
313  void dirInfo( filesystem::DirContent & retlist,
314  const Pathname & dirname, bool dots = true ) const;
315 
324  bool doesFileExist( const Pathname & filename ) const;
325 
326  void precacheFiles(const std::vector<OnMediaLocation> &files);
327 
331  virtual ~MediaAccess();
332 
333  public:
334 
335  virtual std::ostream & dumpOn( std::ostream & str ) const;
336 
337  public:
348  void getFile( const Url &from, const Pathname &to );
349 
350  public:
351 
372  class FileProvider {
373  FileProvider( const FileProvider & ); // no copy
374  FileProvider & operator=( const FileProvider & ); // no assign
375  private:
379  public:
383  FileProvider( MediaAccess::constPtr media_r, const Pathname & file_r )
384  : _media( media_r )
385  , _file( file_r )
386  , _local_file( "" )
387  {
388  if ( _file.empty() ) {
390  } else if ( _media ) {
391  try {
392  _media->provideFile( _file, 0 );
393  _local_file = _media->localPath( _file );
394  }
395  catch (const MediaException & excpt_r)
396  {
397  ZYPP_CAUGHT(excpt_r);
398  _media = NULL;
399  ZYPP_RETHROW(excpt_r);
400  }
401  }
402  }
403 
405  if ( _media )
406  {
407  try {
408  _media->releaseFile( _file );
409  }
410  catch (const MediaException &excpt_r)
411  {
412  ZYPP_CAUGHT(excpt_r);
413  }
414  catch(...) {} // No exception from dtor!
415  }
416  }
417 
418  public:
419 
424  Pathname localFile() const { return _local_file; }
425 
431  if ( _media )
432  return _media->localPath( _file );
433  return Pathname();
434  }
435  };
436  };
437 
438  std::ostream & operator<<( std::ostream & str, const MediaAccess & obj );
439 
441 
442  } // namespace media
443 } // namespace zypp
444 
445 #endif // ZYPP_MEDIA_MEDIAACCESS_H
446 
MediaAccess()
constructor
Definition: MediaAccess.cc:54
void open(const Url &url, const Pathname &preferred_attach_point="")
open url.
Definition: MediaAccess.cc:105
void close()
close url
Definition: MediaAccess.cc:251
Pathname localRoot() const
Return the local directory that corresponds to medias url, no matter if media isAttached or not...
Definition: MediaAccess.cc:316
void provideDirTree(const Pathname &dirname) const
Use concrete handler to provide directory tree denoted by path below &#39;attach point&#39; (recursive!!)...
Definition: MediaAccess.cc:402
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
Handle access to a medium.
Definition: MediaAccess.h:51
void setDeltafile(const Pathname &filename) const
set a deltafile to be used in the next download
Definition: MediaAccess.cc:369
std::string protocol() const
Used Protocol if media is opened, otherwise &#39;unknown&#39;.
Definition: MediaAccess.cc:221
Store and operate with byte count.
Definition: ByteCount.h:30
FileProvider(MediaAccess::constPtr media_r, const Pathname &file_r)
Definition: MediaAccess.h:383
void disconnect()
Use concrete handler to disconnect the media.
Definition: MediaAccess.cc:336
Pathname localPath(const Pathname &pathname) const
Short for &#39;localRoot() + pathname&#39;, but returns an empty pathname if media is not open...
Definition: MediaAccess.cc:327
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
Definition: MediaAccess.cc:346
bool isSharedMedia() const
Definition: MediaAccess.cc:77
Url url() const
Url if media is opened, otherwise empty.
Definition: MediaAccess.cc:241
String related utilities and Regular expression matching.
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
void provideFile(const Pathname &filename, const ByteCount &expectedFileSize) const
Use concrete handler to provide file denoted by path below &#39;attach point&#39;.
Definition: MediaAccess.cc:359
std::ostream & operator<<(std::ostream &str, const MediaAccess &obj)
Definition: MediaAccess.cc:510
MediaHandler * _handler
handler for &#39;physical&#39; media == 0 if not open
Definition: MediaAccess.h:65
bool hasMoreDevices() const
Definition: MediaAccess.cc:291
void provideDir(const Pathname &dirname) const
Use concrete handler to provide directory denoted by path below &#39;attach point&#39; (not recursive!)...
Definition: MediaAccess.cc:392
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
Definition: MediaAccess.cc:476
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:400
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Abstract base class for &#39;physical&#39; MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:46
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:133
virtual ~MediaAccess()
Destructor.
Definition: MediaAccess.cc:60
const std::string & asString() const
String representation.
Definition: Pathname.h:91
Just inherits Exception to separate media exceptions.
FileProvider & operator=(const FileProvider &)
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
bool downloads() const
Hint if files are downloaded or not.
Definition: MediaAccess.cc:230
void releaseDir(const Pathname &dirname) const
Remove directory tree below attach point IFF handler downloads files to the local filesystem...
Definition: MediaAccess.cc:412
void attach(bool next=false)
Use concrete handler to attach the media.
Definition: MediaAccess.cc:275
static const Pathname _noPath
Definition: MediaAccess.h:59
Base class for reference counted objects.
void releaseFile(const Pathname &filename) const
Remove filename below attach point IFF handler downloads files to the local filesystem.
Definition: MediaAccess.cc:379
bool doesFileExist(const Pathname &filename) const
check if a file exists
Definition: MediaAccess.cc:457
Helper class that provides file on construction and cleans up on destruction.
Definition: MediaAccess.h:372
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:396
Pathname operator()() const
Return the local Pathname of the provided file or an empty Pathname on error.
Definition: MediaAccess.h:430
Manages access to the &#39;physical&#39; media, e.g CDROM drives, Disk volumes, directory trees...
Definition: MediaManager.h:471
intrusive_ptr< const MediaAccess > constPtr
Definition: MediaAccess.h:55
Pathname localFile() const
If no error, expect operator() to return the local Pathname of the provided file. ...
Definition: MediaAccess.h:424
bool isAttached() const
True if media is attached.
Definition: MediaAccess.cc:285
void precacheFiles(const std::vector< OnMediaLocation > &files)
Definition: MediaAccess.cc:466
intrusive_ptr< MediaAccess > Ptr
Definition: MediaAccess.h:54
void releasePath(const Pathname &pathname) const
Remove pathname below attach point IFF handler downloads files to the local filesystem.
Definition: MediaAccess.cc:421
AttachedMedia attachedMedia() const
Definition: MediaAccess.cc:70
virtual void getDetectedDevices(std::vector< std::string > &devices, unsigned int &index) const
Fill in a vector of detected ejectable devices and the index of the currently attached device within ...
Definition: MediaAccess.cc:298
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool dependsOnParent() const
Definition: MediaAccess.cc:90
void dirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Return content of directory on media via retlist.
Definition: MediaAccess.cc:431
Url manipulation class.
Definition: Url.h:87
bool isOpen() const
True if media is open.
Definition: MediaAccess.h:101
void getFile(const Url &from, const Pathname &to)
Get file from location at specified by URL and copy it to destination.
Definition: MediaAccess.cc:485