os/mm/devsoundextensions/mmfcustominterfaces/SpeechEncoderConfig/SpeechEncoderConfigMsgHdlr/src/SpeechEncoderConfigMsgHdlr.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). 
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:   Message handler for speech encoder configuration interface
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
// INCLUDE FILES
sl@0
    21
#include    "SpeechEncoderConfigMsgHdlr.h"
sl@0
    22
#include    "SpeechEncoderConfigMsgs.h"
sl@0
    23
#include    <SpeechEncoderConfig.h>
sl@0
    24
sl@0
    25
// EXTERNAL DATA STRUCTURES
sl@0
    26
sl@0
    27
// EXTERNAL FUNCTION PROTOTYPES  
sl@0
    28
sl@0
    29
// CONSTANTS
sl@0
    30
sl@0
    31
// MACROS
sl@0
    32
sl@0
    33
// LOCAL CONSTANTS AND MACROS
sl@0
    34
sl@0
    35
// MODULE DATA STRUCTURES
sl@0
    36
sl@0
    37
// LOCAL FUNCTION PROTOTYPES
sl@0
    38
sl@0
    39
// FORWARD DECLARATIONS
sl@0
    40
sl@0
    41
// ============================= LOCAL FUNCTIONS ===============================
sl@0
    42
sl@0
    43
// ============================ MEMBER FUNCTIONS ===============================
sl@0
    44
sl@0
    45
// -----------------------------------------------------------------------------
sl@0
    46
// CSpeechEncoderConfigMsgHdlr::CSpeechEncoderConfigMsgHdlr
sl@0
    47
// C++ default constructor can NOT contain any code, that
sl@0
    48
// might leave.
sl@0
    49
// -----------------------------------------------------------------------------
sl@0
    50
//
sl@0
    51
CSpeechEncoderConfigMsgHdlr::CSpeechEncoderConfigMsgHdlr(
sl@0
    52
                                 CSpeechEncoderConfig* aSpeechEncoderConfigCI) :
sl@0
    53
	CMMFObject(KUidSpeechEncoderConfig)
sl@0
    54
    {
sl@0
    55
    iSpeechEncoderConfigCI = aSpeechEncoderConfigCI;
sl@0
    56
    }
sl@0
    57
sl@0
    58
// -----------------------------------------------------------------------------
sl@0
    59
// CSpeechEncoderConfigMsgHdlr::ConstructL
sl@0
    60
// Symbian 2nd phase constructor can leave.
sl@0
    61
// -----------------------------------------------------------------------------
sl@0
    62
//
sl@0
    63
void CSpeechEncoderConfigMsgHdlr::ConstructL()
sl@0
    64
    {
sl@0
    65
    }
sl@0
    66
sl@0
    67
// -----------------------------------------------------------------------------
sl@0
    68
// CSpeechEncoderConfigMsgHdlr::NewL
sl@0
    69
// Two-phased constructor.
sl@0
    70
// -----------------------------------------------------------------------------
sl@0
    71
//
sl@0
    72
EXPORT_C CSpeechEncoderConfigMsgHdlr* CSpeechEncoderConfigMsgHdlr::NewL(
sl@0
    73
                                                  TAny*  aSpeechEncoderConfigCI)
sl@0
    74
    {
sl@0
    75
    CSpeechEncoderConfig* speechEncoderConfigCI = 
sl@0
    76
                                  (CSpeechEncoderConfig*)aSpeechEncoderConfigCI;
sl@0
    77
    CSpeechEncoderConfigMsgHdlr* self = 
sl@0
    78
                new (ELeave) CSpeechEncoderConfigMsgHdlr(speechEncoderConfigCI);
sl@0
    79
    CleanupStack::PushL( self );
sl@0
    80
    self->ConstructL();
sl@0
    81
    CleanupStack::Pop( self );
sl@0
    82
    return self;
sl@0
    83
    }
sl@0
    84
sl@0
    85
// Destructor
sl@0
    86
