libzypp  17.23.6
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:
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 
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 
zypp::media::MediaAccess::getFile
void getFile(const Url &from, const Pathname &to)
Get file from location at specified by URL and copy it to destination.
Definition: MediaAccess.cc:456
zypp::media::MediaAccess::MediaAccess
MediaAccess()
constructor
Definition: MediaAccess.cc:53
zypp::media::MediaAccess::setDeltafile
void setDeltafile(const Pathname &filename) const
set a deltafile to be used in the next download
Definition: MediaAccess.cc:349
zypp::media::MediaAccess::Ptr
intrusive_ptr< MediaAccess > Ptr
Definition: MediaAccess.h:53
PathInfo.h
zypp::media::MediaException
Just inherits Exception to separate media exceptions.
Definition: MediaException.h:35
zypp::media::MediaManager_Impl
Definition: MediaManager.cc:133
zypp::media::MediaAccess::dependsOnParent
bool dependsOnParent() const
Definition: MediaAccess.cc:89
zypp::media::MediaAccess::provideDir
void provideDir(const Pathname &dirname) const
Use concrete handler to provide directory denoted by path below 'attach point' (not recursive!...
Definition: MediaAccess.cc:372
zypp::media::MediaAccess
Handle access to a medium.
Definition: MediaAccess.h:50
zypp::media::MediaAccess::isSharedMedia
bool isSharedMedia() const
Definition: MediaAccess.cc:76
zypp::media::MediaAccess::open
void open(const Url &url, const Pathname &preferred_attach_point="")
open url.
Definition: MediaAccess.cc:104
zypp::base::ReferenceCounted
Base class for reference counted objects.
Definition: ReferenceCounted.h:33
zypp::media::MediaAccess::FileProvider::_local_file
Pathname _local_file
Definition: MediaAccess.h:375
zypp::media::MediaAccess::FileProvider::_media
MediaAccess::constPtr _media
Definition: MediaAccess.h:373
zypp::media::MediaHandler
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
zypp::media::MediaAccess::disconnect
void disconnect()
Use concrete handler to disconnect the media.
Definition: MediaAccess.cc:316
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
zypp::media::MediaAccess::localPath
Pathname localPath(const Pathname &pathname) const
Short for 'localRoot() + pathname', but returns an empty pathname if media is not open.
Definition: MediaAccess.cc:307
zypp::media::MediaAccess::FileProvider::localFile
Pathname localFile() const
If no error, expect operator() to return the local Pathname of the provided file.
Definition: MediaAccess.h:421
zypp::media::MediaAccess::url
Url url() const
Url if media is opened, otherwise empty.
Definition: MediaAccess.cc:221
zypp::media::MediaAccess::downloads
bool downloads() const
Hint if files are downloaded or not.
Definition: MediaAccess.cc:210
PtrTypes.h
zypp::media::MediaAccess::attach
void attach(bool next=false)
Use concrete handler to attach the media.
Definition: MediaAccess.cc:255
zypp::media::MediaAccess::_handler
MediaHandler * _handler
handler for 'physical' media == 0 if not open
Definition: MediaAccess.h:64
zypp::media::MediaAccess::close
void close()
close url
Definition: MediaAccess.cc:231
Pathname.h
zypp::media::MediaBadFilenameException
Definition: MediaException.h:116
MediaSource.h
zypp::ByteCount
Store and operate with byte count.
Definition: ByteCount.h:30
zypp::media::MediaAccess::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
Definition: MediaAccess.cc:447
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
zypp::media::MediaAccess::_noPath
static const Pathname _noPath
Definition: MediaAccess.h:58
zypp::media::operator<<
std::ostream & operator<<(std::ostream &str, const MediaAccess &obj)
Definition: MediaAccess.cc:481
zypp::media::MediaAccess::~MediaAccess
virtual ~MediaAccess()
Destructor.
Definition: MediaAccess.cc:59
Url.h
zypp::media::MediaAccess::hasMoreDevices
bool hasMoreDevices() const
Definition: MediaAccess.cc:271
zypp::media::MediaAccess::FileProvider::operator()
Pathname operator()() const
Return the local Pathname of the provided file or an empty Pathname on error.
Definition: MediaAccess.h:427
zypp::media::MediaAccess::FileProvider::~FileProvider
~FileProvider()
Definition: MediaAccess.h:401
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
zypp::media::MediaManager
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees,...
Definition: MediaManager.h:470
zypp::media::AttachedMedia
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:133
MediaException.h
zypp::media::MediaAccess::isAttached
bool isAttached() const
True if media is attached.
Definition: MediaAccess.cc:265
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
zypp::media::MediaAccess::releaseFile
void releaseFile(const Pathname &filename) const
Remove filename below attach point IFF handler downloads files to the local filesystem.
Definition: MediaAccess.cc:359
zypp::media::MediaAccess::releasePath
void releasePath(const Pathname &pathname) const
Remove pathname below attach point IFF handler downloads files to the local filesystem.
Definition: MediaAccess.cc:401
zypp::media::MediaAccess::provideFile
void provideFile(const Pathname &filename, const ByteCount &expectedFileSize) const
Use concrete handler to provide file denoted by path below 'attach point'.
Definition: MediaAccess.cc:339
zypp::media::MediaAccess::isOpen
bool isOpen() const
True if media is open.
Definition: MediaAccess.h:100
ZYPP_RETHROW
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:400
ReferenceCounted.h
zypp::media::MediaAccess::FileProvider
Helper class that provides file on construction and cleans up on destruction.
Definition: MediaAccess.h:369
zypp::media::MediaAccess::FileProvider::FileProvider
FileProvider(const FileProvider &)
zypp::media::MediaAccess::FileProvider::_file
Pathname _file
Definition: MediaAccess.h:374
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:44
zypp::media::MediaAccess::releaseDir
void releaseDir(const Pathname &dirname) const
Remove directory tree below attach point IFF handler downloads files to the local filesystem.
Definition: MediaAccess.cc:392
zypp::media::MediaAccess::attachedMedia
AttachedMedia attachedMedia() const
Definition: MediaAccess.cc:69
zypp::media::MediaAccess::FileProvider::operator=
FileProvider & operator=(const FileProvider &)
zypp::media::MediaAccess::getDetectedDevices
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:278
str
String related utilities and Regular expression matching.
zypp::media::MediaAccess::protocol
std::string protocol() const
Used Protocol if media is opened, otherwise 'unknown'.
Definition: MediaAccess.cc:201
zypp::media::MediaAccess::dirInfo
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:411
zypp::media::MediaAccess::constPtr
intrusive_ptr< const MediaAccess > constPtr
Definition: MediaAccess.h:54
zypp::media::MediaAccess::doesFileExist
bool doesFileExist(const Pathname &filename) const
check if a file exists
Definition: MediaAccess.cc:437
ZYPP_CAUGHT
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:396
zypp::filesystem::Pathname::asString
const std::string & asString() const
String representation.
Definition: Pathname.h:91
zypp::media::MediaAccess::localRoot
Pathname localRoot() const
Return the local directory that corresponds to medias url, no matter if media isAttached or not.
Definition: MediaAccess.cc:296
zypp::Url
Url manipulation class.
Definition: Url.h:87
zypp::media::MediaAccess::provideDirTree
void provideDirTree(const Pathname &dirname) const
Use concrete handler to provide directory tree denoted by path below 'attach point' (recursive!...
Definition: MediaAccess.cc:382
zypp::media::MediaAccess::resetParentId
void resetParentId()
Definition: MediaAccess.cc:83
zypp::media::MediaAccess::release
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
Definition: MediaAccess.cc:326
zypp::media::MediaAccess::FileProvider::FileProvider
FileProvider(MediaAccess::constPtr media_r, const Pathname &file_r)
Definition: MediaAccess.h:380
NonCopyable.h