os/mm/devsound/a3fdevsound/src/mmfdevsound/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 <ecom/ecom.h>
sl@0
    20
#include <mm/mmpluginutils.h>
sl@0
    21
sl@0
    22
const TInt KMuxTempBufferSize = 20;
sl@0
    23
sl@0
    24
sl@0
    25
CMMFDevSoundCIMuxUtility* CMMFDevSoundCIMuxUtility::NewL(MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
sl@0
    26
	{
sl@0
    27
	CMMFDevSoundCIMuxUtility* self = new (ELeave) CMMFDevSoundCIMuxUtility(aCustomChannel);
sl@0
    28
	CleanupStack::PushL(self);
sl@0
    29
	self->ConstructL();
sl@0
    30
	CleanupStack::Pop(self);
sl@0
    31
	return self;
sl@0
    32
	}
sl@0
    33
sl@0
    34
void CMMFDevSoundCIMuxUtility::ConstructL()
sl@0
    35
	{
sl@0
    36
	// nothing needed in this implementation
sl@0
    37
	}
sl@0
    38
sl@0
    39
CMMFDevSoundCIMuxUtility::~CMMFDevSoundCIMuxUtility()
sl@0
    40
	{
sl@0
    41
	iAsyncCustomCommandCleanup.ResetAndDestroy();
sl@0
    42
	iAsyncCustomCommandCleanup.Close();	
sl@0
    43
	}
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 used as string for matching the best suitable plug in.
sl@0
    49
	TInt uidAsInteger = aInterfaceId.iUid;
sl@0
    50
	TBuf8<KMuxTempBufferSize> tempBuffer;
sl@0
    51
	tempBuffer.Num(uidAsInteger, EHex);
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
	TA3FCustomInterfaceCommand command;
sl@0
    78
	command.iType = EMMFDevSoundCustomCommandCIOpenSlave;
sl@0
    79
	command.iCommand = 0; // No custom command passed on an OpenSlave
sl@0
    80
	command.iHandle = aInterface.iUid;
sl@0
    81
	TPckgBuf<TA3FCustomInterfaceCommand> commandBuffer(command);
sl@0
    82
	return iCustomChannel->SyncCustomCommand(KUidInterfaceMMFDevSound, commandBuffer, 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
	TA3FCustomInterfaceCommand command;
sl@0
    90
	command.iType = EMMFDevSoundCustomCommandCICloseSlave;
sl@0
    91
	command.iCommand = 0; // No custom command passed on a CloseSlave
sl@0
    92
	command.iHandle = aHandle;
sl@0
    93
	TPckgBuf<TA3FCustomInterfaceCommand> commandBuffer(command);
sl@0
    94
	iCustomChannel->SyncCustomCommand(KUidInterfaceMMFDevSound, commandBuffer, KNullDesC8, NULL);
sl@0
    95
	}
sl@0
    96
sl@0
    97
sl@0
    98
TInt CMMFDevSoundCIMuxUtility::SendSlaveSyncCommand(TInt aHandle, TInt aCommand, const TDesC8& aPackageBuf)
sl@0
    99
	{
sl@0
   100
	TA3FCustomInterfaceCommand command;
sl@0
   101
	command.iType = EMMFDevSoundCustomCommandCISendSlaveSyncCommand;
sl@0
   102
	command.iCommand = aCommand;
sl@0
   103
	command.iHandle = aHandle;
sl@0
   104
	TPckgBuf<TA3FCustomInterfaceCommand> commandBuffer(command);
sl@0
   105
	
sl@0
   106
	return iCustomChannel->SyncCustomCommand(KUidInterfaceMMFDevSound, commandBuffer, aPackageBuf, NULL);
sl@0
   107
	}
sl@0
   108
sl@0
   109
TInt CMMFDevSoundCIMuxUtility::SendSlaveSyncCommandResult(TInt aHandle, TInt aCommand, const TDesC8& aPackageBuf, TDes8& aResultBuf)
sl@0
   110
	{
sl@0
   111
	TA3FCustomInterfaceCommand command;
sl@0
   112
	command.iType = EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult;
sl@0
   113
	command.iCommand = aCommand;
sl@0
   114
	command.iHandle = aHandle;
sl@0
   115
	TPckgBuf<TA3FCustomInterfaceCommand> commandBuffer(command);
sl@0
   116
sl@0
   117
	return iCustomChannel->SyncCustomCommand(KUidInterfaceMMFDevSound, commandBuffer, aPackageBuf, &aResultBuf);
sl@0
   118
	}
sl@0
   119
sl@0
   120
void CMMFDevSoundCIMuxUtility::SendSlaveAsyncCommand(TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf)
sl@0
   121
	{
sl@0
   122
	CAsyncCommandCleanup *ciMuxAsyncCommandCleanup=NULL;
sl@0
   123
	TRAPD(err,ciMuxAsyncCommandCleanup = CAsyncCommandCleanup::NewL(this,iCustomChannel));
sl@0
   124
	TRequestStatus* status= &aStatus;
sl@0
   125
	if(err == KErrNone)
sl@0
   126
		{
sl@0
   127
		err=iAsyncCustomCommandCleanup.Append(ciMuxAsyncCommandCleanup);
sl@0
   128
		if(err == KErrNone)
sl@0
   129
			{
sl@0
   130
			ciMuxAsyncCommandCleanup->AsyncCustomCommand(EMMFDevSoundCustomCommandCISendSlaveAsyncCommand,aComPackage,aStatus,aPackageBuf,NULL);		
sl@0
   131
			}
sl@0
   132
		else
sl@0
   133
			{
sl@0
   134
			User::RequestComplete(status,err);
sl@0
   135
			delete ciMuxAsyncCommandCleanup;
sl@0
   136
			return;			
sl@0
   137
			}	
sl@0
   138
		}
sl@0
   139
	else
sl@0
   140
		{
sl@0
   141
		User::RequestComplete(status,err);
sl@0
   142
		return;	
sl@0
   143
		}
sl@0
   144
	
sl@0
   145
	}
sl@0
   146
	
sl@0
   147
void CMMFDevSoundCIMuxUtility::SendSlaveAsyncCommandResult(TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf, TDes8& aResultBuf)
sl@0
   148
	{
sl@0
   149
	CAsyncCommandCleanup* ciMuxAsyncCommandCleanup=NULL;
sl@0
   150
	TRAPD(err,ciMuxAsyncCommandCleanup = CAsyncCommandCleanup::NewL(this,iCustomChannel));
sl@0
   151
	TRequestStatus* status= &aStatus;
sl@0
   152
	if(err == KErrNone)
sl@0
   153
		{
sl@0
   154
		err=iAsyncCustomCommandCleanup.Append(ciMuxAsyncCommandCleanup);
sl@0
   155
		if(err == KErrNone)
sl@0
   156
			{
sl@0
   157
			ciMuxAsyncCommandCleanup->AsyncCustomCommand(EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult,aComPackage,aStatus,aPackageBuf,&aResultBuf);
sl@0
   158
			}
sl@0
   159
		else
sl@0
   160
			{
sl@0
   161
			User::RequestComplete(status,err);
sl@0
   162
			delete ciMuxAsyncCommandCleanup;
sl@0
   163
			return;			
sl@0
   164
			}	
sl@0
   165
		}
sl@0
   166
	else
sl@0
   167
		{
sl@0
   168
		User::RequestComplete(status,err);
sl@0
   169
		return;
sl@0
   170
		}
sl@0
   171
	}
sl@0
   172
sl@0
   173
CMMFDevSoundCIMuxUtility::CMMFDevSoundCIMuxUtility(MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
sl@0
   174
: iCustomChannel(aCustomChannel)
sl@0
   175
	{
sl@0
   176
	}
sl@0
   177
	
sl@0
   178
void CMMFDevSoundCIMuxUtility::RemoveAsyncCommand(CAsyncCommandCleanup* aAsyncCustomCommandCleanup)
sl@0
   179
	{
sl@0
   180
	TInt index = iAsyncCustomCommandCleanup.Find(aAsyncCustomCommandCleanup);
sl@0
   181
	__ASSERT_DEBUG( index != KErrNotFound,User::Invariant());
sl@0
   182
	if(index > KErrNotFound)
sl@0
   183
		{
sl@0
   184
		iAsyncCustomCommandCleanup.Remove(index);
sl@0
   185
		iAsyncCustomCommandCleanup.Compress();
sl@0
   186
		}
sl@0
   187
	return;
sl@0
   188
	}
sl@0
   189
	
sl@0
   190
CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup* CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::NewL(CMMFDevSoundCIMuxUtility* aMuxUtility,MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
sl@0
   191
	{
sl@0
   192
	CAsyncCommandCleanup *self= new (ELeave) CAsyncCommandCleanup(aMuxUtility,aCustomChannel);
sl@0
   193
	CleanupStack::PushL(self);
sl@0
   194
	self->ConstructL();
sl@0
   195
	CleanupStack::Pop(self);
sl@0
   196
	return self;
sl@0
   197
	}
sl@0
   198
	
sl@0
   199
void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::ConstructL()
sl@0
   200
	{
sl@0
   201
	iCommandBuffer = new (ELeave) TPckgBuf<TA3FCustomInterfaceCommand>;
sl@0
   202
	}
sl@0
   203
	
sl@0
   204
CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::CAsyncCommandCleanup(CMMFDevSoundCIMuxUtility* aMuxUtility,MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
sl@0
   205
:CActive(CActive::EPriorityStandard),iMuxUtility(aMuxUtility),iCustomChannel(aCustomChannel)
sl@0
   206
	{
sl@0
   207
	CActiveScheduler::Add(this);
sl@0
   208
	}
sl@0
   209
	
sl@0
   210
CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::~CAsyncCommandCleanup()
sl@0
   211
	{
sl@0
   212
	delete iCommandBuffer;
sl@0
   213
	Cancel();
sl@0
   214
	}
sl@0
   215
	
sl@0
   216
void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::AsyncCustomCommand(CMMFDevSoundCIMuxUtility::TMMFDevSoundCustomCommand aType,TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf, TDes8* aResultBuf)
sl@0
   217
	{
sl@0
   218
	iClientRequestStatus = &aStatus;
sl@0
   219
	
sl@0
   220
	(*iCommandBuffer)().iType = aType;
sl@0
   221
	(*iCommandBuffer)().iCommand = aComPackage().iCommand;
sl@0
   222
	(*iCommandBuffer)().iHandle = aComPackage().iHandle;
sl@0
   223
	*iClientRequestStatus = KRequestPending;
sl@0
   224
	iCustomChannel->AsyncCustomCommand(KUidInterfaceMMFDevSound,iStatus, *iCommandBuffer, aPackageBuf, aResultBuf);
sl@0
   225
	SetActive();
sl@0
   226
	}
sl@0
   227
	
sl@0
   228
void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::RunL()
sl@0
   229
	{
sl@0
   230
	if(iClientRequestStatus)
sl@0
   231
		{
sl@0
   232
		User::RequestComplete(iClientRequestStatus,iStatus.Int());		
sl@0
   233
		}
sl@0
   234
	iClientRequestStatus = NULL;
sl@0
   235
	iMuxUtility->RemoveAsyncCommand(this);
sl@0
   236
	delete this;
sl@0
   237
	}
sl@0
   238
	
sl@0
   239
void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::DoCancel()
sl@0
   240
	{
sl@0
   241
sl@0
   242
	}