os/mm/devsound/devsoundrefplugin/src/platsec/SoundDevice/MmfDevSoundCIMuxUtility.cpp
First public contribution.
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 <mmf/server/mmfdevsoundcustomcommands.h>
20 #include <ecom/ecom.h>
21 #include <mm/mmpluginutils.h>
24 CMMFDevSoundCIMuxUtility* CMMFDevSoundCIMuxUtility::NewL(MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
26 CMMFDevSoundCIMuxUtility* self = new (ELeave) CMMFDevSoundCIMuxUtility(aCustomChannel);
27 CleanupStack::PushL(self);
29 CleanupStack::Pop(self);
33 void CMMFDevSoundCIMuxUtility::ConstructL()
35 // nothing needed in this implementation
38 CMMFDevSoundCIMuxUtility::~CMMFDevSoundCIMuxUtility()
43 const TInt KMuxTempBufferSize = 20;
45 // create a custom interface Mux implementation
46 MMMFDevSoundCustomInterfaceMuxPlugin* CMMFDevSoundCIMuxUtility::CreateCustomInterfaceMuxL(TUid aInterfaceId)
48 // The Uid of the plugin will be the match string
49 TInt uidAsInteger = aInterfaceId.iUid;
50 TBuf8<KMuxTempBufferSize> tempBuffer;
51 tempBuffer.Num(uidAsInteger, EHex); // has value
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 // open packet = command, interface, inBuff
78 TUid commandId(KNullUid);
79 commandId.iUid = EMMFDevSoundCustomCommandCIOpenSlave;
80 TPckgBuf<TUid> idBuffer(aInterface);
82 return iCustomChannel->SyncCustomCommand(commandId, idBuffer, 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 TUid commandId(KNullUid);
90 commandId.iUid = EMMFDevSoundCustomCommandCICloseSlave;
91 TPckgBuf<TInt> handleBuffer(aHandle);
93 iCustomChannel->SyncCustomCommand(commandId, handleBuffer, KNullDesC8, NULL);
97 TInt CMMFDevSoundCIMuxUtility::SendSlaveSyncCommand(TInt aHandle, TInt aCommand, const TDesC8& aPackageBuf)
99 TUid commandId(KNullUid);
100 commandId.iUid = EMMFDevSoundCustomCommandCISendSlaveSyncCommand;
102 TMMFDevSoundCustomInterfaceCommand commandPair;
103 commandPair.iCommand = aCommand;
104 commandPair.iHandle = aHandle;
105 TPckgBuf<TMMFDevSoundCustomInterfaceCommand> comBuffer(commandPair);
107 return iCustomChannel->SyncCustomCommand(commandId, comBuffer, aPackageBuf, NULL);
110 TInt CMMFDevSoundCIMuxUtility::SendSlaveSyncCommandResult(TInt aHandle, TInt aCommand, const TDesC8& aPackageBuf, TDes8& aResultBuf)
112 TUid commandId(KNullUid);
113 commandId.iUid = EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult;
115 TMMFDevSoundCustomInterfaceCommand commandPair;
116 commandPair.iCommand = aCommand;
117 commandPair.iHandle = aHandle;
118 TPckgBuf<TMMFDevSoundCustomInterfaceCommand> comBuffer(commandPair);
120 return iCustomChannel->SyncCustomCommand(commandId, comBuffer, aPackageBuf, &aResultBuf);
123 void CMMFDevSoundCIMuxUtility::SendSlaveAsyncCommand(TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf)
125 TUid commandId(KNullUid);
126 commandId.iUid = EMMFDevSoundCustomCommandCISendSlaveAsyncCommand;
128 // command and handle comes from client with asynchronous commands
130 iCustomChannel->AsyncCustomCommand(commandId, aStatus, aComPackage, aPackageBuf, NULL);
133 void CMMFDevSoundCIMuxUtility::SendSlaveAsyncCommandResult(TMMFDevSoundCustomInterfaceCommandPackage& aComPackage, TRequestStatus& aStatus, const TDesC8& aPackageBuf, TDes8& aResultBuf)
135 TUid commandId(KNullUid);
136 commandId.iUid = EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult;
138 // command and handle comes from client with asynchronous commands
140 iCustomChannel->AsyncCustomCommand(commandId, aStatus, aComPackage, aPackageBuf, &aResultBuf);
143 CMMFDevSoundCIMuxUtility::CMMFDevSoundCIMuxUtility(MMMFDevSoundCustomInterfaceChannel* aCustomChannel)
144 : iCustomChannel(aCustomChannel)