author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 27 Aug 2009 07:43:07 +0300 | |
changeset 22 | fc9cf246af83 |
parent 19 | 989d2f495d90 |
permissions | -rw-r--r-- |
19 | 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 ); |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
53 |
void HandleReturnId( const TInt& aError, HBufC8* acntId, TInt aTransId ); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
54 |
void HandleReturnArray(const TInt& aError, RPointerArray<HBufC8>& aArray, TInt aTransId ); |
19 | 55 |
|
56 |
private: |
|
57 |
CActiveSchedulerWait* iWaitSchedular; |
|
58 |
CContactService* iContactService; |
|
59 |
TInt iResult; |
|
60 |
||
61 |
}; |
|
62 |
||
63 |
CGetListTestSrhAsync* CGetListTestSrhAsync::NewL() |
|
64 |
{ |
|
65 |
CGetListTestSrhAsync* self = new(ELeave)CGetListTestSrhAsync(); |
|
66 |
self->ConstructL(); |
|
67 |
return self; |
|
68 |
} |
|
69 |
||
70 |
CGetListTestSrhAsync::~CGetListTestSrhAsync() |
|
71 |
{ |
|
72 |
Cancel(); |
|
73 |
||
74 |
if(iWaitSchedular->IsStarted()) |
|
75 |
iWaitSchedular->AsyncStop(); |
|
76 |
||
77 |
if(iContactService) |
|
78 |
delete iContactService; |
|
79 |
||
80 |
if(iWaitSchedular) |
|
81 |
delete iWaitSchedular; |
|
82 |
} |
|
83 |
||
84 |
void CGetListTestSrhAsync::ConstructL() |
|
85 |
{ |
|
86 |
CActiveScheduler::Add(this); |
|
87 |
iContactService = CContactService::NewL(); |
|
88 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
89 |
} |
|
90 |
||
91 |
CGetListTestSrhAsync::CGetListTestSrhAsync() : |
|
92 |
CActive(EPriorityStandard) |
|
93 |
{ |
|
94 |
} |
|
95 |
||
96 |
void CGetListTestSrhAsync::DoCancel() |
|
97 |
{ |
|
98 |
||
99 |
} |
|
100 |
||
101 |
void CGetListTestSrhAsync::RunL() |
|
102 |
{ |
|
103 |
TestFunc(); |
|
104 |
} |
|
105 |
||
106 |
void CGetListTestSrhAsync::Start() |
|
107 |
{ |
|
108 |
SetActive(); |
|
109 |
TRequestStatus* temp = &iStatus; |
|
110 |
User::RequestComplete(temp, KErrNone); |
|
111 |
iWaitSchedular->Start(); |
|
112 |
} |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
113 |
void CGetListTestSrhAsync::HandleReturnId( const TInt& aError, HBufC8* acntId, TInt aTransId ) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
114 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
115 |
CActiveScheduler::Stop(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
116 |
} |
19 | 117 |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
118 |
void CGetListTestSrhAsync::HandleReturnArray(const TInt& aError, RPointerArray<HBufC8>& aArray, TInt aTransId ) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
119 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
120 |
CActiveScheduler::Stop(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
121 |
} |
19 | 122 |
void CGetListTestSrhAsync::HandleReturnValue(TOperationEvent aEvent, const TInt& aError , TInt aTransId) |
123 |
{ |
|
124 |
//******************* set iResult **************************** |
|
125 |
_LIT(KName,"Jack"); |
|
126 |
if(EOpCancel ==aEvent) |
|
127 |
{ |
|
128 |
iResult = KErrNone; |
|
129 |
return; |
|
130 |
} |
|
131 |
||
132 |
else |
|
133 |
iResult = KErrGeneral; |
|
134 |
||
135 |
||
136 |
TRAPD(err,iContactService->GetListL(this,0,EContacts,KNullDesC8,KName,NULL,EAsc )); |
|
137 |
||
138 |
TInt error = iContactService->Cancel(0); |
|
139 |
iWaitSchedular->AsyncStop(); |
|
140 |
||
141 |
} |
|
142 |
||
143 |
void CGetListTestSrhAsync::HandleReturnIter( const TInt& aError, CContactIter* aIter, TInt aTransId ) |
|
144 |
{ |
|
145 |
// It should not be called |
|
146 |
iResult = KErrGeneral; |
|
147 |
||
148 |
} |
|
149 |
||
150 |
||
151 |
TInt CGetListTestSrhAsync::Result() |
|
152 |
{ |
|
153 |
return iResult; |
|
154 |
} |
|
155 |
||
156 |
void CGetListTestSrhAsync::TestFunc() |
|
157 |
{ |
|
158 |
iWaitSchedular->AsyncStop(); |
|
159 |
_LIT8(KFirstName,"FirstName"); |
|
160 |
_LIT(KName,"Jack"); |
|
161 |
_LIT8(KNumber,"MobilePhoneHome"); |
|
162 |
_LIT(KPhone,"0909977"); |
|
163 |
||
164 |
TInt32 transId = 1003; |
|
165 |
||
166 |
CSingleContact* singleContact = CSingleContact::NewL(); |
|
167 |
CleanupStack::PushL(singleContact); |
|
168 |
||
169 |
CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
170 |
CleanupStack::PushL(nameContactField); |
|
171 |
||
172 |
CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
173 |
CleanupStack::PushL(phoneContactField); |
|
174 |
||
175 |
nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
176 |
singleContact->AddFieldToContactL(nameContactField); |
|
177 |
||
178 |
phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhone); |
|
179 |
singleContact->AddFieldToContactL(phoneContactField); |
|
180 |
||
181 |
iContactService->AddL(this,transId,singleContact,KNullDesC8,KNullDesC); |
|
182 |
iWaitSchedular->Start(); |
|
183 |
||
184 |
||
185 |
CleanupStack::Pop(phoneContactField);//singleContactField |
|
186 |
CleanupStack::Pop(nameContactField);//singleContactField |
|
187 |
CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
188 |
||
189 |
} |
|
190 |
||
191 |
||
192 |
int getlistsrh_cancel(int, char**) |
|
193 |
{ |
|
194 |
__UHEAP_MARK; |
|
195 |
CGetListTestSrhAsync* test = CGetListTestSrhAsync::NewL(); |
|
196 |
||
197 |
test->Start(); |
|
198 |
||
199 |
TInt result = test->Result(); |
|
200 |
||
201 |
delete test; |
|
202 |
__UHEAP_MARKEND; |
|
203 |
||
204 |
return result; |
|
205 |
} |
|
206 |
||
207 |
||
208 |
||
209 |
||
210 |
||
211 |