os/mm/devsoundextensions/audiorouting/Output/AudioOutputMessageHandler/src/AudioOutputMessageHandler.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: Audio output msg handler implementation
    15 *
    16 */
    17 
    18 
    19 
    20 // INCLUDE FILES
    21 #include    "AudioOutput.h"
    22 #include    "AudioOutputMessageHandler.h"
    23 #include    "AudioOutputMessageTypes.h"
    24 #include	"MAudioOutputObserver.h"
    25 
    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
    29 
    30 // ================= MEMBER FUNCTIONS =======================
    31 
    32 // C++ default constructor can NOT contain any code, that
    33 // might leave.
    34 //
    35 CAudioOutputMessageHandler::CAudioOutputMessageHandler(CAudioOutput*        aAudioOutput,
    36                                                        CMMFObjectContainer& aContainer) :
    37 	CMMFObject(KUidAudioOutput),
    38 	iContainer(aContainer)
    39     {
    40     iAudioOutput = aAudioOutput;
    41     }
    42 
    43 // Two-phased constructor.
    44 EXPORT_C CAudioOutputMessageHandler* CAudioOutputMessageHandler::NewL(TAny*                aCustomInterface,
    45                                                              CMMFObjectContainer& aContainer)
    46     {
    47     CAudioOutput* audioOutput = (CAudioOutput*)aCustomInterface;
    48     CAudioOutputMessageHandler* self = new (ELeave) CAudioOutputMessageHandler(audioOutput,
    49                                                                                aContainer);
    50 
    51 	self->ConstructL();
    52     return self;
    53     }
    54 
    55     
    56 // Destructor
    57 CAudioOutputMessageHandler::~CAudioOutputMessageHandler()
    58 	{
    59 	delete iAudioOutput;
    60 	delete iCallbackMessage;
    61 	}
    62 
    63 
    64 // ---------------------------------------------------------
    65 // CAudioOutputMessageHandler::AudioOutputL
    66 // ?implementation_description
    67 // (other items were commented in a header).
    68 // ---------------------------------------------------------
    69 //
    70 EXPORT_C TUid CAudioOutputMessageHandler::Uid()
    71 	{
    72 	return KUidAudioOutput;
    73 	}
    74 
    75 // ---------------------------------------------------------
    76 // CAudioOutputMessageHandler::SetAudioOutputL
    77 // ?implementation_description
    78 // (other items were commented in a header).
    79 // ---------------------------------------------------------
    80 //
    81 void CAudioOutputMessageHandler::HandleRequest(TMMFMessage& aMessage)
    82 	{
    83 	ASSERT(aMessage.Destination().InterfaceId() == KUidAudioOutput);
    84 	TRAPD(error,DoHandleRequestL(aMessage));
    85 	if(error)
    86 		{
    87 		aMessage.Complete(error);
    88 		}
    89 	}
    90 
    91 // ---------------------------------------------------------
    92 // CAudioOutputMessageHandler::DoHandleRequestL
    93 // ?implementation_description
    94 // (other items were commented in a header).
    95 // ---------------------------------------------------------
    96 //
    97 void CAudioOutputMessageHandler::DoHandleRequestL(TMMFMessage& aMessage)
    98 	{
    99 
   100 	switch(aMessage.Function())
   101 		{
   102 		case EAofDelete:
   103 			{
   104 			DoDeleteL(aMessage);
   105 			break;
   106 			}
   107 		case EAofRegisterObserver:
   108 			{
   109 			iCallbackMessage = new (ELeave) TMMFMessage( aMessage );
   110 			DoRegisterObserverL();
   111 			break;
   112 			}
   113 		case EAofSetAudioOutput:
   114 			{
   115 			DoSetAudioOutputL(aMessage);
   116 			break;
   117 			}
   118 		case EAofGetAudioOutput:
   119 			{
   120 			DoGetAudioOutputL(aMessage);
   121 			break;
   122 			}			
   123 		case EAofSetSecureOutput:
   124 			{
   125 			DoSetSecureOutputL(aMessage);
   126 			break;
   127 			}
   128 		case EAofUnregisterObserver:
   129 			{
   130 			DoUnregisterObserverL(aMessage);
   131 			break;
   132 			}
   133 		default:
   134 			{
   135 			aMessage.Complete(KErrNotSupported);
   136 			}
   137 		}
   138 	}
   139 
   140 // ---------------------------------------------------------
   141 // CAudioOutputMessageHandler::DoDeleteL
   142 // ?implementation_description
   143 // (other items were commented in a header).
   144 // ---------------------------------------------------------
   145 //
   146 void CAudioOutputMessageHandler::DoDeleteL(TMMFMessage& aMessage)
   147 	{
   148 	aMessage.Complete(KErrNone);
   149 	iContainer.RemoveAndDestroyMMFObject(*this);
   150 	}
   151 
   152 // ---------------------------------------------------------
   153 // CAudioOutputMessageHandler::DoRegisterObserverL
   154 // ?implementation_description
   155 // (other items were commented in a header).
   156 // ---------------------------------------------------------
   157 //
   158 void CAudioOutputMessageHandler::DoRegisterObserverL()
   159 	{
   160 	iAudioOutput->RegisterObserverL(*this);
   161 	}
   162 
   163 // ---------------------------------------------------------
   164 // CAudioOutputMessageHandler::DoSetAudioOutputL
   165 // ?implementation_description
   166 // (other items were commented in a header).
   167 // ---------------------------------------------------------
   168 //
   169 void CAudioOutputMessageHandler::DoSetAudioOutputL(TMMFMessage& aMessage)
   170 	{
   171 	TPckgBuf<CAudioOutput::TAudioOutputPreference> outputPckg;
   172 	aMessage.ReadData1FromClient(outputPckg);
   173 	CAudioOutput::TAudioOutputPreference output = outputPckg();
   174 	iAudioOutput->SetAudioOutputL(output);
   175 	aMessage.Complete(KErrNone);
   176 	}
   177 
   178 // ---------------------------------------------------------
   179 // CAudioOutputMessageHandler::DoSetSecureOutputL
   180 // ?implementation_description
   181 // (other items were commented in a header).
   182 // ---------------------------------------------------------
   183 //
   184 void CAudioOutputMessageHandler::DoSetSecureOutputL(TMMFMessage& aMessage)
   185 	{
   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)
   198 	    {
   199 	    //since we are in secure DRM process, completing request with KErrPermissionDenied.
   200 	    aMessage.Complete(KErrPermissionDenied);
   201 	    return;
   202 	    }
   203 	TPckgBuf<TBool> secureOutputPckg;
   204 	aMessage.ReadData1FromClient(secureOutputPckg);
   205 	TBool secureOutput = secureOutputPckg();
   206 	iAudioOutput->SetSecureOutputL(secureOutput);
   207 	aMessage.Complete(KErrNone);
   208 	}
   209 
   210 // ---------------------------------------------------------
   211 // CAudioOutputMessageHandler::DoUnregisterObserverL
   212 // ?implementation_description
   213 // (other items were commented in a header).
   214 // ---------------------------------------------------------
   215 //
   216 void CAudioOutputMessageHandler::DoUnregisterObserverL(TMMFMessage& aMessage)
   217 	{
   218 	iAudioOutput->UnregisterObserver(*this);
   219 	if ( iCallbackMessage )
   220 		{
   221 		if ( !iCallbackMessage->IsCompleted() )
   222 			{
   223 			iCallbackMessage->Complete(KErrNone);
   224 			}
   225 		}
   226 	aMessage.Complete(KErrNone);
   227 	delete iCallbackMessage;
   228 	iCallbackMessage = NULL;
   229 	}
   230 
   231 
   232 // ---------------------------------------------------------
   233 // CAudioOutputMessageHandler::DefaultAudioOutputChanged
   234 // ?implementation_description
   235 // (other items were commented in a header).
   236 // ---------------------------------------------------------
   237 //
   238 void CAudioOutputMessageHandler::DefaultAudioOutputChanged( CAudioOutput& /*aAudioOutput*/,
   239 		                                CAudioOutput::TAudioOutputPreference aNewDefault )
   240 	{
   241 	TPckgBuf<CAudioOutput::TAudioOutputPreference> outputPckg(aNewDefault);
   242 
   243 	if ( iCallbackMessage )
   244 		{
   245 		if ( !iCallbackMessage->IsCompleted() )
   246 			{
   247 			iCallbackMessage->WriteDataToClient( outputPckg );
   248 			iCallbackMessage->Complete( KErrNone );
   249 			}
   250 		}
   251 	delete iCallbackMessage;
   252 	iCallbackMessage = NULL;
   253 	}
   254 
   255 
   256 // -----------------------------------------------------------------------------
   257 // CAudioOutputMessageHandler::ConstructL
   258 // Symbian 2nd phase constructor can leave.
   259 // -----------------------------------------------------------------------------
   260 //
   261 void CAudioOutputMessageHandler::ConstructL()
   262 	{
   263 	}
   264 
   265 // ---------------------------------------------------------
   266 // CAudioOutputMessageHandler::DoSetAudioOutputL
   267 // ?implementation_description
   268 // (other items were commented in a header).
   269 // ---------------------------------------------------------
   270 //
   271 void CAudioOutputMessageHandler::DoGetAudioOutputL(TMMFMessage& aMessage)
   272 	{
   273 #ifdef _DEBUG
   274     RDebug::Print(_L("CAudioOutputMessageHandler::DoGetAudioOutputL"));
   275 #endif
   276 	CAudioOutput::TAudioOutputPreference outPut = iAudioOutput->AudioOutput();
   277 	TPckgBuf<CAudioOutput::TAudioOutputPreference> outPutPckg(outPut);
   278 	aMessage.WriteDataToClient(outPutPckg);
   279 	aMessage.Complete(KErrNone);
   280 	}
   281 // ========================== OTHER EXPORTED FUNCTIONS =========================
   282 
   283 
   284 
   285 // End of File