Imported Upstream version 17.0.0
[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        * \throws Exception If pi_r refers to neither a \c Package nor a \c SrcPackage.
65        */
66       PackageProvider( RepoMediaAccess & access, const PoolItem & pi_r,
67                        const PackageProviderPolicy & policy_r = PackageProviderPolicy() );
68
69       /** \overload Ctor taking additional hint to deltarpms (not used for SrcPackages)
70        * \throws Exception If pi_r refers to neither a \c Package nor a \c SrcPackage.
71        */
72       PackageProvider( RepoMediaAccess & access, const PoolItem & pi_r,
73                        const DeltaCandidates & deltas,
74                        const PackageProviderPolicy & policy_r = PackageProviderPolicy() );
75
76       /** Legacy Ctor taking a \c Package::constPtr to provide. */
77       PackageProvider( RepoMediaAccess & access,
78                        const Package::constPtr & package,
79                        const DeltaCandidates & deltas,
80                        const PackageProviderPolicy & policy_r = PackageProviderPolicy() );
81
82       ~PackageProvider();
83
84     public:
85       /** Provide the package.
86        * \throws Exception.
87        */
88       ManagedFile providePackage() const;
89
90       /** Provide the package if it is cached. */
91       ManagedFile providePackageFromCache() const;
92
93       /** Whether the package is cached. */
94       bool isCached() const;
95
96     public:
97       class Impl;              ///< Implementation class.
98     private:
99       RW_pointer<Impl> _pimpl; ///< Pointer to implementation.
100     };
101     ///////////////////////////////////////////////////////////////////
102
103   } // namespace repo
104   ///////////////////////////////////////////////////////////////////
105 } // namespace zypp
106 ///////////////////////////////////////////////////////////////////
107 #endif // ZYPP_SOURCE_PACKAGEPROVIDER_H