1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/a3fdevsound/src/mmfdevsoundserver/MmfDevSoundCIDeMuxUtility.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,207 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "MmfDevSoundCIDeMuxUtility.h"
1.20 +#include "MmfDevSoundCIMuxUtility.h" // included for command definitions
1.21 +#include <mmf/plugin/mmfdevsoundcustominterface.hrh>
1.22 +#include <ecom/ecom.h>
1.23 +#include <mm/mmpluginutils.h>
1.24 +
1.25 +
1.26 +CMMFDevSoundCIDeMuxUtility* CMMFDevSoundCIDeMuxUtility::NewL(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
1.27 + {
1.28 + CMMFDevSoundCIDeMuxUtility* self = new (ELeave) CMMFDevSoundCIDeMuxUtility(aInterface);
1.29 + CleanupStack::PushL(self);
1.30 + self->ConstructL();
1.31 + CleanupStack::Pop(self);
1.32 + return self;
1.33 + }
1.34 +
1.35 +void CMMFDevSoundCIDeMuxUtility::ConstructL()
1.36 + {
1.37 + // nothing to do in this plugin
1.38 + }
1.39 +
1.40 +CMMFDevSoundCIDeMuxUtility::~CMMFDevSoundCIDeMuxUtility()
1.41 + {
1.42 +
1.43 + }
1.44 +
1.45 +const TInt KDeMuxTempBufferSize = 20;
1.46 +
1.47 +// create a custom interface Mux implementation
1.48 +MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFDevSoundCIDeMuxUtility::CreateCustomInterfaceDeMuxL(TUid aInterfaceId)
1.49 + {
1.50 + // The Uid of the plugin will be the match string
1.51 + TInt uidAsInteger = aInterfaceId.iUid;
1.52 +
1.53 + TBuf8<KDeMuxTempBufferSize> tempBuffer;
1.54 + tempBuffer.Num(uidAsInteger, EHex); // has value
1.55 + TUid interfaceUid = {KUidDevSoundCustomInterfaceDeMux};
1.56 +
1.57 + TUid destructorKey;
1.58 + MMMFDevSoundCustomInterfaceDeMuxPlugin* self =
1.59 + static_cast<MMMFDevSoundCustomInterfaceDeMuxPlugin*>
1.60 + (MmPluginUtils::CreateImplementationL(interfaceUid, destructorKey, tempBuffer, KRomOnlyResolverUid));
1.61 +
1.62 + // pass the destructor key so class can destroy itself
1.63 + self->PassDestructorKey(destructorKey);
1.64 + CleanupReleasePushL(*self);
1.65 +
1.66 + // attempt to construct the plugin
1.67 + self->CompleteConstructL(this);
1.68 + CleanupStack::Pop(); // self
1.69 +
1.70 + return self;
1.71 + }
1.72 +
1.73 +
1.74 +// this will leave if the command is not a supported custom interface command
1.75 +// the integer being returned is not an error code per-se it is the return code
1.76 +// from the message being handled and so it makes sense here to have the function
1.77 +// returning an integer but also able to leave if there is a problem
1.78 +TInt CMMFDevSoundCIDeMuxUtility::ProcessCustomInterfaceCommandL(const RMmfIpcMessage& aMessage)
1.79 + {
1.80 + TPckgBuf<TA3FCustomInterfaceCommand> commandBuf;
1.81 + MmfMessageUtil::ReadL(aMessage, 1, commandBuf);
1.82 + CMMFDevSoundCIMuxUtility::TMMFDevSoundCustomCommand commandType = commandBuf().iType;
1.83 + TInt handle = commandBuf().iHandle;
1.84 + TInt retVal = KErrNotFound;
1.85 +
1.86 + switch (commandType)
1.87 + {
1.88 + case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCIOpenSlave:
1.89 + {
1.90 + // get a local copy of descriptor
1.91 + RBuf8 tempBuf;
1.92 + tempBuf.CleanupClosePushL();
1.93 + TInt len = InputDesLength(aMessage);
1.94 + if (len < 0)
1.95 + {
1.96 + User::Leave(KErrBadDescriptor);
1.97 + }
1.98 + else
1.99 + {
1.100 + tempBuf.CreateL(len);
1.101 + }
1.102 + ReadFromInputDesL(aMessage, &tempBuf);
1.103 +
1.104 + TUid interfaceUid(KNullUid);
1.105 + interfaceUid.iUid = handle;
1.106 + TPckgBuf<TUid> idBuffer(interfaceUid);
1.107 +
1.108 + retVal = iInterface->DoOpenSlaveL(idBuffer(), tempBuf);
1.109 + CleanupStack::PopAndDestroy(&tempBuf);
1.110 + break;
1.111 + }
1.112 + case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCICloseSlave:
1.113 + {
1.114 + TPckgBuf<TInt> handleBuffer(handle);
1.115 + iInterface->DoCloseSlaveL(handleBuffer());
1.116 + retVal = KErrNone; // no return from CloseSlave
1.117 + break;
1.118 + }
1.119 + case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveSyncCommand:
1.120 + {
1.121 + retVal = iInterface->DoSendSlaveSyncCommandL(aMessage);
1.122 + break;
1.123 + }
1.124 + case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult:
1.125 + {
1.126 + retVal = iInterface->DoSendSlaveSyncCommandResultL(aMessage);
1.127 + break;
1.128 + }
1.129 + case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveAsyncCommand:
1.130 + {
1.131 + iInterface->DoSendSlaveAsyncCommandL(aMessage);
1.132 + retVal = KErrNone; // no return from async
1.133 + break;
1.134 + }
1.135 + case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult:
1.136 + {
1.137 + iInterface->DoSendSlaveAsyncCommandResultL(aMessage);
1.138 + retVal = KErrNone; // no return from async
1.139 + break;
1.140 + }
1.141 + default:
1.142 + User::Leave(retVal);
1.143 + }
1.144 +
1.145 + return retVal;
1.146 + }
1.147 +
1.148 +
1.149 +// at the moment these two functions are the same but this may change on different platforms
1.150 +// so separate sync and async message data functions have been defined
1.151 +void CMMFDevSoundCIDeMuxUtility::GetSyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
1.152 + {
1.153 + // data is stored as destination, custom command info, inbuf, outbuf
1.154 + TPckgBuf<TA3FCustomInterfaceCommand> comBuffer;
1.155 + aMessage.ReadL(1, comBuffer);
1.156 +
1.157 + // get command and handle
1.158 + aData.iCommand = comBuffer().iCommand;
1.159 + aData.iHandle = comBuffer().iHandle;
1.160 + }
1.161 +
1.162 +void CMMFDevSoundCIDeMuxUtility::GetAsyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
1.163 + {
1.164 + // data is stored as destination, custom command info, inbuf, outbuf,status
1.165 + TPckgBuf<TA3FCustomInterfaceCommand> comBuffer;
1.166 + aMessage.ReadL(1, comBuffer);
1.167 +
1.168 + // get command and handle
1.169 + aData.iCommand = comBuffer().iCommand;
1.170 + aData.iHandle = comBuffer().iHandle;
1.171 + }
1.172 +
1.173 +
1.174 +TInt CMMFDevSoundCIDeMuxUtility::InputDesLength(const RMmfIpcMessage& aMessage)
1.175 + {
1.176 + // input descriptor is at offset 2
1.177 + TInt len = aMessage.GetDesLength(2);
1.178 + return len;
1.179 + }
1.180 +
1.181 +void CMMFDevSoundCIDeMuxUtility::ReadFromInputDesL(const RMmfIpcMessage& aMessage, TDes8* aBufToFill)
1.182 + {
1.183 + // check if the descriptor is large enough
1.184 + TInt len = InputDesLength(aMessage);
1.185 + if (len > aBufToFill->MaxLength())
1.186 + {
1.187 + User::Leave(KErrArgument);
1.188 + }
1.189 +
1.190 + // input descriptor is at offset 2
1.191 + aMessage.ReadL(2, *aBufToFill);
1.192 + }
1.193 +
1.194 +void CMMFDevSoundCIDeMuxUtility::WriteToOutputDesL(const RMmfIpcMessage& aMessage, TDesC8& aBufToWrite)
1.195 + {
1.196 + // output descriptor is at offset 3
1.197 + aMessage.WriteL(3, aBufToWrite);
1.198 + }
1.199 +
1.200 +
1.201 +void CMMFDevSoundCIDeMuxUtility::CompleteMessage(const RMmfIpcMessage& aMessage, TInt aError)
1.202 + {
1.203 + aMessage.Complete(aError);
1.204 + }
1.205 +
1.206 +CMMFDevSoundCIDeMuxUtility::CMMFDevSoundCIDeMuxUtility(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
1.207 +: iInterface(aInterface)
1.208 + {
1.209 + }
1.210 +