callcontinuity/vccpropertyhandler/src/vccuipspropertylistener.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:   Observes the state of a Vcc P&S property
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32cmn.h>
       
    20 #include <e32debug.h>
       
    21 #include <vccsubscribekeys.h>
       
    22 
       
    23 #include "vccuipspropertylistener.h"
       
    24 #include "rubydebug.h"
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 // -----------------------------------------------------------------------------
       
    28 // C++ constructor
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CVccUiPsPropertyListener::CVccUiPsPropertyListener( const TUint aKeyId )
       
    32     :CActive( EPriorityStandard ),
       
    33      iCategoryId( KPSVccPropertyCategory ),
       
    34      iKeyId( aKeyId )
       
    35     {
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // 2nd phase constructor
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 void CVccUiPsPropertyListener::ConstructL()
       
    43     {
       
    44     RUBY_DEBUG_BLOCKL( "CVccUiPsPropertyListener::ConstructL" );
       
    45     // Attach to categroy and key.
       
    46     User::LeaveIfError( iProperty.Attach( iCategoryId, iKeyId ) );
       
    47     // Add to active scheduler
       
    48     CActiveScheduler::Add( this );
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // Constructor
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 EXPORT_C CVccUiPsPropertyListener* CVccUiPsPropertyListener::NewL(
       
    56     const TUint aKeyId )
       
    57     {
       
    58     RUBY_DEBUG_BLOCKL( "CVccUiPsPropertyListener::NewL" );
       
    59 
       
    60     CVccUiPsPropertyListener* self = new ( ELeave ) CVccUiPsPropertyListener(
       
    61                                                     aKeyId );
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64     CleanupStack::Pop( self );
       
    65 
       
    66     return self;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // Destructor
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C CVccUiPsPropertyListener::~CVccUiPsPropertyListener()
       
    74     {
       
    75     RUBY_DEBUG0( "CVccUiPsPropertyListener::~CVccUiPsPropertyListener() - ENTER" );
       
    76     Cancel();
       
    77     iProperty.Close();
       
    78     iObservers.Close();
       
    79     RUBY_DEBUG0( "CVccUiPsPropertyListener::~CVccUiPsPropertyListener() - EXIT" );
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // Adds a Vcc property observer to the list of observers
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C void CVccUiPsPropertyListener::AddObserverL(
       
    87     MVccPsPropertyListenerObserver& aObserver )
       
    88     {
       
    89     RUBY_DEBUG_BLOCKL( "CVccUiPsPropertyListener::AddObserverL" );
       
    90 
       
    91     if ( iObservers.Find( &aObserver ) == KErrNotFound )
       
    92         {
       
    93         User::LeaveIfError( iObservers.Append( &aObserver ) );
       
    94         }
       
    95     
       
    96     // And then start. Start() do not start if there are no observers
       
    97     // so we must also try to start here after adding an observer
       
    98     // (if somebody has called Start() before this method).
       
    99     Start();
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // Removes observer
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 EXPORT_C void CVccUiPsPropertyListener::RemoveObserver(
       
   107     MVccPsPropertyListenerObserver& aObserver )
       
   108     {
       
   109     RUBY_DEBUG_BLOCK( "CVccUiPsPropertyListener::RemoveObserver" );
       
   110     TInt index = iObservers.Find( &aObserver );
       
   111 
       
   112     if ( index != KErrNotFound )
       
   113         {
       
   114         iObservers.Remove( index );
       
   115         }
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // Fetches the current value of the key
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 EXPORT_C TInt CVccUiPsPropertyListener::CurrentValue()
       
   123     {
       
   124     RUBY_DEBUG_BLOCK( "CVccUiPsPropertyListener::CurrentValue" );
       
   125     TInt value( KErrNotFound );
       
   126     iProperty.Get( iCategoryId, iKeyId, value );
       
   127     return value;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // Subscribes to property
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 EXPORT_C void CVccUiPsPropertyListener::Start()
       
   135     {
       
   136     RUBY_DEBUG_BLOCK( "CVccUiPsPropertyListener::Start" );
       
   137 
       
   138     // If no obsevers, do not start.
       
   139     if ( iObservers.Count() == 0 )
       
   140         {
       
   141         return;
       
   142         }
       
   143     
       
   144     // Subscribe to get updates.
       
   145     if ( !IsActive() )
       
   146         {
       
   147         iProperty.Subscribe( iStatus );       
       
   148         SetActive();
       
   149         }
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // Cancels the outstanding subsription request
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CVccUiPsPropertyListener::DoCancel()
       
   157     {
       
   158     RUBY_DEBUG0( "CVccUiPsPropertyListener::DoCancel - ENTER" );
       
   159     iProperty.Cancel();
       
   160     RUBY_DEBUG0( "CVccUiPsPropertyListener::DoCancel - EXIT" );
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // Handles the request completion event
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CVccUiPsPropertyListener::RunL()
       
   168     {
       
   169     RUBY_DEBUG_BLOCKL( "CVccUiPsPropertyListener::RunL" );
       
   170     TInt err = iStatus.Int();
       
   171 
       
   172     // Re-issue the subscription request if there are observers.
       
   173     // Do this before notifying our observser so that we get all
       
   174     // notifications (if the rest of the RunL takes some time).
       
   175     
       
   176     if ( iObservers.Count() > 0 )
       
   177         {
       
   178         Start();
       
   179         }
       
   180      
       
   181     if ( KErrNone == err )
       
   182         {
       
   183         // Notify property changes to observers.
       
   184         NotifyObserversL();
       
   185         }    
       
   186      }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // Notifies all observers about the changed value
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CVccUiPsPropertyListener::NotifyObserversL()
       
   193     {
       
   194     RUBY_DEBUG_BLOCKL( "CVccUiPsPropertyListener::NotifyObserversL" );
       
   195 
       
   196     TInt value = CurrentValue();
       
   197 
       
   198     RUBY_DEBUG1( " -value[%d]", value);
       
   199 
       
   200     for ( TInt i(0) ; i < iObservers.Count() ; i++ )
       
   201         {
       
   202         MVccPsPropertyListenerObserver* observer = iObservers[i];
       
   203 
       
   204         if ( observer )
       
   205             {
       
   206             observer->VccPropertyChangedL( iKeyId, value );
       
   207             }
       
   208         }
       
   209     }