os/mm/devsoundextensions/effects/SrcOrientation/SourceOrientationMessageHandler/src/SourceOrientationMessageHandler.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004 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:   Implementation of the bassboost effect message handler 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 "SourceOrientationMessageHandler.h"
sl@0
    22
#include "SourceOrientationMessageTypes.h"
sl@0
    23
#include <SourceOrientationBase.h>
sl@0
    24
#include "EffectDataQueItem.h"
sl@0
    25
#ifdef _DEBUG
sl@0
    26
#include <e32svr.h>
sl@0
    27
#endif
sl@0
    28
sl@0
    29
// ================= MEMBER FUNCTIONS =======================
sl@0
    30
sl@0
    31
// C++ default constructor can NOT contain any code, that
sl@0
    32
// might leave.
sl@0
    33
//
sl@0
    34
CSourceOrientationMessageHandler::CSourceOrientationMessageHandler(
sl@0
    35
	CSourceOrientation* aSourceOrientation )
sl@0
    36
    :	CMMFObject(KUidSourceOrientationEffect),
sl@0
    37
    	iSourceOrientation(NULL),
sl@0
    38
    	iMessage(NULL),
sl@0
    39
    	iRegistered(EFalse),
sl@0
    40
    	iEffectDataQue(NULL)
sl@0
    41
    {
sl@0
    42
    iSourceOrientation = aSourceOrientation;
sl@0
    43
    }
sl@0
    44
sl@0
    45
sl@0
    46
EXPORT_C CSourceOrientationMessageHandler* CSourceOrientationMessageHandler::NewL(
sl@0
    47
	TAny* aCustomInterface )
sl@0
    48
    {
sl@0
    49
    CSourceOrientation* bassboost = (CSourceOrientation*)aCustomInterface;
sl@0
    50
    CSourceOrientationMessageHandler* self = new (ELeave) CSourceOrientationMessageHandler(bassboost);
sl@0
    51
	self->ConstructL();
sl@0
    52
    return self;
sl@0
    53
    }
sl@0
    54
sl@0
    55
sl@0
    56
// -----------------------------------------------------------------------------
sl@0
    57
// CSourceOrientationMessageHandler::ConstructL
sl@0
    58
// Symbian 2nd phase constructor can leave.
sl@0
    59
// Create and initializes the effect data queue.
sl@0
    60
// -----------------------------------------------------------------------------
sl@0
    61
//
sl@0
    62
void CSourceOrientationMessageHandler::ConstructL()
sl@0
    63
	{
sl@0
    64
	iEffectDataQue = new(ELeave) TSglQue<CEffectDataQueItem>(_FOFF(CEffectDataQueItem, iLink));
sl@0
    65
	}
sl@0
    66
sl@0
    67
sl@0
    68
// -----------------------------------------------------------------------------
sl@0
    69
// CSourceOrientationMessageHandler::~CSourceOrientationMessageHandler
sl@0
    70
// Before going away, unregister with the CI SourceOrientation object.
sl@0
    71
// The observation message must be completed if outstanding.
sl@0
    72
// The effect data queue must be emptied and destroyed.
sl@0
    73
// -----------------------------------------------------------------------------
sl@0
    74
//
sl@0
    75
CSourceOrientationMessageHandler::~CSourceOrientationMessageHandler()
sl@0
    76
	{
sl@0
    77
sl@0
    78
#ifdef _DEBUG
sl@0
    79
    RDebug::Print(_L("CSourceOrientationMessageHandler::~CSourceOrientationMessageHandler"));
sl@0
    80
#endif
sl@0
    81
    if(iSourceOrientation)
sl@0
    82
	    iSourceOrientation->UnRegisterObserver(*this);
sl@0
    83
	iRegistered = EFalse;
sl@0
    84
sl@0
    85
	if(iMessage)
sl@0
    86
		{
sl@0
    87
			if ( !iMessage->IsCompleted() )
sl@0
    88
				{
sl@0
    89
				iMessage->Complete(KErrCancel);
sl@0
    90
				delete iMessage;
sl@0
    91
				}
sl@0
    92
		}
sl@0
    93
sl@0
    94
    if ( iEffectDataQue )
sl@0
    95
        {
sl@0
    96
        CEffectDataQueItem* queItem;
sl@0
    97
        while ( !iEffectDataQue->IsEmpty() )
sl@0
    98
            {
sl@0
    99
            queItem = iEffectDataQue->First();
sl@0
   100
            iEffectDataQue->Remove(*queItem);
sl@0
   101
            delete queItem;
sl@0
   102
            }
sl@0
   103
sl@0
   104
        delete iEffectDataQue;
sl@0
   105
        }
sl@0
   106
sl@0
   107
     delete iSourceOrientation;
sl@0
   108
sl@0
   109
	}
