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 CImportTestAsync: public CActive, public MContactCallback |
|
32 |
{ |
|
33 |
public: |
|
34 |
static CImportTestAsync* NewL(); |
|
35 |
~CImportTestAsync(); |
|
36 |
void Start(); |
|
37 |
TInt Result(); |
|
38 |
||
39 |
private: |
|
40 |
void ConstructL(); |
|
41 |
CImportTestAsync(); |
|
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 ); |
19 | 54 |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
55 |
void HandleReturnArray(const TInt& aError, RPointerArray<HBufC8>& aArray, TInt aTransId ); |
19 | 56 |
private: |
57 |
CActiveSchedulerWait* iWaitSchedular; |
|
58 |
CContactService* iContactService; |
|
59 |
TInt iResult; |
|
60 |
}; |
|
61 |
||
62 |
CImportTestAsync* CImportTestAsync::NewL() |
|
63 |
{ |
|
64 |
CImportTestAsync* self = new(ELeave)CImportTestAsync(); |
|
65 |
self->ConstructL(); |
|
66 |
return self; |
|
67 |
} |
|
68 |
||
69 |
CImportTestAsync::~CImportTestAsync() |
|
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 CImportTestAsync::ConstructL() |
|
84 |
{ |
|
85 |
CActiveScheduler::Add(this); |
|
86 |
iContactService = CContactService::NewL(); |
|
87 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
88 |
} |
|
89 |
||
90 |
CImportTestAsync::CImportTestAsync() : |
|
91 |
CActive(EPriorityStandard) |
|
92 |
{ |
|
93 |
} |
|
94 |
||
95 |
void CImportTestAsync::DoCancel() |
|
96 |
{ |
|
97 |
||
98 |
} |
|
99 |
||
100 |
void CImportTestAsync::RunL() |
|
101 |
{ |
|
102 |
TestFunc(); |
|
103 |
} |
|
104 |
||
105 |
void CImportTestAsync::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 CImportTestAsync::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 |
|
117 |
void CImportTestAsync::HandleReturnValue(TOperationEvent aEvent, const TInt& aError , TInt aTransId) |
|
118 |
{ |
|
119 |
//******************* set iResult **************************** |
|
120 |
||
121 |
if(aEvent ==EOpCancel) |
|
122 |
iResult = KErrNone; |
|
123 |
else |
|
124 |
iResult = KErrGeneral; |
|
125 |
||
126 |
||
127 |
iWaitSchedular->AsyncStop(); |
|
128 |
} |
|
129 |
||
130 |
void CImportTestAsync::HandleReturnIter( const TInt& aError, CContactIter* aIter, TInt aTransId ) |
|
131 |
{ |
|
132 |
// It should not be called |
|
133 |
iResult = KErrGeneral; |
|
134 |
||
135 |
} |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
136 |
void CImportTestAsync::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
|
137 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
138 |
CActiveScheduler::Stop(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
139 |
} |
19 | 140 |
|
141 |
TInt CImportTestAsync::Result() |
|
142 |
{ |
|
143 |
return iResult; |
|
144 |
} |
|
145 |
||
146 |
void CImportTestAsync::TestFunc() |
|
147 |
{ |
|
148 |
||
149 |
||
150 |
TInt32 transId = 1003; |
|
151 |
||
152 |
_LIT(KFileName,"c:\\vcardim.vcf"); |
|
153 |
//using sapi |
|
154 |
TFileName file(KFileName); |
|
155 |
||
156 |
iContactService->ImportVCardToStoreL(this,transId,file); |
|
157 |
||
158 |
TInt error = iContactService->Cancel(transId); |
|
159 |
} |
|
160 |
||
161 |
||
162 |
int import_cancel(int, char**) |
|
163 |
{ |
|
164 |
__UHEAP_MARK; |
|
165 |
CImportTestAsync* test = CImportTestAsync::NewL(); |
|
166 |
||
167 |
test->Start(); |
|
168 |
||
169 |
TInt result = test->Result(); |
|
170 |
||
171 |
delete test; |
|
172 |
__UHEAP_MARKEND; |
|
173 |
||
174 |
return result; |
|
175 |
} |
|
176 |
||
177 |
||
178 |
||
179 |
||
180 |
||
181 |