EXPORT_C CSpeechEncoderConfigMsgHdlr::~CSpeechEncoderConfigMsgHdlr()
sl@0
    87
	{
sl@0
    88
	iSupportedBitrates.Close();
sl@0
    89
	delete iDataCopyBuffer;
sl@0
    90
	delete iSpeechEncoderConfigCI;
sl@0
    91
	}
sl@0
    92
sl@0
    93
// ---------------------------------------------------------
sl@0
    94
// CSpeechEncoderConfigMsgHdlr::HandleRequest
sl@0
    95
// Handles the messages from the proxy.
sl@0
    96
// Calls a subfunction which determines which custom interface to call.
sl@0
    97
// A subfunction is used to contain multiple leaving functions for a single
sl@0
    98
// trap.
sl@0
    99
// (other items were commented in a header).
sl@0
   100
// ---------------------------------------------------------
sl@0
   101
//
sl@0
   102
EXPORT_C void CSpeechEncoderConfigMsgHdlr::HandleRequest(TMMFMessage& aMessage)
sl@0
   103
	{
sl@0
   104
    // debug panic
sl@0
   105
	ASSERT(aMessage.Destination().InterfaceId() == KUidSpeechEncoderConfig);
sl@0
   106
	TRAPD(error,DoHandleRequestL(aMessage));
sl@0
   107
	if(error)
sl@0
   108
		{
sl@0
   109
		aMessage.Complete(error);
sl@0
   110
		}
sl@0
   111
	}
sl@0
   112
sl@0
   113
// ---------------------------------------------------------
sl@0
   114
// CSpeechEncoderConfigMsgHdlr::DoHandleRequestL
sl@0
   115
// Determines which custom interface to call.
sl@0
   116
// (other items were commented in a header).
sl@0
   117
// ---------------------------------------------------------
sl@0
   118
//
sl@0
   119
void CSpeechEncoderConfigMsgHdlr::DoHandleRequestL(TMMFMessage& aMessage)
sl@0
   120
	{
sl@0
   121
	switch(aMessage.Function())
sl@0
   122
		{
sl@0
   123
		case ESecmGetNumOfSupportedBitrates:
sl@0
   124
			{
sl@0
   125
			DoGetNumOfSupportedBitratesL(aMessage);
sl@0
   126
			break;
sl@0
   127
			}
sl@0
   128
		case ESecmGetSupportedBitrates:
sl@0
   129
			{
sl@0
   130
			DoGetSupportedBitratesL(aMessage);
sl@0
   131
			break;
sl@0
   132
			}
sl@0
   133
		case ESecmSetBitrate:
sl@0
   134
			{
sl@0
   135
			DoSetBitrateL(aMessage);
sl@0
   136
			break;
sl@0
   137
			}
sl@0
   138
		case ESecmGetBitrate:
sl@0
   139
			{
sl@0
   140
			DoGetBitrateL(aMessage);
sl@0
   141
			break;
sl@0
   142
			}
sl@0
   143
		case ESecmSetVadMode:
sl@0
   144
			{
sl@0
   145
			DoSetVadModeL(aMessage);
sl@0
   146
			break;
sl@0
   147
			}
sl@0
   148
		case ESecmGetVadMode:
sl@0
   149
			{
sl@0
   150
			DoGetVadModeL(aMessage);
sl@0
   151
			break;
sl@0
   152
			}
sl@0
   153
		default:
sl@0
   154
			{
sl@0
   155
			aMessage.Complete(KErrNotSupported);
sl@0
   156
			}
sl@0
   157
		}
sl@0
   158
	}
sl@0
   159
sl@0
   160
// ---------------------------------------------------------
sl@0
   161
// CSpeechEncoderConfigMsgHdlr::DoGetNumOfSupportedBitratesL
sl@0
   162
// Handles the message from the proxy and calls the custom interface.
sl@0
   163
// The custom interface returns the data requested and this function
sl@0
   164
