|
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: Monitor that observes the status of the current CS call |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "mussesseioninformationapi.h" |
|
19 #include "mustsypropertymonitor.h" |
|
20 #include "muscallconferencemonitor.h" |
|
21 #include "muscallmonitor.h" |
|
22 #include "muslogger.h" |
|
23 #include "mussettings.h" |
|
24 #include "musclirmonitor.h" |
|
25 |
|
26 #include <etel.h> |
|
27 #include <e32property.h> |
|
28 #include <mmtsy_names.h> |
|
29 #include <ctsydomainpskeys.h> |
|
30 |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // Symbian two-phase constructor. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CMusTsyPropertyMonitor* CMusTsyPropertyMonitor::NewL( RMobilePhone& aPhone ) |
|
37 { |
|
38 MUS_LOG( "mus: [MUSAO] -> CMusTsyPropertyMonitor::NewL" ) |
|
39 CMusTsyPropertyMonitor* self = new (ELeave) CMusTsyPropertyMonitor(aPhone); |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop( self ); |
|
43 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::NewL" ) |
|
44 return self; |
|
45 } |
|
46 |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // C++ destructor. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CMusTsyPropertyMonitor::~CMusTsyPropertyMonitor() |
|
53 { |
|
54 MUS_LOG( "mus: [MUSAO] -> CMusTsyPropertyMonitor::~CMusTsyPropertyMonitor" ) |
|
55 Cancel(); |
|
56 delete iConferenceMonitor; |
|
57 delete iClirMonitor; |
|
58 iCallMonitorArray.ResetAndDestroy(); |
|
59 iLine.Close(); |
|
60 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::~CMusTsyPropertyMonitor" ) |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // Symbian second-phase constructor. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CMusTsyPropertyMonitor::ConstructL() |
|
68 { |
|
69 MUS_LOG( "mus: [MUSAO] -> CMusTsyPropertyMonitor::ConstructL" ) |
|
70 CActiveScheduler::Add(this); |
|
71 User::LeaveIfError( iLine.Open( iPhone, KMmTsyVoice1LineName() ) ); |
|
72 iConferenceMonitor = CMusCallConferenceMonitor::NewL( |
|
73 iPhone,iLine,iCallMonitorArray); |
|
74 |
|
75 if (MultimediaSharingSettings::PrivacySetting()) |
|
76 { |
|
77 iClirMonitor = CMusClirMonitor::NewL(); |
|
78 } |
|
79 |
|
80 User::LeaveIfError( iPropertyEvent.Attach( |
|
81 KPSUidCtsyCallInformation, |
|
82 KCTsyCallState ) ); |
|
83 iPropertyEvent.Subscribe( iStatus ); |
|
84 SetActive(); |
|
85 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::ConstructL" ) |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // C++ constructor. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 CMusTsyPropertyMonitor::CMusTsyPropertyMonitor(RMobilePhone& aPhone) |
|
93 : CActive( EPriorityNormal ),iPhone(aPhone) |
|
94 { |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CMusTsyPropertyMonitor::RunL() |
|
99 // Implemented for CActive.It will be called any NotifyMobileLineStatusChange |
|
100 // Event happens. |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 void CMusTsyPropertyMonitor::RunL() |
|
104 { |
|
105 MUS_LOG( "mus: [MUSAO] -> CMusTsyPropertyMonitor::RunL" ) |
|
106 // subscribe , so that we dont miss any events. |
|
107 iPropertyEvent.Subscribe( iStatus ); |
|
108 SetActive(); |
|
109 TInt value = EPSCTsyCallStateUninitialized; |
|
110 User::LeaveIfError(iPropertyEvent.Get( value )); |
|
111 MUS_LOG1( "mus: [MUSAO] iTsyCallMonitor->CallState = %d",value ) |
|
112 switch(value) |
|
113 { |
|
114 case EPSCTsyCallStateNone: |
|
115 SetStateL(NMusSessionInformationApi::ENoCall); |
|
116 // Sometimes disconnected call goes stright to this state |
|
117 // so we have to call this function to remove call monitors. |
|
118 RemoveAllCallMonitor(); |
|
119 break; |
|
120 case EPSCTsyCallStateDisconnecting: |
|
121 case EPSCTsyCallStateAnswering: |
|
122 case EPSCTsyCallStateConnected: |
|
123 case EPSCTsyCallStateHold: |
|
124 // in all above states if multible call exist then |
|
125 // we have to find all the calls state and do accordingly. |
|
126 MonitorCallL(); |
|
127 break; |
|
128 default: |
|
129 MUS_LOG( "mus: [MUSAO] Undesired CallState " ) |
|
130 break; |
|
131 } |
|
132 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::RunL" ) |
|
133 } |
|
134 |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CMusTsyPropertyMonitor::DoCancel() |
|
138 // Implemented for CActive. |
|
139 // Will be called when Cancel() method is called. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CMusTsyPropertyMonitor::DoCancel() |
|
143 { |
|
144 MUS_LOG( "mus: [MUSAO] -> CMusTsyPropertyMonitor::DoCancel" ) |
|
145 iPropertyEvent.Cancel(); |
|
146 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::DoCancel" ) |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CMusTsyPropertyMonitor::RunError( TInt aError ) |
|
151 // Implemented for CActive. |
|
152 // Will be called automatically by framework when RunL Leaves. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TInt CMusTsyPropertyMonitor::RunError( TInt aError ) |
|
156 { |
|
157 MUS_LOG1( "mus: [MUSAO] -> CMusTsyPropertyMonitor::RunError = %d", aError ) |
|
158 aError = KErrNone; // Just to avoid compilation warnings. Dunno what we do. |
|
159 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::RunError" ) |
|
160 return aError; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CMusTsyPropertyMonitor::AddCallMonitorL( TName aCallName ) |
|
165 // Adds new call monitor if the call is not monitored already. |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CMusTsyPropertyMonitor::AddCallMonitorL(TName& aCallName) |
|
169 { |
|
170 MUS_LOG_TDESC( "mus: [MUSAO] -> CMusTsyPropertyMonitor::AddCallMonitorL"\ |
|
171 ,aCallName ) |
|
172 TBool isCallExist = EFalse; |
|
173 for ( TInt i = 0; i < iCallMonitorArray.Count() && !isCallExist; i++ ) |
|
174 { |
|
175 if( iCallMonitorArray[i]->IsEqual( aCallName ) ) |
|
176 { |
|
177 isCallExist = ETrue; |
|
178 } |
|
179 } |
|
180 MUS_LOG1( "mus: [MUSAO] Call Exist = %d ",isCallExist ) |
|
181 if( !isCallExist ) |
|
182 { |
|
183 if ( iClirMonitor ) |
|
184 { |
|
185 //Start async reading of CLIR from phone settings |
|
186 iClirMonitor->ReadClir(); |
|
187 } |
|
188 |
|
189 CMusCallMonitor* callMonitor = CMusCallMonitor::NewL( aCallName, |
|
190 IsPttCallExist() ); |
|
191 CleanupStack::PushL( callMonitor ); |
|
192 iCallMonitorArray.AppendL( callMonitor ); |
|
193 CleanupStack::Pop( callMonitor ); |
|
194 callMonitor->StartMonitorL(iLine, *this); |
|
195 } |
|
196 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::AddCallMonitorL" ) |
|
197 } |
|
198 |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CMusTsyPropertyMonitor::RemoveCallEventMonitorL( TName aCallName ) |
|
202 // Remove the Call Monitor if it exist in array. |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CMusTsyPropertyMonitor::RemoveCallMonitor( TName& aCallName ) |
|
206 { |
|
207 MUS_LOG_TDESC( "mus: [MUSAO] -> CMusTsyPropertyMonitor::RemoveCallMonitor " |
|
208 ,aCallName ) |
|
209 for ( TInt i = 0; i < iCallMonitorArray.Count(); i++ ) |
|
210 { |
|
211 if( iCallMonitorArray[i]->IsEqual( aCallName ) ) |
|
212 { |
|
213 delete iCallMonitorArray[i]; |
|
214 iCallMonitorArray.Remove(i); |
|
215 break; |
|
216 } |
|
217 } |
|
218 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::RemoveCallMonitor" ) |
|
219 } |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CMusTsyPropertyMonitor::RemoveCallEventMonitorL( TName aCallName ) |
|
223 // Remove the Call Monitor if it exist in array. |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 void CMusTsyPropertyMonitor::RemoveAllCallMonitor() |
|
227 { |
|
228 MUS_LOG( "mus: [MUSAO] -> CMusTsyPropertyMonitor::RemoveAllCallMonitor " ) |
|
229 iCallMonitorArray.ResetAndDestroy(); |
|
230 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::RemoveAllCallMonitor" ) |
|
231 } |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CMusTsyPropertyMonitor::IsPTTCallExist() |
|
234 // Remove the Call Monitor if it exist in array. |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 TBool CMusTsyPropertyMonitor::IsPttCallExist() |
|
238 { |
|
239 MUS_LOG( "mus: [MUSAO] -> CMusTsyPropertyMonitor::IsPTTCallExist") |
|
240 TBool exist = EFalse; |
|
241 /* |
|
242 TInt val = 0; |
|
243 TInt err = RProperty::Get(KPSUidCtsyCallInformation,KCTsyKodiakPtt,val ); |
|
244 MUS_LOG2( "mus: [MUSAO] PTTCallValue = val Error = %d",val,err ) |
|
245 if(!err && val== EPSCTsyKodiakPttActive ) |
|
246 { |
|
247 exist = ETrue; |
|
248 } |
|
249 else |
|
250 { |
|
251 // if there is an error dont know what to do. |
|
252 // there could be cases like KodiakPTT is not supported |
|
253 // So considering there is no PttCall. |
|
254 exist = EFalse; |
|
255 } |
|
256 */ |
|
257 MUS_LOG1( "mus: [MUSAO] <- CMusTsyPropertyMonitor::IsPTTCallExist = %d",\ |
|
258 exist ) |
|
259 return exist; |
|
260 } |
|
261 |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CMusTsyPropertyMonitor::IsPTTCallExist() |
|
265 // Remove the Call Monitor if it exist in array. |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 |
|
269 // Enable the below line if Kodiak Ptt has to be monitered |
|
270 /* |
|
271 void CMusTsyPropertyMonitor::PttCallEventOccuredL( TPSCTsyKodiakPtt& aVal) |
|
272 { |
|
273 MUS_LOG1( "mus: [MUSAO] -> CMusTsyPropertyMonitor::PttCallEventOccured\ |
|
274 = %d",aVal) |
|
275 |
|
276 |
|
277 if (iCallMonitorArray.Count()>0) |
|
278 { |
|
279 if( aVal == EPSCTsyKodiakPttNotActive && iCallMonitorArray.Count()==1) |
|
280 { |
|
281 iCallMonitorArray[0]->StartMonitorL(iLine); |
|
282 } |
|
283 else |
|
284 { |
|
285 iCallMonitorArray[0]->StopMonitorL(); |
|
286 } |
|
287 } |
|
288 else |
|
289 { |
|
290 // No CS call. Dont care this event. |
|
291 } |
|
292 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::PttCallEventOccured" ) |
|
293 } |
|
294 */ |
|
295 |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CMusTsyPropertyMonitor::SetStateL( TInt aError ) |
|
299 // Sets the Call State to Property |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 void CMusTsyPropertyMonitor::SetStateL( |
|
303 NMusSessionInformationApi::TMusCallEvent aVal) |
|
304 { |
|
305 MUS_LOG1( "mus: [MUSAO] -> CMusTsyPropertyMonitor::SetStateL,aVal %d",aVal ) |
|
306 TInt currentVal; |
|
307 User::LeaveIfError(RProperty::Get( NMusSessionInformationApi::KCategoryUid, |
|
308 NMusSessionInformationApi::KMusCallEvent,currentVal)); |
|
309 if(currentVal != (TInt)aVal) |
|
310 { |
|
311 User::LeaveIfError(RProperty::Set( |
|
312 NMusSessionInformationApi::KCategoryUid, |
|
313 NMusSessionInformationApi::KMusCallEvent, |
|
314 aVal )); |
|
315 } |
|
316 else |
|
317 { |
|
318 // No point of reporting it . |
|
319 } |
|
320 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::SetStateL" ) |
|
321 } |
|
322 |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CMusTsyPropertyMonitor::MonitorCallL() |
|
326 // Monitors the call and if needed adds/removes call monitor. |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 void CMusTsyPropertyMonitor::MonitorCallL() |
|
330 { |
|
331 MUS_LOG( "mus: [MUSAO] -> CMusTsyPropertyMonitor::MonitorCallL") |
|
332 TInt callCount; |
|
333 iLine.EnumerateCall(callCount); |
|
334 MUS_LOG1( "mus: [MUSAO] -> callCount = %d",callCount) |
|
335 RLine::TCallInfo callInfo; |
|
336 for(TInt i=0;i<callCount;i++) |
|
337 { |
|
338 iLine.GetCallInfo(i,callInfo); |
|
339 MUS_LOG1( "mus: [MUSAO] Call index = %d",i) |
|
340 MUS_LOG_TDESC("mus: [MUSAO] Call Name = ",callInfo.iCallName); |
|
341 MUS_LOG1( "mus: [MUSAO] Call Status = %d",callInfo.iStatus ); |
|
342 if(callInfo.iStatus == RCall::EStatusIdle || |
|
343 callInfo.iStatus == RCall::EStatusHangingUp) |
|
344 { |
|
345 RemoveCallMonitor(callInfo.iCallName); |
|
346 } |
|
347 else if(callInfo.iStatus == RCall::EStatusConnected || |
|
348 callInfo.iStatus == RCall::EStatusAnswering) |
|
349 { |
|
350 AddCallMonitorL(callInfo.iCallName); |
|
351 } |
|
352 } |
|
353 // Sometimes when call get disconnected then call object disappears.So |
|
354 // check the call state or open the call , if there is an error or undesired |
|
355 // call state , remove that callmonitor from array. |
|
356 RemoveUnUsedCallMonitors(); |
|
357 |
|
358 if(iCallMonitorArray.Count() > 1) |
|
359 { |
|
360 // it is already multicall so atleast one should be hold. |
|
361 // so set the state first to hold |
|
362 SetStateL(NMusSessionInformationApi::ECallHold); |
|
363 // still we dont know here about conference state so |
|
364 // let the conference call monitor decide . |
|
365 iConferenceMonitor->SetStateL(); |
|
366 } |
|
367 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::MonitorCallL") |
|
368 } |
|
369 |
|
370 |
|
371 // ----------------------------------------------------------------------------- |
|
372 // CMusTsyPropertyMonitor::CallStatusL() |
|
373 // Somehow Line is not returning correct call info when call disconnected from |
|
374 // remote,So open the call and ask call status |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 RMobileCall::TMobileCallStatus CMusTsyPropertyMonitor::CallStatus(const TDesC& aCallName) |
|
378 { |
|
379 MUS_LOG_TDESC( "mus: [MUSAO] -> CMusTsyPropertyMonitor::CallStatusL",aCallName) |
|
380 RMobileCall call; |
|
381 TInt error = call.OpenExistingCall( iLine, aCallName ); |
|
382 RMobileCall::TMobileCallStatus callStatus = RMobileCall::EStatusUnknown; |
|
383 if(error==KErrNone) |
|
384 { |
|
385 // if error occur here , then leave the status to default. |
|
386 call.GetMobileCallStatus(callStatus); |
|
387 } |
|
388 call.Close(); |
|
389 MUS_LOG1( "mus: [MUSAO] <- CMusTsyPropertyMonitor::CallStatusL = %d",callStatus) |
|
390 return callStatus; |
|
391 } |
|
392 |
|
393 // ----------------------------------------------------------------------------- |
|
394 // CMusTsyPropertyMonitor::RemoveUnUsedCallMonitors() |
|
395 // ----------------------------------------------------------------------------- |
|
396 // |
|
397 void CMusTsyPropertyMonitor:: RemoveUnUsedCallMonitors() |
|
398 { |
|
399 MUS_LOG( "mus: [MUSAO] -> CMusTsyPropertyMonitor::RemoveUnUsedCallMonitors" ) |
|
400 for ( TInt i = 0; i < iCallMonitorArray.Count(); i++ ) |
|
401 { |
|
402 if( CallStatus( iCallMonitorArray[i]->Name() ) == |
|
403 RMobileCall::EStatusUnknown ) |
|
404 { |
|
405 MUS_LOG_TDESC("mus: [MUSAO] Removing = ",iCallMonitorArray[i]->Name()); |
|
406 delete iCallMonitorArray[i]; |
|
407 iCallMonitorArray[i] = NULL; |
|
408 iCallMonitorArray.Remove(i); |
|
409 // this lowers the call monitor index by one , so lower the i by one too |
|
410 i--; |
|
411 } |
|
412 } |
|
413 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::RemoveUnUsedCallMonitors" ) |
|
414 } |
|
415 |
|
416 // ----------------------------------------------------------------------------- |
|
417 // CMusTsyPropertyMonitor::NotifyCallStateChanged() |
|
418 // ----------------------------------------------------------------------------- |
|
419 // |
|
420 void CMusTsyPropertyMonitor::NotifyCallStateChanged(NMusSessionInformationApi::TMusCallEvent aVal, TName& aCallName) |
|
421 { |
|
422 MUS_LOG( "mus: [MUSAO] -> CMusTsyPropertyMonitor::NotifyCallStateChanged" ) |
|
423 |
|
424 if(aVal == NMusSessionInformationApi::ENoCall ) |
|
425 { |
|
426 // Call has been disconnected, |
|
427 // Remove call monitor from array |
|
428 RemoveCallMonitor(aCallName); |
|
429 if( iCallMonitorArray.Count() == 0 ) |
|
430 { |
|
431 SetStateL(NMusSessionInformationApi::ENoCall); |
|
432 } |
|
433 else if( iCallMonitorArray.Count() == 1) |
|
434 { |
|
435 // Only one call left, set its state to be ECallConnected here |
|
436 // The real state of the call will be calculated by CMusCallMonitorBase |
|
437 iCallMonitorArray[0]->SetStateL(NMusSessionInformationApi::ECallConnected); |
|
438 } |
|
439 else |
|
440 { |
|
441 // it is already multicall so atleast one should be hold. |
|
442 // so set the state first to hold |
|
443 SetStateL(NMusSessionInformationApi::ECallHold); |
|
444 // still we dont know here about conference state so |
|
445 // let the conference call monitor decide . |
|
446 iConferenceMonitor->SetStateL(); |
|
447 } |
|
448 } |
|
449 |
|
450 MUS_LOG( "mus: [MUSAO] <- CMusTsyPropertyMonitor::NotifyCallStateChanged" ) |
|
451 } |
|
452 // End of file |