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