os/mm/devsoundextensions/mmfcustominterfaces/SbcEncoderIntfc/SbcEncoderIntfcMsgHdlr/src/SbcEncoderIntfcMsgHdlr.cpp
Update contrib.
2 * Copyright (c) 2006 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 SBC encoder interface.
21 #include <SbcEncoderIntfc.h>
22 #include "SbcEncoderIntfcMsgHdlr.h"
23 #include "SbcEncoderIntfcMsgs.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 ===============================
46 * CSbcEncoderIntfcMsgHdlr::CSbcEncoderIntfcMsgHdlr
47 * C++ default constructor can NOT contain any code, that might leave.
49 CSbcEncoderIntfcMsgHdlr::CSbcEncoderIntfcMsgHdlr(
50 CSbcEncoderIntfc* aSbcEncoderIntfcCI) :
51 CMMFObject(KUidSbcEncoderIntfc)
53 iSbcEncoderIntfcCI = aSbcEncoderIntfcCI;
57 * CSbcEncoderIntfcMsgHdlr::ConstructL
58 * Symbian 2nd phase constructor can leave.
60 void CSbcEncoderIntfcMsgHdlr::ConstructL()
65 * CSbcEncoderIntfcMsgHdlr::NewL
66 * Two-phased constructor.
68 EXPORT_C CSbcEncoderIntfcMsgHdlr* CSbcEncoderIntfcMsgHdlr::NewL(
69 TAny* aSbcEncoderIntfcCI)
71 CSbcEncoderIntfc* SbcEncoderIntfcCI =
72 (CSbcEncoderIntfc*)aSbcEncoderIntfcCI;
73 CSbcEncoderIntfcMsgHdlr* self =
74 new (ELeave) CSbcEncoderIntfcMsgHdlr(SbcEncoderIntfcCI);
75 CleanupStack::PushL( self );
77 CleanupStack::Pop( self );
84 EXPORT_C CSbcEncoderIntfcMsgHdlr::~CSbcEncoderIntfcMsgHdlr()
86 delete iDataCopyBuffer;
87 delete iSbcEncoderIntfcCI;
91 * CSbcEncoderIntfcMsgHdlr::HandleRequest
92 * Handles the messages from the proxy.
93 * Calls a subfunction which determines which custom interface to call.
94 * A subfunction is used to contain multiple leaving functions for a
96 * (other items were commented in a header).
98 EXPORT_C void CSbcEncoderIntfcMsgHdlr::HandleRequest(TMMFMessage& aMessage)
101 ASSERT(aMessage.Destination().InterfaceId() == KUidSbcEncoderIntfc);
102 TRAPD(error, DoHandleRequestL(aMessage));
105 aMessage.Complete(error);
110 * CSbcEncoderIntfcMsgHdlr::DoHandleRequestL
111 * Determines which custom interface to call.
112 * (other items were commented in a header).
114 void CSbcEncoderIntfcMsgHdlr::DoHandleRequestL(TMMFMessage& aMessage)
116 switch(aMessage.Function())
118 case ESbceimGetNumOfSupportedSamplingFrequencies:
120 DoGetNumOfSupportedSamplingFrequenciesL(aMessage);
123 case ESbceimGetSupportedSamplingFrequencies:
125 DoGetSupportedSamplingFrequenciesL(aMessage);
128 case ESbceimGetNumOfSupportedChannelModes:
130 DoGetNumOfSupportedChannelModesL(aMessage);
133 case ESbceimGetSupportedChannelModes:
135 DoGetSupportedChannelModesL(aMessage);
138 case ESbceimGetNumOfSupportedNumOfSubbands:
140 DoGetNumOfSupportedNumOfSubbandsL(aMessage);
143 case ESbceimGetSupportedNumOfSubbands:
145 DoGetSupportedNumOfSubbandsL(aMessage);
148 case ESbceimGetNumOfSupportedBlocks:
150 DoGetNumOfSupportedBlocksL(aMessage);
153 case ESbceimGetSupportedBlocks:
155 DoGetSupportedBlocksL(aMessage);
158 case ESbceimGetNumOfSupportedAllocationMethods:
160 DoGetNumOfSupportedAllocationMethodsL(aMessage);
163 case ESbceimGetSupportedAllocationMethods:
165 DoGetSupportedAllocationMethodsL(aMessage);
168 case ESbceimGetSupportedBitpoolRange:
170 DoGetSupportedBitpoolRangeL(aMessage);
173 case ESbceimApplyConfig:
175 DoApplyConfigL(aMessage);
180 aMessage.Complete(KErrNotSupported);
186 * CSbcEncoderIntfcMsgHdlr::DoGetNumOfSupportedSamplingFrequenciesL
187 * Handles the message from the proxy and calls the custom interface.
188 * The custom interface returns the data requested and this function writes
189 * it back to the proxy. It also creates a buffer and fills the sampling
190 * frequencies data to be returned in the subsequent call to
191 * DoGetSupportedSamplingFrequenciesL().
192 * (other items were commented in a header).
194 void CSbcEncoderIntfcMsgHdlr::DoGetNumOfSupportedSamplingFrequenciesL(
195 TMMFMessage& aMessage)
197 RArray<TUint> supSamplingFrequencies;
198 CleanupClosePushL(supSamplingFrequencies);
200 TInt status = iSbcEncoderIntfcCI->GetSupportedSamplingFrequencies(
201 supSamplingFrequencies);
203 // store array in iDataCopyBuffer
204 CreateBufFromUintArrayL(supSamplingFrequencies);
206 if (status == KErrNone)
208 TPckgBuf<TUint> pckg;
209 pckg() = supSamplingFrequencies.Count();
210 aMessage.WriteDataToClientL(pckg);
213 CleanupStack::PopAndDestroy(&supSamplingFrequencies);
214 aMessage.Complete(status);
218 * CSbcEncoderIntfcMsgHdlr::DoGetSupportedSamplingFrequenciesL
219 * Sends the sampling frequency data returned from the custom interface
220 * implementation to the client.
221 * (other items were commented in a header).
223 void CSbcEncoderIntfcMsgHdlr::DoGetSupportedSamplingFrequenciesL(
224 TMMFMessage& aMessage)
226 SendDataBufferToClientL(aMessage);
230 * CSbcEncoderIntfcMsgHdlr::DoGetNumOfSupportedChannelModesL
231 * Handles the message from the proxy and calls the custom interface.
232 * The custom interface returns the data requested and this function writes
233 * it back to the proxy. It also creates a buffer and fills the sampling
234 * frequencies data to be returned in the subsequent call to
235 * DoGetSupportedChannelModesL().
236 * (other items were commented in a header).
238 void CSbcEncoderIntfcMsgHdlr::DoGetNumOfSupportedChannelModesL(
239 TMMFMessage& aMessage)
241 RArray<CSbcEncoderIntfc::TSbcChannelMode> supChannelModes;
242 CleanupClosePushL(supChannelModes);
244 iSbcEncoderIntfcCI->GetSupportedChannelModes(supChannelModes);
246 // store array in iDataCopyBuffer
247 CreateBufFromUintArrayL(reinterpret_cast<RArray<TUint>&>(supChannelModes));
249 if (status == KErrNone)
251 TPckgBuf<TUint> pckg;
252 pckg() = supChannelModes.Count();
253 aMessage.WriteDataToClientL(pckg);
256 CleanupStack::PopAndDestroy(&supChannelModes);
257 aMessage.Complete(status);
261 * CSbcEncoderIntfcMsgHdlr::DoGetSupportedChannelModesL
262 * Sends the channel modes data returned from the custom interface
263 * implementation to the client.
264 * (other items were commented in a header).
266 void CSbcEncoderIntfcMsgHdlr::DoGetSupportedChannelModesL(
267 TMMFMessage& aMessage)
269 SendDataBufferToClientL(aMessage);
273 * CSbcEncoderIntfcMsgHdlr::DoGetNumOfSupportedBlocksL
274 * Handles the message from the proxy and calls the custom interface.
275 * The custom interface returns the data requested and this function writes
276 * it back to the proxy. It also creates a buffer and fills the supported
277 * blocks data to be returned in the subsequent call to
278 * DoGetSupportedBlocksL().
279 * (other items were commented in a header).
281 void CSbcEncoderIntfcMsgHdlr::DoGetNumOfSupportedBlocksL(
282 TMMFMessage& aMessage)
284 RArray<TUint> supNumBlocks;
285 CleanupClosePushL(supNumBlocks);
287 TInt status = iSbcEncoderIntfcCI->GetSupportedNumOfBlocks(supNumBlocks);
289 CreateBufFromUintArrayL(supNumBlocks);
291 if (status == KErrNone)
293 TPckgBuf<TUint> pckg;
294 pckg() = supNumBlocks.Count();
295 aMessage.WriteDataToClientL(pckg);
298 CleanupStack::PopAndDestroy(&supNumBlocks);
299 aMessage.Complete(status);
303 * CSbcEncoderIntfcMsgHdlr::DoGetSupportedBlocksL
304 * Sends the supported blocks data returned from the custom interface
305 * implementation to the client.
306 * (other items were commented in a header).
308 void CSbcEncoderIntfcMsgHdlr::DoGetSupportedBlocksL(TMMFMessage& aMessage)
310 SendDataBufferToClientL(aMessage);
314 * CSbcEncoderIntfcMsgHdlr::DoGetNumOfSupportedNumOfSubbandsL
315 * Handles the message from the proxy and calls the custom interface.
316 * The custom interface returns the data requested and this function writes
317 * it back to the proxy. It also creates a buffer and fills the supported
318 * subbands data to be returned in the subsequent call to
319 * DoGetSupportedNumOfSubbandsL().
320 * (other items were commented in a header).
322 void CSbcEncoderIntfcMsgHdlr::DoGetNumOfSupportedNumOfSubbandsL(
323 TMMFMessage& aMessage)
325 RArray<TUint> supNumSubbands;
326 CleanupClosePushL(supNumSubbands);
328 TInt status = iSbcEncoderIntfcCI->GetSupportedNumOfSubbands(supNumSubbands);
330 CreateBufFromUintArrayL(supNumSubbands);
332 if (status == KErrNone)
334 TPckgBuf<TUint> pckg;
335 pckg() = supNumSubbands.Count();
336 aMessage.WriteDataToClientL(pckg);
339 CleanupStack::PopAndDestroy(&supNumSubbands);
340 aMessage.Complete(status);
344 * CSbcEncoderIntfcMsgHdlr::DoGetSupportedNumOfSubbandsL
345 * Sends the supported subbands data returned from the custom interface
346 * implementation to the client.
347 * (other items were commented in a header).
349 void CSbcEncoderIntfcMsgHdlr::DoGetSupportedNumOfSubbandsL(
350 TMMFMessage& aMessage)
352 SendDataBufferToClientL(aMessage);
356 * CSbcEncoderIntfcMsgHdlr::DoGetNumOfSupportedAllocationMethodsL
357 * Handles the message from the proxy and calls the custom interface.
358 * The custom interface returns the data requested and this function writes
359 * it back to the proxy. It also creates a buffer and fills the supported
360 * allocation methods data to be returned in the subsequent call to
361 * DoGetSupportedAllocationMethodsL().
362 * (other items were commented in a header).
364 void CSbcEncoderIntfcMsgHdlr::DoGetNumOfSupportedAllocationMethodsL(
365 TMMFMessage& aMessage)
367 RArray<CSbcEncoderIntfc::TSbcAllocationMethod> supAllocMethods;
368 CleanupClosePushL(supAllocMethods);
371 iSbcEncoderIntfcCI->GetSupportedAllocationMethods(supAllocMethods);
373 // store array in iDataCopyBuffer
374 CreateBufFromUintArrayL(reinterpret_cast<RArray<TUint>&>(supAllocMethods));
376 if (status == KErrNone)
378 TPckgBuf<TUint> pckg;
379 pckg() = supAllocMethods.Count();
380 aMessage.WriteDataToClientL(pckg);
383 CleanupStack::PopAndDestroy(&supAllocMethods);
384 aMessage.Complete(status);
388 * CSbcEncoderIntfcMsgHdlr::DoGetSupportedAllocationMethodsL
389 * Sends the supported allocation methods data returned from the custom
390 * interface implementation to the client.
391 * (other items were commented in a header).
393 void CSbcEncoderIntfcMsgHdlr::DoGetSupportedAllocationMethodsL(
394 TMMFMessage& aMessage)
396 SendDataBufferToClientL(aMessage);
400 * CSbcEncoderIntfcMsgHdlr::DoGetSupportedBitpoolRangeL
401 * Handles the message from the proxy and calls the custom interface.
402 * The custom interface returns the requested bitpool range and this function
403 * writes it back to the proxy.
404 * (other items were commented in a header).
406 void CSbcEncoderIntfcMsgHdlr::DoGetSupportedBitpoolRangeL(
407 TMMFMessage& aMessage)
409 TSbcEncoderBitpoolRange bitPoolRange;
410 bitPoolRange.iMinSupportedBitpoolSize = 0;
411 bitPoolRange.iMaxSupportedBitpoolSize = 0;
413 TInt status = iSbcEncoderIntfcCI->GetSupportedBitpoolRange(
414 bitPoolRange.iMinSupportedBitpoolSize,
415 bitPoolRange.iMaxSupportedBitpoolSize);
417 if (status == KErrNone)
419 TPckgBuf<TSbcEncoderBitpoolRange> pckg;
420 pckg() = bitPoolRange;
421 aMessage.WriteDataToClientL(pckg);
424 aMessage.Complete(status);
428 * CSbcEncoderIntfcMsgHdlr::DoApplyConfigL
429 * Handles the message from the proxy to commit configuration settings and
430 * calls the custom interface method. The data passed from the proxy is read
431 * from the message and passed to the custom interface.
432 * (other items were commented in a header).
434 void CSbcEncoderIntfcMsgHdlr::DoApplyConfigL(TMMFMessage& aMessage)
436 TPckgBuf<TSbcEncoderConfig> pckgBuf;
437 aMessage.ReadData1FromClientL(pckgBuf);
439 iSbcEncoderIntfcCI->SetSamplingFrequency(pckgBuf().iSamplingFrequency);
440 iSbcEncoderIntfcCI->SetChannelMode(pckgBuf().iChannelMode);
441 iSbcEncoderIntfcCI->SetNumOfSubbands(pckgBuf().iNumOfSubbands);
442 iSbcEncoderIntfcCI->SetNumOfBlocks(pckgBuf().iNumOfBlocks);
443 iSbcEncoderIntfcCI->SetAllocationMethod(pckgBuf().iAllocationMethod);
444 iSbcEncoderIntfcCI->SetBitpoolSize(pckgBuf().iBitpoolSize);
446 TInt status = iSbcEncoderIntfcCI->ApplyConfig();
447 aMessage.Complete(status);
451 * CSbcEncoderIntfcMsgHdlr::CreateBufFromUintArrayL
452 * Utility function used to create a buffer and fill it with data from the
454 * (other items were commented in a header).
456 void CSbcEncoderIntfcMsgHdlr::CreateBufFromUintArrayL(RArray<TUint>& aArray)
458 delete iDataCopyBuffer;
459 iDataCopyBuffer = NULL;
460 iDataCopyBuffer = CBufFlat::NewL(8);
462 RBufWriteStream stream;
463 stream.Open(*iDataCopyBuffer);
464 CleanupClosePushL(stream);
466 for (TInt i = 0; i < aArray.Count(); i++)
468 stream.WriteUint32L(aArray[i]);
471 CleanupStack::PopAndDestroy(&stream);
475 * CSbcEncoderIntfcMsgHdlr::SendDataBufferToClientL
476 * Sends message with requested configuration data back to the client.
477 * (other items were commented in a header).
479 void CSbcEncoderIntfcMsgHdlr::SendDataBufferToClientL(TMMFMessage& aMessage)
481 if (!iDataCopyBuffer)
483 User::Leave(KErrNotReady);
486 aMessage.WriteDataToClientL(iDataCopyBuffer->Ptr(0));
487 aMessage.Complete(KErrNone);
491 // ========================== OTHER EXPORTED FUNCTIONS =========================