internetradio2.0/uisrc/irpropertyobserver2.cpp
changeset 0 09774dfdd46b
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Source file for CIRPropertyObserver2.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "irpropertyobserver2.h"
       
    20 #include "irdebug.h"
       
    21 
       
    22 // ============================ MEMBER FUNCTIONS ===============================
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // C++ default constructor can NOT contain any code, that might leave.
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 CIRPropertyObserver2::CIRPropertyObserver2(MIRPropertyChangeObserver2& aObserver, 
       
    29 					const TUid& aCategory, const TUint aKey, const TIRPropertyType aPropertyType)
       
    30     : CActive( CActive::EPriorityStandard ),
       
    31     iObserver( aObserver ),
       
    32     iCategory( aCategory ),
       
    33     iKey( aKey ),
       
    34     iPropertyType( aPropertyType )
       
    35 	{
       
    36 	IRLOG_INFO( "CIRPropertyObserver2::CIRPropertyObserver2" );
       
    37 	}
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // Symbian 2nd phase constructor can leave.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 void CIRPropertyObserver2::ConstructL()
       
    44 	{
       
    45 	IRLOG_INFO( "CIRPropertyObserver2::ConstructL - Entering" );
       
    46     switch (iPropertyType)
       
    47         {
       
    48         case EIRPropertyInt:
       
    49 	        {
       
    50 	        break;
       
    51 	        }
       
    52 	    case EIRPropertyByteArray:
       
    53 	        {
       
    54 	        iValueByteArray = HBufC8::NewL( RProperty::KMaxPropertySize );
       
    55 	        break;
       
    56 	        }
       
    57 	    case EIRPropertyText:
       
    58 	        {
       
    59 	        // Max size in bytes, length is size / 2
       
    60 	        iValueText = HBufC::NewL( RProperty::KMaxPropertySize / 2 );
       
    61 	        break;
       
    62 	        }
       
    63 	    default:
       
    64 	        {
       
    65 	        break;
       
    66 	        }
       
    67         }
       
    68 
       
    69     User::LeaveIfError( iProperty.Attach( iCategory, iKey ) );
       
    70     CActiveScheduler::Add( this );
       
    71     IRLOG_INFO( "CIRPropertyObserver2::ConstructL - Exiting" );
       
    72 	}
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // Two-phased constructor.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C CIRPropertyObserver2* CIRPropertyObserver2::NewL(MIRPropertyChangeObserver2& aObserver,
       
    79 		                        const TUid& aCategory, const TUint aKey,
       
    80 		                        	 const TIRPropertyType aPropertyType)
       
    81 	{
       
    82 	IRLOG_INFO( "CIRPropertyObserver2::NewL - Entering" );
       
    83     CIRPropertyObserver2* self = new( ELeave )CIRPropertyObserver2( aObserver, aCategory,
       
    84     				 aKey, aPropertyType );
       
    85     CleanupStack::PushL( self );
       
    86     self->ConstructL();
       
    87     CleanupStack::Pop( self );
       
    88     IRLOG_INFO( "CIRPropertyObserver2::NewL - Exiting" );
       
    89     return self;
       
    90 	}
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // Destructor
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CIRPropertyObserver2::~CIRPropertyObserver2()
       
    97 	{
       
    98 	IRLOG_INFO( "CIRPropertyObserver2::~CIRPropertyObserver2 - Entering" );
       
    99 	Cancel();
       
   100     iProperty.Close();
       
   101     delete iValueByteArray;
       
   102     delete iValueText;
       
   103     IRLOG_INFO( "CIRPropertyObserver2::~CIRPropertyObserver2 - Exiting" );
       
   104 	}
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Subscribes to a property and reads the value, if not already active.
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C void CIRPropertyObserver2::ActivateL()
       
   111 	{
       
   112 	IRLOG_INFO( "CIRPropertyObserver2::ActivateL - Entering" );
       
   113     if ( !IsActive() )
       
   114         {
       
   115         RunL();
       
   116         }
       
   117     IRLOG_INFO( "CIRPropertyObserver2::ActivateL - Exiting" );
       
   118 	}
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CIRPropertyObserver2::RunL
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CIRPropertyObserver2::RunL()
       
   125 	{
       
   126 	IRLOG_INFO( "CIRPropertyObserver2::RunL - Entering" );
       
   127 	
       
   128     iProperty.Subscribe( iStatus );
       
   129     SetActive();
       
   130     
       
   131     TInt err(KErrNone);
       
   132     
       
   133     switch (iPropertyType)
       
   134         {
       
   135         case EIRPropertyInt:
       
   136 	        {
       
   137 	        err = iProperty.Get( iValueInt );
       
   138 	        if (!err)
       
   139             	{
       
   140                 iObserver.HandlePropertyChangeL( iCategory, iKey, iValueInt );
       
   141              	}
       
   142 	        break;
       
   143 	        }
       
   144 	    case EIRPropertyByteArray:
       
   145 	        {
       
   146 	        TPtr8 ptr8( iValueByteArray->Des() );
       
   147 	        err = iProperty.Get( ptr8 );
       
   148 	        if (!err)
       
   149             	{
       
   150                 iObserver.HandlePropertyChangeL( iCategory, iKey, *iValueByteArray );
       
   151              	}
       
   152 	        break;
       
   153 	        }
       
   154 	    case EIRPropertyText:
       
   155 	        {
       
   156 	        TPtr ptr( iValueText->Des() );
       
   157 	        err = iProperty.Get( ptr );
       
   158 	        if (!err)
       
   159             	{
       
   160                 iObserver.HandlePropertyChangeL( iCategory, iKey, *iValueText );
       
   161              	}
       
   162 	        break;
       
   163 	        }
       
   164 	    default:
       
   165 	        {
       
   166 	        break;
       
   167 	        }
       
   168         }
       
   169     
       
   170     if (err)
       
   171     	{
       
   172         iObserver.HandlePropertyChangeErrorL(iCategory, iKey, err);
       
   173      	}
       
   174     IRLOG_INFO( "CIRPropertyObserver2::RunL - Exiting" );
       
   175 	}
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // Cancels an outstanding active request
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CIRPropertyObserver2::DoCancel()
       
   182 	{
       
   183 	IRLOG_INFO( "CIRPropertyObserver2::DoCancel - Entering" );
       
   184     iProperty.Cancel();
       
   185     IRLOG_INFO( "CIRPropertyObserver2::DoCancel - Exiting" );
       
   186 	}
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // Getter for integer value
       
   190 // -----------------------------------------------------------------------------
       
   191 //	
       
   192 EXPORT_C TInt CIRPropertyObserver2::ValueInt() const
       
   193 	{
       
   194 	IRLOG_INFO( "CIRPropertyObserver2::ValueInt" );
       
   195 	return iValueInt;
       
   196 	}
       
   197 	
       
   198 // -----------------------------------------------------------------------------
       
   199 // Getter for byte array value
       
   200 // -----------------------------------------------------------------------------
       
   201 //	
       
   202 EXPORT_C const TDesC8& CIRPropertyObserver2::ValueDes8() const
       
   203 	{
       
   204 	IRLOG_INFO( "CIRPropertyObserver2::ValueDes8" );
       
   205 	return *iValueByteArray;
       
   206 	}
       
   207 	
       
   208 // -----------------------------------------------------------------------------
       
   209 // Getter for text value
       
   210 // -----------------------------------------------------------------------------
       
   211 //	
       
   212 EXPORT_C const TDesC& CIRPropertyObserver2::ValueDes() const
       
   213 	{
       
   214 	IRLOG_INFO( "CIRPropertyObserver2::ValueDes" );
       
   215 	return *iValueText;
       
   216 	}
       
   217