// writes it back to the proxy. It also creates a buffer and fills
sl@0
   165
// it with the bitrate data to be returned in the subsequent call
sl@0
   166
// of DoGetSupportedBitratesL().
sl@0
   167
// (other items were commented in a header).
sl@0
   168
// ---------------------------------------------------------
sl@0
   169
//
sl@0
   170
void CSpeechEncoderConfigMsgHdlr::DoGetNumOfSupportedBitratesL(
sl@0
   171
                                                       TMMFMessage& aMessage)
sl@0
   172
	{
sl@0
   173
	iSupportedBitrates.Reset();
sl@0
   174
	TInt status = iSpeechEncoderConfigCI->GetSupportedBitrates(
sl@0
   175
	                                                     iSupportedBitrates);
sl@0
   176
	CreateBufFromUintArrayL(iSupportedBitrates);
sl@0
   177
	if (status == KErrNone)
sl@0
   178
    	{
sl@0
   179
	    TPckgBuf<TUint> pckg;
sl@0
   180
    	pckg() = iSupportedBitrates.Count();
sl@0
   181
	    aMessage.WriteDataToClientL(pckg);
sl@0
   182
	    }
sl@0
   183
    aMessage.Complete(status);
sl@0
   184
	}
sl@0
   185
sl@0
   186
// ---------------------------------------------------------
sl@0
   187
// CSpeechEncoderConfigMsgHdlr::CreateBufFromUintArrayL
sl@0
   188
// Utility function used to create a buffer a fill it with data from the array
sl@0
   189
// passed in.
sl@0
   190
// (other items were commented in a header).
sl@0
   191
// ---------------------------------------------------------
sl@0
   192
//
sl@0
   193
void CSpeechEncoderConfigMsgHdlr::CreateBufFromUintArrayL(RArray<TUint>& aArray)
sl@0
   194
	{
sl@0
   195
	delete iDataCopyBuffer;
sl@0
   196
	iDataCopyBuffer = NULL;
sl@0
   197
sl@0
   198
	iDataCopyBuffer = CBufFlat::NewL(8);
sl@0
   199
	RBufWriteStream stream;
sl@0
   200
	stream.Open(*iDataCopyBuffer);
sl@0
   201
	CleanupClosePushL(stream);
sl@0
   202
	for (TInt i=0;i<aArray.Count();i++)
sl@0
   203
		stream.WriteUint32L(aArray[i]);
sl@0
   204
	CleanupStack::PopAndDestroy(&stream);//stream
sl@0
   205
	}
sl@0
   206
	
sl@0
   207
// ---------------------------------------------------------
sl@0
   208
// CSpeechEncoderConfigMsgHdlr::DoGetSupportedBitratesL
sl@0
   209
// Handles the message from the proxy and calls the custom interface.
sl@0
   210
// The custom interface returns the data requested and this function
sl@0
   211
// writes it back to the proxy.
sl@0
   212
// (other items were commented in a header).
sl@0
   213
// ---------------------------------------------------------
sl@0
   214
//
sl@0
   215
void CSpeechEncoderConfigMsgHdlr::DoGetSupportedBitratesL(TMMFMessage& aMessage)
sl@0
   216
	{
sl@0
   217
	if (!iDataCopyBuffer)
sl@0
   218
		User::Leave(KErrNotReady);
sl@0
   219
	aMessage.WriteDataToClientL(iDataCopyBuffer->Ptr(0));
sl@0
   220
    aMessage.Complete(KErrNone);
sl@0
   221
	}
sl@0
   222
	
sl@0
   223
// ---------------------------------------------------------
sl@0
   224
// CSpeechEncoderConfigMsgHdlr::DoSetBitrateL
sl@0
   225
// Handles the message from the proxy and calls the custom interface method.
sl@0
   226
// The data passed from the proxy is read from the message and passed to
sl@0
   227
// the custom interface.
sl@0
   228
// (other items were commented in a header).
sl@0
   229
// ---------------------------------------------------------
sl@0
   230
