phoneengine/phonemodel/src/tperemotepartyinfomediatorupdater.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     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:  Updates remote party information via mediator.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "tperemotepartyinfomediatorupdater.h"
       
    19 #include "mpemediator.h"
       
    20 #include "mpedatastore.h"
       
    21 
       
    22 #include <talogger.h>
       
    23 #include <MediatorDomainUIDs.h>
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // C++ constructor
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 TPERemotePartyInfoMediatorUpdater::TPERemotePartyInfoMediatorUpdater(
       
    30     MPEMediator& aMediator,
       
    31     MPEDataStore& aDataStore ) 
       
    32     : iMediator( aMediator ),
       
    33     iDataStore( aDataStore )
       
    34     {
       
    35     }
       
    36    
       
    37 // ---------------------------------------------------------------------------
       
    38 // Sends mediator event with remote info.
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 void TPERemotePartyInfoMediatorUpdater::Update()
       
    42     {
       
    43     HBufC8* data = NULL;
       
    44     TRAPD( err, data = TakeSnapshotOfRemotePartyInfosL() );
       
    45     if ( !err )
       
    46         {
       
    47         iMediator.RaiseEvent( 
       
    48                 KCatCallRemotePartyInformation,
       
    49                 EChangesInRemotePartyInformation,
       
    50                 *data );
       
    51         }
       
    52     delete data;
       
    53         
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // From base class MMediatorCommandObserver
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 void TPERemotePartyInfoMediatorUpdater::MediatorCommandL( 
       
    61     TUid aDomain,
       
    62     TUid aCategory, 
       
    63     TInt aCommandId,
       
    64     TVersion /*aVersion*/, 
       
    65     const TDesC8& /*aData*/ )
       
    66     {
       
    67     if ( aDomain == KMediatorTelephonyDomain &&
       
    68          aCategory == KCatCallRemotePartyInformation &&
       
    69          aCommandId == EGetCallRemotePartyInformation )
       
    70         {
       
    71         HBufC8* data = TakeSnapshotOfRemotePartyInfosL();
       
    72         
       
    73         iMediator.SendResponse( 
       
    74             KCatCallRemotePartyInformation,
       
    75             EGetCallRemotePartyInformation,
       
    76             *data );
       
    77     
       
    78         delete data;
       
    79         }
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // From base class MMediatorCommandObserver
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void TPERemotePartyInfoMediatorUpdater::CancelMediatorCommand( 
       
    87     TUid /*aDomain*/,
       
    88     TUid /*aCategory*/, 
       
    89     TInt /*aCommandId*/ )
       
    90     {
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // Takes remote party information from all calls and packs them to 
       
    95 // descriptor.
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 HBufC8* TPERemotePartyInfoMediatorUpdater::TakeSnapshotOfRemotePartyInfosL()
       
    99     {
       
   100     CCallRemotePartyInfos* infos = CCallRemotePartyInfos::NewLC();
       
   101     for ( TInt callId = 0; callId < KPEMaximumNumberOfCalls; callId++ )
       
   102         {
       
   103         const TInt callIndex = iDataStore.CallIndex( callId );
       
   104         if ( callIndex != KPEInvalidCallIndex )
       
   105             {
       
   106             CCallRemotePartyInfo* info = CCallRemotePartyInfo::NewLC();
       
   107             info->SetCallIndex( callIndex );
       
   108             
       
   109             if ( iDataStore.RemoteColpNumber( callId ).Length() )
       
   110                 {
       
   111                 info->SetAddressL( iDataStore.RemoteColpNumber( callId ) );
       
   112                 }
       
   113             else
       
   114                 {
       
   115                 info->SetAddressL( iDataStore.RemotePhoneNumber( callId ) );    
       
   116                 }            
       
   117             
       
   118             info->SetMatchedNameL( iDataStore.RemoteName( callId ) );
       
   119             info->SetCompanyNameL( iDataStore.RemoteCompanyName( callId ) );
       
   120             info->SetNameFromNetworkL( iDataStore.RemotePartyName( callId ) );
       
   121             
       
   122             if ( iDataStore.CallOrigin( callId ) == EPECallOriginSAT )
       
   123                 {
       
   124                 info->SetSATCall( ETrue );
       
   125                 }  
       
   126             
       
   127             info->SetRemoteIdentity( ResolveRemoteIdentity( callId ) );
       
   128                         
       
   129             infos->AddL( info );
       
   130             CleanupStack::Pop( info );
       
   131             }
       
   132         }
       
   133     HBufC8* data = infos->ExternalizeL();
       
   134     CleanupStack::PopAndDestroy( infos );
       
   135     return data;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // Sets remote party identity.
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 MCallRemotePartyInfo::TRemoteIdentityStatus
       
   143     TPERemotePartyInfoMediatorUpdater::ResolveRemoteIdentity( const TInt aCallId )
       
   144     {    
       
   145     MCallRemotePartyInfo::TRemoteIdentityStatus remoteIdentity;
       
   146     if ( iDataStore.CallDirection( aCallId ) == RMobileCall::EMobileOriginated  )
       
   147         {
       
   148         // In MO case Remote party address is always available 
       
   149         remoteIdentity = MCallRemotePartyInfo::ERemoteIdentityAvailable;
       
   150         }
       
   151     else
       
   152         {
       
   153         remoteIdentity = ConvertRemoteIdentity( aCallId );    
       
   154         }                 
       
   155     
       
   156     return remoteIdentity;
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // Converts remote party identity.
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 MCallRemotePartyInfo::TRemoteIdentityStatus 
       
   164     TPERemotePartyInfoMediatorUpdater::ConvertRemoteIdentity( const TInt aCallId )
       
   165     {    
       
   166     RMobileCall::TMobileCallRemoteIdentityStatus etelRemoteIdentity = iDataStore.RemoteIdentity( aCallId );    
       
   167     MCallRemotePartyInfo::TRemoteIdentityStatus remoteIdentity;
       
   168     
       
   169     switch ( etelRemoteIdentity )
       
   170             {
       
   171             case RMobileCall::ERemoteIdentityUnknown:
       
   172             case RMobileCall::ERemoteIdentityAvailableNoCliUnavailable:
       
   173                 {
       
   174                 remoteIdentity = MCallRemotePartyInfo::ERemoteIdentityUnknown;
       
   175                 }
       
   176                 break;
       
   177             case RMobileCall::ERemoteIdentityAvailable:
       
   178                 {
       
   179                 remoteIdentity = MCallRemotePartyInfo::ERemoteIdentityAvailable;
       
   180                 }
       
   181                 break;
       
   182             case RMobileCall::ERemoteIdentitySuppressed:
       
   183             case RMobileCall::ERemoteIdentityAvailableNoCliRejectedByUser:
       
   184                 {
       
   185                 remoteIdentity = MCallRemotePartyInfo::ERemoteIdentityRejectedByUser;
       
   186                 }
       
   187                 break;
       
   188             case RMobileCall::ERemoteIdentityAvailableNoCliInteractionWithOtherService:
       
   189             case RMobileCall::ERemoteIdentityUnavailableNoCliInteractionWithOtherService:
       
   190                 {
       
   191                 remoteIdentity = MCallRemotePartyInfo::ERemoteIdentityNoCliInteractionWithOtherService;
       
   192                 }
       
   193                 break;
       
   194             case RMobileCall::ERemoteIdentityAvailableNoCliCoinOrPayphone:
       
   195             case RMobileCall::ERemoteIdentityUnavailableNoCliCoinOrPayphone:
       
   196                 {
       
   197                 remoteIdentity = MCallRemotePartyInfo::ERemoteIdentityNoCliCoinOrPayphone;
       
   198                 }
       
   199                 break;
       
   200             default:
       
   201                 {
       
   202                 TEFLOGSTRING( KTAERROR, "TPERemotePartyInfoMediatorUpdater::ConvertRemoteIdentity, UNKNOWN REMOTE IDENTITY!" );
       
   203                 remoteIdentity = MCallRemotePartyInfo::ERemoteIdentityUnknown;                
       
   204                 break;
       
   205                 }
       
   206             }    
       
   207     return remoteIdentity;
       
   208     }
       
   209