d57d048d3d6744b508722241d18f858537a2b52f
[platform/upstream/libzypp.git] / zypp / ProvideFilePolicy.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9
10 #ifndef ZYPP_PROVIDEFILEPOLICY_H
11 #define ZYPP_PROVIDEFILEPOLICY_H
12
13 #include <iosfwd>
14
15 #include "zypp/base/Function.h"
16 #include "zypp/base/Functional.h"
17
18 ///////////////////////////////////////////////////////////////////
19 namespace zypp
20 { /////////////////////////////////////////////////////////////////
21 ///////////////////////////////////////////////////////////////////
22 // CLASS NAME : ProvideFilePolicy
23   
24   /** Policy for \ref provideFile.
25     * Provides callback hooks for e.g progress reporting or
26     * behaviour on checksum failure. Provides default
27     * implementations if no callback is set.
28     */
29   class ProvideFilePolicy
30   {
31   public:
32     /** Progress callback signature. */
33     typedef function<bool ( int )> ProgressCB;
34
35     /** Set callback. */
36     ProvideFilePolicy & progressCB( ProgressCB progressCB_r )
37     { _progressCB = progressCB_r; return *this; }
38
39     /** Evaluate callback. */
40     bool progress( int value ) const;
41
42   public:
43     /** FailOnChecksumError callback signature. */
44     typedef function<bool ()> FailOnChecksumErrorCB;
45
46     /** Set callback. */
47     ProvideFilePolicy & failOnChecksumErrorCB( FailOnChecksumErrorCB failOnChecksumErrorCB_r )
48     { _failOnChecksumErrorCB = failOnChecksumErrorCB_r; return *this; }
49
50     /** Set callback convenience.
51       * Let callback return \c yesno_r.
52     */
53     ProvideFilePolicy & failOnChecksumErrorCB( bool yesno_r );
54
55     /** Evaluate callback. */
56     bool failOnChecksumError() const;
57
58   private:
59     FailOnChecksumErrorCB _failOnChecksumErrorCB;
60     ProgressCB            _progressCB;
61   };
62
63 } // namespace zypp
64 ///////////////////////////////////////////////////////////////////
65 #endif // ZYPP_PROVIDEFILEPOLICY_H