|
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: Harvester server harvesting queue* |
|
15 */ |
|
16 |
|
17 |
|
18 #include "harvesterqueue.h" |
|
19 #include "harvesterao.h" |
|
20 #include "harvesterlog.h" |
|
21 #include "harvesterblacklist.h" |
|
22 #include "mdsutils.h" |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // NewL |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CHarvesterQueue* CHarvesterQueue::NewL( CHarvesterAO* aHarvesterAO, |
|
29 CHarvesterBlacklist* aBlacklist ) |
|
30 { |
|
31 WRITELOG( "CHarvesterQueue::NewL()" ); |
|
32 |
|
33 CHarvesterQueue* self = CHarvesterQueue::NewLC( aHarvesterAO, aBlacklist ); |
|
34 CleanupStack::Pop( self ); |
|
35 return self; |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // NewLC |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CHarvesterQueue* CHarvesterQueue::NewLC( CHarvesterAO* aHarvesterAO, |
|
43 CHarvesterBlacklist* aBlacklist ) |
|
44 { |
|
45 WRITELOG( "CHarvesterQueue::NewLC()" ); |
|
46 |
|
47 CHarvesterQueue* self = new ( ELeave ) CHarvesterQueue( |
|
48 aHarvesterAO, aBlacklist ); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CHarvesterQueue |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CHarvesterQueue::CHarvesterQueue( CHarvesterAO* aHarvesterAO, |
|
59 CHarvesterBlacklist* aBlacklist ) : iMediaIdUtil( NULL ) |
|
60 { |
|
61 WRITELOG( "CHarvesterQueue::CHarvesterQueue()" ); |
|
62 iHarvesterAO = aHarvesterAO; |
|
63 iBlacklist = aBlacklist; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // ~CHarvesterQueue |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CHarvesterQueue::~CHarvesterQueue() |
|
71 { |
|
72 WRITELOG( "CHarvesterQueue::CHarvesterQueue()" ); |
|
73 iItemQueue.ResetAndDestroy(); |
|
74 iItemQueue.Close(); |
|
75 iFs.Close(); |
|
76 RMediaIdUtil::ReleaseInstance(); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // ConstructL |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CHarvesterQueue::ConstructL() |
|
84 { |
|
85 WRITELOG( "CHarvesterQueue::ConstructL()" ); |
|
86 User::LeaveIfError( iFs.Connect() ); |
|
87 iMediaIdUtil = &RMediaIdUtil::GetInstanceL(); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // ItemsInQueue |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 TInt CHarvesterQueue::ItemsInQueue() |
|
95 { |
|
96 WRITELOG( "CHarvesterQueue::ItemsInQueue()" ); |
|
97 |
|
98 return iItemQueue.Count(); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // GetNextItem |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 CHarvesterData* CHarvesterQueue::GetNextItem() |
|
106 { |
|
107 WRITELOG( "CHarvesterQueue::GetNextItem()" ); |
|
108 CHarvesterData* item = NULL; |
|
109 |
|
110 if ( iItemQueue.Count() > 0 ) |
|
111 { |
|
112 #ifdef _DEBUG |
|
113 WRITELOG1( "Harvester queue items = %d", iItemQueue.Count() ); |
|
114 #endif |
|
115 item = iItemQueue[0]; |
|
116 iItemQueue.Remove( 0 ); |
|
117 } |
|
118 else |
|
119 { |
|
120 WRITELOG( "Harvester queue items zero!" ); |
|
121 iItemQueue.Compress(); |
|
122 } |
|
123 |
|
124 WRITELOG( "CHarvesterQueue::GetNextItem, end" ); |
|
125 return item; |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // Append |
|
130 // Files are checked against blacklist and blacklisted files |
|
131 // will not be appended. |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 void CHarvesterQueue::Append( CHarvesterData* aItem ) |
|
135 { |
|
136 WRITELOG( "CHarvesterQueue::Append()" ); |
|
137 TInt err = KErrNone; |
|
138 |
|
139 if ( iBlacklist ) |
|
140 { |
|
141 TUint32 mediaId( 0 ); |
|
142 err = iMediaIdUtil->GetMediaId( aItem->Uri(), mediaId ); |
|
143 |
|
144 TTime time( 0 ); |
|
145 if ( err == KErrNone && iBlacklist->IsBlacklisted( |
|
146 aItem->Uri(), mediaId, time ) ) |
|
147 { |
|
148 WRITELOG( "CHarvesterQueue::Append() - found a blacklisted file" ); |
|
149 delete aItem; |
|
150 aItem = NULL; |
|
151 err = KErrCorrupt; |
|
152 } |
|
153 } |
|
154 |
|
155 if ( err != KErrCorrupt ) |
|
156 { |
|
157 // check if fast harvest file and add to start of queue |
|
158 if ( aItem->ObjectType() == EFastHarvest || aItem->Origin() == MdeConstants::Object::ECamera ) |
|
159 { |
|
160 err = iItemQueue.Insert( aItem, 0 ); |
|
161 } |
|
162 else |
|
163 { |
|
164 err = iItemQueue.Append( aItem ); |
|
165 } |
|
166 |
|
167 if( err != KErrNone ) |
|
168 { |
|
169 delete aItem; |
|
170 aItem = NULL; |
|
171 } |
|
172 } |
|
173 |
|
174 if ( err != KErrNone ) |
|
175 { |
|
176 WRITELOG1( "CHarvesterQueue::Append() - error: %d", err ); |
|
177 delete aItem; |
|
178 } |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // RemoveItems |
|
183 // Remove items from the queue based on them mediaid. |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 TUint CHarvesterQueue::RemoveItems( TUint32 aMediaId ) |
|
187 { |
|
188 #ifdef _DEBUG |
|
189 WRITELOG1( "CHarvesterQueue::RemoveItems( %d )", aMediaId); |
|
190 |
|
191 WRITELOG1( "CHarvesterQueue::RemoveItems() iItemQueue.Count() == %d", iItemQueue.Count()); |
|
192 #endif |
|
193 |
|
194 TUint removedCount(0); |
|
195 TInt err(KErrNone); |
|
196 TUint32 mediaId( 0 ); |
|
197 CHarvesterData* hd = NULL; |
|
198 |
|
199 for(TInt i = iItemQueue.Count() - 1; i >=0; i--) |
|
200 { |
|
201 hd = iItemQueue[i]; |
|
202 err = iMediaIdUtil->GetMediaId( hd->Uri(), mediaId ); |
|
203 |
|
204 if( err == KErrNone) |
|
205 { |
|
206 if( mediaId == aMediaId) |
|
207 { |
|
208 delete hd; |
|
209 hd = NULL; |
|
210 iItemQueue.Remove( i ); |
|
211 removedCount++; |
|
212 } |
|
213 else |
|
214 { |
|
215 WRITELOG2( "CHarvesterQueue::RemoveItems( ) %d != %d", mediaId, aMediaId); |
|
216 } |
|
217 } |
|
218 else |
|
219 { |
|
220 WRITELOG1( "CHarvesterQueue::RemoveItems( ) GetMediaId err == %d", err); |
|
221 } |
|
222 } |
|
223 iItemQueue.Compress(); |
|
224 #ifdef _DEBUG |
|
225 WRITELOG2( "CHarvesterQueue::RemoveItems() iItemQueue.Count() = %d, removedCount = %d", iItemQueue.Count(), removedCount); |
|
226 #endif |
|
227 return removedCount; |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // MonitorEvent |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void CHarvesterQueue::MonitorEvent( CHarvesterData* aHarvesterData ) |
|
235 { |
|
236 Append( aHarvesterData ); |
|
237 |
|
238 // signal to start harvest if harvester idles |
|
239 if ( !iHarvesterAO->IsServerPaused() ) |
|
240 { |
|
241 iHarvesterAO->SetNextRequest( CHarvesterAO::ERequestHarvest ); |
|
242 } |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // MonitorEvent |
|
247 // --------------------------------------------------------------------------- |
|
248 // |
|
249 void CHarvesterQueue::MonitorEvent( |
|
250 RPointerArray<CHarvesterData>& aHarvesterDataArray ) |
|
251 { |
|
252 for( TInt i = aHarvesterDataArray.Count(); --i >= 0; ) |
|
253 { |
|
254 MonitorEvent( aHarvesterDataArray[i] ); |
|
255 } |
|
256 |
|
257 // "clear" array after ownership of items |
|
258 // was changed for MonitorEvent-method |
|
259 aHarvesterDataArray.Reset(); |
|
260 } |
|
261 |