radioengine/utils/src/radioengineutils.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 19 Mar 2010 09:29:04 +0200
changeset 13 46974bebc798
child 14 63aabac4416d
permissions -rw-r--r--
Revision: 201007 Kit: 201011

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/

// System includes
#include <stringloader.h>
#include <utf.h>

// User includes
#include "radioengineutils.h"
#include "cradioenginetls.h"

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
EXPORT_C void RadioEngineUtils::InitializeL( CCoeEnv* aCoeEnv )
    {
    CRadioEngineTls::InitializeL( aCoeEnv );
    CRadioEngineTls::Instance().AddRef();
    }

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
EXPORT_C void RadioEngineUtils::Release()
    {
    CRadioEngineTls::Instance().Release();
    }

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
EXPORT_C MRadioEngineLogger* RadioEngineUtils::Logger()
    {
    return CRadioEngineTls::Instance().Logger();
    }

// ---------------------------------------------------------------------------
// Return the cone environment
// ---------------------------------------------------------------------------
//
EXPORT_C CCoeEnv* RadioEngineUtils::Env()
    {
    return CRadioEngineTls::Instance().Env();
    }

// ---------------------------------------------------------------------------
// Returns the file server session
// ---------------------------------------------------------------------------
//
EXPORT_C RFs& RadioEngineUtils::FsSession()
    {
    return CRadioEngineTls::Instance().FsSession();
    }

// ---------------------------------------------------------------------------
// Utility method for frequency formatting.
// Frequency is assumed to be in kilohertz format.
// ---------------------------------------------------------------------------
//
EXPORT_C HBufC* RadioEngineUtils::ReadFrequencyStringLC( TUint32 aFreq,
                                                         TInt aDecimalCount,
                                                         TInt aResourceId )
    {
    TBuf<KDefaultRealWidth> freqText;
    freqText.AppendNum( static_cast<TReal>( aFreq ) / 1000.0f, TRealFormat( KDefaultRealWidth, aDecimalCount ) ); // Converts kilohertz to megahertz.

    // Converts the numbers to the proper display mode.

    HBufC* channelFreq = NULL;

    if ( aResourceId == KErrNotFound ) // No resource string.
        {
        channelFreq = freqText.AllocLC();
        }
    else
        {
        channelFreq = StringLoader::LoadLC( aResourceId, freqText );
        }

    return channelFreq;
    }

// ---------------------------------------------------------------------------
//
// ---------------------------------------------------------------------------
//
EXPORT_C void RadioEngineUtils::FormatFrequencyString( TDes& aDest,
                                                       TUint32 aFreq,
                                                       TInt aDecimalCount,
                                                       TDesC& aFormat )
    {
    TBuf<KDefaultRealWidth> freqText;
    freqText.AppendNum( static_cast<TReal>( aFreq ) / 1000.0f, TRealFormat( KDefaultRealWidth, aDecimalCount ) ); // Converts kilohertz to megahertz.

    // Converts the numbers to the proper display mode.

    if ( aFormat.Length() <= 0 || freqText.Length() > aDest.MaxLength() ) // No format.
        {
        aDest.Copy( freqText.Left( aDest.Length() ) );
        }
    else
        {
        StringLoader::Format( aDest, aFormat, KErrNotFound, freqText );
        }
    }