|
1 /* |
|
2 * Copyright (c) 2005-2007 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: class to watch call monitor event properties |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "musavacalleventmonitor.h" |
|
21 #include "muslogger.h" |
|
22 #include "mussesseioninformationapi.h" |
|
23 #include "musresourceproperties.h" |
|
24 #include "muscallmonitorobserver.h" |
|
25 #include <e32property.h> |
|
26 |
|
27 // -------------------------------------------------------------------------- |
|
28 // Two phase constructor NewL() |
|
29 // -------------------------------------------------------------------------- |
|
30 // |
|
31 CMusAvaCallEventMonitor* CMusAvaCallEventMonitor::NewL( |
|
32 MMusCallMonitorObserver& aObserver ) |
|
33 { |
|
34 MUS_LOG( "mus: [MUSAOP] -> CMusAvaCallEventMonitor::NewL" ) |
|
35 CMusAvaCallEventMonitor* self = |
|
36 new (ELeave) CMusAvaCallEventMonitor( aObserver ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 MUS_LOG( "mus: [MUSAOP] <- CMusAvaCallEventMonitor::NewL" ) |
|
41 return self; |
|
42 } |
|
43 |
|
44 // -------------------------------------------------------------------------- |
|
45 // Destructor |
|
46 // -------------------------------------------------------------------------- |
|
47 // |
|
48 CMusAvaCallEventMonitor::~CMusAvaCallEventMonitor() |
|
49 { |
|
50 MUS_LOG( "-> CMusAvaCallEventMonitor::~CMusAoPlugin" ) |
|
51 |
|
52 MUS_LOG( "<- CMusAvaCallEventMonitor::~CMusAoPlugin" ) |
|
53 } |
|
54 |
|
55 // -------------------------------------------------------------------------- |
|
56 // Constructor |
|
57 // -------------------------------------------------------------------------- |
|
58 // |
|
59 CMusAvaCallEventMonitor::CMusAvaCallEventMonitor( |
|
60 MMusCallMonitorObserver& aObserver ) |
|
61 :CActive( EPriorityNormal ), |
|
62 iObserver( aObserver ) |
|
63 { |
|
64 } |
|
65 |
|
66 // -------------------------------------------------------------------------- |
|
67 // Two phase constructor ConstructL() |
|
68 // -------------------------------------------------------------------------- |
|
69 // |
|
70 void CMusAvaCallEventMonitor::ConstructL() |
|
71 { |
|
72 MUS_LOG( "mus: [MUSAOP] -> CMusAvaCallEventMonitor::ConstructL" ) |
|
73 CActiveScheduler::Add( this ); |
|
74 MUS_LOG( "mus: [MUSAOP] <- CMusAvaCallEventMonitor::ConstructL" ) |
|
75 } |
|
76 |
|
77 |
|
78 // -------------------------------------------------------------------------- |
|
79 // Returns the status of the call |
|
80 // -------------------------------------------------------------------------- |
|
81 // |
|
82 TInt CMusAvaCallEventMonitor::CallStatusL() |
|
83 { |
|
84 MUS_LOG( "mus: [CMusAvaCallEventMonitor] -> CMusAvaCallEventMonitor::\ |
|
85 CallStatusL" ) |
|
86 TInt callStatus; |
|
87 User::LeaveIfError( RProperty::Get( |
|
88 NMusSessionInformationApi::KCategoryUid, |
|
89 NMusSessionInformationApi::KMusCallEvent, |
|
90 callStatus ) ); |
|
91 |
|
92 MUS_LOG1( "mus: [CMusAvaCallEventMonitor] Call Event = %d ", |
|
93 callStatus ) |
|
94 MUS_LOG( "mus: [CMusAvaCallEventMonitor] <- CMusAvaCallEventMonitor::\ |
|
95 CallStatusL" ) |
|
96 return callStatus; |
|
97 } |
|
98 |
|
99 // -------------------------------------------------------------------------- |
|
100 // Returns the direction of connected call. |
|
101 // -------------------------------------------------------------------------- |
|
102 // |
|
103 TInt CMusAvaCallEventMonitor::CallDirectionL() |
|
104 { |
|
105 MUS_LOG( "mus: [CMusAvaCallEventMonitor] -> CMusAvaCallEventMonitor::\ |
|
106 CallDirectionL" ) |
|
107 // retrieve call count |
|
108 TInt direction( 0 ); |
|
109 User::LeaveIfError( RProperty::Get( |
|
110 NMusSessionInformationApi::KCategoryUid, |
|
111 NMusSessionInformationApi::KMusCallDirection, |
|
112 direction ) ); |
|
113 |
|
114 MUS_LOG1( "mus: [CMusAvaCallEventMonitor] Call Direction = %d ", |
|
115 direction ) |
|
116 MUS_LOG( "mus: [CMusAvaCallEventMonitor] <- CMusAvaCallEventMonitor::\ |
|
117 CallDirectionL" ) |
|
118 return direction; |
|
119 } |
|
120 |
|
121 // -------------------------------------------------------------------------- |
|
122 // Returns the direction of connected call. |
|
123 // -------------------------------------------------------------------------- |
|
124 // |
|
125 TInt CMusAvaCallEventMonitor::CallPrivacyL() |
|
126 { |
|
127 MUS_LOG( "mus: [CMusAvaCallEventMonitor] -> CMusAvaCallEventMonitor::\ |
|
128 CallPrivacyL" ) |
|
129 // retrieve call count |
|
130 TInt privacy( 0 ); |
|
131 User::LeaveIfError( RProperty::Get( |
|
132 NMusSessionInformationApi::KCategoryUid, |
|
133 NMusSessionInformationApi::KMUSPrivacy, |
|
134 privacy ) ); |
|
135 |
|
136 MUS_LOG1( "mus: [CMusAvaCallEventMonitor] Call privacy = %d ", |
|
137 privacy ) |
|
138 MUS_LOG( "mus: [CMusAvaCallEventMonitor] <- CMusAvaCallEventMonitor::\ |
|
139 CallPrivacyL" ) |
|
140 return privacy; |
|
141 } |
|
142 |
|
143 // -------------------------------------------------------------------------- |
|
144 // aTelNumber will be filled with telephone number of current connected call |
|
145 // -------------------------------------------------------------------------- |
|
146 // |
|
147 void CMusAvaCallEventMonitor::GetTelNumberL( TDes& aTelNumber ) |
|
148 { |
|
149 MUS_LOG( "mus: [CMusAvaCallEventMonitor] -> CMusAvaCallEventMonitor::\ |
|
150 GetTelNumberL" ) |
|
151 TBuf<KMusTelNumberMaxLength> telNumber; |
|
152 |
|
153 MUS_LOG( "mus: [CMusAvaCallEventMonitor] CMusAvaCallEventMonitor::\ |
|
154 GetTelNumberL - a" ) |
|
155 TInt error = RProperty::Get( |
|
156 NMusSessionInformationApi::KCategoryUid, |
|
157 NMusSessionInformationApi::KMusTelNumber, |
|
158 telNumber ); |
|
159 |
|
160 MUS_LOG1( "mus: [CMusAvaCallEventMonitor] CMusAvaCallEventMonitor::\ |
|
161 GetTelNumberL (%d)", error ) |
|
162 |
|
163 if ( error != KErrOverflow ) |
|
164 { |
|
165 User::LeaveIfError( error ); |
|
166 } |
|
167 |
|
168 TInt length = telNumber.Length(); |
|
169 TInt maxLength = aTelNumber.MaxLength(); |
|
170 if ( maxLength < length ) |
|
171 { |
|
172 // buffer is too small for returned tel number. |
|
173 MUS_LOG2( "mus: [CMusAvaCallEventMonitor] CMusAvaCallEventMonitor::\ |
|
174 GetTelNumberL - Buffer too small (%d, %d), leave", |
|
175 maxLength, length ) |
|
176 User::Leave( KErrOverflow ); |
|
177 } |
|
178 |
|
179 aTelNumber.Copy( telNumber ); |
|
180 MUS_LOG( "mus: [CMusAvaCallEventMonitor] <- CMusAvaCallEventMonitor::\ |
|
181 GetTelNumberL" ) |
|
182 } |
|
183 |
|
184 |
|
185 // -------------------------------------------------------------------------- |
|
186 // Subscribe to the property, means start monitoring the property |
|
187 // -------------------------------------------------------------------------- |
|
188 // |
|
189 void CMusAvaCallEventMonitor::StartMonitoringL() |
|
190 { |
|
191 MUS_LOG( "mus: [CMusAvaCallEventMonitor] -> CMusAvaCallEventMonitor::\ |
|
192 StartMonitoringL" ) |
|
193 if ( !IsActive() ) |
|
194 { |
|
195 MUS_LOG( "mus: [CMusAvaCallEventMonitor] CMusAvaCallEventMonitor::\ |
|
196 StartMonitoringL - Not active, starting" ) |
|
197 User::LeaveIfError( iPropertyEvent.Attach( |
|
198 NMusSessionInformationApi::KCategoryUid, |
|
199 NMusSessionInformationApi::KMusCallEvent ) ); |
|
200 // initial subscription and process current property value |
|
201 iPropertyEvent.Subscribe( iStatus ); |
|
202 SetActive(); |
|
203 } |
|
204 MUS_LOG( "mus: [CMusAvaCallEventMonitor] <- CMusAvaCallEventMonitor::\ |
|
205 StartMonitoringL" ) |
|
206 } |
|
207 |
|
208 |
|
209 // -------------------------------------------------------------------------- |
|
210 // Called by Cancel() |
|
211 // -------------------------------------------------------------------------- |
|
212 // |
|
213 void CMusAvaCallEventMonitor::DoCancel() |
|
214 { |
|
215 iPropertyEvent.Cancel(); |
|
216 iPropertyEvent.Close(); |
|
217 } |
|
218 |
|
219 |
|
220 // -------------------------------------------------------------------------- |
|
221 // Active Object RunL implementation. Will be called when property changes. |
|
222 // -------------------------------------------------------------------------- |
|
223 // |
|
224 void CMusAvaCallEventMonitor::RunL() |
|
225 { |
|
226 MUS_LOG( "mus: [MUSAOP] -> CMusAvaCallEventMonitor::RunL" ) |
|
227 |
|
228 // resubscribe before processing new value to prevent missing updates |
|
229 iPropertyEvent.Subscribe( iStatus ); |
|
230 SetActive(); |
|
231 |
|
232 // property updated, get new value |
|
233 TInt callStatus; |
|
234 if ( iPropertyEvent.Get( callStatus ) == KErrNotFound ) |
|
235 { |
|
236 // property deleted |
|
237 iObserver.NoActiveCallL(); |
|
238 } |
|
239 else |
|
240 { |
|
241 switch( callStatus ) |
|
242 { |
|
243 case NMusSessionInformationApi::ENoCall: |
|
244 { |
|
245 iObserver.NoActiveCallL(); |
|
246 break; |
|
247 } |
|
248 |
|
249 case NMusSessionInformationApi::ECallConnected: |
|
250 { |
|
251 // retrieve telnumber |
|
252 TInt error; |
|
253 TBuf<KMusTelNumberMaxLength> telNumber; |
|
254 error = RProperty::Get( |
|
255 NMusSessionInformationApi::KCategoryUid, |
|
256 NMusSessionInformationApi::KMusTelNumber, |
|
257 telNumber ); |
|
258 |
|
259 if ( error != KErrOverflow ) |
|
260 { |
|
261 User::LeaveIfError( error ); |
|
262 } |
|
263 |
|
264 iObserver.CallConnectedL( telNumber ); |
|
265 break; |
|
266 } |
|
267 |
|
268 case NMusSessionInformationApi::ECallHold: |
|
269 { |
|
270 // retrieve telnumber |
|
271 TInt error; |
|
272 TBuf<KMusTelNumberMaxLength> telNumber; |
|
273 error = RProperty::Get( |
|
274 NMusSessionInformationApi::KCategoryUid, |
|
275 NMusSessionInformationApi::KMusTelNumber, |
|
276 telNumber ); |
|
277 |
|
278 if ( error != KErrOverflow ) |
|
279 { |
|
280 User::LeaveIfError( error ); |
|
281 } |
|
282 iObserver.CallHoldL( telNumber ); |
|
283 break; |
|
284 } |
|
285 |
|
286 case NMusSessionInformationApi::EConferenceCall: |
|
287 { |
|
288 iObserver.ConferenceCallL(); |
|
289 break; |
|
290 } |
|
291 |
|
292 default: |
|
293 { |
|
294 iObserver.NoActiveCallL(); |
|
295 break; |
|
296 } |
|
297 } |
|
298 } |
|
299 |
|
300 MUS_LOG( "mus: [MUSAOP] <- CMusAvaCallEventMonitor::RunL" ) |
|
301 } |
|
302 |
|
303 |
|
304 // -------------------------------------------------------------------------- |
|
305 // RunL leaves will be handled here. Make sure it returns KErrNone |
|
306 // Otherwise Active Scheduler Error() will be called. |
|
307 // -------------------------------------------------------------------------- |
|
308 // |
|
309 TInt CMusAvaCallEventMonitor::RunError( TInt aError ) |
|
310 { |
|
311 MUS_LOG1( "mus: [MUSAOP] -> CMusAvaCallEventMonitor::RunError(%d)", |
|
312 aError ) |
|
313 |
|
314 // Not much things can be done here as cleanup operation. |
|
315 aError = KErrNone; |
|
316 |
|
317 MUS_LOG( "mus: [MUSAOP] <- CMusAvaCallEventMonitor::RunError" ) |
|
318 return aError; |
|
319 } |