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