|
1 /* |
|
2 * Copyright (c) 2005-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: An implementation for find operation. Can be used e.g |
|
15 * in store domain implementation to handle Find -operations |
|
16 * from stores. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "CVPbkContactFindOperation.h" |
|
22 |
|
23 #include <CVPbkContactLinkArray.h> |
|
24 #include <MVPbkContactLink.h> |
|
25 |
|
26 CVPbkContactFindOperation::CVPbkContactFindOperation( |
|
27 MVPbkContactFindObserver& aObserver) : |
|
28 iObserver(aObserver) |
|
29 { |
|
30 } |
|
31 |
|
32 inline void CVPbkContactFindOperation::ConstructL() |
|
33 { |
|
34 } |
|
35 |
|
36 EXPORT_C CVPbkContactFindOperation* CVPbkContactFindOperation::NewLC( |
|
37 MVPbkContactFindObserver& aObserver) |
|
38 { |
|
39 CVPbkContactFindOperation* self = new(ELeave) CVPbkContactFindOperation(aObserver); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CVPbkContactFindOperation::~CVPbkContactFindOperation() |
|
46 { |
|
47 delete iResults; |
|
48 } |
|
49 |
|
50 void CVPbkContactFindOperation::HandleZeroSuboperations() |
|
51 { |
|
52 // If no suboperations then complete find with empty array. |
|
53 // If completing leaves then call FindFailed |
|
54 TRAPD( res, HandleZeroSuboperationsL() ); |
|
55 if ( res != KErrNone ) |
|
56 { |
|
57 iObserver.FindFailed( res ); |
|
58 } |
|
59 } |
|
60 |
|
61 void CVPbkContactFindOperation::FindCompleteL(MVPbkContactLinkArray* aResults) |
|
62 { |
|
63 ++iCompleteCount; |
|
64 |
|
65 // take ownership of aResults immediately |
|
66 MVPbkContactLinkArray* passedResults = aResults; |
|
67 CleanupDeletePushL(passedResults); |
|
68 |
|
69 // lazy creation of result array |
|
70 if (!iResults) |
|
71 { |
|
72 iResults = CVPbkContactLinkArray::NewL(); |
|
73 } |
|
74 |
|
75 if (aResults) |
|
76 { |
|
77 // append results to this operations array |
|
78 for (TInt i = aResults->Count() - 1; i >= 0; --i) |
|
79 { |
|
80 MVPbkContactLink* link = aResults->At(i).CloneLC(); |
|
81 iResults->AppendL(link); |
|
82 CleanupStack::Pop(); // link |
|
83 } |
|
84 } |
|
85 CleanupStack::PopAndDestroy(passedResults); |
|
86 |
|
87 // notify clients if all suboperations have completed |
|
88 if (iCompleteCount >= SubOperationCount()) |
|
89 { |
|
90 // takes ownership of results |
|
91 CVPbkContactLinkArray* results = iResults; |
|
92 iResults = NULL; |
|
93 iObserver.FindCompleteL(results); |
|
94 } |
|
95 } |
|
96 |
|
97 void CVPbkContactFindOperation::FindFailed(TInt aError) |
|
98 { |
|
99 ++iCompleteCount; |
|
100 |
|
101 // notify clients if all suboperations have completed |
|
102 if (iCompleteCount >= SubOperationCount()) |
|
103 { |
|
104 // if there are results give them to the client |
|
105 if (iResults) |
|
106 { |
|
107 // the observer takes ownership of results |
|
108 CVPbkContactLinkArray* results = iResults; |
|
109 iResults = NULL; |
|
110 TRAPD(err, iObserver.FindCompleteL(results)); |
|
111 if (err) |
|
112 { |
|
113 // client must take ownership of results before it can leave |
|
114 iObserver.FindFailed(aError); |
|
115 } |
|
116 } |
|
117 else |
|
118 { |
|
119 // otherwise inform find failure |
|
120 iObserver.FindFailed(aError); |
|
121 } |
|
122 } |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CVPbkContactFindOperation::HandleZeroSuboperationsL |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CVPbkContactFindOperation::HandleZeroSuboperationsL() |
|
130 { |
|
131 CVPbkContactLinkArray* emptyResults = CVPbkContactLinkArray::NewL(); |
|
132 // Client takes the ownership of the results |
|
133 iObserver.FindCompleteL( emptyResults ); |
|
134 } |
|
135 // End of File |