5
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 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 the License "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: class implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "sysinfoservice.h"
|
|
20 |
#include "sysconnectionrequest.h"
|
|
21 |
#include "sysrequest.h"
|
|
22 |
|
|
23 |
const TInt KGranularity(2);
|
|
24 |
|
|
25 |
// --------------------------------------------------------------------
|
|
26 |
// CConnection::CConnection()
|
|
27 |
// C++ default constructor.
|
|
28 |
// --------------------------------------------------------------------
|
|
29 |
//
|
|
30 |
CConnection::CConnection( TSysRequest::TRequestType aReqType, TInt32 aTransID,
|
|
31 |
ISystemObserver* aObsrver):
|
|
32 |
CActiveRequest(aReqType,aTransID,aObsrver),
|
|
33 |
iConnectionCount(0), iConnectionIndex(1),
|
|
34 |
iConnectionInfoArray(KGranularity),
|
|
35 |
iConnectionInit(ETrue)
|
|
36 |
{
|
|
37 |
}
|
|
38 |
|
|
39 |
// --------------------------------------------------------------------
|
|
40 |
// CConnection::~CConnection()
|
|
41 |
// Destructor.
|
|
42 |
// --------------------------------------------------------------------
|
|
43 |
//
|
|
44 |
CConnection::~CConnection()
|
|
45 |
{
|
|
46 |
Cancel();
|
|
47 |
|
|
48 |
iConnectionInfoArray.Close();
|
|
49 |
iConnMonitor.Close();
|
|
50 |
|
|
51 |
delete iReadConnectionInfo;
|
|
52 |
|
|
53 |
delete iEntity;
|
|
54 |
delete iKey;
|
|
55 |
}
|
|
56 |
|
|
57 |
// --------------------------------------------------------------------
|
|
58 |
// CConnection::NewL
|
|
59 |
// Two-phased constructor, returns instance of this class.
|
|
60 |
// --------------------------------------------------------------------
|
|
61 |
//
|
|
62 |
CConnection* CConnection::NewL(const TSysRequest& aRequest)
|
|
63 |
{
|
|
64 |
CConnection* self;
|
|
65 |
self = new (ELeave) CConnection(aRequest.RequestType(),
|
|
66 |
aRequest.TransactionID(), aRequest.Observer());
|
|
67 |
|
|
68 |
CleanupStack::PushL(self);
|
|
69 |
self->ConstructL (aRequest);
|
|
70 |
CleanupStack::Pop(self);
|
|
71 |
|
|
72 |
return self;
|
|
73 |
}
|
|
74 |
|
|
75 |
// --------------------------------------------------------------------
|
|
76 |
// CConnection::ConstructL
|
|
77 |
// 2nd Phase constructor to allocate required resources for this obj.
|
|
78 |
// --------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
void CConnection::ConstructL(const TSysRequest& aRequest)
|
|
81 |
{
|
|
82 |
//connect
|
|
83 |
User::LeaveIfError(iConnMonitor.ConnectL());
|
|
84 |
|
|
85 |
// Make local copy of SA.
|
|
86 |
iEntity = aRequest.Entity().AllocL();
|
|
87 |
|
|
88 |
iKey = aRequest.Key().AllocL();
|
|
89 |
}
|
|
90 |
|
|
91 |
// --------------------------------------------------------------------
|
|
92 |
// CConnection::Request
|
|
93 |
// Issues connection request.
|
|
94 |
// --------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
TInt CConnection::Request()
|
|
97 |
{
|
|
98 |
TInt err = KErrNone;
|
|
99 |
if( !IsActive() )
|
|
100 |
{
|
|
101 |
//Retrieve all connections.
|
|
102 |
iConnMonitor.GetConnectionCount(iConnectionCount, iStatus);
|
|
103 |
SetActive();
|
|
104 |
if(TSysRequest::ENotification == RequestType())
|
|
105 |
TRAP(err,iConnMonitor.NotifyEventL(*this));
|
|
106 |
}
|
|
107 |
return err;
|
|
108 |
}
|
|
109 |
|
|
110 |
// --------------------------------------------------------------------
|
|
111 |
// CConnection::RunL
|
|
112 |
// Gets called in event of request completion or error situation.
|
|
113 |
// --------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
void CConnection::RunL()
|
|
116 |
{
|
|
117 |
TSysRequest::TRequestType ReqType = RequestType();
|
|
118 |
TInt32 transId = this->TransactionID();
|
|
119 |
TInt error(iStatus.Int());
|
|
120 |
|
|
121 |
if(error >= KErrNone)
|
|
122 |
{
|
|
123 |
// Read All Connected Connection IDs.
|
|
124 |
for(TInt i=1; i<=iConnectionCount; i++)
|
|
125 |
{
|
|
126 |
TUint ConnectioID,IgnoreSubConnects;
|
|
127 |
iConnMonitor.GetConnectionInfo(i, ConnectioID, IgnoreSubConnects);
|
|
128 |
iConnectionIds[i-1] = ConnectioID;
|
|
129 |
}
|
|
130 |
|
|
131 |
// read if thr are connections.
|
|
132 |
if ( iConnectionCount > 0 )
|
|
133 |
{
|
|
134 |
//read the connections.
|
|
135 |
ReadNextConnectionL();
|
|
136 |
}
|
|
137 |
else if( ReqType == TSysRequest::EASyncONESHOT )
|
|
138 |
{
|
|
139 |
//create a copy of SA for response.
|
|
140 |
CConnectionList* connList = CConnectionList::
|
|
141 |
NewL(iConnectionInfoArray);
|
|
142 |
//call observer.
|
|
143 |
TRAP_IGNORE(SystemObserver()->HandleResponseL(*iEntity,*iKey,
|
|
144 |
connList,transId,RequestType(),error));
|
|
145 |
//remove this from active store.
|
|
146 |
ActiveStore::RemoveRequest(transId);
|
|
147 |
}
|
|
148 |
}
|
|
149 |
else // in case error.
|
|
150 |
{
|
|
151 |
//call observer.
|
|
152 |
TRAP_IGNORE(SystemObserver()->HandleResponseL(*iEntity,*iKey,
|
|
153 |
NULL,transId,RequestType(),error));
|
|
154 |
}
|
|
155 |
}
|
|
156 |
|
|
157 |
// --------------------------------------------------------------------
|
|
158 |
// CConnection::HandleConnectionInfoL
|
|
159 |
// Gets called when an ConnectionID Connection information is read.
|
|
160 |
// --------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
void CConnection::HandleConnectionInfoL(CConnectionInfo*& aInfo,TInt error)
|
|
163 |
{
|
|
164 |
TInt32 transId = this->TransactionID();
|
|
165 |
iReadConnectionInfo = NULL;
|
|
166 |
|
|
167 |
if(TSysRequest::ENotification == RequestType())
|
|
168 |
{
|
|
169 |
iConnectionInfoArray.AppendL(aInfo);
|
|
170 |
if( !iConnectionInit )
|
|
171 |
{
|
|
172 |
CConnectionInfo* conninfo = aInfo->CopyL();
|
|
173 |
TRAP_IGNORE(SystemObserver()->HandleResponseL(*iEntity, *iKey,
|
|
174 |
conninfo, transId, RequestType(), error));
|
|
175 |
}
|
|
176 |
}
|
|
177 |
else
|
|
178 |
{
|
|
179 |
//Inc index.
|
|
180 |
++iConnectionIndex;
|
|
181 |
|
|
182 |
//Add connection info to RArrayPointer.
|
|
183 |
if( !error )
|
|
184 |
iConnectionInfoArray.AppendL(aInfo);
|
|
185 |
|
|
186 |
// check if some more connections exists.
|
|
187 |
if( iConnectionIndex <= iConnectionCount)
|
|
188 |
{
|
|
189 |
ReadNextConnectionL();
|
|
190 |
// don't send response.
|
|
191 |
return;
|
|
192 |
}
|
|
193 |
|
|
194 |
//create a ConnectionList object.
|
|
195 |
CConnectionList* connList = CConnectionList::NewL(iConnectionInfoArray);
|
|
196 |
//call observer.
|
|
197 |
TRAP_IGNORE(SystemObserver()->HandleResponseL(*iEntity, *iKey,
|
|
198 |
connList, transId, RequestType(), error));
|
|
199 |
|
|
200 |
// Remove this from active store.
|
|
201 |
ActiveStore::RemoveRequest(TransactionID());
|
|
202 |
}
|
|
203 |
}
|
|
204 |
|
|
205 |
// --------------------------------------------------------------------
|
|
206 |
// CConnection::ReadNextConnectionL
|
|
207 |
// Creates CReadConnectionInfo request for an ConnectionID.
|
|
208 |
// --------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
void CConnection::ReadNextConnectionL()
|
|
211 |
{
|
|
212 |
iReadConnectionInfo = CReadConnectionInfo::NewL(iConnMonitor,
|
|
213 |
iConnectionIds[iConnectionIndex-1],
|
|
214 |
this,CConnectionInfo::EConnected,
|
|
215 |
TSysRequest::EASyncONESHOT);
|
|
216 |
|
|
217 |
iReadConnectionInfo->Request();
|
|
218 |
}
|
|
219 |
|
|
220 |
// --------------------------------------------------------------------
|
|
221 |
// CConnection::DoCancel
|
|
222 |
// cancel any notificatons.
|
|
223 |
// --------------------------------------------------------------------
|
|
224 |
//
|
|
225 |
void CConnection::DoCancel()
|
|
226 |
{
|
|
227 |
TSysRequest::TRequestType ReqType = RequestType();
|
|
228 |
if(ReqType ==TSysRequest::ENotification )
|
|
229 |
iConnMonitor.CancelNotifications();
|
|
230 |
}
|
|
231 |
|
|
232 |
// --------------------------------------------------------------------
|
|
233 |
// CConnection::EventL
|
|
234 |
// gets called whenever there is change in connections.
|
|
235 |
// --------------------------------------------------------------------
|
|
236 |
//
|
|
237 |
void CConnection::EventL(const CConnMonEventBase& aEvent)
|
|
238 |
{
|
|
239 |
TUint connectionId =0;
|
|
240 |
CReadConnectionInfo* rdConnectionInfo = NULL;
|
|
241 |
switch( aEvent.EventType() )
|
|
242 |
{
|
|
243 |
case EConnMonCreateConnection:
|
|
244 |
iConnectionInit = EFalse;
|
|
245 |
CConnMonCreateConnection* eventCreate;
|
|
246 |
eventCreate = (CConnMonCreateConnection*)& aEvent;
|
|
247 |
connectionId = eventCreate->ConnectionId();
|
|
248 |
rdConnectionInfo = CReadConnectionInfo::NewL(iConnMonitor,
|
|
249 |
connectionId,
|
|
250 |
this,
|
|
251 |
CConnectionInfo::EConnected,
|
|
252 |
TSysRequest::ENotification);
|
|
253 |
CleanupStack::PushL(rdConnectionInfo);
|
|
254 |
// get connection details.
|
|
255 |
User::LeaveIfError(rdConnectionInfo->Request());
|
|
256 |
CleanupStack::Pop(rdConnectionInfo);
|
|
257 |
break;
|
|
258 |
|
|
259 |
case EConnMonDeleteConnection:
|
|
260 |
CConnMonDeleteConnection* eventDelete;
|
|
261 |
eventDelete = (CConnMonDeleteConnection*)& aEvent;
|
|
262 |
connectionId = eventDelete->ConnectionId();
|
|
263 |
|
|
264 |
for(TInt i=0; i<iConnectionInfoArray.Count(); i++)
|
|
265 |
{
|
|
266 |
CConnectionInfo* conninfo = iConnectionInfoArray[i];
|
|
267 |
if( connectionId == conninfo->ConnectionId() )
|
|
268 |
{
|
|
269 |
CConnectionInfo* info = conninfo->CopyL();
|
|
270 |
info->SetConnectionState(CConnectionInfo::EDisconnected);
|
|
271 |
TRAP_IGNORE(SystemObserver()->HandleResponseL(
|
|
272 |
*iEntity,*iKey,info,TransactionID(),
|
|
273 |
RequestType(),KErrNone));
|
|
274 |
|
|
275 |
iConnectionInfoArray.Remove(i);
|
|
276 |
delete conninfo;
|
|
277 |
break;
|
|
278 |
}
|
|
279 |
}
|
|
280 |
break;
|
|
281 |
|
|
282 |
default:
|
|
283 |
break;
|
|
284 |
}
|
|
285 |
}
|
|
286 |
|
|
287 |
// --------------------------------------------------------------------
|
|
288 |
// CReadConnectionInfo::CReadConnectionInfo
|
|
289 |
// C++ default constructor.
|
|
290 |
// --------------------------------------------------------------------
|
|
291 |
//
|
|
292 |
CReadConnectionInfo::CReadConnectionInfo( RConnectionMonitor& aConnMon,
|
|
293 |
TUint aConnId, MConnectInfoCallback* aCallBack,
|
|
294 |
CConnectionInfo::TConnectionState aState,
|
|
295 |
TSysRequest::TRequestType aReqType ) :
|
|
296 |
CActive(EPriorityNormal), iConnectionID(aConnId),
|
|
297 |
iCallBack(aCallBack), iConnMon(aConnMon),
|
|
298 |
iState(EInitial), iConnState(aState),iReqType(aReqType)
|
|
299 |
{
|
|
300 |
CActiveScheduler::Add(this);
|
|
301 |
}
|
|
302 |
|
|
303 |
// --------------------------------------------------------------------
|
|
304 |
// CReadConnectionInfo::~CReadConnectionInfo
|
|
305 |
// Destructor.
|
|
306 |
// --------------------------------------------------------------------
|
|
307 |
//
|
|
308 |
CReadConnectionInfo::~CReadConnectionInfo()
|
|
309 |
{
|
|
310 |
Cancel();
|
|
311 |
delete iIAPName;
|
|
312 |
delete iNetworkName;
|
|
313 |
delete iConnectionName;
|
|
314 |
}
|
|
315 |
|
|
316 |
// --------------------------------------------------------------------
|
|
317 |
// CReadConnectionInfo::NewL
|
|
318 |
// Two-phased constructor, returns instance of this class.
|
|
319 |
// --------------------------------------------------------------------
|
|
320 |
//
|
|
321 |
CReadConnectionInfo* CReadConnectionInfo::NewL(RConnectionMonitor& aConnMon,
|
|
322 |
TUint aConnId,MConnectInfoCallback* aCallBack,
|
|
323 |
CConnectionInfo::TConnectionState aState,
|
|
324 |
TSysRequest::TRequestType aReqType )
|
|
325 |
{
|
|
326 |
CReadConnectionInfo* self = new (ELeave) CReadConnectionInfo(aConnMon,
|
|
327 |
aConnId, aCallBack, aState, aReqType);
|
|
328 |
return self;
|
|
329 |
}
|
|
330 |
|
|
331 |
// --------------------------------------------------------------------
|
|
332 |
// CReadConnectionInfo::Request
|
|
333 |
// Issues ConnectionInfo read request.
|
|
334 |
// --------------------------------------------------------------------
|
|
335 |
//
|
|
336 |
TInt CReadConnectionInfo::Request()
|
|
337 |
{
|
|
338 |
if(!IsActive())
|
|
339 |
{
|
|
340 |
TRequestStatus* status = &iStatus;
|
|
341 |
User::RequestComplete(status,KErrNone);
|
|
342 |
SetActive();
|
|
343 |
}
|
|
344 |
return KErrNone;
|
|
345 |
}
|
|
346 |
|
|
347 |
// --------------------------------------------------------------------
|
|
348 |
// CReadConnectionInfo::RunL
|
|
349 |
// Gets called in event of request completion or error situation.
|
|
350 |
// --------------------------------------------------------------------
|
|
351 |
//
|
|
352 |
void CReadConnectionInfo::RunL()
|
|
353 |
{
|
|
354 |
CConnectionInfo* connectionInfo=NULL;
|
|
355 |
|
|
356 |
TInt error(iStatus.Int());
|
|
357 |
if(error >= KErrNone)
|
|
358 |
{
|
|
359 |
switch(iState)
|
|
360 |
{
|
|
361 |
case EInitial:
|
|
362 |
iConnMon.GetUintAttribute(iConnectionID, 0, KIAPId, iIAPId, iStatus);
|
|
363 |
iState = EIAPId;
|
|
364 |
break;
|
|
365 |
|
|
366 |
case EIAPId:
|
|
367 |
iConnMon.GetIntAttribute(iConnectionID, 0, KBearer,iBearerType, iStatus);
|
|
368 |
iState = EBearerType;
|
|
369 |
break;
|
|
370 |
|
|
371 |
case EBearerType:
|
|
372 |
iConnMon.GetStringAttribute(iConnectionID, 0, KIAPName, iNameBuf, iStatus);
|
|
373 |
iState = EIAPName;
|
|
374 |
break;
|
|
375 |
|
|
376 |
case EIAPName:
|
|
377 |
iIAPName = iNameBuf.AllocL();
|
|
378 |
iNameBuf.Zero();
|
|
379 |
|
|
380 |
if(iBearerType == EBearerWLAN )
|
|
381 |
{
|
|
382 |
iConnMon.GetStringAttribute(iConnectionID, 0,
|
|
383 |
KNetworkName, iNameBuf, iStatus);
|
|
384 |
iState = ENetworkName;
|
|
385 |
}
|
|
386 |
else
|
|
387 |
{
|
|
388 |
iConnMon.GetStringAttribute(iConnectionID, 0,
|
|
389 |
KAccessPointName, iNameBuf, iStatus);
|
|
390 |
iState = EIAPConnectionName;
|
|
391 |
}
|
|
392 |
break;
|
|
393 |
|
|
394 |
case ENetworkName :
|
|
395 |
iNetworkName = iNameBuf.AllocL();
|
|
396 |
iNameBuf.Zero();
|
|
397 |
connectionInfo = CConnectionInfo::NewL(iConnectionID, iIAPId,
|
|
398 |
iBearerType, iConnState, *iIAPName,
|
|
399 |
*iNetworkName, KNullDesC);
|
|
400 |
|
|
401 |
iState = EComplete;
|
|
402 |
break;
|
|
403 |
|
|
404 |
case EIAPConnectionName:
|
|
405 |
iConnectionName = iNameBuf.AllocL();
|
|
406 |
iNameBuf.Zero();
|
|
407 |
|
|
408 |
connectionInfo = CConnectionInfo::NewL(iConnectionID, iIAPId,
|
|
409 |
iBearerType, iConnState, *iIAPName,
|
|
410 |
KNullDesC, *iConnectionName);
|
|
411 |
iState = EComplete;
|
|
412 |
}
|
|
413 |
}
|
|
414 |
else
|
|
415 |
{
|
|
416 |
if (iState == EIAPConnectionName || iState == ENetworkName)
|
|
417 |
{
|
|
418 |
connectionInfo = CConnectionInfo::NewL(iConnectionID, iIAPId,
|
|
419 |
iBearerType, iConnState, *iIAPName,
|
|
420 |
KNullDesC, KNullDesC);
|
|
421 |
error = KErrNone;
|
|
422 |
}
|
|
423 |
iState = EComplete;
|
|
424 |
}
|
|
425 |
|
|
426 |
//if not complete read next attribute.
|
|
427 |
if(iState != EComplete)
|
|
428 |
SetActive();
|
|
429 |
else
|
|
430 |
{
|
|
431 |
iCallBack->HandleConnectionInfoL(connectionInfo,error);
|
|
432 |
delete this;
|
|
433 |
}
|
|
434 |
}
|
|
435 |
|
|
436 |
// --------------------------------------------------------------------
|
|
437 |
// CReadConnectionInfo::DoCancel
|
|
438 |
// cancels any ongoing request.
|
|
439 |
// --------------------------------------------------------------------
|
|
440 |
//
|
|
441 |
void CReadConnectionInfo::DoCancel()
|
|
442 |
{
|
|
443 |
if( IsActive() )
|
|
444 |
{
|
|
445 |
switch(iState)
|
|
446 |
{
|
|
447 |
case EIAPId:
|
|
448 |
iConnMon.CancelAsyncRequest(EConnMonGetUintAttribute);
|
|
449 |
break;
|
|
450 |
case EBearerType:
|
|
451 |
iConnMon.CancelAsyncRequest(EConnMonGetIntAttribute);
|
|
452 |
break;
|
|
453 |
case EIAPName:
|
|
454 |
case ENetworkName:
|
|
455 |
case EIAPConnectionName:
|
|
456 |
iConnMon.CancelAsyncRequest(EConnMonGetStringAttribute);
|
|
457 |
break;
|
|
458 |
|
|
459 |
default:
|
|
460 |
iConnMon.CancelNotifications();
|
|
461 |
break;
|
|
462 |
}
|
|
463 |
}
|
|
464 |
}
|
|
465 |
|
|
466 |
// End of file
|