os/mm/devsoundextensions/mmfcustominterfaces/SpeechEncoderConfig/SpeechEncoderConfigProxy/src/SpeechEncoderConfigProxy.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsoundextensions/mmfcustominterfaces/SpeechEncoderConfig/SpeechEncoderConfigProxy/src/SpeechEncoderConfigProxy.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,233 @@
     1.4 +/*
     1.5 +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:   Interface proxy for speech encoder configuration.
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +// INCLUDE FILES
    1.24 +#include "SpeechEncoderConfigProxy.h"
    1.25 +#include "SpeechEncoderConfigMsgs.h"
    1.26 +#include <CustomCommandUtility.h>
    1.27 +#include <CustomInterfaceUtility.h>
    1.28 +
    1.29 +// EXTERNAL DATA STRUCTURES
    1.30 +
    1.31 +// EXTERNAL FUNCTION PROTOTYPES  
    1.32 +
    1.33 +// CONSTANTS
    1.34 +
    1.35 +// MACROS
    1.36 +
    1.37 +// LOCAL CONSTANTS AND MACROS
    1.38 +
    1.39 +// MODULE DATA STRUCTURES
    1.40 +
    1.41 +// LOCAL FUNCTION PROTOTYPES
    1.42 +
    1.43 +// FORWARD DECLARATIONS
    1.44 +
    1.45 +// ============================= LOCAL FUNCTIONS ===============================
    1.46 +
    1.47 +// ================= MEMBER FUNCTIONS =======================
    1.48 +
    1.49 +// -----------------------------------------------------------------------------
    1.50 +// CSpeechEncoderConfigProxy::CSpeechEncoderConfigProxy
    1.51 +// C++ default constructor can NOT contain any code, that
    1.52 +// might leave.
    1.53 +// -----------------------------------------------------------------------------
    1.54 +//
    1.55 +CSpeechEncoderConfigProxy::CSpeechEncoderConfigProxy(
    1.56 +                            TMMFMessageDestinationPckg aMessageHandler, 
    1.57 +                            MCustomCommand& aCustomCommand,
    1.58 +                            CCustomInterfaceUtility* aCustomInterfaceUtility) :
    1.59 +	iCustomCommand(aCustomCommand),
    1.60 +	iMessageHandler(aMessageHandler),
    1.61 +	iCustomInterfaceUtility(aCustomInterfaceUtility)
    1.62 +    {
    1.63 +    }
    1.64 +
    1.65 +
    1.66 +// -----------------------------------------------------------------------------
    1.67 +// CSpeechEncoderConfigProxy::ConstructL
    1.68 +// Symbian 2nd phase constructor can leave.
    1.69 +// -----------------------------------------------------------------------------
    1.70 +//
    1.71 +void CSpeechEncoderConfigProxy::ConstructL()
    1.72 +    {
    1.73 +    }
    1.74 +
    1.75 +// -----------------------------------------------------------------------------
    1.76 +// CSpeechEncoderConfigProxy::NewL
    1.77 +// Two-phased constructor.
    1.78 +// -----------------------------------------------------------------------------
    1.79 +//
    1.80 +EXPORT_C CSpeechEncoderConfigProxy* CSpeechEncoderConfigProxy::NewL(
    1.81 +                               TMMFMessageDestinationPckg aMessageHandler, 
    1.82 +                               MCustomCommand& aCustomCommand,
    1.83 +                               CCustomInterfaceUtility* aCustomInterfaceUtility)
    1.84 +    {
    1.85 +    CSpeechEncoderConfigProxy* self = new(ELeave) CSpeechEncoderConfigProxy(
    1.86 +                                                      aMessageHandler,
    1.87 +                                                      aCustomCommand,
    1.88 +                                                      aCustomInterfaceUtility);
    1.89 +    CleanupStack::PushL( self );
    1.90 +    self->ConstructL();
    1.91 +    CleanupStack::Pop( self );
    1.92 +    return self;
    1.93 +    }
    1.94 +    
    1.95 +// Destructor
    1.96 +EXPORT_C CSpeechEncoderConfigProxy::~CSpeechEncoderConfigProxy()
    1.97 +    {
    1.98 +    iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler);
    1.99 +    delete iCustomInterfaceUtility;
   1.100 +    }
   1.101 +
   1.102 +// ---------------------------------------------------------
   1.103 +// CSpeechEncoderConfigProxy::GetSupportedBitrates
   1.104 +// Calls a  subfunction which sends the appropriate custom command for this
   1.105 +// function to its message handler. A subfunction is used
   1.106 +// to contain multiple leaving functions for a single trap.
   1.107 +// (other items were commented in a header).
   1.108 +// ---------------------------------------------------------
   1.109 +//
   1.110 +EXPORT_C TInt CSpeechEncoderConfigProxy::GetSupportedBitrates(
   1.111 +                                           RArray<TUint>& aSupportedBitrates)
   1.112 +    {
   1.113 +    TInt status;
   1.114 +    TRAP(status, GetSupportedBitratesL(aSupportedBitrates));
   1.115 +    return status;
   1.116 +    }
   1.117 +
   1.118 +// ---------------------------------------------------------
   1.119 +// CSpeechEncoderConfigProxy::GetSupportedBitratesL
   1.120 +// Sends the custom command for this function to its message handler.
   1.121 +// This requires two commands. The first is a request for the number of
   1.122 +// supported bitrates. A buffer is allocated locally to hold this number of
   1.123 +// bitrates that will be returned. A pointer to this buffer is sent with the
   1.124 +// next command which is a request for the bitrates. This buffer will be filled
   1.125 +// with the bitrate values. These bitrates are then copied into the array
   1.126 +// provided to this function and the local buffer is deleted.
   1.127 +// (other items were commented in a header).
   1.128 +// ---------------------------------------------------------
   1.129 +//
   1.130 +void CSpeechEncoderConfigProxy::GetSupportedBitratesL(
   1.131 +                                            RArray<TUint>& aSupportedBitrates)
   1.132 +    {
   1.133 +	aSupportedBitrates.Reset();
   1.134 +
   1.135 +	TPckgBuf<TUint> numberOfBitratesPckg;
   1.136 +	User::LeaveIfError(iCustomCommand.CustomCommandSync(
   1.137 +	                                           iMessageHandler, 
   1.138 +                                               ESecmGetNumOfSupportedBitrates, 
   1.139 +                                               KNullDesC8,
   1.140 +                                               KNullDesC8,
   1.141 +                                               numberOfBitratesPckg));
   1.142 +    HBufC8* buf = HBufC8::NewLC(numberOfBitratesPckg()*sizeof(TUint));
   1.143 +    // buf is left on cleanup 
   1.144 +    TPtr8 ptr = buf->Des();
   1.145 +
   1.146 +    User::LeaveIfError(iCustomCommand.CustomCommandSync(
   1.147 +                                               iMessageHandler, 
   1.148 +                                               ESecmGetSupportedBitrates, 
   1.149 +                                               KNullDesC8,
   1.150 +                                               KNullDesC8,
   1.151 +                                               ptr));
   1.152 +   	RDesReadStream stream(ptr);
   1.153 +    CleanupClosePushL(stream); // stream on cleanup
   1.154 +   	for (TInt i=0; i<numberOfBitratesPckg(); i++)
   1.155 +      	{
   1.156 +   		aSupportedBitrates.AppendL(stream.ReadUint32L());
   1.157 +   		}
   1.158 +   	CleanupStack::PopAndDestroy(&stream);
   1.159 +   	CleanupStack::PopAndDestroy(buf);
   1.160 +    }
   1.161 +
   1.162 +// ---------------------------------------------------------
   1.163 +// CSpeechEncoderConfigProxy::SetBitrate
   1.164 +// Sends the custom command for this function to its message handler.
   1.165 +// (other items were commented in a header).
   1.166 +// ---------------------------------------------------------
   1.167 +//
   1.168 +EXPORT_C TInt CSpeechEncoderConfigProxy::SetBitrate(TUint aBitrate)
   1.169 +	{
   1.170 +	TPckgBuf<TInt> bitratePckg(aBitrate);
   1.171 +	TInt status = iCustomCommand.CustomCommandSync(iMessageHandler,
   1.172 +	                                               ESecmSetBitrate,
   1.173 +	                                               bitratePckg,
   1.174 +	                                               KNullDesC8);
   1.175 +	return status;
   1.176 +	}
   1.177 +
   1.178 +// ---------------------------------------------------------
   1.179 +// CSpeechEncoderConfigProxy::GetBitrate
   1.180 +// Sends the custom command for this function to its message handler.
   1.181 +// (other items were commented in a header).
   1.182 +// ---------------------------------------------------------
   1.183 +//
   1.184 +EXPORT_C TInt CSpeechEncoderConfigProxy::GetBitrate(TUint& aBitrate)
   1.185 +	{
   1.186 +	TInt bitrate = 0;
   1.187 +	TPckgBuf<TInt> bitratePckg(bitrate);
   1.188 +	TInt status = iCustomCommand.CustomCommandSync(iMessageHandler,
   1.189 +	                                               ESecmGetBitrate,
   1.190 +	                                               KNullDesC8,
   1.191 +	                                               KNullDesC8,
   1.192 +	                                               bitratePckg);
   1.193 +	if (status == KErrNone)
   1.194 +	    aBitrate = bitratePckg();
   1.195 +	return status;
   1.196 +	}
   1.197 +
   1.198 +// ---------------------------------------------------------
   1.199 +// CSpeechEncoderConfigProxy::SetVadMode
   1.200 +// Sends the custom command for this function to its message handler.
   1.201 +// (other items were commented in a header).
   1.202 +// ---------------------------------------------------------
   1.203 +//
   1.204 +EXPORT_C TInt CSpeechEncoderConfigProxy::SetVadMode(TBool aVadMode)
   1.205 +	{
   1.206 +	TPckgBuf<TBool> pckgBuf(aVadMode);
   1.207 +	TInt status = iCustomCommand.CustomCommandSync(iMessageHandler,
   1.208 +	                                               ESecmSetVadMode,
   1.209 +	                                               pckgBuf,
   1.210 +	                                               KNullDesC8);
   1.211 +	return status;
   1.212 +	}
   1.213 +
   1.214 +// ---------------------------------------------------------
   1.215 +// CSpeechEncoderConfigProxy::GetVadMode
   1.216 +// Sends the custom command for this function to its message handler.
   1.217 +// (other items were commented in a header).
   1.218 +// ---------------------------------------------------------
   1.219 +//
   1.220 +EXPORT_C TInt CSpeechEncoderConfigProxy::GetVadMode(TBool& aVadMode)
   1.221 +	{
   1.222 +	TInt vadMode = EFalse;
   1.223 +	TPckgBuf<TBool> pckgBuf(vadMode);
   1.224 +	TInt status = iCustomCommand.CustomCommandSync(iMessageHandler,
   1.225 +	                                               ESecmGetVadMode,
   1.226 +	                                               KNullDesC8,
   1.227 +	                                               KNullDesC8,
   1.228 +	                                               pckgBuf);
   1.229 +	if (status == KErrNone)
   1.230 +	    aVadMode = pckgBuf();
   1.231 +	return status;
   1.232 +	}
   1.233 +
   1.234 +
   1.235 +
   1.236 +// End of File