17 // CLASS HEADER |
17 // CLASS HEADER |
18 #include "CMSRPConnectionManager.h" |
18 #include "CMSRPConnectionManager.h" |
19 #include "MSRPCommon.h" |
19 #include "MSRPCommon.h" |
20 #include "CMSRPConnection.h" |
20 #include "CMSRPConnection.h" |
21 #include "CMSRPConnListener.h" |
21 #include "CMSRPConnListener.h" |
22 #include <CommDbConnPref.h> |
22 #undef __SERIES60_ |
23 #if defined(__SERIES60_) |
23 #if defined(__SERIES60_) |
24 #include <extendedconnpref.h> |
24 #include <extendedconnpref.h> |
25 #endif |
25 #endif |
26 |
26 |
27 // INTERNAL INCLUDES |
27 // INTERNAL INCLUDES |
28 |
28 |
29 // ----------------------------------------------------------------------------- |
29 // ----------------------------------------------------------------------------- |
30 // Constructor |
30 // Constructor |
31 // ----------------------------------------------------------------------------- |
31 // ----------------------------------------------------------------------------- |
32 // |
32 // |
33 CMSRPConnectionManager::CMSRPConnectionManager( const TUint32 aIapID, MMSRPConnectionManagerObserver& aServer ) |
33 CMSRPConnectionManager::CMSRPConnectionManager( const TUint32 aIapID, MMSRPConnectionManagerObserver& aServer ) |
34 : iIapID( aIapID ), iObserver( aServer ) |
34 : iIapID( aIapID ), iObserver( aServer ) |
35 { |
35 { |
36 MSRPLOG( "CMSRPConnectionManager::CMSRPConnectionManager enter" ) |
36 MSRPLOG( "CMSRPConnectionManager::CMSRPConnectionManager enter" ) |
37 MSRPLOG( "CMSRPConnectionManager::CMSRPConnectionManager exit" ) |
37 MSRPLOG( "CMSRPConnectionManager::CMSRPConnectionManager exit" ) |
38 } |
38 } |
59 // CMSRPConnectionManager::ConstructL |
59 // CMSRPConnectionManager::ConstructL |
60 // ----------------------------------------------------------------------------- |
60 // ----------------------------------------------------------------------------- |
61 // |
61 // |
62 void CMSRPConnectionManager::ConstructL( ) |
62 void CMSRPConnectionManager::ConstructL( ) |
63 { |
63 { |
64 MSRPLOG( "CMSRPConnectionManager::ConstructL enter" ) |
64 MSRPLOG( "CMSRPConnectionManager::ConstructL enter" ) |
65 |
65 |
66 TInt status = iSocketServer.Connect(); |
66 TInt status = iSocketServer.Connect(); |
67 if (status != KErrNone) |
67 if (status != KErrNone) |
68 { |
68 { |
69 //iObserver->HandleError(ESocketServerStartFailed, status , *this );//need to pass connmngr as server handles many connmngrs |
69 //iObserver->HandleError(ESocketServerStartFailed, status , *this );//need to pass connmngr as server handles many connmngrs |
70 //User::Leave(status); |
70 //User::Leave(status); |
71 User::Leave(MMSRPConnectionManagerObserver::ESocketServerStartFailed); //leave code instead of observer call, as in constructl itself |
71 User::Leave(MMSRPConnectionManagerObserver::ESocketServerStartFailed); //leave code instead of observer call, as in constructl itself |
72 } |
72 } |
73 |
73 |
74 status = StartInterface(); |
74 status = StartInterface(); |
75 if (status != KErrNone) |
75 if (status != KErrNone) |
76 { |
76 { |
77 User::Leave(MMSRPConnectionManagerObserver::EInterfaceStartFailed); |
77 User::Leave(MMSRPConnectionManagerObserver::EInterfaceStartFailed); |
78 } |
78 } |
79 |
79 |
80 MSRPLOG( "CMSRPConnectionManager::ConstructL exit" ) |
80 MSRPLOG( "CMSRPConnectionManager::ConstructL exit" ) |
81 } |
81 } |
82 |
82 |
83 |
83 |
84 CMSRPConnectionManager::~CMSRPConnectionManager() |
84 CMSRPConnectionManager::~CMSRPConnectionManager() |
85 { |
85 { |
86 MSRPLOG( "CMSRPConnectionManager::~CMSRPConnectionManager enter" ) |
86 MSRPLOG( "CMSRPConnectionManager::~CMSRPConnectionManager enter" ) |
87 |
87 |
88 delete iConnListener; |
88 delete iConnListener; |
89 iConnectionArray.ResetAndDestroy(); |
89 iConnectionArray.ResetAndDestroy(); |
90 iConnectionArray.Close(); |
90 iConnectionArray.Close(); |
91 iHostResolver.Close(); |
91 iHostResolver.Close(); |
92 iConnection.Close(); |
92 iConnection.Close(); |
93 iSocketServer.Close(); |
93 iSocketServer.Close(); |
94 |
94 |
95 MSRPLOG( "CMSRPConnectionManager::~CMSRPConnectionManager exit" ) |
95 MSRPLOG( "CMSRPConnectionManager::~CMSRPConnectionManager exit" ) |
96 } |
96 } |
97 |
97 |
98 |
98 |
99 // ----------------------------------------------------------------------------- |
99 // ----------------------------------------------------------------------------- |
110 { |
110 { |
111 //iObserver->HandleError( MMSRPConnectionManagerObserver::EAddressResolveError, err , *this ); |
111 //iObserver->HandleError( MMSRPConnectionManagerObserver::EAddressResolveError, err , *this ); |
112 User::Leave(MMSRPConnectionManagerObserver::EAddressResolveError); |
112 User::Leave(MMSRPConnectionManagerObserver::EAddressResolveError); |
113 } |
113 } |
114 hostAddr.SetPort(aPort); |
114 hostAddr.SetPort(aPort); |
115 |
115 |
116 MMSRPConnection* connection = CheckConnection( hostAddr, FALSE ); |
116 MMSRPConnection* connection = CheckConnection( hostAddr, FALSE ); |
117 |
117 |
118 if ( !connection ) |
118 if ( !connection ) |
119 { |
119 { |
120 connection = CMSRPConnection::NewL( hostAddr, *this ); |
120 connection = CMSRPConnection::NewL( hostAddr, *this ); |
121 CleanupDeletePushL(connection);//as M class |
121 CleanupDeletePushL(connection);//as M class |
122 //CleanupStack::PushL( connection ); |
122 //CleanupStack::PushL( connection ); |
123 iConnectionArray.AppendL( connection ); |
123 iConnectionArray.AppendL( connection ); |
124 CleanupStack::Pop( ); |
124 CleanupStack::Pop( ); |
125 } |
125 } |
126 |
126 |
127 MSRPLOG( "CMSRPConnectionManager::getConnectionL exit" ) |
127 MSRPLOG( "CMSRPConnectionManager::getConnectionL exit" ) |
128 |
128 |
129 return *connection; |
129 return *connection; |
130 } |
130 } |
131 |
131 |
132 |
132 |
133 // ----------------------------------------------------------------------------- |
133 // ----------------------------------------------------------------------------- |
134 // CMSRPConnectionManager::StartListener |
134 // CMSRPConnectionManager::StartListener |
141 MSRPLOG( "CMSRPConnectionManager::ListenL enter" ) |
141 MSRPLOG( "CMSRPConnectionManager::ListenL enter" ) |
142 if(!iConnListener) |
142 if(!iConnListener) |
143 { |
143 { |
144 iConnListener = CMSRPConnListener::NewL(*this); |
144 iConnListener = CMSRPConnListener::NewL(*this); |
145 } |
145 } |
146 |
146 |
147 TRAPD(err,iConnListener->ListenL()); |
147 TRAPD(err,iConnListener->ListenL()); |
148 |
148 |
149 if(err != KErrNone) |
149 if(err != KErrNone) |
150 { |
150 { |
151 //delete iConnListener; |
151 //delete iConnListener; |
152 //iConnListener = NULL; |
152 //iConnListener = NULL; |
153 //iObserver->HandleError( MMSRPConnectionManagerObserver::EListenerStartError, err , *this );//communicate to server to trigger cleanup |
153 //iObserver->HandleError( MMSRPConnectionManagerObserver::EListenerStartError, err , *this );//communicate to server to trigger cleanup |
154 |
154 |
155 /*subsession can propagate to server (based on error), which handles error*/ |
155 /*subsession can propagate to server (based on error), which handles error*/ |
156 User::Leave(MMSRPConnectionManagerObserver::EListenerStartError); //listenL leaves to subsession |
156 User::Leave(MMSRPConnectionManagerObserver::EListenerStartError); //listenL leaves to subsession |
157 } |
157 } |
158 |
158 |
159 MSRPLOG( "CMSRPConnectionManager::ListenL exit" ) |
159 MSRPLOG( "CMSRPConnectionManager::ListenL exit" ) |
160 |
160 |
161 } |
161 } |
162 |
162 |
163 // ----------------------------------------------------------------------------- |
163 // ----------------------------------------------------------------------------- |
164 // CMSRPConnectionManager::ListenCancel |
164 // CMSRPConnectionManager::ListenCancel |
165 //connection listencancel calls mngr cancel if one registered subsession observer or state notlistening |
165 //connection listencancel calls mngr cancel if one registered subsession observer or state notlistening |
167 // |
167 // |
168 void CMSRPConnectionManager::ListenCancel(MMSRPConnection* aConnection) |
168 void CMSRPConnectionManager::ListenCancel(MMSRPConnection* aConnection) |
169 { |
169 { |
170 MSRPLOG( "CMSRPConnectionManager::ListenCancel enter" ) |
170 MSRPLOG( "CMSRPConnectionManager::ListenCancel enter" ) |
171 if(iConnListener) |
171 if(iConnListener) |
172 { |
172 { |
173 iConnListener->ListenCancel(); |
173 iConnListener->ListenCancel(); |
174 } |
174 } |
175 Remove(aConnection); |
175 Remove(aConnection); |
176 |
176 |
177 MSRPLOG( "CMSRPConnectionManager::ListenCancel exit" ) |
177 MSRPLOG( "CMSRPConnectionManager::ListenCancel exit" ) |
178 } |
178 } |
179 |
179 |
180 |
180 |
181 // ----------------------------------------------------------------------------- |
181 // ----------------------------------------------------------------------------- |
182 // CMSRPConnectionManager::ListenerState |
182 // CMSRPConnectionManager::ListenerState |
184 // |
184 // |
185 void CMSRPConnectionManager::ListenerStateL( TInt aNewState, RSocket* aDataSocket, TInt aStatus ) |
185 void CMSRPConnectionManager::ListenerStateL( TInt aNewState, RSocket* aDataSocket, TInt aStatus ) |
186 { |
186 { |
187 MSRPLOG( "CMSRPConnectionManager::ListenerStateL enter" ) |
187 MSRPLOG( "CMSRPConnectionManager::ListenerStateL enter" ) |
188 if (aNewState == MMSRPListener::EListenAccepted) |
188 if (aNewState == MMSRPListener::EListenAccepted) |
189 { |
189 { |
190 TInetAddr remoteAddr; |
190 TInetAddr remoteAddr; |
191 aDataSocket->RemoteName(remoteAddr); |
191 aDataSocket->RemoteName(remoteAddr); |
192 |
192 |
193 MMSRPConnection* connection = CheckConnection( remoteAddr, TRUE ); |
193 MMSRPConnection* connection = CheckConnection( remoteAddr, TRUE ); |
194 |
194 |
195 if ( !connection ) |
195 if ( !connection ) |
196 { |
196 { |
197 iConnListener->ListenCompletedL(FALSE); |
197 iConnListener->ListenCompletedL(FALSE); |
198 } |
198 } |
199 else |
199 else |
200 { |
200 { |
201 iConnListener->ListenCompletedL(TRUE); |
201 iConnListener->ListenCompletedL(TRUE); |
202 TRAPD(err, connection->ConnectionEstablishedL(MMSRPConnection::EConnected, aDataSocket, aStatus )); |
202 TRAPD(err, connection->ConnectionEstablishedL(MMSRPConnection::EConnected, aDataSocket, aStatus )); |
203 if(err!=KErrNone) |
203 if(err!=KErrNone) |
204 //non leaving on error, introduce separate fn later |
204 //non leaving on error, introduce separate fn later |
205 connection->ConnectionEstablishedL(MMSRPConnection::EError, aDataSocket, err ); |
205 connection->ConnectionEstablishedL(MMSRPConnection::EError, aDataSocket, err ); |
206 } |
206 } |
207 } |
207 } |
208 else if (aNewState == MMSRPListener::ETimedOut || aNewState == MMSRPListener::ETerminate) |
208 else if (aNewState == MMSRPListener::ETimedOut || aNewState == MMSRPListener::ETerminate) |
209 { |
209 { |
210 delete iConnListener; |
210 delete iConnListener; |
211 iConnListener = NULL; |
211 iConnListener = NULL; |
214 else if (aNewState == MMSRPListener::EListenPortError) |
214 else if (aNewState == MMSRPListener::EListenPortError) |
215 { |
215 { |
216 delete iConnListener; |
216 delete iConnListener; |
217 iConnListener = NULL; |
217 iConnListener = NULL; |
218 User::Leave(MMSRPConnectionManagerObserver::EListenPortFailed); |
218 User::Leave(MMSRPConnectionManagerObserver::EListenPortFailed); |
219 //leave here, propagate upto msrpscheduler, in scheduler error intimate server to handle the error |
219 //leave here, propagate upto msrpscheduler, in scheduler error intimate server to handle the error |
220 //instead could intimate observer (server) directly |
220 //instead could intimate observer (server) directly |
221 //iObserver->HandleError( MMSRPConnectionManagerObserver::EListenPortFailed, aStatus , *this ); |
221 //iObserver->HandleError( MMSRPConnectionManagerObserver::EListenPortFailed, aStatus , *this ); |
222 } |
222 } |
223 MSRPLOG( "CMSRPConnectionManager::ListenerStateL exit" ) |
223 MSRPLOG( "CMSRPConnectionManager::ListenerStateL exit" ) |
224 } |
224 } |
237 { |
237 { |
238 return iConnectionArray[ i ]; |
238 return iConnectionArray[ i ]; |
239 } |
239 } |
240 } |
240 } |
241 MSRPLOG( "CMSRPConnectionManager::CheckConnection exit" ) |
241 MSRPLOG( "CMSRPConnectionManager::CheckConnection exit" ) |
242 return NULL; |
242 return NULL; |
243 } |
243 } |
244 |
244 |
245 |
245 |
246 // ----------------------------------------------------------------------------- |
246 // ----------------------------------------------------------------------------- |
247 // CMSRPConnectionManager::StartInterfaceL |
247 // CMSRPConnectionManager::StartInterfaceL |
248 // Activates PDP ctx |
248 // Activates PDP ctx |
249 // ----------------------------------------------------------------------------- |
249 // ----------------------------------------------------------------------------- |
250 // |
250 // |
251 TInt CMSRPConnectionManager::StartInterface() |
251 TInt CMSRPConnectionManager::StartInterface() |
252 { |
252 { |
253 |
253 |
254 MSRPLOG( "CMSRPConnectionManager::StartInterface enter" ) |
254 MSRPLOG( "CMSRPConnectionManager::StartInterface enter" ) |
255 |
255 |
256 TInt status = KErrNone; |
256 TInt status = KErrNone; |
257 //if( !iConnection.SubSessionHandle() ) |
257 //if( !iConnection.SubSessionHandle() ) |
258 { |
258 { |
259 status = iConnection.Open( iSocketServer ); |
259 status = iConnection.Open( iSocketServer ); |
260 } |
260 } |
262 #if defined(__SERIES60_) |
262 #if defined(__SERIES60_) |
263 if (status == KErrNone) |
263 if (status == KErrNone) |
264 { |
264 { |
265 TConnPrefList prefList; |
265 TConnPrefList prefList; |
266 TExtendedConnPref extPrefs; |
266 TExtendedConnPref extPrefs; |
267 |
267 |
268 extPrefs.SetIapId( iIapID ); |
268 extPrefs.SetIapId( iIapID ); |
269 TRAP(status, prefList.AppendL(&extPrefs)); |
269 TRAP(status, prefList.AppendL(&extPrefs)); |
270 if (status == KErrNone) |
270 if (status == KErrNone) |
271 { |
271 { |
272 status = iConnection.Start( prefList ); |
272 status = iConnection.Start( prefList ); |
273 } |
273 } |
274 } |
274 } |
275 #else |
275 #else |
276 if (status == KErrNone) |
276 if (status == KErrNone) |
277 { |
277 { |
278 TCommDbConnPref prefs; |
278 iConnectionPreferences.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
279 prefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
279 iConnectionPreferences.SetDirection( ECommDbConnectionDirectionUnknown ); |
280 prefs.SetDirection( ECommDbConnectionDirectionUnknown ); |
280 iConnectionPreferences.SetIapId( iIapID ); |
281 prefs.SetIapId( iIapID ); |
281 |
282 |
282 status = iConnection.Start( iConnectionPreferences ); |
283 status = iConnection.Start( prefs ); |
283 } |
284 } |
284 #endif |
285 #endif |
285 |
286 |
|
287 MSRPLOG( "CMSRPConnectionManager::StartInterface exit" ) |
286 MSRPLOG( "CMSRPConnectionManager::StartInterface exit" ) |
288 return status; |
287 return status; |
289 |
288 |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CMSRPConnectionManager::ReStartInterface |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 TInt CMSRPConnectionManager::ReStartInterface() |
|
296 { |
|
297 iConnection.Close(); |
|
298 iSocketServer.Close(); |
|
299 |
|
300 TInt error = iSocketServer.Connect(); |
|
301 if ( !error ) |
|
302 { |
|
303 error = StartInterface(); |
|
304 } |
|
305 return error; |
290 } |
306 } |
291 |
307 |
292 // ----------------------------------------------------------------------------- |
308 // ----------------------------------------------------------------------------- |
293 // CMSRPConnectionManager::ResolveIPAddressL |
309 // CMSRPConnectionManager::ResolveIPAddressL |
294 // ----------------------------------------------------------------------------- |
310 // ----------------------------------------------------------------------------- |
299 { |
315 { |
300 MSRPLOG( "CMSRPConnectionManager::ResolveIPAddressL enter" ) |
316 MSRPLOG( "CMSRPConnectionManager::ResolveIPAddressL enter" ) |
301 //RHostResolver hostResolver; |
317 //RHostResolver hostResolver; |
302 TNameEntry entry; |
318 TNameEntry entry; |
303 TBuf< KMaxLengthOfUrl > hostAddr; |
319 TBuf< KMaxLengthOfUrl > hostAddr; |
304 |
320 |
305 if( !iHostResolver.SubSessionHandle() ) |
321 if( !iHostResolver.SubSessionHandle() ) |
306 { |
322 { |
307 User::LeaveIfError( iHostResolver.Open( iSocketServer, KAfInet, |
323 User::LeaveIfError( iHostResolver.Open( iSocketServer, KAfInet, |
308 KProtocolInetTcp, iConnection )); |
324 KProtocolInetTcp, iConnection )); |
309 } |
325 } |
310 |
326 |
311 //CleanupClosePushL( hostResolver ); |
327 //CleanupClosePushL( hostResolver ); |
312 |
328 |
313 hostAddr.Copy( aHost ); |
329 hostAddr.Copy( aHost ); |
314 User::LeaveIfError( iHostResolver.GetByName( hostAddr, entry ) ); |
330 User::LeaveIfError( iHostResolver.GetByName( hostAddr, entry ) ); |
315 if ( !TInetAddr::Cast( entry().iAddr ).IsWildAddr() ) |
331 if ( !TInetAddr::Cast( entry().iAddr ).IsWildAddr() ) |
316 { |
332 { |
317 aAddress = TInetAddr::Cast( entry().iAddr ); |
333 aAddress = TInetAddr::Cast( entry().iAddr ); |
334 return; |
350 return; |
335 } |
351 } |
336 /* Open an RSocket and find its address */ |
352 /* Open an RSocket and find its address */ |
337 RSocket socket; |
353 RSocket socket; |
338 User::LeaveIfError(socket.Open(iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp,iConnection)); |
354 User::LeaveIfError(socket.Open(iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp,iConnection)); |
339 |
355 |
340 CleanupClosePushL(socket); |
356 CleanupClosePushL(socket); |
341 |
357 |
342 TSoInetInterfaceInfo networkInfo; |
358 TSoInetInterfaceInfo networkInfo; |
343 TPckg<TSoInetInterfaceInfo> opt(networkInfo); |
359 TPckg<TSoInetInterfaceInfo> opt(networkInfo); |
344 User::LeaveIfError(socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl)); |
360 User::LeaveIfError(socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl)); |
345 TSoInetIfQuery query; |
361 TSoInetIfQuery query; |
346 TPckg<TSoInetIfQuery> queryBuf(query); |
362 TPckg<TSoInetIfQuery> queryBuf(query); |
347 TInt res = KErrNone; |
363 TInt res = KErrNone; |
348 do |
364 do |
349 { |
365 { |
350 res = socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, opt); |
366 res = socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, opt); |
351 if (!res && opt().iState == EIfUp) |
367 if (!res && opt().iState == EIfUp) |
352 { |
368 { |
353 query.iName = opt().iName; |
369 query.iName = opt().iName; |
369 |
385 |
370 void CMSRPConnectionManager::Remove(MMSRPConnection* aConn) |
386 void CMSRPConnectionManager::Remove(MMSRPConnection* aConn) |
371 { |
387 { |
372 MSRPLOG( "CMSRPConnectionManager::Remove connection enter" ) |
388 MSRPLOG( "CMSRPConnectionManager::Remove connection enter" ) |
373 TInt index = iConnectionArray.Find(aConn); |
389 TInt index = iConnectionArray.Find(aConn); |
374 |
390 |
375 delete iConnectionArray[index]; |
391 delete iConnectionArray[index]; |
376 iConnectionArray.Remove(index); |
392 iConnectionArray.Remove(index); |
377 MSRPLOG( "CMSRPConnectionManager::Remove connection exit" ) |
393 MSRPLOG( "CMSRPConnectionManager::Remove connection exit" ) |
378 } |
394 } |
379 |
395 |
380 |
396 |
381 RSocketServ& CMSRPConnectionManager::SocketServer() |
397 RSocketServ& CMSRPConnectionManager::SocketServer() |
382 { |
398 { |
383 MSRPLOG( "CMSRPConnectionManager::SocketServer fetch enter" ) |
399 MSRPLOG( "CMSRPConnectionManager::SocketServer fetch enter" ) |
384 MSRPLOG( "CMSRPConnectionManager::SocketServer fetch exit" ) |
400 MSRPLOG( "CMSRPConnectionManager::SocketServer fetch exit" ) |
385 return iSocketServer; |
401 return iSocketServer; |
386 |
402 |
387 } |
403 } |
388 |
404 |
389 RConnection& CMSRPConnectionManager::SocketServerConn() |
405 RConnection& CMSRPConnectionManager::SocketServerConn() |
390 { |
406 { |
391 MSRPLOG( "CMSRPConnectionManager::SocketServerConn fetch enter" ) |
407 MSRPLOG( "CMSRPConnectionManager::SocketServerConn fetch enter" ) |
392 MSRPLOG( "CMSRPConnectionManager::SocketServerConn fetch exit" ) |
408 MSRPLOG( "CMSRPConnectionManager::SocketServerConn fetch exit" ) |
393 return iConnection; |
409 return iConnection; |
394 } |
410 } |
395 |
411 |
396 /* |
412 /* |
397 TBool CMSRPConnectionManager::MatchIapId(TUint32 aIapID) |
413 TBool CMSRPConnectionManager::MatchIapId(TUint32 aIapID) |
398 { |
414 { |
399 return (aIapID == iIapID); |
415 return (aIapID == iIapID); |
400 } |
416 } |
401 */ |
417 */ |
402 |
418 |