- Create the cache directly from the schema (installed) file.
[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 #include "zypp/OnMediaLocation.h"
25
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29
30     DEFINE_PTR_TYPE(MediaSetAccess);
31
32     typedef boost::function<bool ( const Pathname &file )> FileChecker;
33
34     class NullFileChecker
35     {
36       public:
37       bool operator()( const Pathname &file );
38     };
39
40     class ChecksumFileChecker
41     {
42       public:
43       ChecksumFileChecker( const CheckSum &checksum );
44       bool operator()( const Pathname &file );
45       private:
46       CheckSum _checksum;
47     };
48
49     ///////////////////////////////////////////////////////////////////
50     //
51     //  CLASS NAME : SourceCache
52     //
53     /**
54      * The
55      */
56     class MediaSetAccess : public base::ReferenceCounted, private base::NonCopyable
57     {
58       friend std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj );
59
60     public:
61       /**
62        * creates a callback enabled media access  for \param url and \param path.
63        * with only 1 media no verified
64        */
65       MediaSetAccess( const Url &url, const Pathname &path );
66       ~MediaSetAccess();
67
68       /**
69        * Sets a \ref MediaVerifierRef verifier for given media number
70        */
71       void setVerifier( unsigned media_nr, media::MediaVerifierRef verifier );
72       
73       /**
74        * provide a file from a media location.
75        */
76       Pathname provideFile( const OnMediaLocation & on_media_file );
77
78       Pathname provideFile(const Pathname & file, unsigned media_nr = 1 );
79       Pathname provideFile(const Pathname & file, unsigned media_nr, const FileChecker checker );
80       
81     protected:
82       Pathname provideFileInternal(const Pathname & file, unsigned media_nr, bool checkonly, bool cached);
83       Url rewriteUrl (const Url & url_r, const media::MediaNr medianr);
84       media::MediaAccessId getMediaAccessId (media::MediaNr medianr);
85       virtual std::ostream & dumpOn( std::ostream & str ) const;
86     private:
87       Url _url;
88       Pathname _path;
89       typedef std::map<media::MediaNr, media::MediaAccessId> MediaMap;
90       typedef std::map<media::MediaNr, media::MediaVerifierRef > VerifierMap;
91       /** Mapping between each CD and Media Access ID */
92       MediaMap _medias;
93       VerifierMap _verifiers;
94     };
95     ///////////////////////////////////////////////////////////////////
96
97     /** \relates MediaSetAccess Stream output */
98     inline std::ostream & operator<<( std::ostream & str, const MediaSetAccess & obj )
99     { return obj.dumpOn( str ); }
100
101
102 } // namespace zypp
103 ///////////////////////////////////////////////////////////////////
104 #endif // ZYPP_SOURCE_MediaSetAccess_H