Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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>
22 const TInt KMuxTempBufferSize = 20;
25 CMMFDevSoundCIMuxUtility* CMMFDevSoundCIMuxUtility::NewL(MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
27 CMMFDevSoundCIMuxUtility* self = new (ELeave) CMMFDevSoundCIMuxUtility(aCustomChannel);
28 CleanupStack::PushL(self);
30 CleanupStack::Pop(self);
34 void CMMFDevSoundCIMuxUtility::ConstructL()
36 // nothing needed in this implementation
39 CMMFDevSoundCIMuxUtility::~CMMFDevSoundCIMuxUtility()
41 iAsyncCustomCommandCleanup.ResetAndDestroy();
42 iAsyncCustomCommandCleanup.Close();
45 // create a custom interface Mux implementation
46 MMMFDevSoundCustomInterfaceMuxPlugin* CMMFDevSoundCIMuxUtility::CreateCustomInterfaceMuxL(TUid aInterfaceId)
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};
55 MMMFDevSoundCustomInterfaceMuxPlugin* self =
56 static_cast<MMMFDevSoundCustomInterfaceMuxPlugin*>
57 (MmPluginUtils::CreateImplementationL(interfaceUid, destructorKey, tempBuffer, KRomOnlyResolverUid));
59 // pass the destructor key so class can destroy itself
60 self->PassDestructorKey(destructorKey);
61 CleanupReleasePushL(*self);
63 // attempt to construct the plugin
64 self->CompleteConstructL(this);
65 CleanupStack::Pop(); // self
71 // from MMMFDevSoundCustomInterfaceMux interface
72 TInt CMMFDevSoundCIMuxUtility::OpenSlave(TUid aInterface, const TDesC8& aPackageBuf)
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);
85 void CMMFDevSoundCIMuxUtility::CloseSlave(TInt aHandle)
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);
98 TInt CMMFDevSoundCIMuxUtility::SendSlaveSyncCommand(TInt aHandle, TInt aCommand, const TDesC8& aPackageBuf)
100 TA3FCustomInterfaceCommand command;
101 command.iType = EMMFDevSoundCustomCommandCISendSlaveSyncCommand;
102 command.iCommand = aCommand;
103 command.iHandle = aHandle;
104 TPckgBuf<TA3FCustomInterfaceCommand> commandBuffer(command);
106 return iCustomChannel->SyncCustomCommand(KUidInterfaceMMFDevSound, commandBuffer, aPackageBuf, NULL);
109 TInt CMMFDevSoundCIMuxUtility::SendSlaveSyncCommandResult(TInt aHandle, TInt aCommand, const TDesC8& aPackageBuf, TDes8& aResultBuf)
111 TA3FCustomInterfaceCommand command;
112 command.iType = EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult;
113 command.iCommand = aCommand;
114 command.iHandle = aHandle;
115 TPckgBuf<TA3FCustomInterfaceCommand> commandBuffer(command);
117 return iCustomChannel->SyncCustomCommand(KUidInterfaceMMFDevSound, commandBuffer, aPackageBuf, &aResultBuf);
120 void CMMFDevSoundCIMuxUtility::SendSlaveAsyncCommand(TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf)
122 CAsyncCommandCleanup *ciMuxAsyncCommandCleanup=NULL;
123 TRAPD(err,ciMuxAsyncCommandCleanup = CAsyncCommandCleanup::NewL(this,iCustomChannel));
124 TRequestStatus* status= &aStatus;
127 err=iAsyncCustomCommandCleanup.Append(ciMuxAsyncCommandCleanup);
130 ciMuxAsyncCommandCleanup->AsyncCustomCommand(EMMFDevSoundCustomCommandCISendSlaveAsyncCommand,aComPackage,aStatus,aPackageBuf,NULL);
134 User::RequestComplete(status,err);
135 delete ciMuxAsyncCommandCleanup;
141 User::RequestComplete(status,err);
147 void CMMFDevSoundCIMuxUtility::SendSlaveAsyncCommandResult(TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf, TDes8& aResultBuf)
149 CAsyncCommandCleanup* ciMuxAsyncCommandCleanup=NULL;
150 TRAPD(err,ciMuxAsyncCommandCleanup = CAsyncCommandCleanup::NewL(this,iCustomChannel));
151 TRequestStatus* status= &aStatus;
154 err=iAsyncCustomCommandCleanup.Append(ciMuxAsyncCommandCleanup);
157 ciMuxAsyncCommandCleanup->AsyncCustomCommand(EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult,aComPackage,aStatus,aPackageBuf,&aResultBuf);
161 User::RequestComplete(status,err);
162 delete ciMuxAsyncCommandCleanup;
168 User::RequestComplete(status,err);
173 CMMFDevSoundCIMuxUtility::CMMFDevSoundCIMuxUtility(MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
174 : iCustomChannel(aCustomChannel)
178 void CMMFDevSoundCIMuxUtility::RemoveAsyncCommand(CAsyncCommandCleanup* aAsyncCustomCommandCleanup)
180 TInt index = iAsyncCustomCommandCleanup.Find(aAsyncCustomCommandCleanup);
181 __ASSERT_DEBUG( index != KErrNotFound,User::Invariant());
182 if(index > KErrNotFound)
184 iAsyncCustomCommandCleanup.Remove(index);
185 iAsyncCustomCommandCleanup.Compress();
190 CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup* CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::NewL(CMMFDevSoundCIMuxUtility* aMuxUtility,MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
192 CAsyncCommandCleanup *self= new (ELeave) CAsyncCommandCleanup(aMuxUtility,aCustomChannel);
193 CleanupStack::PushL(self);
195 CleanupStack::Pop(self);
199 void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::ConstructL()
201 iCommandBuffer = new (ELeave) TPckgBuf<TA3FCustomInterfaceCommand>;
204 CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::CAsyncCommandCleanup(CMMFDevSoundCIMuxUtility* aMuxUtility,MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
205 :CActive(CActive::EPriorityStandard),iMuxUtility(aMuxUtility),iCustomChannel(aCustomChannel)
207 CActiveScheduler::Add(this);
210 CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::~CAsyncCommandCleanup()
212 delete iCommandBuffer;
216 void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::AsyncCustomCommand(CMMFDevSoundCIMuxUtility::TMMFDevSoundCustomCommand aType,TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf, TDes8* aResultBuf)
218 iClientRequestStatus = &aStatus;
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);
228 void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::RunL()
230 if(iClientRequestStatus)
232 User::RequestComplete(iClientRequestStatus,iStatus.Int());
234 iClientRequestStatus = NULL;
235 iMuxUtility->RemoveAsyncCommand(this);
239 void CMMFDevSoundCIMuxUtility::CAsyncCommandCleanup::DoCancel()