|
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 #include<LiwCommon.h> |
|
20 #include<LiwVariant.h> |
|
21 #include<LiwServiceHandler.h> |
|
22 #include "tcalendardeletetest.h" |
|
23 #include "deletetimerangebefore.h" |
|
24 |
|
25 _LIT8(KTestInterface, "IDataSource"); |
|
26 _LIT8(KTestContent, "Service.Calendar"); |
|
27 _LIT8(KCmd, "Delete"); |
|
28 _LIT8(KCmdCancel, "CancelNotification"); |
|
29 _LIT8(KMessageId, "MessageId"); |
|
30 _LIT8(KMap, "NotificationType"); |
|
31 _LIT8(KMessageList, "MessageList" ); |
|
32 _LIT8(KMessage, "Message" ); |
|
33 _LIT8(KErrorCode,"ErrorCode"); |
|
34 _LIT(KMsgType,"NewMessage"); |
|
35 _LIT8(KContentType,"Type"); |
|
36 _LIT8(KFilter,"Filter"); |
|
37 _LIT8(KData,"Data"); |
|
38 |
|
39 _LIT8(KDeleteAll,"DeleteAll"); |
|
40 _LIT(KCalFileName1,"C:CalendarFileA"); |
|
41 _LIT8(KCalendarName,"CalendarName"); |
|
42 |
|
43 TInt AddProvCalendar(CLiwGenericParamList* inparam, CLiwGenericParamList* outparam, MLiwInterface* interface, const TDesC& aCalendar); |
|
44 TInt RemoveProvCalendar(CLiwGenericParamList* inparam, CLiwGenericParamList* outparam, MLiwInterface* interface, const TDesC& aCalendar); |
|
45 TInt AddProvToDo(CLiwGenericParamList* inparam, CLiwGenericParamList* outparam, MLiwInterface* interface, const TDesC& aCalendar, TUint& localuid,HBufC8*& globaluid); |
|
46 TInt AddProvDayEvent(CLiwGenericParamList* inparam, CLiwGenericParamList* outparam, MLiwInterface* interface, const TDesC& aCalendar, TUint& localuid); |
|
47 TInt AddProvAnni(CLiwGenericParamList* inparam, CLiwGenericParamList* outparam, MLiwInterface* interface, const TDesC& aCalendar, TUint& localuid); |
|
48 |
|
49 |
|
50 CCalCallbackTimeBefore* CCalCallbackTimeBefore::NewL(CActiveSchedulerWait* aWaitSchedular, MLiwInterface* aInterface, TInt& aError) |
|
51 { |
|
52 return new (ELeave) CCalCallbackTimeBefore(aWaitSchedular, aInterface, aError); |
|
53 } |
|
54 |
|
55 TInt CCalCallbackTimeBefore::HandleNotifyL(TInt aCmdId, |
|
56 TInt aEventId, |
|
57 CLiwGenericParamList& aEventParamList, |
|
58 const CLiwGenericParamList& aInParamList) |
|
59 { |
|
60 TInt32 errCode; |
|
61 TInt pos = 0; |
|
62 |
|
63 // Traiverse the List and Fill in the Log Files |
|
64 const TLiwGenericParam* p = aEventParamList.FindFirst(pos, KErrorCode); // Finding Error Code |
|
65 if( p ) |
|
66 { |
|
67 errCode = p->Value().AsTInt32(); |
|
68 } |
|
69 |
|
70 if ( errCode == KErrNone ) |
|
71 { |
|
72 |
|
73 CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL(); |
|
74 CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL(); |
|
75 |
|
76 TLiwVariant dsName; |
|
77 dsName.Set(_L("CalendarEntry")); |
|
78 TLiwGenericParam dsNameParam(KContentType, dsName); |
|
79 inParamList->AppendL(dsNameParam); |
|
80 dsName.Reset(); |
|
81 |
|
82 CLiwDefaultMap *filterMap = CLiwDefaultMap::NewL(); |
|
83 TLiwGenericParam filterParam(KFilter, TLiwVariant(filterMap)); |
|
84 inParamList->AppendL(filterParam); |
|
85 filterMap->DecRef(); |
|
86 |
|
87 TLiwVariant calname; |
|
88 calname.Set(KCalFileName1);; |
|
89 filterMap->InsertL(KCalendarName,calname); |
|
90 calname.Reset(); |
|
91 |
|
92 |
|
93 TInt err = 0; |
|
94 TRAP(err,iInterface->ExecuteCmdL( _L8("GetList") ,*inParamList ,*outParamList)); |
|
95 |
|
96 pos = 0 ; |
|
97 |
|
98 const TLiwGenericParam* finaloutput = outParamList->FindFirst( pos,_L8("ReturnValue")); |
|
99 TInt count = 0; |
|
100 CLiwMap* map; |
|
101 |
|
102 if ( finaloutput ) |
|
103 { |
|
104 CLiwIterable* iterlist = finaloutput->Value().AsIterable(); |
|
105 if(iterlist) |
|
106 { |
|
107 TLiwVariant data; |
|
108 while(iterlist->NextL(data) ) |
|
109 { |
|
110 map = (CLiwMap*)data.AsMap(); |
|
111 map->DecRef(); |
|
112 count++; |
|
113 } |
|
114 data.Reset(); |
|
115 } |
|
116 } |
|
117 if(count != 1) |
|
118 errCode = KErrGeneral; |
|
119 inParamList->Reset(); |
|
120 outParamList->Reset(); |
|
121 RemoveProvCalendar(inParamList, outParamList, iInterface, KCalFileName1); |
|
122 delete inParamList; |
|
123 delete outParamList; |
|
124 } |
|
125 if ( iWaitSchedular && iWaitSchedular->IsStarted()) |
|
126 { |
|
127 iWaitSchedular->AsyncStop(); |
|
128 } |
|
129 iResult = errCode; |
|
130 return errCode; |
|
131 } |
|
132 |
|
133 |
|
134 |
|
135 CTestAsyncDeleteBefore* CTestAsyncDeleteBefore::NewL() |
|
136 { |
|
137 CTestAsyncDeleteBefore* self = new (ELeave) CTestAsyncDeleteBefore(); |
|
138 self->ConstructL(); |
|
139 return self; |
|
140 } |
|
141 |
|
142 CTestAsyncDeleteBefore::~CTestAsyncDeleteBefore() |
|
143 { |
|
144 Cancel(); |
|
145 |
|
146 if( interface ) |
|
147 interface->Close(); |
|
148 |
|
149 delete iServiceHandler; |
|
150 |
|
151 delete iCallback; |
|
152 |
|
153 if(iWaitSchedular && iWaitSchedular->IsStarted()) |
|
154 iWaitSchedular->AsyncStop(); |
|
155 |
|
156 delete iWaitSchedular; |
|
157 } |
|
158 |
|
159 |
|
160 void CTestAsyncDeleteBefore::ConstructL() |
|
161 { |
|
162 CActiveScheduler::Add(this); |
|
163 iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
164 } |
|
165 |
|
166 |
|
167 CTestAsyncDeleteBefore::CTestAsyncDeleteBefore() : |
|
168 CActive(EPriorityStandard) |
|
169 { |
|
170 interface = NULL ; |
|
171 } |
|
172 |
|
173 void CTestAsyncDeleteBefore::DoCancel() |
|
174 { |
|
175 |
|
176 } |
|
177 |
|
178 void CTestAsyncDeleteBefore::RunL() |
|
179 { |
|
180 |
|
181 TestFunc(); |
|
182 |
|
183 } |
|
184 |
|
185 |
|
186 int CTestAsyncDeleteBefore::Start() |
|
187 { |
|
188 SetActive(); |
|
189 TRequestStatus* temp = &iStatus; |
|
190 User::RequestComplete(temp, KErrNone); |
|
191 iWaitSchedular->Start(); |
|
192 return iError; |
|
193 } |
|
194 |
|
195 |
|
196 void CTestAsyncDeleteBefore::TestFunc() |
|
197 { |
|
198 iServiceHandler = CLiwServiceHandler::NewL(); |
|
199 |
|
200 CLiwGenericParamList* inparam = &(iServiceHandler->InParamListL()); |
|
201 CLiwGenericParamList* outparam = &(iServiceHandler->OutParamListL()); |
|
202 |
|
203 |
|
204 TInt err; |
|
205 |
|
206 RCriteriaArray interest; |
|
207 CleanupClosePushL(interest); |
|
208 |
|
209 CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1, KTestInterface,KTestContent); |
|
210 crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
211 CleanupStack::PushL(crit); |
|
212 interest.AppendL(crit); |
|
213 iServiceHandler->AttachL(interest); |
|
214 iServiceHandler->ExecuteServiceCmdL(*crit, *inparam, *outparam); |
|
215 |
|
216 TInt pos = 0; |
|
217 |
|
218 outparam->FindFirst( pos, KTestInterface ); |
|
219 if(pos != KErrNotFound) |
|
220 { |
|
221 interface = (*outparam)[pos].Value().AsInterface(); |
|
222 } |
|
223 |
|
224 CleanupStack::PopAndDestroy(crit); |
|
225 CleanupStack::PopAndDestroy(&interest); |
|
226 |
|
227 outparam->Reset(); |
|
228 inparam->Reset(); |
|
229 |
|
230 AddProvCalendar(inparam, outparam, interface, KCalFileName1); |
|
231 HBufC8* globaluid; |
|
232 TUint localuid; |
|
233 AddProvToDo(inparam, outparam, interface, KCalFileName1 ,localuid, globaluid) ; |
|
234 |
|
235 AddProvToDo(inparam, outparam, interface, KCalFileName1 ,localuid, globaluid) ; |
|
236 |
|
237 AddProvDayEvent(inparam, outparam, interface, KCalFileName1 ,localuid) ; |
|
238 |
|
239 TLiwVariant dsName; |
|
240 dsName.Set(_L("CalendarEntry")); |
|
241 TLiwGenericParam dsNameParam(KContentType, dsName); |
|
242 inparam->AppendL(dsNameParam); |
|
243 dsName.Reset(); |
|
244 |
|
245 CLiwDefaultMap *filterMap = CLiwDefaultMap::NewL(); |
|
246 TLiwGenericParam filterParam(KData, TLiwVariant(filterMap)); |
|
247 inparam->AppendL(filterParam); |
|
248 |
|
249 CLiwDefaultList *uidlist = CLiwDefaultList::NewL(); |
|
250 uidlist->AppendL(TLiwVariant(globaluid->Des())); |
|
251 TLiwVariant calname; |
|
252 TPtrC filename(_L("C:CalendarFileA")); |
|
253 calname.Set(filename); |
|
254 |
|
255 filterMap->InsertL(KCalendarName,calname); |
|
256 //filterMap->InsertL(_L8("GlobalUidList"), TLiwVariant(uidlist)); |
|
257 uidlist->DecRef(); |
|
258 filterMap->DecRef(); |
|
259 |
|
260 iCallback = CCalCallbackTimeBefore::NewL(iWaitSchedular, interface, iError); |
|
261 |
|
262 TRAPD(err1 ,interface->ExecuteCmdL(KCmd, *inparam, *outparam, KLiwOptASyncronous, iCallback)); |
|
263 TInt errCode; |
|
264 |
|
265 const TLiwGenericParam* p = outparam->FindFirst(pos, KErrorCode); // Finding Error Code |
|
266 if( p ) |
|
267 { |
|
268 errCode = p->Value().AsTInt32(); |
|
269 } |
|
270 if( errCode != KErrNone ) |
|
271 { |
|
272 inparam->Reset(); |
|
273 outparam->Reset(); |
|
274 RemoveProvCalendar(inparam, outparam, interface, KCalFileName1); |
|
275 |
|
276 if ( iWaitSchedular && iWaitSchedular->IsStarted()) |
|
277 { |
|
278 iWaitSchedular->AsyncStop(); |
|
279 } |
|
280 iError = errCode; |
|
281 } |
|
282 delete globaluid; |
|
283 inparam->Reset(); |
|
284 outparam->Reset(); |
|
285 calname.Reset(); |
|
286 } |
|
287 |
|
288 |
|
289 int DeleteGuidAsync() |
|
290 { |
|
291 __UHEAP_MARK; |
|
292 CTestAsyncDeleteBefore* test = CTestAsyncDeleteBefore::NewL(); |
|
293 int res = test->Start(); |
|
294 delete test; |
|
295 return res; |
|
296 |
|
297 __UHEAP_MARKEND; |
|
298 |
|
299 } |
|
300 |