1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This contains CTestMessProcessor which an active object utility |
|
15 // used for send/recieving or any time consuming |
|
16 // |
|
17 // |
|
18 |
|
19 #include "TestMessProcessor.h" |
|
20 #include "TestMessBase.h" |
|
21 |
|
22 CTestMessProcessor* CTestMessProcessor::NewL(CTestStep& aTestStep, CMsvSession& aSession) |
|
23 { |
|
24 CTestMessProcessor* self=new(ELeave) CTestMessProcessor(aTestStep, aSession); |
|
25 CleanupStack::PushL(self); |
|
26 self->ConstructL(); |
|
27 CleanupStack::Pop(); |
|
28 return self; |
|
29 } |
|
30 |
|
31 CTestMessProcessor::CTestMessProcessor(CTestStep& aTestStep, CMsvSession& aSession) |
|
32 : CActive(EPriorityStandard) |
|
33 , iState(EStatePrepareToSendMsg) |
|
34 , iTestStep(aTestStep) |
|
35 , iSession(aSession) |
|
36 , iEntry(NULL) |
|
37 , iMsgId(KMsvRootIndexEntryId) |
|
38 , iClient(NULL) |
|
39 , iMsvOperation(NULL) |
|
40 , iCancelSms(EFalse) |
|
41 { |
|
42 } |
|
43 |
|
44 CTestMessProcessor::~CTestMessProcessor() |
|
45 { |
|
46 delete iEntry; |
|
47 iEntry=NULL; |
|
48 delete iMsvOperation; |
|
49 iMsvOperation=NULL; |
|
50 } |
|
51 |
|
52 void CTestMessProcessor::ConstructL() |
|
53 { |
|
54 CActiveScheduler::Add(this); |
|
55 } |
|
56 |
|
57 void CTestMessProcessor::DoCancel() |
|
58 { |
|
59 iTestStep.INFO_PRINTF1(_L("Cancel operation")); |
|
60 iMsvOperation->Cancel(); |
|
61 } |
|
62 |
|
63 void CTestMessProcessor::DisplayProgress() |
|
64 { |
|
65 // display the current progress |
|
66 switch(iState) |
|
67 { |
|
68 case EStatePrepareToSendMsg: |
|
69 { |
|
70 TMsvLocalOperationProgress temp; |
|
71 TPckgC<TMsvLocalOperationProgress> progress(temp); |
|
72 |
|
73 progress.Set(iMsvOperation->ProgressL()); |
|
74 iTestStep.INFO_PRINTF1(_L(" Progress")); |
|
75 iTestStep.INFO_PRINTF2(_L(" Operation :%d"), progress().iType); |
|
76 iTestStep.INFO_PRINTF2(_L(" Total Number Of Entries:%d"), progress().iTotalNumberOfEntries); |
|
77 iTestStep.INFO_PRINTF2(_L(" Number Completed :%d"), progress().iNumberCompleted); |
|
78 iTestStep.INFO_PRINTF2(_L(" Number Failed :%d"), progress().iNumberFailed); |
|
79 iTestStep.INFO_PRINTF2(_L(" Number Remaining :%d"), progress().iNumberRemaining); |
|
80 iTestStep.INFO_PRINTF2(_L(" Error :%d"), progress().iError); |
|
81 iTestStep.INFO_PRINTF2(_L(" Id :%x"), progress().iId); |
|
82 } |
|
83 break; |
|
84 case EStateRequest: |
|
85 iClient->DisplayProgressL(EFalse, iMsvOperation); |
|
86 break; |
|
87 default: |
|
88 break; |
|
89 } |
|
90 } |
|
91 |
|
92 void CTestMessProcessor::SendEmailMessageL(TMsvId aMsgId, MTestMessProcessorClient* aClient) |
|
93 { |
|
94 iMsgId=aMsgId; |
|
95 iClient=aClient; |
|
96 iState=EStatePrepareToSendMsg; |
|
97 |
|
98 delete iEntry; |
|
99 iEntry=NULL; |
|
100 iEntry=iSession.GetEntryL(iMsgId); |
|
101 iMsgEntry=iEntry->Entry(); |
|
102 iMsgEntry.SetSendingState(KMsvSendStateWaiting); |
|
103 delete iMsvOperation; |
|
104 iMsvOperation=NULL; |
|
105 iMsvOperation=iEntry->ChangeL(iMsgEntry, iStatus); |
|
106 SetActive(); |
|
107 } |
|
108 |
|
109 /** |
|
110 Sends the sms message. It sets the fields of the enty. |
|
111 @param aMsgId - TMsvId of the message |
|
112 @param aClient - Pointer to the MTestMessProcessClient |
|
113 @param aCancelSms - Bool value for the Cancel sms flag |
|
114 */ |
|
115 void CTestMessProcessor::SendSmsMessageL(TMsvId aMsgId, MTestMessProcessorClient* aClient, TBool aCancelSms) |
|
116 { |
|
117 iMsgId=aMsgId; |
|
118 iClient=aClient; |
|
119 iState=EStatePrepareToSendMsg; |
|
120 iCancelSms = aCancelSms; |
|
121 |
|
122 delete iEntry; |
|
123 iEntry=NULL; |
|
124 iEntry=iSession.GetEntryL(iMsgId); |
|
125 iMsgEntry=iEntry->Entry(); |
|
126 iMsgEntry.SetConnected(ETrue); |
|
127 iMsgEntry.SetFailed(EFalse); |
|
128 iMsgEntry.SetSendingState(KMsvSendStateWaiting); |
|
129 iMsgEntry.iError = KErrNone; |
|
130 delete iMsvOperation; |
|
131 iMsvOperation=NULL; |
|
132 iMsvOperation=iEntry->ChangeL(iMsgEntry, iStatus); |
|
133 SetActive(); |
|
134 } |
|
135 |
|
136 void CTestMessProcessor::SendMmsMessageL(TMsvId aMsgId, MTestMessProcessorClient* aClient) |
|
137 { |
|
138 iMsgId=aMsgId; |
|
139 iClient=aClient; |
|
140 iState=EStatePrepareToSendMsg; |
|
141 |
|
142 delete iEntry; |
|
143 iEntry=NULL; |
|
144 iEntry=iSession.GetEntryL(iMsgId); |
|
145 iMsgEntry=iEntry->Entry(); |
|
146 iMsgEntry.SetSendingState(KMsvSendStateWaiting); |
|
147 delete iMsvOperation; |
|
148 iMsvOperation=NULL; |
|
149 iMsvOperation=iEntry->ChangeL(iMsgEntry, iStatus); |
|
150 SetActive(); |
|
151 } |
|
152 |
|
153 void CTestMessProcessor::MtmRequestL(TMsvId aAccountId, MTestMessProcessorClient* aClient) |
|
154 { |
|
155 iMsgId=aAccountId; |
|
156 iClient=aClient; |
|
157 iState=EStateRequest; |
|
158 |
|
159 delete iEntry; |
|
160 iEntry=NULL; |
|
161 iEntry=iSession.GetEntryL(iMsgId); |
|
162 iStatus = KRequestPending; |
|
163 delete iMsvOperation; |
|
164 iMsvOperation=NULL; |
|
165 TRAPD(err, iMsvOperation=iClient->CreateOperationL(iStatus)); |
|
166 if ( iTestStep.TestStepResult() == EPass && err==KErrNone ) |
|
167 { |
|
168 SetActive(); |
|
169 } |
|
170 } |
|
171 |
|
172 void CTestMessProcessor::RunL() |
|
173 { |
|
174 switch(iState) |
|
175 { |
|
176 case EStatePrepareToSendMsg: |
|
177 switch (iStatus.Int()) |
|
178 { |
|
179 case KErrNone: |
|
180 { |
|
181 delete iMsvOperation; |
|
182 iMsvOperation=NULL; |
|
183 delete iEntry; |
|
184 iEntry=NULL; |
|
185 iEntry=iSession.GetEntryL(iMsgId); |
|
186 iMsgEntry=iEntry->Entry(); |
|
187 iMsgEntry.SetSendingState(KMsvSendStateWaiting); |
|
188 iEntry->ChangeL(iMsgEntry); |
|
189 if ( iMsgEntry.SendingState() == KMsvSendStateWaiting ) |
|
190 { |
|
191 iState=EStateRequest; |
|
192 iStatus = KRequestPending; |
|
193 TRAPD(err, iMsvOperation=iClient->CreateOperationL(iStatus)); |
|
194 if ( iTestStep.TestStepResult() == EPass && err==KErrNone ) |
|
195 { |
|
196 SetActive(); |
|
197 } |
|
198 else |
|
199 { |
|
200 CActiveScheduler::Stop(); |
|
201 } |
|
202 } |
|
203 else |
|
204 { |
|
205 iTestStep.ERR_PRINTF2(_L("Sending State not Waiting :%d"), iMsgEntry.SendingState()); |
|
206 iTestStep.SetTestStepResult(EFail); |
|
207 CActiveScheduler::Stop(); |
|
208 } |
|
209 } |
|
210 break; |
|
211 case KErrCancel: |
|
212 { |
|
213 if(iCancelSms) |
|
214 { |
|
215 iTestStep.INFO_PRINTF1(_L("Sending of the mesage Cancelled successfully")); |
|
216 } |
|
217 else |
|
218 { |
|
219 iTestStep.ERR_PRINTF2(_L("Message failed to Send, Error = %d"), iStatus.Int()); |
|
220 iTestStep.SetTestStepResult(EFail); |
|
221 } |
|
222 CActiveScheduler::Stop(); |
|
223 break; |
|
224 } |
|
225 default: |
|
226 iTestStep.ERR_PRINTF2(_L("Unknown Event :%d"), iStatus.Int()); |
|
227 iTestStep.SetTestStepResult(EFail); |
|
228 CActiveScheduler::Stop(); |
|
229 } |
|
230 break; |
|
231 case EStateRequest: |
|
232 switch (iStatus.Int()) |
|
233 { |
|
234 case KErrNone: |
|
235 { |
|
236 TInt error=iClient->DisplayProgressL(ETrue, iMsvOperation); |
|
237 if ( error != KErrNone ) |
|
238 { |
|
239 iTestStep.ERR_PRINTF2(_L("Progress Error:%d"), error); |
|
240 iTestStep.SetTestStepResult(EFail); |
|
241 } |
|
242 delete iMsvOperation; |
|
243 iMsvOperation=NULL; |
|
244 |
|
245 // Is there another operation |
|
246 if ( iClient->MoreOperations() ) |
|
247 { |
|
248 iStatus = KRequestPending; |
|
249 TRAPD(err, iMsvOperation=iClient->CreateOperationL(iStatus)); |
|
250 if ( iTestStep.TestStepResult() == EPass && err==KErrNone ) |
|
251 { |
|
252 SetActive(); |
|
253 } |
|
254 else |
|
255 { |
|
256 CActiveScheduler::Stop(); |
|
257 } |
|
258 } |
|
259 else |
|
260 { |
|
261 CActiveScheduler::Stop(); |
|
262 } |
|
263 } |
|
264 break; |
|
265 case KErrServerTerminated: |
|
266 { |
|
267 TInt error=iClient->DisplayProgressL(ETrue, iMsvOperation); |
|
268 if ( error != KErrServerTerminated ) |
|
269 { |
|
270 iTestStep.ERR_PRINTF2(_L("Progress Error:%d"), error); |
|
271 iTestStep.SetTestStepResult(EFail); |
|
272 } |
|
273 delete iMsvOperation; |
|
274 iMsvOperation=NULL; |
|
275 CActiveScheduler::Stop(); |
|
276 } |
|
277 default: |
|
278 iTestStep.ERR_PRINTF2(_L("Unknown Event :%d"), iStatus.Int()); |
|
279 iTestStep.SetTestStepResult(EFail); |
|
280 CActiveScheduler::Stop(); |
|
281 } |
|
282 break; |
|
283 default: |
|
284 iTestStep.ERR_PRINTF1(_L("No handler found in CTestMessProcessor class")); |
|
285 iTestStep.SetTestStepResult(EFail); |
|
286 CActiveScheduler::Stop(); |
|
287 } |
|
288 } |
|