os/mm/devsoundextensions/restrictedaudiooutput/RestrictedAudioOutputMessageHandler/src/RestrictedAudioOutputMessageHandler.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:   This is the implementation of the CRestrictedAudioOutputMessageHandler class.
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
// INCLUDE FILES
sl@0
    21
#include    "RestrictedAudioOutput.h"
sl@0
    22
#include    "RestrictedAudioOutputMessageHandler.h"
sl@0
    23
#include    "RestrictedAudioOutputMessageTypes.h"
sl@0
    24
                
sl@0
    25
sl@0
    26
// ================= MEMBER FUNCTIONS =======================
sl@0
    27
sl@0
    28
// C++ default constructor can NOT contain any code, that
sl@0
    29
// might leave.
sl@0
    30
//
sl@0
    31
CRestrictedAudioOutputMessageHandler::CRestrictedAudioOutputMessageHandler(CRestrictedAudioOutput* aAudioOutput)
sl@0
    32
	 :	CMMFObject(KUidRestrictedAudioOutput)
sl@0
    33
    {
sl@0
    34
    iAudioOutput = aAudioOutput;
sl@0
    35
    }
sl@0
    36
sl@0
    37
// Two-phased constructor.
sl@0
    38
EXPORT_C CRestrictedAudioOutputMessageHandler* CRestrictedAudioOutputMessageHandler::NewL(TAny* aCustomInterface)
sl@0
    39
    {
sl@0
    40
    CRestrictedAudioOutput* audioOutput = (CRestrictedAudioOutput*)aCustomInterface;
sl@0
    41
    CRestrictedAudioOutputMessageHandler* self = new (ELeave) CRestrictedAudioOutputMessageHandler(audioOutput);
sl@0
    42
sl@0
    43
	self->ConstructL();
sl@0
    44
    return self;
sl@0
    45
    }
sl@0
    46
    
sl@0
    47
// -----------------------------------------------------------------------------
sl@0
    48
// CRestrictedAudioOutputMessageHandler::ConstructL
sl@0
    49
// Symbian 2nd phase constructor can leave.
sl@0
    50
// -----------------------------------------------------------------------------
sl@0
    51
//
sl@0
    52
void CRestrictedAudioOutputMessageHandler::ConstructL()
sl@0
    53
	{
sl@0
    54
	}
sl@0
    55
sl@0
    56
    
sl@0
    57
// Destructor
sl@0
    58
CRestrictedAudioOutputMessageHandler::~CRestrictedAudioOutputMessageHandler()
sl@0
    59
	{
sl@0
    60
	delete iAudioOutput;
sl@0
    61
	}
sl@0
    62
sl@0
    63
sl@0
    64
// ---------------------------------------------------------
sl@0
    65
// CRestrictedAudioOutputMessageHandler::AudioOutputL
sl@0
    66
// ?implementation_description
sl@0
    67
// (other items were commented in a header).
sl@0
    68
// ---------------------------------------------------------
sl@0
    69
//
sl@0
    70
EXPORT_C TUid CRestrictedAudioOutputMessageHandler::Uid()
sl@0
    71
	{
sl@0
    72
	return KUidRestrictedAudioOutput;
sl@0
    73
	}
sl@0
    74
sl@0
    75
// ---------------------------------------------------------
sl@0
    76
// CRestrictedAudioOutputMessageHandler::SetAudioOutputL
sl@0
    77
// ?implementation_description
sl@0
    78
// (other items were commented in a header).
sl@0
    79
// ---------------------------------------------------------
sl@0
    80
//
sl@0
    81
void CRestrictedAudioOutputMessageHandler::HandleRequest(TMMFMessage& aMessage)
sl@0
    82
	{
sl@0
    83
	ASSERT(aMessage.Destination().InterfaceId() == KUidRestrictedAudioOutput);
sl@0
    84
	TRAPD(error,DoHandleRequestL(aMessage));
sl@0
    85
	if(error)
sl@0
    86
		{
sl@0
    87
		aMessage.Complete(error);
sl@0
    88
		}
sl@0
    89
	}
sl@0
    90
sl@0
    91
