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