|
1 /* |
|
2 * Copyright (c) 2007 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: Active object to cleanup broken links |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <mpxlog.h> |
|
21 #include <badesca.h> |
|
22 |
|
23 #include "mpxfilescanstateobserver.h" |
|
24 #include "mpxbrokenlinkcleanupobserver.h" |
|
25 #include "mpxbrokenlinkcleanup.h" |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KDeleteGranularity = 10; |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // Constructor |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CMPXBrokenLinkCleanup::CMPXBrokenLinkCleanup( MMPXFileScanStateObserver& aObserver, |
|
37 MMPXBrokenLinkObserver& aBrokenLinkObserver ) |
|
38 : CActive( EPriorityNull ), |
|
39 iStateObserver( aObserver ), |
|
40 iBrokenLinkObserver( aBrokenLinkObserver ) |
|
41 { |
|
42 CActiveScheduler::Add( this ); |
|
43 } |
|
44 |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // 2nd Phase Constructor |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 void CMPXBrokenLinkCleanup::ConstructL() |
|
51 { |
|
52 iBrokenLinks = new(ELeave) CDesCArrayFlat(2); // magic |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // Two-Phased Constructor |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CMPXBrokenLinkCleanup* CMPXBrokenLinkCleanup::NewL( MMPXFileScanStateObserver& aObserver, |
|
60 MMPXBrokenLinkObserver& aBrokenLinkObserver ) |
|
61 { |
|
62 CMPXBrokenLinkCleanup* self = new( ELeave ) CMPXBrokenLinkCleanup( aObserver, |
|
63 aBrokenLinkObserver ); |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 CleanupStack::Pop( self ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Virtual destructor |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CMPXBrokenLinkCleanup::~CMPXBrokenLinkCleanup() |
|
76 { |
|
77 Cancel(); |
|
78 Reset(); |
|
79 delete iBrokenLinks; |
|
80 iColIds.Close(); |
|
81 iDBRefs.Close(); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // Start the broken link cleanup |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void CMPXBrokenLinkCleanup::Start() |
|
89 { |
|
90 MPX_DEBUG1("CMPXBrokenLinkCleanup::Start <---"); |
|
91 |
|
92 // If this isn't already running |
|
93 // |
|
94 if( !IsActive() ) |
|
95 { |
|
96 iCleaningUp = ETrue; |
|
97 |
|
98 // Set Active |
|
99 iStatus = KRequestPending; |
|
100 SetActive(); |
|
101 TRequestStatus* status = &iStatus; |
|
102 User::RequestComplete( status, KErrNone ); |
|
103 MPX_DEBUG1("CMPXBrokenLinkCleanup::Started"); |
|
104 } |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // Reset this object's state |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CMPXBrokenLinkCleanup::Reset() |
|
112 { |
|
113 iBrokenLinks->Reset(); |
|
114 iColIds.Reset(); |
|
115 iDBRefs.Reset(); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // Adds a broken link for cleanup |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CMPXBrokenLinkCleanup::AddBrokenLinkL( const TDesC& aFile, |
|
123 TInt aColId, |
|
124 CMPXHarvesterDB* aDb ) |
|
125 { |
|
126 iBrokenLinks->AppendL( aFile ); |
|
127 iColIds.AppendL( aColId ); |
|
128 iDBRefs.AppendL( aDb ); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // From CActive |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void CMPXBrokenLinkCleanup::DoCancel() |
|
136 { |
|
137 if( iCleaningUp ) |
|
138 { |
|
139 MPX_DEBUG1("CMPXBrokenLinkCleanup::DoCancel <---"); |
|
140 // Callback to observer |
|
141 Reset(); |
|
142 TRAP_IGNORE( iStateObserver.HandleScanStateCompleteL( MMPXFileScanStateObserver::ECleanupBrokenLink, |
|
143 KErrCancel ) ); |
|
144 iCleaningUp = EFalse; |
|
145 } |
|
146 } |
|
147 |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // From CActive |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void CMPXBrokenLinkCleanup::RunL() |
|
154 { |
|
155 TBool done(EFalse); |
|
156 TRAPD( err, done = DoBrokenLinkL() ); |
|
157 if( KErrNone != err || done ) |
|
158 { |
|
159 // Callback to observer |
|
160 MPX_DEBUG1("CMPXBrokenLinkCleanup::RunL -- Done"); |
|
161 TRAP_IGNORE( iStateObserver.HandleScanStateCompleteL( MMPXFileScanStateObserver::ECleanupBrokenLink, |
|
162 err ) ); |
|
163 iCleaningUp = EFalse; |
|
164 } |
|
165 else |
|
166 { |
|
167 MPX_DEBUG1("CMPXBrokenLinkCleanup::RunL -- Run again"); |
|
168 iStatus = KRequestPending; |
|
169 SetActive(); |
|
170 TRequestStatus* status = &iStatus; |
|
171 User::RequestComplete( status, KErrNone ); |
|
172 } |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // From CActive |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 TInt CMPXBrokenLinkCleanup::RunError(TInt aError) |
|
180 { |
|
181 MPX_DEBUG1("CMPXBrokenLinkCleanup::RunError <---"); |
|
182 Reset(); |
|
183 TRAP_IGNORE( iStateObserver.HandleScanStateCompleteL( MMPXFileScanStateObserver::ECleanupBrokenLink, |
|
184 aError ) ); |
|
185 iCleaningUp = EFalse; |
|
186 return KErrNone; |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // Perform one iteration of the broken link check |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 TBool CMPXBrokenLinkCleanup::DoBrokenLinkL() |
|
194 { |
|
195 MPX_DEBUG1("CMPXBrokenLinkCleanup::DoBrokenLinkL <---"); |
|
196 TBool done(EFalse); |
|
197 |
|
198 // Call back to observer to perform the cleanup |
|
199 TInt count(iBrokenLinks->Count()); |
|
200 iBrokenLinkObserver.HandleBrokenLinkL( *iBrokenLinks, |
|
201 iColIds, |
|
202 iDBRefs, |
|
203 count<KDeleteGranularity?count:KDeleteGranularity ); |
|
204 |
|
205 // Loop through and remove KDeleteGranularity elements |
|
206 // from the broken links array |
|
207 // |
|
208 for( TInt i=0; i<KDeleteGranularity; ++i ) |
|
209 { |
|
210 // No more to delete |
|
211 if( count == 0 ) |
|
212 { |
|
213 done = ETrue; |
|
214 break; |
|
215 } |
|
216 |
|
217 iBrokenLinks->Delete(0); |
|
218 count--; |
|
219 } |
|
220 MPX_DEBUG1("CMPXBrokenLinkCleanup::DoBrokenLinkL --->"); |
|
221 return done; |
|
222 } |
|
223 // END OF FILE |