sl@0
   110
sl@0
   111
sl@0
   112
// ---------------------------------------------------------
sl@0
   113
// CSourceOrientationMessageHandler::HandleRequest
sl@0
   114
// (other items were commented in a header).
sl@0
   115
// ---------------------------------------------------------
sl@0
   116
//
sl@0
   117
void CSourceOrientationMessageHandler::HandleRequest(
sl@0
   118
	TMMFMessage& aMessage )
sl@0
   119
	{
sl@0
   120
	ASSERT(aMessage.Destination().InterfaceId() == KUidSourceOrientationEffect);
sl@0
   121
	TRAPD(error,DoHandleRequestL(aMessage));
sl@0
   122
	if ( error )
sl@0
   123
		{
sl@0
   124
		aMessage.Complete(error);
sl@0
   125
		}
sl@0
   126
	}
sl@0
   127
sl@0
   128
// ---------------------------------------------------------
sl@0
   129
// CSourceOrientationMessageHandler::DoHandleRequestL
sl@0
   130
// Dispatches the message to the appropriate handler.
sl@0
   131
// ---------------------------------------------------------
sl@0
   132
//
sl@0
   133
void CSourceOrientationMessageHandler::DoHandleRequestL(
sl@0
   134
	TMMFMessage& aMessage )
sl@0
   135
	{
sl@0
   136
	switch( aMessage.Function() )
sl@0
   137
		{
sl@0
   138
		case ESofInitialize: // Request to initialize the bassboost
sl@0
   139
			{
sl@0
   140
			DoInitializeL(aMessage);
sl@0
   141
			break;
sl@0
   142
			}
sl@0
   143
		case ESofApply: // Request to apply the bassboost settings
sl@0
   144
			{
sl@0
   145
			DoApplyL(aMessage);
sl@0
   146
			break;
sl@0
   147
			}
sl@0
   148
		case ESofObserve: // Observation request
sl@0
   149
			{
sl@0
   150
			DoObserveL(aMessage);
sl@0
   151
			break;
sl@0
   152
			}
sl@0
   153
		default:
sl@0
   154
			{
sl@0
   155
			aMessage.Complete(KErrNotSupported);
sl@0
   156
			}
sl@0
   157
		}
sl@0
   158
	}
sl@0
   159
sl@0
   160
// ---------------------------------------------------------
sl@0
   161
// CSourceOrientationMessageHandler::DoInitializeL
sl@0
   162
// ---------------------------------------------------------
sl@0
   163
//
sl@0
   164
void CSourceOrientationMessageHandler::DoInitializeL(TMMFMessage& aMessage)
sl@0
   165
	{
sl@0
   166
	aMessage.WriteDataToClient(iSourceOrientation->DoEffectData());
sl@0
   167
	aMessage.Complete(KErrNone);
sl@0
   168
	}
sl@0
   169
sl@0
   170
// ---------------------------------------------------------
sl@0
   171
// CSourceOrientationMessageHandler::DoApplyL
sl@0
   172
// Extracts the data from the message. The client bassboost data
sl@0
   173
// is applied to the CI bassboost object.
sl@0
   174
// ---------------------------------------------------------
sl@0
   175
//
sl@0
   176
void CSourceOrientationMessageHandler::DoApplyL(
sl@0
   177
	TMMFMessage& aMessage )
sl@0
   178
	{
sl@0
   179
    TEfOrientationDataPckg orientationPckgFromClient;
sl@0
   180
    aMessage.ReadData1FromClient(orientationPckgFromClient);
sl@0
   181
sl@0
   182
	iSourceOrientation->SetEffectData(orientationPckgFromClient);
sl@0
   183
	iSourceOrientation->ApplyL();
sl@0
   184
	aMessage.Complete(KErrNone);
sl@0
   185
	}
sl@0
   186
sl@0
   187
// ---------------------------------------------------------
sl@0
   188
// CSourceOrientationMessageHandler::DoObserveL
sl@0
   189
// Receives the observation request message and depending
sl@0
   190
// on the status of the effect data queue, the message is
sl@0
   191
// completed immediately or saved for later completion.
sl@0
   192
// ---------------------------------------------------------
sl@0
   193
//
sl@0
   194
