|
1 /* |
|
2 * Copyright (c) 2005-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: Provide interface for the client requestin availability class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "musavaconnectionmonitor.h" |
|
21 #include "musavasettingsimp.h" |
|
22 #include "musavanetworkavailability.h" |
|
23 #include "musavaobserver.h" |
|
24 #include "musavaavailability.h" |
|
25 #include "musavasharedobject.h" |
|
26 #include "musavaconnectionmonitorobserver.h" |
|
27 #include "musavasip.h" |
|
28 #include "muslogger.h" |
|
29 |
|
30 #include <e32base.h> |
|
31 #include <sipprofile.h> |
|
32 #include <mmtsy_names.h> |
|
33 |
|
34 // ------------------------------------------------------------------------- |
|
35 // Two-phased constructor. |
|
36 // ------------------------------------------------------------------------- |
|
37 // |
|
38 CMusAvaConnectionMonitor* CMusAvaConnectionMonitor::NewL( |
|
39 CMusAvaSharedObject& aSharedObject ) |
|
40 { |
|
41 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::NewL()" ) |
|
42 CMusAvaConnectionMonitor* self = |
|
43 new( ELeave ) CMusAvaConnectionMonitor( aSharedObject ); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop( self ); |
|
47 MUS_LOG( "mus: [MUSAVA] <- CMusAvaConnectionMonitor::NewL()" ) |
|
48 return self; |
|
49 } |
|
50 |
|
51 |
|
52 // ------------------------------------------------------------------------- |
|
53 // Destructor. |
|
54 // ------------------------------------------------------------------------- |
|
55 // |
|
56 CMusAvaConnectionMonitor::~CMusAvaConnectionMonitor() |
|
57 { |
|
58 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::\ |
|
59 ~CMusAvaConnectionMonitor()" ) |
|
60 iConnectionMonitorObserver.Reset(); |
|
61 iConnectionMonitorObserver.Close(); |
|
62 // Close the monitor when event notifications are no longer required |
|
63 iConnectionMonitor.Close(); |
|
64 |
|
65 MUS_LOG( "mus: [MUSAVA] <- CMusAvaConnectionMonitor::\ |
|
66 ~CMusAvaConnectionMonitor()" ) |
|
67 } |
|
68 |
|
69 // ------------------------------------------------------------------------- |
|
70 // Constructor function. |
|
71 // ------------------------------------------------------------------------- |
|
72 // |
|
73 void CMusAvaConnectionMonitor::EventL(const CConnMonEventBase& aConnMonEvent) |
|
74 { |
|
75 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::EventL()" ) |
|
76 TUint connectionId = aConnMonEvent.ConnectionId(); |
|
77 TInt eventType = aConnMonEvent.EventType(); |
|
78 MUS_LOG1( "Connection ID = %d", connectionId ) |
|
79 MUS_LOG1( "Event type = %d", eventType ) |
|
80 |
|
81 for( TInt i=0; i<iConnectionMonitorObserver.Count(); i++ ) |
|
82 { |
|
83 iConnectionMonitorObserver[i]->EventL( aConnMonEvent ); |
|
84 } |
|
85 MUS_LOG( "mus: [MUSAVA] <- CMusAvaConnectionMonitor::EventL()" ) |
|
86 } |
|
87 |
|
88 |
|
89 // ------------------------------------------------------------------------- |
|
90 // Constructor function. |
|
91 // ------------------------------------------------------------------------- |
|
92 // |
|
93 CMusAvaConnectionMonitor::CMusAvaConnectionMonitor( |
|
94 CMusAvaSharedObject& aSharedObject ): |
|
95 iSharedObj( &aSharedObject ) |
|
96 { |
|
97 } |
|
98 |
|
99 // ------------------------------------------------------------------------- |
|
100 // Second phase constructor. |
|
101 // ------------------------------------------------------------------------- |
|
102 // |
|
103 void CMusAvaConnectionMonitor::ConstructL() |
|
104 { |
|
105 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::ConstructL()" ) |
|
106 User::LeaveIfError( iConnectionMonitor.ConnectL() ); |
|
107 |
|
108 MUS_LOG( "mus: [MUSAVA] <- CMusAvaConnectionMonitor::ConstructL()" ) |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 // ----------------------------------------------------------------------------- |
|
114 void CMusAvaConnectionMonitor::AddAdapterL( |
|
115 MMusAvaConnectionMonitorObserver& aAdapter ) |
|
116 { |
|
117 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::\ |
|
118 AddAdapterL( MMusAvaConnectionMonitorObserver& aAdapter )" ) |
|
119 iConnectionMonitorObserver.AppendL( &aAdapter ); |
|
120 MUS_LOG( "mus: [MUSAVA] <- CMusAvaSip::\ |
|
121 AddAdapterL( MMusAvaConnectionMonitorObserver& aAdapter )" ) |
|
122 } |
|
123 |
|
124 // ------------------------------------------------------------------------- |
|
125 // Created connection ID for multimedia sharing is returned |
|
126 // ------------------------------------------------------------------------- |
|
127 // |
|
128 TUint CMusAvaConnectionMonitor::CreatedConnectionID() |
|
129 { |
|
130 return iConnectionID; |
|
131 } |
|
132 |
|
133 // ------------------------------------------------------------------------- |
|
134 // Connection ID is stored |
|
135 // ------------------------------------------------------------------------- |
|
136 // |
|
137 void CMusAvaConnectionMonitor::SetConnectionID( TUint aConnectionID ) |
|
138 { |
|
139 iConnectionID = aConnectionID; |
|
140 } |
|
141 // ------------------------------------------------------------------------- |
|
142 // Active connection ID for multimedia sharing is returned |
|
143 // ------------------------------------------------------------------------- |
|
144 // |
|
145 TUint CMusAvaConnectionMonitor::ConnectionIDL() |
|
146 { |
|
147 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::ConnectionIDL()" ) |
|
148 TUint iap = 0; //Internet acces point |
|
149 TUint sipIap = 0; //SIP acces point |
|
150 TUint count = 0; //Number of connections |
|
151 TUint id = 0; //Connection ID |
|
152 TUint activeIapID = 0; //Connection ID for active SIP IAP |
|
153 TUint subId = 0; //SubconnectionID |
|
154 TUint subCount; //Subconnectioncount |
|
155 TRequestStatus status; |
|
156 |
|
157 //Fetch number of connections to count |
|
158 count = ConnectionCount(); |
|
159 if ( count == 0 ) |
|
160 { |
|
161 MUS_LOG( "mus: [MUSAVA] Non connections" ) |
|
162 } |
|
163 else |
|
164 { |
|
165 MUS_LOG1( "mus: [MUSAVA] Fetch number of connections: %d", count ) |
|
166 |
|
167 //Fetch internet access point to iap |
|
168 sipIap = MultimediaSharingAccessPointID(); |
|
169 if ( sipIap == 0 ) |
|
170 { |
|
171 MUS_LOG( "mus: [MUSAVA] Non Access Point ID's for app" ) |
|
172 } |
|
173 else |
|
174 { |
|
175 MUS_LOG1( "mus: [MUSAVA] Internet access point for sip: %d", |
|
176 sipIap ) |
|
177 |
|
178 TBool goOn = ETrue; |
|
179 for ( TUint i = 1; i <= count && goOn; i++ ) |
|
180 { |
|
181 //Fetch connectionId to id |
|
182 User::LeaveIfError(iConnectionMonitor.GetConnectionInfo( |
|
183 i, id, subCount )); |
|
184 MUS_LOG1( "mus: [MUSAVA] Connection ID = %d", id ) |
|
185 |
|
186 //Fetch internet access point to iap |
|
187 iConnectionMonitor.GetUintAttribute( id, subId, KIAPId, |
|
188 iap, status ); |
|
189 #ifndef UNIT_TESTING |
|
190 User::WaitForRequest( status ); |
|
191 #endif |
|
192 MUS_LOG1( "mus: [MUSAVA] Internet access point %d ", iap ) |
|
193 |
|
194 // when correct Iap found ... |
|
195 if( iap == sipIap ) |
|
196 { |
|
197 MUS_LOG( "mus: [MUSAVA] Connection ID found" ) |
|
198 activeIapID = id; |
|
199 goOn = EFalse; |
|
200 } |
|
201 } |
|
202 |
|
203 } |
|
204 } |
|
205 MUS_LOG( "mus: [MUSAVA] <- CMusAvaConnectionMonitor::ConnectionIDL()" ) |
|
206 return activeIapID; |
|
207 } |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 // ----------------------------------------------------------------------------- |
|
211 TBool CMusAvaConnectionMonitor::KillPdpContext() |
|
212 { |
|
213 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::KillPdpContext" ) |
|
214 |
|
215 TUint connId = 0; |
|
216 TUint subConnectionCount = 0; |
|
217 TRequestStatus requestStatus; |
|
218 TUint count = ConnectionCount(); |
|
219 TInt ret = 0; |
|
220 TBool retval = EFalse; |
|
221 |
|
222 for ( TUint i = 1; i <= count && !retval; i++ ) |
|
223 { |
|
224 TInt bearerType = 0; |
|
225 iConnectionMonitor.GetIntAttribute( connId, |
|
226 subConnectionCount, |
|
227 KBearer, |
|
228 bearerType, |
|
229 requestStatus ); |
|
230 User::WaitForRequest( requestStatus ); |
|
231 if ( bearerType == EBearerCSD || |
|
232 bearerType == EBearerHSCSD || |
|
233 bearerType == EBearerGPRS || |
|
234 bearerType == EBearerEdgeGPRS || |
|
235 bearerType == EBearerWCDMA || |
|
236 bearerType == EBearerWcdmaCSD ) |
|
237 { |
|
238 MUS_LOG1( "mus: [MUSAVA] now killing connection whose connId \ |
|
239 == <%d>", connId ) |
|
240 ret = iConnectionMonitor.GetConnectionInfo( i, connId, |
|
241 subConnectionCount ); |
|
242 if ( ret == KErrNone ) |
|
243 { |
|
244 ret = iConnectionMonitor.SetBoolAttribute( connId, 0, |
|
245 KConnectionStop, ETrue ); |
|
246 if ( ret == KErrNone ) |
|
247 { |
|
248 retval = ETrue; |
|
249 } |
|
250 } |
|
251 } |
|
252 } |
|
253 MUS_LOG( "mus: [MUSAVA] <- CMusAvaConnectionMonitor::KillPdpContext" ) |
|
254 return retval; |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 // ----------------------------------------------------------------------------- |
|
260 void CMusAvaConnectionMonitor::RemoveAdapter( |
|
261 MMusAvaConnectionMonitorObserver& aAdapter ) |
|
262 { |
|
263 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::\ |
|
264 RemoveAdapter( MMusAvaConnectionMonitorObserver& aAdapter )" ) |
|
265 TInt index = iConnectionMonitorObserver.Find( &aAdapter ); |
|
266 |
|
267 if( index != KErrNotFound ) |
|
268 { |
|
269 iConnectionMonitorObserver.Remove( index ); |
|
270 } |
|
271 MUS_LOG( "mus: [MUSAVA] <- CMusAvaSip::\ |
|
272 RemoveAdapter( MMusAvaConnectionMonitorObserver& aAdapter )" ) |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 // ----------------------------------------------------------------------------- |
|
278 void CMusAvaConnectionMonitor::NotifyEventL() |
|
279 { |
|
280 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::NotifyEventL()" ) |
|
281 iConnectionMonitor.NotifyEventL( *this ); |
|
282 MUS_LOG( "mus: [MUSAVA] <- CMusAvaConnectionMonitor::NotifyEventL()" ) |
|
283 } |
|
284 |
|
285 // ------------------------------------------------------------------------- |
|
286 // Active connection count for multimedia sharing is returned |
|
287 // ------------------------------------------------------------------------- |
|
288 // |
|
289 TUint CMusAvaConnectionMonitor::ConnectionCount() |
|
290 { |
|
291 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::ConnectionCount()" ) |
|
292 TUint count = (TUint) KErrNotFound; |
|
293 TRequestStatus status; |
|
294 |
|
295 iConnectionMonitor.GetConnectionCount( count, status ); |
|
296 #ifndef UNIT_TESTING |
|
297 User::WaitForRequest( status ); |
|
298 #endif |
|
299 if ( status.Int() != KErrNone ) |
|
300 { |
|
301 MUS_LOG( "mus: [MUSAVA] Phone doesn't have any active connections" ) |
|
302 } |
|
303 MUS_LOG( "mus: [MUSAVA] <- CMusAvaConnectionMonitor::ConnectionCount()" ) |
|
304 return count; |
|
305 } |
|
306 |
|
307 // ------------------------------------------------------------------------- |
|
308 // Active Internet Access Point ID for multimedia sharing is returned |
|
309 // ------------------------------------------------------------------------- |
|
310 // |
|
311 TUint CMusAvaConnectionMonitor::MultimediaSharingAccessPointID() |
|
312 { |
|
313 MUS_LOG( "mus: [MUSAVA] -> CMusAvaConnectionMonitor::\ |
|
314 MultimediaSharingAccessPointID()" ) |
|
315 TUint retval = KErrNone; |
|
316 TBool profileCreated = EFalse; |
|
317 TRAPD( err, profileCreated = iSharedObj->MusAvaSip().CreateProfileL() ); |
|
318 if ( err || !profileCreated ) |
|
319 { |
|
320 retval = (TUint)KErrNotFound; |
|
321 } |
|
322 else |
|
323 { |
|
324 CSIPProfile* profile = iSharedObj->MusAvaSip().Profile(); |
|
325 // Get IAP ID |
|
326 MUS_LOG( "mus: [MUSAVA] Get IAP ID" ) |
|
327 |
|
328 TInt ret = profile->GetParameter( KSIPAccessPointId, iProfileId ); |
|
329 if( ret ) |
|
330 { |
|
331 MUS_LOG( "mus: [MUSAVA] IAP ID is not found" ) |
|
332 MUS_LOG( "mus: [MUSAVA] <- CMusAvaConnectionMonitor::\ |
|
333 MultimediaSharingAccessPointID()" ) |
|
334 retval = (TUint)ret; |
|
335 } |
|
336 else |
|
337 { |
|
338 MUS_LOG1( "mus: [MUSAVA] IAP ID = %d", iProfileId ) |
|
339 retval = iProfileId; |
|
340 } |
|
341 } |
|
342 MUS_LOG( "mus: [MUSAVA] <- CMusAvaConnectionMonitor::\ |
|
343 MultimediaSharingAccessPointID()" ) |
|
344 return retval; |
|
345 } |