|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // EGetNextDevice state in the PSY Connecting State Machine; should return |
|
15 // the next device from the BT GPS Configuration API |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <bt_sock.h> |
|
20 #include "btgpsgetnextdevice.h" |
|
21 #include "BTGPSDeviceManager.h" |
|
22 #include "BTGPSConnectManagerExt.h" |
|
23 #include "BTGPSHandlerFactory.h" |
|
24 #include "btgpsdevicelistmanager.h" |
|
25 #include "BTGPSLogging.h" |
|
26 |
|
27 /** Static constructor |
|
28 */ |
|
29 CBTGPSGetNextDevice* CBTGPSGetNextDevice::NewL(MBTGPSConnectManagerExt& aManagerExt) |
|
30 { |
|
31 CBTGPSGetNextDevice* self = new (ELeave) CBTGPSGetNextDevice(aManagerExt); |
|
32 CleanupStack::PushL(self); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop(self); |
|
35 return self; |
|
36 } |
|
37 |
|
38 /** Destructor |
|
39 */ |
|
40 CBTGPSGetNextDevice::~CBTGPSGetNextDevice() |
|
41 { |
|
42 if(iIdle) |
|
43 { |
|
44 iIdle->Cancel(); |
|
45 delete iIdle; |
|
46 } |
|
47 } |
|
48 |
|
49 /** Class constructor |
|
50 */ |
|
51 CBTGPSGetNextDevice::CBTGPSGetNextDevice(MBTGPSConnectManagerExt& aManagerExt) |
|
52 : iManagerExt(aManagerExt), |
|
53 iError(KErrNone) |
|
54 { |
|
55 } |
|
56 |
|
57 /** Second phase constructor |
|
58 */ |
|
59 void CBTGPSGetNextDevice::ConstructL() |
|
60 { |
|
61 TRACESTRING("CBTGPSGetNextDevice::ConstructL start...") |
|
62 |
|
63 TInt tempDeviceType; |
|
64 TBTSockAddr deviceAddress; |
|
65 |
|
66 //Set the PSY state back to Connecting, as we are now dealing with a new device |
|
67 iManagerExt.DeviceManager().SetBTDeviceConnectStatus(EBTDeviceConnecting); |
|
68 |
|
69 //construct idle object |
|
70 iIdle = CIdle::NewL(CActive::EPriorityStandard); |
|
71 |
|
72 //Get the next valid device from the BT Device List |
|
73 iError = iManagerExt.DeviceListManager().GetNextDevice(tempDeviceType, deviceAddress); |
|
74 |
|
75 if(iError == KErrNone) |
|
76 { |
|
77 //Valid device in the list, update the device info manager |
|
78 TBTDeviceType deviceType = static_cast<TBTDeviceType>(tempDeviceType); |
|
79 iManagerExt.DeviceManager().SetDeviceInfo(deviceAddress, deviceType); |
|
80 } |
|
81 |
|
82 iIdle->Start(TCallBack(HandlerCompleteCallback, this)); |
|
83 |
|
84 TRACESTRING2("CBTGPSGetNextDevice::ConstructL end...with err: %d", iError) |
|
85 } |
|
86 |
|
87 /** CIdle Handler Complete Callback. This should be called after the ConstrucL |
|
88 function has completed. This allows the object to finish construction and allows |
|
89 the object to continue its operation. |
|
90 */ |
|
91 TInt CBTGPSGetNextDevice::HandlerCompleteCallback(TAny* aAny) |
|
92 { |
|
93 reinterpret_cast<CBTGPSGetNextDevice*>(aAny)->HandlerCompleteNotify(); |
|
94 |
|
95 return KErrNone; |
|
96 } |
|
97 |
|
98 /** Handler Complete |
|
99 */ |
|
100 void CBTGPSGetNextDevice::HandlerCompleteNotify() |
|
101 { |
|
102 iManagerExt.HandlerComplete(EGetNextDevice, iError); |
|
103 } |