os/mm/devsoundextensions/audiorouting/Output/AudioOutputMessageHandler/src/AudioOutputMessageHandler.cpp
Update contrib.
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Audio output msg handler implementation
21 #include "AudioOutput.h"
22 #include "AudioOutputMessageHandler.h"
23 #include "AudioOutputMessageTypes.h"
24 #include "MAudioOutputObserver.h"
26 //reason for defining this secure id here but not using from the mmfbase.hrh is that
27 //lot of macros in mmfbase.hrh collide with base.hrh
28 #define KUidMmfDrmPluginServerDefine 0x10283439
30 // ================= MEMBER FUNCTIONS =======================
32 // C++ default constructor can NOT contain any code, that
35 CAudioOutputMessageHandler::CAudioOutputMessageHandler(CAudioOutput* aAudioOutput,
36 CMMFObjectContainer& aContainer) :
37 CMMFObject(KUidAudioOutput),
38 iContainer(aContainer)
40 iAudioOutput = aAudioOutput;
43 // Two-phased constructor.
44 EXPORT_C CAudioOutputMessageHandler* CAudioOutputMessageHandler::NewL(TAny* aCustomInterface,
45 CMMFObjectContainer& aContainer)
47 CAudioOutput* audioOutput = (CAudioOutput*)aCustomInterface;
48 CAudioOutputMessageHandler* self = new (ELeave) CAudioOutputMessageHandler(audioOutput,
57 CAudioOutputMessageHandler::~CAudioOutputMessageHandler()
60 delete iCallbackMessage;
64 // ---------------------------------------------------------
65 // CAudioOutputMessageHandler::AudioOutputL
66 // ?implementation_description
67 // (other items were commented in a header).
68 // ---------------------------------------------------------
70 EXPORT_C TUid CAudioOutputMessageHandler::Uid()
72 return KUidAudioOutput;
75 // ---------------------------------------------------------
76 // CAudioOutputMessageHandler::SetAudioOutputL
77 // ?implementation_description
78 // (other items were commented in a header).
79 // ---------------------------------------------------------
81 void CAudioOutputMessageHandler::HandleRequest(TMMFMessage& aMessage)
83 ASSERT(aMessage.Destination().InterfaceId() == KUidAudioOutput);
84 TRAPD(error,DoHandleRequestL(aMessage));
87 aMessage.Complete(error);
91 // ---------------------------------------------------------
92 // CAudioOutputMessageHandler::DoHandleRequestL
93 // ?implementation_description
94 // (other items were commented in a header).
95 // ---------------------------------------------------------
97 void CAudioOutputMessageHandler::DoHandleRequestL(TMMFMessage& aMessage)
100 switch(aMessage.Function())
107 case EAofRegisterObserver:
109 iCallbackMessage = new (ELeave) TMMFMessage( aMessage );
110 DoRegisterObserverL();
113 case EAofSetAudioOutput:
115 DoSetAudioOutputL(aMessage);
118 case EAofGetAudioOutput:
120 DoGetAudioOutputL(aMessage);
123 case EAofSetSecureOutput:
125 DoSetSecureOutputL(aMessage);
128 case EAofUnregisterObserver:
130 DoUnregisterObserverL(aMessage);
135 aMessage.Complete(KErrNotSupported);
140 // ---------------------------------------------------------
141 // CAudioOutputMessageHandler::DoDeleteL
142 // ?implementation_description
143 // (other items were commented in a header).
144 // ---------------------------------------------------------
146 void CAudioOutputMessageHandler::DoDeleteL(TMMFMessage& aMessage)
148 aMessage.Complete(KErrNone);
149 iContainer.RemoveAndDestroyMMFObject(*this);
152 // ---------------------------------------------------------
153 // CAudioOutputMessageHandler::DoRegisterObserverL
154 // ?implementation_description
155 // (other items were commented in a header).
156 // ---------------------------------------------------------
158 void CAudioOutputMessageHandler::DoRegisterObserverL()
160 iAudioOutput->RegisterObserverL(*this);
163 // ---------------------------------------------------------
164 // CAudioOutputMessageHandler::DoSetAudioOutputL
165 // ?implementation_description
166 // (other items were commented in a header).
167 // ---------------------------------------------------------
169 void CAudioOutputMessageHandler::DoSetAudioOutputL(TMMFMessage& aMessage)
171 TPckgBuf<CAudioOutput::TAudioOutputPreference> outputPckg;
172 aMessage.ReadData1FromClient(outputPckg);
173 CAudioOutput::TAudioOutputPreference output = outputPckg();
174 iAudioOutput->SetAudioOutputL(output);
175 aMessage.Complete(KErrNone);
178 // ---------------------------------------------------------
179 // CAudioOutputMessageHandler::DoSetSecureOutputL
180 // ?implementation_description
181 // (other items were commented in a header).
182 // ---------------------------------------------------------
184 void CAudioOutputMessageHandler::DoSetSecureOutputL(TMMFMessage& aMessage)
186 //Since we allow the creation of CAudioOutput from Custom interface builder.
187 //We have to make sure that this message is blocked in case we are running in Secure DRM process
188 const TSecureId KSecureDRMSID(KUidMmfDrmPluginServerDefine);
189 RThread currentThread;
190 RProcess currentProcess;
191 CleanupClosePushL(currentThread);
192 CleanupClosePushL(currentProcess);
193 User::LeaveIfError(currentThread.Process(currentProcess));
194 TSecureId curProcessSID = currentProcess.SecureId();
195 CleanupStack::PopAndDestroy();//calls currentThread.Close()
196 CleanupStack::PopAndDestroy();//calls currentProcess.Close()
197 if (curProcessSID == KSecureDRMSID)
199 //since we are in secure DRM process, completing request with KErrPermissionDenied.
200 aMessage.Complete(KErrPermissionDenied);
203 TPckgBuf<TBool> secureOutputPckg;
204 aMessage.ReadData1FromClient(secureOutputPckg);
205 TBool secureOutput = secureOutputPckg();
206 iAudioOutput->SetSecureOutputL(secureOutput);
207 aMessage.Complete(KErrNone);
210 // ---------------------------------------------------------
211 // CAudioOutputMessageHandler::DoUnregisterObserverL
212 // ?implementation_description
213 // (other items were commented in a header).
214 // ---------------------------------------------------------
216 void CAudioOutputMessageHandler::DoUnregisterObserverL(TMMFMessage& aMessage)
218 iAudioOutput->UnregisterObserver(*this);
219 if ( iCallbackMessage )
221 if ( !iCallbackMessage->IsCompleted() )
223 iCallbackMessage->Complete(KErrNone);
226 aMessage.Complete(KErrNone);
227 delete iCallbackMessage;
228 iCallbackMessage = NULL;
232 // ---------------------------------------------------------
233 // CAudioOutputMessageHandler::DefaultAudioOutputChanged
234 // ?implementation_description
235 // (other items were commented in a header).
236 // ---------------------------------------------------------
238 void CAudioOutputMessageHandler::DefaultAudioOutputChanged( CAudioOutput& /*aAudioOutput*/,
239 CAudioOutput::TAudioOutputPreference aNewDefault )
241 TPckgBuf<CAudioOutput::TAudioOutputPreference> outputPckg(aNewDefault);
243 if ( iCallbackMessage )
245 if ( !iCallbackMessage->IsCompleted() )
247 iCallbackMessage->WriteDataToClient( outputPckg );
248 iCallbackMessage->Complete( KErrNone );
251 delete iCallbackMessage;
252 iCallbackMessage = NULL;
256 // -----------------------------------------------------------------------------
257 // CAudioOutputMessageHandler::ConstructL
258 // Symbian 2nd phase constructor can leave.
259 // -----------------------------------------------------------------------------
261 void CAudioOutputMessageHandler::ConstructL()
265 // ---------------------------------------------------------
266 // CAudioOutputMessageHandler::DoSetAudioOutputL
267 // ?implementation_description
268 // (other items were commented in a header).
269 // ---------------------------------------------------------
271 void CAudioOutputMessageHandler::DoGetAudioOutputL(TMMFMessage& aMessage)
274 RDebug::Print(_L("CAudioOutputMessageHandler::DoGetAudioOutputL"));
276 CAudioOutput::TAudioOutputPreference outPut = iAudioOutput->AudioOutput();
277 TPckgBuf<CAudioOutput::TAudioOutputPreference> outPutPckg(outPut);
278 aMessage.WriteDataToClient(outPutPckg);
279 aMessage.Complete(KErrNone);
281 // ========================== OTHER EXPORTED FUNCTIONS =========================