mmshplugins/mmshaoplugin/src/muscallmonitorbase.cpp
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     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 #include "mussettings.h"
       
    23 
       
    24 #include <etel.h>
       
    25 #include <etelmm.h>
       
    26 #include <e32svr.h>
       
    27 #include <mmtsy_names.h>
       
    28 #include <e32property.h>
       
    29 
       
    30 _LIT( KDoNotSendOwnNumber, "#31#" );
       
    31 _LIT( KDoSendOwnNumber, "*31#" );
       
    32 
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // C++ destructor.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMusCallMonitorBase::~CMusCallMonitorBase()
       
    39     {
       
    40     MUS_LOG( "mus: [MUSAO]  -> CMusCallMonitorBase::~CMusCallMonitorBase" )        
       
    41     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::~CMusCallMonitorBase" )
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // C++ constructor.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CMusCallMonitorBase::CMusCallMonitorBase(const RMobileCall& aCall, MMusTsyPropertyObserver& aObserver ) 
       
    49         : CActive( EPriorityNormal ),iCall(aCall),iTsyObserver( aObserver )
       
    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     * CountOfCallMonitors is number of CallMonitor Objects.Static Reference Count.
       
    72     * = No of active calls . 
       
    73     * React one and only if one call is present -> Mush Call criteria.
       
    74     * if call count is more than one , should be taken care by conference call or
       
    75     * multicall criteria.
       
    76     */
       
    77      if( callCount == 1) 
       
    78         {
       
    79         TInt currentVal;
       
    80         User::LeaveIfError(RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
    81                             NMusSessionInformationApi::KMusCallEvent,currentVal));
       
    82         MUS_LOG1( "mus: [MUSAO]  - Remote State = %d",iRemoteCallEvent )
       
    83         /* If current event is callconnected and remote is not in hold set the
       
    84            property value to CallConnected.Else set it to CallHold.
       
    85            Note : We can be sure about Local is connected when it goes to
       
    86                   CallConnected State. But remote call events are just notified
       
    87                   in call event monitor. So this stores the last remotecall event
       
    88                   and checks it now.
       
    89         */        
       
    90         if( aVal==NMusSessionInformationApi::ECallConnected 
       
    91             && iRemoteCallEvent!=RMobileCall::ERemoteHold)
       
    92             {
       
    93             /* If the current property value is same of new value, there is no
       
    94                point of setting it since it will cause lot of other processes.               
       
    95             */
       
    96             if(currentVal != (TInt)aVal)
       
    97                 {
       
    98                 User::LeaveIfError(RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
    99                                                  NMusSessionInformationApi::KMusCallEvent,
       
   100                                                  aVal ));    
       
   101                 }
       
   102             } 
       
   103         else if( aVal==NMusSessionInformationApi::ECallHold || iRemoteCallEvent==RMobileCall::ERemoteHold )
       
   104             {            
       
   105             User::LeaveIfError(RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
   106                                                NMusSessionInformationApi::KMusCallEvent,
       
   107                                                NMusSessionInformationApi::ECallHold   ));  
       
   108             }          
       
   109         if( aVal != NMusSessionInformationApi::ENoCall)
       
   110             {
       
   111             RMobileCall::TMobileCallInfoV3 callInfo;
       
   112             RMobileCall::TMobileCallInfoV3Pckg pckg( callInfo );
       
   113     
       
   114             User::LeaveIfError(iCall.GetMobileCallInfo( pckg ));  
       
   115             if( callInfo.iEmergency )
       
   116                     {
       
   117                     User::LeaveIfError(RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
   118                                              NMusSessionInformationApi::KMusCallEvent,
       
   119                                              ( TInt ) NMusSessionInformationApi::ENoCall ));
       
   120                     }
       
   121             }
       
   122         /*
       
   123          If Call is Connected then set the Call info.
       
   124          */
       
   125         if( aVal==NMusSessionInformationApi::ECallConnected ) 
       
   126             {
       
   127             SetCallInfoL();
       
   128             }
       
   129         
       
   130         }   
       
   131  
       
   132     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::SetStateL" )    
       
   133     }
       
   134 
       
   135 ///-----------------------------------------------------------------------------
       
   136 // CMusCallMonitorBase::SetCallInfoL( TInt aError )
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CMusCallMonitorBase::SetCallInfoL()
       
   140     {
       
   141     MUS_LOG( "mus: [MUSAO]  -> CMusCallMonitorBase::SetCallInfoL ")           
       
   142     RMobileCall::TMobileCallInfoV3 callInfo;
       
   143     RMobileCall::TMobileCallInfoV3Pckg callInfoPckg( callInfo );
       
   144     User::LeaveIfError(iCall.GetMobileCallInfo( callInfoPckg ));    
       
   145     RMobilePhone::TMobileAddress remoteNumber = 
       
   146                                            callInfo.iRemoteParty.iRemoteNumber;
       
   147      // Set telephone number
       
   148     HBufC* telNo( NULL );
       
   149     HBufC* cleanTelNo( NULL );
       
   150     if( remoteNumber.iTelNumber.Length() > 0 )
       
   151         {
       
   152         MUS_LOG( "mus: [MUSAO]     remoteNumber.iTelNumber.Lenght > 0" )
       
   153         telNo = remoteNumber.iTelNumber.AllocLC();
       
   154         }
       
   155     else
       
   156         {
       
   157         MUS_LOG( "mus: [MUSAO]     remoteNumber.iTelNumber.Lenght =< 0" )
       
   158         RMobilePhone::TMobileAddress dialledParty = callInfo.iDialledParty;
       
   159         telNo = dialledParty.iTelNumber.AllocLC();
       
   160         
       
   161         }
       
   162     if ( MultimediaSharingSettings::PrivacySetting() )
       
   163         {
       
   164         SetClirSetting( *telNo );
       
   165         }
       
   166     cleanTelNo = RemovePrefix( *telNo );
       
   167     CleanupStack::PushL( cleanTelNo );  
       
   168     
       
   169     User::LeaveIfError(RProperty::Set( 
       
   170                                       NMusSessionInformationApi::KCategoryUid,
       
   171                                       NMusSessionInformationApi::KMusTelNumber,
       
   172                                       *cleanTelNo ));  
       
   173     MUS_LOG_TDESC("mus: [MUSAO]     telNo = ", (*cleanTelNo))
       
   174     CleanupStack::PopAndDestroy(cleanTelNo);
       
   175     CleanupStack::PopAndDestroy(telNo);
       
   176     
       
   177     // Set call direction.
       
   178     RMobileCall::TMobileCallDirection direction =
       
   179                                             callInfo.iRemoteParty.iDirection;
       
   180     MUS_LOG1( "mus: [MUSAO]  Call Direction = %d",direction )
       
   181     if( direction == RMobileCall::EMobileOriginated )
       
   182         {
       
   183         User::LeaveIfError(RProperty::Set( 
       
   184                         NMusSessionInformationApi::KCategoryUid,
       
   185                         NMusSessionInformationApi::KMusCallDirection,
       
   186                         ( TInt ) NMusSessionInformationApi::ECallOrginated ));
       
   187         }
       
   188     else if ( direction  == RMobileCall::EMobileTerminated )
       
   189         {
       
   190         SetTerminatingPrivacy( iCall );
       
   191         User::LeaveIfError(RProperty::Set( 
       
   192                         NMusSessionInformationApi::KCategoryUid,
       
   193                         NMusSessionInformationApi::KMusCallDirection,
       
   194                         ( TInt ) NMusSessionInformationApi::ECallTerminated ));
       
   195         }
       
   196     else
       
   197         {
       
   198         User::LeaveIfError(RProperty::Set( 
       
   199                         NMusSessionInformationApi::KCategoryUid,
       
   200                         NMusSessionInformationApi::KMusCallDirection,
       
   201                         ( TInt ) NMusSessionInformationApi::ENoDirection ));
       
   202         }
       
   203     
       
   204     
       
   205     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::SetCallInfoL" )  
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CMusCallMonitorBase::RunError( TInt aError )
       
   210 // Implemented for CActive.
       
   211 // Will be called automatically by framework when RunL Leaves.
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 
       
   215 TInt CMusCallMonitorBase::RunError( TInt aError )
       
   216     {
       
   217     MUS_LOG1( "mus: [MUSAO]  -> CMusCallMonitorBase::RunError, aError %d",\
       
   218                                                                       aError )
       
   219     aError = KErrNone; // just to avoid warnings.
       
   220     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::RunError" )    
       
   221     return aError;
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CMusCallMonitorBase::NotifyCallStateChanged()
       
   226 // Notify TSYobserver that our call status or call event state changed
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CMusCallMonitorBase::NotifyCallStateChanged( NMusSessionInformationApi::TMusCallEvent aVal )
       
   230     {
       
   231     RCall::TCallInfo callInfo;
       
   232     iCall.GetInfo(callInfo);
       
   233     iTsyObserver.NotifyCallStateChanged( aVal, callInfo.iCallName );
       
   234     }
       
   235 
       
   236 // --------------------------------------------------------------------------
       
   237 // void CMusCallMonitorBase::SetClirSetting()
       
   238 // Determine CLIR setting from dialled digits
       
   239 // --------------------------------------------------------------------------
       
   240 //
       
   241 void CMusCallMonitorBase::SetClirSetting( const TDesC& aDialledNumber ) const
       
   242     {
       
   243     MUS_LOG( "mus: [MUSAO]  -> CMusCallMonitorBase::SetClirSetting" );
       
   244 
       
   245     NMusSessionInformationApi::TMusClirSetting 
       
   246         sendNumber( NMusSessionInformationApi::ESendOwnNumber );
       
   247 
       
   248     TPtrC prefix = aDialledNumber.Left( KDoNotSendOwnNumber().Length() );
       
   249     if ( prefix == KDoNotSendOwnNumber() )
       
   250         {
       
   251         sendNumber = NMusSessionInformationApi::EDoNotSendOwnNumber;
       
   252         }
       
   253     RProperty::Set( NMusSessionInformationApi::KCategoryUid, 
       
   254                     NMusSessionInformationApi::KMusClirSetting, sendNumber );
       
   255     MUS_LOG1( "mus: [MUSAO]  <- CMusCallMonitorBase::SetClirSetting send nbr=%d",
       
   256     sendNumber == NMusSessionInformationApi::ESendOwnNumber );
       
   257     }
       
   258 
       
   259 
       
   260 // --------------------------------------------------------------------------
       
   261 // void CMusCallMonitorBase::RemovePrefix()
       
   262 // --------------------------------------------------------------------------
       
   263 //
       
   264 HBufC* CMusCallMonitorBase::RemovePrefix( const TDesC& aOriginator ) const
       
   265     {
       
   266     MUS_LOG( "mus: [MUSAO]  -> CMusCallMonitorBase::removePrefix" );
       
   267 
       
   268     HBufC * withoutPrefix(NULL);
       
   269     
       
   270     TPtrC prefix = aOriginator.Left( KDoNotSendOwnNumber().Length() );
       
   271     if ( prefix == KDoNotSendOwnNumber()|| prefix == KDoSendOwnNumber() )
       
   272         {
       
   273         MUS_LOG( "Number have a prefix" );
       
   274         withoutPrefix = aOriginator.AllocL();
       
   275         *withoutPrefix = aOriginator;
       
   276         TPtr ptr = withoutPrefix->Des();
       
   277         ptr.Delete(0,KDoNotSendOwnNumber().Length());
       
   278         }
       
   279     else
       
   280         {
       
   281         withoutPrefix = aOriginator.AllocL();
       
   282         }
       
   283     
       
   284     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::RemovePrefix" );
       
   285     return withoutPrefix;
       
   286     }
       
   287 
       
   288 
       
   289 // --------------------------------------------------------------------------
       
   290 // void CMusCallMonitorBase::SetTerminatingPrivacy()
       
   291 // --------------------------------------------------------------------------
       
   292 //
       
   293 void CMusCallMonitorBase::SetTerminatingPrivacy( const RMobileCall& aCall ) const
       
   294     {
       
   295     MUS_LOG( "mus: [MUSAO]  -> CMusCallMonitorBase::SetTerminatingPrivacy" )
       
   296     RMobileCall::TMobileCallInfoV3 callInfo;
       
   297     RMobileCall::TMobileCallInfoV3Pckg callInfoPckg( callInfo );
       
   298     if( aCall.GetMobileCallInfo( callInfoPckg ) != KErrNone )
       
   299         {
       
   300         return; // error cannot do
       
   301         }
       
   302     MUS_LOG( "mus: [MUSAO] Get remote status" )
       
   303     RMobileCall::TMobileCallRemoteIdentityStatus remoteStatus = 
       
   304                     callInfo.iRemoteParty.iRemoteIdStatus;
       
   305             
       
   306     if( remoteStatus == RMobileCall::ERemoteIdentitySuppressed )
       
   307         {
       
   308          RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
   309                         NMusSessionInformationApi::KMUSPrivacy,
       
   310                         ( TInt ) NMusSessionInformationApi::EPrivacyOn );
       
   311         }
       
   312     else
       
   313         {
       
   314         RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
   315                         NMusSessionInformationApi::KMUSPrivacy,
       
   316                         ( TInt ) NMusSessionInformationApi::EPrivacyOff );
       
   317         }
       
   318     MUS_LOG1( "mus: [MUSAO] Remote status = %d",remoteStatus )
       
   319     MUS_LOG( "mus: [MUSAO]  <- CMusCallMonitorBase::SetTerminatingPrivacy" )
       
   320     }
       
   321 
       
   322 // End of file
       
   323