//
sl@0
   231
void CSpeechEncoderConfigMsgHdlr::DoSetBitrateL(TMMFMessage& aMessage)
sl@0
   232
	{
sl@0
   233
	TPckgBuf<TUint> pckg;
sl@0
   234
	aMessage.ReadData1FromClientL(pckg);
sl@0
   235
	TInt status = iSpeechEncoderConfigCI->SetBitrate(pckg());
sl@0
   236
    aMessage.Complete(status);
sl@0
   237
	}
sl@0
   238
sl@0
   239
// ---------------------------------------------------------
sl@0
   240
// CSpeechEncoderConfigMsgHdlr::DoGetBitrateL
sl@0
   241
// Handles the message from the proxy and calls the custom interface.
sl@0
   242
// The custom interface returns the data requested and this function
sl@0
   243
// writes it back to the proxy.
sl@0
   244
// (other items were commented in a header).
sl@0
   245
// ---------------------------------------------------------
sl@0
   246
//
sl@0
   247
void CSpeechEncoderConfigMsgHdlr::DoGetBitrateL(TMMFMessage& aMessage)
sl@0
   248
	{
sl@0
   249
	TUint bitrate;
sl@0
   250
	TInt status = iSpeechEncoderConfigCI->GetBitrate(bitrate);
sl@0
   251
	if (status == KErrNone)
sl@0
   252
    	{
sl@0
   253
    	TPckgBuf<TUint> pckg;
sl@0
   254
    	pckg() = bitrate;
sl@0
   255
	    aMessage.WriteDataToClientL(pckg);
sl@0
   256
    	}
sl@0
   257
    aMessage.Complete(status);
sl@0
   258
	}
sl@0
   259
sl@0
   260
// ---------------------------------------------------------
sl@0
   261
// CSpeechEncoderConfigMsgHdlr::DoSetVadModeL
sl@0
   262
// Handles the message from the proxy and calls the custom interface method.
sl@0
   263
// The data passed from the proxy is read from the message and passed to
sl@0
   264
// the custom interface.
sl@0
   265
// (other items were commented in a header).
sl@0
   266
// ---------------------------------------------------------
sl@0
   267
//
sl@0
   268
void CSpeechEncoderConfigMsgHdlr::DoSetVadModeL(TMMFMessage& aMessage)
sl@0
   269
	{
sl@0
   270
	TPckgBuf<TBool> pckg;
sl@0
   271
	aMessage.ReadData1FromClientL(pckg);
sl@0
   272
	TInt status = iSpeechEncoderConfigCI->SetVadMode(pckg());
sl@0
   273
    aMessage.Complete(status);
sl@0
   274
	}
sl@0
   275
sl@0
   276
// ---------------------------------------------------------
sl@0
   277
// CSpeechEncoderConfigMsgHdlr::DoGetVadModeL
sl@0
   278
// Handles the message from the proxy and calls the custom interface.
sl@0
   279
// The custom interface returns the data requested and this function
sl@0
   280
// writes it back to the proxy.
sl@0
   281
// (other items were commented in a header).
sl@0
   282
// ---------------------------------------------------------
sl@0
   283
//
sl@0
   284
void CSpeechEncoderConfigMsgHdlr::DoGetVadModeL(TMMFMessage& aMessage)
sl@0
   285
	{
sl@0
   286
	TBool vadMode;
sl@0
   287
	TInt status = iSpeechEncoderConfigCI->GetVadMode(vadMode);
sl@0
   288
	if (status == KErrNone)
sl@0
   289
    	{
sl@0
   290
    	TPckgBuf<TBool> pckg;
sl@0
   291
	    pckg() = vadMode;
sl@0
   292
    	aMessage.WriteDataToClientL(pckg);
sl@0
   293
    	}
sl@0
   294
    aMessage.Complete(status);
sl@0
   295
	}
sl@0
   296
sl@0
   297
sl@0
   298
sl@0
   299
// End of File