1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
10 #ifndef ZYPP_MediaSetAccess_H
11 #define ZYPP_MediaSetAccess_H
16 #include <boost/function.hpp>
18 #include "zypp/base/ReferenceCounted.h"
19 #include "zypp/base/NonCopyable.h"
20 #include "zypp/base/PtrTypes.h"
21 #include "zypp/media/MediaManager.h"
22 #include "zypp/Pathname.h"
23 #include "zypp/CheckSum.h"
24 #include "zypp/OnMediaLocation.h"
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
30 DEFINE_PTR_TYPE(MediaSetAccess);
32 typedef boost::function<bool ( const Pathname &file )> FileChecker;
37 bool operator()( const Pathname &file );
40 class ChecksumFileChecker
43 ChecksumFileChecker( const CheckSum &checksum );
44 bool operator()( const Pathname &file );
49 ///////////////////////////////////////////////////////////////////
51 // CLASS NAME : MediaSetAccess
54 * Media access layer responsible for handling media distributed as a set.
56 * This is provided as a means to handle CD or DVD sets accessible through
57 * dir, iso, nfs or other URL schemes other than cd/dvd (see
58 * \ref MediaManager for info on different implemented media backends).
59 * Currently it handles URLs containing cdN, CDN, dvdN, and DVDN strings,
60 * where N is the number of particular media in the set.
64 * "iso:/?iso=/path/to/iso/images/openSUSE-10.3-Alpha2plus-DVD-x86_64-DVD1.iso"
65 * "dir:/path/to/cdset/sources/openSUSE-10.3/Alpha2plus/CD1"
68 * MediaSetAccess accesses files on desired media by rewriting
69 * the original URL, replacing the digit (usually) 1 with requested media
70 * number and uses \ref MediaManager to get the files from the new URL.
72 * Additionaly, each media number can be assined a media verifier which
73 * checks if the media we are trying to access is the desired one. See
74 * \ref MediaVerifierBase for more info.
78 * Url url("dir:/path/to/cdset/sources/openSUSE-10.3/Alpha2plus/CD1");
80 * MediaSetAccess access(url, "/");
82 * access.setVerifier(1, media1VerifierRef);
83 * access.setVerifier(2, media2VerifierRef);
85 * Pathname file1 = "/some/file/on/media1";
86 * access.provideFile(1, file1);
87 * Pathname file2 = "/some/file/on/media2";
88 * access.provideFile(2, file1);
92 class MediaSetAccess : public base::ReferenceCounted, private base::NonCopyable
94 friend std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj );
98 * creates a callback enabled media access for \param url and \param path.
99 * with only 1 media no verified
101 MediaSetAccess( const Url &url, const Pathname &path );
105 * Sets a \ref MediaVerifierRef verifier for given media number
107 void setVerifier( unsigned media_nr, media::MediaVerifierRef verifier );
110 * provide a file from a media location.
112 Pathname provideFile( const OnMediaLocation & on_media_file );
114 Pathname provideFile(const Pathname & file, unsigned media_nr = 1 );
115 Pathname provideFile(const Pathname & file, unsigned media_nr, const FileChecker checker );
117 static Url rewriteUrl (const Url & url_r, const media::MediaNr medianr);
120 Pathname provideFileInternal(const Pathname & file, unsigned media_nr, bool checkonly, bool cached);
121 media::MediaAccessId getMediaAccessId (media::MediaNr medianr);
122 virtual std::ostream & dumpOn( std::ostream & str ) const;
125 /** Media or media set URL */
127 /** Path on the media relative to _url */
130 typedef std::map<media::MediaNr, media::MediaAccessId> MediaMap;
131 typedef std::map<media::MediaNr, media::MediaVerifierRef > VerifierMap;
133 /** Mapping between media number and Media Access ID */
135 /** Mapping between media number and corespondent verifier */
136 VerifierMap _verifiers;
138 ///////////////////////////////////////////////////////////////////
140 /** \relates MediaSetAccess Stream output */
141 inline std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj )
142 { return obj.dumpOn( str ); }
146 ///////////////////////////////////////////////////////////////////
147 #endif // ZYPP_SOURCE_MediaSetAccess_H