os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundCIDeMuxUtility.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundCIDeMuxUtility.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,202 @@
     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 <mmf/plugin/mmfdevsoundcustominterface.hrh>
    1.21 +#include <mmf/server/mmfdevsoundcustomcommands.h>
    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 +	// get command manually - this is quicker than extracting all info
    1.81 +	// plus we don't know whether this is async or sync
    1.82 +	TInt command;
    1.83 +	command = aMessage.Int0();
    1.84 +	
    1.85 +	TInt retVal = KErrNotFound;
    1.86 +	
    1.87 +	switch (command)
    1.88 +		{
    1.89 +		case EMMFDevSoundCustomCommandCIOpenSlave:
    1.90 +			{
    1.91 +			// get a local copy of descriptor
    1.92 +			HBufC8* tempBuf = HBufC8::NewL(User::LeaveIfError(InputDesLength(aMessage)));
    1.93 +			CleanupStack::PushL(tempBuf);
    1.94 +			TPtr8 tempPtr(tempBuf->Des());
    1.95 +			ReadFromInputDesL(aMessage, &tempPtr);
    1.96 +			
    1.97 +			// fetch the interface Uid
    1.98 +			TPckgBuf<TUid> idBuffer;
    1.99 +			aMessage.ReadL(1, idBuffer);
   1.100 +			
   1.101 +			retVal = iInterface->DoOpenSlaveL(idBuffer(), tempPtr);		
   1.102 +			CleanupStack::PopAndDestroy(tempBuf);
   1.103 +			break;
   1.104 +			}
   1.105 +		case EMMFDevSoundCustomCommandCICloseSlave:
   1.106 +			{
   1.107 +			// handle is at offset 1
   1.108 +			TPckgBuf<TInt> handleBuffer;
   1.109 +			aMessage.ReadL(1, handleBuffer);
   1.110 +			iInterface->DoCloseSlaveL(handleBuffer());
   1.111 +			retVal = KErrNone; // no return from CloseSlave
   1.112 +			break;
   1.113 +			}
   1.114 +		case EMMFDevSoundCustomCommandCISendSlaveSyncCommand:
   1.115 +			{
   1.116 +			retVal = iInterface->DoSendSlaveSyncCommandL(aMessage);
   1.117 +			break;
   1.118 +			}
   1.119 +		case EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult:
   1.120 +			{
   1.121 +			retVal = iInterface->DoSendSlaveSyncCommandResultL(aMessage);
   1.122 +			break;
   1.123 +			}
   1.124 +		case EMMFDevSoundCustomCommandCISendSlaveAsyncCommand:
   1.125 +			{
   1.126 +			iInterface->DoSendSlaveAsyncCommandL(aMessage);
   1.127 +			retVal = KErrNone; // no return from async
   1.128 +			break;
   1.129 +			}
   1.130 +		case EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult:
   1.131 +			{
   1.132 +			iInterface->DoSendSlaveAsyncCommandResultL(aMessage);
   1.133 +			retVal = KErrNone;	// no return from async
   1.134 +			break;
   1.135 +			}
   1.136 +		default:
   1.137 +			User::Leave(retVal);
   1.138 +		}
   1.139 +		
   1.140 +	return retVal;
   1.141 +	}
   1.142 +	
   1.143 +
   1.144 +// at the moment these two functions are the same but this may change on different platforms
   1.145 +// so separate sync and async message data functions have been defined
   1.146 +void CMMFDevSoundCIDeMuxUtility::GetSyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
   1.147 +	{
   1.148 +	// data is stored as commandUID, (command, handle), inbuf, outbuf
   1.149 +	TPckgBuf<TMMFDevSoundCustomInterfaceCommand> comBuffer;
   1.150 +	aMessage.ReadL(1, comBuffer);
   1.151 +	
   1.152 +	// get command and handle
   1.153 +	aData.iCommand = comBuffer().iCommand;
   1.154 +	aData.iHandle = comBuffer().iHandle;
   1.155 +	}
   1.156 +	
   1.157 +void CMMFDevSoundCIDeMuxUtility::GetAsyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
   1.158 +	{
   1.159 +	// data is stored as commandUID, (command, handle), inbuf, outbuf,status 
   1.160 +	TPckgBuf<TMMFDevSoundCustomInterfaceCommand> comBuffer;
   1.161 +	aMessage.ReadL(1, comBuffer);
   1.162 +	
   1.163 +	// get command and handle
   1.164 +	aData.iCommand = comBuffer().iCommand;
   1.165 +	aData.iHandle = comBuffer().iHandle;
   1.166 +	}
   1.167 +
   1.168 +
   1.169 +TInt CMMFDevSoundCIDeMuxUtility::InputDesLength(const RMmfIpcMessage& aMessage)
   1.170 +	{
   1.171 +	// input descriptor is at offset 2
   1.172 +	TInt len = aMessage.GetDesLength(2);	
   1.173 +	return len;
   1.174 +	}
   1.175 +
   1.176 +void CMMFDevSoundCIDeMuxUtility::ReadFromInputDesL(const RMmfIpcMessage& aMessage, TDes8* aBufToFill)
   1.177 +	{
   1.178 +	// check if the descriptor is large enough
   1.179 +	TInt len = User::LeaveIfError(InputDesLength(aMessage));
   1.180 +	if (len > aBufToFill->MaxLength())
   1.181 +		{
   1.182 +		User::Leave(KErrArgument);
   1.183 +		}
   1.184 +	
   1.185 +	// input descriptor is at offset 2
   1.186 +	aMessage.ReadL(2, *aBufToFill);
   1.187 +	}
   1.188 +	
   1.189 +void CMMFDevSoundCIDeMuxUtility::WriteToOutputDesL(const RMmfIpcMessage& aMessage, TDesC8& aBufToWrite)
   1.190 +	{
   1.191 +	// output descriptor is at offset 3
   1.192 +	aMessage.WriteL(3, aBufToWrite);
   1.193 +	}
   1.194 +
   1.195 +	
   1.196 +void CMMFDevSoundCIDeMuxUtility::CompleteMessage(const RMmfIpcMessage& aMessage, TInt aError)
   1.197 +	{
   1.198 +	aMessage.Complete(aError);
   1.199 +	}
   1.200 +
   1.201 +CMMFDevSoundCIDeMuxUtility::CMMFDevSoundCIDeMuxUtility(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
   1.202 +: iInterface(aInterface)
   1.203 +	{
   1.204 +	}
   1.205 +