os/mm/devsoundextensions/effects/RoomLevel/RoomLevelMessageHandler/src/RoomLevelMessageHandler.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsoundextensions/effects/RoomLevel/RoomLevelMessageHandler/src/RoomLevelMessageHandler.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,287 @@
1.4 +/*
1.5 +* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: Implementation of the RoomLevel effect message handler class.
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +// INCLUDE FILES
1.24 +#include "RoomLevelMessageHandler.h"
1.25 +#include "RoomLevelMessageTypes.h"
1.26 +#include <RoomLevelBase.h>
1.27 +#include "EffectDataQueItem.h"
1.28 +#include <RoomLevelBase.h>
1.29 +#ifdef _DEBUG
1.30 +#include <e32svr.h>
1.31 +#endif
1.32 +
1.33 +// ================= MEMBER FUNCTIONS =======================
1.34 +
1.35 +// C++ default constructor can NOT contain any code, that
1.36 +// might leave.
1.37 +//
1.38 +CRoomLevelMessageHandler::CRoomLevelMessageHandler(
1.39 + CRoomLevel* aRoomLevel )
1.40 + : CMMFObject(KUidRoomLevelEffect),
1.41 + iRoomLevel(NULL),
1.42 + iMessage(NULL),
1.43 + iRegistered(EFalse),
1.44 + iEffectDataQue(NULL)
1.45 + {
1.46 + iRoomLevel = aRoomLevel;
1.47 + }
1.48 +
1.49 +
1.50 +EXPORT_C CRoomLevelMessageHandler* CRoomLevelMessageHandler::NewL(
1.51 + TAny* aCustomInterface )
1.52 + {
1.53 + CRoomLevel* roomLevel = (CRoomLevel*)aCustomInterface;
1.54 + CRoomLevelMessageHandler* self = new (ELeave) CRoomLevelMessageHandler(roomLevel);
1.55 + self->ConstructL();
1.56 + return self;
1.57 + }
1.58 +
1.59 +
1.60 +// -----------------------------------------------------------------------------
1.61 +// CRoomLevelMessageHandler::ConstructL
1.62 +// Symbian 2nd phase constructor can leave.
1.63 +// Create and initializes the effect data queue.
1.64 +// -----------------------------------------------------------------------------
1.65 +//
1.66 +void CRoomLevelMessageHandler::ConstructL()
1.67 + {
1.68 + iEffectDataQue = new(ELeave) TSglQue<CEffectDataQueItem>(_FOFF(CEffectDataQueItem, iLink));
1.69 + }
1.70 +
1.71 +
1.72 +// -----------------------------------------------------------------------------
1.73 +// CRoomLevelMessageHandler::~CRoomLevelMessageHandler
1.74 +// Before going away, unregister with the CI RoomLevel object.
1.75 +// The observation message must be completed if outstanding.
1.76 +// The effect data queue must be emptied and destroyed.
1.77 +// -----------------------------------------------------------------------------
1.78 +//
1.79 +CRoomLevelMessageHandler::~CRoomLevelMessageHandler()
1.80 + {
1.81 +
1.82 +#ifdef _DEBUG
1.83 + RDebug::Print(_L("CRoomLevelMessageHandler::~CRoomLevelMessageHandler"));
1.84 +#endif
1.85 + if(iRoomLevel)
1.86 + iRoomLevel->UnRegisterObserver(*this);
1.87 + iRegistered = EFalse;
1.88 +
1.89 + if(iMessage)
1.90 + {
1.91 + if ( !iMessage->IsCompleted() )
1.92 + {
1.93 + iMessage->Complete(KErrCancel);
1.94 + delete iMessage;
1.95 + }
1.96 + }
1.97 +
1.98 + if ( iEffectDataQue )
1.99 + {
1.100 + CEffectDataQueItem* queItem;
1.101 + while ( !iEffectDataQue->IsEmpty() )
1.102 + {
1.103 + queItem = iEffectDataQue->First();
1.104 + iEffectDataQue->Remove(*queItem);
1.105 + delete queItem;
1.106 + }
1.107 +
1.108 + delete iEffectDataQue;
1.109 + }
1.110 +
1.111 + delete iRoomLevel;
1.112 +
1.113 + }
1.114 +
1.115 +
1.116 +// ---------------------------------------------------------
1.117 +// CRoomLevelMessageHandler::HandleRequest
1.118 +// (other items were commented in a header).
1.119 +// ---------------------------------------------------------
1.120 +//
1.121 +void CRoomLevelMessageHandler::HandleRequest(
1.122 + TMMFMessage& aMessage )
1.123 + {
1.124 + ASSERT(aMessage.Destination().InterfaceId() == KUidRoomLevelEffect);
1.125 + TRAPD(error,DoHandleRequestL(aMessage));
1.126 + if ( error )
1.127 + {
1.128 + aMessage.Complete(error);
1.129 + }
1.130 + }
1.131 +
1.132 +// ---------------------------------------------------------
1.133 +// CRoomLevelMessageHandler::DoHandleRequestL
1.134 +// Dispatches the message to the appropriate handler.
1.135 +// ---------------------------------------------------------
1.136 +//
1.137 +void CRoomLevelMessageHandler::DoHandleRequestL(
1.138 + TMMFMessage& aMessage )
1.139 + {
1.140 + switch( aMessage.Function() )
1.141 + {
1.142 + case ERoomInitialize:
1.143 + {
1.144 + DoInitializeL(aMessage);
1.145 + break;
1.146 + }
1.147 + case ERoomApply:
1.148 + {
1.149 + DoApplyL(aMessage);
1.150 + break;
1.151 + }
1.152 + case ERoomObserve:
1.153 + {
1.154 + DoObserveL(aMessage);
1.155 + break;
1.156 + }
1.157 + default:
1.158 + {
1.159 + aMessage.Complete(KErrNotSupported);
1.160 + }
1.161 + }
1.162 + }
1.163 +
1.164 +// ---------------------------------------------------------
1.165 +// CRoomLevelMessageHandler::DoInitializeL
1.166 +// ---------------------------------------------------------
1.167 +//
1.168 +void CRoomLevelMessageHandler::DoInitializeL(TMMFMessage& aMessage)
1.169 + {
1.170 +#ifdef _DEBUG
1.171 + RDebug::Print(_L("CRoomLevelMessageHandler::DoInitializeL"));
1.172 +#endif
1.173 + aMessage.WriteDataToClient(iRoomLevel->DoEffectData());
1.174 + aMessage.Complete(KErrNone);
1.175 + }
1.176 +
1.177 +// ---------------------------------------------------------
1.178 +// CRoomLevelMessageHandler::DoApplyL
1.179 +// Extracts the data from the message. The client RoomLevel
1.180 +// data is applied to the CI RoomLevel object.
1.181 +// ---------------------------------------------------------
1.182 +//
1.183 +void CRoomLevelMessageHandler::DoApplyL(
1.184 + TMMFMessage& aMessage )
1.185 + {
1.186 +#ifdef _DEBUG
1.187 + RDebug::Print(_L("CRoomLevelMessageHandler::DoApplyL"));
1.188 +#endif
1.189 + TEfRoomLevelDataPckg RoomLevelPckgFromClient;
1.190 + aMessage.ReadData1FromClient(RoomLevelPckgFromClient);
1.191 + iRoomLevel->SetEffectData(RoomLevelPckgFromClient);
1.192 + iRoomLevel->ApplyL();
1.193 + aMessage.Complete(KErrNone);
1.194 + }
1.195 +
1.196 +// ---------------------------------------------------------
1.197 +// CRoomLevelMessageHandler::DoObserveL
1.198 +// Receives the observation request message and depending
1.199 +// on the status of the effect data queue, the message is
1.200 +// completed immediately or saved for later completion.
1.201 +// ---------------------------------------------------------
1.202 +//
1.203 +void CRoomLevelMessageHandler::DoObserveL(
1.204 + TMMFMessage& aMessage )
1.205 + {
1.206 +
1.207 +#ifdef _DEBUG
1.208 + RDebug::Print(_L("CRoomLevelMessageHandler::DoObserveL"));
1.209 +#endif
1.210 +
1.211 + if ( !iRegistered )
1.212 + {
1.213 + iRoomLevel->RegisterObserverL(*this);
1.214 + iRegistered = ETrue;
1.215 + }
1.216 +
1.217 + if ( iEffectDataQue->IsEmpty() )
1.218 + {
1.219 + //iMessage = &aMessage;
1.220 + iMessage = new(ELeave) TMMFMessage(aMessage);
1.221 + }
1.222 + else
1.223 + {
1.224 + TEfRoomLevelDataPckg dataPckg;
1.225 + CEffectDataQueItem* item = iEffectDataQue->First();
1.226 + dataPckg.Copy(item->EffectData());
1.227 + aMessage.WriteDataToClient(dataPckg);
1.228 + aMessage.Complete(KErrNone);
1.229 + iEffectDataQue->Remove(*item);
1.230 + delete item;
1.231 + }
1.232 + }
1.233 +
1.234 +// ---------------------------------------------------------
1.235 +// CRoomLevelMessageHandler::EffectChanged
1.236 +// The CI RoomLevel object has changed state.
1.237 +// The observation message is completed if no data has been
1.238 +// queued up. Otherwise, the CI RoomLevel object's data is
1.239 +// packaged and queued.
1.240 +// ---------------------------------------------------------
1.241 +//
1.242 +void CRoomLevelMessageHandler::EffectChanged(
1.243 + const CAudioEffect* aAudioEffect,
1.244 + TUint8 /*aEvent*/ )
1.245 + {
1.246 +#ifdef _DEBUG
1.247 + RDebug::Print(_L("CRoomLevelMessageHandler::EffectChanged"));
1.248 +#endif
1.249 +
1.250 + if ( iMessage && !iMessage->IsCompleted() && iEffectDataQue->IsEmpty() )
1.251 + {
1.252 + iMessage->WriteDataToClient(((CRoomLevel*)aAudioEffect)->DoEffectData());
1.253 + iMessage->Complete(KErrNone);
1.254 + delete iMessage;
1.255 + iMessage = NULL;
1.256 + }
1.257 + else
1.258 + {
1.259 + // Saves the data and complete an observation message next time around.
1.260 + HBufC8* data = NULL;
1.261 + TRAPD(err1,data = ((CRoomLevel*)aAudioEffect)->DoEffectData().AllocL());
1.262 + if(!err1)
1.263 + {
1.264 + //CleanupStack::PushL(data);
1.265 + CEffectDataQueItem* item = NULL;
1.266 + TRAPD(err2,item = CEffectDataQueItem::NewL(data));
1.267 + if(!err2)
1.268 + {
1.269 + iEffectDataQue->AddLast(*item);
1.270 + }
1.271 + else
1.272 + {
1.273 + delete data;
1.274 + }
1.275 + }
1.276 + else
1.277 + {
1.278 +#ifdef _DEBUG
1.279 + RDebug::Print(_L("CRoomLevelMessageHandler::EffectChanged Error Allocating Memory %d"),err1);
1.280 +#endif
1.281 + }
1.282 + }
1.283 +
1.284 + }
1.285 +
1.286 +
1.287 +// ========================== OTHER EXPORTED FUNCTIONS =========================
1.288 +
1.289 +
1.290 +// End of File