emailuis/emailui/src/FreestyleEmailUiPropertySubscriber.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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: Used for observing property changes and notifying listeners.
       
    15  *
       
    16  */
       
    17 
       
    18 // CLASS HEADER
       
    19 #include "FreestyleEmailUiPropertySubscriber.h"
       
    20 
       
    21 
       
    22 // CONSTRUCTION AND DESTRUCTION
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // Private C++ constructor.  
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 CFreestyleEmailUiPropertySubscriber::CFreestyleEmailUiPropertySubscriber(
       
    29 	MFreestyleEmailUiPropertyChangedObserver& aObserver ) 
       
    30     : CActive( EPriorityStandard ),
       
    31     iPropertyChangeObserver( aObserver )
       
    32 	{
       
    33 	// No implementation required.
       
    34     }
       
    35 
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // Two-phase constructor.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CFreestyleEmailUiPropertySubscriber* CFreestyleEmailUiPropertySubscriber::NewLC(
       
    42     const TUid aUid, 
       
    43     const TUint32 aKey,
       
    44     MFreestyleEmailUiPropertyChangedObserver& aObserver )
       
    45 	{
       
    46     CFreestyleEmailUiPropertySubscriber* self =
       
    47 		new ( ELeave ) CFreestyleEmailUiPropertySubscriber( aObserver );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( aUid, aKey );
       
    50     return self;
       
    51     }
       
    52 
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // Two-phase constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CFreestyleEmailUiPropertySubscriber* CFreestyleEmailUiPropertySubscriber::NewL(
       
    59     const TUid aUid, 
       
    60     const TUint32 aKey,
       
    61     MFreestyleEmailUiPropertyChangedObserver& aObserver )
       
    62     {
       
    63     CFreestyleEmailUiPropertySubscriber* self =
       
    64 		CFreestyleEmailUiPropertySubscriber::NewLC( aUid, aKey, aObserver );
       
    65     CleanupStack::Pop( self );
       
    66     return self;
       
    67     }
       
    68 
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // Second phase constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CFreestyleEmailUiPropertySubscriber::ConstructL( const TUid aUid,
       
    75 													const TUint32 aKey )
       
    76     {
       
    77     User::LeaveIfError( iProperty.Attach( aUid, aKey ) );
       
    78     CActiveScheduler::Add( this ); // Add to scheduler.
       
    79     // The initial subscription and processing of the current property value.
       
    80     RunL();
       
    81     }
       
    82 
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // Destructor.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CFreestyleEmailUiPropertySubscriber::~CFreestyleEmailUiPropertySubscriber()
       
    89     {
       
    90     Cancel(); // Cancel any pending request.
       
    91     iProperty.Close();
       
    92     }
       
    93 
       
    94 
       
    95 // PRIVATE METHODS FROM CACTIVE
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // Handles completion.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CFreestyleEmailUiPropertySubscriber::RunL()
       
   102     {
       
   103     // Resubscribe before processing a new value in order to prevent missing
       
   104     // updates.
       
   105     iProperty.Subscribe( iStatus );
       
   106     SetActive();
       
   107      
       
   108     TInt intValue( 0 );
       
   109 
       
   110     if ( iProperty.Get( intValue ) == KErrNone )
       
   111     	{
       
   112         iPropertyChangeObserver.PropertyChangedL( intValue );
       
   113         }
       
   114     }
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // Cancels the pending requests.
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CFreestyleEmailUiPropertySubscriber::DoCancel()
       
   122     {
       
   123     iProperty.Cancel();
       
   124     }
       
   125 
       
   126 
       
   127 // End of file.