mmsharing/mmshshared/src/muspropertywatch.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     1 /*
       
     2 * Copyright (c) 2005 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "muspropertywatch.h"
       
    21 #include "muspropertyobserver.h"
       
    22 #include "mussessionproperties.h"
       
    23 #include "musresourceproperties.h"
       
    24 #include "muslogger.h" // debug logging
       
    25 
       
    26 using namespace NMusSessionApi;
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // Symbian two-phase constructor.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CMusPropertyWatch* CMusPropertyWatch::NewL(
       
    33                                       MMusPropertyObserver& aObserver,
       
    34                                       TUid aCategory,
       
    35                                       const TInt aPropertyName )
       
    36     {
       
    37     CMusPropertyWatch* self = new (ELeave) CMusPropertyWatch(
       
    38                                             aObserver,
       
    39                                             aCategory,
       
    40                                             aPropertyName );
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // C++ destructor.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CMusPropertyWatch::~CMusPropertyWatch()
       
    53     {
       
    54     MUS_LOG( "mus: [MUSSH ]  -> CMusPropertyWatch::~CMusPropertyWatch" );
       
    55     if ( IsActive() )
       
    56         {
       
    57         Cancel();
       
    58         }
       
    59     iProperty.Close();
       
    60     MUS_LOG( "mus: [MUSSH ]  <- CMusPropertyWatch::~CMusPropertyWatch" );
       
    61     }
       
    62 
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // C++ constructor.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CMusPropertyWatch::CMusPropertyWatch( MMusPropertyObserver& aObserver,
       
    69                                           TUid aCategory,
       
    70                                           const TInt aPropertyName ) :
       
    71     CActive( EPriorityNormal ),
       
    72     iObserver( aObserver )
       
    73     {
       
    74     iPropertyCategory = aCategory;
       
    75     iPropertyKey = aPropertyName;
       
    76     }
       
    77 
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // Symbian second-phase constructor.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CMusPropertyWatch::ConstructL( )
       
    84     {
       
    85     MUS_LOG( "mus: [MUSSH ]  -> CMusPropertyWatch::ConstructL" );
       
    86     User::LeaveIfError( iProperty.Attach( iPropertyCategory,
       
    87                                           iPropertyKey) );
       
    88     CActiveScheduler::Add( this );
       
    89     
       
    90     iProperty.Subscribe( iStatus );
       
    91     SetActive();
       
    92     
       
    93     MUS_LOG( "mus: [MUSSH ]  <- CMusPropertyWatch::ConstructL" );
       
    94     }
       
    95 
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 TInt CMusPropertyWatch::ReadIntPropertyL( TUint aKey )
       
   102     {
       
   103     MUS_LOG1( "mus: [MUSSH ]     -> CMusPropertyWatch::ReadIntPropertyL: aKey: [%d]",
       
   104                             aKey );
       
   105     TInt val;
       
   106     User::LeaveIfError( RProperty::Get( KCategoryUid,
       
   107                                         aKey,
       
   108                                         val ) );
       
   109     MUS_LOG1( "mus: [MUSSH ]     <- CMusPropertyWatch::ReadIntPropertyL: val: [%d]",
       
   110                             val );
       
   111     return val;
       
   112     }
       
   113 
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 HBufC* CMusPropertyWatch::ReadDescPropertyL( TUint aKey )
       
   120     {
       
   121     MUS_LOG1( "mus: [MUSSH ]     -> CMusPropertyWatch::ReadDescPropertyL: aKey: [%d]",
       
   122                             aKey );
       
   123     TBuf<RProperty::KMaxPropertySize> buffer;
       
   124 
       
   125     User::LeaveIfError( RProperty::Get( KCategoryUid,
       
   126                                         aKey,
       
   127                                         buffer ) );
       
   128     HBufC* desc = buffer.AllocL();
       
   129     MUS_LOG_TDESC( "mus: [MUSSH ]    <- CMusPropertyWatch::ReadDescPropertyL: val: ",
       
   130                             (*desc) );
       
   131     return desc;
       
   132     }
       
   133 
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CMusPropertyWatch::DoCancel()
       
   140     {
       
   141     MUS_LOG( "mus: [MUSSH ]  -> CMusPropertyWatch::DoCancel" );
       
   142     iProperty.Cancel();
       
   143     MUS_LOG( "mus: [MUSSH ]  <- CMusPropertyWatch::DoCancel" );
       
   144     }
       
   145 
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CMusPropertyWatch::RunL()
       
   152     {
       
   153     MUS_LOG( "mus: [MUSSH ]  -> CMusPropertyWatch::RunL" );
       
   154     TInt val;
       
   155 
       
   156     User::LeaveIfError( RProperty::Get( iPropertyCategory,
       
   157                                         iPropertyKey,
       
   158                                         val ) );
       
   159 
       
   160     iObserver.PropertyChanged( iPropertyKey, val );
       
   161     MUS_LOG( "mus: [MUSSH ]  <- CMusPropertyWatch::RunL" );
       
   162     }
       
   163 
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 TInt CMusPropertyWatch::RunError( TInt aError )
       
   170     {
       
   171     MUS_LOG1( "mus: [MUSSH ]     -> CMusPropertyWatch::RunError [%d]", aError );
       
   172     iObserver.HandlePropertyError( aError );
       
   173     MUS_LOG( "mus: [MUSSH ]  <- CMusPropertyWatch::RunError" );
       
   174     return KErrNone;
       
   175     }
       
   176 
       
   177 
       
   178 // end of file