|
1 /* |
|
2 * Copyright (c) 2007 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: Wrapper class to convert multiplexer connection into object. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "mncmconnectionmultiplexer.h" |
|
21 #include "natfwcandidate.h" |
|
22 #include "ciceconnection.h" |
|
23 #include "icecandidatehandlerdefs.h" |
|
24 #include "icecandidatehandlerlogs.h" |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 CIceConnection::CIceConnection( TUint aStreamId, |
|
29 MNcmConnectionMultiplexer& aMultiplexer, |
|
30 MIceConnectionObserver& aObserver ) |
|
31 : |
|
32 iStreamId( aStreamId ), |
|
33 iMultiplexer( aMultiplexer ), |
|
34 iObserver( aObserver ) |
|
35 { |
|
36 |
|
37 } |
|
38 |
|
39 |
|
40 void CIceConnection::ConstructL( TUint aAddrFamily ) |
|
41 { |
|
42 iMultiplexer.RegisterConnectionObserverL( iStreamId, *this ); |
|
43 iConnectionId |
|
44 = iMultiplexer.CreateConnectionL( iStreamId, aAddrFamily ); |
|
45 |
|
46 TUint32 dummyIap; |
|
47 TInt dummyQos; |
|
48 iMultiplexer.GetStreamInfoL( iStreamId, dummyIap, dummyQos, iProtocol ); |
|
49 |
|
50 iLocalAddress = iMultiplexer.LocalIPAddressL( iStreamId, iConnectionId ); |
|
51 } |
|
52 |
|
53 |
|
54 CIceConnection* CIceConnection::NewL( TUint aStreamId, |
|
55 TUint aAddrFamily, |
|
56 MNcmConnectionMultiplexer& aMultiplexer, |
|
57 MIceConnectionObserver& aObserver ) |
|
58 { |
|
59 CIceConnection* self = CIceConnection::NewLC( |
|
60 aStreamId, aAddrFamily, aMultiplexer, aObserver ); |
|
61 CleanupStack::Pop( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 |
|
66 CIceConnection* CIceConnection::NewLC( TUint aStreamId, |
|
67 TUint aAddrFamily, |
|
68 MNcmConnectionMultiplexer& aMultiplexer, |
|
69 MIceConnectionObserver& aObserver ) |
|
70 { |
|
71 CIceConnection* self = new( ELeave ) CIceConnection( |
|
72 aStreamId, aMultiplexer, aObserver ); |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL( aAddrFamily ); |
|
75 return self; |
|
76 } |
|
77 |
|
78 |
|
79 CIceConnection::~CIceConnection() |
|
80 { |
|
81 TRAP_IGNORE( iMultiplexer.UnregisterConnectionObserverL( |
|
82 iStreamId, *this ) ) |
|
83 |
|
84 TRAP_IGNORE( iMultiplexer.RemoveConnectionL( iStreamId, iConnectionId ) ) |
|
85 iBoundCandidates.ResetAndDestroy(); |
|
86 } |
|
87 |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CIceConnection::StreamId |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 TUint CIceConnection::StreamId() const |
|
94 { |
|
95 return iStreamId; |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CIceConnection::State |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 CIceConnection::TConnectionState CIceConnection::State() const |
|
104 { |
|
105 return iState; |
|
106 } |
|
107 |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // CIceConnection::LocalAddress |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 const TInetAddr& CIceConnection::LocalAddress() const |
|
114 { |
|
115 return iLocalAddress; |
|
116 } |
|
117 |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // CIceConnection::TransportProtocol |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 TUint CIceConnection::TransportProtocol() const |
|
124 { |
|
125 return iProtocol; |
|
126 } |
|
127 |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CIceConnection::ConnectionId |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 TUint CIceConnection::ConnectionId() const |
|
134 { |
|
135 return iConnectionId; |
|
136 } |
|
137 |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // CIceConnection::SetReceivingStateL |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void CIceConnection::SetReceivingStateL( TNATFWStreamingState aState, |
|
144 TConnectionNotifyState aNotifyState ) |
|
145 { |
|
146 __ICEDP( "CIceConnection::SetReceivingStateL" ) |
|
147 |
|
148 iNotifyState = aNotifyState; |
|
149 iMultiplexer.SetReceivingStateL( iStreamId, iConnectionId, aState ); |
|
150 } |
|
151 |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CIceConnection::SetSendingStateL |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CIceConnection::SetSendingStateL( TNATFWStreamingState aState, |
|
158 TConnectionNotifyState aNotifyState, |
|
159 const TInetAddr& aDestAddr ) |
|
160 { |
|
161 __ICEDP( "CIceConnection::SetSendingStateL" ) |
|
162 |
|
163 iNotifyState = aNotifyState; |
|
164 iMultiplexer.SetSendingStateL( |
|
165 iStreamId, iConnectionId, aDestAddr, aState ); |
|
166 } |
|
167 |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CIceConnection::BindWithCandidateL |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CIceConnection::BindWithCandidateL( const CNATFWCandidate& aCandidate ) |
|
174 { |
|
175 CNATFWCandidate* candidate = CNATFWCandidate::NewLC( aCandidate ); |
|
176 iBoundCandidates.AppendL( candidate ); |
|
177 CleanupStack::Pop( candidate ); |
|
178 } |
|
179 |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CIceConnection::IsBoundToCandidate |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 TBool CIceConnection::IsBoundToCandidate( |
|
186 const CNATFWCandidate& aCandidate ) const |
|
187 { |
|
188 TInt index( iBoundCandidates.Count() - 1 ); |
|
189 TBool matchFound( EFalse ); |
|
190 while ( !matchFound && 0 <= index ) |
|
191 { |
|
192 CNATFWCandidate& item( *iBoundCandidates[index] ); |
|
193 if ( aCandidate.Type() == item.Type() && |
|
194 TIceUtils::MatchAddresses( aCandidate.TransportAddr(), |
|
195 item.TransportAddr() ) && |
|
196 TIceUtils::MatchAddresses( aCandidate.Base(), item.Base() ) ) |
|
197 { |
|
198 matchFound = ETrue; |
|
199 } |
|
200 |
|
201 index--; |
|
202 } |
|
203 |
|
204 return matchFound; |
|
205 } |
|
206 |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // From class MNcmConnectionObserver. |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 void CIceConnection::ConnectionNotify( TUint aStreamId, TUint aConnectionId, |
|
213 TConnectionNotifyType aType, TInt aError ) |
|
214 { |
|
215 if ( iStreamId == aStreamId && iConnectionId == aConnectionId ) |
|
216 { |
|
217 __ICEDP( "CIceConnection::ConnectionNotify, CONSUMING" ) |
|
218 |
|
219 if ( ENotifyStateEnabled == iNotifyState ) |
|
220 { |
|
221 MIceConnectionObserver::TNotifyType type |
|
222 = ConvertToIceConnectionEvent( aType ); |
|
223 |
|
224 if ( MIceConnectionObserver::ENotifyFirstMediaPacketSent != type ) |
|
225 { |
|
226 iObserver.ConnectionNotify( *this, type, aError ); |
|
227 } |
|
228 } |
|
229 } |
|
230 } |
|
231 |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CIceConnection::ConvertToIceConnectionEvent |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 MIceConnectionObserver::TNotifyType |
|
238 CIceConnection::ConvertToIceConnectionEvent( |
|
239 MNcmConnectionObserver::TConnectionNotifyType aType ) const |
|
240 { |
|
241 switch ( aType ) |
|
242 { |
|
243 case MNcmConnectionObserver::EConnectionRemoved: |
|
244 return MIceConnectionObserver::ENotifyConnectionRemoved; |
|
245 |
|
246 case MNcmConnectionObserver::EConnectionError: |
|
247 return MIceConnectionObserver::ENotifyConnectionError; |
|
248 |
|
249 case MNcmConnectionObserver::EFirstMediaPacketSent: |
|
250 return MIceConnectionObserver::ENotifyFirstMediaPacketSent; |
|
251 |
|
252 case MNcmConnectionObserver::EReceivingActivated: |
|
253 return MIceConnectionObserver::ENotifyRecvActivated; |
|
254 |
|
255 case MNcmConnectionObserver::EReceivingDeactivated: |
|
256 return MIceConnectionObserver::ENotifyRecvDeactivated; |
|
257 |
|
258 case MNcmConnectionObserver::ESendingActivated: |
|
259 return MIceConnectionObserver::ENotifySendActivated; |
|
260 |
|
261 case MNcmConnectionObserver::ESendingDeactivated: |
|
262 return MIceConnectionObserver::ENotifySendDeactivated; |
|
263 |
|
264 default: |
|
265 ASSERT( EFalse ); |
|
266 return MIceConnectionObserver::ENotifyUnknown; // lint#527 |
|
267 } |
|
268 } |