os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundCIDeMuxUtility.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "MmfDevSoundCIDeMuxUtility.h"
sl@0
    17
#include <mmf/plugin/mmfdevsoundcustominterface.hrh>
sl@0
    18
#include <mmf/server/mmfdevsoundcustomcommands.h>
sl@0
    19
#include <ecom/ecom.h>
sl@0
    20
#include <mm/mmpluginutils.h>
sl@0
    21
sl@0
    22
sl@0
    23
CMMFDevSoundCIDeMuxUtility* CMMFDevSoundCIDeMuxUtility::NewL(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
sl@0
    24
	{
sl@0
    25
	CMMFDevSoundCIDeMuxUtility* self = new (ELeave) CMMFDevSoundCIDeMuxUtility(aInterface);
sl@0
    26
	CleanupStack::PushL(self);
sl@0
    27
	self->ConstructL();
sl@0
    28
	CleanupStack::Pop(self);
sl@0
    29
	return self;
sl@0
    30
	}
sl@0
    31
sl@0
    32
void CMMFDevSoundCIDeMuxUtility::ConstructL()
sl@0
    33
	{
sl@0
    34
	// nothing to do in this plugin
sl@0
    35
	}
sl@0
    36
sl@0
    37
CMMFDevSoundCIDeMuxUtility::~CMMFDevSoundCIDeMuxUtility()
sl@0
    38
	{
sl@0
    39
sl@0
    40
	}
sl@0
    41
sl@0
    42
const TInt KDeMuxTempBufferSize = 20;
sl@0
    43
sl@0
    44
// create a custom interface Mux implementation
sl@0
    45
MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFDevSoundCIDeMuxUtility::CreateCustomInterfaceDeMuxL(TUid aInterfaceId)
sl@0
    46
	{
sl@0
    47
	// The Uid of the plugin will be the match string
sl@0
    48
	TInt uidAsInteger = aInterfaceId.iUid;
sl@0
    49
sl@0
    50
	TBuf8<KDeMuxTempBufferSize> tempBuffer;
sl@0
    51
	tempBuffer.Num(uidAsInteger, EHex); // has value
sl@0
    52
	TUid interfaceUid = {KUidDevSoundCustomInterfaceDeMux};
sl@0
    53
	
sl@0
    54
	TUid destructorKey;
sl@0
    55
	MMMFDevSoundCustomInterfaceDeMuxPlugin* self = 
sl@0
    56
		static_cast<MMMFDevSoundCustomInterfaceDeMuxPlugin*>
sl@0
    57
		(MmPluginUtils::CreateImplementationL(interfaceUid, destructorKey, tempBuffer, KRomOnlyResolverUid));
sl@0
    58
sl@0
    59
	// pass the destructor key so class can destroy itself
sl@0
    60
	self->PassDestructorKey(destructorKey);
sl@0
    61
	CleanupReleasePushL(*self);
sl@0
    62
sl@0
    63
	// attempt to construct the plugin
sl@0
    64
	self->CompleteConstructL(this);
sl@0
    65
	CleanupStack::Pop();	// self
sl@0
    66
	
sl@0
    67
	return self;
sl@0
    68
	}
sl@0
    69
sl@0
    70
	
sl@0
    71
// this will leave if the command is not a supported custom interface command
sl@0
    72
// the integer being returned is not an error code per-se it is the return code
sl@0
    73
// from the message being handled and so it makes sense here to have the function
sl@0
    74
// returning an integer but also able to leave if there is a problem
sl@0
    75
TInt CMMFDevSoundCIDeMuxUtility::ProcessCustomInterfaceCommandL(const RMmfIpcMessage& aMessage)
sl@0
    76
	{
sl@0
    77
	// get command manually - this is quicker than extracting all info
sl@0
    78
	// plus we don't know whether this is async or sync
sl@0
    79
	TInt command;
sl@0
    80
	command = aMessage.Int0();
sl@0
    81
	
sl@0
    82
	TInt retVal = KErrNotFound;
sl@0
    83
	
sl@0
    84
	switch (command)
sl@0
    85
		{
sl@0
    86
		case EMMFDevSoundCustomCommandCIOpenSlave:
sl@0
    87
			{
sl@0
    88
			// get a local copy of descriptor
sl@0
    89
			HBufC8* tempBuf = HBufC8::NewL(User::LeaveIfError(InputDesLength(aMessage)));
sl@0
    90
			CleanupStack::PushL(tempBuf);
sl@0
    91
			TPtr8 tempPtr(tempBuf->Des());
sl@0
    92
			ReadFromInputDesL(aMessage, &tempPtr);
sl@0
    93
			
sl@0
    94
			// fetch the interface Uid
sl@0
    95
			TPckgBuf<TUid> idBuffer;
sl@0
    96
			aMessage.ReadL(1, idBuffer);
sl@0
    97
			
sl@0
    98
			retVal = iInterface->DoOpenSlaveL(idBuffer(), tempPtr);		
sl@0
    99
			CleanupStack::PopAndDestroy(tempBuf);
sl@0
   100
			break;
sl@0
   101
			}
sl@0
   102
		case EMMFDevSoundCustomCommandCICloseSlave:
sl@0
   103
			{
sl@0
   104
			// handle is at offset 1
sl@0
   105
			TPckgBuf<TInt> handleBuffer;
sl@0
   106
			aMessage.ReadL(1, handleBuffer);
sl@0
   107
			iInterface->DoCloseSlaveL(handleBuffer());
sl@0
   108
			retVal = KErrNone; // no return from CloseSlave
sl@0
   109
			break;
sl@0
   110
			}
sl@0
   111
		case EMMFDevSoundCustomCommandCISendSlaveSyncCommand:
sl@0
   112
			{
sl@0
   113
			retVal = iInterface->DoSendSlaveSyncCommandL(aMessage);
sl@0
   114
			break;
sl@0
   115
			}
sl@0
   116
		case EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult:
sl@0
   117
			{
sl@0
   118
			retVal = iInterface->DoSendSlaveSyncCommandResultL(aMessage);
sl@0
   119
			break;
sl@0
   120
			}
sl@0
   121
		case EMMFDevSoundCustomCommandCISendSlaveAsyncCommand:
sl@0
   122
			{
sl@0
   123
			iInterface->DoSendSlaveAsyncCommandL(aMessage);
sl@0
   124
			retVal = KErrNone; // no return from async
sl@0
   125
			break;
sl@0
   126
			}
sl@0
   127
		case EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult:
sl@0
   128
			{
sl@0
   129
			iInterface->DoSendSlaveAsyncCommandResultL(aMessage);
sl@0
   130
			retVal = KErrNone;	// no return from async
sl@0
   131
			break;
sl@0
   132
			}
sl@0
   133
		default:
sl@0
   134
			User::Leave(retVal);
sl@0
   135
		}
sl@0
   136
		
sl@0
   137
	return retVal;
sl@0
   138
	}
sl@0
   139
	
sl@0
   140
sl@0
   141
// at the moment these two functions are the same but this may change on different platforms
sl@0
   142
// so separate sync and async message data functions have been defined
sl@0
   143
void CMMFDevSoundCIDeMuxUtility::GetSyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
sl@0
   144
	{
sl@0
   145
	// data is stored as commandUID, (command, handle), inbuf, outbuf
sl@0
   146
	TPckgBuf<TMMFDevSoundCustomInterfaceCommand> comBuffer;
sl@0
   147
	aMessage.ReadL(1, comBuffer);
sl@0
   148
	
sl@0
   149
	// get command and handle
sl@0
   150
	aData.iCommand = comBuffer().iCommand;
sl@0
   151
	aData.iHandle = comBuffer().iHandle;
sl@0
   152
	}
sl@0
   153
	
sl@0
   154
void CMMFDevSoundCIDeMuxUtility::GetAsyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
sl@0
   155
	{
sl@0
   156
	// data is stored as commandUID, (command, handle), inbuf, outbuf,status 
sl@0
   157
	TPckgBuf<TMMFDevSoundCustomInterfaceCommand> comBuffer;
sl@0
   158
	aMessage.ReadL(1, comBuffer);
sl@0
   159
	
sl@0
   160
	// get command and handle
sl@0
   161
	aData.iCommand = comBuffer().iCommand;
sl@0
   162
	aData.iHandle = comBuffer().iHandle;
sl@0
   163
	}
sl@0
   164
sl@0
   165
sl@0
   166
TInt CMMFDevSoundCIDeMuxUtility::InputDesLength(const RMmfIpcMessage& aMessage)
sl@0
   167
	{
sl@0
   168
	// input descriptor is at offset 2
sl@0
   169
	TInt len = aMessage.GetDesLength(2);	
sl@0
   170
	return len;
sl@0
   171
	}
sl@0
   172
sl@0
   173
void CMMFDevSoundCIDeMuxUtility::ReadFromInputDesL(const RMmfIpcMessage& aMessage, TDes8* aBufToFill)
sl@0
   174
	{
sl@0
   175
	// check if the descriptor is large enough
sl@0
   176
	TInt len = User::LeaveIfError(InputDesLength(aMessage));
sl@0
   177
	if (len > aBufToFill->MaxLength())
sl@0
   178
		{
sl@0
   179
		User::Leave(KErrArgument);
sl@0
   180
		}
sl@0
   181
	
sl@0
   182
	// input descriptor is at offset 2
sl@0
   183
	aMessage.ReadL(2, *aBufToFill);
sl@0
   184
	}
sl@0
   185
	
sl@0
   186
void CMMFDevSoundCIDeMuxUtility::WriteToOutputDesL(const RMmfIpcMessage& aMessage, TDesC8& aBufToWrite)
sl@0
   187
	{
sl@0
   188
	// output descriptor is at offset 3
sl@0
   189
	aMessage.WriteL(3, aBufToWrite);
sl@0
   190
	}
sl@0
   191
sl@0
   192
	
sl@0
   193
void CMMFDevSoundCIDeMuxUtility::CompleteMessage(const RMmfIpcMessage& aMessage, TInt aError)
sl@0
   194
	{
sl@0
   195
	aMessage.Complete(aError);
sl@0
   196
	}
sl@0
   197
sl@0
   198
CMMFDevSoundCIDeMuxUtility::CMMFDevSoundCIDeMuxUtility(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
sl@0
   199
: iInterface(aInterface)
sl@0
   200
	{
sl@0
   201
	}
sl@0
   202