|
1 /* |
|
2 * Copyright (c) 2009 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 "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <e32cmn.h> |
|
20 |
|
21 // User includes |
|
22 #include "cradioaccessoryobserver.h" |
|
23 #include "cradiosystemeventcollectorimp.h" |
|
24 #include "cradiosystemeventdetector.h" |
|
25 #include "radioengineutils.h" |
|
26 #include "cradioenginelogger.h" |
|
27 |
|
28 const TInt KVRObserverArrayGranularity( 2 ); |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CRadioSystemEventCollectorImp::CRadioSystemEventCollectorImp() : |
|
35 iSystemEventObservers( KVRObserverArrayGranularity ) |
|
36 { |
|
37 LEVEL3( LOG_METHOD_AUTO ); |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 void CRadioSystemEventCollectorImp::ConstructL() |
|
45 { |
|
46 LEVEL3( LOG_METHOD_AUTO ); |
|
47 RadioEngineUtils::InitializeL(); |
|
48 iSystemEventDetector = CRadioSystemEventDetector::NewL( *this ); |
|
49 |
|
50 iHeadsetObserver = CRadioAccessoryObserver::NewL(); |
|
51 iHeadsetObserver->SetObserver( this ); |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CRadioSystemEventCollectorImp* CRadioSystemEventCollectorImp::NewL() |
|
59 { |
|
60 LEVEL3( LOG_METHOD_AUTO ); |
|
61 CRadioSystemEventCollectorImp* self = new( ELeave ) CRadioSystemEventCollectorImp; |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop( self ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CRadioSystemEventCollectorImp::~CRadioSystemEventCollectorImp() |
|
73 { |
|
74 LEVEL3( LOG_METHOD_AUTO ); |
|
75 delete iSystemEventDetector; |
|
76 delete iHeadsetObserver; |
|
77 |
|
78 iSystemEventObservers.Close(); |
|
79 RadioEngineUtils::Release(); |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // Adds a system event observer |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 void CRadioSystemEventCollectorImp::AddObserverL( MRadioSystemEventObserver* aHeadsetObserver ) |
|
87 { |
|
88 LEVEL3( LOG_METHOD_AUTO ); |
|
89 iSystemEventObservers.AppendL( aHeadsetObserver ); |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // Removes a system event observer |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CRadioSystemEventCollectorImp::RemoveObserver( MRadioSystemEventObserver* aSystemObserver ) |
|
97 { |
|
98 LEVEL3( LOG_METHOD_AUTO ); |
|
99 TInt objectIndex = iSystemEventObservers.Find( aSystemObserver ); |
|
100 |
|
101 if ( objectIndex != KErrNotFound ) |
|
102 { |
|
103 iSystemEventObservers.Remove( objectIndex ); |
|
104 } |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // Getter for mobile network state |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 TBool CRadioSystemEventCollectorImp::IsMobileNetworkCoverage() const |
|
112 { |
|
113 LEVEL3( LOG_METHOD_AUTO ); |
|
114 return iSystemEventDetector->IsMobileNetworkCoverage(); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // Getter for network state |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 TBool CRadioSystemEventCollectorImp::IsNetworkCoverage() const |
|
122 { |
|
123 LEVEL3( LOG_METHOD_AUTO ); |
|
124 return iSystemEventDetector->IsNetworkCoverage(); |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // Getter for call state |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 TBool CRadioSystemEventCollectorImp::IsCallActive() const |
|
132 { |
|
133 LEVEL3( LOG_METHOD_AUTO ); |
|
134 return iSystemEventDetector->IsCallActive(); |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // Getter for audio resource state |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 TBool CRadioSystemEventCollectorImp::IsAudioResourcesAvailable() const |
|
142 { |
|
143 LEVEL3( LOG_METHOD_AUTO ); |
|
144 return iSystemEventDetector->IsAudioResourcesAvailable(); |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------------------------- |
|
148 // Getter for headset connection status |
|
149 // --------------------------------------------------------------------------- |
|
150 TBool CRadioSystemEventCollectorImp::IsHeadsetConnectedL() const |
|
151 { |
|
152 LEVEL3( LOG_METHOD_AUTO ); |
|
153 return iHeadsetObserver->IsHeadsetConnectedL(); |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // Notifies the observers of system event |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 void CRadioSystemEventCollectorImp::NotifyObserversL( TRadioSystemEventType aEvent ) |
|
161 { |
|
162 LEVEL3( LOG_METHOD_AUTO ); |
|
163 for ( TInt i = 0; i < iSystemEventObservers.Count(); ++i ) |
|
164 { |
|
165 iSystemEventObservers[i]->HandleSystemEventL( aEvent ); |
|
166 } |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // From class MRadioSystemEventDetectorObserver. |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CRadioSystemEventCollectorImp::NetworkUpCallbackL() |
|
174 { |
|
175 LEVEL3( LOG_METHOD_AUTO ); |
|
176 NotifyObserversL( ERadioNetworkCoverageUp ); |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // From class MRadioSystemEventDetectorObserver. |
|
181 // --------------------------------------------------------------------------- |
|
182 // |
|
183 void CRadioSystemEventCollectorImp::NetworkDownCallbackL() |
|
184 { |
|
185 LEVEL3( LOG_METHOD_AUTO ); |
|
186 NotifyObserversL( ERadioNetworkCoverageDown ); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // From class MRadioSystemEventDetectorObserver. |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 void CRadioSystemEventCollectorImp::CallActivatedCallbackL() |
|
194 { |
|
195 LEVEL3( LOG_METHOD_AUTO ); |
|
196 NotifyObserversL( ERadioCallActivated ); |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // From class MRadioSystemEventDetectorObserver. |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CRadioSystemEventCollectorImp::CallDeactivatedCallbackL() |
|
204 { |
|
205 LEVEL3( LOG_METHOD_AUTO ); |
|
206 NotifyObserversL( ERadioCallDeactivated ); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // From class MRadioSystemEventDetectorObserver. |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CRadioSystemEventCollectorImp::AudioResourcesAvailableL() |
|
214 { |
|
215 LEVEL3( LOG_METHOD_AUTO ); |
|
216 NotifyObserversL( ERadioAudioResourcesAvailable ); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // From class MRadioSystemEventDetectorObserver. |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 void CRadioSystemEventCollectorImp::AudioAutoResumeForbiddenL() |
|
224 { |
|
225 LEVEL3( LOG_METHOD_AUTO ); |
|
226 NotifyObserversL( ERadioAudioAutoResumeForbidden ); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // From class MRadioSystemEventDetectorObserver. |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 void CRadioSystemEventCollectorImp::ErrorCallbackL( TInt DEBUGVAR3( aError ) ) |
|
234 { |
|
235 LEVEL3( LOG_METHOD_AUTO ); |
|
236 LEVEL3( LOG_FORMAT( "aError = %d", aError ) ); |
|
237 // P&S get fail not considered as a critical issue. |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // From class MRadioHeadsetEventObserver. |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CRadioSystemEventCollectorImp::HeadsetConnectedCallbackL() |
|
245 { |
|
246 LEVEL3( LOG_METHOD_AUTO ); |
|
247 NotifyObserversL( ERadioHeadsetConnected ); |
|
248 } |
|
249 |
|
250 // --------------------------------------------------------------------------- |
|
251 // From class MRadioHeadsetEventObserver. |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 void CRadioSystemEventCollectorImp::HeadsetDisconnectedCallbackL() |
|
255 { |
|
256 LEVEL3( LOG_METHOD_AUTO ); |
|
257 NotifyObserversL( ERadioHeadsetDisconnected ); |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // From class MRadioAudioRoutingObserver. |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 void CRadioSystemEventCollectorImp::AudioRouteChangedL( RadioEngine::TRadioAudioRoute aRoute ) |
|
265 { |
|
266 LEVEL3( LOG_METHOD_AUTO ); |
|
267 TRadioSystemEventType ev = ERadioAudioRouteHeadset; |
|
268 if ( aRoute != RadioEngine::ERadioHeadset ) |
|
269 { |
|
270 ev = ERadioAudioRouteSpeaker; |
|
271 } |
|
272 |
|
273 NotifyObserversL( ev ); |
|
274 } |