devsound/a3fdevsound/src/mmfdevsoundserver/MmfDevSoundCIDeMuxUtility.cpp
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     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 "MmfDevSoundCIMuxUtility.h" // included for command definitions
       
    18 #include <mmf/plugin/mmfdevsoundcustominterface.hrh>
       
    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 	TPckgBuf<TA3FCustomInterfaceCommand> commandBuf;
       
    78 	MmfMessageUtil::ReadL(aMessage, 1, commandBuf);
       
    79 	CMMFDevSoundCIMuxUtility::TMMFDevSoundCustomCommand commandType = commandBuf().iType;
       
    80 	TInt handle = commandBuf().iHandle;
       
    81 	TInt retVal = KErrNotFound;
       
    82 	
       
    83 	switch (commandType)
       
    84 		{
       
    85 		case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCIOpenSlave:
       
    86 			{
       
    87 			// get a local copy of descriptor
       
    88 			RBuf8 tempBuf;
       
    89 			tempBuf.CleanupClosePushL();
       
    90 			TInt len = InputDesLength(aMessage);
       
    91 			if (len < 0)
       
    92 				{
       
    93 				User::Leave(KErrBadDescriptor);
       
    94 				}
       
    95 			else
       
    96 				{
       
    97 				tempBuf.CreateL(len);
       
    98 				}
       
    99 			ReadFromInputDesL(aMessage, &tempBuf);
       
   100 			
       
   101 			TUid interfaceUid(KNullUid);
       
   102 			interfaceUid.iUid = handle;
       
   103 			TPckgBuf<TUid> idBuffer(interfaceUid);
       
   104 			
       
   105 			retVal = iInterface->DoOpenSlaveL(idBuffer(), tempBuf);		
       
   106 			CleanupStack::PopAndDestroy(&tempBuf);
       
   107 			break;
       
   108 			}
       
   109 		case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCICloseSlave:
       
   110 			{
       
   111 			TPckgBuf<TInt> handleBuffer(handle);
       
   112 			iInterface->DoCloseSlaveL(handleBuffer());
       
   113 			retVal = KErrNone; // no return from CloseSlave
       
   114 			break;
       
   115 			}
       
   116 		case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveSyncCommand:
       
   117 			{
       
   118 			retVal = iInterface->DoSendSlaveSyncCommandL(aMessage);
       
   119 			break;
       
   120 			}
       
   121 		case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult:
       
   122 			{
       
   123 			retVal = iInterface->DoSendSlaveSyncCommandResultL(aMessage);
       
   124 			break;
       
   125 			}
       
   126 		case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveAsyncCommand:
       
   127 			{
       
   128 			iInterface->DoSendSlaveAsyncCommandL(aMessage);
       
   129 			retVal = KErrNone; // no return from async
       
   130 			break;
       
   131 			}
       
   132 		case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult:
       
   133 			{
       
   134 			iInterface->DoSendSlaveAsyncCommandResultL(aMessage);
       
   135 			retVal = KErrNone;	// no return from async
       
   136 			break;
       
   137 			}
       
   138 		default:
       
   139 			User::Leave(retVal);
       
   140 		}
       
   141 		
       
   142 	return retVal;
       
   143 	}
       
   144 	
       
   145 
       
   146 // at the moment these two functions are the same but this may change on different platforms
       
   147 // so separate sync and async message data functions have been defined
       
   148 void CMMFDevSoundCIDeMuxUtility::GetSyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
       
   149 	{
       
   150 	// data is stored as destination, custom command info, inbuf, outbuf
       
   151 	TPckgBuf<TA3FCustomInterfaceCommand> comBuffer;
       
   152 	aMessage.ReadL(1, comBuffer);
       
   153 	
       
   154 	// get command and handle
       
   155 	aData.iCommand = comBuffer().iCommand;
       
   156 	aData.iHandle = comBuffer().iHandle;
       
   157 	}
       
   158 	
       
   159 void CMMFDevSoundCIDeMuxUtility::GetAsyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
       
   160 	{
       
   161 	// data is stored as destination, custom command info, inbuf, outbuf,status 
       
   162 	TPckgBuf<TA3FCustomInterfaceCommand> comBuffer;
       
   163 	aMessage.ReadL(1, comBuffer);
       
   164 	
       
   165 	// get command and handle
       
   166 	aData.iCommand = comBuffer().iCommand;
       
   167 	aData.iHandle = comBuffer().iHandle;
       
   168 	}
       
   169 
       
   170 
       
   171 TInt CMMFDevSoundCIDeMuxUtility::InputDesLength(const RMmfIpcMessage& aMessage)
       
   172 	{
       
   173 	// input descriptor is at offset 2
       
   174 	TInt len = aMessage.GetDesLength(2);	
       
   175 	return len;
       
   176 	}
       
   177 
       
   178 void CMMFDevSoundCIDeMuxUtility::ReadFromInputDesL(const RMmfIpcMessage& aMessage, TDes8* aBufToFill)
       
   179 	{
       
   180 	// check if the descriptor is large enough
       
   181 	TInt len = InputDesLength(aMessage);
       
   182 	if (len > aBufToFill->MaxLength())
       
   183 		{
       
   184 		User::Leave(KErrArgument);
       
   185 		}
       
   186 	
       
   187 	// input descriptor is at offset 2
       
   188 	aMessage.ReadL(2, *aBufToFill);
       
   189 	}
       
   190 	
       
   191 void CMMFDevSoundCIDeMuxUtility::WriteToOutputDesL(const RMmfIpcMessage& aMessage, TDesC8& aBufToWrite)
       
   192 	{
       
   193 	// output descriptor is at offset 3
       
   194 	aMessage.WriteL(3, aBufToWrite);
       
   195 	}
       
   196 
       
   197 	
       
   198 void CMMFDevSoundCIDeMuxUtility::CompleteMessage(const RMmfIpcMessage& aMessage, TInt aError)
       
   199 	{
       
   200 	aMessage.Complete(aError);
       
   201 	}
       
   202 
       
   203 CMMFDevSoundCIDeMuxUtility::CMMFDevSoundCIDeMuxUtility(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
       
   204 : iInterface(aInterface)
       
   205 	{
       
   206 	}
       
   207