ignore
[platform/upstream/libzypp.git] / zypp / MediaSetAccess.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9
10 #ifndef ZYPP_MediaSetAccess_H
11 #define ZYPP_MediaSetAccess_H
12
13 #include <iosfwd>
14 #include <string>
15 #include <vector>
16 #include <boost/function.hpp>
17
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
25 ///////////////////////////////////////////////////////////////////
26 namespace zypp
27 { /////////////////////////////////////////////////////////////////
28
29     DEFINE_PTR_TYPE(MediaSetAccess);
30
31
32     class MediaVerifier : public zypp::media::MediaVerifierBase
33     {
34       public:
35       /** ctor */
36       MediaVerifier(const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr = 1);
37       /**
38        * Check if the specified attached media contains
39        * the desired media number (e.g. SLES10 CD1).
40        */
41       virtual bool isDesiredMedia(const media::MediaAccessRef &ref);
42       private:
43         std::string _media_vendor;
44         std::string _media_id;
45         media::MediaNr _media_nr;
46     };
47
48     class OnMediaLocation
49     {
50       public:
51       OnMediaLocation()
52       {};
53       private:
54       
55     };
56
57     typedef boost::function<bool ( const Pathname &file )> FileChecker;
58
59     class NullFileChecker
60     {
61       public:
62       bool operator()( const Pathname &file );
63     };
64
65     class ChecksumFileChecker
66     {
67       public:
68       ChecksumFileChecker( const CheckSum &checksum );
69       bool operator()( const Pathname &file );
70       private:
71       CheckSum _checksum;
72     };
73
74     ///////////////////////////////////////////////////////////////////
75     //
76     //  CLASS NAME : SourceCache
77     //
78     class MediaSetAccess : public base::ReferenceCounted, private base::NonCopyable
79     {
80       friend std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj );
81
82     public:
83       /**
84        * creates a callback enabled media access  for \param url and \param path.
85        * with only  media no verified
86        */
87       MediaSetAccess( const Url &url, const Pathname &path );
88       ~MediaSetAccess();
89       /**
90        * the media change callbacks depend on the verifiers given for each media.
91        */
92       void setVerifiers( const std::vector<media::MediaVerifierRef> &verifiers );
93       Pathname provideFile(const Pathname & file, unsigned media_nr = 1 );
94       Pathname provideFile(const Pathname & file, unsigned media_nr, const FileChecker checker );
95       void providePossiblyCachedMetadataFile( const Pathname &file_to_download, unsigned medianr, const Pathname &destination, const Pathname &cached_file, const CheckSum &checksum );
96     protected:
97       Pathname provideFileInternal(const Pathname & file, unsigned media_nr, bool checkonly, bool cached);
98       Url rewriteUrl (const Url & url_r, const media::MediaNr medianr);
99       media::MediaAccessId getMediaAccessId (media::MediaNr medianr);
100       virtual std::ostream & dumpOn( std::ostream & str ) const;
101     private:
102       Url _url;
103       Pathname _path;
104       std::vector<media::MediaVerifierRef> _verifiers;
105       typedef std::map<media::MediaNr, media::MediaAccessId> MediaMap;
106       /** Mapping between each CD and Media Access ID */
107       MediaMap medias;
108     };
109     ///////////////////////////////////////////////////////////////////
110
111     /** \relates MediaSetAccess Stream output */
112     inline std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj )
113     { return obj.dumpOn( str ); }
114
115
116 } // namespace zypp
117 ///////////////////////////////////////////////////////////////////
118 #endif // ZYPP_SOURCE_MediaSetAccess_H