- Create the cache directly from the schema (installed) file.
[platform/upstream/libzypp.git] / zypp / SourceFactory.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/SourceFactory.h
10  *
11 */
12 #ifndef ZYPP_SOURCEFACTORY_H
13 #define ZYPP_SOURCEFACTORY_H
14
15 #include <iosfwd>
16 #include <string>
17 #include <set>
18 #include <boost/logic/tribool.hpp>
19
20 #include "zypp/base/PtrTypes.h"
21
22 #include "zypp/Source.h"
23 #include "zypp/source/SourceInfo.h"
24 #include "zypp/Url.h"
25 #include "zypp/Pathname.h"
26
27 using namespace boost;
28
29 ///////////////////////////////////////////////////////////////////
30 namespace zypp
31 { /////////////////////////////////////////////////////////////////
32
33   template<class T>
34   bool probeSource( media::MediaAccessId media_id );
35   
36   
37   ///////////////////////////////////////////////////////////////////
38   //
39   //    CLASS NAME : SourceFactory
40   //
41   /** Factory to create a \ref Source_Ref.
42    * Actually a Singleton
43    *
44   */
45   class SourceFactory
46   {
47     friend std::ostream & operator<<( std::ostream & str, const SourceFactory & obj );
48
49   public:
50     /** Default ctor */
51     SourceFactory();
52     /** Dtor */
53     ~SourceFactory();
54
55   public:
56     /** Construct source.
57      * \throw EXCEPTION on fail
58      */
59     Source_Ref createFrom( const source::SourceInfo & context );
60     
61     /** Construct source from an implementation.
62      * Returns Source_Ref::noSource on NULL \a impl_r.
63     */
64     Source_Ref createFrom( const Source_Ref::Impl_Ptr & impl_r );
65
66     /** Construct source.
67      * \throw EXCEPTION on fail
68     */
69     Source_Ref createFrom( const Url & url_r, const Pathname & path_r = "/", const std::string & alias_r = "", const Pathname & cache_dir_r = "", bool base_source = false );
70
71     /** Construct source of a given type.
72      * \throw EXCEPTION on fail
73     */
74     Source_Ref createFrom( const std::string & type,  const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, bool base_source, tribool auto_refresh );
75
76     protected:
77     template<class _SourceImpl>
78         Source_Ref createSourceImplWorkflow( media::MediaId id, const source::SourceInfo &context );
79   private:
80     /** Implementation  */
81     class Impl;
82     /** Pointer to implementation */
83     RW_pointer<Impl> _pimpl;
84
85   public:
86    struct ProductEntry {
87       Pathname    _dir;
88       std::string _name;
89       ProductEntry( const Pathname & dir_r = "/", const std::string & name_r = std::string() ){
90         _dir  = dir_r;
91         _name = name_r;
92       }
93       bool operator<( const ProductEntry & rhs ) const {
94         return( _dir.asString() < rhs._dir.asString() );
95       }
96     };
97
98     typedef std::set<ProductEntry> ProductSet;
99
100     /** Check which products are available on the media
101      * \throw Exception or MediaException on fail
102      */
103     void listProducts( const Url & url_r, ProductSet & products_r );
104   private:
105 //     bool probeSource( const std::string name, boost::function<bool()> prober, callback::SendReport<CreateSourceReport> &report );
106     void scanProductsFile( const Pathname & file_r, ProductSet & pset_r ) const;
107   };
108   ///////////////////////////////////////////////////////////////////
109
110   /** \relates SourceFactory Stream output */
111   extern std::ostream & operator<<( std::ostream & str, const SourceFactory & obj );
112
113   /////////////////////////////////////////////////////////////////
114 } // namespace zypp
115 ///////////////////////////////////////////////////////////////////
116 #endif // ZYPP_SOURCEFACTORY_H