|
1 // Copyright (c) 2000-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 |
|
17 #include "WapSocketWatcher.h" |
|
18 #include <watcher.h> |
|
19 |
|
20 #include <wapmessage.h> |
|
21 #include <wapmsgerr.h> |
|
22 |
|
23 // |
|
24 //CWdpPortWatcher |
|
25 // |
|
26 |
|
27 CWdpPortWatcher::CWdpPortWatcher(CWatcherLog& aWatcherLog, TInt aPriority, TUid aBioID, RFs& aFs, TUint16 aWapPort) |
|
28 : CWapPortWatcher(aWatcherLog, aPriority, aBioID, aFs, aWapPort), iRecvPtr(0,0), iDataSize(0), iDataSizePckg(iDataSize) |
|
29 { |
|
30 } |
|
31 |
|
32 CWdpPortWatcher::~CWdpPortWatcher() |
|
33 { |
|
34 Cancel(); |
|
35 CloseConn(); |
|
36 } |
|
37 |
|
38 void CWdpPortWatcher::CloseConn() |
|
39 { |
|
40 //Close the RWDPConn connection |
|
41 delete iWdpConn; |
|
42 iWdpConn=NULL; |
|
43 iRecvNext = ERecvSize; |
|
44 |
|
45 CWapPortWatcher::CloseConn(); //deletes iRecvBuf |
|
46 } |
|
47 |
|
48 void CWdpPortWatcher::DoCancel() |
|
49 { |
|
50 //Cancel outstanding requests |
|
51 if (iWdpConn!=NULL) |
|
52 iWdpConn->CancelRecv(); |
|
53 |
|
54 Complete(KErrCancel); |
|
55 } |
|
56 |
|
57 void CWdpPortWatcher::DoSetupL() |
|
58 { |
|
59 BIOWATCHERLOG(iWatcherLog.Printf(_L("BioWdp: DoSetupL: %S, port %d"), &iBioMsgText, iWapPort)); |
|
60 |
|
61 //Open the RWDPConn connection on port iWapPort |
|
62 iWdpConn = CWapBoundDatagramService::NewL(); |
|
63 User::LeaveIfError(iWdpConn->Connect(Wap::ESMS,iWapPort)); |
|
64 iRecvNext = ERecvSize; |
|
65 } |
|
66 |
|
67 void CWdpPortWatcher::WaitForMessageL() |
|
68 { |
|
69 BIOWATCHERLOG(iWatcherLog.Printf(_L("BioWdp: WaitForMessageL: %S, port %d"), &iBioMsgText, iWapPort)); |
|
70 |
|
71 User::LeaveIfError(iStatus.Int()); |
|
72 |
|
73 //Wait to receive a WDP message on port iWapPort |
|
74 if (iRecvNext == ERecvSize) |
|
75 { |
|
76 User::LeaveIfError(iWdpConn->AwaitRecvDataSize(iDataSizePckg, iStatus)); |
|
77 } |
|
78 else //iRecvNext == ERecv |
|
79 { |
|
80 iRecvPtr.Set(iRecvBuf->Des()); |
|
81 iRecvPtr.Zero(); |
|
82 iRemoteAddress.Zero(); |
|
83 // 0 is an infinate time out, as we just got the recieved size we know a message is waiting |
|
84 User::LeaveIfError(iWdpConn->RecvFrom(iRemoteAddress,iRemotePort,iRecvPtr,iTruncated,iStatus,0)); |
|
85 } |
|
86 |
|
87 //SetActive() is called by CBaseSmsActiveSocketWatcher::DoRunL() |
|
88 } |
|
89 |
|
90 void CWdpPortWatcher::ReceiveL() |
|
91 { |
|
92 BIOWATCHERLOG(iWatcherLog.Printf(_L("BioWdp: ReceiveL: %S, port %d"), &iBioMsgText, iWapPort)); |
|
93 |
|
94 //Receive the WAP Message. |
|
95 User::LeaveIfError(iStatus.Int()); |
|
96 if(iTruncated) // should never happen as we ask for the size and allocate the required buffer |
|
97 User::Leave(KErrOverflow); |
|
98 |
|
99 if (iRecvNext == ERecvSize) |
|
100 { |
|
101 // iRecvBuf should not currently exist because it is deleted after a message is received (below) |
|
102 // or if there is an error (it is deleted by CloseConn()) |
|
103 __ASSERT_DEBUG(iRecvBuf == NULL, PanicWatcher(EBufferNotNull)); |
|
104 iRecvBuf = HBufC8::NewL(iDataSizePckg()); |
|
105 iRecvNext = ERecv; |
|
106 |
|
107 TRequestStatus* status = &iStatus; |
|
108 User::RequestComplete(status, KErrNone); |
|
109 } |
|
110 else //iRecvNext == ERecv |
|
111 { |
|
112 DoReceiveL(iRemoteAddress); |
|
113 delete iRecvBuf; // buffer is no longer required. |
|
114 iRecvBuf = NULL; |
|
115 iRecvNext = ERecvSize; |
|
116 } |
|
117 } |