mmsharing/mmshavailability/src/musavacalleventmonitor.cpp
changeset 22 496ad160a278
equal deleted inserted replaced
15:ccd8e69b5392 22:496ad160a278
       
     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 // aTelNumber will be filled with telephone number or SIP URI of current
       
   123 // connected call
       
   124 // --------------------------------------------------------------------------
       
   125 //
       
   126 void
       
   127 CMusAvaCallEventMonitor::GetTelNumberL( TDes& aTelNumber, TBool& aIsSipUri )
       
   128 
       
   129     {
       
   130     MUS_LOG( "mus: [CMusAvaCallEventMonitor]  -> CMusAvaCallEventMonitor::\
       
   131         GetTelNumberL" )
       
   132 
       
   133     TInt error = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   134                                  NMusSessionInformationApi::KMusTelNumber,
       
   135                                  aTelNumber );
       
   136 
       
   137     MUS_LOG1( "mus: [CMusAvaCallEventMonitor]  CMusAvaCallEventMonitor::\
       
   138         GetTelNumberL (%d)", error )
       
   139 
       
   140     if ( error == KErrOverflow )
       
   141         {
       
   142         MUS_LOG1( "mus: [CMusAvaCallEventMonitor]  CMusAvaCallEventMonitor::\
       
   143             GetTelNumberL - Buffer too small (%d), leave", 
       
   144             aTelNumber.MaxLength() )
       
   145         User::Leave( error );
       
   146         }
       
   147     User::LeaveIfError( error );
       
   148     
       
   149     aIsSipUri = IsSipUri( aTelNumber );
       
   150     MUS_LOG1( "mus: [CMusAvaCallEventMonitor]  CMusAvaCallEventMonitor::\
       
   151           GetTelNumberL (is SIP URI=%d)", aIsSipUri )
       
   152     
       
   153     MUS_LOG( "mus: [CMusAvaCallEventMonitor]  <- CMusAvaCallEventMonitor::\
       
   154         GetTelNumberL" )
       
   155     }
       
   156 
       
   157 
       
   158 // --------------------------------------------------------------------------
       
   159 // Subscribe to the property, means start monitoring the property
       
   160 // --------------------------------------------------------------------------
       
   161 //
       
   162 void CMusAvaCallEventMonitor::StartMonitoringL()
       
   163     {
       
   164     MUS_LOG( "mus: [CMusAvaCallEventMonitor]  -> CMusAvaCallEventMonitor::\
       
   165         StartMonitoringL" )
       
   166     if ( !IsActive() )
       
   167         {
       
   168         MUS_LOG( "mus: [CMusAvaCallEventMonitor]   CMusAvaCallEventMonitor::\
       
   169             StartMonitoringL - Not active, starting" )
       
   170         User::LeaveIfError( iPropertyEvent.Attach(
       
   171             NMusSessionInformationApi::KCategoryUid,
       
   172             NMusSessionInformationApi::KMusCallEvent ) );
       
   173         // initial subscription and process current property value
       
   174         iPropertyEvent.Subscribe( iStatus );
       
   175         SetActive();
       
   176         }
       
   177     MUS_LOG( "mus: [CMusAvaCallEventMonitor]  <- CMusAvaCallEventMonitor::\
       
   178         StartMonitoringL" )
       
   179     }
       
   180 
       
   181 
       
   182 // --------------------------------------------------------------------------
       
   183 // Called by Cancel()
       
   184 // --------------------------------------------------------------------------
       
   185 //
       
   186 void CMusAvaCallEventMonitor::DoCancel()
       
   187     {
       
   188     iPropertyEvent.Cancel();
       
   189     iPropertyEvent.Close();
       
   190     }
       
   191 
       
   192 
       
   193 // --------------------------------------------------------------------------
       
   194 // Active Object RunL implementation. Will be called when property changes.
       
   195 // --------------------------------------------------------------------------
       
   196 //
       
   197 void CMusAvaCallEventMonitor::RunL()
       
   198     {
       
   199     MUS_LOG( "mus: [MUSAOP]  -> CMusAvaCallEventMonitor::RunL" )
       
   200 
       
   201     // resubscribe before processing new value to prevent missing updates
       
   202     iPropertyEvent.Subscribe( iStatus );
       
   203     SetActive();
       
   204 
       
   205     // property updated, get new value
       
   206     TInt callStatus;
       
   207     if ( iPropertyEvent.Get( callStatus ) == KErrNotFound )
       
   208         {
       
   209         // property deleted
       
   210         iObserver.NoActiveCallL();
       
   211         }
       
   212     else
       
   213         {
       
   214         switch( callStatus )
       
   215             {
       
   216             case NMusSessionInformationApi::ENoCall:
       
   217                 {
       
   218                 iObserver.NoActiveCallL();
       
   219                 break;
       
   220                 }
       
   221 
       
   222             case NMusSessionInformationApi::ECallConnected:
       
   223                 {
       
   224                 TBuf<KMusTelNumberMaxLength> telNumber;
       
   225                 TBool isSipUri( EFalse );
       
   226                 GetTelNumberL( telNumber, isSipUri );
       
   227                 iObserver.CallConnectedL( telNumber, isSipUri );
       
   228                 break;
       
   229                 }
       
   230 
       
   231             case NMusSessionInformationApi::ECallHold:
       
   232                 {
       
   233                 TBuf<KMusTelNumberMaxLength> telNumber;
       
   234                 TBool isSipUri( EFalse );
       
   235                 GetTelNumberL( telNumber, isSipUri );
       
   236                 iObserver.CallHoldL( telNumber, isSipUri );
       
   237                 break;
       
   238                 }
       
   239 
       
   240             case NMusSessionInformationApi::EConferenceCall:
       
   241                 {
       
   242                 iObserver.ConferenceCallL();
       
   243                 break;
       
   244                 }
       
   245 
       
   246             default:
       
   247                 {
       
   248                 iObserver.NoActiveCallL();
       
   249                 break;
       
   250                 }
       
   251             }
       
   252         }
       
   253 
       
   254     MUS_LOG( "mus: [MUSAOP]  <- CMusAvaCallEventMonitor::RunL" )
       
   255     }
       
   256 
       
   257 
       
   258 // --------------------------------------------------------------------------
       
   259 // RunL leaves will be handled here. Make sure it returns KErrNone
       
   260 // Otherwise Active Scheduler Error() will be called.
       
   261 // --------------------------------------------------------------------------
       
   262 //
       
   263 TInt CMusAvaCallEventMonitor::RunError( TInt aError )
       
   264     {
       
   265     MUS_LOG1( "mus: [MUSAOP]  -> CMusAvaCallEventMonitor::RunError(%d)",
       
   266         aError )
       
   267 
       
   268     // Not much things can be done here as cleanup operation.
       
   269     aError = KErrNone;
       
   270 
       
   271     MUS_LOG( "mus: [MUSAOP]  <- CMusAvaCallEventMonitor::RunError" )
       
   272     return aError;
       
   273     }
       
   274 
       
   275 
       
   276 // --------------------------------------------------------------------------
       
   277 // CMusAvaCallEventMonitor::IsSipUri()
       
   278 // --------------------------------------------------------------------------
       
   279 //
       
   280 TBool CMusAvaCallEventMonitor::IsSipUri( const TDesC& aTelNumber ) const
       
   281     {
       
   282     _LIT( KSipPrefix, "sip:" );
       
   283      TPtrC prefix = aTelNumber.Left( KSipPrefix().Length() );
       
   284      return prefix.Compare( KSipPrefix ) == 0;
       
   285      }