mmshplugins/mmshaoplugin/src/muscallmonitorbase.cpp
changeset 22 496ad160a278
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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 the events of CS call
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mussesseioninformationapi.h"
       
    20 #include "muscallmonitorbase.h"
       
    21 #include "muslogger.h"
       
    22 
       
    23 #include <etel.h>
       
    24 #include <etelmm.h>
       
    25 #include <e32svr.h>
       
    26 #include <mmtsy_names.h>
       
    27 #include <e32property.h>
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // C++ destructor.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CMusCallMonitorBase::~CMusCallMonitorBase()
       
    35     {
       
    36     MUS_LOG( "mus: [MUSAO]  -> CMusCallMonitorBase::~CMusCallMonitorBase" )        
       
    37     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::~CMusCallMonitorBase" )
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // C++ constructor.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CMusCallMonitorBase::CMusCallMonitorBase(const RMobileCall& aCall, 
       
    45         MMusTsyPropertyObserver& aObserver, 
       
    46         MMusCallStateObserver& aCallStateObserver ) 
       
    47         : CActive( EPriorityNormal ),iCall(aCall),iTsyObserver( aObserver ), 
       
    48         iCallStateObserver( aCallStateObserver )
       
    49         
       
    50         
       
    51     {   
       
    52 	// Intialize the remote call event state to Resume , means connected.
       
    53     iRemoteCallEvent = RMobileCall::ERemoteResume;
       
    54     // Intialize the local call event state to Resume , means connected.
       
    55     iLocalCallEvent = RMobileCall::ELocalResume;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CMusCallMonitorBase::SetStateL( TInt aError )
       
    60 // Sets the Call State to Property
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void CMusCallMonitorBase::SetStateL(NMusSessionInformationApi::TMusCallEvent aVal)
       
    64     {
       
    65     MUS_LOG1( "mus: [MUSAO]  -> CMusCallMonitorBase::SetStateL, aVal %d", aVal )
       
    66     TInt callCount = 0;
       
    67     User::LeaveIfError(RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
    68                             NMusSessionInformationApi::KMusCallCount,callCount));
       
    69     MUS_LOG1( "mus: [MUSAO]  - CallCount = %d",callCount )
       
    70     
       
    71     RMobileCall::TMobileCallInfoV3 callInfo;
       
    72     RMobileCall::TMobileCallInfoV3Pckg pckg( callInfo );
       
    73     iCall.GetMobileCallInfo( pckg );
       
    74     if( callInfo.iEmergency )
       
    75     	{
       
    76     	User::LeaveIfError(RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
    77     				 NMusSessionInformationApi::KMusCallEvent,
       
    78     				 ( TInt ) NMusSessionInformationApi::ENoCall ));
       
    79     	}
       
    80     /*
       
    81     * CountOfCallMonitors is number of CallMonitor Objects.Static Reference Count.
       
    82     * = No of active calls . 
       
    83     * React one and only if one call is present -> Mush Call criteria.
       
    84     * if call count is more than one , should be taken care by conference call or
       
    85     * multicall criteria.
       
    86     */
       
    87     else if( callCount == 1 ) 
       
    88         {
       
    89         TInt currentVal;
       
    90         User::LeaveIfError(RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
    91                             NMusSessionInformationApi::KMusCallEvent,currentVal));
       
    92         MUS_LOG1( "mus: [MUSAO]  - Remote State = %d",iRemoteCallEvent )
       
    93         /* If current event is callconnected and remote is not in hold set the
       
    94            property value to CallConnected.Else set it to CallHold.
       
    95            Note : We can be sure about Local is connected when it goes to
       
    96                   CallConnected State. But remote call events are just notified
       
    97                   in call event monitor. So this stores the last remotecall event
       
    98                   and checks it now.
       
    99         */        
       
   100         if( aVal==NMusSessionInformationApi::ECallConnected 
       
   101             && iRemoteCallEvent!=RMobileCall::ERemoteHold)
       
   102             {
       
   103             /* If the current property value is same of new value, there is no
       
   104                point of setting it since it will cause lot of other processes.               
       
   105             */
       
   106             if(currentVal != (TInt)aVal)
       
   107                 {
       
   108                 User::LeaveIfError(RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
   109                                                  NMusSessionInformationApi::KMusCallEvent,
       
   110                                                  aVal ));    
       
   111                 }
       
   112             } 
       
   113         else if( aVal==NMusSessionInformationApi::ECallHold || iRemoteCallEvent==RMobileCall::ERemoteHold )
       
   114             {            
       
   115             User::LeaveIfError(RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
   116                                                NMusSessionInformationApi::KMusCallEvent,
       
   117                                                NMusSessionInformationApi::ECallHold   ));  
       
   118             }          
       
   119          else if( aVal==NMusSessionInformationApi::ENoCall )
       
   120             {            
       
   121             User::LeaveIfError(RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
   122                                                NMusSessionInformationApi::KMusCallEvent,
       
   123                                                NMusSessionInformationApi::ENoCall ));  
       
   124             }  
       
   125           else if( aVal==NMusSessionInformationApi::EConferenceCall )
       
   126             {            
       
   127             User::LeaveIfError(RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
   128                                                NMusSessionInformationApi::KMusCallEvent,
       
   129                                                NMusSessionInformationApi::EConferenceCall ));  
       
   130             }  
       
   131          	  
       
   132         /*
       
   133          If Call is Connected then set the Call info.
       
   134          */
       
   135         if( aVal==NMusSessionInformationApi::ECallConnected ) 
       
   136             {
       
   137             SetCallInfoL();
       
   138             }
       
   139 
       
   140         // All P/S Keys are Set
       
   141         //Check if preconditions are met to start or stop the MushClient.
       
   142         iCallStateObserver.MusCallStateChanged();
       
   143         }   
       
   144  
       
   145     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::SetStateL" )    
       
   146     }
       
   147 
       
   148 ///-----------------------------------------------------------------------------
       
   149 // CMusCallMonitorBase::SetCallInfoL( TInt aError )
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CMusCallMonitorBase::SetCallInfoL()
       
   153     {
       
   154     MUS_LOG( "mus: [MUSAO]  -> CMusCallMonitorBase::SetCallInfoL ")           
       
   155     RMobileCall::TMobileCallInfoV3 callInfo;
       
   156     RMobileCall::TMobileCallInfoV3Pckg callInfoPckg( callInfo );
       
   157     User::LeaveIfError(iCall.GetMobileCallInfo( callInfoPckg ));    
       
   158     RMobilePhone::TMobileAddress remoteNumber = 
       
   159                                            callInfo.iRemoteParty.iRemoteNumber;
       
   160      // Set telephone number
       
   161     HBufC* telNo( NULL );
       
   162     if( remoteNumber.iTelNumber.Length() > 0 )
       
   163         {
       
   164         MUS_LOG( "mus: [MUSAO]     remoteNumber.iTelNumber.Lenght > 0" )
       
   165         telNo = remoteNumber.iTelNumber.AllocLC();
       
   166         }
       
   167     else
       
   168         {
       
   169         MUS_LOG( "mus: [CALLMN]     remoteNumber.iTelNumber.Lenght =< 0" )
       
   170         RMobilePhone::TMobileAddress dialledParty = callInfo.iDialledParty;
       
   171         telNo = dialledParty.iTelNumber.AllocLC();
       
   172         }
       
   173     User::LeaveIfError(RProperty::Set( 
       
   174                                       NMusSessionInformationApi::KCategoryUid,
       
   175                                       NMusSessionInformationApi::KMusTelNumber,
       
   176                                       *telNo ));  
       
   177     MUS_LOG_TDESC("mus: [MUSAO]     telNo = ", (*telNo))
       
   178     CleanupStack::PopAndDestroy(telNo);
       
   179     
       
   180     // Set call direction.     
       
   181     RMobileCall::TMobileCallDirection direction =
       
   182                                             callInfo.iRemoteParty.iDirection;
       
   183     MUS_LOG1( "mus: [MUSAO]  Call Direction = %d",direction )
       
   184     if( direction == RMobileCall::EMobileOriginated )
       
   185         {
       
   186         User::LeaveIfError(RProperty::Set( 
       
   187                         NMusSessionInformationApi::KCategoryUid,
       
   188                         NMusSessionInformationApi::KMusCallDirection,
       
   189                         ( TInt ) NMusSessionInformationApi::ECallOrginated ));
       
   190         }
       
   191     else if ( direction  == RMobileCall::EMobileTerminated )
       
   192         {
       
   193         User::LeaveIfError(RProperty::Set( 
       
   194                         NMusSessionInformationApi::KCategoryUid,
       
   195                         NMusSessionInformationApi::KMusCallDirection,
       
   196                         ( TInt ) NMusSessionInformationApi::ECallTerminated ));
       
   197         }
       
   198     else
       
   199         {
       
   200         User::LeaveIfError(RProperty::Set( 
       
   201                         NMusSessionInformationApi::KCategoryUid,
       
   202                         NMusSessionInformationApi::KMusCallDirection,
       
   203                         ( TInt ) NMusSessionInformationApi::ENoDirection ));
       
   204         } 
       
   205     
       
   206     
       
   207     /* Set the call provider information to some dummy Value */
       
   208     User::LeaveIfError(RProperty::Set( 
       
   209                             NMusSessionInformationApi::KCategoryUid,
       
   210                             NMusSessionInformationApi::KMUSCallProvider,
       
   211                             KNullDesC));
       
   212     
       
   213     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::SetCallInfoL" )  
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CMusCallMonitorBase::RunError( TInt aError )
       
   218 // Implemented for CActive.
       
   219 // Will be called automatically by framework when RunL Leaves.
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 
       
   223 TInt CMusCallMonitorBase::RunError( TInt aError )
       
   224     {
       
   225     MUS_LOG1( "mus: [MUSAO]  -> CMusCallMonitorBase::RunError, aError %d",\
       
   226                                                                       aError )
       
   227     aError = KErrNone; // just to avoid warnings.
       
   228     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::RunError" )    
       
   229     return aError;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CMusCallMonitorBase::NotifyCallStateChanged()
       
   234 // Notify TSYobserver that our call status or call event state changed
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CMusCallMonitorBase::NotifyCallStateChanged( NMusSessionInformationApi::TMusCallEvent aVal )
       
   238     {
       
   239     RCall::TCallInfo callInfo;
       
   240     iCall.GetInfo(callInfo);
       
   241     iTsyObserver.NotifyCallStateChanged( aVal, callInfo.iCallName );
       
   242     }
       
   243 
       
   244 
       
   245 // --------------------------------------------------------------------------------
       
   246 // CMusCallConferenceMonitor::IsDataReadyL()
       
   247 // Checks if Data is ready CS Call.
       
   248 // --------------------------------------------------------------------------------
       
   249 
       
   250 TBool CMusCallMonitorBase::IsDataReadyL()
       
   251     {
       
   252     // This function need to be updated when new 
       
   253     // P/S key is published in Call monitor 
       
   254 
       
   255     MUS_LOG( "mus: [MUSAO]  -> CMusCallMonitorBase::IsDataReadyL" )
       
   256     
       
   257     // Ensure there is tel Number.
       
   258     HBufC* telNumInfo = HBufC::NewLC( RProperty::KMaxPropertySize );
       
   259     TPtr ptelInfo = telNumInfo->Des();
       
   260     TInt err  = KErrNone;
       
   261        
       
   262     err = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   263                             NMusSessionInformationApi::KMusTelNumber,
       
   264                             ptelInfo );
       
   265 
       
   266     TBool telInfoExisit ( err == KErrNone && telNumInfo->Des().Length() > 0 );
       
   267     CleanupStack::PopAndDestroy( telNumInfo );
       
   268     
       
   269     // Ensure Call direction info is there
       
   270     TInt callDirection = NMusSessionInformationApi::ENoDirection;
       
   271     err = RProperty::Get( 
       
   272                     NMusSessionInformationApi::KCategoryUid,
       
   273                     NMusSessionInformationApi::KMusCallDirection,
       
   274                     callDirection );
       
   275     
       
   276     TBool callInfoExisit ( err == KErrNone && callDirection != NMusSessionInformationApi::ENoDirection );
       
   277     
       
   278     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::IsDataReadyL" )
       
   279     return telInfoExisit && callInfoExisit;
       
   280     }
       
   281 
       
   282 // End of file
       
   283