presetserver/serversrc/Pspropertyobserver.cpp
changeset 0 09774dfdd46b
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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:  Observer for Publish & Subscribe keys
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include "pspropertyobserver.h"
       
    21 
       
    22 // ============================ MEMBER FUNCTIONS ===============================
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CPSPropertyObserver::CPSPropertyObserver
       
    26 // C++ default constructor can NOT contain any code, that
       
    27 // might leave.
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CPSPropertyObserver::CPSPropertyObserver(MPSPropertyChangeObserver& aObserver, const TUid& aCategory, const TUint aKey, const RProperty::TType aPropertyType)
       
    31     : CActive( CActive::EPriorityStandard ),
       
    32     iObserver( aObserver ),
       
    33     iCategory( aCategory ),
       
    34     iKey( aKey ),
       
    35     iPropertyType( aPropertyType )
       
    36 	{
       
    37 	}
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CPSPropertyObserver::ConstructL
       
    41 // Symbian 2nd phase constructor can leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void CPSPropertyObserver::ConstructL()
       
    45 	{
       
    46     User::LeaveIfError( iProperty.Attach( iCategory, iKey ) );
       
    47     CActiveScheduler::Add( this );
       
    48     RunL();
       
    49 	}
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CPSPropertyObserver::NewL
       
    53 // Two-phased constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CPSPropertyObserver* CPSPropertyObserver::NewL(MPSPropertyChangeObserver& aObserver, const TUid& aCategory, const TUint aKey, const RProperty::TType aPropertyType)
       
    57 	{
       
    58     CPSPropertyObserver* self = new( ELeave )CPSPropertyObserver( aObserver, aCategory, aKey, aPropertyType );
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63 	}
       
    64 
       
    65 // Destructor
       
    66 CPSPropertyObserver::~CPSPropertyObserver()
       
    67 	{
       
    68 	Cancel();
       
    69     iProperty.Close();
       
    70 	}
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CPSPropertyObserver::RunL
       
    74 // 
       
    75 // (other items were commented in a header).
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CPSPropertyObserver::RunL()
       
    79 	{
       
    80     iProperty.Subscribe( iStatus );
       
    81     SetActive();
       
    82     
       
    83     TInt err(KErrNone);
       
    84     
       
    85     switch (iPropertyType)
       
    86         {
       
    87         case RProperty::EInt:
       
    88 	        {
       
    89 	        err = iProperty.Get( iValueInt );
       
    90 	        if (!err)
       
    91             	{
       
    92                 iObserver.HandlePropertyChangeL( iCategory, iKey, iValueInt );
       
    93              	}
       
    94 	        break;
       
    95 	        }
       
    96 	    case RProperty::EText:
       
    97 	        {
       
    98 	        err = iProperty.Get( iValueText );
       
    99 	        if (!err)
       
   100             	{
       
   101                 iObserver.HandlePropertyChangeL( iCategory, iKey, iValueText );
       
   102              	}
       
   103 	        break;
       
   104 	        }
       
   105 	    default:
       
   106 	        {
       
   107 	        break;
       
   108 	        }
       
   109         }
       
   110     
       
   111     if (err)
       
   112     	{
       
   113         iObserver.HandlePropertyChangeErrorL(iCategory, iKey, err);
       
   114      	}
       
   115 	}
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CPSPropertyObserver::DoCancel
       
   119 // Cancels an outstanding active request
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void CPSPropertyObserver::DoCancel()
       
   123 	{
       
   124     iProperty.Cancel();
       
   125 	}
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CPSPropertyObserver::GetValue
       
   129 // -----------------------------------------------------------------------------
       
   130 //	
       
   131 void CPSPropertyObserver::GetValue(TInt& aValue) const
       
   132 	{
       
   133 	aValue = iValueInt;
       
   134 	}
       
   135 	
       
   136 // -----------------------------------------------------------------------------
       
   137 // CPSPropertyObserver::GetValue
       
   138 // -----------------------------------------------------------------------------
       
   139 //	
       
   140 void CPSPropertyObserver::GetValue(TPSTextProperty& aValue) const
       
   141 	{
       
   142 	aValue = iValueText;
       
   143 	}
       
   144 	
       
   145 // End of File