|
1 /* |
|
2 * Copyright (c) 2005-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: Manages object search from database* |
|
15 */ |
|
16 |
|
17 #include "mdsfindengine.h" |
|
18 |
|
19 #include "mdcresult.h" |
|
20 #include "mdcitem.h" |
|
21 #include "mdsdbconnectionpool.h" |
|
22 #include "mdsobjectlocklist.h" |
|
23 #include "mdsserversession.h" |
|
24 #include "mdsfindsequence.h" |
|
25 #include "mdslogger.h" |
|
26 #include "mdcserializationbuffer.h" |
|
27 #include "mdsschema.h" |
|
28 #include "mdsserver.h" |
|
29 |
|
30 __USES_LOGGER |
|
31 |
|
32 |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // NewL |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CMdSFindEngine* CMdSFindEngine::NewL( |
|
39 TUint32 aQueryId, |
|
40 CMdSServerSession& aParent, |
|
41 CMdSObjectLockList& aLockList, |
|
42 CMdsSchema& aSchemaNew ) |
|
43 { |
|
44 CMdSFindEngine* self = CMdSFindEngine::NewLC( |
|
45 aQueryId, aParent, aLockList, aSchemaNew ); |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // NewLC |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CMdSFindEngine* CMdSFindEngine::NewLC( |
|
55 TUint32 aQueryId, |
|
56 CMdSServerSession& aParent, |
|
57 CMdSObjectLockList& aLockList, |
|
58 CMdsSchema& aSchemaNew ) |
|
59 { |
|
60 CMdSFindEngine* self = new ( ELeave ) CMdSFindEngine( |
|
61 aQueryId, aParent, aLockList ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL( aSchemaNew ); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // Default constructor |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CMdSFindEngine::CMdSFindEngine( |
|
72 TUint32 aQueryId, |
|
73 CMdSServerSession& aParent, |
|
74 CMdSObjectLockList& aLockList ) |
|
75 : iQueryId( aQueryId ) |
|
76 , iParent( aParent ) |
|
77 , iLockList( aLockList ) |
|
78 , iSequence( NULL ) |
|
79 , iSerializedCriteria( NULL ) |
|
80 , iAsyncPending( EFalse ) |
|
81 { |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // ConstructL |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void CMdSFindEngine::ConstructL( CMdsSchema& aSchema ) |
|
89 { |
|
90 iSequence = CMdSFindSequence::NewL( iParent.GetServer(), aSchema, *this ); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // QueryId |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 TUint32 CMdSFindEngine::QueryId() |
|
98 { |
|
99 return iQueryId; |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // SetFindParams |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 void CMdSFindEngine::SetFindParams( TUint32 aNotifyCount ) |
|
107 { |
|
108 iSequence->SetFindParams( aNotifyCount ); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // SetFindCriteria |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CMdSFindEngine::SetFindCriteria( CMdCSerializationBuffer* aSerializedCriteria ) |
|
116 { |
|
117 iSerializedCriteria = aSerializedCriteria; |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CreateResultSetL |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CMdSFindEngine::CreateResultSet(RMessage2 aMessage) |
|
125 { |
|
126 iMessage = aMessage; |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // Destructor |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 CMdSFindEngine::~CMdSFindEngine() |
|
134 { |
|
135 delete iSerializedCriteria; |
|
136 delete iSequence; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // FindL |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 TInt CMdSFindEngine::FindL( TUserLevel aUserLevel ) |
|
144 { |
|
145 const TInt result = iSequence->FindL( *iSerializedCriteria, aUserLevel ); |
|
146 |
|
147 if( result == KErrNone && iMessage.IsNull() == EFalse ) |
|
148 { |
|
149 TPckgBuf<TInt> sizeBuf( iSequence->ResultsL().Size() ); |
|
150 iMessage.WriteL( 2, sizeBuf ); |
|
151 } |
|
152 |
|
153 return result; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // ContinueL |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 TInt CMdSFindEngine::ContinueL() |
|
161 { |
|
162 const TInt result = iSequence->ContinueL(); |
|
163 |
|
164 if( result == KErrNone && iMessage.IsNull() == EFalse ) |
|
165 { |
|
166 TPckgBuf<TInt> sizeBuf( iSequence->ResultsL().Size() ); |
|
167 iMessage.WriteL( 2, sizeBuf ); |
|
168 } |
|
169 |
|
170 return result; |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // FindAsyncL |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 void CMdSFindEngine::FindAsyncL( TUserLevel aUserLevel ) |
|
178 { |
|
179 iAsyncPending = ETrue; |
|
180 iSequence->FindAsync( *iSerializedCriteria, aUserLevel ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // ContinueAsync |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CMdSFindEngine::ContinueAsync() |
|
188 { |
|
189 iAsyncPending = ETrue; |
|
190 iSequence->ContinueAsync(); |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // Cancel |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 void CMdSFindEngine::Cancel( TInt aError ) |
|
198 { |
|
199 TBool toComplete = iAsyncPending; |
|
200 iAsyncPending = EFalse; |
|
201 iSequence->Cancel(); |
|
202 |
|
203 if( iMessage.IsNull() == EFalse ) |
|
204 { |
|
205 if ( toComplete ) |
|
206 { |
|
207 iMessage.Complete( KErrCancel ); |
|
208 } |
|
209 else |
|
210 { |
|
211 iMessage.Complete( aError ); |
|
212 } |
|
213 } |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // SetComplete |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 void CMdSFindEngine::SetComplete( TInt aError ) |
|
221 { |
|
222 TBool toComplete = iAsyncPending; |
|
223 __LOG1( ELogServer, "<- Find Set Complete (%d)", aError ); |
|
224 |
|
225 if( aError == KErrNone ) |
|
226 { |
|
227 TUint32 resultSize = 0; |
|
228 |
|
229 TInt err = KErrNone; |
|
230 |
|
231 TRAP( err, resultSize = iSequence->ResultsL().Size() ); |
|
232 |
|
233 if( err ) |
|
234 { |
|
235 if ( toComplete && iMessage.IsNull() == EFalse ) |
|
236 { |
|
237 iMessage.Complete( err ); |
|
238 } |
|
239 return; |
|
240 } |
|
241 |
|
242 iAsyncPending = EFalse; |
|
243 |
|
244 if ( iMessage.IsNull() == EFalse ) |
|
245 { |
|
246 TPckgBuf<TInt> sizeBuf( resultSize ); |
|
247 |
|
248 err = iMessage.Write( 2, sizeBuf ); |
|
249 } |
|
250 |
|
251 if( err ) |
|
252 { |
|
253 if ( toComplete && iMessage.IsNull() == EFalse ) |
|
254 { |
|
255 iMessage.Complete( err ); |
|
256 } |
|
257 return; |
|
258 } |
|
259 else |
|
260 { |
|
261 if ( toComplete && iMessage.IsNull() == EFalse ) |
|
262 { |
|
263 iMessage.Complete( EAsyncFindSetReady ); |
|
264 } |
|
265 } |
|
266 } |
|
267 else |
|
268 { |
|
269 if ( toComplete && iMessage.IsNull() == EFalse ) |
|
270 { |
|
271 iMessage.Complete( aError ); |
|
272 } |
|
273 return; |
|
274 } |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // FindComplete |
|
279 // --------------------------------------------------------------------------- |
|
280 // |
|
281 void CMdSFindEngine::FindComplete( TInt aError ) |
|
282 { |
|
283 TBool toComplete = iAsyncPending; |
|
284 __LOG1( ELogServer, "<- Find Complete (%d)", aError ); |
|
285 |
|
286 if( aError == KErrNone ) |
|
287 { |
|
288 TUint32 resultSize = 0; |
|
289 |
|
290 TInt err = KErrNone; |
|
291 |
|
292 TRAP( err, resultSize = iSequence->ResultsL().Size() ); |
|
293 |
|
294 if( err ) |
|
295 { |
|
296 if ( toComplete && iMessage.IsNull() == EFalse ) |
|
297 { |
|
298 iMessage.Complete( err ); |
|
299 } |
|
300 return; |
|
301 } |
|
302 |
|
303 iAsyncPending = EFalse; |
|
304 |
|
305 if ( iMessage.IsNull() == EFalse ) |
|
306 { |
|
307 TPckgBuf<TInt> sizeBuf( resultSize ); |
|
308 |
|
309 err = iMessage.Write( 2, sizeBuf ); |
|
310 } |
|
311 |
|
312 if( err ) |
|
313 { |
|
314 if ( toComplete && iMessage.IsNull() == EFalse ) |
|
315 { |
|
316 iMessage.Complete( err ); |
|
317 } |
|
318 return; |
|
319 } |
|
320 else |
|
321 { |
|
322 if ( toComplete && iMessage.IsNull() == EFalse ) |
|
323 { |
|
324 iMessage.Complete( EAsyncFindComplete ); |
|
325 } |
|
326 } |
|
327 } |
|
328 else |
|
329 { |
|
330 if ( toComplete && iMessage.IsNull() == EFalse ) |
|
331 { |
|
332 iMessage.Complete( aError ); |
|
333 } |
|
334 return; |
|
335 } |
|
336 } |
|
337 |
|
338 const CMdCSerializationBuffer& CMdSFindEngine::ResultsL() const |
|
339 { |
|
340 return iSequence->ResultsL(); |
|
341 } |
|
342 |
|
343 void CMdSFindEngine::SetResultMode( TBool aResultModeItems ) |
|
344 { |
|
345 iLastResultModeItems = aResultModeItems; |
|
346 } |
|
347 |
|
348 TBool CMdSFindEngine::IsComplete() const |
|
349 { |
|
350 if( iSequence ) |
|
351 { |
|
352 return iSequence->IsComplete(); |
|
353 } |
|
354 else |
|
355 { |
|
356 return ETrue; |
|
357 } |
|
358 } |
|
359 |
|
360 TBool CMdSFindEngine::IsQueryComplete() |
|
361 { |
|
362 if( iSequence ) |
|
363 { |
|
364 return iSequence->IsQueryComplete(); |
|
365 } |
|
366 else |
|
367 { |
|
368 return ETrue; |
|
369 } |
|
370 } |
|
371 |
|
372 CMdSServer& CMdSFindEngine::GetServer() const |
|
373 { |
|
374 return iParent.GetServer(); |
|
375 } |
|
376 |
|
377 void CMdSFindEngine::LockFindResultObjectsL( CMdSObjectLockList& aLockList ) |
|
378 { |
|
379 if (!iLastResultModeItems) |
|
380 { |
|
381 return; |
|
382 } |
|
383 |
|
384 CMdsSchema& schema = iParent.GetServer().Schema(); |
|
385 CMdCSerializationBuffer& buffer = iSequence->ResultsL(); |
|
386 buffer.PositionL( KNoOffset ); |
|
387 TMdCItems items; |
|
388 items.DeserializeL( buffer ); |
|
389 |
|
390 const CMdsNamespaceDef* namespaceDef = schema.GetNamespaceByIdL( items.iNamespaceDefId ); |
|
391 |
|
392 for(TInt32 i = 0; i < items.iObjects.iPtr.iCount; ++i) |
|
393 { |
|
394 buffer.PositionL( items.iObjects.iPtr.iOffset + i * sizeof(TMdCObject) ); |
|
395 TMdCObject object; |
|
396 object.DeserializeL( buffer ); |
|
397 |
|
398 if ( aLockList.IsLocked( *namespaceDef, object.iId ) ) |
|
399 { |
|
400 object.iFlags &= ~EMdEObjectFlagModOpen; |
|
401 } |
|
402 else |
|
403 { |
|
404 aLockList.LockObjectL( iParent, *namespaceDef, object.iId ); |
|
405 object.iFlags |= EMdEObjectFlagModOpen; |
|
406 } |
|
407 |
|
408 buffer.PositionL( items.iObjects.iPtr.iOffset + i * sizeof(TMdCObject) ); |
|
409 object.SerializeL( buffer ); |
|
410 } |
|
411 } |
|
412 |