libzypp  15.28.6
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  class MountEntry;
46  class MediaManager_Impl;
47 
49  //
50  // CLASS NAME : MediaVerifierBase
51  //
55  class MediaVerifierBase //: private zypp::NonCopyable
56  {
57  public:
59  {}
60 
61  virtual
63  {}
64 
69  virtual std::string
70  info() const;
71 
72  /*
73  ** Check if the specified attached media contains
74  ** the desired media (e.g. SLES10 CD1).
75  */
76  virtual bool
77  isDesiredMedia(const MediaAccessRef &ref) = 0;
78  };
79 
80 
82  //
83  // CLASS NAME : NoVerifier
84  //
89  {
90  public:
92  {}
93 
94  virtual
96  {}
97 
101  virtual std::string
102  info() const;
103 
104  /*
105  ** Don't check if the specified attached media contains
106  ** the desired media number. Always return true.
107  */
108  virtual bool
110  {
111  (void)ref;
112  return true;
113  }
114  };
115 
116 
118  //
119  // CLASS NAME : MediaVerifierRef
120  //
125 
126 
128  //
129  // CLASS NAME : MediaManager
130  //
474  {
475  public:
487  MediaManager();
488 
493  ~MediaManager();
494 
516  open(const Url &url, const Pathname & preferred_attach_point = "");
517 
522  void
523  close(MediaAccessId accessId);
524 
531  bool
532  isOpen(MediaAccessId accessId) const;
533 
543  std::string
544  protocol(MediaAccessId accessId) const;
545 
551  bool
552  downloads(MediaAccessId accessId) const;
553 
561  Url
562  url(MediaAccessId accessId) const;
563 
564  public:
573  void
574  addVerifier(MediaAccessId accessId,
575  const MediaVerifierRef &verifier);
576 
584  void
585  delVerifier(MediaAccessId accessId);
586 
587  public:
600  bool
601  setAttachPrefix(const Pathname &attach_prefix);
602 
612  void
613  attach(MediaAccessId accessId);
614 
626  void
627  release(MediaAccessId accessId, const std::string & ejectDev = "");
628 
632  void
633  releaseAll();
634 
649  void
650  disconnect(MediaAccessId accessId);
651 
659  bool
660  isAttached(MediaAccessId accessId) const;
661 
670  bool
671  isSharedMedia(MediaAccessId accessId) const;
672 
682  bool
683  isDesiredMedia(MediaAccessId accessId) const;
684 
695  bool
696  isDesiredMedia(MediaAccessId accessId,
697  const MediaVerifierRef &verifier) const;
698 
710  bool
711  isChangeable(MediaAccessId accessId);
712 
725  Pathname
726  localRoot(MediaAccessId accessId) const;
727 
740  Pathname
741  localPath(MediaAccessId accessId, const Pathname & pathname) const;
742 
743  public:
763  void
764  provideFile(MediaAccessId accessId,
765  const Pathname &filename,
766  const ByteCount &expectedFileSize) const;
767 
768  void
769  provideFile(MediaAccessId accessId,
770  const Pathname &filename ) const;
771 
775  void
776  provideDir(MediaAccessId accessId,
777  const Pathname &dirname) const;
778 
782  void
783  provideDirTree(MediaAccessId accessId,
784  const Pathname &dirname) const;
785 
789  void
790  releaseFile(MediaAccessId accessId,
791  const Pathname &filename) const;
792 
796  void
797  releaseDir(MediaAccessId accessId,
798  const Pathname &dirname) const;
799 
803  void
804  releasePath(MediaAccessId accessId,
805  const Pathname &pathname) const;
806 
810  void
811  dirInfo(MediaAccessId accessId,
812  std::list<std::string> &retlist,
813  const Pathname &dirname,
814  bool dots = true) const;
815 
819  void
820  dirInfo(MediaAccessId accessId,
821  filesystem::DirContent &retlist,
822  const Pathname &dirname,
823  bool dots = true) const;
824 
828  bool doesFileExist(MediaAccessId accessId,
829  const Pathname & filename ) const;
830 
840  void
842  std::vector<std::string> & devices,
843  unsigned int & index) const;
844 
845  void
846  setDeltafile(MediaAccessId accessId,
847  const Pathname &filename ) const;
848 
849  public:
854  static time_t
856 
861  static std::vector<MountEntry>
862  getMountEntries();
863 
873  bool
874  isUseableAttachPoint(const Pathname &path,
875  bool mtab=true) const;
876 
877  private:
878  friend class MediaHandler;
879 
890  getAttachedMedia(MediaAccessId &accessId) const;
891 
902  findAttachedMedia(const MediaSourceRef &media) const;
903 
912  void
913  forceReleaseShared(const MediaSourceRef &media);
914 
915  private:
920  };
921 
922 
924  } // namespace media
926 
928 } // namespace zypp
930 
931 #endif // ZYPP_MEDIA_MEDIAMANAGER_H
932 
933 /*
934 ** vim: set ts=2 sts=2 sw=2 ai et:
935 */
Dummy default media verifier, which is always happy.
Definition: MediaManager.h:88
void releaseFile(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
Url url(MediaAccessId accessId) const
Returns the Media Access Url of the media access id.
void releasePath(MediaAccessId accessId, const Pathname &pathname) const
FIXME: see MediaAccess class.
void provideDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
zypp::RW_pointer< MediaVerifierBase > MediaVerifierRef
A shared reference to the MediaVerifier implementation.
Definition: MediaManager.h:124
Store and operate with byte count.
Definition: ByteCount.h:30
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 ...
bool isOpen(MediaAccessId accessId) const
Query if the media access is open / exists.
MediaAccessId MediaId
Definition: MediaManager.h:39
bool isUseableAttachPoint(const Pathname &path, bool mtab=true) const
Check if the specified path is useable as attach point.
void setDeltafile(MediaAccessId accessId, const Pathname &filename) const
Pathname localRoot(MediaAccessId accessId) const
Return the local directory that corresponds to medias url, no matter if media isAttached or not...
bool isDesiredMedia(MediaAccessId accessId) const
Ask the registered verifier if the attached media is the desired one or not.
void dirInfo(MediaAccessId accessId, std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
FIXME: see MediaAccess class.
Interface to implement a media verifier.
Definition: MediaManager.h:55
bool downloads(MediaAccessId accessId) const
Hint if files are downloaded or not.
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
bool isChangeable(MediaAccessId accessId)
Simple check, based on media'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:919
std::string protocol(MediaAccessId accessId) const
Query the protocol name used by the media access handler.
~MediaManager()
Destroys MediaManager envelope instance.
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
bool doesFileExist(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:133
virtual std::string info() const
Returns the "zypp::media::NoVerifier" string.
AttachedMedia getAttachedMedia(MediaAccessId &accessId) const
Pathname localPath(MediaAccessId accessId, const Pathname &pathname) const
Shortcut for 'localRoot() + pathname', but returns an empty pathname if media is not attached...
Provides API related macros.
bool isSharedMedia(MediaAccessId accessId) const
Returns information if media is on a shared physical device 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 ...
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
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
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.
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees...
Definition: MediaManager.h:473
MediaVerifierRef verifier
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:109
void provideDirTree(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
virtual std::string info() const
Returns a string with some info about the verifier.
bool isAttached(MediaAccessId accessId) const
Check if media is attached or not.
void releaseAll()
Release all attached media.
void releaseDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
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:36
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.
unsigned int MediaNr
Definition: MediaManager.h:40
void close(MediaAccessId accessId)
Close the media access with specified id.
static std::vector< MountEntry > getMountEntries()
Get current mount entries from /etc/mtab file.