os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundCIDeMuxUtility.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 "MmfDevSoundCIDeMuxUtility.h"
17 #include <mmf/plugin/mmfdevsoundcustominterface.hrh>
18 #include <mmf/server/mmfdevsoundcustomcommands.h>
19 #include <ecom/ecom.h>
20 #include <mm/mmpluginutils.h>
23 CMMFDevSoundCIDeMuxUtility* CMMFDevSoundCIDeMuxUtility::NewL(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
25 CMMFDevSoundCIDeMuxUtility* self = new (ELeave) CMMFDevSoundCIDeMuxUtility(aInterface);
26 CleanupStack::PushL(self);
28 CleanupStack::Pop(self);
32 void CMMFDevSoundCIDeMuxUtility::ConstructL()
34 // nothing to do in this plugin
37 CMMFDevSoundCIDeMuxUtility::~CMMFDevSoundCIDeMuxUtility()
42 const TInt KDeMuxTempBufferSize = 20;
44 // create a custom interface Mux implementation
45 MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFDevSoundCIDeMuxUtility::CreateCustomInterfaceDeMuxL(TUid aInterfaceId)
47 // The Uid of the plugin will be the match string
48 TInt uidAsInteger = aInterfaceId.iUid;
50 TBuf8<KDeMuxTempBufferSize> tempBuffer;
51 tempBuffer.Num(uidAsInteger, EHex); // has value
52 TUid interfaceUid = {KUidDevSoundCustomInterfaceDeMux};
55 MMMFDevSoundCustomInterfaceDeMuxPlugin* self =
56 static_cast<MMMFDevSoundCustomInterfaceDeMuxPlugin*>
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 // this will leave if the command is not a supported custom interface command
72 // the integer being returned is not an error code per-se it is the return code
73 // from the message being handled and so it makes sense here to have the function
74 // returning an integer but also able to leave if there is a problem
75 TInt CMMFDevSoundCIDeMuxUtility::ProcessCustomInterfaceCommandL(const RMmfIpcMessage& aMessage)
77 // get command manually - this is quicker than extracting all info
78 // plus we don't know whether this is async or sync
80 command = aMessage.Int0();
82 TInt retVal = KErrNotFound;
86 case EMMFDevSoundCustomCommandCIOpenSlave:
88 // get a local copy of descriptor
89 HBufC8* tempBuf = HBufC8::NewL(User::LeaveIfError(InputDesLength(aMessage)));
90 CleanupStack::PushL(tempBuf);
91 TPtr8 tempPtr(tempBuf->Des());
92 ReadFromInputDesL(aMessage, &tempPtr);
94 // fetch the interface Uid
95 TPckgBuf<TUid> idBuffer;
96 aMessage.ReadL(1, idBuffer);
98 retVal = iInterface->DoOpenSlaveL(idBuffer(), tempPtr);
99 CleanupStack::PopAndDestroy(tempBuf);
102 case EMMFDevSoundCustomCommandCICloseSlave:
104 // handle is at offset 1
105 TPckgBuf<TInt> handleBuffer;
106 aMessage.ReadL(1, handleBuffer);
107 iInterface->DoCloseSlaveL(handleBuffer());
108 retVal = KErrNone; // no return from CloseSlave
111 case EMMFDevSoundCustomCommandCISendSlaveSyncCommand:
113 retVal = iInterface->DoSendSlaveSyncCommandL(aMessage);
116 case EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult:
118 retVal = iInterface->DoSendSlaveSyncCommandResultL(aMessage);
121 case EMMFDevSoundCustomCommandCISendSlaveAsyncCommand:
123 iInterface->DoSendSlaveAsyncCommandL(aMessage);
124 retVal = KErrNone; // no return from async
127 case EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult:
129 iInterface->DoSendSlaveAsyncCommandResultL(aMessage);
130 retVal = KErrNone; // no return from async
141 // at the moment these two functions are the same but this may change on different platforms
142 // so separate sync and async message data functions have been defined
143 void CMMFDevSoundCIDeMuxUtility::GetSyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
145 // data is stored as commandUID, (command, handle), inbuf, outbuf
146 TPckgBuf<TMMFDevSoundCustomInterfaceCommand> comBuffer;
147 aMessage.ReadL(1, comBuffer);
149 // get command and handle
150 aData.iCommand = comBuffer().iCommand;
151 aData.iHandle = comBuffer().iHandle;
154 void CMMFDevSoundCIDeMuxUtility::GetAsyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
156 // data is stored as commandUID, (command, handle), inbuf, outbuf,status
157 TPckgBuf<TMMFDevSoundCustomInterfaceCommand> comBuffer;
158 aMessage.ReadL(1, comBuffer);
160 // get command and handle
161 aData.iCommand = comBuffer().iCommand;
162 aData.iHandle = comBuffer().iHandle;
166 TInt CMMFDevSoundCIDeMuxUtility::InputDesLength(const RMmfIpcMessage& aMessage)
168 // input descriptor is at offset 2
169 TInt len = aMessage.GetDesLength(2);
173 void CMMFDevSoundCIDeMuxUtility::ReadFromInputDesL(const RMmfIpcMessage& aMessage, TDes8* aBufToFill)
175 // check if the descriptor is large enough
176 TInt len = User::LeaveIfError(InputDesLength(aMessage));
177 if (len > aBufToFill->MaxLength())
179 User::Leave(KErrArgument);
182 // input descriptor is at offset 2
183 aMessage.ReadL(2, *aBufToFill);
186 void CMMFDevSoundCIDeMuxUtility::WriteToOutputDesL(const RMmfIpcMessage& aMessage, TDesC8& aBufToWrite)
188 // output descriptor is at offset 3
189 aMessage.WriteL(3, aBufToWrite);
193 void CMMFDevSoundCIDeMuxUtility::CompleteMessage(const RMmfIpcMessage& aMessage, TInt aError)
195 aMessage.Complete(aError);
198 CMMFDevSoundCIDeMuxUtility::CMMFDevSoundCIDeMuxUtility(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
199 : iInterface(aInterface)