// ---------------------------------------------------------
sl@0
    92
// CRestrictedAudioOutputMessageHandler::DoHandleRequestL
sl@0
    93
// ?implementation_description
sl@0
    94
// (other items were commented in a header).
sl@0
    95
// ---------------------------------------------------------
sl@0
    96
//
sl@0
    97
void CRestrictedAudioOutputMessageHandler::DoHandleRequestL(TMMFMessage& aMessage)
sl@0
    98
	{
sl@0
    99
sl@0
   100
	switch(aMessage.Function())
sl@0
   101
		{
sl@0
   102
		case ERaofCommit:
sl@0
   103
			{
sl@0
   104
			DoCommitL(aMessage);
sl@0
   105
			break;
sl@0
   106
			}			
sl@0
   107
		default:
sl@0
   108
			{
sl@0
   109
			aMessage.Complete(KErrNotSupported);
sl@0
   110
			}
sl@0
   111
		}
sl@0
   112
	}
sl@0
   113
	
sl@0
   114
	
sl@0
   115
// ---------------------------------------------------------
sl@0
   116
// CRestrictedAudioOutputMessageHandler::DoCommitL
sl@0
   117
// ?implementation_description
sl@0
   118
// (other items were commented in a header).
sl@0
   119
// ---------------------------------------------------------
sl@0
   120
//
sl@0
   121
void CRestrictedAudioOutputMessageHandler::DoCommitL(TMMFMessage& aMessage)
sl@0
   122
	{
sl@0
   123
#ifdef _DEBUG 	
sl@0
   124
	RDebug::Print(_L("CRestrictedAudioOutputMessageHandler::DoCommitL"));
sl@0
   125
#endif
sl@0
   126
	
sl@0
   127
	TPckgBuf<TInt> countPckg;
sl@0
   128
	aMessage.ReadData1FromClient(countPckg);
sl@0
   129
	TInt count = countPckg();
sl@0
   130
	
sl@0
   131
#ifdef _DEBUG 	
sl@0
   132
	RDebug::Print(_L("CRestrictedAudioOutputMessageHandler::DoCommitL Count: %d"),count);
sl@0
   133
#endif
sl@0
   134
		
sl@0
   135
	CArrayFixFlat<CRestrictedAudioOutput::TAllowedOutputPreference>* outputArray =
sl@0
   136
		new(ELeave) CArrayFixFlat<CRestrictedAudioOutput::TAllowedOutputPreference>(4);
sl@0
   137
	CleanupStack::PushL(outputArray);
sl@0
   138
	outputArray->ResizeL(count);
sl@0
   139
	
sl@0
   140
	TInt length = count * outputArray->Length();
sl@0
   141
	TPtr8 arrayPtr((TUint8*)&(*outputArray)[0],length, length);
sl@0
   142
	aMessage.ReadData2FromClient(arrayPtr);
sl@0
   143
	
sl@0
   144
	CRestrictedAudioOutput::TAllowedOutputPreference pref;	
sl@0
   145
	
sl@0
   146
	TInt err = iAudioOutput->Reset();
sl@0
   147
	
sl@0
   148
	for (TInt i = 0; i < count; i++)
sl@0
   149
	{
sl@0
   150
		pref = (outputArray->Array())[i];
sl@0
   151
#ifdef _DEBUG 
sl@0
   152
		RDebug::Print(_L("DoCommitL Calling Append for: %d"),pref);
sl@0
   153
#endif		
sl@0
   154
		TInt err = iAudioOutput->AppendAllowedOutput(pref);
sl@0
   155
	}
sl@0
   156
	
sl@0
   157
#ifdef _DEBUG 		
sl@0
   158
	RDebug::Print(_L("CRestrictedAudioOutputMessageHandler::DoCommitL Calling Commit..."));
sl@0
   159
#endif
sl@0
   160
sl@0
   161
	iAudioOutput->Commit();	
sl@0
   162
	CleanupStack::PopAndDestroy();	//outputArray
sl@0
   163
		
sl@0
   164
	aMessage.Complete(KErrNone);
sl@0
   165
	}
sl@0
   166
		
sl@0
   167
sl@0
   168
// End of File