libzypp  17.37.5
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-core/Globals.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/media/MediaUrl.h>
21 #include <zypp-core/OnMediaLocation>
22 #include <zypp/media/MediaSource.h>
23 #include <zypp-media/MediaException>
24 
25 #include <list>
26 
27 
28 namespace zypp::media
29 {
30  class MediaHandler;
31 
32  using MediaNr = unsigned int;
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 
495  MediaAccessId open(const Url &url, const Pathname & preferred_attach_point = "");
496 
497 
516  open(const std::vector<MediaUrl> &urls, const Pathname & preferred_attach_point = "");
517 
518 
523  void
524  close(MediaAccessId accessId);
525 
532  bool
533  isOpen(MediaAccessId accessId) const;
534 
544  std::string
545  protocol(MediaAccessId accessId) const;
546 
552  bool
553  downloads(MediaAccessId accessId) const;
554 
562  Url
563  url(MediaAccessId accessId) const;
564 
565  public:
574  void
575  addVerifier(MediaAccessId accessId,
576  const MediaVerifierRef &verifier);
577 
585  void
586  delVerifier(MediaAccessId accessId);
587 
588  public:
601  bool
602  setAttachPrefix(const Pathname &attach_prefix);
603 
613  void
614  attach(MediaAccessId accessId);
615 
627  void
628  release(MediaAccessId accessId, const std::string & ejectDev = "");
629 
633  void
634  releaseAll();
635 
650  void
651  disconnect(MediaAccessId accessId);
652 
660  bool
661  isAttached(MediaAccessId accessId) const;
662 
671  bool
672  isSharedMedia(MediaAccessId accessId) const;
673 
683  bool
684  isDesiredMedia(MediaAccessId accessId) const;
685 
696  bool
697  isDesiredMedia(MediaAccessId accessId,
698  const MediaVerifierRef &verifier) const;
699 
711  bool
712  isChangeable(MediaAccessId accessId);
713 
726  Pathname
727  localRoot(MediaAccessId accessId) const;
728 
741  Pathname
742  localPath(MediaAccessId accessId, const Pathname & pathname) const;
743 
744  public:
745 
750  ZYPP_DEPRECATED void
751  provideFile(MediaAccessId accessId,
752  const Pathname &filename,
753  const ByteCount &expectedFileSize) const;
754 
759  ZYPP_DEPRECATED void
760  provideFile(MediaAccessId accessId,
761  const Pathname &filename ) const;
762 
763 
781  void
782  provideFile(MediaAccessId accessId,
783  const OnMediaLocation &file ) const;
784 
788  void
789  provideDir(MediaAccessId accessId,
790  const Pathname &dirname) const;
791 
795  void
796  provideDirTree(MediaAccessId accessId,
797  const Pathname &dirname) const;
798 
802  void
803  releaseFile(MediaAccessId accessId,
804  const Pathname &filename) const;
805 
809  void
810  releaseDir(MediaAccessId accessId,
811  const Pathname &dirname) const;
812 
816  void
817  releasePath(MediaAccessId accessId,
818  const Pathname &pathname) const;
819 
823  void
824  dirInfo(MediaAccessId accessId,
825  std::list<std::string> &retlist,
826  const Pathname &dirname,
827  bool dots = true) const;
828 
832  void
833  dirInfo(MediaAccessId accessId,
834  filesystem::DirContent &retlist,
835  const Pathname &dirname,
836  bool dots = true) const;
837 
841  bool doesFileExist(MediaAccessId accessId,
842  const Pathname & filename ) const;
843 
853  void
854  getDetectedDevices(MediaAccessId accessId,
855  std::vector<std::string> & devices,
856  unsigned int & index) const;
857 
858  ZYPP_DEPRECATED void
859  setDeltafile(MediaAccessId accessId,
860  const Pathname &filename ) const;
861 
873  void precacheFiles( MediaAccessId accessId,
874  const std::vector<OnMediaLocation> &files);
875 
876  public:
881  static time_t
882  getMountTableMTime();
883 
888  static std::vector<MountEntry>
889  getMountEntries();
890 
900  bool
901  isUseableAttachPoint(const Pathname &path,
902  bool mtab=true) const;
903 
904  private:
905  friend class MediaHandler;
906 
917  getAttachedMedia(MediaAccessId &accessId) const;
918 
929  findAttachedMedia(const MediaSourceRef &media) const;
930 
939  void
940  forceReleaseShared(const MediaSourceRef &media);
941 
942  private:
947  };
948 
950 } // namespace zypp::media
952 
953 #endif // ZYPP_MEDIA_MEDIAMANAGER_H
954 
955 /*
956 ** vim: set ts=2 sts=2 sw=2 ai et:
957 */
Dummy default media verifier, which is always happy.
Definition: MediaManager.h:77
Describes a resource file located on a medium.
Store and operate with byte count.
Definition: ByteCount.h:31
Provides API related macros.
Interface to implement a media verifier.
Definition: MediaManager.h:47
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:526
static zypp::RW_pointer< MediaManager_Impl > m_impl
Static reference to the implementation (singleton).
Definition: MediaManager.h:946
virtual std::string info() const
Returns a string with some info about the verifier.
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:30
ManagedFile provideFile(RepoInfo repo_r, const OnMediaLocation &loc_r, const ProvideFilePolicy &policy_r)
Provide a file from a Repository.
Abstract base class for &#39;physical&#39; MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:51
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:134
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
bool isDesiredMedia(const MediaHandler &ref) const override
Definition: MediaManager.h:95
Manages access to the &#39;physical&#39; media, e.g CDROM drives, Disk volumes, directory trees...
Definition: MediaManager.h:453
MediaVerifierRef verifier
unsigned int MediaNr
Definition: MediaManager.h:32
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:292
A "struct mntent" like mount entry structure, but using std::strings.
Definition: mount.h:35
std::string info() const override
Returns the "zypp::media::NoVerifier" string.
#define ZYPP_DEPRECATED
The ZYPP_DEPRECATED macro can be used to trigger compile-time warnings with gcc >= 3...
Definition: Globals.h:112
Url manipulation class.
Definition: Url.h:92
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
virtual bool isDesiredMedia(const MediaHandler &ref) const =0