internetradio2.0/activeidleengsrc/iractiveidleengpubsub.cpp
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 15 065198191975
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
     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 "iractiveidleengpubsub.h"
       
    20 #include "iractiveidleengpubsubnotifyhandler.h"
       
    21 #include "irdebug.h"
       
    22 
       
    23 // ==================== MEMBER FUNCTIONS ===================
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CIRActiveIdleEngPubSub::CIRActiveIdleEngPubSub
       
    27 // Constructor.
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CIRActiveIdleEngPubSub::CIRActiveIdleEngPubSub(
       
    31 	MIRActiveIdleEngPubSubNotifyHandler& aObserver, const TUid& aCategory, 
       
    32 	TUint aKey , const RProperty::TType aPropertyType): CActive( CActive::
       
    33 	EPriorityStandard ),  iPropertyType(aPropertyType),iObserver( aObserver ), 
       
    34 	iCategory( aCategory ), iKey( aKey )
       
    35     {
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CIRActiveIdleEngPubSub::ConstructL
       
    40 // Second-phase constructor
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 void CIRActiveIdleEngPubSub::ConstructL()
       
    44     {
       
    45     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::ConstructL" );	
       
    46     User::LeaveIfError( iProperty.Attach( iCategory, iKey ) );
       
    47     CActiveScheduler::Add( this );
       
    48     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::ConstructL - Exiting." );	
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CIRActiveIdleEngPubSub::SecondConstructL()
       
    53 // Finalizes the construction of this object.
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CIRActiveIdleEngPubSub::SecondConstructL()
       
    57 	{
       
    58 	IRLOG_DEBUG( "CIRActiveIdleEngPubSub::SecondConstructL" );	
       
    59 	if(!IsActive())	
       
    60 		{
       
    61 	    iProperty.Subscribe( iStatus );
       
    62 	    SetActive();	
       
    63 		}
       
    64 
       
    65     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::SecondConstructL - Exiting." );	
       
    66 	}
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CIRActiveIdleEngPubSub::NewL
       
    70 // Static constructor.
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CIRActiveIdleEngPubSub* CIRActiveIdleEngPubSub::NewL( 
       
    74 	MIRActiveIdleEngPubSubNotifyHandler& aObserver, const TUid& aCategory, 
       
    75 	TUint aKey, const RProperty::TType aPropertyType  )
       
    76     {
       
    77     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::NewL" );	
       
    78     CIRActiveIdleEngPubSub* self = new ( ELeave ) CIRActiveIdleEngPubSub( 
       
    79     							aObserver, aCategory, aKey, aPropertyType );
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL();
       
    82     CleanupStack::Pop( self );
       
    83     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::NewL - Exiting." );	
       
    84     return self;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CIRActiveIdleEngPubSub::~CIRActiveIdleEngPubSub()
       
    89 // Destructor
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 CIRActiveIdleEngPubSub::~CIRActiveIdleEngPubSub()
       
    93     {
       
    94     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::~CIRActiveIdleEngPubSub" );	
       
    95     Cancel();
       
    96     iProperty.Close();
       
    97     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::~CIRActiveIdleEngPubSub - Exiting." );	
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CIRActiveIdleEngPubSub::DoCancel()
       
   102 // Invoked when the active object is cancelled.
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CIRActiveIdleEngPubSub::DoCancel()
       
   106     {
       
   107     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::DoCancel" );	
       
   108     iProperty.Cancel();
       
   109     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::DoCancel - Exiting." );	
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // CIRActiveIdleEngPubSub::RunL()
       
   114 // The function is called by the active scheduler when a request completion event occurs,
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CIRActiveIdleEngPubSub::RunL()
       
   118     {
       
   119     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::RunL" );	
       
   120 
       
   121     iProperty.Subscribe( iStatus );
       
   122     SetActive();
       
   123     TInt err(KErrNone);
       
   124     switch (iPropertyType)
       
   125         {
       
   126         // Subscribes the property of interger type 
       
   127         case RProperty::EInt:
       
   128 	        {
       
   129 	        err = iProperty.Get( iValue );
       
   130 	        if (!err)
       
   131             	{
       
   132                 iObserver.HandlePropertyChangeL( iCategory, iKey, iValue );
       
   133              	}
       
   134 	        break;
       
   135 	        }
       
   136 	    // Subscribes the property of text type 
       
   137 	    case RProperty::ELargeText:
       
   138 	        {
       
   139 	        err = iProperty.Get( iText );
       
   140 	        if (!err)
       
   141             	{
       
   142                 iObserver.HandlePropertyChangeL( iCategory, iKey, iText );
       
   143              	}
       
   144 	        break;
       
   145 	        }
       
   146 	    default:
       
   147 	        {
       
   148 	        break;
       
   149 	        }
       
   150         }
       
   151     
       
   152     if (err)
       
   153     	{
       
   154         iObserver.HandlePropertyChangeErrorL(iCategory, iKey, err);
       
   155     	}
       
   156 	
       
   157     IRLOG_DEBUG( "CIRActiveIdleEngPubSub::RunL - Exiting." );	
       
   158     }