1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef DBACCESS_PROGRESSMIXER_HXX
25 #define DBACCESS_PROGRESSMIXER_HXX
26 
27 /** === begin UNO includes === **/
28 /** === end UNO includes === **/
29 
30 #include <sal/types.h>
31 
32 #include <memory>
33 
34 //........................................................................
35 namespace dbmm
36 {
37 //........................................................................
38 
39     typedef sal_uInt32  PhaseID;
40     typedef sal_uInt32  PhaseWeight;
41 
42 	//====================================================================
43 	//= IProgressConsumer
44 	//====================================================================
45     class SAL_NO_VTABLE IProgressConsumer
46     {
47     public:
48         virtual void    start( sal_uInt32 _nRange ) = 0;
49         virtual void    advance( sal_uInt32 _nValue ) = 0;
50         virtual void    end() = 0;
51     };
52 
53     //====================================================================
54 	//= ProgressMixer
55 	//====================================================================
56     struct ProgressMixer_Data;
57     /** a class which mixes (i.e. concatenates) progress values from different
58         sources/phases, with different weight
59     */
60 	class ProgressMixer
61 	{
62     public:
63         ProgressMixer( IProgressConsumer& _rConsumer );
64         ~ProgressMixer();
65 
66         /** registers a phase of the process, which has the given weight
67             in the overall process
68             @precond
69                 the progress is not runnig, yet
70         */
71         void    registerPhase( const PhaseID _nID, const PhaseWeight _nWeight );
72 
73         /** enters the phase with the given ID, with the phase having
74             the given overall range
75         */
76         void    startPhase( const PhaseID _nID, const sal_uInt32 _nPhaseRange );
77 
78         /** announces a new progress in the current phase.
79 
80             The given phase progress must be between 0 and the overall phase range
81             as specified in ->startPhase.
82         */
83         void    advancePhase( const sal_uInt32 _nPhaseProgress );
84 
85         /** leaves the current phase, which has been started with ->startPhase previously
86         */
87         void    endPhase();
88 
89     private:
90         ::std::auto_ptr< ProgressMixer_Data >   m_pData;
91 	};
92 
93 //........................................................................
94 } // namespace dbmm
95 //........................................................................
96 
97 #endif // DBACCESS_PROGRESSMIXER_HXX
98