mmserv/radioutility/presetutility/src/preset.cpp
changeset 14 80975da52420
equal deleted inserted replaced
12:5a06f39ad45b 14:80975da52420
       
     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 
       
    19 
       
    20 //  INCLUDES
       
    21 #include <s32mem.h> // RWriteStream, RReadStream
       
    22 
       
    23 #include <preset.h>
       
    24 #include "trace.h"
       
    25 
       
    26 /**
       
    27  * On/Off type flags
       
    28  *
       
    29  * Bit shifting in the value initialization is used to easily create
       
    30  * progressing bit patterns like so:
       
    31  *  1 << 0 equals 0001 equals 0x1
       
    32  *  1 << 1 equals 0010 equals 0x2
       
    33  *  1 << 2 equals 0100 equals 0x4
       
    34  *  1 << 3 equals 1000 equals 0x8
       
    35  */
       
    36 enum TFlagValues
       
    37     {
       
    38      EFavorite       = 1 << 0
       
    39     ,ELocalStation   = 1 << 1
       
    40     ,ERenamedByUser  = 1 << 2
       
    41     };
       
    42 
       
    43 // ============== LOCAL FUNCTIONS ===============
       
    44 
       
    45 /**
       
    46  * Normalize return value from TBitFlags to ETrue or EFalse values
       
    47  * Two negations: 16 => 0 => 1
       
    48  */
       
    49 static TBool NormalizeBool( TBool aBool )
       
    50     {
       
    51     return !( !aBool );
       
    52     }
       
    53 
       
    54 const TUint8 KNbrOfMyExternalizedUint32Items = 3;
       
    55 
       
    56 // ============= MEMBER FUNCTIONS ==============
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 EXPORT_C TPreset::TPreset()
       
    63     : iPresetFrequency( 0 )
       
    64     {
       
    65     FUNC_LOG;
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // Returns the channel frequency
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 EXPORT_C TUint TPreset::Frequency() const
       
    73     {
       
    74     FUNC_LOG;
       
    75     return iPresetFrequency;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // Returns the channel name
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 EXPORT_C TPtrC TPreset::Name() const
       
    83     {
       
    84     FUNC_LOG;
       
    85     return TPtrC( iPresetName );
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 EXPORT_C TPtrC TPreset::Url() const
       
    93     {
       
    94     FUNC_LOG;
       
    95     return TPtrC( iUrl );
       
    96     }
       
    97 
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Sets the channel name
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 EXPORT_C void TPreset::SetName( const TPresetName& aStationName )
       
   104     {
       
   105     FUNC_LOG;
       
   106     iPresetName = aStationName;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Sets the channel frequency
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 EXPORT_C void TPreset::SetFrequency( const TUint aFrequency )
       
   114     {
       
   115     FUNC_LOG;
       
   116     iPresetFrequency = aFrequency;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C void TPreset::SetUrl( const TRadioUrl& aUrl )
       
   124     {
       
   125     FUNC_LOG;
       
   126     iUrl = aUrl;
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C void TPreset::SetFavorite( TBool aFavorite )
       
   134     {
       
   135     FUNC_LOG;
       
   136     iFlags.Assign( EFavorite, aFavorite );
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 EXPORT_C TBool TPreset::Favorite() const
       
   144     {
       
   145     FUNC_LOG;
       
   146     // Normalize return value from TBitFlags to 1 or 0 just in case
       
   147     // Two negations: 16 => 0 => 1
       
   148     return NormalizeBool( iFlags.IsSet( EFavorite ) );
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C void TPreset::SetLocalStation( TBool aLocalStation )
       
   156     {
       
   157     FUNC_LOG;
       
   158     iFlags.Assign( ELocalStation, aLocalStation );
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C TBool TPreset::LocalStation() const
       
   166     {
       
   167     FUNC_LOG;
       
   168     // Normalize return value from TBitFlags to 1 or 0 just in case
       
   169     // Two negations: 16 => 0 => 1
       
   170     return NormalizeBool( iFlags.IsSet( ELocalStation ) );
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 EXPORT_C void TPreset::SetRenamedByUser( TBool aRenamed )
       
   178     {
       
   179     FUNC_LOG;
       
   180     iFlags.Assign( ERenamedByUser, aRenamed );
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 EXPORT_C TBool TPreset::RenamedByUser() const
       
   188     {
       
   189     FUNC_LOG;
       
   190     // Normalize return value from TBitFlags to 1 or 0 just in case
       
   191     // Two negations: 16 => 0 => 1
       
   192     return NormalizeBool( iFlags.IsSet( ERenamedByUser ) );
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 EXPORT_C void TPreset::SetGenre( TInt aGenre )
       
   200     {
       
   201     FUNC_LOG;
       
   202     iGenre = aGenre;
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 EXPORT_C TInt TPreset::Genre() const
       
   210     {
       
   211     FUNC_LOG;
       
   212     return iGenre;
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 EXPORT_C void TPreset::SetPiCode( TInt aPiCode )
       
   220     {
       
   221     FUNC_LOG;
       
   222     iPiCode = aPiCode;
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 EXPORT_C TInt TPreset::PiCode() const
       
   230     {
       
   231     FUNC_LOG;
       
   232     return iPiCode;
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 EXPORT_C TUint TPreset::MyExternalizedDataSize() const
       
   240     {
       
   241     FUNC_LOG;
       
   242     return ( KNbrOfMyExternalizedUint32Items * sizeof(TUint32) );
       
   243     }
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 EXPORT_C void TPreset::ExternalizeL( RWriteStream& aStream ) const
       
   249     {
       
   250     FUNC_LOG;
       
   251     aStream.WriteUint32L( iGenre );
       
   252     aStream.WriteUint32L( iPiCode );
       
   253     aStream.WriteUint32L( iFlags.Value() );
       
   254 
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 EXPORT_C void TPreset::InternalizeL( RReadStream& aStream )
       
   262     {
       
   263     FUNC_LOG;
       
   264     iGenre = aStream.ReadUint32L();
       
   265     iPiCode = aStream.ReadUint32L();
       
   266     iFlags = TBitFlags( aStream.ReadUint32L() );
       
   267 
       
   268     }