libzypp  17.25.2
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 #include <zypp/OnMediaLocation.h>
23 
24 #include <list>
25 
26 
28 namespace zypp
29 {
30 
32  namespace media
33  {
34 
35 
38 
39  // OBSOLETE HERE:
41  typedef unsigned int MediaNr;
42 
43 
45  // forward declaration
46  struct MountEntry;
47  class MediaManager_Impl;
48 
50  //
51  // CLASS NAME : MediaVerifierBase
52  //
56  class MediaVerifierBase //: private zypp::NonCopyable
57  {
58  public:
60  {}
61 
62  virtual
64  {}
65 
70  virtual std::string
71  info() const;
72 
73  /*
74  ** Check if the specified attached media contains
75  ** the desired media (e.g. SLES10 CD1).
76  */
77  virtual bool
78  isDesiredMedia(const MediaAccessRef &ref) = 0;
79  };
80 
81 
83  //
84  // CLASS NAME : NoVerifier
85  //
90  {
91  public:
93  {}
94 
95  virtual
97  {}
98 
102  virtual std::string
103  info() const;
104 
105  /*
106  ** Don't check if the specified attached media contains
107  ** the desired media number. Always return true.
108  */
109  virtual bool
111  {
112  (void)ref;
113  return true;
114  }
115  };
116 
117 
119  //
120  // CLASS NAME : MediaVerifierRef
121  //
126 
127 
129  //
130  // CLASS NAME : MediaManager
131  //
472  {
473  public:
485  MediaManager();
486 
491  ~MediaManager();
492 
514  open(const Url &url, const Pathname & preferred_attach_point = "");
515 
520  void
521  close(MediaAccessId accessId);
522 
529  bool
530  isOpen(MediaAccessId accessId) const;
531 
541  std::string
542  protocol(MediaAccessId accessId) const;
543 
549  bool
550  downloads(MediaAccessId accessId) const;
551 
559  Url
560  url(MediaAccessId accessId) const;
561 
562  public:
571  void
572  addVerifier(MediaAccessId accessId,
573  const MediaVerifierRef &verifier);
574 
582  void
583  delVerifier(MediaAccessId accessId);
584 
585  public:
598  bool
599  setAttachPrefix(const Pathname &attach_prefix);
600 
610  void
611  attach(MediaAccessId accessId);
612 
624  void
625  release(MediaAccessId accessId, const std::string & ejectDev = "");
626 
630  void
631  releaseAll();
632 
647  void
648  disconnect(MediaAccessId accessId);
649 
657  bool
658  isAttached(MediaAccessId accessId) const;
659 
668  bool
669  isSharedMedia(MediaAccessId accessId) const;
670 
680  bool
681  isDesiredMedia(MediaAccessId accessId) const;
682 
693  bool
694  isDesiredMedia(MediaAccessId accessId,
695  const MediaVerifierRef &verifier) const;
696 
708  bool
709  isChangeable(MediaAccessId accessId);
710 
723  Pathname
724  localRoot(MediaAccessId accessId) const;
725 
738  Pathname
739  localPath(MediaAccessId accessId, const Pathname & pathname) const;
740 
741  public:
761  void
762  provideFile(MediaAccessId accessId,
763  const Pathname &filename,
764  const ByteCount &expectedFileSize) const;
765 
766  void
767  provideFile(MediaAccessId accessId,
768  const Pathname &filename ) const;
769 
773  void
774  provideDir(MediaAccessId accessId,
775  const Pathname &dirname) const;
776 
780  void
781  provideDirTree(MediaAccessId accessId,
782  const Pathname &dirname) const;
783 
787  void
788  releaseFile(MediaAccessId accessId,
789  const Pathname &filename) const;
790 
794  void
795  releaseDir(MediaAccessId accessId,
796  const Pathname &dirname) const;
797 
801  void
802  releasePath(MediaAccessId accessId,
803  const Pathname &pathname) const;
804 
808  void
809  dirInfo(MediaAccessId accessId,
810  std::list<std::string> &retlist,
811  const Pathname &dirname,
812  bool dots = true) const;
813 
817  void
818  dirInfo(MediaAccessId accessId,
819  filesystem::DirContent &retlist,
820  const Pathname &dirname,
821  bool dots = true) const;
822 
826  bool doesFileExist(MediaAccessId accessId,
827  const Pathname & filename ) const;
828 
838  void
840  std::vector<std::string> & devices,
841  unsigned int & index) const;
842 
843  void
844  setDeltafile(MediaAccessId accessId,
845  const Pathname &filename ) const;
846 
858  void precacheFiles( MediaAccessId accessId,
859  const std::vector<OnMediaLocation> &files);
860 
861  public:
866  static time_t
868 
873  static std::vector<MountEntry>
874  getMountEntries();
875 
885  bool
886  isUseableAttachPoint(const Pathname &path,
887  bool mtab=true) const;
888 
889  private:
890  friend class MediaHandler;
891 
902  getAttachedMedia(MediaAccessId &accessId) const;
903 
914  findAttachedMedia(const MediaSourceRef &media) const;
915 
924  void
925  forceReleaseShared(const MediaSourceRef &media);
926 
927  private:
932  };
933 
934 
936  } // namespace media
938 
940 } // namespace zypp
942 
943 #endif // ZYPP_MEDIA_MEDIAMANAGER_H
944 
945 /*
946 ** vim: set ts=2 sts=2 sw=2 ai et:
947 */
Dummy default media verifier, which is always happy.
Definition: MediaManager.h:89
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
void releasePath(MediaAccessId accessId, const Pathname &pathname) const
FIXME: see MediaAccess class.
void provideDirTree(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
void setDeltafile(MediaAccessId accessId, const Pathname &filename) const
bool doesFileExist(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
zypp::RW_pointer< MediaVerifierBase > MediaVerifierRef
A shared reference to the MediaVerifier implementation.
Definition: MediaManager.h:125
Store and operate with byte count.
Definition: ByteCount.h:30
MediaAccessId MediaId
Definition: MediaManager.h:40
void dirInfo(MediaAccessId accessId, std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
FIXME: see MediaAccess class.
bool isOpen(MediaAccessId accessId) const
Query if the media access is open / exists.
void provideFile(MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const
Provide provide file denoted by relative path below of the &#39;attach point&#39; of the specified media and ...
Interface to implement a media verifier.
Definition: MediaManager.h:56
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
bool isChangeable(MediaAccessId accessId)
Simple check, based on media&#39;s URL scheme, telling whether the it is possible to physically change th...
bool setAttachPrefix(const Pathname &attach_prefix)
Set or resets the directory name, where the media manager handlers create their temporary attach poin...
void disconnect(MediaAccessId accessId)
Disconnect a remote media.
static zypp::RW_pointer< MediaManager_Impl > m_impl
Static reference to the implementation (singleton).
Definition: MediaManager.h:931
virtual std::string info() const
Returns a string with some info about the verifier.
Pathname localPath(MediaAccessId accessId, const Pathname &pathname) const
Shortcut for &#39;localRoot() + pathname&#39;, but returns an empty pathname if media is not attached...
~MediaManager()
Destroys MediaManager envelope instance.
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
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
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
void addVerifier(MediaAccessId accessId, const MediaVerifierRef &verifier)
Add verifier implementation for the specified media id.
virtual bool isDesiredMedia(const MediaAccessRef &ref)=0
void precacheFiles(MediaAccessId accessId, const std::vector< OnMediaLocation > &files)
Tries to fetch the given files and precaches them.
AttachedMedia getAttachedMedia(MediaAccessId &accessId) const
void provideDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
void forceReleaseShared(const MediaSourceRef &media)
void attach(MediaAccessId accessId)
Attach the media using the concrete handler (checks all devices).
MediaManager()
Creates a MediaManager envelope instance.
void releaseDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
Url url(MediaAccessId accessId) const
Returns the Media Access Url of the media access id.
Manages access to the &#39;physical&#39; media, e.g CDROM drives, Disk volumes, directory trees...
Definition: MediaManager.h:471
bool isSharedMedia(MediaAccessId accessId) const
Returns information if media is on a shared physical device or not.
bool downloads(MediaAccessId accessId) const
Hint if files are downloaded or not.
MediaVerifierRef verifier
virtual std::string info() const
Returns the "zypp::media::NoVerifier" string.
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:285
A "struct mntent" like mount entry structure, but using std::strings.
Definition: Mount.h:34
virtual bool isDesiredMedia(const MediaAccessRef &ref)
Definition: MediaManager.h:110
bool isAttached(MediaAccessId accessId) const
Check if media is attached or not.
void releaseAll()
Release all attached media.
bool isDesiredMedia(MediaAccessId accessId) const
Ask the registered verifier if the attached media is the desired one or not.
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 ...
Pathname localRoot(MediaAccessId accessId) const
Return the local directory that corresponds to medias url, no matter if media isAttached or not...
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
MediaAccessId open(const Url &url, const Pathname &preferred_attach_point="")
Opens the media access for specified with the url.
zypp::RW_pointer< MediaAccess > MediaAccessRef
Definition: MediaManager.h:37
static time_t getMountTableMTime()
Get the modification time of the /etc/mtab file.
Url manipulation class.
Definition: Url.h:87
void delVerifier(MediaAccessId accessId)
Remove verifier for specified media id.
void releaseFile(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
unsigned int MediaNr
Definition: MediaManager.h:41
void close(MediaAccessId accessId)
Close the media access with specified id.
std::string protocol(MediaAccessId accessId) const
Query the protocol name used by the media access handler.
static std::vector< MountEntry > getMountEntries()
Get current mount entries from /etc/mtab file.
bool isUseableAttachPoint(const Pathname &path, bool mtab=true) const
Check if the specified path is useable as attach point.