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 "MmfDevSoundCIMuxUtility.h" // included for command definitions
18 #include <mmf/plugin/mmfdevsoundcustominterface.hrh>
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 TPckgBuf<TA3FCustomInterfaceCommand> commandBuf;
78 MmfMessageUtil::ReadL(aMessage, 1, commandBuf);
79 CMMFDevSoundCIMuxUtility::TMMFDevSoundCustomCommand commandType = commandBuf().iType;
80 TInt handle = commandBuf().iHandle;
81 TInt retVal = KErrNotFound;
85 case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCIOpenSlave:
87 // get a local copy of descriptor
89 tempBuf.CleanupClosePushL();
90 TInt len = InputDesLength(aMessage);
93 User::Leave(KErrBadDescriptor);
99 ReadFromInputDesL(aMessage, &tempBuf);
101 TUid interfaceUid(KNullUid);
102 interfaceUid.iUid = handle;
103 TPckgBuf<TUid> idBuffer(interfaceUid);
105 retVal = iInterface->DoOpenSlaveL(idBuffer(), tempBuf);
106 CleanupStack::PopAndDestroy(&tempBuf);
109 case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCICloseSlave:
111 TPckgBuf<TInt> handleBuffer(handle);
112 iInterface->DoCloseSlaveL(handleBuffer());
113 retVal = KErrNone; // no return from CloseSlave
116 case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveSyncCommand:
118 retVal = iInterface->DoSendSlaveSyncCommandL(aMessage);
121 case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult:
123 retVal = iInterface->DoSendSlaveSyncCommandResultL(aMessage);
126 case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveAsyncCommand:
128 iInterface->DoSendSlaveAsyncCommandL(aMessage);
129 retVal = KErrNone; // no return from async
132 case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult:
134 iInterface->DoSendSlaveAsyncCommandResultL(aMessage);
135 retVal = KErrNone; // no return from async
146 // at the moment these two functions are the same but this may change on different platforms
147 // so separate sync and async message data functions have been defined
148 void CMMFDevSoundCIDeMuxUtility::GetSyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
150 // data is stored as destination, custom command info, inbuf, outbuf
151 TPckgBuf<TA3FCustomInterfaceCommand> comBuffer;
152 aMessage.ReadL(1, comBuffer);
154 // get command and handle
155 aData.iCommand = comBuffer().iCommand;
156 aData.iHandle = comBuffer().iHandle;
159 void CMMFDevSoundCIDeMuxUtility::GetAsyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
161 // data is stored as destination, custom command info, inbuf, outbuf,status
162 TPckgBuf<TA3FCustomInterfaceCommand> comBuffer;
163 aMessage.ReadL(1, comBuffer);
165 // get command and handle
166 aData.iCommand = comBuffer().iCommand;
167 aData.iHandle = comBuffer().iHandle;
171 TInt CMMFDevSoundCIDeMuxUtility::InputDesLength(const RMmfIpcMessage& aMessage)
173 // input descriptor is at offset 2
174 TInt len = aMessage.GetDesLength(2);
178 void CMMFDevSoundCIDeMuxUtility::ReadFromInputDesL(const RMmfIpcMessage& aMessage, TDes8* aBufToFill)
180 // check if the descriptor is large enough
181 TInt len = InputDesLength(aMessage);
182 if (len > aBufToFill->MaxLength())
184 User::Leave(KErrArgument);
187 // input descriptor is at offset 2
188 aMessage.ReadL(2, *aBufToFill);
191 void CMMFDevSoundCIDeMuxUtility::WriteToOutputDesL(const RMmfIpcMessage& aMessage, TDesC8& aBufToWrite)
193 // output descriptor is at offset 3
194 aMessage.WriteL(3, aBufToWrite);
198 void CMMFDevSoundCIDeMuxUtility::CompleteMessage(const RMmfIpcMessage& aMessage, TInt aError)
200 aMessage.Complete(aError);
203 CMMFDevSoundCIDeMuxUtility::CMMFDevSoundCIDeMuxUtility(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
204 : iInterface(aInterface)