libzypp  17.28.0
MediaManager.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_MEDIA_MEDIAMANAGER_H
13 #define ZYPP_MEDIA_MEDIAMANAGER_H
14 
15 #include <zypp/APIConfig.h>
16 #include <zypp/base/NonCopyable.h>
17 #include <zypp/base/PtrTypes.h>
18 #include <zypp/Pathname.h>
19 #include <zypp/PathInfo.h>
20 #include <zypp/Url.h>
21 #include <zypp/OnMediaLocation.h>
22 #include <zypp/media/MediaSource.h>
24 
25 #include <list>
26 
27 
28 namespace zypp::media
29 {
30  class MediaHandler;
31 
32  typedef unsigned int MediaNr;
33 
34 
36  // forward declaration
37  struct MountEntry;
38  class MediaManager_Impl;
39 
41  //
42  // CLASS NAME : MediaVerifierBase
43  //
47  class MediaVerifierBase //: private zypp::NonCopyable
48  {
49  public:
51  {}
52 
54  {}
55 
60  virtual std::string info() const;
61 
62  /*
63  ** Check if the specified attached media contains
64  ** the desired media (e.g. SLES10 CD1).
65  */
66  virtual bool isDesiredMedia(const MediaHandler &ref) const = 0;
67  };
68 
69 
71  //
72  // CLASS NAME : NoVerifier
73  //
78  {
79  public:
81  {}
82 
83  ~NoVerifier() override
84  {}
85 
89  std::string info() const override;
90 
91  /*
92  ** Don't check if the specified attached media contains
93  ** the desired media number. Always return true.
94  */
95  bool isDesiredMedia(const MediaHandler &ref) const override
96  { return true; }
97  };
98 
99 
101  //
102  // CLASS NAME : MediaVerifierRef
103  //
108 
109 
111  //
112  // CLASS NAME : MediaManager
113  //
454  {
455  public:
467  MediaManager();
468 
473  ~MediaManager();
474 
496  open(const Url &url, const Pathname & preferred_attach_point = "");
497 
502  void
503  close(MediaAccessId accessId);
504 
511  bool
512  isOpen(MediaAccessId accessId) const;
513 
523  std::string
524  protocol(MediaAccessId accessId) const;
525 
531  bool
532  downloads(MediaAccessId accessId) const;
533 
541  Url
542  url(MediaAccessId accessId) const;
543 
544  public:
553  void
554  addVerifier(MediaAccessId accessId,
555  const MediaVerifierRef &verifier);
556 
564  void
565  delVerifier(MediaAccessId accessId);
566 
567  public:
580  bool
581  setAttachPrefix(const Pathname &attach_prefix);
582 
592  void
593  attach(MediaAccessId accessId);
594 
606  void
607  release(MediaAccessId accessId, const std::string & ejectDev = "");
608 
612  void
613  releaseAll();
614 
629  void
630  disconnect(MediaAccessId accessId);
631 
639  bool
640  isAttached(MediaAccessId accessId) const;
641 
650  bool
651  isSharedMedia(MediaAccessId accessId) const;
652 
662  bool
663  isDesiredMedia(MediaAccessId accessId) const;
664 
675  bool
676  isDesiredMedia(MediaAccessId accessId,
677  const MediaVerifierRef &verifier) const;
678 
690  bool
691  isChangeable(MediaAccessId accessId);
692 
705  Pathname
706  localRoot(MediaAccessId accessId) const;
707 
720  Pathname
721  localPath(MediaAccessId accessId, const Pathname & pathname) const;
722 
723  public:
724 
729  ZYPP_DEPRECATED void
730  provideFile(MediaAccessId accessId,
731  const Pathname &filename,
732  const ByteCount &expectedFileSize) const;
733 
738  ZYPP_DEPRECATED void
739  provideFile(MediaAccessId accessId,
740  const Pathname &filename ) const;
741 
742 
760  void
761  provideFile(MediaAccessId accessId,
762  const OnMediaLocation &file ) const;
763 
767  void
768  provideDir(MediaAccessId accessId,
769  const Pathname &dirname) const;
770 
774  void
775  provideDirTree(MediaAccessId accessId,
776  const Pathname &dirname) const;
777 
781  void
782  releaseFile(MediaAccessId accessId,
783  const Pathname &filename) const;
784 
788  void
789  releaseDir(MediaAccessId accessId,
790  const Pathname &dirname) const;
791 
795  void
796  releasePath(MediaAccessId accessId,
797  const Pathname &pathname) const;
798 
802  void
803  dirInfo(MediaAccessId accessId,
804  std::list<std::string> &retlist,
805  const Pathname &dirname,
806  bool dots = true) const;
807 
811  void
812  dirInfo(MediaAccessId accessId,
813  filesystem::DirContent &retlist,
814  const Pathname &dirname,
815  bool dots = true) const;
816 
820  bool doesFileExist(MediaAccessId accessId,
821  const Pathname & filename ) const;
822 
832  void
834  std::vector<std::string> & devices,
835  unsigned int & index) const;
836 
837  ZYPP_DEPRECATED void
838  setDeltafile(MediaAccessId accessId,
839  const Pathname &filename ) const;
840 
852  void precacheFiles( MediaAccessId accessId,
853  const std::vector<OnMediaLocation> &files);
854 
855  public:
860  static time_t
862 
867  static std::vector<MountEntry>
868  getMountEntries();
869 
879  bool
880  isUseableAttachPoint(const Pathname &path,
881  bool mtab=true) const;
882 
883  private:
884  friend class MediaHandler;
885 
896  getAttachedMedia(MediaAccessId &accessId) const;
897 
908  findAttachedMedia(const MediaSourceRef &media) const;
909 
918  void
919  forceReleaseShared(const MediaSourceRef &media);
920 
921  private:
926  };
927 
929 } // namespace zypp::media
931 
932 #endif // ZYPP_MEDIA_MEDIAMANAGER_H
933 
934 /*
935 ** vim: set ts=2 sts=2 sw=2 ai et:
936 */
zypp::media::MediaManager::releaseFile
void releaseFile(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:778
zypp::media::MediaNr
unsigned int MediaNr
Definition: MediaManager.h:30
zypp::media::MediaManager::disconnect
void disconnect(MediaAccessId accessId)
Disconnect a remote media.
Definition: MediaManager.cc:585
zypp::media::NoVerifier::info
std::string info() const override
Returns the "zypp::media::NoVerifier" string.
Definition: MediaManager.cc:194
zypp::media::MediaManager_Impl
Definition: MediaManager.cc:202
zypp::media::MediaManager::isAttached
bool isAttached(MediaAccessId accessId) const
Check if media is attached or not.
Definition: MediaManager.cc:594
zypp::media::MediaManager::releaseAll
void releaseAll()
Release all attached media.
Definition: MediaManager.cc:549
zypp::media::MediaManager::m_impl
static zypp::RW_pointer< MediaManager_Impl > m_impl
Static reference to the implementation (singleton).
Definition: MediaManager.h:925
zypp::media::MediaVerifierRef
zypp::RW_pointer< MediaVerifierBase > MediaVerifierRef
A shared reference to the MediaVerifier implementation.
Definition: MediaManager.h:107
zypp::media
Definition: CredentialFileReader.cc:31
zypp::media::MediaManager::~MediaManager
~MediaManager()
Destroys MediaManager envelope instance.
Definition: MediaManager.cc:307
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition: OnMediaLocation.h:39
zypp::media::MediaHandler
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:51
ZYPP_DEPRECATED
#define ZYPP_DEPRECATED
The ZYPP_DEPRECATED macro can be used to trigger compile-time warnings with gcc >= 3....
Definition: Globals.h:99
zypp::media::MediaVerifierBase::info
virtual std::string info() const
Returns a string with some info about the verifier.
Definition: MediaManager.cc:186
zypp::media::MediaVerifierBase
Interface to implement a media verifier.
Definition: MediaManager.h:48
zypp::media::MediaManager::releaseDir
void releaseDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:790
zypp::media::MediaManager::attach
void attach(MediaAccessId accessId)
Attach the media using the concrete handler (checks all devices).
Definition: MediaManager.cc:437
zypp::media::NoVerifier::isDesiredMedia
bool isDesiredMedia(const MediaHandler &ref) const override
Definition: MediaManager.h:95
zypp::media::MediaManager::url
Url url(MediaAccessId accessId) const
Returns the Media Access Url of the media access id.
Definition: MediaManager.cc:391
zypp::media::MediaManager::delVerifier
void delVerifier(MediaAccessId accessId)
Remove verifier for specified media id.
Definition: MediaManager.cc:417
zypp::media::MediaManager::isUseableAttachPoint
bool isUseableAttachPoint(const Pathname &path, bool mtab=true) const
Check if the specified path is useable as attach point.
Definition: MediaManager.cc:883
zypp::media::MediaManager::setDeltafile
ZYPP_DEPRECATED void setDeltafile(MediaAccessId accessId, const Pathname &filename) const
Definition: MediaManager.cc:733
zypp::media::NoVerifier::NoVerifier
NoVerifier()
Definition: MediaManager.h:80
MediaSource.h
zypp::ByteCount
Store and operate with byte count.
Definition: ByteCount.h:31
zypp::media::MediaVerifierBase::~MediaVerifierBase
virtual ~MediaVerifierBase()
Definition: MediaManager.h:53
zypp::media::NoVerifier
Dummy default media verifier, which is always happy.
Definition: MediaManager.h:78
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
OnMediaLocation.h
zypp::media::MediaManager::MediaManager
MediaManager()
Creates a MediaManager envelope instance.
Definition: MediaManager.cc:298
zypp::media::MediaVerifierBase::MediaVerifierBase
MediaVerifierBase()
Definition: MediaManager.h:50
zypp::media::MediaManager::provideDirTree
void provideDirTree(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:766
zypp::RW_pointer
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:286
zypp::media::MediaManager::isOpen
bool isOpen(MediaAccessId accessId) const
Query if the media access is open / exists.
Definition: MediaManager.cc:365
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:454
zypp::media::AttachedMedia
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:134
zypp::media::MediaManager::localRoot
Pathname localRoot(MediaAccessId accessId) const
Return the local directory that corresponds to medias url, no matter if media isAttached or not.
Definition: MediaManager.cc:674
MediaException.h
zypp::media::MediaManager::open
MediaAccessId open(const Url &url, const Pathname &preferred_attach_point="")
Opens the media access for specified with the url.
Definition: MediaManager.cc:313
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:514
zypp::media::MediaManager::provideDir
void provideDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:754
zypp::media::MediaManager::setAttachPrefix
bool setAttachPrefix(const Pathname &attach_prefix)
Set or resets the directory name, where the media manager handlers create their temporary attach poin...
Definition: MediaManager.cc:431
zypp::media::MediaManager::localPath
Pathname localPath(MediaAccessId accessId, const Pathname &pathname) const
Shortcut for 'localRoot() + pathname', but returns an empty pathname if media is not attached.
Definition: MediaManager.cc:685
zypp::media::MediaManager::findAttachedMedia
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Definition: MediaManager.cc:961
zypp::media::MediaManager::getMountTableMTime
static time_t getMountTableMTime()
Get the modification time of the /etc/mtab file.
Definition: MediaManager.cc:868
zypp::media::MediaManager::downloads
bool downloads(MediaAccessId accessId) const
Hint if files are downloaded or not.
Definition: MediaManager.cc:382
zypp::media::MediaManager::close
void close(MediaAccessId accessId)
Close the media access with specified id.
Definition: MediaManager.cc:331
zypp::media::MediaManager::addVerifier
void addVerifier(MediaAccessId accessId, const MediaVerifierRef &verifier)
Add verifier implementation for the specified media id.
Definition: MediaManager.cc:400
zypp::media::MediaManager::getMountEntries
static std::vector< MountEntry > getMountEntries()
Get current mount entries from /etc/mtab file.
Definition: MediaManager.cc:876
zypp::media::MediaManager::isDesiredMedia
bool isDesiredMedia(MediaAccessId accessId) const
Ask the registered verifier if the attached media is the desired one or not.
Definition: MediaManager.cc:611
zypp::media::MediaManager::doesFileExist
bool doesFileExist(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:845
zypp::media::MediaVerifierBase::isDesiredMedia
virtual bool isDesiredMedia(const MediaHandler &ref) const =0
zypp::media::MediaManager::release
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
Definition: MediaManager.cc:506
zypp::media::MediaManager::precacheFiles
void precacheFiles(MediaAccessId accessId, const std::vector< OnMediaLocation > &files)
Tries to fetch the given files and precaches them.
Definition: MediaManager.cc:743
zypp::media::MediaManager::getAttachedMedia
AttachedMedia getAttachedMedia(MediaAccessId &accessId) const
Definition: MediaManager.cc:952
zypp::media::MountEntry
A "struct mntent" like mount entry structure, but using std::strings.
Definition: Mount.h:35
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::media::MediaManager::dirInfo
void dirInfo(MediaAccessId accessId, std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:815
zypp::media::NoVerifier::~NoVerifier
~NoVerifier() override
Definition: MediaManager.h:83
verifier
MediaVerifierRef verifier
Definition: MediaManager.cc:159
zypp::media::MediaManager::getDetectedDevices
void getDetectedDevices(MediaAccessId accessId, 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: MediaManager.cc:857
zypp::media::MediaManager::isSharedMedia
bool isSharedMedia(MediaAccessId accessId) const
Returns information if media is on a shared physical device or not.
Definition: MediaManager.cc:602
zypp::Url
Url manipulation class.
Definition: Url.h:92
zypp::media::MediaManager::provideFile
ZYPP_DEPRECATED void provideFile(MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const
Definition: MediaManager.cc:696
zypp::media::MediaManager::protocol
std::string protocol(MediaAccessId accessId) const
Query the protocol name used by the media access handler.
Definition: MediaManager.cc:373
zypp::media::MediaManager::isChangeable
bool isChangeable(MediaAccessId accessId)
Simple check, based on media's URL scheme, telling whether the it is possible to physically change th...
Definition: MediaManager.cc:667
zypp::media::MediaManager::forceReleaseShared
void forceReleaseShared(const MediaSourceRef &media)
Definition: MediaManager.cc:981
zypp::media::MediaManager::releasePath
void releasePath(MediaAccessId accessId, const Pathname &pathname) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:803