os/mm/devsoundextensions/mmfcustominterfaces/SpeechEncoderConfig/SpeechEncoderConfigMsgHdlr/src/SpeechEncoderConfigMsgHdlr.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsoundextensions/mmfcustominterfaces/SpeechEncoderConfig/SpeechEncoderConfigMsgHdlr/src/SpeechEncoderConfigMsgHdlr.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,299 @@
     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:   Message handler for speech encoder configuration interface
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +// INCLUDE FILES
    1.24 +#include    "SpeechEncoderConfigMsgHdlr.h"
    1.25 +#include    "SpeechEncoderConfigMsgs.h"
    1.26 +#include    <SpeechEncoderConfig.h>
    1.27 +
    1.28 +// EXTERNAL DATA STRUCTURES
    1.29 +
    1.30 +// EXTERNAL FUNCTION PROTOTYPES  
    1.31 +
    1.32 +// CONSTANTS
    1.33 +
    1.34 +// MACROS
    1.35 +
    1.36 +// LOCAL CONSTANTS AND MACROS
    1.37 +
    1.38 +// MODULE DATA STRUCTURES
    1.39 +
    1.40 +// LOCAL FUNCTION PROTOTYPES
    1.41 +
    1.42 +// FORWARD DECLARATIONS
    1.43 +
    1.44 +// ============================= LOCAL FUNCTIONS ===============================
    1.45 +
    1.46 +// ============================ MEMBER FUNCTIONS ===============================
    1.47 +
    1.48 +// -----------------------------------------------------------------------------
    1.49 +// CSpeechEncoderConfigMsgHdlr::CSpeechEncoderConfigMsgHdlr
    1.50 +// C++ default constructor can NOT contain any code, that
    1.51 +// might leave.
    1.52 +// -----------------------------------------------------------------------------
    1.53 +//
    1.54 +CSpeechEncoderConfigMsgHdlr::CSpeechEncoderConfigMsgHdlr(
    1.55 +                                 CSpeechEncoderConfig* aSpeechEncoderConfigCI) :
    1.56 +	CMMFObject(KUidSpeechEncoderConfig)
    1.57 +    {
    1.58 +    iSpeechEncoderConfigCI = aSpeechEncoderConfigCI;
    1.59 +    }
    1.60 +
    1.61 +// -----------------------------------------------------------------------------
    1.62 +// CSpeechEncoderConfigMsgHdlr::ConstructL
    1.63 +// Symbian 2nd phase constructor can leave.
    1.64 +// -----------------------------------------------------------------------------
    1.65 +//
    1.66 +void CSpeechEncoderConfigMsgHdlr::ConstructL()
    1.67 +    {
    1.68 +    }
    1.69 +
    1.70 +// -----------------------------------------------------------------------------
    1.71 +// CSpeechEncoderConfigMsgHdlr::NewL
    1.72 +// Two-phased constructor.
    1.73 +// -----------------------------------------------------------------------------
    1.74 +//
    1.75 +EXPORT_C CSpeechEncoderConfigMsgHdlr* CSpeechEncoderConfigMsgHdlr::NewL(
    1.76 +                                                  TAny*  aSpeechEncoderConfigCI)
    1.77 +    {
    1.78 +    CSpeechEncoderConfig* speechEncoderConfigCI = 
    1.79 +                                  (CSpeechEncoderConfig*)aSpeechEncoderConfigCI;
    1.80 +    CSpeechEncoderConfigMsgHdlr* self = 
    1.81 +                new (ELeave) CSpeechEncoderConfigMsgHdlr(speechEncoderConfigCI);
    1.82 +    CleanupStack::PushL( self );
    1.83 +    self->ConstructL();
    1.84 +    CleanupStack::Pop( self );
    1.85 +    return self;
    1.86 +    }
    1.87 +
    1.88 +// Destructor
    1.89 +EXPORT_C CSpeechEncoderConfigMsgHdlr::~CSpeechEncoderConfigMsgHdlr()
    1.90 +	{
    1.91 +	iSupportedBitrates.Close();
    1.92 +	delete iDataCopyBuffer;
    1.93 +	delete iSpeechEncoderConfigCI;
    1.94 +	}
    1.95 +
    1.96 +// ---------------------------------------------------------
    1.97 +// CSpeechEncoderConfigMsgHdlr::HandleRequest
    1.98 +// Handles the messages from the proxy.
    1.99 +// Calls a subfunction which determines which custom interface to call.
   1.100 +// A subfunction is used to contain multiple leaving functions for a single
   1.101 +// trap.
   1.102 +// (other items were commented in a header).
   1.103 +// ---------------------------------------------------------
   1.104 +//
   1.105 +EXPORT_C void CSpeechEncoderConfigMsgHdlr::HandleRequest(TMMFMessage& aMessage)
   1.106 +	{
   1.107 +    // debug panic
   1.108 +	ASSERT(aMessage.Destination().InterfaceId() == KUidSpeechEncoderConfig);
   1.109 +	TRAPD(error,DoHandleRequestL(aMessage));
   1.110 +	if(error)
   1.111 +		{
   1.112 +		aMessage.Complete(error);
   1.113 +		}
   1.114 +	}
   1.115 +
   1.116 +// ---------------------------------------------------------
   1.117 +// CSpeechEncoderConfigMsgHdlr::DoHandleRequestL
   1.118 +// Determines which custom interface to call.
   1.119 +// (other items were commented in a header).
   1.120 +// ---------------------------------------------------------
   1.121 +//
   1.122 +void CSpeechEncoderConfigMsgHdlr::DoHandleRequestL(TMMFMessage& aMessage)
   1.123 +	{
   1.124 +	switch(aMessage.Function())
   1.125 +		{
   1.126 +		case ESecmGetNumOfSupportedBitrates:
   1.127 +			{
   1.128 +			DoGetNumOfSupportedBitratesL(aMessage);
   1.129 +			break;
   1.130 +			}
   1.131 +		case ESecmGetSupportedBitrates:
   1.132 +			{
   1.133 +			DoGetSupportedBitratesL(aMessage);
   1.134 +			break;
   1.135 +			}
   1.136 +		case ESecmSetBitrate:
   1.137 +			{
   1.138 +			DoSetBitrateL(aMessage);
   1.139 +			break;
   1.140 +			}
   1.141 +		case ESecmGetBitrate:
   1.142 +			{
   1.143 +			DoGetBitrateL(aMessage);
   1.144 +			break;
   1.145 +			}
   1.146 +		case ESecmSetVadMode:
   1.147 +			{
   1.148 +			DoSetVadModeL(aMessage);
   1.149 +			break;
   1.150 +			}
   1.151 +		case ESecmGetVadMode:
   1.152 +			{
   1.153 +			DoGetVadModeL(aMessage);
   1.154 +			break;
   1.155 +			}
   1.156 +		default:
   1.157 +			{
   1.158 +			aMessage.Complete(KErrNotSupported);
   1.159 +			}
   1.160 +		}
   1.161 +	}
   1.162 +
   1.163 +// ---------------------------------------------------------
   1.164 +// CSpeechEncoderConfigMsgHdlr::DoGetNumOfSupportedBitratesL
   1.165 +// Handles the message from the proxy and calls the custom interface.
   1.166 +// The custom interface returns the data requested and this function
   1.167 +// writes it back to the proxy. It also creates a buffer and fills
   1.168 +// it with the bitrate data to be returned in the subsequent call
   1.169 +// of DoGetSupportedBitratesL().
   1.170 +// (other items were commented in a header).
   1.171 +// ---------------------------------------------------------
   1.172 +//
   1.173 +void CSpeechEncoderConfigMsgHdlr::DoGetNumOfSupportedBitratesL(
   1.174 +                                                       TMMFMessage& aMessage)
   1.175 +	{
   1.176 +	iSupportedBitrates.Reset();
   1.177 +	TInt status = iSpeechEncoderConfigCI->GetSupportedBitrates(
   1.178 +	                                                     iSupportedBitrates);
   1.179 +	CreateBufFromUintArrayL(iSupportedBitrates);
   1.180 +	if (status == KErrNone)
   1.181 +    	{
   1.182 +	    TPckgBuf<TUint> pckg;
   1.183 +    	pckg() = iSupportedBitrates.Count();
   1.184 +	    aMessage.WriteDataToClientL(pckg);
   1.185 +	    }
   1.186 +    aMessage.Complete(status);
   1.187 +	}
   1.188 +
   1.189 +// ---------------------------------------------------------
   1.190 +// CSpeechEncoderConfigMsgHdlr::CreateBufFromUintArrayL
   1.191 +// Utility function used to create a buffer a fill it with data from the array
   1.192 +// passed in.
   1.193 +// (other items were commented in a header).
   1.194 +// ---------------------------------------------------------
   1.195 +//
   1.196 +void CSpeechEncoderConfigMsgHdlr::CreateBufFromUintArrayL(RArray<TUint>& aArray)
   1.197 +	{
   1.198 +	delete iDataCopyBuffer;
   1.199 +	iDataCopyBuffer = NULL;
   1.200 +
   1.201 +	iDataCopyBuffer = CBufFlat::NewL(8);
   1.202 +	RBufWriteStream stream;
   1.203 +	stream.Open(*iDataCopyBuffer);
   1.204 +	CleanupClosePushL(stream);
   1.205 +	for (TInt i=0;i<aArray.Count();i++)
   1.206 +		stream.WriteUint32L(aArray[i]);
   1.207 +	CleanupStack::PopAndDestroy(&stream);//stream
   1.208 +	}
   1.209 +	
   1.210 +// ---------------------------------------------------------
   1.211 +// CSpeechEncoderConfigMsgHdlr::DoGetSupportedBitratesL
   1.212 +// Handles the message from the proxy and calls the custom interface.
   1.213 +// The custom interface returns the data requested and this function
   1.214 +// writes it back to the proxy.
   1.215 +// (other items were commented in a header).
   1.216 +// ---------------------------------------------------------
   1.217 +//
   1.218 +void CSpeechEncoderConfigMsgHdlr::DoGetSupportedBitratesL(TMMFMessage& aMessage)
   1.219 +	{
   1.220 +	if (!iDataCopyBuffer)
   1.221 +		User::Leave(KErrNotReady);
   1.222 +	aMessage.WriteDataToClientL(iDataCopyBuffer->Ptr(0));
   1.223 +    aMessage.Complete(KErrNone);
   1.224 +	}
   1.225 +	
   1.226 +// ---------------------------------------------------------
   1.227 +// CSpeechEncoderConfigMsgHdlr::DoSetBitrateL
   1.228 +// Handles the message from the proxy and calls the custom interface method.
   1.229 +// The data passed from the proxy is read from the message and passed to
   1.230 +// the custom interface.
   1.231 +// (other items were commented in a header).
   1.232 +// ---------------------------------------------------------
   1.233 +//
   1.234 +void CSpeechEncoderConfigMsgHdlr::DoSetBitrateL(TMMFMessage& aMessage)
   1.235 +	{
   1.236 +	TPckgBuf<TUint> pckg;
   1.237 +	aMessage.ReadData1FromClientL(pckg);
   1.238 +	TInt status = iSpeechEncoderConfigCI->SetBitrate(pckg());
   1.239 +    aMessage.Complete(status);
   1.240 +	}
   1.241 +
   1.242 +// ---------------------------------------------------------
   1.243 +// CSpeechEncoderConfigMsgHdlr::DoGetBitrateL
   1.244 +// Handles the message from the proxy and calls the custom interface.
   1.245 +// The custom interface returns the data requested and this function
   1.246 +// writes it back to the proxy.
   1.247 +// (other items were commented in a header).
   1.248 +// ---------------------------------------------------------
   1.249 +//
   1.250 +void CSpeechEncoderConfigMsgHdlr::DoGetBitrateL(TMMFMessage& aMessage)
   1.251 +	{
   1.252 +	TUint bitrate;
   1.253 +	TInt status = iSpeechEncoderConfigCI->GetBitrate(bitrate);
   1.254 +	if (status == KErrNone)
   1.255 +    	{
   1.256 +    	TPckgBuf<TUint> pckg;
   1.257 +    	pckg() = bitrate;
   1.258 +	    aMessage.WriteDataToClientL(pckg);
   1.259 +    	}
   1.260 +    aMessage.Complete(status);
   1.261 +	}
   1.262 +
   1.263 +// ---------------------------------------------------------
   1.264 +// CSpeechEncoderConfigMsgHdlr::DoSetVadModeL
   1.265 +// Handles the message from the proxy and calls the custom interface method.
   1.266 +// The data passed from the proxy is read from the message and passed to
   1.267 +// the custom interface.
   1.268 +// (other items were commented in a header).
   1.269 +// ---------------------------------------------------------
   1.270 +//
   1.271 +void CSpeechEncoderConfigMsgHdlr::DoSetVadModeL(TMMFMessage& aMessage)
   1.272 +	{
   1.273 +	TPckgBuf<TBool> pckg;
   1.274 +	aMessage.ReadData1FromClientL(pckg);
   1.275 +	TInt status = iSpeechEncoderConfigCI->SetVadMode(pckg());
   1.276 +    aMessage.Complete(status);
   1.277 +	}
   1.278 +
   1.279 +// ---------------------------------------------------------
   1.280 +// CSpeechEncoderConfigMsgHdlr::DoGetVadModeL
   1.281 +// Handles the message from the proxy and calls the custom interface.
   1.282 +// The custom interface returns the data requested and this function
   1.283 +// writes it back to the proxy.
   1.284 +// (other items were commented in a header).
   1.285 +// ---------------------------------------------------------
   1.286 +//
   1.287 +void CSpeechEncoderConfigMsgHdlr::DoGetVadModeL(TMMFMessage& aMessage)
   1.288 +	{
   1.289 +	TBool vadMode;
   1.290 +	TInt status = iSpeechEncoderConfigCI->GetVadMode(vadMode);
   1.291 +	if (status == KErrNone)
   1.292 +    	{
   1.293 +    	TPckgBuf<TBool> pckg;
   1.294 +	    pckg() = vadMode;
   1.295 +    	aMessage.WriteDataToClientL(pckg);
   1.296 +    	}
   1.297 +    aMessage.Complete(status);
   1.298 +	}
   1.299 +
   1.300 +
   1.301 +
   1.302 +// End of File