mmshplugins/mmshaoplugin/src/muspropertymonitor.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 #include "muspropertymonitor.h"
       
    20 #include "mussesseioninformationapi.h"
       
    21 #include "muslogger.h"
       
    22 
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // Symbian two-phase constructor.
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 CMusPropertyMonitor* CMusPropertyMonitor::NewL( MMusCallStateObserver& aCallStateObserver )  
       
    29     {
       
    30     MUS_LOG( "mus: [MUSAO]  -> CMusPropertyMonitor::NewL" )
       
    31     CMusPropertyMonitor* self = new (ELeave) CMusPropertyMonitor( aCallStateObserver );
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop( self );
       
    35     MUS_LOG( "mus: [MUSAO]  <- CMusPropertyMonitor::NewL" )
       
    36     return self;
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // C++ constructor.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CMusPropertyMonitor::CMusPropertyMonitor( MMusCallStateObserver& aCallStateObserver )
       
    44     :CActive( EPriorityNormal ), iCallStateObserver ( aCallStateObserver )
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // Symbian second-phase constructor.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CMusPropertyMonitor::ConstructL()
       
    53     {
       
    54     MUS_LOG( "mus: [MUSAO]  -> CMusPropertyMonitor::ConstructL" )
       
    55     CActiveScheduler::Add(this);
       
    56     User::LeaveIfError( 
       
    57             iPropertyEvent.Attach(
       
    58                                 NMusSessionInformationApi::KCategoryUid,
       
    59                                 NMusSessionInformationApi::KMusCallEvent ) );
       
    60     MUS_LOG( "mus: [MUSAO] Property attached to KMusCallEvent" )    
       
    61     iPropertyEvent.Subscribe( iStatus );
       
    62     SetActive();
       
    63     MUS_LOG( "mus: [MUSAO]  <- CMusPropertyMonitor::ConstructL" )
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // C++ destructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CMusPropertyMonitor::~CMusPropertyMonitor()
       
    71     {
       
    72     MUS_LOG( "mus: [MUSAO]  -> CMusPropertyMonitor::~CMusPropertyMonitor" )
       
    73     Cancel();
       
    74     iPropertyEvent.Close(); 
       
    75     MUS_LOG( "mus: [MUSAO]  -> <- CMusPropertyMonitor::~CMusPropertyMonitor" )
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CMusPropertyMonitor::RunL()
       
    80 // Implemented for CActive.It will be called automatically
       
    81 // when new property event occurs
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CMusPropertyMonitor::RunL()
       
    85     {
       
    86     MUS_LOG( "mus: [MUSAO]  -> CMusPropertyMonitor::RunL" )
       
    87 
       
    88     // resubscribe before processing new value to prevent missing updates
       
    89     iPropertyEvent.Subscribe( iStatus );
       
    90     SetActive();    
       
    91 
       
    92     //Check if preconditions are met to start or stop the MushClient.
       
    93     iCallStateObserver.MusCallStateChanged();
       
    94 
       
    95     MUS_LOG( "mus: [MUSAO]  <- CMusPropertyMonitor::RunL" )
       
    96     }
       
    97 
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CMusPropertyMonitor::DoCancel()
       
   101 // Implemented for CActive.Will be called when Cancel() method called.
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CMusPropertyMonitor::DoCancel()
       
   105     {
       
   106     MUS_LOG( "mus: [MUSAO]  -> CMusPropertyMonitor::DoCancel" )
       
   107     iPropertyEvent.Cancel();
       
   108     MUS_LOG( "mus: [MUSAO]  <- CMusPropertyMonitor::DoCancel" )
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CMusPropertyMonitor::RunError()
       
   113 // Implemented for CActive.It will be called automatically
       
   114 // when a leave occurs in RunL()
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 TInt CMusPropertyMonitor::RunError(TInt aError)
       
   118     {
       
   119     MUS_LOG1( "mus: [MUSAO]  -> CMusPropertyMonitor::RunError = %d",aError )
       
   120     
       
   121     // Monitoring Error Occurred, Terminate the MushSession.
       
   122     TInt err = RProperty::Set( NMusSessionInformationApi::KCategoryUid,
       
   123                           NMusSessionInformationApi::KMusCallEvent,
       
   124                           NMusSessionInformationApi::ENoCall);
       
   125 
       
   126     iCallStateObserver.MusCallStateChanged();
       
   127 
       
   128     aError = KErrNone; // We handled this error already. So return KErrNone.
       
   129     MUS_LOG( "mus: [MUSAO]  <- CMusPropertyMonitor::RunError " )    
       
   130     return aError;
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CMusPropertyMonitor::IsCallConnected()
       
   135 // Checks if the call is connected: 
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 TBool CMusPropertyMonitor::IsCallConnected()
       
   139     {
       
   140     MUS_LOG( "mus: [MUSAO]  -> CMusPropertyMonitor::IsCallConnected" )
       
   141     TInt callState = ( TInt ) NMusSessionInformationApi::ENoCall;
       
   142     TInt err = KErrNone;
       
   143     
       
   144     err = RProperty::Get( NMusSessionInformationApi::KCategoryUid,
       
   145                           NMusSessionInformationApi::KMusCallEvent,
       
   146                           callState );
       
   147     
       
   148     MUS_LOG( "mus: [MUSAO]  <- CMusPropertyMonitor::IsCallConnected" )
       
   149     
       
   150     return ( err == KErrNone && callState != NMusSessionInformationApi::ENoCall );
       
   151     }
       
   152 
       
   153 // End of file