|
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 // INCLUDE FILES |
|
19 #include <centralrepository.h> |
|
20 #include <cenrepnotifyhandler.h> |
|
21 #include <hwrm/hwrmfmtx.h> |
|
22 #include "HWRMtrace.h" |
|
23 #include "HWRMFmTxInternalCRKeys.h" |
|
24 #include "HWRMFmTxFrequencyObserver.h" |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CHWRMFmTxFrequencyObserver::CHWRMFmTxFrequencyObserver |
|
30 // C++ constructor |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CHWRMFmTxFrequencyObserver::CHWRMFmTxFrequencyObserver() |
|
34 { |
|
35 COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::CHWRMFmTxFrequencyObserver()" ) ); |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CHWRMFmTxFrequencyObserver::ConstructL |
|
40 // Symbian 2nd phase constructor can leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 void CHWRMFmTxFrequencyObserver::ConstructL(MHWRMFmTxObserver* aCallback) |
|
44 { |
|
45 COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::ConstructL(0x%x)" ), aCallback ); |
|
46 |
|
47 // To get access to cenrep |
|
48 iRepository = CRepository::NewL(KCRUidFmTxCenRes); |
|
49 |
|
50 // Register for central repository notifications |
|
51 iFreqNotify = CCenRepNotifyHandler::NewL(*this, *iRepository, |
|
52 CCenRepNotifyHandler::EIntKey, KFmTxCenResKeyFrequency); |
|
53 iMinFreqNotify = CCenRepNotifyHandler::NewL(*this, *iRepository, |
|
54 CCenRepNotifyHandler::EIntKey, KFmTxCenResKeyMinFrequency); |
|
55 iMaxFreqNotify = CCenRepNotifyHandler::NewL(*this, *iRepository, |
|
56 CCenRepNotifyHandler::EIntKey, KFmTxCenResKeyMaxFrequency); |
|
57 iStepSizeNotify = CCenRepNotifyHandler::NewL(*this, *iRepository, |
|
58 CCenRepNotifyHandler::EIntKey, KFmTxCenResKeyStepSize); |
|
59 |
|
60 iFreqNotify->StartListeningL(); |
|
61 iMinFreqNotify->StartListeningL(); |
|
62 iMaxFreqNotify->StartListeningL(); |
|
63 iStepSizeNotify->StartListeningL(); |
|
64 |
|
65 iCallback = aCallback; |
|
66 |
|
67 // Get previous/default FM Tx frequency |
|
68 TInt err = iRepository->Get(KFmTxCenResKeyFrequency, iFrequency); |
|
69 if ( err != KErrNone ) |
|
70 { |
|
71 COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::ConstructL - Unable to read KFmTxCenResKeyFrequency from Cenrep" ) ); |
|
72 User::Leave(err); |
|
73 } |
|
74 |
|
75 // Get FM Tx frequency range |
|
76 err = iRepository->Get(KFmTxCenResKeyMinFrequency, iMinFrequency); |
|
77 if ( err != KErrNone ) |
|
78 { |
|
79 COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::ConstructL - Unable to read KFmTxCenResKeyMinFrequency from Cenrep" ) ); |
|
80 User::Leave(err); |
|
81 } |
|
82 err = iRepository->Get(KFmTxCenResKeyMaxFrequency, iMaxFrequency); |
|
83 if ( err != KErrNone ) |
|
84 { |
|
85 COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::ConstructL - Unable to read KFmTxCenResKeyMaxFrequency from Cenrep" ) ); |
|
86 User::Leave(err); |
|
87 } |
|
88 err = iRepository->Get(KFmTxCenResKeyStepSize, iStepSize); |
|
89 if ( err != KErrNone ) |
|
90 { |
|
91 COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::ConstructL - Unable to read KFmTxCenResKeyStepSize from Cenrep" ) ); |
|
92 User::Leave(err); |
|
93 } |
|
94 |
|
95 COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::ConstructL - return, iFrequency = %d " ), iFrequency ); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CHWRMFmTxFrequencyObserver::NewL |
|
100 // Two-phased constructor. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 CHWRMFmTxFrequencyObserver* CHWRMFmTxFrequencyObserver::NewL(MHWRMFmTxObserver* aCallback) |
|
104 { |
|
105 COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::NewL(0x%x)" ), aCallback ); |
|
106 |
|
107 CHWRMFmTxFrequencyObserver* self = new( ELeave ) CHWRMFmTxFrequencyObserver(); |
|
108 |
|
109 CleanupStack::PushL( self ); |
|
110 self->ConstructL(aCallback); |
|
111 CleanupStack::Pop( self ); |
|
112 |
|
113 COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::NewL - return 0x%x" ), self ); |
|
114 |
|
115 return self; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------- |
|
119 // Destructor |
|
120 // --------------------------------------------------------- |
|
121 // |
|
122 CHWRMFmTxFrequencyObserver::~CHWRMFmTxFrequencyObserver() |
|
123 { |
|
124 COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::~CHWRMFmTxFrequencyObserver()" ) ); |
|
125 |
|
126 delete iFreqNotify; |
|
127 delete iMinFreqNotify; |
|
128 delete iMaxFreqNotify; |
|
129 delete iStepSizeNotify; |
|
130 delete iRepository; |
|
131 |
|
132 COMPONENT_TRACE1( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::~CHWRMFmTxFrequencyObserver - return" ) ); |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CHWRMFmTxFrequencyObserver::HandleNotifyInt |
|
137 // Callback to handle Central Repository notifications |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CHWRMFmTxFrequencyObserver::HandleNotifyInt(TUint32 aId, TInt aNewValue) |
|
141 { |
|
142 COMPONENT_TRACE3(_L("HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::HandleNotifyInt(0x%x, 0x%x)"), aId, aNewValue); |
|
143 |
|
144 switch (aId) |
|
145 { |
|
146 case KFmTxCenResKeyFrequency: |
|
147 { |
|
148 COMPONENT_TRACE1(_L("HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::HandleNotifyInt KFmTxCenResKeyFrequency") ); |
|
149 iFrequency = aNewValue; |
|
150 |
|
151 if (iCallback) |
|
152 { |
|
153 // Inform user about change of the FM Tx frequency |
|
154 iCallback->FmTxFrequencyChanged(aNewValue); |
|
155 } |
|
156 } |
|
157 break; |
|
158 |
|
159 case KFmTxCenResKeyMinFrequency: |
|
160 { |
|
161 COMPONENT_TRACE1(_L("HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::HandleNotifyInt KFmTxCenResKeyMinFrequency") ); |
|
162 iMinFrequency = aNewValue; |
|
163 } |
|
164 break; |
|
165 |
|
166 case KFmTxCenResKeyMaxFrequency: |
|
167 { |
|
168 COMPONENT_TRACE1(_L("HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::HandleNotifyInt KFmTxCenResKeyMaxFrequency") ); |
|
169 iMaxFrequency = aNewValue; |
|
170 } |
|
171 break; |
|
172 |
|
173 case KFmTxCenResKeyStepSize: |
|
174 { |
|
175 COMPONENT_TRACE1(_L("HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::HandleNotifyInt KFmTxCenResKeyStepSize") ); |
|
176 iStepSize = aNewValue; |
|
177 } |
|
178 break; |
|
179 |
|
180 default: |
|
181 // do nothing |
|
182 break; |
|
183 } |
|
184 |
|
185 COMPONENT_TRACE1(_L("HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::HandleNotifyInt - return") ); |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CHWRMFmTxFrequencyObserver::HandleNotifyError |
|
190 // Callback to handle Central Repository error notifications |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 #if defined(COMPONENT_TRACE_FLAG) && defined(_DEBUG) |
|
194 void CHWRMFmTxFrequencyObserver::HandleNotifyError(TUint32 aId, TInt error, CCenRepNotifyHandler* aHandler) |
|
195 |
|
196 #else |
|
197 void CHWRMFmTxFrequencyObserver::HandleNotifyError(TUint32 /*aId*/, TInt /*error*/, CCenRepNotifyHandler* aHandler) |
|
198 #endif |
|
199 { |
|
200 COMPONENT_TRACE4(_L("HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::HandleNotifyError(0x%x, 0x%x, 0x%x)"), aId, error, aHandler); |
|
201 |
|
202 // retry notification |
|
203 TRAPD(err,aHandler->StartListeningL()); |
|
204 if ( err != KErrNone ) |
|
205 { |
|
206 COMPONENT_TRACE2(_L("HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::HandleNotifyError - error: %d "), err ); |
|
207 } |
|
208 |
|
209 // Do nothing |
|
210 |
|
211 COMPONENT_TRACE1(_L("HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::HandleNotifyError - return") ); |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CHWRMFmTxFrequencyObserver::Frequency |
|
216 // Return FM Tx frequency |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 TInt CHWRMFmTxFrequencyObserver::Frequency() const |
|
220 { |
|
221 COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::Frequency - return %d" ), iFrequency ); |
|
222 |
|
223 return iFrequency; |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CHWRMFmTxFrequencyObserver::MinFrequency |
|
228 // Return the minimum FM Tx frequency |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 TInt CHWRMFmTxFrequencyObserver::MinFrequency() const |
|
232 { |
|
233 COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::MinFrequency - return %d" ), iMinFrequency ); |
|
234 |
|
235 return iMinFrequency; |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CHWRMFmTxFrequencyObserver::MaxFrequency |
|
240 // Return the maximum FM Tx frequency |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 TInt CHWRMFmTxFrequencyObserver::MaxFrequency() const |
|
244 { |
|
245 COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::MaxFrequency - return %d" ), iMaxFrequency ); |
|
246 |
|
247 return iMaxFrequency; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CHWRMFmTxFrequencyObserver::StepSize |
|
252 // Return the FM Tx frequency step size |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 TInt CHWRMFmTxFrequencyObserver::StepSize() const |
|
256 { |
|
257 COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::StepSize - return %d" ), iStepSize ); |
|
258 |
|
259 return iStepSize; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CHWRMFmTxFrequencyObserver::FrequencyRangeUpdated |
|
264 // Return the FM Tx frequency step size |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 TBool CHWRMFmTxFrequencyObserver::FrequencyRangeUpdated() const |
|
268 { |
|
269 TBool retVal = EFalse; |
|
270 |
|
271 if ( iMinFrequency != 0 && |
|
272 iMaxFrequency != 0 && |
|
273 iStepSize != 0 ) |
|
274 { |
|
275 retVal = ETrue; |
|
276 } |
|
277 |
|
278 COMPONENT_TRACE2( _L( "HWRM FM Tx Client - CHWRMFmTxFrequencyObserver::FrequencyRangeUpdated - return %d" ), retVal ); |
|
279 return retVal; |
|
280 } |
|
281 |
|
282 // End of File |