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 |
||
27 |
#ifdef MAIN |
|
28 |
#define getlist_cancel main |
|
29 |
#endif |
|
30 |
||
31 |
class CAddTestAsync: public CActive, public MContactCallback |
|
32 |
{ |
|
33 |
public: |
|
34 |
static CAddTestAsync* NewL(); |
|
35 |
~CAddTestAsync(); |
|
36 |
void Start(); |
|
37 |
TInt Result(); |
|
38 |
||
39 |
private: |
|
40 |
void ConstructL(); |
|
41 |
CAddTestAsync(); |
|
42 |
||
43 |
virtual void DoCancel(); |
|
44 |
virtual void RunL(); |
|
45 |
||
46 |
||
47 |
void TestFunc(); |
|
48 |
||
49 |
void HandleReturnValue(TOperationEvent aEvent, const TInt& aError , TInt aTransId); |
|
50 |
||
51 |
void HandleReturnIter( const TInt& aError, CContactIter* aIter, TInt aTransId ); |
|
52 |
||
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 |
private: |
56 |
CActiveSchedulerWait* iWaitSchedular; |
|
57 |
CContactService* iContactService; |
|
58 |
TInt iResult; |
|
59 |
||
60 |
}; |
|
61 |
||
62 |
CAddTestAsync* CAddTestAsync::NewL() |
|
63 |
{ |
|
64 |
CAddTestAsync* self = new(ELeave)CAddTestAsync(); |
|
65 |
self->ConstructL(); |
|
66 |
return self; |
|
67 |
} |
|
68 |
||
69 |
CAddTestAsync::~CAddTestAsync() |
|
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 CAddTestAsync::ConstructL() |
|
84 |
{ |
|
85 |
CActiveScheduler::Add(this); |
|
86 |
iContactService = CContactService::NewL(); |
|
87 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
88 |
} |
|
89 |
||
90 |
CAddTestAsync::CAddTestAsync() : |
|
91 |
CActive(EPriorityStandard) |
|
92 |
{ |
|
93 |
} |
|
94 |
||
95 |
void CAddTestAsync::DoCancel() |
|
96 |
{ |
|
97 |
||
98 |
} |
|
99 |
||
100 |
void CAddTestAsync::RunL() |
|
101 |
{ |
|
102 |
TestFunc(); |
|
103 |
} |
|
104 |
||
105 |
void CAddTestAsync::Start() |
|
106 |
{ |
|
107 |
SetActive(); |
|
108 |
TRequestStatus* temp = &iStatus; |
|
109 |
User::RequestComplete(temp, KErrNone); |
|
110 |
iWaitSchedular->Start(); |
|
111 |
} |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
112 |
void CAddTestAsync::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
|
113 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
114 |
CActiveScheduler::Stop(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
115 |
} |
19 | 116 |
void CAddTestAsync::HandleReturnValue(TOperationEvent aEvent, const TInt& aError , TInt aTransId) |
117 |
{ |
|
118 |
//******************* set iResult **************************** |
|
119 |
||
120 |
if(aEvent ==EOpCancel) |
|
121 |
iResult = KErrNone; |
|
122 |
else |
|
123 |
iResult = KErrGeneral; |
|
124 |
||
125 |
||
126 |
iWaitSchedular->AsyncStop(); |
|
127 |
} |
|
128 |
||
129 |
void CAddTestAsync::HandleReturnIter( const TInt& aError, CContactIter* aIter, TInt aTransId ) |
|
130 |
{ |
|
131 |
// It should not be called |
|
132 |
iResult = KErrGeneral; |
|
133 |
||
134 |
} |
|
135 |
||
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
136 |
|
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
137 |
void CAddTestAsync::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
|
138 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
139 |
CActiveScheduler::Stop(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
140 |
} |
19 | 141 |
TInt CAddTestAsync::Result() |
142 |
{ |
|
143 |
return iResult; |
|
144 |
} |
|
145 |
||
146 |
void CAddTestAsync::TestFunc() |
|
147 |
{ |
|
148 |
||
149 |
TInt transId = 666; |
|
150 |
/**Add contact using SAPI Core class*/ |
|
151 |
||
152 |
_LIT8(KFirstName,"FirstName"); |
|
153 |
_LIT(KName,"Suzanne"); |
|
154 |
_LIT8(KNumber,"MobilePhoneHome"); |
|
155 |
_LIT(KPhone,"88888888"); |
|
156 |
||
157 |
// __UHEAP_MARK; |
|
158 |
//instantiate service class |
|
159 |
||
160 |
CSingleContact* singleContact = CSingleContact::NewL(); |
|
161 |
CleanupStack::PushL(singleContact); |
|
162 |
||
163 |
CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
164 |
CleanupStack::PushL(nameContactField); |
|
165 |
||
166 |
CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
167 |
CleanupStack::PushL(phoneContactField); |
|
168 |
||
169 |
nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
170 |
singleContact->AddFieldToContactL(nameContactField); |
|
171 |
||
172 |
phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhone); |
|
173 |
singleContact->AddFieldToContactL(phoneContactField); |
|
174 |
||
175 |
iContactService->AddL(this,transId,singleContact,KNullDesC8,KNullDesC); |
|
176 |
||
177 |
TInt error = iContactService->Cancel(transId); |
|
178 |
||
179 |
CleanupStack::Pop(phoneContactField);//singleContactField |
|
180 |
CleanupStack::Pop(nameContactField);//singleContactField |
|
181 |
CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
182 |
// __UHEAP_MARKEND; |
|
183 |
/**end */ |
|
184 |
||
185 |
} |
|
186 |
||
187 |
||
188 |
int add_cancel(int, char**) |
|
189 |
{ |
|
190 |
__UHEAP_MARK; |
|
191 |
CAddTestAsync* test = CAddTestAsync::NewL(); |
|
192 |
||
193 |
test->Start(); |
|
194 |
||
195 |
TInt result = test->Result(); |
|
196 |
||
197 |
delete test; |
|
198 |
__UHEAP_MARKEND; |
|
199 |
||
200 |
return result; |
|
201 |
} |
|
202 |
||
203 |
||
204 |
||
205 |
||
206 |
||
207 |