void CSourceOrientationMessageHandler::DoObserveL(
sl@0
   195
	TMMFMessage& aMessage )
sl@0
   196
	{
sl@0
   197
sl@0
   198
#ifdef _DEBUG
sl@0
   199
    RDebug::Print(_L("CSourceOrientationMessageHandler::DoObserveL"));
sl@0
   200
#endif
sl@0
   201
sl@0
   202
	if ( !iRegistered ) // Don't register again if we're registered.
sl@0
   203
		{
sl@0
   204
		iSourceOrientation->RegisterObserverL(*this);
sl@0
   205
		iRegistered = ETrue;
sl@0
   206
		}
sl@0
   207
sl@0
   208
	if ( iEffectDataQue->IsEmpty() )
sl@0
   209
		{
sl@0
   210
		// Message is saved and completed when an event occurs
sl@0
   211
		iMessage = new(ELeave) TMMFMessage(aMessage);
sl@0
   212
		}
sl@0
   213
	else
sl@0
   214
		{
sl@0
   215
		TEfOrientationDataPckg dataPckg;
sl@0
   216
		CEffectDataQueItem* item = iEffectDataQue->First();
sl@0
   217
		dataPckg.Copy(item->EffectData());
sl@0
   218
		aMessage.WriteDataToClient(dataPckg);
sl@0
   219
		aMessage.Complete(KErrNone);
sl@0
   220
		iEffectDataQue->Remove(*item);
sl@0
   221
		delete item;
sl@0
   222
		}
sl@0
   223
	}
sl@0
   224
sl@0
   225
// ---------------------------------------------------------
sl@0
   226
// CSourceOrientationMessageHandler::EffectChanged
sl@0
   227
// The CI bassboost object has changed state.
sl@0
   228
// The observation message is completed if no data has been
sl@0
   229
// queued up. Otherwise, the CI bassboost object's data is
sl@0
   230
// packaged and queued.
sl@0
   231
// ---------------------------------------------------------
sl@0
   232
//
sl@0
   233
void CSourceOrientationMessageHandler::EffectChanged(
sl@0
   234
	const CAudioEffect* aAudioEffect,
sl@0
   235
	 TUint8 /*aEvent*/ )
sl@0
   236
	{
sl@0
   237
#ifdef _DEBUG
sl@0
   238
    RDebug::Print(_L("CSourceOrientationMessageHandler::EffectChanged"));
sl@0
   239
#endif
sl@0
   240
sl@0
   241
	if ( iMessage && !iMessage->IsCompleted() && iEffectDataQue->IsEmpty() )
sl@0
   242
		{
sl@0
   243
		iMessage->WriteDataToClient(((CSourceOrientation*)aAudioEffect)->DoEffectData());
sl@0
   244
		iMessage->Complete(KErrNone);
sl@0
   245
		delete iMessage;
sl@0
   246
		iMessage = NULL;
sl@0
   247
		}
sl@0
   248
	else // no message pending and there is no event queued up
sl@0
   249
		{
sl@0
   250
		// Saves the data and complete an observation message next time when
sl@0
   251
		// there is a pending message.
sl@0
   252
		HBufC8* data = NULL;
sl@0
   253
		TRAPD(err1,data = ((CSourceOrientation*)aAudioEffect)->DoEffectData().AllocL());
sl@0
   254
		if(!err1)
sl@0
   255
			{
sl@0
   256
				//CleanupStack::PushL(data);
sl@0
   257
				CEffectDataQueItem* item = NULL;
sl@0
   258
				TRAPD(err2,item = CEffectDataQueItem::NewL(data));
sl@0
   259
				if(!err2)
sl@0
   260
				{
sl@0
   261
					iEffectDataQue->AddLast(*item);
sl@0
   262
				}
sl@0
   263
				else
sl@0
   264
				{
sl@0
   265
					delete data;
sl@0
   266
				}
sl@0
   267
			}
sl@0
   268
		else
sl@0
   269
			{
sl@0
   270
#ifdef _DEBUG
sl@0
   271
				RDebug::Print(_L("CSourceOrientationMessageHandler::EffectChanged Error Allocating Memory %d"),err1);
sl@0
   272
#endif
sl@0
   273
			}
sl@0
   274
		}
sl@0
   275
	}
sl@0
   276
sl@0
   277
sl@0
   278
// ========================== OTHER EXPORTED FUNCTIONS =========================
sl@0
   279
sl@0
   280
sl@0
   281
sl@0
   282
// End of File