|
1 // Copyright (c) 1999-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 // |
|
15 |
|
16 #include <gsmubuf.h> |
|
17 #include <gsmuset.h> |
|
18 #include <smsustrm.h> |
|
19 |
|
20 #include "TE_smsinterbase.h" |
|
21 |
|
22 const TInt KActiveReceiverSocketGranularity = 8; |
|
23 const TInt KActiveSocketPriority = CActive::EPriorityIdle; |
|
24 |
|
25 class CStopIfKeyPressed; |
|
26 |
|
27 class MStopTest |
|
28 { |
|
29 public: |
|
30 virtual void StopTests() = 0; |
|
31 }; |
|
32 |
|
33 // |
|
34 // |
|
35 // CActiveSocket |
|
36 // |
|
37 // |
|
38 |
|
39 class CActiveSocket : public CActive |
|
40 { |
|
41 public: |
|
42 enum { EPriority = KActiveSocketPriority }; |
|
43 public: |
|
44 static CActiveSocket* NewL(const TTestCase& aTest, RSocketServ& aSocketServer, RFs& aFs); |
|
45 ~CActiveSocket(); |
|
46 void ReceiveMessage(TRequestStatus* aStatus); |
|
47 void SetIndex(TInt aIndex); |
|
48 void TestResultL(); |
|
49 TBool TestComplete(); |
|
50 TPtrC Message(); |
|
51 private: |
|
52 virtual void DoCancel(); |
|
53 virtual void RunL(); |
|
54 CActiveSocket(RSocketServ& aSocketServer); |
|
55 private: |
|
56 void InitRSocketL(); |
|
57 private: |
|
58 TRequestStatus* iActiveReceiverStatus; |
|
59 RSocket iSocket; |
|
60 TTestCase iTestCase; |
|
61 CSmsMessage* iSmsMessage; |
|
62 TInt iActiveReceiverIndex; |
|
63 TPckgBuf<TUint> iSelectBuf; |
|
64 RSocketServ& iSocketServer; |
|
65 }; |
|
66 |
|
67 // |
|
68 // |
|
69 // CActiveSenderImp |
|
70 // |
|
71 // |
|
72 |
|
73 class CActiveSenderImp : public CActiveSender, MStopTest |
|
74 { |
|
75 public: |
|
76 static CActiveSenderImp* NewL(RSocketServ& aSocketServer, |
|
77 RFs& aFs, |
|
78 const TDesC& aTelephoneNumber, |
|
79 const TDesC& aServiceCenterNumber); |
|
80 virtual void StartSendingL(); |
|
81 virtual void StopIfKeyPressedL(); |
|
82 ~CActiveSenderImp(); |
|
83 public: |
|
84 void StopTests(); |
|
85 private: |
|
86 void InitRSocketL(); |
|
87 void SendSmsMessageL(); |
|
88 private: |
|
89 virtual void DoCancel(); |
|
90 virtual void RunL(); |
|
91 private: |
|
92 CActiveSenderImp(RSocketServ& aSocketServer, RFs& aFs); |
|
93 CStopIfKeyPressed* iStopTest; |
|
94 RSocket iSocket; |
|
95 CSmsMessage* iSmsMessage; |
|
96 TPckgBuf<TUint> iIntBuf; |
|
97 TInt iCount; |
|
98 }; |
|
99 |
|
100 // |
|
101 // |
|
102 // CActiveReceiverImp |
|
103 // |
|
104 // |
|
105 |
|
106 class CActiveReceiverImp : public CActiveReceiver, MStopTest |
|
107 { |
|
108 public: |
|
109 static CActiveReceiverImp* NewL(RSocketServ& aSocketServer, RFs& aFs); |
|
110 virtual void AddTestL(const TTestCase& aTest); |
|
111 virtual void StartTestsL(); |
|
112 virtual void StopIfKeyPressedL(); |
|
113 ~CActiveReceiverImp(); |
|
114 public: |
|
115 void StopTests(); |
|
116 private: |
|
117 virtual void DoCancel(); |
|
118 virtual void RunL(); |
|
119 private: |
|
120 CActiveReceiverImp(RSocketServ& aSocketServer, RFs& aFs); |
|
121 CArrayPtr<CActiveSocket>* iSockArray; |
|
122 TInt iResultCount; |
|
123 CStopIfKeyPressed* iStopTest; |
|
124 }; |
|
125 |
|
126 // |
|
127 // |
|
128 // CStopIfKeyPressed |
|
129 // |
|
130 // |
|
131 |
|
132 class CStopIfKeyPressed : public CActive |
|
133 { |
|
134 public: |
|
135 enum { EPriority = KStopIfKeyPressedPriority }; |
|
136 public: |
|
137 static CStopIfKeyPressed* NewL(MStopTest* aReceiver); |
|
138 virtual void RunL(); |
|
139 virtual void DoCancel(); |
|
140 public: |
|
141 void StopIfKeyPressed(); |
|
142 private: |
|
143 CStopIfKeyPressed(); |
|
144 MStopTest* iReceiver; |
|
145 }; |
|
146 |
|
147 CStopIfKeyPressed* CStopIfKeyPressed::NewL(MStopTest* aReceiver) |
|
148 // |
|
149 // Factory |
|
150 // |
|
151 { |
|
152 |
|
153 CStopIfKeyPressed* stopTest = new(ELeave) CStopIfKeyPressed; |
|
154 stopTest->iReceiver = aReceiver; |
|
155 CActiveScheduler::Add(stopTest); |
|
156 return stopTest; |
|
157 } |
|
158 |
|
159 void CStopIfKeyPressed::StopIfKeyPressed() |
|
160 // |
|
161 // Activate |
|
162 // |
|
163 { |
|
164 |
|
165 if (IsActive()) |
|
166 return; |
|
167 // CConsoleBase* console = gTest.Console(); |
|
168 // console->Read(iStatus); |
|
169 // SetActive(); |
|
170 } |
|
171 |
|
172 CStopIfKeyPressed::CStopIfKeyPressed() |
|
173 // |
|
174 // Constructor |
|
175 // |
|
176 : CActive(EPriority) |
|
177 {} |
|
178 |
|
179 void CStopIfKeyPressed::RunL() |
|
180 // |
|
181 // Called if a key has been pressed |
|
182 // |
|
183 { |
|
184 |
|
185 iReceiver->StopTests(); |
|
186 CActiveScheduler::Stop(); |
|
187 } |
|
188 |
|
189 void CStopIfKeyPressed::DoCancel() |
|
190 // |
|
191 // Cancel has been called |
|
192 // |
|
193 { |
|
194 |
|
195 // CConsoleBase* console = gTest.Console(); |
|
196 // console->ReadCancel(); |
|
197 } |
|
198 |
|
199 // |
|
200 // |
|
201 // CActiveSocket |
|
202 // |
|
203 // |
|
204 |
|
205 CActiveSocket* CActiveSocket::NewL(const TTestCase& aTest, RSocketServ& aSocketServer, RFs& aFs) |
|
206 // |
|
207 // Factory |
|
208 // |
|
209 { |
|
210 |
|
211 CActiveSocket* socket = new(ELeave) CActiveSocket(aSocketServer); |
|
212 CleanupStack::PushL(socket); |
|
213 socket->iTestCase=aTest; |
|
214 socket->InitRSocketL(); |
|
215 |
|
216 CSmsBuffer* buffer=NULL; |
|
217 buffer=CSmsBuffer::NewL(); |
|
218 socket->iSmsMessage=CSmsMessage::NewL(aFs, CSmsPDU::ESmsSubmit,buffer); |
|
219 CleanupStack::Pop(); |
|
220 |
|
221 CActiveScheduler::Add(socket); |
|
222 return socket; |
|
223 } |
|
224 |
|
225 CActiveSocket::CActiveSocket(RSocketServ& aSocketServer) |
|
226 // |
|
227 // Constructor |
|
228 // |
|
229 : CActive(EPriority), |
|
230 iSocketServer(aSocketServer) |
|
231 {} |
|
232 |
|
233 CActiveSocket::~CActiveSocket() |
|
234 // |
|
235 // Destructor |
|
236 // |
|
237 { |
|
238 |
|
239 delete iSmsMessage; |
|
240 iSocket.Close(); |
|
241 } |
|
242 |
|
243 void CActiveSocket::TestResultL() |
|
244 // |
|
245 // Test the sms message contains the expected data |
|
246 // |
|
247 { |
|
248 |
|
249 CSmsBufferBase& smsBuffer=iSmsMessage->Buffer(); |
|
250 TInt bufLen=smsBuffer.Length(); |
|
251 HBufC* textBuf=HBufC::NewL(bufLen); |
|
252 TPtr textPtr(textBuf->Des()); |
|
253 smsBuffer.Extract(textPtr,0,bufLen); |
|
254 |
|
255 // if (iTestCase.iTestForever) |
|
256 // gTest.Printf(_L("RECEIVED: Msg %S\n"),&textPtr); |
|
257 // else if (iTestCase.iMatchType==ESmsAddrStatusReport) |
|
258 // gTest.Printf(_L("SUCCESS: Status report received for %S\n"),&iTestCase.iMsg); |
|
259 // else |
|
260 // { |
|
261 // TBool ret = (textPtr==iTestCase.iMsg); |
|
262 // if (ret>0) |
|
263 // gTest.Printf(_L("SUCCESS: Msg %S received\n"),&iTestCase.iMsg); |
|
264 // else |
|
265 // gTest.Printf(_L("SUCCESS: Msg %S not received\n"),&iTestCase.iMsg); |
|
266 // } |
|
267 |
|
268 delete textBuf; |
|
269 } |
|
270 |
|
271 |
|
272 void CActiveSocket::SetIndex(TInt aIndex) |
|
273 // |
|
274 // Set the index ofthe socket within the receiver's iSockArray |
|
275 // |
|
276 { |
|
277 |
|
278 iActiveReceiverIndex = aIndex; |
|
279 } |
|
280 |
|
281 TPtrC CActiveSocket::Message() |
|
282 // |
|
283 // Return the testcase message |
|
284 // |
|
285 { |
|
286 |
|
287 return iTestCase.iMsg; |
|
288 } |
|
289 |
|
290 void CActiveSocket::InitRSocketL() |
|
291 // |
|
292 // Initialise the active socket's connection with the socket server |
|
293 // |
|
294 { |
|
295 |
|
296 TInt ret=iSocket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); |
|
297 User::LeaveIfError(ret); |
|
298 TSmsAddr smsAddr; |
|
299 smsAddr.SetSmsAddrFamily(iTestCase.iMatchType); |
|
300 |
|
301 switch(iTestCase.iMatchType) |
|
302 { |
|
303 case ESmsAddrMatchText: |
|
304 { |
|
305 TBuf8<128> match; |
|
306 match.Copy(iTestCase.iMatch); |
|
307 smsAddr.SetTextMatch(match); |
|
308 break; |
|
309 } |
|
310 case ESmsAddrMatchIEI: |
|
311 smsAddr.SetIdentifierMatch(iTestCase.iIdentifierMatch); |
|
312 break; |
|
313 case ESmsAddrMessageIndication: |
|
314 break; |
|
315 default: |
|
316 break; |
|
317 }; |
|
318 |
|
319 ret=iSocket.Bind(smsAddr); |
|
320 User::LeaveIfError(ret); |
|
321 } |
|
322 |
|
323 void CActiveSocket::ReceiveMessage(TRequestStatus* aStatus) |
|
324 // |
|
325 // Receive a message |
|
326 // |
|
327 { |
|
328 |
|
329 iActiveReceiverStatus = aStatus; |
|
330 iSelectBuf()=KSockSelectRead; |
|
331 iSocket.Ioctl(KIOctlSelect,iStatus,&iSelectBuf,KSOLSocket); |
|
332 SetActive(); |
|
333 } |
|
334 |
|
335 void CActiveSocket::DoCancel() |
|
336 // |
|
337 // Cancel the select |
|
338 // |
|
339 { |
|
340 |
|
341 iSocket.CancelAll(); |
|
342 } |
|
343 |
|
344 void CActiveSocket::RunL() |
|
345 // |
|
346 // Got something to read |
|
347 // |
|
348 { |
|
349 |
|
350 if (iStatus<0) |
|
351 { |
|
352 User::RequestComplete(iActiveReceiverStatus,iStatus.Int()); |
|
353 return; |
|
354 } |
|
355 |
|
356 RSmsSocketReadStream readstream(iSocket); |
|
357 TRAPD(ret,readstream >> *iSmsMessage); |
|
358 User::LeaveIfError(ret); |
|
359 |
|
360 TPckgBuf<TUint> sbuf; |
|
361 TRequestStatus status; |
|
362 iSocket.Ioctl(KIoctlReadMessageSucceeded,status,&sbuf, KSolSmsProv); |
|
363 User::WaitForRequest(status); |
|
364 |
|
365 User::RequestComplete(iActiveReceiverStatus,iActiveReceiverIndex); |
|
366 } |
|
367 |
|
368 TBool CActiveSocket::TestComplete() |
|
369 // |
|
370 // Socket has finished performing all tests |
|
371 // |
|
372 { |
|
373 |
|
374 if (iTestCase.iTestForever) |
|
375 return EFalse; |
|
376 return ETrue; |
|
377 } |
|
378 |
|
379 // |
|
380 // |
|
381 // CActiveReceiverImp |
|
382 // |
|
383 // |
|
384 |
|
385 CActiveReceiverImp* CActiveReceiverImp::NewL(RSocketServ& aSocketServer, RFs& aFs) |
|
386 // |
|
387 // Factory |
|
388 // |
|
389 { |
|
390 |
|
391 CActiveReceiverImp* actRecv = new(ELeave) CActiveReceiverImp(aSocketServer, aFs); |
|
392 CleanupStack::PushL(actRecv); |
|
393 actRecv->iSockArray=new(ELeave) CArrayPtrSeg<CActiveSocket>(KActiveReceiverSocketGranularity); |
|
394 actRecv->iStatus=KRequestPending; |
|
395 CleanupStack::Pop(); |
|
396 CActiveScheduler::Add(actRecv); |
|
397 return actRecv; |
|
398 } |
|
399 |
|
400 CActiveReceiverImp::CActiveReceiverImp(RSocketServ& aSocketServer, RFs& aFs) |
|
401 // |
|
402 // Constructor |
|
403 // |
|
404 :CActiveReceiver(aSocketServer, aFs) |
|
405 {} |
|
406 |
|
407 CActiveReceiverImp::~CActiveReceiverImp() |
|
408 // |
|
409 // Destructor |
|
410 // |
|
411 { |
|
412 |
|
413 if (iSockArray) |
|
414 { |
|
415 StopTests(); |
|
416 iSockArray->ResetAndDestroy(); |
|
417 } |
|
418 delete iStopTest; |
|
419 delete iSockArray; |
|
420 } |
|
421 |
|
422 void CActiveReceiverImp::AddTestL(const TTestCase& aTest) |
|
423 // |
|
424 // Add a test case to the receiver |
|
425 // |
|
426 { |
|
427 |
|
428 CActiveSocket* socket = CActiveSocket::NewL(aTest, iSocketServer, iFs); |
|
429 CleanupStack::PushL(socket); |
|
430 iSockArray->AppendL(socket); |
|
431 socket->SetIndex(iSockArray->Count()-1); |
|
432 socket->ReceiveMessage(&iStatus); |
|
433 CleanupStack::Pop(); |
|
434 |
|
435 if (aTest.iMatchType==ESmsAddrStatusReport) |
|
436 { |
|
437 // Add a test to match the original message as well as the status report |
|
438 TTestCase srrIdMatch(aTest.iMsg,aTest.iMsg.Left(TSmsAddr::EMaxTextMatchLength)); |
|
439 AddTestL(srrIdMatch); |
|
440 } |
|
441 } |
|
442 |
|
443 void CActiveReceiverImp::StartTestsL() |
|
444 // |
|
445 // Kick off the tests |
|
446 // |
|
447 { |
|
448 |
|
449 SetActive(); |
|
450 CActiveScheduler::Start(); |
|
451 } |
|
452 |
|
453 void CActiveReceiverImp::StopTests() |
|
454 // |
|
455 // Cancel all active sockets |
|
456 // |
|
457 { |
|
458 |
|
459 for (TInt i=0;i<iSockArray->Count();i++) |
|
460 (*iSockArray)[i]->Cancel(); |
|
461 if (iStopTest) |
|
462 iStopTest->Cancel(); |
|
463 Cancel(); |
|
464 } |
|
465 |
|
466 void CActiveReceiverImp::StopIfKeyPressedL() |
|
467 // |
|
468 // Stop the active scheduler if a key is pressed |
|
469 // |
|
470 { |
|
471 |
|
472 if (!iStopTest) |
|
473 iStopTest=CStopIfKeyPressed::NewL(this); |
|
474 iStopTest->StopIfKeyPressed(); |
|
475 } |
|
476 |
|
477 void CActiveReceiverImp::DoCancel() |
|
478 { |
|
479 |
|
480 TRequestStatus* status = &iStatus; |
|
481 User::RequestComplete(status,KErrCancel); |
|
482 } |
|
483 |
|
484 void CActiveReceiverImp::RunL() |
|
485 // |
|
486 // An active socket has received a message |
|
487 // |
|
488 { |
|
489 |
|
490 TInt index = iStatus.Int(); |
|
491 CActiveSocket* socket = (*iSockArray)[index]; |
|
492 socket->TestResultL(); |
|
493 |
|
494 if (socket->TestComplete()) |
|
495 iResultCount++; |
|
496 else |
|
497 socket->ReceiveMessage(&iStatus); |
|
498 |
|
499 if (iResultCount == iSockArray->Count()) |
|
500 { |
|
501 StopTests(); |
|
502 CActiveScheduler::Stop(); |
|
503 return; |
|
504 } |
|
505 |
|
506 SetActive(); |
|
507 iStatus=KRequestPending; |
|
508 } |
|
509 |
|
510 // |
|
511 // |
|
512 // TTestCase |
|
513 // |
|
514 // |
|
515 |
|
516 TTestCase::TTestCase() |
|
517 // |
|
518 // Constructor |
|
519 // |
|
520 { |
|
521 |
|
522 CommonInit(); |
|
523 } |
|
524 |
|
525 TTestCase::TTestCase(const TDesC& aMsg, const TDesC& aMatch) |
|
526 // |
|
527 // Constructor |
|
528 // |
|
529 : iMatchType(ESmsAddrMatchText), iMsg(aMsg), iMatch(aMatch) |
|
530 { |
|
531 |
|
532 CommonInit(); |
|
533 } |
|
534 |
|
535 void TTestCase::CommonInit() |
|
536 // |
|
537 // Reset member variables |
|
538 // |
|
539 { |
|
540 |
|
541 iTestSmsClass = EFalse; |
|
542 iTestValidityPeriod = EFalse; |
|
543 iTestForever=EFalse; |
|
544 iTestIndicators=EFalse; |
|
545 } |
|
546 |
|
547 TTestCase::TTestCase(const TDesC& aMsg, CSmsInformationElement::TSmsInformationElementIdentifier aIdentifier) |
|
548 // |
|
549 // Constructor |
|
550 // |
|
551 : iMatchType(ESmsAddrMatchIEI), iMsg(aMsg), iIdentifierMatch(aIdentifier) |
|
552 { |
|
553 |
|
554 CommonInit(); |
|
555 } |
|
556 |
|
557 TTestCase::TTestCase(const TDesC& aMsg, TSmsFirstOctet::TSmsStatusReportRequest /*aSRR*/) |
|
558 // |
|
559 // Match on status report - ignore actual value of aSRR |
|
560 // |
|
561 : iMatchType(ESmsAddrStatusReport), iMsg(aMsg) |
|
562 { |
|
563 |
|
564 CommonInit(); |
|
565 } |
|
566 |
|
567 TTestCase::TTestCase(const TDesC& aMsg, TSmsDataCodingScheme::TSmsIndicationType aIndicationType, |
|
568 TSmsDataCodingScheme::TSmsDCSBits7To4 aBits7To4, |
|
569 TSmsDataCodingScheme::TSmsIndicationState aIndicationState) |
|
570 // |
|
571 // Match on a type of message indication |
|
572 // |
|
573 : iMatchType(ESmsAddrMessageIndication), iMsg(aMsg), iIndicationType(aIndicationType), |
|
574 iBits7To4(aBits7To4), iIndicationState(aIndicationState) |
|
575 { |
|
576 |
|
577 __ASSERT_ALWAYS(iBits7To4==TSmsDataCodingScheme::ESmsDCSMessageWaitingIndicationDiscardMessage |
|
578 || iBits7To4==TSmsDataCodingScheme::ESmsDCSMessageWaitingIndication7Bit |
|
579 || iBits7To4==TSmsDataCodingScheme::ESmsDCSMessageWaitingIndicationUCS2, |
|
580 User::Panic(_L("TestCase"), KErrNotSupported)); |
|
581 |
|
582 CommonInit(); |
|
583 iTestIndicators=ETrue; |
|
584 |
|
585 } |
|
586 |
|
587 TTestCase::TTestCase(const TDesC& aMsg) |
|
588 // |
|
589 // Constructor |
|
590 // |
|
591 : iMatchType(ESmsAddrRecvAny), iMsg(aMsg) |
|
592 { |
|
593 |
|
594 CommonInit(); |
|
595 } |
|
596 |
|
597 const TTestCase& TTestCase::operator=(const TTestCase& aTest) |
|
598 // |
|
599 // Assignment operator |
|
600 // |
|
601 { |
|
602 |
|
603 iMatchType = aTest.iMatchType; |
|
604 iMsg.Set(aTest.iMsg); |
|
605 iMatch.Set(aTest.iMatch); |
|
606 iIdentifierMatch = aTest.iIdentifierMatch; |
|
607 iTestForever = aTest.iTestForever; |
|
608 return *this; |
|
609 } |
|
610 |
|
611 void TTestCase::SetSmsClass(TSmsDataCodingScheme::TSmsClass aClass) |
|
612 // |
|
613 // Set Sms Class |
|
614 // |
|
615 { |
|
616 |
|
617 iTestSmsClass = ETrue; |
|
618 iSmsClass = aClass; |
|
619 } |
|
620 |
|
621 void TTestCase::SetValidityPeriod(const TTimeIntervalMinutes& aTimeInterval) |
|
622 // |
|
623 // Set the validity period |
|
624 // |
|
625 { |
|
626 |
|
627 iTestValidityPeriod = ETrue; |
|
628 iValidityPeriod = aTimeInterval; |
|
629 } |
|
630 |
|
631 void TTestCase::SetRecvForever() |
|
632 // |
|
633 // Recv all messages forever |
|
634 // |
|
635 { |
|
636 |
|
637 iTestForever = ETrue; |
|
638 iMatchType = ESmsAddrRecvAny; |
|
639 } |
|
640 |
|
641 |
|
642 // |
|
643 // |
|
644 // CActiveReceiver |
|
645 // |
|
646 // |
|
647 |
|
648 CActiveReceiver* CActiveReceiver::NewL(RSocketServ& aSocketServer, RFs& aFs) |
|
649 { return CActiveReceiverImp::NewL(aSocketServer, aFs); } |
|
650 CActiveReceiver::CActiveReceiver(RSocketServ& aSocketServer, RFs& aFs) |
|
651 : CActive(EPriority), |
|
652 iSocketServer(aSocketServer), |
|
653 iFs(aFs) |
|
654 {} |
|
655 void CActiveReceiver::AddTestL(const TTestCase& /*aTest*/) |
|
656 {} |
|
657 void CActiveReceiver::StartTestsL() |
|
658 {} |
|
659 void CActiveReceiver::StopIfKeyPressedL() |
|
660 {} |
|
661 |
|
662 // |
|
663 // |
|
664 // CActiveSender |
|
665 // |
|
666 // |
|
667 |
|
668 CActiveSender* CActiveSender::NewL(RSocketServ& aSocketServer, |
|
669 RFs& aFs, |
|
670 const TDesC& aTelephoneNumber, |
|
671 const TDesC& aServiceCenterNumber) |
|
672 { return CActiveSenderImp::NewL(aSocketServer, aFs, aTelephoneNumber, aServiceCenterNumber); } |
|
673 CActiveSender::CActiveSender(RSocketServ& aSocketServer, RFs& aFs) |
|
674 : CActive(EPriority), |
|
675 iSocketServer(aSocketServer), |
|
676 iFs(aFs) |
|
677 {} |
|
678 void CActiveSender::StartSendingL() |
|
679 {} |
|
680 void CActiveSender::StopIfKeyPressedL() |
|
681 {} |
|
682 |
|
683 |
|
684 // |
|
685 // |
|
686 // CActiveSenderImp |
|
687 // |
|
688 // |
|
689 |
|
690 CActiveSenderImp* CActiveSenderImp::NewL(RSocketServ& aSocketServer, |
|
691 RFs& aFs, |
|
692 const TDesC& aTelephoneNumber, |
|
693 const TDesC& aServiceCenterNumber) |
|
694 // |
|
695 // Factory |
|
696 // |
|
697 { |
|
698 |
|
699 CActiveSenderImp* actSend = new(ELeave) CActiveSenderImp(aSocketServer, aFs); |
|
700 CleanupStack::PushL(actSend); |
|
701 actSend->iStatus=KRequestPending; |
|
702 actSend->InitRSocketL(); |
|
703 |
|
704 CSmsBuffer* buffer=NULL; |
|
705 buffer=CSmsBuffer::NewL(); |
|
706 actSend->iSmsMessage=CSmsMessage::NewL(aFs, CSmsPDU::ESmsSubmit,buffer); |
|
707 |
|
708 TSmsUserDataSettings smsSettings; |
|
709 smsSettings.SetAlphabet(TSmsDataCodingScheme::ESmsAlphabet7Bit); |
|
710 smsSettings.SetTextCompressed(EFalse); |
|
711 actSend->iSmsMessage->SetUserDataSettingsL(smsSettings); |
|
712 |
|
713 actSend->iSmsMessage->SetToFromAddressL(aTelephoneNumber); |
|
714 actSend->iSmsMessage->SmsPDU().SetServiceCenterAddressL(aServiceCenterNumber); |
|
715 buffer->InsertL(0,_L("Test Message")); |
|
716 |
|
717 CleanupStack::Pop(); // actSend |
|
718 CActiveScheduler::Add(actSend); |
|
719 return actSend; |
|
720 } |
|
721 |
|
722 CActiveSenderImp::CActiveSenderImp(RSocketServ& aSocketServer, RFs& aFs) |
|
723 // |
|
724 // Constructor |
|
725 // |
|
726 :CActiveSender(aSocketServer, aFs) |
|
727 {} |
|
728 |
|
729 CActiveSenderImp::~CActiveSenderImp() |
|
730 // |
|
731 // Destructor |
|
732 // |
|
733 { |
|
734 |
|
735 Cancel(); |
|
736 delete iStopTest; |
|
737 delete iSmsMessage; |
|
738 iSocket.Close(); |
|
739 } |
|
740 |
|
741 void CActiveSenderImp::StartSendingL() |
|
742 // |
|
743 // Kick off the tests |
|
744 // |
|
745 { |
|
746 |
|
747 SendSmsMessageL(); |
|
748 CActiveScheduler::Start(); |
|
749 } |
|
750 |
|
751 void CActiveSenderImp::StopTests() |
|
752 // |
|
753 // Prepare for active scheduler stop |
|
754 // |
|
755 { |
|
756 |
|
757 Cancel(); |
|
758 } |
|
759 |
|
760 void CActiveSenderImp::StopIfKeyPressedL() |
|
761 // |
|
762 // Stop the active scheduler if a key is pressed |
|
763 // |
|
764 { |
|
765 |
|
766 if (!iStopTest) |
|
767 iStopTest=CStopIfKeyPressed::NewL(this); |
|
768 iStopTest->StopIfKeyPressed(); |
|
769 } |
|
770 |
|
771 void CActiveSenderImp::DoCancel() |
|
772 // |
|
773 // Cancel the current send |
|
774 // |
|
775 { |
|
776 |
|
777 iSocket.CancelSend(); |
|
778 } |
|
779 |
|
780 void CActiveSenderImp::SendSmsMessageL() |
|
781 // |
|
782 // Send an SMS message and wait for complete |
|
783 // |
|
784 { |
|
785 |
|
786 RSmsSocketWriteStream writestream(iSocket); |
|
787 iSmsMessage->SmsPDU().SetClass(ETrue, TSmsDataCodingScheme::ESmsClass2); |
|
788 TRAPD(ret,writestream << *iSmsMessage); |
|
789 User::LeaveIfError(ret); |
|
790 TRAP(ret,writestream.CommitL()); |
|
791 User::LeaveIfError(ret); |
|
792 |
|
793 iSocket.Ioctl(KIoctlSendSmsMessage,iStatus,&iIntBuf, KSolSmsProv); |
|
794 SetActive(); |
|
795 } |
|
796 |
|
797 void CActiveSenderImp::RunL() |
|
798 // |
|
799 // An active socket has received a message |
|
800 // |
|
801 { |
|
802 |
|
803 if (iStatus.Int()!=KErrNone) |
|
804 { |
|
805 //gTest.Printf(_L("Error: Send completed with %d\n"),iStatus.Int()); |
|
806 iStopTest->DoCancel(); |
|
807 return; |
|
808 } |
|
809 iCount++; |
|
810 //gTest.Printf(_L("Sent %d messages\n"),iCount); |
|
811 SendSmsMessageL(); |
|
812 } |
|
813 |
|
814 void CActiveSenderImp::InitRSocketL() |
|
815 // |
|
816 // Initialise the sender's socket |
|
817 // |
|
818 { |
|
819 |
|
820 TInt ret=iSocket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol); |
|
821 User::LeaveIfError(ret); |
|
822 TSmsAddr smsAddr; |
|
823 smsAddr.SetSmsAddrFamily(ESmsAddrSendOnly); |
|
824 ret=iSocket.Bind(smsAddr); |
|
825 User::LeaveIfError(ret); |
|
826 } |