|
1 // Copyright (c) 2004-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 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <e32std.h> |
|
20 #include "BTGPSPowerManager.h" |
|
21 #include "BTGPSConnectManager.h" |
|
22 #include "BTGPSPsyConnectionManager.h" |
|
23 #include "BTGPSDeviceManager.h" |
|
24 #include "BTGPSConstantsManager.h" |
|
25 #include "BTGPSRequestHandler.h" |
|
26 #include "BTGPSLogging.h" |
|
27 |
|
28 // EXTERNAL DATA STRUCTURES |
|
29 |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // MACROS |
|
35 |
|
36 // LOCAL CONSTANTS AND MACROS |
|
37 |
|
38 // MODULE DATA STRUCTURES |
|
39 |
|
40 // LOCAL FUNCTION PROTOTYPES |
|
41 |
|
42 // FORWARD DECLARATIONS |
|
43 |
|
44 // ============================= LOCAL FUNCTIONS =============================== |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS =============================== |
|
47 |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CBTGPSPowerManager::NewL |
|
51 // ----------------------------------------------------------------------------- |
|
52 CBTGPSPowerManager* CBTGPSPowerManager::NewL( |
|
53 CBTGPSConnectManager& aConnectManager, |
|
54 CBTGPSPsyConnectionManager& aPsyConnectionManager, |
|
55 CBTGPSDeviceManager& aDeviceManager, |
|
56 CBTGPSConstantsManager& aConstantsManager) |
|
57 { |
|
58 CBTGPSPowerManager* self = new (ELeave) CBTGPSPowerManager( |
|
59 aConnectManager, |
|
60 aPsyConnectionManager, |
|
61 aDeviceManager, |
|
62 aConstantsManager); |
|
63 CleanupStack::PushL(self); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CBTGPSPowerManager::~CBTGPSPowerManager |
|
71 // ----------------------------------------------------------------------------- |
|
72 CBTGPSPowerManager::~CBTGPSPowerManager() |
|
73 { |
|
74 if(iTimer!=NULL) |
|
75 { |
|
76 iTimer->Cancel(); |
|
77 delete iTimer; |
|
78 } |
|
79 iPsyConnectionManager.RemoveListener(*this); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CBTGPSPowerManager::ConstructL |
|
84 // ----------------------------------------------------------------------------- |
|
85 void CBTGPSPowerManager::ConstructL() |
|
86 { |
|
87 iPsyConnectionManager.AddListenerL(*this); |
|
88 |
|
89 //Construct timer |
|
90 iTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CBTGPSPowerManager::CBTGPSPowerManager |
|
95 // C++ default constructor can NOT contain any code, that |
|
96 // might leave. |
|
97 // ----------------------------------------------------------------------------- |
|
98 CBTGPSPowerManager::CBTGPSPowerManager( |
|
99 CBTGPSConnectManager& aConnectManager, |
|
100 CBTGPSPsyConnectionManager& aPsyConnectionManager, |
|
101 CBTGPSDeviceManager& aDeviceManager, |
|
102 CBTGPSConstantsManager& aConstantsManager) |
|
103 : iConnectManager(aConnectManager), |
|
104 iPsyConnectionManager(aPsyConnectionManager), |
|
105 iDeviceManager(aDeviceManager), |
|
106 iConstantsManager(aConstantsManager) |
|
107 { |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CBTGPSPowerManager::HandlePsyConnectionChange |
|
112 // ----------------------------------------------------------------------------- |
|
113 void CBTGPSPowerManager::HandlePsyConnectionChange() |
|
114 { |
|
115 CheckTimer(); |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CBTGPSPowerManager::BTDeviceStatusChanged |
|
120 // ----------------------------------------------------------------------------- |
|
121 void CBTGPSPowerManager::BTDeviceStatusChanged( |
|
122 TInt /*aConnectStatus*/, |
|
123 TInt /*aDeviceType*/, |
|
124 TInt /*aErr*/) |
|
125 { |
|
126 CheckTimer(); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CBTGPSPowerManager::CheckTimer |
|
131 // ----------------------------------------------------------------------------- |
|
132 void CBTGPSPowerManager::CheckTimer() |
|
133 { |
|
134 if( CBTGPSRequestHandler::ConstantsManager().iUtilisePowerSaving && |
|
135 iPsyConnectionManager.LocationRequestCount()==0 && |
|
136 iDeviceManager.DeviceConnectStatus() == EBTDeviceConnected && |
|
137 iDeviceManager.IsGpsConnected() ) |
|
138 { |
|
139 if(!iTimer->IsActive()) |
|
140 { |
|
141 TRACESTRING("CBTGPSPowerManager::CheckTimer timer start") |
|
142 iTimer->Start( |
|
143 iConstantsManager.iInactivityDelay, |
|
144 iConstantsManager.iInactivityDelay, |
|
145 TCallBack(TimerCallback, this)); |
|
146 } |
|
147 } |
|
148 else |
|
149 { |
|
150 TRACESTRING("CBTGPSPowerManager::CheckTimer timer cancel") |
|
151 iTimer->Cancel(); |
|
152 } |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CBTGPSPowerManager::TimerTick |
|
157 // ----------------------------------------------------------------------------- |
|
158 void CBTGPSPowerManager::TimerTick() |
|
159 { |
|
160 TRACESTRING("CBTGPSPowerManager::TimerTick start...") |
|
161 //close connection |
|
162 iTimer->Cancel(); |
|
163 iConnectManager.CancelConnecting(); |
|
164 TRACESTRING("CBTGPSPowerManager::TimerTick end") |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CBTGPSPowerManager::TimerCallback |
|
169 // ----------------------------------------------------------------------------- |
|
170 TInt CBTGPSPowerManager::TimerCallback(TAny* aAny) |
|
171 { |
|
172 reinterpret_cast<CBTGPSPowerManager*>(aAny)->TimerTick(); |
|
173 return KErrNone; |
|
174 } |
|
175 |
|
176 // End of File |
|
177 |
|
178 |
|
179 |