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