Imported Upstream version 16.3.2
[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/ZYppCallbacks.h"
18 #include "zypp/Package.h"
19 #include "zypp/ManagedFile.h"
20 #include "zypp/repo/DeltaCandidates.h"
21 #include "zypp/repo/RepoProvideFile.h"
22
23 ///////////////////////////////////////////////////////////////////
24 namespace zypp
25 {
26   ///////////////////////////////////////////////////////////////////
27   namespace repo
28   {
29
30     ///////////////////////////////////////////////////////////////////
31     /// \class PackageProviderPolicy
32     /// \brief Policies and options for \ref PackageProvider
33     ///////////////////////////////////////////////////////////////////
34     class PackageProviderPolicy
35     {
36     public:
37       /** Get installed Editions callback signature. */
38       typedef function<bool ( const std::string &, const Edition &, const Arch & )> QueryInstalledCB;
39
40       /** Set callback. */
41       PackageProviderPolicy & queryInstalledCB( QueryInstalledCB queryInstalledCB_r )
42       { _queryInstalledCB = queryInstalledCB_r; return *this; }
43
44       /** Evaluate callback. */
45       bool queryInstalled( const std::string & name_r,
46                            const Edition &     ed_r,
47                            const Arch &        arch_r ) const;
48
49     private:
50       QueryInstalledCB _queryInstalledCB;
51     };
52     ///////////////////////////////////////////////////////////////////
53
54     ///////////////////////////////////////////////////////////////////
55     /// \class PackageProvider
56     /// \brief Provide a package from a Repo.
57     ///
58     /// Use available deltarpm if apropriate.
59     ///////////////////////////////////////////////////////////////////
60     class PackageProvider
61     {
62     public:
63       /** Ctor taking the Package to provide. */
64       PackageProvider( RepoMediaAccess & access,
65                        const Package::constPtr & package,
66                        const DeltaCandidates & deltas,
67                        const PackageProviderPolicy & policy_r = PackageProviderPolicy() );
68       ~PackageProvider();
69
70     public:
71       /** Provide the package.
72        * \throws Exception.
73        */
74       ManagedFile providePackage() const;
75
76       /** Provide the package if it is cached. */
77       ManagedFile providePackageFromCache() const;
78
79       /** Whether the package is cached. */
80       bool isCached() const;
81
82     public:
83       class Impl;              ///< Implementation class.
84     private:
85       RW_pointer<Impl> _pimpl; ///< Pointer to implementation.
86     };
87     ///////////////////////////////////////////////////////////////////
88
89   } // namespace repo
90   ///////////////////////////////////////////////////////////////////
91 } // namespace zypp
92 ///////////////////////////////////////////////////////////////////
93 #endif // ZYPP_SOURCE_PACKAGEPROVIDER_H