menufw/menufwui/matrixmenu/src/mmpropertysubscriber.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 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:  Subscribes properties from P&S
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mmpropertysubscriber.h"
       
    20 
       
    21 // -----------------------------------------------------------------------------
       
    22 // -----------------------------------------------------------------------------
       
    23 //
       
    24 CMmPropertySubscriber::CMmPropertySubscriber(MMmPropertyChangeObserver& aObserver) 
       
    25     : CActive( EPriorityStandard ),
       
    26     iPropertyChangeObserver(aObserver)
       
    27      {
       
    28      }
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CMmPropertySubscriber* CMmPropertySubscriber::NewLC(
       
    34     const TUid aUid, 
       
    35     const TUint32 aKey,
       
    36     MMmPropertyChangeObserver& aObserver)
       
    37     {
       
    38     CMmPropertySubscriber* self = new ( ELeave ) CMmPropertySubscriber(aObserver);
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL(aUid,aKey);
       
    41     return self;
       
    42     }
       
    43 // -----------------------------------------------------------------------------
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CMmPropertySubscriber* CMmPropertySubscriber::NewL(
       
    47     const TUid aUid, 
       
    48     const TUint32 aKey,
       
    49     MMmPropertyChangeObserver& aObserver)
       
    50     {
       
    51     CMmPropertySubscriber* self = CMmPropertySubscriber::NewLC(aUid,aKey,aObserver);
       
    52     CleanupStack::Pop(); // self;
       
    53     return self;
       
    54     }
       
    55 // -----------------------------------------------------------------------------
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CMmPropertySubscriber::ConstructL(
       
    59     const TUid aUid, 
       
    60     const TUint32 aKey)
       
    61     {
       
    62     User::LeaveIfError( iProperty.Attach( aUid, aKey ) );
       
    63     CActiveScheduler::Add( this); // Add to scheduler
       
    64     // initial subscription and process current property value
       
    65     RunL();
       
    66     }
       
    67 // -----------------------------------------------------------------------------
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CMmPropertySubscriber::~CMmPropertySubscriber()
       
    71     {
       
    72     Cancel(); // Cancel any request, if outstanding
       
    73     iProperty.Close();
       
    74     }
       
    75 // -----------------------------------------------------------------------------
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CMmPropertySubscriber::DoCancel()
       
    79     {
       
    80     iProperty.Close();
       
    81     }
       
    82 // -----------------------------------------------------------------------------
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CMmPropertySubscriber::RunL()
       
    86     {
       
    87     // resubscribe before processing new value to prevent missing updates
       
    88     iProperty.Subscribe( iStatus );
       
    89     SetActive();
       
    90      
       
    91     TInt intValue;
       
    92     if( iProperty.Get( intValue ) != KErrNotFound )
       
    93         {
       
    94         iPropertyChangeObserver.PropertyChangedL(intValue);
       
    95         }
       
    96     }
       
    97