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