Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / parser / RepoindexFileReader.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/RepoindexFileReader.h
10  * Interface of repoindex.xml file reader.
11  */
12 #ifndef zypp_source_yum_RepoindexFileReader_H
13 #define zypp_source_yum_RepoindexFileReader_H
14
15 #include "zypp/base/PtrTypes.h"
16 #include "zypp/base/NonCopyable.h"
17 #include "zypp/base/Function.h"
18 #include "zypp/base/InputStream.h"
19 #include "zypp/Pathname.h"
20 #include "zypp/Date.h"
21
22 namespace zypp
23 {
24   class RepoInfo;
25
26   namespace parser
27   {
28
29   /**
30    * Reads through a repoindex.xml file and collects repositories.
31    *
32    * After each repository is read, a \ref RepoInfo
33    * is prepared and \ref _callback
34    * is called with this object passed in.
35    *
36    * The \ref _callback is provided on construction.
37    *
38    *
39    * \code
40    * RepoindexFileReader reader(repoindex_file,
41    *                  bind( &SomeClass::callbackfunc, &SomeClassInstance, _1) );
42    * \endcode
43    */
44   class RepoindexFileReader : private base::NonCopyable
45   {
46   public:
47    /**
48     * Callback definition.
49     * First parameter is a \ref RepoInfo object with the resource
50     * FIXME return value is ignored
51     */
52     typedef function< bool( const RepoInfo & )> ProcessResource;
53
54    /**
55     * CTOR. Creates also \ref xml::Reader and starts reading.
56     *
57     * \param repoindexFile is the repoindex.xml file you want to read
58     * \param callback is a function.
59     *
60     * \see RepoindexFileReader::ProcessResource
61     */
62     RepoindexFileReader( const zypp::Pathname & repoindexFile,
63                          const ProcessResource & callback);
64
65     /**
66      * \short Constructor. Creates the reader and start reading.
67      *
68      * \param is a valid input stream
69      * \param callback Callback that will be called for each repository.
70      *
71      * \see RepoindexFileReader::ProcessResource
72      */
73      RepoindexFileReader( const InputStream &is,
74                           const ProcessResource & callback );
75
76     /**
77      * DTOR
78      */
79     ~RepoindexFileReader();
80
81     /** Metadata TTL (repoindex.xml:xpath:/repoindex@ttl or 0). */
82     Date::Duration ttl() const;
83
84   private:
85     class Impl;
86     RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
87   };
88
89
90   } // ns parser
91 } // ns zypp
92
93 #endif /*zypp_source_yum_RepoindexFileReader_H*/
94
95 // vim: set ts=2 sts=2 sw=2 et ai: