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