libzypp  17.25.8
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/media/MediaAccess.h>
16 
17 #include <zypp/APIConfig.h>
18 #include <zypp/base/NonCopyable.h>
19 #include <zypp/base/PtrTypes.h>
20 #include <zypp/Pathname.h>
21 #include <zypp/Url.h>
22 
23 #include <list>
24 
25 
27 namespace zypp
28 {
29 
31  namespace media
32  {
33 
34 
37 
38  // OBSOLETE HERE:
40  typedef unsigned int MediaNr;
41 
42 
44  // forward declaration
45  struct MountEntry;
46  class MediaManager_Impl;
47 
49  //
50  // CLASS NAME : MediaVerifierBase
51  //
55  class MediaVerifierBase //: private zypp::NonCopyable
56  {
57  public:
59  {}
60 
62  {}
63 
68  virtual std::string info() const;
69 
70  /*
71  ** Check if the specified attached media contains
72  ** the desired media (e.g. SLES10 CD1).
73  */
74  virtual bool isDesiredMedia(const MediaAccessRef &ref) const = 0;
75  };
76 
77 
79  //
80  // CLASS NAME : NoVerifier
81  //
86  {
87  public:
89  {}
90 
91  ~NoVerifier() override
92  {}
93 
97  std::string info() const override;
98 
99  /*
100  ** Don't check if the specified attached media contains
101  ** the desired media number. Always return true.
102  */
103  bool isDesiredMedia(const MediaAccessRef &) const override
104  { return true; }
105  };
106 
107 
109  //
110  // CLASS NAME : MediaVerifierRef
111  //
116 
117 
119  //
120  // CLASS NAME : MediaManager
121  //
462  {
463  public:
475  MediaManager();
476 
481  ~MediaManager();
482 
504  open(const Url &url, const Pathname & preferred_attach_point = "");
505 
510  void
511  close(MediaAccessId accessId);
512 
519  bool
520  isOpen(MediaAccessId accessId) const;
521 
531  std::string
532  protocol(MediaAccessId accessId) const;
533 
539  bool
540  downloads(MediaAccessId accessId) const;
541 
549  Url
550  url(MediaAccessId accessId) const;
551 
552  public:
561  void
562  addVerifier(MediaAccessId accessId,
563  const MediaVerifierRef &verifier);
564 
572  void
573  delVerifier(MediaAccessId accessId);
574 
575  public:
588  bool
589  setAttachPrefix(const Pathname &attach_prefix);
590 
600  void
601  attach(MediaAccessId accessId);
602 
614  void
615  release(MediaAccessId accessId, const std::string & ejectDev = "");
616 
620  void
621  releaseAll();
622 
637  void
638  disconnect(MediaAccessId accessId);
639 
647  bool
648  isAttached(MediaAccessId accessId) const;
649 
658  bool
659  isSharedMedia(MediaAccessId accessId) const;
660 
670  bool
671  isDesiredMedia(MediaAccessId accessId) const;
672 
683  bool
684  isDesiredMedia(MediaAccessId accessId,
685  const MediaVerifierRef &verifier) const;
686 
698  bool
699  isChangeable(MediaAccessId accessId);
700 
713  Pathname
714  localRoot(MediaAccessId accessId) const;
715 
728  Pathname
729  localPath(MediaAccessId accessId, const Pathname & pathname) const;
730 
731  public:
751  void
752  provideFile(MediaAccessId accessId,
753  const Pathname &filename,
754  const ByteCount &expectedFileSize) const;
755 
756  void
757  provideFile(MediaAccessId accessId,
758  const Pathname &filename ) const;
759 
763  void
764  provideDir(MediaAccessId accessId,
765  const Pathname &dirname) const;
766 
770  void
771  provideDirTree(MediaAccessId accessId,
772  const Pathname &dirname) const;
773 
777  void
778  releaseFile(MediaAccessId accessId,
779  const Pathname &filename) const;
780 
784  void
785  releaseDir(MediaAccessId accessId,
786  const Pathname &dirname) const;
787 
791  void
792  releasePath(MediaAccessId accessId,
793  const Pathname &pathname) const;
794 
798  void
799  dirInfo(MediaAccessId accessId,
800  std::list<std::string> &retlist,
801  const Pathname &dirname,
802  bool dots = true) const;
803 
807  void
808  dirInfo(MediaAccessId accessId,
809  filesystem::DirContent &retlist,
810  const Pathname &dirname,
811  bool dots = true) const;
812 
816  bool doesFileExist(MediaAccessId accessId,
817  const Pathname & filename ) const;
818 
828  void
830  std::vector<std::string> & devices,
831  unsigned int & index) const;
832 
833  void
834  setDeltafile(MediaAccessId accessId,
835  const Pathname &filename ) const;
836 
837  public:
842  static time_t
844 
849  static std::vector<MountEntry>
850  getMountEntries();
851 
861  bool
862  isUseableAttachPoint(const Pathname &path,
863  bool mtab=true) const;
864 
865  private:
866  friend class MediaHandler;
867 
878  getAttachedMedia(MediaAccessId &accessId) const;
879 
890  findAttachedMedia(const MediaSourceRef &media) const;
891 
900  void
901  forceReleaseShared(const MediaSourceRef &media);
902 
903  private:
908  };
909 
910 
912  } // namespace media
914 
916 } // namespace zypp
918 
919 #endif // ZYPP_MEDIA_MEDIAMANAGER_H
920 
921 /*
922 ** vim: set ts=2 sts=2 sw=2 ai et:
923 */
zypp::media::MediaManager::releaseFile
void releaseFile(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:685
zypp::media::MediaNr
unsigned int MediaNr
Definition: MediaManager.h:40
zypp::media::MediaManager::disconnect
void disconnect(MediaAccessId accessId)
Disconnect a remote media.
Definition: MediaManager.cc:517
zypp::media::NoVerifier::info
std::string info() const override
Returns the "zypp::media::NoVerifier" string.
Definition: MediaManager.cc:126
zypp::media::MediaManager_Impl
Definition: MediaManager.cc:134
zypp::media::MediaManager::isAttached
bool isAttached(MediaAccessId accessId) const
Check if media is attached or not.
Definition: MediaManager.cc:526
zypp::media::MediaManager::releaseAll
void releaseAll()
Release all attached media.
Definition: MediaManager.cc:482
zypp::media::MediaManager::m_impl
static zypp::RW_pointer< MediaManager_Impl > m_impl
Static reference to the implementation (singleton).
Definition: MediaManager.h:907
zypp::media::MediaVerifierRef
zypp::RW_pointer< MediaVerifierBase > MediaVerifierRef
A shared reference to the MediaVerifier implementation.
Definition: MediaManager.h:115
zypp::media::MediaId
MediaAccessId MediaId
Definition: MediaManager.h:39
zypp::media::MediaManager::~MediaManager
~MediaManager()
Destroys MediaManager envelope instance.
Definition: MediaManager.cc:239
zypp::media::MediaHandler
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
zypp::media::MediaVerifierBase::isDesiredMedia
virtual bool isDesiredMedia(const MediaAccessRef &ref) const =0
zypp::media::MediaVerifierBase::info
virtual std::string info() const
Returns a string with some info about the verifier.
Definition: MediaManager.cc:118
PtrTypes.h
zypp::media::MediaVerifierBase
Interface to implement a media verifier.
Definition: MediaManager.h:56
zypp::media::MediaManager::releaseDir
void releaseDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:697
zypp::media::MediaManager::attach
void attach(MediaAccessId accessId)
Attach the media using the concrete handler (checks all devices).
Definition: MediaManager.cc:372
Pathname.h
zypp::media::MediaManager::url
Url url(MediaAccessId accessId) const
Returns the Media Access Url of the media access id.
Definition: MediaManager.cc:326
zypp::media::MediaManager::delVerifier
void delVerifier(MediaAccessId accessId)
Remove verifier for specified media id.
Definition: MediaManager.cc:352
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:790
zypp::media::MediaManager::setDeltafile
void setDeltafile(MediaAccessId accessId, const Pathname &filename) const
Definition: MediaManager.cc:649
zypp::media::NoVerifier::NoVerifier
NoVerifier()
Definition: MediaManager.h:88
zypp::ByteCount
Store and operate with byte count.
Definition: ByteCount.h:31
zypp::media::MediaVerifierBase::~MediaVerifierBase
virtual ~MediaVerifierBase()
Definition: MediaManager.h:61
zypp::media::NoVerifier
Dummy default media verifier, which is always happy.
Definition: MediaManager.h:86
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
zypp::media::MediaManager::MediaManager
MediaManager()
Creates a MediaManager envelope instance.
Definition: MediaManager.cc:230
zypp::media::MediaVerifierBase::MediaVerifierBase
MediaVerifierBase()
Definition: MediaManager.h:58
zypp::media::MediaManager::provideDirTree
void provideDirTree(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:673
zypp::RW_pointer
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:286
Url.h
zypp::media::MediaManager::isOpen
bool isOpen(MediaAccessId accessId) const
Query if the media access is open / exists.
Definition: MediaManager.cc:299
zypp::media::NoVerifier::isDesiredMedia
bool isDesiredMedia(const MediaAccessRef &) const override
Definition: MediaManager.h:103
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:462
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:606
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
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:245
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
zypp::media::MediaManager::provideDir
void provideDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:661
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:366
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:617
zypp::media::MediaManager::findAttachedMedia
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Definition: MediaManager.cc:868
MediaAccess.h
zypp::media::MediaManager::getMountTableMTime
static time_t getMountTableMTime()
Get the modification time of the /etc/mtab file.
Definition: MediaManager.cc:775
zypp::media::MediaManager::downloads
bool downloads(MediaAccessId accessId) const
Hint if files are downloaded or not.
Definition: MediaManager.cc:317
zypp::media::MediaManager::close
void close(MediaAccessId accessId)
Close the media access with specified id.
Definition: MediaManager.cc:265
zypp::media::MediaManager::addVerifier
void addVerifier(MediaAccessId accessId, const MediaVerifierRef &verifier)
Add verifier implementation for the specified media id.
Definition: MediaManager.cc:335
zypp::media::MediaManager::getMountEntries
static std::vector< MountEntry > getMountEntries()
Get current mount entries from /etc/mtab file.
Definition: MediaManager.cc:783
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:543
zypp::media::MediaManager::doesFileExist
bool doesFileExist(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:752
zypp::media::MediaManager::release
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
Definition: MediaManager.cc:440
zypp::media::MediaManager::getAttachedMedia
AttachedMedia getAttachedMedia(MediaAccessId &accessId) const
Definition: MediaManager.cc:859
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:722
zypp::media::NoVerifier::~NoVerifier
~NoVerifier() override
Definition: MediaManager.h:91
verifier
MediaVerifierRef verifier
Definition: MediaManager.cc:104
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:764
zypp::media::MediaManager::isSharedMedia
bool isSharedMedia(MediaAccessId accessId) const
Returns information if media is on a shared physical device or not.
Definition: MediaManager.cc:534
zypp::Url
Url manipulation class.
Definition: Url.h:92
zypp::media::MediaAccessRef
zypp::RW_pointer< MediaAccess > MediaAccessRef
Definition: MediaManager.h:36
zypp::media::MediaManager::provideFile
void provideFile(MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const
Provide provide file denoted by relative path below of the 'attach point' of the specified media and ...
Definition: MediaManager.cc:628
zypp::media::MediaManager::protocol
std::string protocol(MediaAccessId accessId) const
Query the protocol name used by the media access handler.
Definition: MediaManager.cc:308
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:599
zypp::media::MediaManager::forceReleaseShared
void forceReleaseShared(const MediaSourceRef &media)
Definition: MediaManager.cc:888
NonCopyable.h
zypp::media::MediaManager::releasePath
void releasePath(MediaAccessId accessId, const Pathname &pathname) const
FIXME: see MediaAccess class.
Definition: MediaManager.cc:710