internetradio2.0/uisrc/irchangeobserver.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 "irchangeobserver.h"
       
    20 #include "irdebug.h"
       
    21 
       
    22 // ============================ MEMBER FUNCTIONS ===============================
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CIRObserver::CIRObserver
       
    26 // C++ default constructor CIRObserver
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CIRObserver::CIRObserver(MIRChangeObserver& aObserver, const TUid& aCategory, 
       
    30 	const TUint aKey, const RProperty::TType aPropertyType)
       
    31     : CActive( CActive::EPriorityLow ),
       
    32     iObserver( aObserver ),
       
    33     iCategory( aCategory ),
       
    34     iKey( aKey ),
       
    35     iPropertyType( aPropertyType )
       
    36 	{
       
    37 	IRLOG_DEBUG( "CIRObserver::CIRObserver" );
       
    38 	}
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CIRObserver::ConstructL
       
    42 // Symbian 2nd phase constructor can leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 void CIRObserver::ConstructL()
       
    46 	{
       
    47 	IRLOG_DEBUG( "CIRObserver::ConstructL - Entering" );
       
    48     User::LeaveIfError( iProperty.Attach( iCategory, iKey ) );
       
    49     CActiveScheduler::Add( this );
       
    50     RunL();
       
    51 	IRLOG_DEBUG( "CIRObserver::ConstructL - Exiting." );
       
    52 	}
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CIRObserver::NewL
       
    56 // Two-phased constructor.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CIRObserver* CIRObserver::NewL(MIRChangeObserver& aObserver, const TUid& 
       
    60 	aCategory, const TUint aKey, const RProperty::TType aPropertyType)
       
    61 	{
       
    62 	IRLOG_DEBUG( "CIRObserver::NewL - Entering" );
       
    63     CIRObserver* self = new( ELeave )CIRObserver( aObserver, aCategory, aKey,
       
    64     	aPropertyType );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68 	IRLOG_DEBUG( "CIRObserver::NewL - Exiting." );
       
    69     return self;
       
    70 	}
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CIRObserver::~CIRObserver
       
    74 // C++ default destructor
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CIRObserver::~CIRObserver()
       
    78 	{
       
    79 	IRLOG_DEBUG( "CIRObserver::~CIRObserver - Entering" );
       
    80 	Cancel();
       
    81 	iProperty.Close(); //Closes the publish and subscribe handler
       
    82 	IRLOG_DEBUG( "CIRObserver::~CIRObserver - Exiting." );
       
    83 	}
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CIRObserver::RunL
       
    87 // The function is called by the active scheduler 
       
    88 // when a request completion event occurs
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CIRObserver::RunL()
       
    92 	{
       
    93 	IRLOG_DEBUG( "CIRObserver::RunL - Entering" );
       
    94 	//Subscribe the handler
       
    95     iProperty.Subscribe( iStatus );
       
    96     SetActive();
       
    97     TInt err(KErrNone);
       
    98     switch (iPropertyType)
       
    99         {
       
   100         case RProperty::EInt:
       
   101 	        {
       
   102 	        err = iProperty.Get( iValueInt );
       
   103 	        if (!err)
       
   104             	{
       
   105             	//callback function called when a property value of type int.
       
   106                 iObserver.HandleChangeL( iCategory, iKey, iValueInt );
       
   107              	}
       
   108 	        break;
       
   109 	        }
       
   110 	     case RProperty::EText:
       
   111 	        {
       
   112 	        break;
       
   113 	       	}
       
   114 	    default:
       
   115 	        {
       
   116 	        break;
       
   117 	        }
       
   118         }
       
   119 	  IRLOG_DEBUG( "CIRObserver::RunL - Exiting." );
       
   120       }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CIRObserver::DoCancel
       
   124 // Cancels an outstanding active request
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CIRObserver::DoCancel()
       
   128 	{
       
   129 	IRLOG_DEBUG( "CIRObserver::DoCancel - Entering" );
       
   130     iProperty.Cancel();
       
   131     IRLOG_DEBUG( "CIRObserver::DoCancel - Exiting" );
       
   132 	}
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CIRObserver::GetValue
       
   136 // -----------------------------------------------------------------------------
       
   137 //	
       
   138 void CIRObserver::GetValue(TInt& aValue) const
       
   139 	{
       
   140 	IRLOG_DEBUG( "CIRObserver::GetValue - Entering" );
       
   141 	//aValue assigned with the current Property value
       
   142 	aValue = iValueInt;
       
   143 	IRLOG_DEBUG( "CIRObserver::GetValue - Exiting" );
       
   144 	}
       
   145 
       
   146 // End of File
       
   147