|
1 /* |
|
2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description:A local representation of the operation class assigned for operations that |
|
15 * modifies the database. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CPOSLMLOCALMODIFYOP_H |
|
21 #define CPOSLMLOCALMODIFYOP_H |
|
22 |
|
23 #include <epos_cposlmlocaloperation.h> |
|
24 #include <epos_cposlmcompactdatabase.h> |
|
25 |
|
26 class CPosLmLocalDatabase; |
|
27 |
|
28 /** |
|
29 * A local representation of the operation class assigned for operations that |
|
30 * modifies the database. It provides an interface for operations that are |
|
31 * performed in small synchronous steps. |
|
32 */ |
|
33 NONSHARABLE_CLASS(CPosLmLocalModifyOp) : public CPosLmLocalOperation |
|
34 { |
|
35 |
|
36 public: // Constructors and destructor |
|
37 |
|
38 /** |
|
39 * Destructor. |
|
40 */ |
|
41 virtual ~CPosLmLocalModifyOp(); |
|
42 |
|
43 public: // New functions |
|
44 |
|
45 /** |
|
46 * Performs a step of the operation. Before this is called, this class |
|
47 * has begun a transaction. |
|
48 * |
|
49 * @param[out] aProgress The current progress. |
|
50 */ |
|
51 virtual void DoNextStepPreL( TReal32& aProgress ) = 0; |
|
52 |
|
53 /** |
|
54 * Performs actions after a transaction commit. |
|
55 * |
|
56 * @param[out] aProgress The current progress. |
|
57 * @return The sub class should return ETrue if it wants the base class |
|
58 * to begin a new transaction. EFalse otherwise. |
|
59 */ |
|
60 virtual TBool DoNextStepPostL( TReal32& aProgress ) = 0; |
|
61 |
|
62 /** |
|
63 * Returns the current progress step size. This is the value of how much |
|
64 * the progress increases between each step. |
|
65 * |
|
66 * @return Current step size. |
|
67 */ |
|
68 virtual TReal32 Step() = 0; |
|
69 |
|
70 /** |
|
71 * Panics if the number of sub operations is invalid. |
|
72 * |
|
73 * @param aResourceId A resource id. |
|
74 * @param aNoOfSubOperations A number of sub operations. |
|
75 */ |
|
76 virtual void CheckResourceValue( TInt aResourceId, TInt aNrOfSubOperations ) = 0; |
|
77 |
|
78 public: // From base classes |
|
79 |
|
80 /** |
|
81 * From CPosLmLocalOperation. |
|
82 * |
|
83 * @param[out] aProgress Will be set to the progress of the operation when |
|
84 * the step has finished. |
|
85 * @return @p KPosLmOperationNotComplete if the step has completed but |
|
86 * more steps are needed before the operation has finished, |
|
87 * @p KErrNone if the operation has finished successfully. |
|
88 */ |
|
89 TInt NextStepL( TReal32& aProgress ); |
|
90 |
|
91 protected: |
|
92 |
|
93 /** |
|
94 * C++ default constructor. |
|
95 * |
|
96 * @param[in] aDb A local database. |
|
97 */ |
|
98 CPosLmLocalModifyOp( CPosLmLocalDatabase& aDb ); |
|
99 |
|
100 /** |
|
101 * Symbian 2nd phase constructor. |
|
102 */ |
|
103 void BaseConstructL(); |
|
104 |
|
105 /** |
|
106 * Reads information about number of suboperations for asynchronous |
|
107 * operations from a resource file. |
|
108 * @param aResourceId The id of the resource to read. |
|
109 */ |
|
110 void ReadInfoFromResourceFileL( TInt aResourceId ); |
|
111 |
|
112 /** |
|
113 * The transaction is rolled back if needed. |
|
114 */ |
|
115 void RollbackIfNeeded(); |
|
116 |
|
117 /** |
|
118 * Tells whether in compacting state or not. |
|
119 * @return @p ETrue if in compacting state, @p EFalse otherwise. |
|
120 */ |
|
121 TBool IsInCompactingState(); |
|
122 |
|
123 private: |
|
124 |
|
125 /** |
|
126 * Calculates the progress when a compacting operation is used as a |
|
127 * sub operation to another operation. |
|
128 * |
|
129 * @param aProgressStep The progress step for the operation (i.e. 0.1 if |
|
130 * the operation takes 10 steps). |
|
131 * @param aCompactProgress The current progress of the compact operation. |
|
132 * @return A progress to add to the current operation progress. The |
|
133 * operation progress should be constant during the sub operation. |
|
134 * This means that the operation progress should be saved before |
|
135 * starting the sub operation [i.e. iCurrentProgress = iSavedProgress + |
|
136 * CalculateSubOperationProgress(step, compactProgress)]. |
|
137 */ |
|
138 TReal32 CalculateSubOperationProgress( |
|
139 TReal32 aProgressStep, |
|
140 TReal32 aCompactProgress ); |
|
141 |
|
142 /** |
|
143 * Recalculates the progress if the compacting sub operation should be |
|
144 * performed. |
|
145 * |
|
146 * @param[in,out] aProgress An operation progress. |
|
147 * @param[in] aProgressStep The progress step for the operation (i.e. 0.1 if |
|
148 * the operation takes 10 steps). |
|
149 */ |
|
150 void RecalculateProgressDueToCompact( |
|
151 TReal32& aProgress, |
|
152 TReal32 aProgressStep ); |
|
153 |
|
154 // By default, prohibit copy constructor |
|
155 CPosLmLocalModifyOp( const CPosLmLocalModifyOp& ); |
|
156 // Prohibit assigment operator |
|
157 CPosLmLocalModifyOp& operator= ( const CPosLmLocalModifyOp& ); |
|
158 |
|
159 private: // Data types |
|
160 |
|
161 enum TPosSubOperationState |
|
162 { |
|
163 ECompactSubOperationOn = 0, |
|
164 ECompactSubOperationOff |
|
165 }; |
|
166 |
|
167 protected: // Data |
|
168 |
|
169 // Status flag. Holding the current status. |
|
170 TInt iStatusFlag; |
|
171 |
|
172 // Number of suboperations in each transaction. |
|
173 TInt iNoOfSubOperations; |
|
174 |
|
175 // Whether this operation uses server-side data, |
|
176 // which needs transactions |
|
177 TBool iUsesServerData; |
|
178 |
|
179 private: // Data |
|
180 |
|
181 // Compact sub operation |
|
182 TPosSubOperationState iCompactState; |
|
183 CPosLmCompactDatabase* iCompactSubOp; |
|
184 TReal32 iSavedProgress; |
|
185 }; |
|
186 |
|
187 #endif // CPOSLMLOCALMODIFYOP_H |
|
188 |