resourcemgmt/hwresourcesmgr/server/src/HWRMFmTxRdsTextConverter.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "HWRMFmTxRdsTextConverter.h"
       
    20 #include "HWRMPolicy.h"
       
    21 #include "HWRMtrace.h"
       
    22 
       
    23 // CONSTANTS
       
    24 _LIT( KConvertFromUnicodeFileName, "ConvertFromUnicode.dat" );
       
    25 
       
    26 const TUint8 KUnmappedRdsChar = 0xFF;
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CHWRMFmTxRdsTextConverter::CHWRMFmTxRdsTextConverter
       
    32 // C++ constructor
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CHWRMFmTxRdsTextConverter::CHWRMFmTxRdsTextConverter()
       
    36     {
       
    37     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::CHWRMFmTxRdsTextConverter()" ) );
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CHWRMFmTxRdsTextConverter::ConstructL
       
    42 // Symbian 2nd phase constructor can leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 void CHWRMFmTxRdsTextConverter::ConstructL()
       
    46     {    
       
    47     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConstructL()" ) );
       
    48 
       
    49     // Open conversion table file
       
    50     User::LeaveIfError( iFileServer.Connect() );    
       
    51 
       
    52     TFileName conversionTableFilename;
       
    53     User::LeaveIfError( iFileServer.PrivatePath( conversionTableFilename ) ); // Private-folder of HWRM
       
    54     conversionTableFilename.Insert(0, KDrivename); // "Z:"
       
    55     conversionTableFilename.Append( KConvertFromUnicodeFileName ); // Actual filename
       
    56     
       
    57     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConstructL(), RFile::Open(%S)" ), &conversionTableFilename );
       
    58     User::LeaveIfError( iConvertFromUnicodeFile.Open( iFileServer, conversionTableFilename, EFileRead) );   
       
    59 
       
    60     // Read from conversion table file
       
    61     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConstructL() RFile::Read" ) );
       
    62     User::LeaveIfError( iConvertFromUnicodeFile.Read(iConvertFromUnicodeTable) );
       
    63 
       
    64     if ( iConvertFromUnicodeTable.Length() != KConvertFromTableLength )
       
    65         {
       
    66         COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConstructL - invalid table length %d "), iConvertFromUnicodeTable.Length() );
       
    67         User::Leave( KErrNotReady );
       
    68         }
       
    69 
       
    70     // Default value.  Should be overwritten with CenRep setting
       
    71     SetUnsupportedCharReplacement( 0x3F /* Question Mark ? symbol */ );
       
    72 
       
    73     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConstructL - return " ) );
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CHWRMFmTxRdsTextConverter::NewL
       
    78 // Two-phased constructor.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CHWRMFmTxRdsTextConverter* CHWRMFmTxRdsTextConverter::NewL()
       
    82     {
       
    83     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::NewL()" ) );
       
    84 
       
    85     CHWRMFmTxRdsTextConverter* self = new( ELeave ) CHWRMFmTxRdsTextConverter();
       
    86     
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop( self );
       
    90 
       
    91     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::NewL - return 0x%x" ), self );
       
    92     
       
    93     return self;
       
    94     }
       
    95    
       
    96 // ---------------------------------------------------------
       
    97 // Destructor
       
    98 // ---------------------------------------------------------
       
    99 //
       
   100 CHWRMFmTxRdsTextConverter::~CHWRMFmTxRdsTextConverter()
       
   101     {
       
   102     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::~CHWRMFmTxRdsTextConverter()" ) );
       
   103 
       
   104     iFileServer.Close();
       
   105 
       
   106     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::~CHWRMFmTxRdsTextConverter - return" ) );
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CHWRMFmTxRdsTextConverter::ConvertFromUnicodeL
       
   111 // Converts a unicode descriptor into 8bit RDS format
       
   112 // All input characters must be within U+0000 -> U+024F range
       
   113 // ---------------------------------------------------------
       
   114 //
       
   115 void CHWRMFmTxRdsTextConverter::ConvertFromUnicodeL(const TDesC& aInput, TDes8& aOutput)
       
   116     {
       
   117     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConvertFromUnicodeL(%S)" ), &aInput );
       
   118     
       
   119     // empty output buffer
       
   120     aOutput.Zero();
       
   121 
       
   122     TInt inputLength = aInput.Length();
       
   123     // convert each character from input buffer
       
   124     for (TInt inputIndex=0; inputIndex < inputLength; inputIndex++)
       
   125         {
       
   126         // get input buffer values to index conversion table
       
   127         TUint tableIndex = aInput[inputIndex];
       
   128         COMPONENT_TRACE3( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConvertFromUnicodeL aInput[%d] = 0x%x" ), inputIndex, tableIndex );
       
   129         if ( tableIndex >= KConvertFromTableLength )
       
   130             {
       
   131             COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConvertFromUnicodeL() aInput outside valid range" ) );
       
   132             aOutput.Zero();
       
   133             User::Leave(KErrArgument);
       
   134             }
       
   135 
       
   136         // convert into 8bit RDS value
       
   137         TUint8 value = iConvertFromUnicodeTable[ tableIndex ];      
       
   138         if ( SupportedCharacter(value) == EFalse )
       
   139             {
       
   140             COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConvertFromUnicodeL() using replacement char" ) );
       
   141             value = iUnsupportedCharReplacement;
       
   142             }
       
   143 
       
   144         COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConvertFromUnicodeL() appending 0x%x" ), value );
       
   145         aOutput.Append( (TChar)value );
       
   146         }
       
   147 
       
   148     COMPONENT_TRACE1( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::ConvertFromUnicodeL - return" ) );
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------
       
   152 // CHWRMFmTxRdsTextConverter::SetUnsupportedCharReplacement
       
   153 // Sets the character used, to replace unsupported characters
       
   154 // ---------------------------------------------------------
       
   155 //
       
   156 void CHWRMFmTxRdsTextConverter::SetUnsupportedCharReplacement(const TText8 aChar)
       
   157     {
       
   158     COMPONENT_TRACE2( _L( "HWRM Server - CHWRMFmTxRdsTextConverter::SetUnsupportedCharReplacement(0x%x)" ), aChar );
       
   159 
       
   160     iUnsupportedCharReplacement = aChar;
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------
       
   164 // CHWRMFmTxRdsTextConverter::SupportedCharacter
       
   165 // Returns whether a character returned by the conversion 
       
   166 // table is actually supported
       
   167 // ---------------------------------------------------------
       
   168 //  
       
   169 TBool CHWRMFmTxRdsTextConverter::SupportedCharacter( TUint8 aChar )
       
   170     {
       
   171     return (aChar < KUnmappedRdsChar);
       
   172     }
       
   173 
       
   174 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   175 
       
   176 //  End of File