00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef ZYPP_MediaSetAccess_H
00011 #define ZYPP_MediaSetAccess_H
00012
00013 #include <iosfwd>
00014 #include <string>
00015 #include <vector>
00016 #include <boost/function.hpp>
00017
00018 #include "zypp/base/ReferenceCounted.h"
00019 #include "zypp/base/NonCopyable.h"
00020 #include "zypp/base/PtrTypes.h"
00021 #include "zypp/media/MediaManager.h"
00022 #include "zypp/Pathname.h"
00023 #include "zypp/CheckSum.h"
00024
00026 namespace zypp
00027 {
00028
00029 DEFINE_PTR_TYPE(MediaSetAccess);
00030
00031
00032 class MediaVerifier : public zypp::media::MediaVerifierBase
00033 {
00034 public:
00036 MediaVerifier(const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr = 1);
00041 virtual bool isDesiredMedia(const media::MediaAccessRef &ref);
00042 private:
00043 std::string _media_vendor;
00044 std::string _media_id;
00045 media::MediaNr _media_nr;
00046 };
00047
00048 class OnMediaLocation
00049 {
00050 public:
00051 OnMediaLocation()
00052 {};
00053 private:
00054
00055 };
00056
00057 typedef boost::function<bool ( const Pathname &file )> FileChecker;
00058
00059 class NullFileChecker
00060 {
00061 public:
00062 bool operator()( const Pathname &file );
00063 };
00064
00065 class ChecksumFileChecker
00066 {
00067 public:
00068 ChecksumFileChecker( const CheckSum &checksum );
00069 bool operator()( const Pathname &file );
00070 private:
00071 CheckSum _checksum;
00072 };
00073
00075
00076
00077
00078 class MediaSetAccess : public base::ReferenceCounted, private base::NonCopyable
00079 {
00080 friend std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj );
00081
00082 public:
00087 MediaSetAccess( const Url &url, const Pathname &path );
00088 ~MediaSetAccess();
00092 void setVerifiers( const std::vector<media::MediaVerifierRef> &verifiers );
00093 Pathname provideFile(const Pathname & file, unsigned media_nr = 1 );
00094 Pathname provideFile(const Pathname & file, unsigned media_nr, const FileChecker checker );
00095 void providePossiblyCachedMetadataFile( const Pathname &file_to_download, unsigned medianr, const Pathname &destination, const Pathname &cached_file, const CheckSum &checksum );
00096 protected:
00097 Pathname provideFileInternal(const Pathname & file, unsigned media_nr, bool checkonly, bool cached);
00098 Url rewriteUrl (const Url & url_r, const media::MediaNr medianr);
00099 media::MediaAccessId getMediaAccessId (media::MediaNr medianr);
00100 virtual std::ostream & dumpOn( std::ostream & str ) const;
00101 private:
00102 Url _url;
00103 Pathname _path;
00104 std::vector<media::MediaVerifierRef> _verifiers;
00105 typedef std::map<media::MediaNr, media::MediaAccessId> MediaMap;
00107 MediaMap medias;
00108 };
00110
00112 inline std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj )
00113 { return obj.dumpOn( str ); }
00114
00115
00116 }
00118 #endif // ZYPP_SOURCE_MediaSetAccess_H