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