|
1 /* |
|
2 * Copyright (c) 2006-2008 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 "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: Send data to User of NAT Connectivity Framework. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "natfwsocketsender.h" |
|
22 #include "natfwsocketmediaconnwrapperlogs.h" |
|
23 |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CNATFWSocketSender::CNATFWSocketSender( ) |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CNATFWSocketSender::CNATFWSocketSender( MNATFWSocketSenderObserver& aObserver, |
|
32 TUint aProtocol ) : CActive(EPriorityUserInput), iProtocol( aProtocol ), |
|
33 iObserver( aObserver ), iSendQueue( CNsmcwSendItem::iOffset ), |
|
34 iQueueIter( iSendQueue ) |
|
35 { |
|
36 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketSender::CNATFWSocketSender" ) |
|
37 |
|
38 CActiveScheduler::Add(this); |
|
39 } |
|
40 |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CNATFWSocketSender::NewL( ) |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CNATFWSocketSender* CNATFWSocketSender::NewL( |
|
47 MNATFWSocketSenderObserver& aObserver, TUint aProtocol ) |
|
48 { |
|
49 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketSender::NewL" ) |
|
50 |
|
51 CNATFWSocketSender* self = |
|
52 new (ELeave) CNATFWSocketSender ( aObserver, aProtocol ); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CNATFWSocketSender::~CNATFWSocketSender() |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CNATFWSocketSender::~CNATFWSocketSender() |
|
63 { |
|
64 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketSender::~CNATFWSocketSender") |
|
65 |
|
66 Cancel(); |
|
67 |
|
68 iQueueIter.SetToFirst(); |
|
69 CNsmcwSendItem* item = iQueueIter++; |
|
70 while ( item ) |
|
71 { |
|
72 iSendQueue.Remove( *item ); |
|
73 delete item; |
|
74 item = iQueueIter++; |
|
75 } |
|
76 } |
|
77 |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // CNATFWSocketSender::SetRemoteAddress( ) |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CNATFWSocketSender::SetRemoteAddress( const TSockAddr& aRemoteAddress, |
|
84 const RSocket& aSocket ) |
|
85 { |
|
86 iRemoteAddress = aRemoteAddress; |
|
87 iSocket = aSocket; |
|
88 } |
|
89 |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CNATFWSocketSender::SendL( ) |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 void CNATFWSocketSender::SendL( const TDesC8& aStreamPortion ) |
|
96 { |
|
97 CNsmcwSendItem* item = NULL; |
|
98 TRAPD( err, item = CNsmcwSendItem::NewL( aStreamPortion ) ); |
|
99 |
|
100 if ( KErrNone == err && item ) |
|
101 { |
|
102 iSendQueue.AddLast( *item ); |
|
103 } |
|
104 else |
|
105 { |
|
106 User::Leave( err ); |
|
107 } |
|
108 if ( !IsActive() ) |
|
109 { |
|
110 SendNextPacket(); |
|
111 } |
|
112 } |
|
113 |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CNATFWSocketSender::SendNextPacket() |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CNATFWSocketSender::SendNextPacket() |
|
120 { |
|
121 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketSender::SendNextPacket" ) |
|
122 |
|
123 iQueueIter.SetToFirst(); |
|
124 CNsmcwSendItem* item = iQueueIter++; |
|
125 if ( item ) |
|
126 { |
|
127 if( KProtocolInetUdp == iProtocol ) |
|
128 { |
|
129 iSocket.SendTo( item->GetData(), iRemoteAddress, 0, iStatus ); |
|
130 } |
|
131 if( KProtocolInetTcp == iProtocol ) |
|
132 { |
|
133 iSocket.Send( item->GetData(), 0, iStatus ); |
|
134 } |
|
135 SetActive(); |
|
136 } |
|
137 |
|
138 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketSender::SendNextPacket - End" ) |
|
139 } |
|
140 |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CNATFWSocketSender::RemoveFromQueue() |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CNATFWSocketSender::RemoveFromQueue() |
|
147 { |
|
148 if ( !( iSendQueue.IsEmpty( ) ) ) |
|
149 { |
|
150 CNsmcwSendItem* item = iSendQueue.First(); |
|
151 iSendQueue.Remove( *item ); |
|
152 delete item; |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // CNATFWSocketSender::RunL( ) |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void CNATFWSocketSender::RunL( ) |
|
162 { |
|
163 __SOCKETMEDIACONNWRAPPER_INT1( |
|
164 "CNATFWSocketSender::RunL iStatus:", iStatus.Int() ) |
|
165 |
|
166 iObserver.SendingCompleted( iStatus.Int() ); |
|
167 |
|
168 if ( KErrNone == iStatus.Int() ) |
|
169 { |
|
170 RemoveFromQueue(); |
|
171 SendNextPacket(); |
|
172 } |
|
173 else |
|
174 { |
|
175 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketSender::RunL - Sending failed" ) |
|
176 |
|
177 iQueueIter.SetToFirst(); |
|
178 CNsmcwSendItem* item = iQueueIter++; |
|
179 while ( item ) |
|
180 { |
|
181 iSendQueue.Remove( *item ); |
|
182 delete item; |
|
183 item = iQueueIter++; |
|
184 } |
|
185 } |
|
186 } |
|
187 |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // CNATFWSocketSender::DoCancel( ) |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 void CNATFWSocketSender::DoCancel( ) |
|
194 { |
|
195 __SOCKETMEDIACONNWRAPPER( "CNATFWSocketSender::DoCancel start" ) |
|
196 |
|
197 iSocket.CancelAll(); |
|
198 } |