os/mm/devsoundextensions/mmfcustominterfaces/SpeechEncoderConfig/SpeechEncoderConfigMsgHdlr/src/SpeechEncoderConfigMsgHdlr.cpp
First public contribution.
2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Message handler for speech encoder configuration interface
21 #include "SpeechEncoderConfigMsgHdlr.h"
22 #include "SpeechEncoderConfigMsgs.h"
23 #include <SpeechEncoderConfig.h>
25 // EXTERNAL DATA STRUCTURES
27 // EXTERNAL FUNCTION PROTOTYPES
33 // LOCAL CONSTANTS AND MACROS
35 // MODULE DATA STRUCTURES
37 // LOCAL FUNCTION PROTOTYPES
39 // FORWARD DECLARATIONS
41 // ============================= LOCAL FUNCTIONS ===============================
43 // ============================ MEMBER FUNCTIONS ===============================
45 // -----------------------------------------------------------------------------
46 // CSpeechEncoderConfigMsgHdlr::CSpeechEncoderConfigMsgHdlr
47 // C++ default constructor can NOT contain any code, that
49 // -----------------------------------------------------------------------------
51 CSpeechEncoderConfigMsgHdlr::CSpeechEncoderConfigMsgHdlr(
52 CSpeechEncoderConfig* aSpeechEncoderConfigCI) :
53 CMMFObject(KUidSpeechEncoderConfig)
55 iSpeechEncoderConfigCI = aSpeechEncoderConfigCI;
58 // -----------------------------------------------------------------------------
59 // CSpeechEncoderConfigMsgHdlr::ConstructL
60 // Symbian 2nd phase constructor can leave.
61 // -----------------------------------------------------------------------------
63 void CSpeechEncoderConfigMsgHdlr::ConstructL()
67 // -----------------------------------------------------------------------------
68 // CSpeechEncoderConfigMsgHdlr::NewL
69 // Two-phased constructor.
70 // -----------------------------------------------------------------------------
72 EXPORT_C CSpeechEncoderConfigMsgHdlr* CSpeechEncoderConfigMsgHdlr::NewL(
73 TAny* aSpeechEncoderConfigCI)
75 CSpeechEncoderConfig* speechEncoderConfigCI =
76 (CSpeechEncoderConfig*)aSpeechEncoderConfigCI;
77 CSpeechEncoderConfigMsgHdlr* self =
78 new (ELeave) CSpeechEncoderConfigMsgHdlr(speechEncoderConfigCI);
79 CleanupStack::PushL( self );
81 CleanupStack::Pop( self );
86 EXPORT_C CSpeechEncoderConfigMsgHdlr::~CSpeechEncoderConfigMsgHdlr()
88 iSupportedBitrates.Close();
89 delete iDataCopyBuffer;
90 delete iSpeechEncoderConfigCI;
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
99 // (other items were commented in a header).
100 // ---------------------------------------------------------
102 EXPORT_C void CSpeechEncoderConfigMsgHdlr::HandleRequest(TMMFMessage& aMessage)
105 ASSERT(aMessage.Destination().InterfaceId() == KUidSpeechEncoderConfig);
106 TRAPD(error,DoHandleRequestL(aMessage));
109 aMessage.Complete(error);
113 // ---------------------------------------------------------
114 // CSpeechEncoderConfigMsgHdlr::DoHandleRequestL
115 // Determines which custom interface to call.
116 // (other items were commented in a header).
117 // ---------------------------------------------------------
119 void CSpeechEncoderConfigMsgHdlr::DoHandleRequestL(TMMFMessage& aMessage)
121 switch(aMessage.Function())
123 case ESecmGetNumOfSupportedBitrates:
125 DoGetNumOfSupportedBitratesL(aMessage);
128 case ESecmGetSupportedBitrates:
130 DoGetSupportedBitratesL(aMessage);
133 case ESecmSetBitrate:
135 DoSetBitrateL(aMessage);
138 case ESecmGetBitrate:
140 DoGetBitrateL(aMessage);
143 case ESecmSetVadMode:
145 DoSetVadModeL(aMessage);
148 case ESecmGetVadMode:
150 DoGetVadModeL(aMessage);
155 aMessage.Complete(KErrNotSupported);
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 // ---------------------------------------------------------
170 void CSpeechEncoderConfigMsgHdlr::DoGetNumOfSupportedBitratesL(
171 TMMFMessage& aMessage)
173 iSupportedBitrates.Reset();
174 TInt status = iSpeechEncoderConfigCI->GetSupportedBitrates(
176 CreateBufFromUintArrayL(iSupportedBitrates);
177 if (status == KErrNone)
179 TPckgBuf<TUint> pckg;
180 pckg() = iSupportedBitrates.Count();
181 aMessage.WriteDataToClientL(pckg);
183 aMessage.Complete(status);
186 // ---------------------------------------------------------
187 // CSpeechEncoderConfigMsgHdlr::CreateBufFromUintArrayL
188 // Utility function used to create a buffer a fill it with data from the array
190 // (other items were commented in a header).
191 // ---------------------------------------------------------
193 void CSpeechEncoderConfigMsgHdlr::CreateBufFromUintArrayL(RArray<TUint>& aArray)
195 delete iDataCopyBuffer;
196 iDataCopyBuffer = NULL;
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
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 // ---------------------------------------------------------
215 void CSpeechEncoderConfigMsgHdlr::DoGetSupportedBitratesL(TMMFMessage& aMessage)
217 if (!iDataCopyBuffer)
218 User::Leave(KErrNotReady);
219 aMessage.WriteDataToClientL(iDataCopyBuffer->Ptr(0));
220 aMessage.Complete(KErrNone);
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 // ---------------------------------------------------------
231 void CSpeechEncoderConfigMsgHdlr::DoSetBitrateL(TMMFMessage& aMessage)
233 TPckgBuf<TUint> pckg;
234 aMessage.ReadData1FromClientL(pckg);
235 TInt status = iSpeechEncoderConfigCI->SetBitrate(pckg());
236 aMessage.Complete(status);
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 // ---------------------------------------------------------
247 void CSpeechEncoderConfigMsgHdlr::DoGetBitrateL(TMMFMessage& aMessage)
250 TInt status = iSpeechEncoderConfigCI->GetBitrate(bitrate);
251 if (status == KErrNone)
253 TPckgBuf<TUint> pckg;
255 aMessage.WriteDataToClientL(pckg);
257 aMessage.Complete(status);
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 // ---------------------------------------------------------
268 void CSpeechEncoderConfigMsgHdlr::DoSetVadModeL(TMMFMessage& aMessage)
270 TPckgBuf<TBool> pckg;
271 aMessage.ReadData1FromClientL(pckg);
272 TInt status = iSpeechEncoderConfigCI->SetVadMode(pckg());
273 aMessage.Complete(status);
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 // ---------------------------------------------------------
284 void CSpeechEncoderConfigMsgHdlr::DoGetVadModeL(TMMFMessage& aMessage)
287 TInt status = iSpeechEncoderConfigCI->GetVadMode(vadMode);
288 if (status == KErrNone)
290 TPckgBuf<TBool> pckg;
292 aMessage.WriteDataToClientL(pckg);
294 aMessage.Complete(status);