|
1 /* |
|
2 * Copyright (c) 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include<e32base.h> |
|
21 |
|
22 #include "contactservice.h" |
|
23 #include "contactcallback.h" |
|
24 #include "tcontacts_async.h" |
|
25 #include "contactiter.h" // Iterator |
|
26 #include "searchfields.h" |
|
27 |
|
28 #ifdef MAIN |
|
29 #define getlist_cancel main |
|
30 #endif |
|
31 |
|
32 class CGetListTestSrhAsync: public CActive, public MContactCallback |
|
33 { |
|
34 public: |
|
35 static CGetListTestSrhAsync* NewL(); |
|
36 ~CGetListTestSrhAsync(); |
|
37 void Start(); |
|
38 TInt Result(); |
|
39 |
|
40 private: |
|
41 void ConstructL(); |
|
42 CGetListTestSrhAsync(); |
|
43 |
|
44 virtual void DoCancel(); |
|
45 virtual void RunL(); |
|
46 |
|
47 |
|
48 void TestFunc(); |
|
49 |
|
50 void HandleReturnValue(TOperationEvent aEvent, const TInt& aError , TInt aTransId); |
|
51 |
|
52 void HandleReturnIter( const TInt& aError, CContactIter* aIter, TInt aTransId ); |
|
53 |
|
54 |
|
55 private: |
|
56 CActiveSchedulerWait* iWaitSchedular; |
|
57 CContactService* iContactService; |
|
58 TInt iResult; |
|
59 |
|
60 }; |
|
61 |
|
62 CGetListTestSrhAsync* CGetListTestSrhAsync::NewL() |
|
63 { |
|
64 CGetListTestSrhAsync* self = new(ELeave)CGetListTestSrhAsync(); |
|
65 self->ConstructL(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 CGetListTestSrhAsync::~CGetListTestSrhAsync() |
|
70 { |
|
71 Cancel(); |
|
72 |
|
73 if(iWaitSchedular->IsStarted()) |
|
74 iWaitSchedular->AsyncStop(); |
|
75 |
|
76 if(iContactService) |
|
77 delete iContactService; |
|
78 |
|
79 if(iWaitSchedular) |
|
80 delete iWaitSchedular; |
|
81 } |
|
82 |
|
83 void CGetListTestSrhAsync::ConstructL() |
|
84 { |
|
85 CActiveScheduler::Add(this); |
|
86 iContactService = CContactService::NewL(); |
|
87 iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
88 } |
|
89 |
|
90 CGetListTestSrhAsync::CGetListTestSrhAsync() : |
|
91 CActive(EPriorityStandard) |
|
92 { |
|
93 } |
|
94 |
|
95 void CGetListTestSrhAsync::DoCancel() |
|
96 { |
|
97 |
|
98 } |
|
99 |
|
100 void CGetListTestSrhAsync::RunL() |
|
101 { |
|
102 TestFunc(); |
|
103 } |
|
104 |
|
105 void CGetListTestSrhAsync::Start() |
|
106 { |
|
107 SetActive(); |
|
108 TRequestStatus* temp = &iStatus; |
|
109 User::RequestComplete(temp, KErrNone); |
|
110 iWaitSchedular->Start(); |
|
111 } |
|
112 |
|
113 void CGetListTestSrhAsync::HandleReturnValue(TOperationEvent aEvent, const TInt& aError , TInt aTransId) |
|
114 { |
|
115 //******************* set iResult **************************** |
|
116 _LIT(KName,"Jack"); |
|
117 if(EOpCancel ==aEvent) |
|
118 { |
|
119 iResult = KErrNone; |
|
120 return; |
|
121 } |
|
122 |
|
123 else |
|
124 iResult = KErrGeneral; |
|
125 |
|
126 |
|
127 TRAPD(err,iContactService->GetListL(this,0,EContacts,KNullDesC8,KName,NULL,EAsc )); |
|
128 |
|
129 TInt error = iContactService->Cancel(0); |
|
130 iWaitSchedular->AsyncStop(); |
|
131 |
|
132 } |
|
133 |
|
134 void CGetListTestSrhAsync::HandleReturnIter( const TInt& aError, CContactIter* aIter, TInt aTransId ) |
|
135 { |
|
136 // It should not be called |
|
137 iResult = KErrGeneral; |
|
138 |
|
139 } |
|
140 |
|
141 |
|
142 TInt CGetListTestSrhAsync::Result() |
|
143 { |
|
144 return iResult; |
|
145 } |
|
146 |
|
147 void CGetListTestSrhAsync::TestFunc() |
|
148 { |
|
149 iWaitSchedular->AsyncStop(); |
|
150 _LIT8(KFirstName,"FirstName"); |
|
151 _LIT(KName,"Jack"); |
|
152 _LIT8(KNumber,"MobilePhoneHome"); |
|
153 _LIT(KPhone,"0909977"); |
|
154 |
|
155 TInt32 transId = 1003; |
|
156 |
|
157 CSingleContact* singleContact = CSingleContact::NewL(); |
|
158 CleanupStack::PushL(singleContact); |
|
159 |
|
160 CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
161 CleanupStack::PushL(nameContactField); |
|
162 |
|
163 CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
164 CleanupStack::PushL(phoneContactField); |
|
165 |
|
166 nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
167 singleContact->AddFieldToContactL(nameContactField); |
|
168 |
|
169 phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhone); |
|
170 singleContact->AddFieldToContactL(phoneContactField); |
|
171 |
|
172 iContactService->AddL(this,transId,singleContact,KNullDesC8,KNullDesC); |
|
173 iWaitSchedular->Start(); |
|
174 |
|
175 |
|
176 CleanupStack::Pop(phoneContactField);//singleContactField |
|
177 CleanupStack::Pop(nameContactField);//singleContactField |
|
178 CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
179 |
|
180 } |
|
181 |
|
182 |
|
183 int getlistsrh_cancel(int, char**) |
|
184 { |
|
185 __UHEAP_MARK; |
|
186 CGetListTestSrhAsync* test = CGetListTestSrhAsync::NewL(); |
|
187 |
|
188 test->Start(); |
|
189 |
|
190 TInt result = test->Result(); |
|
191 |
|
192 delete test; |
|
193 __UHEAP_MARKEND; |
|
194 |
|
195 return result; |
|
196 } |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |