radioengine/settings/src/cradiosettingsbase.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 26 6bcf277166c1
parent 33 11b6825f0862
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
     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 // System includes
       
    19 #include <s32mem.h>
       
    20 
       
    21 // User includes
       
    22 #include "cradiorepositorymanager.h"
       
    23 #include "cradiosettingsbase.h"
       
    24 #include "cradioenginelogger.h"
       
    25 
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CRadioSettingsBase::CRadioSettingsBase( CRadioRepositoryManager& aRepositoryManager,
       
    34                                         CCoeEnv& aCoeEnv )
       
    35     : iCoeEnv( aCoeEnv )
       
    36     , iRepositoryManager( aRepositoryManager )
       
    37     {
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CRadioSettingsBase::~CRadioSettingsBase()
       
    45     {
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // Writes a desciptor array to the repository.
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 void CRadioSettingsBase::WriteArrayEntityL( const TUid& aUid, TUint32 aKey, const CDesCArray& aArray )
       
    53     {
       
    54     LOG_FORMAT( "CRadioSettingsBase::WriteArrayEntityL( aUid = %d, aKey = %d )", aUid.iUid, aKey );
       
    55 
       
    56     CBufFlat* buf = CBufFlat::NewL( KRadioEntityBuf8Length );
       
    57     CleanupStack::PushL( buf );
       
    58     RBufWriteStream stream( *buf );
       
    59     CleanupClosePushL( stream );
       
    60 
       
    61     TInt count = aArray.MdcaCount();
       
    62     stream << TCardinality( count );
       
    63 
       
    64     LOG_FORMAT( "     count = %d", count );
       
    65 
       
    66     for ( TInt i = 0; i < count; i++ )
       
    67         {
       
    68         DEBUGVAR( TPtrC ptr( aArray.MdcaPoint( i ) ) );
       
    69         LOG_FORMAT( "     entry %d: %S", i, &ptr );
       
    70         stream << aArray.MdcaPoint( i );
       
    71         }
       
    72 
       
    73     stream.CommitL();
       
    74 
       
    75     CleanupStack::PopAndDestroy( &stream );
       
    76 
       
    77     TRadioEntityBuf8 entityBuf( buf->Ptr( 0 ).Left( KRadioEntityBuf8Length ) );
       
    78     User::LeaveIfError( iRepositoryManager.SetEntityValue( aUid, aKey, entityBuf ) );
       
    79 
       
    80     CleanupStack::PopAndDestroy( buf );
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // Reads a descriptor array from the repository.
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CDesCArray* CRadioSettingsBase::ReadArrayEntityL( const TUid& aUid, TUint32 aKey ) const
       
    88     {
       
    89     LOG_FORMAT( "CRadioSettingsBase::ReadArrayEntityL( aUid = %d, aKey = %d )", aUid.iUid, aKey );
       
    90 
       
    91     CBufFlat* buf = CBufFlat::NewL( KRadioEntityBuf8Length );
       
    92     CleanupStack::PushL( buf );
       
    93     buf->InsertL( 0, iRepositoryManager.EntityValueDes8( aUid, aKey ) );
       
    94     RBufReadStream stream( *buf );
       
    95     CleanupClosePushL( stream );
       
    96 
       
    97     TCardinality count;
       
    98     stream >> count;
       
    99 
       
   100     LOG_FORMAT( "     count = %d", static_cast<TInt>( count ) );
       
   101 
       
   102     CDesCArray* array = new ( ELeave ) CDesCArrayFlat( Max( static_cast<TInt>( count ), 1 ) );
       
   103     CleanupStack::PushL( array );
       
   104 
       
   105     for ( TInt i = 0; i < count; i++ )
       
   106         {
       
   107         HBufC* curBuf = HBufC::NewLC( stream, KMaxTInt );
       
   108         DEBUGVAR( TPtrC ptr( *curBuf ) );
       
   109         LOG_FORMAT( "     entry %d: %S", i, &ptr );
       
   110         array->AppendL( *curBuf );
       
   111         CleanupStack::PopAndDestroy( curBuf );
       
   112         }
       
   113 
       
   114     CleanupStack::Pop( array );
       
   115     CleanupStack::PopAndDestroy( 2, buf );
       
   116 
       
   117     return array;
       
   118     }