1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/a3fdevsound/src/mmfdevsound/MmfDevSoundCIMuxUtility.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,242 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "MmfDevSoundCIMuxUtility.h"
1.20 +#include <mmf/plugin/mmfdevsoundcustominterface.hrh>
1.21 +#include <mmf/server/mmfdevsoundcustominterface.h>
1.22 +#include <ecom/ecom.h>
1.23 +#include <mm/mmpluginutils.h>
1.24 +
1.25 +const TInt KMuxTempBufferSize = 20;
1.26 +
1.27 +
1.28 +CMMFDevSoundCIMuxUtility* CMMFDevSoundCIMuxUtility::NewL(MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
1.29 + {
1.30 + CMMFDevSoundCIMuxUtility* self = new (ELeave) CMMFDevSoundCIMuxUtility(aCustomChannel);
1.31 + CleanupStack::PushL(self);
1.32 + self->ConstructL();
1.33 + CleanupStack::Pop(self);
1.34 + return self;
1.35 + }
1.36 +
1.37 +void CMMFDevSoundCIMuxUtility::ConstructL()
1.38 + {
1.39 + // nothing needed in this implementation
1.40 + }
1.41 +
1.42 +CMMFDevSoundCIMuxUtility::~CMMFDevSoundCIMuxUtility()
1.43 + {
1.44 + iAsyncCustomCommandCleanup.ResetAndDestroy();
1.45 + iAsyncCustomCommandCleanup.Close();
1.46 + }
1.47 +
1.48 +// create a custom interface Mux implementation
1.49 +MMMFDevSoundCustomInterfaceMuxPlugin* CMMFDevSoundCIMuxUtility::CreateCustomInterfaceMuxL(TUid aInterfaceId)
1.50 + {
1.51 + // The Uid of the plugin will be used as string for matching the best suitable plug in.
1.52 + TInt uidAsInteger = aInterfaceId.iUid;
1.53 + TBuf8<KMuxTempBufferSize> tempBuffer;
1.54 + tempBuffer.Num(uidAsInteger, EHex);
1.55 + TUid interfaceUid = {KUidDevSoundCustomInterfaceMux};
1.56 +
1.57 + TUid destructorKey;
1.58 + MMMFDevSoundCustomInterfaceMuxPlugin* self =
1.59 + static_cast<MMMFDevSoundCustomInterfaceMuxPlugin*>
1.60 + (MmPluginUtils::CreateImplementationL(interfaceUid, destructorKey, tempBuffer, KRomOnlyResolverUid));
1.61 +
1.62 + // pass the destructor key so class can destroy itself
1.63 + self->PassDestructorKey(destructorKey);
1.64 + CleanupReleasePushL(*self);
1.65 +
1.66 + // attempt to construct the plugin
1.67 + self->CompleteConstructL(this);
1.68 + CleanupStack::Pop(); // self
1.69 +
1.70 + return self;
1.71 + }
1.72 +
1.73 +
1.74 +// from MMMFDevSoundCustomInterfaceMux interface
1.75 +TInt CMMFDevSoundCIMuxUtility::OpenSlave(TUid aInterface, const TDesC8& aPackageBuf)
1.76 + {
1.77 + // 1. send openslave custom command to remote side
1.78 + // 2. devsoundsession intercepts this custom command
1.79 + // and creates / opens interface
1.80 + TA3FCustomInterfaceCommand command;
1.81 + command.iType = EMMFDevSoundCustomCommandCIOpenSlave;
1.82 + command.iCommand = 0; // No custom command passed on an OpenSlave
1.83 + command.iHandle = aInterface.iUid;
1.84 + TPckgBuf<TA3FCustomInterfaceCommand> commandBuffer(command);
1.85 + return iCustomChannel->SyncCustomCommand(KUidInterfaceMMFDevSound, commandBuffer, aPackageBuf, NULL);
1.86 + }
1.87 +
1.88 +void CMMFDevSoundCIMuxUtility::CloseSlave(TInt aHandle)
1.89 + {
1.90 + // 1. send closeslave custom command to remote side
1.91 + // 2. demuxplugin removes its handle for this interface
1.92 + TA3FCustomInterfaceCommand command;
1.93 + command.iType = EMMFDevSoundCustomCommandCICloseSlave;
1.94 + command.iCommand = 0; // No custom command passed on a CloseSlave
1.95 + command.iHandle = aHandle;
1.96 + TPckgBuf<TA3FCustomInterfaceCommand> commandBuffer(command);
1.97 + iCustomChannel->SyncCustomCommand(KUidInterfaceMMFDevSound, commandBuffer, KNullDesC8, NULL);
1.98 + }
1.99 +
1.100 +
1.101 +TInt CMMFDevSoundCIMuxUtility::SendSlaveSyncCommand(TInt aHandle, TInt aCommand, const TDesC8& aPackageBuf)
1.102 + {
1.103 + TA3FCustomInterfaceCommand command;
1.104 + command.iType = EMMFDevSoundCustomCommandCISendSlaveSyncCommand;
1.105 + command.iCommand = aCommand;
1.106 + command.iHandle = aHandle;
1.107 + TPckgBuf<TA3FCustomInterfaceCommand> commandBuffer(command);
1.108 +
1.109 + return iCustomChannel->SyncCustomCommand(KUidInterfaceMMFDevSound, commandBuffer, aPackageBuf, NULL);
1.110 + }
1.111 +
1.112 +TInt CMMFDevSoundCIMuxUtility::SendSlaveSyncCommandResult(TInt aHandle, TInt aCommand, const TDesC8& aPackageBuf, TDes8& aResultBuf)
1.113 + {
1.114 + TA3FCustomInterfaceCommand command;
1.115 + command.iType = EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult;
1.116 + command.iCommand = aCommand;
1.117 + command.iHandle = aHandle;
1.118 + TPckgBuf<TA3FCustomInterfaceCommand> commandBuffer(command);
1.119 +
1.120 + return iCustomChannel->SyncCustomCommand(KUidInterfaceMMFDevSound, commandBuffer, aPackageBuf, &aResultBuf);
1.121 + }
1.122 +
1.123 +void CMMFDevSoundCIMuxUtility::SendSlaveAsyncCommand(TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf)
1.124 + {
1.125 + CAsyncCommandCleanup *ciMuxAsyncCommandCleanup=NULL;
1.126 + TRAPD(err,ciMuxAsyncCommandCleanup = CAsyncCommandCleanup::NewL(this,iCustomChannel));
1.127 + TRequestStatus* status= &aStatus;
1.128 + if(err == KErrNone)
1.129 + {
1.130 + err=iAsyncCustomCommandCleanup.Append(ciMuxAsyncCommandCleanup);
1.131 + if(err == KErrNone)
1.132 + {
1.133 + ciMuxAsyncCommandCleanup->AsyncCustomCommand(EMMFDevSoundCustomCommandCISendSlaveAsyncCommand,aComPackage,aStatus,aPackageBuf,NULL);
1.134 + }
1.135 + else
1.136 + {
1.137 + User::RequestComplete(status,err);
1.138 + delete ciMuxAsyncCommandCleanup;
1.139 + return;
1.140 + }
1.141 + }
1.142 + else
1.143 + {
1.144 + User::RequestComplete(status,err);
1.145 + return;
1.146 + }
1.147 +
1.148 + }
1.149 +
1.150 +void CMMFDevSoundCIMuxUtility::SendSlaveAsyncCommandResult(TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf, TDes8& aResultBuf)
1.151 + {
1.152 + CAsyncCommandCleanup* ciMuxAsyncCommandCleanup=NULL;
1.153 + TRAPD(err,ciMuxAsyncCommandCleanup = CAsyncCommandCleanup::NewL(this,iCustomChannel));
1.154 + TRequestStatus* status= &aStatus;
1.155 + if(err == KErrNone)
1.156 + {
1.157 + err=iAsyncCustomCommandCleanup.Append(ciMuxAsyncCommandCleanup);
1.158 + if(err == KErrNone)
1.159 + {
1.160 + ciMuxAsyncCommandCleanup->AsyncCustomCommand(EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult,aComPackage,aStatus,aPackageBuf,&aResultBuf);
1.161 + }
1.162 + else
1.163 + {
1.164 + User::RequestComplete(status,err);
1.165 + delete ciMuxAsyncCommandCleanup;
1.166 + return;
1.167 + }
1.168 + }
1.169 + else
1.170 + {
1.171 + User::RequestComplete(status,err);
1.172 + return;
1.173 + }
1.174 + }
1.175 +
1.176 +CMMFDevSoundCIMuxUtility::CMMFDevSoundCIMuxUtility(MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
1.177 +: iCustomChannel(aCustomChannel)
1.178 + {
1.179 + }
1.180 +
1.181 +void CMMFDevSoundCIMuxUtility::RemoveAsyncCommand(CAsyncCommandCleanup* aAsyncCustomCommandCleanup)
1.182 + {
1.183 + TInt index = iAsyncCustomCommandCleanup.Find(aAsyncCustomCommandCleanup);
1.184 + __ASSERT_DEBUG( index != KErrNotFound,User::Invariant());
1.185 + if(index > KErrNotFound)
1.186 + {
1.187 + iAsyncCustomCommandCleanup.Remove(index);
1.188 + iAsyncCustomCommandCleanup.Compress();
1.189 + }
1.190 + return;
1.191 + }
1.192 +
1.193 +CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup* CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::NewL(CMMFDevSoundCIMuxUtility* aMuxUtility,MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
1.194 + {
1.195 + CAsyncCommandCleanup *self= new (ELeave) CAsyncCommandCleanup(aMuxUtility,aCustomChannel);
1.196 + CleanupStack::PushL(self);
1.197 + self->ConstructL();
1.198 + CleanupStack::Pop(self);
1.199 + return self;
1.200 + }
1.201 +
1.202 +void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::ConstructL()
1.203 + {
1.204 + iCommandBuffer = new (ELeave) TPckgBuf<TA3FCustomInterfaceCommand>;
1.205 + }
1.206 +
1.207 +CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::CAsyncCommandCleanup(CMMFDevSoundCIMuxUtility* aMuxUtility,MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
1.208 +:CActive(CActive::EPriorityStandard),iMuxUtility(aMuxUtility),iCustomChannel(aCustomChannel)
1.209 + {
1.210 + CActiveScheduler::Add(this);
1.211 + }
1.212 +
1.213 +CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::~CAsyncCommandCleanup()
1.214 + {
1.215 + delete iCommandBuffer;
1.216 + Cancel();
1.217 + }
1.218 +
1.219 +void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::AsyncCustomCommand(CMMFDevSoundCIMuxUtility::TMMFDevSoundCustomCommand aType,TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf, TDes8* aResultBuf)
1.220 + {
1.221 + iClientRequestStatus = &aStatus;
1.222 +
1.223 + (*iCommandBuffer)().iType = aType;
1.224 + (*iCommandBuffer)().iCommand = aComPackage().iCommand;
1.225 + (*iCommandBuffer)().iHandle = aComPackage().iHandle;
1.226 + *iClientRequestStatus = KRequestPending;
1.227 + iCustomChannel->AsyncCustomCommand(KUidInterfaceMMFDevSound,iStatus, *iCommandBuffer, aPackageBuf, aResultBuf);
1.228 + SetActive();
1.229 + }
1.230 +
1.231 +void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::RunL()
1.232 + {
1.233 + if(iClientRequestStatus)
1.234 + {
1.235 + User::RequestComplete(iClientRequestStatus,iStatus.Int());
1.236 + }
1.237 + iClientRequestStatus = NULL;
1.238 + iMuxUtility->RemoveAsyncCommand(this);
1.239 + delete this;
1.240 + }
1.241 +
1.242 +void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::DoCancel()
1.243 + {
1.244 +
1.245 + }