libzypp 17.37.10

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-core/MirroredOrigin.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:
50 MediaVerifierBase()
51 {}
52
53 virtual ~MediaVerifierBase()
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 //
77 class NoVerifier : public MediaVerifierBase
78 {
79 public:
80 NoVerifier(): MediaVerifierBase()
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 //
107 using MediaVerifierRef = zypp::RW_pointer<MediaVerifierBase>;
108
109
111 //
112 // CLASS NAME : MediaManager
113 //
453 class ZYPP_API MediaManager: private zypp::base::NonCopyable
454 {
455 public:
467 MediaManager();
468
473 ~MediaManager();
474
495 MediaAccessId open(const Url &url, const Pathname & preferred_attach_point = "");
496
497
515 MediaAccessId
516 open(const MirroredOrigin &origin_r, 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
916 AttachedMedia
917 getAttachedMedia(MediaAccessId &accessId) const;
918
928 AttachedMedia
929 findAttachedMedia(const MediaSourceRef &media) const;
930
939 void
940 forceReleaseShared(const MediaSourceRef &media);
941
942 private:
946 static zypp::RW_pointer<MediaManager_Impl> m_impl;
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*/
MediaSource.h
MirroredOrigin.h
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::MirroredOrigin
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Definition MirroredOrigin.h:170
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition onmedialocation.h:37
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::media::MediaHandler
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition MediaHandler.h:50
zypp::media::MediaManager_Impl
Definition MediaManager.cc:207
zypp::media::MediaManager::setDeltafile
ZYPP_DEPRECATED void setDeltafile(MediaAccessId accessId, const Pathname &filename) const
Definition MediaManager.cc:744
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:318
zypp::media::MediaManager::delVerifier
void delVerifier(MediaAccessId accessId)
Remove verifier for specified media id.
Definition MediaManager.cc:427
zypp::media::MediaManager::releaseFile
void releaseFile(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
Definition MediaManager.cc:789
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:678
zypp::media::MediaManager::forceReleaseShared
void forceReleaseShared(const MediaSourceRef &media)
Definition MediaManager.cc:992
zypp::media::MediaManager::releaseAll
void releaseAll()
Release all attached media.
Definition MediaManager.cc:559
zypp::media::MediaManager::m_impl
static zypp::RW_pointer< MediaManager_Impl > m_impl
Static reference to the implementation (singleton).
Definition MediaManager.h:946
zypp::media::MediaManager::disconnect
void disconnect(MediaAccessId accessId)
Disconnect a remote media.
Definition MediaManager.cc:596
zypp::media::MediaManager::attach
void attach(MediaAccessId accessId)
Attach the media using the concrete handler (checks all devices).
Definition MediaManager.cc:447
zypp::media::MediaManager::releaseDir
void releaseDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
Definition MediaManager.cc:801
zypp::media::MediaManager::isOpen
bool isOpen(MediaAccessId accessId) const
Query if the media access is open / exists.
Definition MediaManager.cc:375
zypp::media::MediaManager::releasePath
void releasePath(MediaAccessId accessId, const Pathname &pathname) const
FIXME: see MediaAccess class.
Definition MediaManager.cc:814
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:826
zypp::media::MediaManager::close
void close(MediaAccessId accessId)
Close the media access with specified id.
Definition MediaManager.cc:341
zypp::media::MediaManager::url
Url url(MediaAccessId accessId) const
Returns the primary Media Access Url of the media access id.
Definition MediaManager.cc:401
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:622
zypp::media::MediaManager::provideFile
ZYPP_DEPRECATED void provideFile(MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const
Definition MediaManager.cc:707
zypp::media::MediaManager::release
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
Definition MediaManager.cc:516
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:754
zypp::media::MediaManager::isAttached
bool isAttached(MediaAccessId accessId) const
Check if media is attached or not.
Definition MediaManager.cc:605
zypp::media::MediaManager::getAttachedMedia
AttachedMedia getAttachedMedia(MediaAccessId &accessId) const
Definition MediaManager.cc:963
zypp::media::MediaManager::getMountTableMTime
static time_t getMountTableMTime()
Get the modification time of the /etc/mtab file.
Definition MediaManager.cc:879
zypp::media::MediaManager::isSharedMedia
bool isSharedMedia(MediaAccessId accessId) const
Returns information if media is on a shared physical device or not.
Definition MediaManager.cc:613
zypp::media::MediaManager::protocol
std::string protocol(MediaAccessId accessId) const
Query the protocol name used by the media access handler.
Definition MediaManager.cc:383
zypp::media::MediaManager::doesFileExist
bool doesFileExist(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
Definition MediaManager.cc:856
zypp::media::MediaManager::provideDir
void provideDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
Definition MediaManager.cc:765
zypp::media::MediaManager::findAttachedMedia
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Definition MediaManager.cc:972
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:894
zypp::media::MediaManager::MediaManager
MediaManager()
Creates a MediaManager envelope instance.
Definition MediaManager.cc:303
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:696
zypp::media::MediaManager::provideDirTree
void provideDirTree(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
Definition MediaManager.cc:777
zypp::media::MediaManager::addVerifier
void addVerifier(MediaAccessId accessId, const MediaVerifierRef &verifier)
Add verifier implementation for the specified media id.
Definition MediaManager.cc:410
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:441
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:868
zypp::media::MediaManager::MediaHandler
friend class MediaHandler
Definition MediaManager.h:905
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:685
zypp::media::MediaManager::downloads
bool downloads(MediaAccessId accessId) const
Hint if files are downloaded or not.
Definition MediaManager.cc:392
zypp::media::MediaManager::getMountEntries
static std::vector< MountEntry > getMountEntries()
Get current mount entries from /etc/mtab file.
Definition MediaManager.cc:887
zypp::media::MediaVerifierBase::info
virtual std::string info() const
Returns a string with some info about the verifier.
Definition MediaManager.cc:191
zypp::media::MediaVerifierBase::~MediaVerifierBase
virtual ~MediaVerifierBase()
Definition MediaManager.h:53
zypp::media::MediaVerifierBase::isDesiredMedia
virtual bool isDesiredMedia(const MediaHandler &ref) const =0
zypp::media::MediaVerifierBase::MediaVerifierBase
MediaVerifierBase()
Definition MediaManager.h:50
zypp::media::NoVerifier::~NoVerifier
~NoVerifier() override
Definition MediaManager.h:83
zypp::media::NoVerifier::info
std::string info() const override
Returns the "zypp::media::NoVerifier" string.
Definition MediaManager.cc:199
zypp::media::NoVerifier::isDesiredMedia
bool isDesiredMedia(const MediaHandler &ref) const override
Definition MediaManager.h:95
zypp::media::NoVerifier::NoVerifier
NoVerifier()
Definition MediaManager.h:80
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition NonCopyable.h:26
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition PathInfo.h:526
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp::media::MediaNr
unsigned int MediaNr
Definition MediaManager.h:32
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition MediaSource.h:30
zypp::media::MediaSourceRef
zypp::RW_pointer< MediaSource > MediaSourceRef
Definition MediaSource.h:125
zypp::media::MediaVerifierRef
zypp::RW_pointer< MediaVerifierBase > MediaVerifierRef
A shared reference to the MediaVerifier implementation.
Definition MediaManager.h:107
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
zypp::RW_pointer
Wrapper for const correct access via Smart pointer types.
Definition PtrTypes.h:293
zypp::media::AttachedMedia
A simple structure containing references to a media source and its attach point.
Definition MediaSource.h:135
zypp::media::MountEntry
A "struct mntent" like mount entry structure, but using std::strings.
Definition mount.h:36
Globals.h
Provides API related macros.
ZYPP_DEPRECATED
#define ZYPP_DEPRECATED
The ZYPP_DEPRECATED macro can be used to trigger compile-time warnings with gcc >= 3....
Definition Globals.h:112
PathInfo.h
Pathname.h
NonCopyable.h
PtrTypes.h