|
1 // Copyright (c) 2006-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 |
|
19 // INCLUDE FILES |
|
20 #include "HWRMtrace.h" |
|
21 #include "HWRMFmTxStateUtility.h" |
|
22 #include "HWRMPluginHandler.h" |
|
23 #include "HWRMReservationHandler.h" |
|
24 #include "HWRMFmTxInternalCRKeys.h" |
|
25 #include "HWRMFmTxInternalPSKeys.h" |
|
26 #include "HWRMFmTxAudioPolicyDomainPSKeys.h" |
|
27 #include "HWRMFmTxService.h" |
|
28 #include "HWRMFmTxCommonData.h" |
|
29 #include "HWRMFmTxRdsTextConverter.h" |
|
30 #include "HWRMClientServer.h" |
|
31 #include "HWRMConfiguration.h" |
|
32 #include "HWRMFmTxCommands.h" |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CHWRMFmTxStateUtility::CHWRMFmTxStateUtility |
|
38 // C++ constructor |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CHWRMFmTxStateUtility::CHWRMFmTxStateUtility() : iPreviousState(EFmTxStateUnknown), iEnableStandby(EFalse) |
|
42 { |
|
43 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMFmTxStateUtility::CHWRMFmTxStateUtility()" ) ) ); |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CHWRMFmTxStateUtility::ConstructL |
|
48 // Symbian 2nd phase constructor can leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CHWRMFmTxStateUtility::ConstructL(CHWRMPluginHandler* aPluginHandler, |
|
52 CHWRMPluginHandler* aWatcherPluginHandler, |
|
53 CHWRMReservationHandler* aReservationHandler, |
|
54 CHWRMFmTxCommonData* aFmTxCommonData) |
|
55 { |
|
56 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMFmTxStateUtility::ConstructL()" ) ) ); |
|
57 |
|
58 iFmTxCommonData = aFmTxCommonData; |
|
59 |
|
60 iFmTxStateObserver = CHWRMPSChangeObserver::NewL(*this, KPSUidHWRMFmTx, KHWRMFmTxStatus); |
|
61 iAudioRoutedObserver = CHWRMPSChangeObserver::NewL(*this, KPSUidHWRMFmTx, KHWRMFmTxAudioRoutedFlag); |
|
62 |
|
63 iFmTxService = CHWRMFmTxService::NewL( aPluginHandler, *aWatcherPluginHandler, |
|
64 aReservationHandler, *aFmTxCommonData, *(aFmTxCommonData->GetRdsTextConverter()) ); |
|
65 |
|
66 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMFmTxStateUtility::ConstructL - return " ) ) ); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CHWRMFmTxStateUtility::CancelPowerSaveTimer |
|
71 // Stops and deletes power save timer. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CHWRMFmTxStateUtility::CancelPowerSaveTimer() |
|
75 { |
|
76 COMPONENT_TRACE1( (_L("HWRM Server - CHWRMFmTxStateUtility::CancelPowerSaveTimer()" ) ) ); |
|
77 |
|
78 if( iPowerSaveTimer ) |
|
79 { |
|
80 iPowerSaveTimer->Stop(); |
|
81 delete iPowerSaveTimer; |
|
82 iPowerSaveTimer = NULL; |
|
83 } |
|
84 |
|
85 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMFmTxStateUtility::CancelPowerSaveTimer - return" ) ) ); |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CHWRMFmTxStateUtility::NewL |
|
90 // Two-phased constructor. |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CHWRMFmTxStateUtility* CHWRMFmTxStateUtility::NewL(CHWRMPluginHandler* aPluginHandler, |
|
94 CHWRMPluginHandler* aWatcherPluginHandler, |
|
95 CHWRMReservationHandler* aReservationHandler, |
|
96 CHWRMFmTxCommonData* aFmTxCommonData) |
|
97 { |
|
98 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMFmTxStateUtility::NewL()" ) ) ); |
|
99 |
|
100 CHWRMFmTxStateUtility* self = new( ELeave ) CHWRMFmTxStateUtility(); |
|
101 |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL(aPluginHandler, aWatcherPluginHandler, aReservationHandler, aFmTxCommonData); |
|
104 CleanupStack::Pop( self ); |
|
105 |
|
106 COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxStateUtility::NewL - return 0x%x" ), self ); |
|
107 |
|
108 return self; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------- |
|
112 // Destructor |
|
113 // --------------------------------------------------------- |
|
114 // |
|
115 CHWRMFmTxStateUtility::~CHWRMFmTxStateUtility() |
|
116 { |
|
117 COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxStateUtility::~CHWRMFmTxStateUtility()" ) ); |
|
118 |
|
119 delete iFmTxService; |
|
120 delete iFmTxStateObserver; |
|
121 delete iPowerSaveObserver; |
|
122 delete iAudioRoutedObserver; |
|
123 |
|
124 CancelPowerSaveTimer(); |
|
125 |
|
126 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMFmTxStateUtility::~CHWRMFmTxStateUtility - return" ) ) ); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CHWRMFmTxStateUtility::PSValueChanged |
|
131 // Act on observed PS value changes |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CHWRMFmTxStateUtility::PSValueChanged(const TUid& aUid, TUint32 aKey, TInt aValue) |
|
135 { |
|
136 COMPONENT_TRACE4(_L("HWRM Server - CHWRMFmTxStateUtility::PSValueChanged(0x%x, 0x%x, 0x%x)"), aUid, aKey, aValue); |
|
137 |
|
138 if ( aUid == KPSUidHWRMFmTx && aKey == KHWRMFmTxStatus ) |
|
139 { |
|
140 COMPONENT_TRACE3(_L("HWRM Server - CHWRMFmTxStateUtility::PSValueChanged new state = %d, previous = %d"), aValue, iPreviousState); |
|
141 |
|
142 TFmTxState currentState = static_cast<TFmTxState>(aValue); |
|
143 |
|
144 // Check if the hardware has switched on |
|
145 if ( iFmTxCommonData->IsFmTxHardwareOn(currentState) && |
|
146 !(iFmTxCommonData->IsFmTxHardwareOn(iPreviousState)) ) |
|
147 { |
|
148 // FM Tx disable event may occur during an enable request |
|
149 if ( iFmTxCommonData->IsPowerSaveOn() ) |
|
150 { |
|
151 COMPONENT_TRACE1( (_L("HWRM Server - CHWRMFmTxStateUtility::PSValueChanged - powering down again")) ); |
|
152 iFmTxService->ExecutePluginCommand(HWRMFmTxCommand::ETxOffCmdId); |
|
153 } |
|
154 else // Now set RDS defaults |
|
155 { |
|
156 COMPONENT_TRACE1( (_L("HWRM Server - CHWRMFmTxStateUtility::PSValueChanged - setting PS")) ); |
|
157 HWRMFmTxCommand::TRdsPsPackage pckg( iFmTxCommonData->ConvertedRdsPs() ); // package up the request |
|
158 iFmTxService->ExecutePluginCommand(HWRMFmTxCommand::ESetTxRdsPsCmdId, EFalse/*not split*/, pckg); |
|
159 if( iFmTxCommonData->IsAudioRouted() || iPreviousState == EFmTxStatePowerSaveInactivity ) |
|
160 { |
|
161 iEnableStandby = ETrue; |
|
162 } |
|
163 else |
|
164 { |
|
165 iEnableStandby = EFalse; |
|
166 } |
|
167 } |
|
168 } |
|
169 else if ( iFmTxCommonData->IsFmTxHardwareOn(currentState) && |
|
170 !iFmTxCommonData->IsAudioRouted() ) |
|
171 { |
|
172 iEnableStandby = ETrue; |
|
173 } |
|
174 |
|
175 // Cache state for next time |
|
176 iPreviousState = currentState; |
|
177 |
|
178 // Stop power save timer if Fm Tx state is set off. |
|
179 if( currentState == EFmTxStateOff ) |
|
180 { |
|
181 CancelPowerSaveTimer(); |
|
182 } |
|
183 } |
|
184 |
|
185 else if ( aUid == KPSUidHWRMFmTx && aKey == KHWRMFmTxAudioRoutedFlag ) |
|
186 { |
|
187 // Update FM Tx status |
|
188 iFmTxCommonData->UpdateAudioStatus( aValue ); |
|
189 if( aValue && iFmTxCommonData->Status() == EFmTxStatePowerSaveInactivity ) |
|
190 { |
|
191 COMPONENT_TRACE1( _L("HWRM Server - CHWRMFmTxStateUtility::PSValueChanged - powering up from standby") ); |
|
192 HWRMFmTxCommand::TSetFrequencyPackage pckg( iFmTxCommonData->Frequency() ); |
|
193 iFmTxService->ExecutePluginCommand(HWRMFmTxCommand::ETxOnCmdId, EFalse/*not split*/, pckg); |
|
194 } |
|
195 } |
|
196 // Check if KHWRFmTxAudioRoutedFlag is set off and FM TX is still enabled |
|
197 if( !iFmTxCommonData->IsAudioRouted() |
|
198 && iFmTxCommonData->Status() == EFmTxStateInactive |
|
199 && !iPowerSaveTimer ) |
|
200 { |
|
201 TRAPD( err, iPowerSaveTimer = CHWRMFmTxPowerSaveTimer::NewL( *this ) ); |
|
202 if( err != KErrNone ) |
|
203 { |
|
204 COMPONENT_TRACE2(_L("HWRM Server - CHWRMFmTxStateUtility::PSValueChanged - Couldn't create power save timer cause %d"), err); |
|
205 } |
|
206 else |
|
207 { |
|
208 iPowerSaveTimer->Start(iFmTxCommonData->PowerSaveTimeout()); |
|
209 } |
|
210 } |
|
211 else if( iFmTxCommonData->IsAudioRouted() ) |
|
212 { |
|
213 CancelPowerSaveTimer(); |
|
214 iEnableStandby = EFalse; |
|
215 } |
|
216 COMPONENT_TRACE1( (_L("HWRM Server - CHWRMFmTxStateUtility::PSValueChanged - return") ) ); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CHWRMFmTxStateUtility::ProcessIndicationL |
|
221 // Handles status change indications from HWRM plugin |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 void CHWRMFmTxStateUtility::ProcessIndicationL( const TUint32 aId, TDesC8& aData ) |
|
225 { |
|
226 COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxStateUtility::ProcessIndicationL, aId = %d" ), aId ); |
|
227 |
|
228 switch ( aId ) |
|
229 { |
|
230 case HWRMFmTxCommand::ETxWatcherConnIndId: |
|
231 { |
|
232 HWRMFmTxCommand::TConnStatusPackage pckg; |
|
233 pckg.Copy( aData ); |
|
234 HWRMFmTxCommand::TConnStatusData data( pckg() ); |
|
235 |
|
236 if( data.iConnected ) |
|
237 { |
|
238 // Update common data power save state if necessary |
|
239 if ( iFmTxCommonData->IsFmTxHardwareOn() || |
|
240 iFmTxCommonData->IsPowerSaveOn() ) |
|
241 { |
|
242 // Update common data power save state if necessary |
|
243 iFmTxCommonData->UpdatePowerSaveState( |
|
244 CHWRMFmTxCommonData::EHWRMFmTxPowerSaveAccessory ); |
|
245 } |
|
246 } |
|
247 else |
|
248 { |
|
249 // Reset power save accessory state, if necessary |
|
250 if ( iFmTxCommonData->IsAccessoryPowerSaveOn() ) |
|
251 { |
|
252 iFmTxCommonData->UpdatePowerSaveState( |
|
253 CHWRMFmTxCommonData::EHWRMFmTxPowerSaveOff ); |
|
254 } |
|
255 } |
|
256 |
|
257 // Switch off transmitter. As specified in client interface state |
|
258 // transition from EFmTxStatePowerSaveAccessory to EFmTxStateOff must occur. |
|
259 iFmTxService->ExecutePluginCommand(HWRMFmTxCommand::ETxOffCmdId); |
|
260 // Don't change iFmTxState until power down completes |
|
261 } |
|
262 break; |
|
263 |
|
264 default: |
|
265 // do nothing |
|
266 break; |
|
267 } |
|
268 |
|
269 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMFmTxStateUtility::ProcessIndicationL - return" ) ) ); |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CHWRMFmTxStateUtility::TimerExpired |
|
274 // This method is called by Power Save Timer, after timer expires. |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 void CHWRMFmTxStateUtility::TimerExpired() |
|
278 { |
|
279 COMPONENT_TRACE1( (_L("HWRM Server - CHWRMFmTxStateUtility::TimerExpired()" ) ) ); |
|
280 |
|
281 delete iPowerSaveTimer; |
|
282 iPowerSaveTimer = NULL; |
|
283 // Power down the transmitter, if necessary |
|
284 if ( iFmTxCommonData->IsFmTxHardwareOn() && !iFmTxCommonData->IsAudioRouted() ) |
|
285 { |
|
286 if( iEnableStandby ) |
|
287 { |
|
288 iFmTxCommonData->UpdatePowerSaveState( CHWRMFmTxCommonData::EHWRMFmTxPowerSaveInactivity ); |
|
289 iEnableStandby = EFalse; |
|
290 } |
|
291 else |
|
292 { |
|
293 iFmTxCommonData->UpdatePowerSaveState( CHWRMFmTxCommonData::EHWRMFmTxPowerSaveOff ); |
|
294 } |
|
295 iFmTxService->ExecutePluginCommand(HWRMFmTxCommand::ETxOffCmdId); |
|
296 // Don't change iFmTxState until power down completes |
|
297 } |
|
298 COMPONENT_TRACE1( ( _L( "HWRM Server - CHWRMFmTxStateUtility::TimerExpired - return" ) ) ); |
|
299 } |
|
300 |
|
301 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
302 |
|
303 // End of File |