merge REFACTORING-10_3 back to trunk
[platform/upstream/libzypp.git] / zypp / repo / PackageProvider.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/repo/PackageProvider.h
10  *
11 */
12 #ifndef ZYPP_REPO_PACKAGEPROVIDER_H
13 #define ZYPP_REPO_PACKAGEPROVIDER_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/NonCopyable.h"
18
19 #include "zypp/ZYppCallbacks.h"
20 #include "zypp/Repository.h"
21 #include "zypp/Package.h"
22 #include "zypp/ManagedFile.h"
23
24 #include "zypp/repo/DeltaCandidates.h"
25
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29   ///////////////////////////////////////////////////////////////////
30   namespace repo
31   { /////////////////////////////////////////////////////////////////
32
33     ///////////////////////////////////////////////////////////////////
34     //
35     //  CLASS NAME : PackageProviderPolicy
36     //
37     /** */
38     class PackageProviderPolicy
39     {
40     public:
41       /** Get installed Editions callback signature. */
42       typedef function<bool ( const std::string &, const Edition &, const Arch & )> QueryInstalledCB;
43
44       /** Set callback. */
45       PackageProviderPolicy & queryInstalledCB( QueryInstalledCB queryInstalledCB_r )
46       { _queryInstalledCB = queryInstalledCB_r; return *this; }
47
48       /** Evaluate callback. */
49       bool queryInstalled( const std::string & name_r,
50                            const Edition &     ed_r,
51                            const Arch &        arch_r ) const;
52
53     private:
54       QueryInstalledCB _queryInstalledCB;
55     };
56     ///////////////////////////////////////////////////////////////////
57
58     ///////////////////////////////////////////////////////////////////
59     //
60     //  CLASS NAME : PackageProvider
61     //
62     /** Provide a package from a Source.
63      * Use available delta/patch-rpm if apropriate.
64     */
65     class PackageProvider : private base::NonCopyable
66     {
67       typedef shared_ptr<void>                                       ScopedGuard;
68       typedef callback::SendReport<repo::DownloadResolvableReport> Report;
69
70       typedef detail::ResImplTraits<Package::Impl>::constPtr PackageImpl_constPtr;
71       typedef packagedelta::DeltaRpm                         DeltaRpm;
72       typedef packagedelta::PatchRpm                         PatchRpm;
73
74
75     public:
76       /** Ctor taking the Package to provide. */
77       PackageProvider( const Package::constPtr & package,
78                        const DeltaCandidates & deltas,
79                        const PackageProviderPolicy & policy_r = PackageProviderPolicy() );
80       ~PackageProvider();
81
82     public:
83       /** Provide the package.
84        * \throws Exception.
85       */
86       ManagedFile providePackage() const;
87
88     private:
89       ManagedFile doProvidePackage() const;
90       ManagedFile tryDelta( const DeltaRpm & delta_r ) const;
91       ManagedFile tryPatch( const PatchRpm & patch_r ) const;
92
93     private:
94       ScopedGuard newReport() const;
95       Report & report() const;
96       bool progressDeltaDownload( int value ) const;
97       void progressDeltaApply( int value ) const;
98       bool progressPatchDownload( int value ) const;
99       bool progressPackageDownload( int value ) const;
100       bool failOnChecksumError() const;
101       bool queryInstalled( const Edition & ed_r = Edition() ) const;
102
103     private:
104       PackageProviderPolicy      _policy;
105       Package::constPtr          _package;
106       PackageImpl_constPtr       _implPtr;
107       mutable bool               _retry;
108       mutable shared_ptr<Report> _report;
109       DeltaCandidates _deltas;
110     };
111     ///////////////////////////////////////////////////////////////////
112
113     /////////////////////////////////////////////////////////////////
114   } // namespace repo
115   ///////////////////////////////////////////////////////////////////
116   /////////////////////////////////////////////////////////////////
117 } // namespace zypp
118 ///////////////////////////////////////////////////////////////////
119 #endif // ZYPP_SOURCE_PACKAGEPROVIDER_H