|
1 /* |
|
2 * Copyright (c) 2006-2009 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 which actually performs the re-harvesting of the files* |
|
15 */ |
|
16 |
|
17 #include "reharvesterao.h" |
|
18 #include "harvesterlog.h" |
|
19 #include "mdeobject.h" |
|
20 #include "mdsutils.h" |
|
21 |
|
22 const TInt KResumeTime = 2000000; //microseconds |
|
23 const TInt KTimeIncrease = 500000; //microseconds |
|
24 const TInt KTimeLimit = 30000000; //microseconds |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // NewLC |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CReHarvesterAO* CReHarvesterAO::NewLC() |
|
31 { |
|
32 WRITELOG( "CReHarvesterAO::NewLC() - begin" ); |
|
33 |
|
34 CReHarvesterAO* self = new (ELeave) CReHarvesterAO(); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(); |
|
37 return self; |
|
38 } |
|
39 // --------------------------------------------------------------------------- |
|
40 // NewL |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CReHarvesterAO* CReHarvesterAO::NewL() |
|
44 { |
|
45 WRITELOG( "CReHarvesterAO::NewL() - begin" ); |
|
46 |
|
47 CReHarvesterAO* self = CReHarvesterAO::NewLC(); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CReHarvesterAO |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CReHarvesterAO::CReHarvesterAO() : CActive( CActive::EPriorityStandard ), |
|
57 iQueue( NULL ), iDelay( KResumeTime ) |
|
58 { |
|
59 WRITELOG( "CReHarvesterAO::CReHarvesterAO()" ); |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // ~CReHarvesterAO |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CReHarvesterAO::~CReHarvesterAO() |
|
67 { |
|
68 WRITELOG( "CReHarvesterAO::~CReHarvesterAO()" ); |
|
69 |
|
70 Cancel(); |
|
71 iItems.ResetAndDestroy(); |
|
72 iItems.Close(); |
|
73 iTimer.Close(); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // ConstructL |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void CReHarvesterAO::ConstructL() |
|
81 { |
|
82 WRITELOG( "CReHarvesterAO::ConstructL()" ); |
|
83 |
|
84 CActiveScheduler::Add( this ); |
|
85 iTimer.CreateLocal(); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // RunL |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void CReHarvesterAO::RunL() |
|
93 { |
|
94 WRITELOG( "ATTENTION!!! CReHarvesterAO::RunL" ); |
|
95 User::LeaveIfError( iStatus.Int() ); |
|
96 if ( iItems.Count() > 0 ) |
|
97 { |
|
98 while( iItems.Count() > 0 ) |
|
99 { |
|
100 CHarvesterData* item = iItems[0]; |
|
101 iQueue->MonitorEvent( item ); |
|
102 iItems.Remove( 0 ); |
|
103 } |
|
104 |
|
105 iItems.Compress(); |
|
106 |
|
107 iDelay += KTimeIncrease; |
|
108 if( iDelay > KTimeLimit ) |
|
109 { |
|
110 iDelay = KResumeTime; |
|
111 } |
|
112 |
|
113 const TTimeIntervalMicroSeconds32 delay = TTimeIntervalMicroSeconds32( iDelay ); |
|
114 iTimer.After( iStatus, delay ); |
|
115 SetActive(); |
|
116 } |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // DoCancel |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 void CReHarvesterAO::DoCancel() |
|
124 { |
|
125 WRITELOG( "CReHarvesterAO::DoCancel()" ); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // RunError |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CReHarvesterAO::RunError( TInt aError ) |
|
133 { |
|
134 if (aError != KErrNone) |
|
135 { |
|
136 WRITELOG1( "CReHarvesterAO::RunError - error: %d", aError ); |
|
137 } |
|
138 return KErrNone; |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // SetHarvesterQueue |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 void CReHarvesterAO::SetHarvesterQueue( CHarvesterQueue* aQueue ) |
|
146 { |
|
147 WRITELOG( "CReHarvesterAO::SetHarvesterQueue()" ); |
|
148 iQueue = aQueue; |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // AddItem |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 void CReHarvesterAO::AddItem( CHarvesterData* aItem ) |
|
156 { |
|
157 WRITELOG( "CReHarvesterAO::AddItem()" ); |
|
158 aItem->SetErrorCode( KErrNone ); |
|
159 // check if already exists |
|
160 for( TInt i = iItems.Count(); --i >= 0; ) |
|
161 { |
|
162 if ( MdsUtils::Compare( iItems[i]->Uri(), aItem->Uri() ) == 0 ) |
|
163 { |
|
164 #ifdef _DEBUG |
|
165 WRITELOG1("CReHarvesterAO::AddItem() - %S already exists in re-harvester queue", &aItem->Uri() ); |
|
166 #endif |
|
167 delete aItem; |
|
168 return; |
|
169 } |
|
170 } |
|
171 |
|
172 CMdEObject* mdeObject = &aItem->MdeObject(); |
|
173 if( mdeObject ) |
|
174 { |
|
175 delete mdeObject; |
|
176 aItem->SetMdeObject( NULL ); |
|
177 } |
|
178 |
|
179 iItems.Append( aItem ); |
|
180 |
|
181 iDelay = KResumeTime; |
|
182 const TTimeIntervalMicroSeconds32 delay = TTimeIntervalMicroSeconds32( iDelay ); |
|
183 |
|
184 if ( !IsActive() ) |
|
185 { |
|
186 iTimer.After( iStatus, delay ); |
|
187 SetActive(); |
|
188 } |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // CheckItem |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CReHarvesterAO::CheckItem( CHarvesterData& aItem ) |
|
196 { |
|
197 WRITELOG( "CReHarvesterAO::CheckItem()" ); |
|
198 |
|
199 for( TInt i = iItems.Count(); --i >= 0; ) |
|
200 { |
|
201 CHarvesterData* item = iItems[i]; |
|
202 if ( aItem.Uri().CompareC( item->Uri(), 1, NULL ) != 0 ) |
|
203 { |
|
204 continue; |
|
205 } |
|
206 // found matching item |
|
207 iItems.Remove( i ); |
|
208 delete item; |
|
209 } |
|
210 |
|
211 if ( iItems.Count() == 0 ) |
|
212 { |
|
213 WRITELOG( "CReHarvesterAO::CheckItem() - item count 0" ); |
|
214 |
|
215 iItems.Compress(); |
|
216 |
|
217 Cancel(); |
|
218 iTimer.Cancel(); |
|
219 } |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // ItemsInQueue |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 TInt CReHarvesterAO::ItemsInQueue() |
|
227 { |
|
228 return iItems.Count(); |
|
229 } |