|
1 // Copyright (c) 2003-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 "WapBoundWDP.h" |
|
17 #include "WapMsgUtils.h" |
|
18 |
|
19 |
|
20 CSWSWapBoundWDPService* CSWSWapBoundWDPService::NewL() |
|
21 /** |
|
22 Static new function |
|
23 @internalComponent |
|
24 @released |
|
25 @since v8.0 |
|
26 */ |
|
27 { |
|
28 CSWSWapBoundWDPService* me = new(ELeave)CSWSWapBoundWDPService(); |
|
29 CleanupStack::PushL(me); |
|
30 me->ConstructL(); |
|
31 CleanupStack::Pop(me); |
|
32 return me; |
|
33 } |
|
34 |
|
35 CSWSWapBoundWDPService::CSWSWapBoundWDPService() |
|
36 : CWapBoundDatagramService() |
|
37 /** |
|
38 Constructor |
|
39 @internalComponent |
|
40 @released |
|
41 @since v8.0 |
|
42 */ |
|
43 { |
|
44 } |
|
45 |
|
46 CSWSWapBoundWDPService::~CSWSWapBoundWDPService() |
|
47 /** |
|
48 Destructor |
|
49 @internalComponent |
|
50 @released |
|
51 @since v8.0 |
|
52 */ |
|
53 { |
|
54 delete iAgent; |
|
55 } |
|
56 |
|
57 void CSWSWapBoundWDPService::ConstructL() |
|
58 /** |
|
59 Second Phase Constructor |
|
60 @internalComponent |
|
61 @released |
|
62 @since v8.0 |
|
63 */ |
|
64 { |
|
65 // Parent class construction |
|
66 CWapBoundDatagramService::ConstructL(); |
|
67 iAgent=CWdpMessageApiAgent::NewL(); |
|
68 } |
|
69 |
|
70 TInt CSWSWapBoundWDPService::Connect(Wap::TBearer aBearer, Wap::TPort aPort, TInetAddr /*aInetAddr*/) |
|
71 /** |
|
72 Connect to the SWS, opening an endpoint that can be used to listen for subsequent incoming datagrams. |
|
73 @internalComponent |
|
74 @released |
|
75 @since v8.0 |
|
76 @param aBearer the bearer to listen on (use EAll for all bearers) |
|
77 @param aPort the port to listen on. If set to 0, a local port will be chosen for the client's first SendTo |
|
78 @param aInetAddr the ip address of the network interface that should be used in a multihomed system. |
|
79 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
80 */ |
|
81 { |
|
82 return iAgent->Connect(aBearer, aPort, EFalse); |
|
83 } |
|
84 |
|
85 TInt CSWSWapBoundWDPService::Connect(Wap::TBearer aBearer, Wap::TPort aPort) |
|
86 /** |
|
87 Connect to the SWS, opening an endpoint that can be used to listen for subsequent incoming datagrams. |
|
88 @internalComponent |
|
89 @released |
|
90 @since v8.0 |
|
91 @param aBearer the bearer to listen on (use EAll for all bearers) |
|
92 @param aPort the port to listen on. If set to 0, a local port will be chosen for the client's first SendTo |
|
93 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
94 */ |
|
95 { |
|
96 TInetAddr inetAddr( KInetAddrAny, 0); |
|
97 return (Connect(aBearer, aPort, inetAddr)); |
|
98 } |
|
99 |
|
100 TInt CSWSWapBoundWDPService::SendTo(const TDesC8& aRemoteHost, Wap::TPort aRemotePort, |
|
101 const TDesC8& aBuffer, Wap::TBearer aBearer) |
|
102 /** |
|
103 Send data to a remote endpoint. |
|
104 @internalComponent |
|
105 @released |
|
106 @since v8.0 |
|
107 @param aRemoteHost the bearer-dependent address of the remote host to which the data will be sent |
|
108 @param aRemotePort the port on the remote host to which the data will be sent |
|
109 @param aBuffer the data buffer to be written over the connection |
|
110 @param aBearer the bearer to be used, if the bound connection was opened with 'all' |
|
111 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
112 */ |
|
113 { |
|
114 return iAgent->SendWdpMessage(aBuffer, aRemoteHost, aRemotePort, aBearer); |
|
115 } |
|
116 |
|
117 TInt CSWSWapBoundWDPService::AwaitRecvDataSize(TPckg<TUint16>& aDataSizePckg, TRequestStatus& aReqStatus) |
|
118 /** |
|
119 Wait for a datagram to be received, and discover how large a buffer is required to retrieve it. |
|
120 This asyncronous method waits for a datagram to be received and will then complete allowing the client to discover how large a buffer |
|
121 is needed to retrieve the entire datagram that has been received. |
|
122 A subsiquent call to RecvFrom with a buffer of sufficent size will then allow the client to retrieve the datagram fully. |
|
123 @internalComponent |
|
124 @released |
|
125 @since v8.0 |
|
126 @param aDataSizePckg the size of data subsequently received, in bytes |
|
127 @param aReqStatus used to signal when a data size is known |
|
128 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
129 */ |
|
130 { |
|
131 return iAgent->AwaitRecvDataSize(aDataSizePckg, aReqStatus); |
|
132 } |
|
133 |
|
134 TInt CSWSWapBoundWDPService::RecvFrom(TDes8& aRemoteHost, Wap::TPort& aRemotePort, TDes8& aBuffer, |
|
135 TBool& aTruncated, TRequestStatus& aReqStatus, TUint32 aTimeout) |
|
136 /** |
|
137 receive data on a bound port. |
|
138 An asynchronous notification is sent to the client when data arrives. |
|
139 @internalComponent |
|
140 @released |
|
141 @since v8.0 |
|
142 @param aRemoteHost the bearer-dependent address of the remote host from which the data was received |
|
143 @param aRemotePort the port on the remote host from which the data was received |
|
144 @param aBuffer a client-allocated data buffer to be filled with data received. Data that overflows the buffer is discarded. |
|
145 @param aTruncated indicates whether the received datagram was truncated to fit in the client's supplied buffer |
|
146 @param aReqStatus used to notify the client that a datagram was received |
|
147 @param aTimeout an optional millisecond time-out which allows a timed read to be made. If no data is received |
|
148 within the timeout period the request completes with KErrTimedOut. If a value of 0 is supplied the timeout is infinite. |
|
149 @retval TInt KErrNone on successful completion, or one of the system error codes on failure. |
|
150 */ |
|
151 { |
|
152 return iAgent->ReceiveWdpMessage(aRemoteHost, aRemotePort, aBuffer, aTruncated, aReqStatus, aTimeout); |
|
153 } |
|
154 |
|
155 void CSWSWapBoundWDPService::CancelRecv() |
|
156 /** |
|
157 Cancel a previously requested asynchronous RecvFrom or AwaitRecvDataSize notification. |
|
158 If a datagram arrives at the local host, it will be discarded. |
|
159 @internalComponent |
|
160 @released |
|
161 @since v8.0 |
|
162 */ |
|
163 { |
|
164 iAgent->CancelRequest(); |
|
165 } |
|
166 |
|
167 TInt CSWSWapBoundWDPService::GetLocalPort(Wap::TPort& aPort) |
|
168 /** |
|
169 Get the local port of this endpoint.Useful if one was chosen automatically. |
|
170 @internalComponent |
|
171 @released |
|
172 @since v8.0 |
|
173 @param aPort the port number |
|
174 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
175 */ |
|
176 { |
|
177 return iAgent->GetLocalPort(aPort); |
|
178 } |
|
179 |
|
180 TInt CSWSWapBoundWDPService::GetLocalAddress(HBufC8*& aLocalHost) |
|
181 /** |
|
182 Get the local address of this endpoint. |
|
183 @internalComponent |
|
184 @released |
|
185 @since v8.0 |
|
186 @param aLocalHost the address of the local host. A reference to a HBufC8 pointer should |
|
187 be passed in. This pointer MUST be null! A HBufC8 will be allocated to hold the address, ownership |
|
188 of this buffer will be passed over to the client. |
|
189 @returns TInt KErrNone on successful completion, or one of the system error codes on failure. |
|
190 */ |
|
191 { |
|
192 return iAgent->GetLocalAddress(aLocalHost); |
|
193 } |
|
194 |
|
195 TInt CSWSWapBoundWDPService::GetBearer(Wap::TBearer& aBearer) |
|
196 /** |
|
197 Get the bearer on which a received datagram arrived. |
|
198 Useful when EAll was specified in Connect() |
|
199 @internalComponent |
|
200 @released |
|
201 @since v8.0 |
|
202 @param aBearer the bearer |
|
203 @returns TInt KErrNone on successful completion, or one of the system error codes on failure. |
|
204 */ |
|
205 { |
|
206 return iAgent->GetBearer(aBearer); |
|
207 } |
|
208 |
|
209 TInt CSWSWapBoundWDPService::GetDatagramSizes(TUint16& aMaxSize, TUint16& aNominalSize) |
|
210 /** |
|
211 Query the WDP bearer for its maximum datagram size and its nominal datagram size. |
|
212 @internalComponent |
|
213 @released |
|
214 @since v8.0 |
|
215 @param aMaxSize the maximum datagram size |
|
216 @param aNominalSize the nominal datagram size (nominal = size within which a datagram won't |
|
217 have to be split into smaller individual messages and then re-assembled at the other end). |
|
218 This will fail for a stream connection |
|
219 @returns KErrNone on successful completion, or one of the system error codes on failure. |
|
220 */ |
|
221 { |
|
222 // Can only retrieve this info from the capcodec when its a connection, not datagram! |
|
223 aMaxSize = KWapStackMaxDatagramSize; |
|
224 aNominalSize = KWapStackNorminalDatagramSize; |
|
225 return KErrNone; |
|
226 } |
|
227 |