os/mm/devsoundextensions/audiorouting/Output/AudioOutputMessageHandler/src/AudioOutputMessageHandler.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsoundextensions/audiorouting/Output/AudioOutputMessageHandler/src/AudioOutputMessageHandler.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,285 @@
1.4 +/*
1.5 +* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: Audio output msg handler implementation
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +// INCLUDE FILES
1.24 +#include "AudioOutput.h"
1.25 +#include "AudioOutputMessageHandler.h"
1.26 +#include "AudioOutputMessageTypes.h"
1.27 +#include "MAudioOutputObserver.h"
1.28 +
1.29 +//reason for defining this secure id here but not using from the mmfbase.hrh is that
1.30 +//lot of macros in mmfbase.hrh collide with base.hrh
1.31 +#define KUidMmfDrmPluginServerDefine 0x10283439
1.32 +
1.33 +// ================= MEMBER FUNCTIONS =======================
1.34 +
1.35 +// C++ default constructor can NOT contain any code, that
1.36 +// might leave.
1.37 +//
1.38 +CAudioOutputMessageHandler::CAudioOutputMessageHandler(CAudioOutput* aAudioOutput,
1.39 + CMMFObjectContainer& aContainer) :
1.40 + CMMFObject(KUidAudioOutput),
1.41 + iContainer(aContainer)
1.42 + {
1.43 + iAudioOutput = aAudioOutput;
1.44 + }
1.45 +
1.46 +// Two-phased constructor.
1.47 +EXPORT_C CAudioOutputMessageHandler* CAudioOutputMessageHandler::NewL(TAny* aCustomInterface,
1.48 + CMMFObjectContainer& aContainer)
1.49 + {
1.50 + CAudioOutput* audioOutput = (CAudioOutput*)aCustomInterface;
1.51 + CAudioOutputMessageHandler* self = new (ELeave) CAudioOutputMessageHandler(audioOutput,
1.52 + aContainer);
1.53 +
1.54 + self->ConstructL();
1.55 + return self;
1.56 + }
1.57 +
1.58 +
1.59 +// Destructor
1.60 +CAudioOutputMessageHandler::~CAudioOutputMessageHandler()
1.61 + {
1.62 + delete iAudioOutput;
1.63 + delete iCallbackMessage;
1.64 + }
1.65 +
1.66 +
1.67 +// ---------------------------------------------------------
1.68 +// CAudioOutputMessageHandler::AudioOutputL
1.69 +// ?implementation_description
1.70 +// (other items were commented in a header).
1.71 +// ---------------------------------------------------------
1.72 +//
1.73 +EXPORT_C TUid CAudioOutputMessageHandler::Uid()
1.74 + {
1.75 + return KUidAudioOutput;
1.76 + }
1.77 +
1.78 +// ---------------------------------------------------------
1.79 +// CAudioOutputMessageHandler::SetAudioOutputL
1.80 +// ?implementation_description
1.81 +// (other items were commented in a header).
1.82 +// ---------------------------------------------------------
1.83 +//
1.84 +void CAudioOutputMessageHandler::HandleRequest(TMMFMessage& aMessage)
1.85 + {
1.86 + ASSERT(aMessage.Destination().InterfaceId() == KUidAudioOutput);
1.87 + TRAPD(error,DoHandleRequestL(aMessage));
1.88 + if(error)
1.89 + {
1.90 + aMessage.Complete(error);
1.91 + }
1.92 + }
1.93 +
1.94 +// ---------------------------------------------------------
1.95 +// CAudioOutputMessageHandler::DoHandleRequestL
1.96 +// ?implementation_description
1.97 +// (other items were commented in a header).
1.98 +// ---------------------------------------------------------
1.99 +//
1.100 +void CAudioOutputMessageHandler::DoHandleRequestL(TMMFMessage& aMessage)
1.101 + {
1.102 +
1.103 + switch(aMessage.Function())
1.104 + {
1.105 + case EAofDelete:
1.106 + {
1.107 + DoDeleteL(aMessage);
1.108 + break;
1.109 + }
1.110 + case EAofRegisterObserver:
1.111 + {
1.112 + iCallbackMessage = new (ELeave) TMMFMessage( aMessage );
1.113 + DoRegisterObserverL();
1.114 + break;
1.115 + }
1.116 + case EAofSetAudioOutput:
1.117 + {
1.118 + DoSetAudioOutputL(aMessage);
1.119 + break;
1.120 + }
1.121 + case EAofGetAudioOutput:
1.122 + {
1.123 + DoGetAudioOutputL(aMessage);
1.124 + break;
1.125 + }
1.126 + case EAofSetSecureOutput:
1.127 + {
1.128 + DoSetSecureOutputL(aMessage);
1.129 + break;
1.130 + }
1.131 + case EAofUnregisterObserver:
1.132 + {
1.133 + DoUnregisterObserverL(aMessage);
1.134 + break;
1.135 + }
1.136 + default:
1.137 + {
1.138 + aMessage.Complete(KErrNotSupported);
1.139 + }
1.140 + }
1.141 + }
1.142 +
1.143 +// ---------------------------------------------------------
1.144 +// CAudioOutputMessageHandler::DoDeleteL
1.145 +// ?implementation_description
1.146 +// (other items were commented in a header).
1.147 +// ---------------------------------------------------------
1.148 +//
1.149 +void CAudioOutputMessageHandler::DoDeleteL(TMMFMessage& aMessage)
1.150 + {
1.151 + aMessage.Complete(KErrNone);
1.152 + iContainer.RemoveAndDestroyMMFObject(*this);
1.153 + }
1.154 +
1.155 +// ---------------------------------------------------------
1.156 +// CAudioOutputMessageHandler::DoRegisterObserverL
1.157 +// ?implementation_description
1.158 +// (other items were commented in a header).
1.159 +// ---------------------------------------------------------
1.160 +//
1.161 +void CAudioOutputMessageHandler::DoRegisterObserverL()
1.162 + {
1.163 + iAudioOutput->RegisterObserverL(*this);
1.164 + }
1.165 +
1.166 +// ---------------------------------------------------------
1.167 +// CAudioOutputMessageHandler::DoSetAudioOutputL
1.168 +// ?implementation_description
1.169 +// (other items were commented in a header).
1.170 +// ---------------------------------------------------------
1.171 +//
1.172 +void CAudioOutputMessageHandler::DoSetAudioOutputL(TMMFMessage& aMessage)
1.173 + {
1.174 + TPckgBuf<CAudioOutput::TAudioOutputPreference> outputPckg;
1.175 + aMessage.ReadData1FromClient(outputPckg);
1.176 + CAudioOutput::TAudioOutputPreference output = outputPckg();
1.177 + iAudioOutput->SetAudioOutputL(output);
1.178 + aMessage.Complete(KErrNone);
1.179 + }
1.180 +
1.181 +// ---------------------------------------------------------
1.182 +// CAudioOutputMessageHandler::DoSetSecureOutputL
1.183 +// ?implementation_description
1.184 +// (other items were commented in a header).
1.185 +// ---------------------------------------------------------
1.186 +//
1.187 +void CAudioOutputMessageHandler::DoSetSecureOutputL(TMMFMessage& aMessage)
1.188 + {
1.189 + //Since we allow the creation of CAudioOutput from Custom interface builder.
1.190 + //We have to make sure that this message is blocked in case we are running in Secure DRM process
1.191 + const TSecureId KSecureDRMSID(KUidMmfDrmPluginServerDefine);
1.192 + RThread currentThread;
1.193 + RProcess currentProcess;
1.194 + CleanupClosePushL(currentThread);
1.195 + CleanupClosePushL(currentProcess);
1.196 + User::LeaveIfError(currentThread.Process(currentProcess));
1.197 + TSecureId curProcessSID = currentProcess.SecureId();
1.198 + CleanupStack::PopAndDestroy();//calls currentThread.Close()
1.199 + CleanupStack::PopAndDestroy();//calls currentProcess.Close()
1.200 + if (curProcessSID == KSecureDRMSID)
1.201 + {
1.202 + //since we are in secure DRM process, completing request with KErrPermissionDenied.
1.203 + aMessage.Complete(KErrPermissionDenied);
1.204 + return;
1.205 + }
1.206 + TPckgBuf<TBool> secureOutputPckg;
1.207 + aMessage.ReadData1FromClient(secureOutputPckg);
1.208 + TBool secureOutput = secureOutputPckg();
1.209 + iAudioOutput->SetSecureOutputL(secureOutput);
1.210 + aMessage.Complete(KErrNone);
1.211 + }
1.212 +
1.213 +// ---------------------------------------------------------
1.214 +// CAudioOutputMessageHandler::DoUnregisterObserverL
1.215 +// ?implementation_description
1.216 +// (other items were commented in a header).
1.217 +// ---------------------------------------------------------
1.218 +//
1.219 +void CAudioOutputMessageHandler::DoUnregisterObserverL(TMMFMessage& aMessage)
1.220 + {
1.221 + iAudioOutput->UnregisterObserver(*this);
1.222 + if ( iCallbackMessage )
1.223 + {
1.224 + if ( !iCallbackMessage->IsCompleted() )
1.225 + {
1.226 + iCallbackMessage->Complete(KErrNone);
1.227 + }
1.228 + }
1.229 + aMessage.Complete(KErrNone);
1.230 + delete iCallbackMessage;
1.231 + iCallbackMessage = NULL;
1.232 + }
1.233 +
1.234 +
1.235 +// ---------------------------------------------------------
1.236 +// CAudioOutputMessageHandler::DefaultAudioOutputChanged
1.237 +// ?implementation_description
1.238 +// (other items were commented in a header).
1.239 +// ---------------------------------------------------------
1.240 +//
1.241 +void CAudioOutputMessageHandler::DefaultAudioOutputChanged( CAudioOutput& /*aAudioOutput*/,
1.242 + CAudioOutput::TAudioOutputPreference aNewDefault )
1.243 + {
1.244 + TPckgBuf<CAudioOutput::TAudioOutputPreference> outputPckg(aNewDefault);
1.245 +
1.246 + if ( iCallbackMessage )
1.247 + {
1.248 + if ( !iCallbackMessage->IsCompleted() )
1.249 + {
1.250 + iCallbackMessage->WriteDataToClient( outputPckg );
1.251 + iCallbackMessage->Complete( KErrNone );
1.252 + }
1.253 + }
1.254 + delete iCallbackMessage;
1.255 + iCallbackMessage = NULL;
1.256 + }
1.257 +
1.258 +
1.259 +// -----------------------------------------------------------------------------
1.260 +// CAudioOutputMessageHandler::ConstructL
1.261 +// Symbian 2nd phase constructor can leave.
1.262 +// -----------------------------------------------------------------------------
1.263 +//
1.264 +void CAudioOutputMessageHandler::ConstructL()
1.265 + {
1.266 + }
1.267 +
1.268 +// ---------------------------------------------------------
1.269 +// CAudioOutputMessageHandler::DoSetAudioOutputL
1.270 +// ?implementation_description
1.271 +// (other items were commented in a header).
1.272 +// ---------------------------------------------------------
1.273 +//
1.274 +void CAudioOutputMessageHandler::DoGetAudioOutputL(TMMFMessage& aMessage)
1.275 + {
1.276 +#ifdef _DEBUG
1.277 + RDebug::Print(_L("CAudioOutputMessageHandler::DoGetAudioOutputL"));
1.278 +#endif
1.279 + CAudioOutput::TAudioOutputPreference outPut = iAudioOutput->AudioOutput();
1.280 + TPckgBuf<CAudioOutput::TAudioOutputPreference> outPutPckg(outPut);
1.281 + aMessage.WriteDataToClient(outPutPckg);
1.282 + aMessage.Complete(KErrNone);
1.283 + }
1.284 +// ========================== OTHER EXPORTED FUNCTIONS =========================
1.285 +
1.286 +
1.287 +
1.288 +// End of File