os/mm/devsound/devsoundrefplugin/src/platsec/SoundDevice/MmfDevSoundCIMuxUtility.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 "MmfDevSoundCIMuxUtility.h"
    17 #include <mmf/plugin/mmfdevsoundcustominterface.hrh>
    18 #include <mmf/server/mmfdevsoundcustominterface.h>
    19 #include <mmf/server/mmfdevsoundcustomcommands.h>
    20 #include <ecom/ecom.h>
    21 #include <mm/mmpluginutils.h>
    22 
    23 
    24 CMMFDevSoundCIMuxUtility* CMMFDevSoundCIMuxUtility::NewL(MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
    25 	{
    26 	CMMFDevSoundCIMuxUtility* self = new (ELeave) CMMFDevSoundCIMuxUtility(aCustomChannel);
    27 	CleanupStack::PushL(self);
    28 	self->ConstructL();
    29 	CleanupStack::Pop(self);
    30 	return self;
    31 	}
    32 
    33 void CMMFDevSoundCIMuxUtility::ConstructL()
    34 	{
    35 	// nothing needed in this implementation
    36 	}
    37 
    38 CMMFDevSoundCIMuxUtility::~CMMFDevSoundCIMuxUtility()
    39 	{
    40 
    41 	}
    42 
    43 const TInt KMuxTempBufferSize = 20;
    44 
    45 // create a custom interface Mux implementation
    46 MMMFDevSoundCustomInterfaceMuxPlugin* CMMFDevSoundCIMuxUtility::CreateCustomInterfaceMuxL(TUid aInterfaceId)
    47 	{
    48 	// The Uid of the plugin will be the match string
    49 	TInt uidAsInteger = aInterfaceId.iUid;
    50 	TBuf8<KMuxTempBufferSize> tempBuffer;
    51 	tempBuffer.Num(uidAsInteger, EHex); // has value
    52 	TUid interfaceUid = {KUidDevSoundCustomInterfaceMux};
    53 	
    54 	TUid destructorKey;
    55 	MMMFDevSoundCustomInterfaceMuxPlugin* self = 
    56 		static_cast<MMMFDevSoundCustomInterfaceMuxPlugin*>
    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 // from MMMFDevSoundCustomInterfaceMux interface
    72 TInt CMMFDevSoundCIMuxUtility::OpenSlave(TUid aInterface, const TDesC8& aPackageBuf)
    73 	{
    74 	// 1. send openslave custom command to remote side
    75 	// 2. devsoundsession intercepts this custom command
    76 	//    and creates / opens interface
    77 	// open packet = command, interface, inBuff
    78 	TUid commandId(KNullUid);
    79 	commandId.iUid = EMMFDevSoundCustomCommandCIOpenSlave;
    80 	TPckgBuf<TUid> idBuffer(aInterface);
    81 	
    82 	return iCustomChannel->SyncCustomCommand(commandId, idBuffer, aPackageBuf, NULL);
    83 	}
    84 	
    85 void CMMFDevSoundCIMuxUtility::CloseSlave(TInt aHandle)
    86 	{
    87 	// 1. send closeslave custom command to remote side
    88 	// 2. demuxplugin removes its handle for this interface
    89 	TUid commandId(KNullUid);
    90 	commandId.iUid = EMMFDevSoundCustomCommandCICloseSlave;
    91 	TPckgBuf<TInt> handleBuffer(aHandle);
    92 	
    93 	iCustomChannel->SyncCustomCommand(commandId, handleBuffer, KNullDesC8, NULL);
    94 	}
    95 
    96 
    97 TInt CMMFDevSoundCIMuxUtility::SendSlaveSyncCommand(TInt aHandle, TInt aCommand, const TDesC8& aPackageBuf)
    98 	{
    99 	TUid commandId(KNullUid);
   100 	commandId.iUid = EMMFDevSoundCustomCommandCISendSlaveSyncCommand;
   101 		
   102 	TMMFDevSoundCustomInterfaceCommand commandPair;
   103 	commandPair.iCommand = aCommand;
   104 	commandPair.iHandle = aHandle;
   105 	TPckgBuf<TMMFDevSoundCustomInterfaceCommand> comBuffer(commandPair);
   106 	
   107 	return iCustomChannel->SyncCustomCommand(commandId, comBuffer, aPackageBuf, NULL);
   108 	}
   109 
   110 TInt CMMFDevSoundCIMuxUtility::SendSlaveSyncCommandResult(TInt aHandle, TInt aCommand, const TDesC8& aPackageBuf, TDes8& aResultBuf)
   111 	{
   112 	TUid commandId(KNullUid);
   113 	commandId.iUid = EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult;
   114 		
   115 	TMMFDevSoundCustomInterfaceCommand commandPair;
   116 	commandPair.iCommand = aCommand;
   117 	commandPair.iHandle = aHandle;
   118 	TPckgBuf<TMMFDevSoundCustomInterfaceCommand> comBuffer(commandPair);
   119 
   120 	return iCustomChannel->SyncCustomCommand(commandId, comBuffer, aPackageBuf, &aResultBuf);
   121 	}
   122 
   123 void CMMFDevSoundCIMuxUtility::SendSlaveAsyncCommand(TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf)
   124 	{
   125 	TUid commandId(KNullUid);
   126 	commandId.iUid = EMMFDevSoundCustomCommandCISendSlaveAsyncCommand;
   127 	
   128 	// command and handle comes from client with asynchronous commands
   129 		
   130 	iCustomChannel->AsyncCustomCommand(commandId, aStatus, aComPackage, aPackageBuf, NULL);
   131 	}
   132 	
   133 void CMMFDevSoundCIMuxUtility::SendSlaveAsyncCommandResult(TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf, TDes8& aResultBuf)
   134 	{
   135 	TUid commandId(KNullUid);
   136 	commandId.iUid = EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult;
   137 		
   138 	// command and handle comes from client with asynchronous commands
   139 
   140 	iCustomChannel->AsyncCustomCommand(commandId, aStatus, aComPackage, aPackageBuf, &aResultBuf);
   141 	}
   142 
   143 CMMFDevSoundCIMuxUtility::CMMFDevSoundCIMuxUtility(MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
   144 : iCustomChannel(aCustomChannel)
   145 	{
   146 	}
   147