sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "MmfDevSoundCIDeMuxUtility.h"
|
sl@0
|
17 |
#include "MmfDevSoundCIMuxUtility.h" // included for command definitions
|
sl@0
|
18 |
#include <mmf/plugin/mmfdevsoundcustominterface.hrh>
|
sl@0
|
19 |
#include <ecom/ecom.h>
|
sl@0
|
20 |
#include <mm/mmpluginutils.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
CMMFDevSoundCIDeMuxUtility* CMMFDevSoundCIDeMuxUtility::NewL(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
|
sl@0
|
24 |
{
|
sl@0
|
25 |
CMMFDevSoundCIDeMuxUtility* self = new (ELeave) CMMFDevSoundCIDeMuxUtility(aInterface);
|
sl@0
|
26 |
CleanupStack::PushL(self);
|
sl@0
|
27 |
self->ConstructL();
|
sl@0
|
28 |
CleanupStack::Pop(self);
|
sl@0
|
29 |
return self;
|
sl@0
|
30 |
}
|
sl@0
|
31 |
|
sl@0
|
32 |
void CMMFDevSoundCIDeMuxUtility::ConstructL()
|
sl@0
|
33 |
{
|
sl@0
|
34 |
// nothing to do in this plugin
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
CMMFDevSoundCIDeMuxUtility::~CMMFDevSoundCIDeMuxUtility()
|
sl@0
|
38 |
{
|
sl@0
|
39 |
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
const TInt KDeMuxTempBufferSize = 20;
|
sl@0
|
43 |
|
sl@0
|
44 |
// create a custom interface Mux implementation
|
sl@0
|
45 |
MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFDevSoundCIDeMuxUtility::CreateCustomInterfaceDeMuxL(TUid aInterfaceId)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
// The Uid of the plugin will be the match string
|
sl@0
|
48 |
TInt uidAsInteger = aInterfaceId.iUid;
|
sl@0
|
49 |
|
sl@0
|
50 |
TBuf8<KDeMuxTempBufferSize> tempBuffer;
|
sl@0
|
51 |
tempBuffer.Num(uidAsInteger, EHex); // has value
|
sl@0
|
52 |
TUid interfaceUid = {KUidDevSoundCustomInterfaceDeMux};
|
sl@0
|
53 |
|
sl@0
|
54 |
TUid destructorKey;
|
sl@0
|
55 |
MMMFDevSoundCustomInterfaceDeMuxPlugin* self =
|
sl@0
|
56 |
static_cast<MMMFDevSoundCustomInterfaceDeMuxPlugin*>
|
sl@0
|
57 |
(MmPluginUtils::CreateImplementationL(interfaceUid, destructorKey, tempBuffer, KRomOnlyResolverUid));
|
sl@0
|
58 |
|
sl@0
|
59 |
// pass the destructor key so class can destroy itself
|
sl@0
|
60 |
self->PassDestructorKey(destructorKey);
|
sl@0
|
61 |
CleanupReleasePushL(*self);
|
sl@0
|
62 |
|
sl@0
|
63 |
// attempt to construct the plugin
|
sl@0
|
64 |
self->CompleteConstructL(this);
|
sl@0
|
65 |
CleanupStack::Pop(); // self
|
sl@0
|
66 |
|
sl@0
|
67 |
return self;
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
|
sl@0
|
71 |
// this will leave if the command is not a supported custom interface command
|
sl@0
|
72 |
// the integer being returned is not an error code per-se it is the return code
|
sl@0
|
73 |
// from the message being handled and so it makes sense here to have the function
|
sl@0
|
74 |
// returning an integer but also able to leave if there is a problem
|
sl@0
|
75 |
TInt CMMFDevSoundCIDeMuxUtility::ProcessCustomInterfaceCommandL(const RMmfIpcMessage& aMessage)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
TPckgBuf<TA3FCustomInterfaceCommand> commandBuf;
|
sl@0
|
78 |
MmfMessageUtil::ReadL(aMessage, 1, commandBuf);
|
sl@0
|
79 |
CMMFDevSoundCIMuxUtility::TMMFDevSoundCustomCommand commandType = commandBuf().iType;
|
sl@0
|
80 |
TInt handle = commandBuf().iHandle;
|
sl@0
|
81 |
TInt retVal = KErrNotFound;
|
sl@0
|
82 |
|
sl@0
|
83 |
switch (commandType)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCIOpenSlave:
|
sl@0
|
86 |
{
|
sl@0
|
87 |
// get a local copy of descriptor
|
sl@0
|
88 |
RBuf8 tempBuf;
|
sl@0
|
89 |
tempBuf.CleanupClosePushL();
|
sl@0
|
90 |
TInt len = InputDesLength(aMessage);
|
sl@0
|
91 |
if (len < 0)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
User::Leave(KErrBadDescriptor);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
else
|
sl@0
|
96 |
{
|
sl@0
|
97 |
tempBuf.CreateL(len);
|
sl@0
|
98 |
}
|
sl@0
|
99 |
ReadFromInputDesL(aMessage, &tempBuf);
|
sl@0
|
100 |
|
sl@0
|
101 |
TUid interfaceUid(KNullUid);
|
sl@0
|
102 |
interfaceUid.iUid = handle;
|
sl@0
|
103 |
TPckgBuf<TUid> idBuffer(interfaceUid);
|
sl@0
|
104 |
|
sl@0
|
105 |
retVal = iInterface->DoOpenSlaveL(idBuffer(), tempBuf);
|
sl@0
|
106 |
CleanupStack::PopAndDestroy(&tempBuf);
|
sl@0
|
107 |
break;
|
sl@0
|
108 |
}
|
sl@0
|
109 |
case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCICloseSlave:
|
sl@0
|
110 |
{
|
sl@0
|
111 |
TPckgBuf<TInt> handleBuffer(handle);
|
sl@0
|
112 |
iInterface->DoCloseSlaveL(handleBuffer());
|
sl@0
|
113 |
retVal = KErrNone; // no return from CloseSlave
|
sl@0
|
114 |
break;
|
sl@0
|
115 |
}
|
sl@0
|
116 |
case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveSyncCommand:
|
sl@0
|
117 |
{
|
sl@0
|
118 |
retVal = iInterface->DoSendSlaveSyncCommandL(aMessage);
|
sl@0
|
119 |
break;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveSyncCommandResult:
|
sl@0
|
122 |
{
|
sl@0
|
123 |
retVal = iInterface->DoSendSlaveSyncCommandResultL(aMessage);
|
sl@0
|
124 |
break;
|
sl@0
|
125 |
}
|
sl@0
|
126 |
case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveAsyncCommand:
|
sl@0
|
127 |
{
|
sl@0
|
128 |
iInterface->DoSendSlaveAsyncCommandL(aMessage);
|
sl@0
|
129 |
retVal = KErrNone; // no return from async
|
sl@0
|
130 |
break;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
case CMMFDevSoundCIMuxUtility::EMMFDevSoundCustomCommandCISendSlaveAsyncCommandResult:
|
sl@0
|
133 |
{
|
sl@0
|
134 |
iInterface->DoSendSlaveAsyncCommandResultL(aMessage);
|
sl@0
|
135 |
retVal = KErrNone; // no return from async
|
sl@0
|
136 |
break;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
default:
|
sl@0
|
139 |
User::Leave(retVal);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
return retVal;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
|
sl@0
|
146 |
// at the moment these two functions are the same but this may change on different platforms
|
sl@0
|
147 |
// so separate sync and async message data functions have been defined
|
sl@0
|
148 |
void CMMFDevSoundCIDeMuxUtility::GetSyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
// data is stored as destination, custom command info, inbuf, outbuf
|
sl@0
|
151 |
TPckgBuf<TA3FCustomInterfaceCommand> comBuffer;
|
sl@0
|
152 |
aMessage.ReadL(1, comBuffer);
|
sl@0
|
153 |
|
sl@0
|
154 |
// get command and handle
|
sl@0
|
155 |
aData.iCommand = comBuffer().iCommand;
|
sl@0
|
156 |
aData.iHandle = comBuffer().iHandle;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
void CMMFDevSoundCIDeMuxUtility::GetAsyncMessageDataL(const RMmfIpcMessage& aMessage, TMMFDevSoundCIMessageData& aData)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
// data is stored as destination, custom command info, inbuf, outbuf,status
|
sl@0
|
162 |
TPckgBuf<TA3FCustomInterfaceCommand> comBuffer;
|
sl@0
|
163 |
aMessage.ReadL(1, comBuffer);
|
sl@0
|
164 |
|
sl@0
|
165 |
// get command and handle
|
sl@0
|
166 |
aData.iCommand = comBuffer().iCommand;
|
sl@0
|
167 |
aData.iHandle = comBuffer().iHandle;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
|
sl@0
|
171 |
TInt CMMFDevSoundCIDeMuxUtility::InputDesLength(const RMmfIpcMessage& aMessage)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
// input descriptor is at offset 2
|
sl@0
|
174 |
TInt len = aMessage.GetDesLength(2);
|
sl@0
|
175 |
return len;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
void CMMFDevSoundCIDeMuxUtility::ReadFromInputDesL(const RMmfIpcMessage& aMessage, TDes8* aBufToFill)
|
sl@0
|
179 |
{
|
sl@0
|
180 |
// check if the descriptor is large enough
|
sl@0
|
181 |
TInt len = InputDesLength(aMessage);
|
sl@0
|
182 |
if (len > aBufToFill->MaxLength())
|
sl@0
|
183 |
{
|
sl@0
|
184 |
User::Leave(KErrArgument);
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
// input descriptor is at offset 2
|
sl@0
|
188 |
aMessage.ReadL(2, *aBufToFill);
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
void CMMFDevSoundCIDeMuxUtility::WriteToOutputDesL(const RMmfIpcMessage& aMessage, TDesC8& aBufToWrite)
|
sl@0
|
192 |
{
|
sl@0
|
193 |
// output descriptor is at offset 3
|
sl@0
|
194 |
aMessage.WriteL(3, aBufToWrite);
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
|
sl@0
|
198 |
void CMMFDevSoundCIDeMuxUtility::CompleteMessage(const RMmfIpcMessage& aMessage, TInt aError)
|
sl@0
|
199 |
{
|
sl@0
|
200 |
aMessage.Complete(aError);
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
CMMFDevSoundCIDeMuxUtility::CMMFDevSoundCIDeMuxUtility(MMMFDevSoundCustomInterfaceDeMuxInterface* aInterface)
|
sl@0
|
204 |
: iInterface(aInterface)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|