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