os/mm/devsound/sounddevbt/src/server/Policy/MmfBtAudioPolicySession.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/sounddevbt/src/server/Policy/MmfBtAudioPolicySession.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,311 @@
     1.4 +// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "MmfBtAudioPolicySession.h"
    1.20 +#include "MmfBtPolicyClientServer.h"
    1.21 +#include "MmfBtAudioPolicyServer.h"
    1.22 +#include "MmfBtDevSoundInfo.h"
    1.23 +
    1.24 +
    1.25 +
    1.26 +CMMFAudioPolicySession* CMMFAudioPolicySession::NewL()
    1.27 +	{
    1.28 +	CMMFAudioPolicySession* self = new(ELeave) CMMFAudioPolicySession();
    1.29 +	CleanupStack::PushL(self);
    1.30 +	self->ConstructL();
    1.31 +	CleanupStack::Pop();
    1.32 +	return self;
    1.33 +	}
    1.34 +
    1.35 +void CMMFAudioPolicySession::ConstructL()
    1.36 +	{
    1.37 +	iAudioPolicyRequest = new (ELeave) CMMFAudioPolicyRequest();
    1.38 +	}
    1.39 +
    1.40 +CMMFAudioPolicySession::CMMFAudioPolicySession() : iEventsQue(_FOFF(TMMFAudioPolicyEventHolder,iLink))
    1.41 +	{
    1.42 +	}
    1.43 +
    1.44 +void CMMFAudioPolicySession::CreateL(const CMmfIpcServer& aServer)
    1.45 +	{
    1.46 +	iServer = STATIC_CAST(CMMFAudioPolicyServer*, (CONST_CAST(CMmfIpcServer*, &aServer)));
    1.47 +	iServer->IncrementSessionCount();
    1.48 +	CMmfIpcSession::CreateL(aServer);
    1.49 +	iServer->IncrementSessionId();
    1.50 +	iPolicySessionId = iServer->PolicySessionId();
    1.51 +	// Get ptr to AudioPolicy from the server
    1.52 +	iAudioPolicy = iServer->AudioPolicy();
    1.53 +	(iAudioPolicy->AudioPolicyRequestArray())->SetReserveL(iServer->PolicySessionCount());
    1.54 +	}
    1.55 +
    1.56 +CMMFAudioPolicyServer* CMMFAudioPolicySession::Server()
    1.57 +	{
    1.58 +	return STATIC_CAST(CMMFAudioPolicyServer*, iServer);
    1.59 +	}
    1.60 +
    1.61 +CMMFAudioPolicySession::~CMMFAudioPolicySession()
    1.62 +	{
    1.63 +	delete iEventReceiver;
    1.64 +	delete iAudioPolicyRequest;
    1.65 +	iEventReceiver=NULL;
    1.66 +	if (!iEventsQue.IsEmpty())
    1.67 +		{
    1.68 +		TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First();
    1.69 +		iEventsQue.Remove(*heldEvent);
    1.70 +		delete heldEvent;
    1.71 +		}
    1.72 +	iAudioPolicyPrioritySettings.iState = EMMFStateClosed;
    1.73 +	// Have session's CMMFAudioPolicyRequest object removed from list
    1.74 +	iAudioPolicy->RemoveFromList(iPolicySessionId);
    1.75 +	iServer->DecrementSessionCount();
    1.76 +	iServer->StopNotificationTimer();
    1.77 +	}
    1.78 +
    1.79 +void CMMFAudioPolicySession::ServiceL(const RMmfIpcMessage& aMessage)
    1.80 +	{
    1.81 +	TBool complete = EFalse;
    1.82 +	switch(aMessage.Function())
    1.83 +		{
    1.84 +	case EMMFPolicyMakeRequest:
    1.85 +		MakeRequestL(aMessage);
    1.86 +		aMessage.Complete(KErrNone);
    1.87 +		break;
    1.88 +	case EMMFPolicySetDevSoundInfo:
    1.89 +		complete = SetDevSoundInfoL(aMessage);
    1.90 +		break;
    1.91 +	case EMMFPolicyUpdateState:
    1.92 +		complete = UpdateStateL(aMessage);
    1.93 +		break;
    1.94 +	case EMMFPolicyReceiveEvents:
    1.95 +		complete = ReceiveEventsL(aMessage);
    1.96 +		break;
    1.97 +	case EMMFPolicyCancelReceiveEvents:
    1.98 +		complete = CancelReceiveEvents();
    1.99 +		break;
   1.100 +	case EMMFPolicyGetPlayFormatsSupported:
   1.101 +		complete = GetPlayFormatsSupportedL(aMessage);
   1.102 +		break;
   1.103 +	case EMMFPolicyGetRecordFormatsSupported:
   1.104 +		complete = GetRecordFormatsSupportedL(aMessage);
   1.105 +		break;
   1.106 +	case EMMFPolicyGetPlayFormat:
   1.107 +		complete = GetPlayFormatL(aMessage);
   1.108 +		break;
   1.109 +	case EMMFPolicyGetRecordFormat:
   1.110 +		complete = GetRecordFormatL(aMessage);
   1.111 +		break;
   1.112 +	case EMMFPolicyLaunchRequests:
   1.113 +		complete = LaunchRequest();
   1.114 +		break;
   1.115 +	case EMMFPolicyRequestResourceNotification:
   1.116 +		complete = RequestResourceNotificationL(aMessage);
   1.117 +		break;
   1.118 +	case EMMFPolicyCancelRequestResourceNotification:
   1.119 +		complete = CancelRequestResourceNotificationL(aMessage);
   1.120 +		break;
   1.121 +	case EMMFPolicyStopNotification:
   1.122 +		complete = StopNotificationL(aMessage);
   1.123 +		break;
   1.124 +	case EMMFPolicyGetResourceNotificationEvent:
   1.125 +		complete = GetResourceNotificationEventL(aMessage);
   1.126 +		break;
   1.127 +	default:
   1.128 +		User::Leave(KErrNotSupported);
   1.129 +		break;
   1.130 +		}
   1.131 +	if(complete)
   1.132 +		{
   1.133 +		aMessage.Complete(KErrNone);
   1.134 +		}
   1.135 +	}
   1.136 +
   1.137 +void CMMFAudioPolicySession::MakeRequestL(const RMmfIpcMessage& aMessage)
   1.138 +	{
   1.139 +	TMMFAudioPolicyPrioritySettingsPckg settingsPckg;
   1.140 +	MmfMessageUtil::ReadL(aMessage, 0, settingsPckg);
   1.141 +
   1.142 +	iAudioPolicyRequest->SetPriority(settingsPckg().iPriority);
   1.143 +	iAudioPolicyRequest->SetPref(settingsPckg().iPref);
   1.144 +	iAudioPolicyRequest->SetState(settingsPckg().iState);
   1.145 +
   1.146 +	iAudioPolicyRequest->SetCapabilities(settingsPckg().iCapabilities);
   1.147 +	
   1.148 +	// Set session Id in Request
   1.149 +	iAudioPolicyRequest->SetPolicySessionId(iPolicySessionId);
   1.150 +	iAudioPolicy->MakeRequest(iAudioPolicyRequest);
   1.151 +	}
   1.152 +
   1.153 +TBool CMMFAudioPolicySession::UpdateStateL(const RMmfIpcMessage& aMessage)
   1.154 +	{
   1.155 +	TMMFAudioPolicyPrioritySettingsPckg settingsPckg;
   1.156 +	MmfMessageUtil::ReadL(aMessage, 0, settingsPckg);
   1.157 +
   1.158 +	iAudioPolicyRequest->SetState(settingsPckg().iState);
   1.159 +	iAudioPolicy->ModifyEntry(iPolicySessionId, iAudioPolicyRequest); 
   1.160 +	return ETrue;
   1.161 +	}
   1.162 +
   1.163 +void CMMFAudioPolicySession::SendEventToClient(TMMFAudioPolicyEvent& aEvent)
   1.164 +	{
   1.165 +	if (iEventReceiver)
   1.166 +		{
   1.167 +		iEventReceiver->SendEvent(aEvent);
   1.168 +		delete iEventReceiver;
   1.169 +		iEventReceiver=NULL;
   1.170 +		}
   1.171 +	else 
   1.172 +		{
   1.173 +		TMMFAudioPolicyEventHolder* heldEvent = new TMMFAudioPolicyEventHolder(aEvent);
   1.174 +		iEventsQue.AddLast(*heldEvent);
   1.175 +		}
   1.176 +	}
   1.177 +
   1.178 +TBool CMMFAudioPolicySession::SetDevSoundInfoL(const RMmfIpcMessage& aMessage)
   1.179 +	{
   1.180 +	TMMFDevSoundInfoPckg devSoundInfoPckg;
   1.181 +	MmfMessageUtil::ReadL(aMessage, 0, devSoundInfoPckg);
   1.182 +	iDevSoundId = devSoundInfoPckg().iDevSoundId;
   1.183 +	return ETrue;
   1.184 +	}
   1.185 +
   1.186 +TBool CMMFAudioPolicySession::ReceiveEventsL(const RMmfIpcMessage& aMessage)
   1.187 +	{
   1.188 +	if (iEventReceiver)
   1.189 +		User::Leave(KErrAlreadyExists);
   1.190 +	iEventReceiver = CMMFAudioPolicyEventReceiver::NewL(aMessage);
   1.191 +	//send the next cached event (if any) to the client
   1.192 +	if (!iEventsQue.IsEmpty())
   1.193 +		{
   1.194 +		TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First();
   1.195 +		iEventReceiver->SendEvent(heldEvent->iEvent);
   1.196 +		iEventsQue.Remove(*heldEvent);
   1.197 +		delete iEventReceiver;
   1.198 +		iEventReceiver=NULL;
   1.199 +		}
   1.200 +	return EFalse;
   1.201 +	}
   1.202 +
   1.203 +TBool CMMFAudioPolicySession::CancelReceiveEvents()
   1.204 +	{
   1.205 +	delete iEventReceiver;
   1.206 +	iEventReceiver = NULL;
   1.207 +	return ETrue;
   1.208 +	}
   1.209 +
   1.210 +TBool CMMFAudioPolicySession::GetPlayFormatsSupportedL(const RMmfIpcMessage& aMessage)
   1.211 +	{
   1.212 +	RMdaDevSound::TSoundFormatsSupportedBuf aPlayFormatsSupported;
   1.213 +	aPlayFormatsSupported = iAudioPolicy->MdaHwInfo()->GetPlayFormatsSupported();
   1.214 +	MmfMessageUtil::WriteL(aMessage, 0, aPlayFormatsSupported);
   1.215 +	return ETrue;
   1.216 +	}
   1.217 +
   1.218 +TBool CMMFAudioPolicySession::GetRecordFormatsSupportedL(const RMmfIpcMessage& aMessage)
   1.219 +	{
   1.220 +	RMdaDevSound::TSoundFormatsSupportedBuf aRecordFormatsSupported;
   1.221 +	aRecordFormatsSupported = iAudioPolicy->MdaHwInfo()->GetRecordFormatsSupported();
   1.222 +	MmfMessageUtil::WriteL(aMessage, 0, aRecordFormatsSupported);
   1.223 +	return ETrue;
   1.224 +	}
   1.225 +
   1.226 +TBool CMMFAudioPolicySession::GetPlayFormatL(const RMmfIpcMessage& aMessage)
   1.227 +	{
   1.228 +	RMdaDevSound::TCurrentSoundFormatBuf aPlayFormat;
   1.229 +	aPlayFormat = iAudioPolicy->MdaHwInfo()->GetPlayFormat();
   1.230 +	MmfMessageUtil::WriteL(aMessage, 0, aPlayFormat);
   1.231 +	return ETrue;
   1.232 +	}
   1.233 +
   1.234 +TBool CMMFAudioPolicySession::GetRecordFormatL(const RMmfIpcMessage& aMessage)
   1.235 +	{
   1.236 +	RMdaDevSound::TCurrentSoundFormatBuf aRecordFormat;
   1.237 +	aRecordFormat = iAudioPolicy->MdaHwInfo()->GetRecordFormat();
   1.238 +	MmfMessageUtil::WriteL(aMessage, 0, aRecordFormat);
   1.239 +	return ETrue;
   1.240 +	}
   1.241 +
   1.242 +TBool CMMFAudioPolicySession::LaunchRequest()
   1.243 +	{
   1.244 +	iAudioPolicy->LaunchRequest();
   1.245 +	return ETrue;
   1.246 +	}
   1.247 +	
   1.248 +TBool CMMFAudioPolicySession::RequestResourceNotificationL(const RMmfIpcMessage& aMessage)
   1.249 +	{
   1.250 +	TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
   1.251 +	MmfMessageUtil::ReadL(aMessage, 0, notificationPckg);
   1.252 +	iAudioPolicyRequest->SetNotificationEvent(notificationPckg().iNotificationUid);
   1.253 +	iAudioPolicy->SetNotification(iPolicySessionId,notificationPckg().iNotificationUid);
   1.254 +	return ETrue;
   1.255 +	}
   1.256 +
   1.257 +TBool CMMFAudioPolicySession::CancelRequestResourceNotificationL(const RMmfIpcMessage& aMessage)
   1.258 +	{
   1.259 +	if(iServer->IsTimerActive() == EFalse)
   1.260 +		{
   1.261 +		iServer->StartNotificationTimer();
   1.262 +		}
   1.263 +	TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
   1.264 +	MmfMessageUtil::ReadL(aMessage, 0, notificationPckg);
   1.265 +	iAudioPolicyRequest->ResetNotificationEvent(notificationPckg().iNotificationUid);
   1.266 +	iAudioPolicy->SetNotification(iPolicySessionId,KNullUid);
   1.267 +	return ETrue;
   1.268 +	}
   1.269 +
   1.270 +TBool CMMFAudioPolicySession::StopNotificationL(const RMmfIpcMessage& /*aMessage*/)
   1.271 +	{
   1.272 +	iServer->StopNotificationTimer();
   1.273 +	return ETrue;
   1.274 +	}
   1.275 +	
   1.276 +TBool CMMFAudioPolicySession::GetResourceNotificationEventL(const RMmfIpcMessage& aMessage)
   1.277 +	{
   1.278 +	TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
   1.279 +	notificationPckg().iNotificationUid = iAudioPolicyRequest->NotificationEvent();
   1.280 +	MmfMessageUtil::WriteL(aMessage, 0, notificationPckg);
   1.281 +	return ETrue;
   1.282 +	}
   1.283 +	
   1.284 +CMMFAudioPolicyEventReceiver* CMMFAudioPolicyEventReceiver::NewL(const RMmfIpcMessage& aMessage)
   1.285 +	{
   1.286 +	return new(ELeave) CMMFAudioPolicyEventReceiver(aMessage);
   1.287 +	}
   1.288 +
   1.289 +CMMFAudioPolicyEventReceiver::~CMMFAudioPolicyEventReceiver()
   1.290 +	{
   1.291 +	if (iNeedToCompleteMessage)
   1.292 +		iMessage.Complete(KErrDied);
   1.293 +	}
   1.294 +
   1.295 +void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFAudioPolicyEvent& aEvent)
   1.296 +	{
   1.297 +	TMMFAudioPolicyEventPckg eventpckg(aEvent);
   1.298 +	TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg);
   1.299 +	iMessage.Complete(err);
   1.300 +	iNeedToCompleteMessage = EFalse;			
   1.301 +	}
   1.302 +	
   1.303 +void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFEvent& aEvent)
   1.304 +	{
   1.305 +	TMMFEventPckg eventpckg(aEvent);
   1.306 +	TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg);
   1.307 +	iMessage.Complete(err);
   1.308 +	iNeedToCompleteMessage = EFalse;
   1.309 +	}
   1.310 +
   1.311 +CMMFAudioPolicyEventReceiver::CMMFAudioPolicyEventReceiver(const RMmfIpcMessage& aMessage) : 
   1.312 +	iMessage(aMessage), iNeedToCompleteMessage(ETrue)
   1.313 +	{
   1.314 +	}