1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/devsoundrefplugin/src/server/Policy/MmfAudioPolicySession.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,396 @@
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 "MmfAudioPolicySession.h"
1.20 +#include "MmfPolicyClientServer.h"
1.21 +#include "MmfAudioPolicyServer.h"
1.22 +#include "MmfDevSoundInfo.h"
1.23 +
1.24 +
1.25 +const TInt KEventQLimit=16; // maximum number of pending events per session
1.26 +
1.27 +CMMFAudioPolicySession* CMMFAudioPolicySession::NewL()
1.28 + {
1.29 + CMMFAudioPolicySession* self = new(ELeave) CMMFAudioPolicySession();
1.30 + CleanupStack::PushL(self);
1.31 + self->ConstructL();
1.32 + CleanupStack::Pop();
1.33 + return self;
1.34 + }
1.35 +
1.36 +void CMMFAudioPolicySession::ConstructL()
1.37 + {
1.38 + iAudioPolicyRequest = new (ELeave) CMMFAudioPolicyRequest();
1.39 + }
1.40 +
1.41 +CMMFAudioPolicySession::CMMFAudioPolicySession() : iEventsQue(_FOFF(TMMFAudioPolicyEventHolder,iLink)),
1.42 + iNoMemoryEventHolder(TMMFAudioPolicyEvent(TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification, KErrNoMemory, EMMFStateCompleted), EFalse)
1.43 + {
1.44 + }
1.45 +
1.46 +void CMMFAudioPolicySession::CreateL(const CMmfIpcServer& aServer)
1.47 + {
1.48 + iServer = STATIC_CAST(CMMFAudioPolicyServer*, (CONST_CAST(CMmfIpcServer*, &aServer)));
1.49 + iServer->IncrementSessionCount();
1.50 + CMmfIpcSession::CreateL(aServer);
1.51 + iServer->IncrementSessionId();
1.52 + iPolicySessionId = iServer->PolicySessionId();
1.53 + // Get ptr to AudioPolicy from the server
1.54 + iAudioPolicy = iServer->AudioPolicy();
1.55 + iAudioPolicy->ReserveClientNumL(iServer->PolicySessionCount());
1.56 + }
1.57 +
1.58 +CMMFAudioPolicyServer* CMMFAudioPolicySession::Server()
1.59 + {
1.60 + return STATIC_CAST(CMMFAudioPolicyServer*, iServer);
1.61 + }
1.62 +
1.63 +CMMFAudioPolicySession::~CMMFAudioPolicySession()
1.64 + {
1.65 + delete iEventReceiver;
1.66 + iEventReceiver=NULL;
1.67 + ClearEventQ();
1.68 + iAudioPolicyPrioritySettings.iState = EMMFStateClosed;
1.69 + // Have session's CMMFAudioPolicyRequest object removed from list
1.70 + if (iAudioPolicy != NULL)
1.71 + {
1.72 + iAudioPolicy->RemoveFromList(iPolicySessionId);
1.73 + }
1.74 + delete iAudioPolicyRequest;
1.75 + if (iServer != NULL)
1.76 + {
1.77 + iServer->DecrementSessionCount();
1.78 + iServer->StopNotificationTimer();
1.79 + }
1.80 + }
1.81 +
1.82 +void CMMFAudioPolicySession::ClearEventQ()
1.83 + {
1.84 + while (!iEventsQue.IsEmpty())
1.85 + {
1.86 + TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First();
1.87 + iEventsQue.Remove(*heldEvent);
1.88 + if (heldEvent == &iNoMemoryEventHolder)
1.89 + {
1.90 + iNoMemoryEventUsed = EFalse;
1.91 + }
1.92 + if (heldEvent->iShallBeDeleted)
1.93 + {
1.94 + delete heldEvent;
1.95 + }
1.96 + --iEventQSize;
1.97 + }
1.98 + }
1.99 +
1.100 +void CMMFAudioPolicySession::ServiceL(const RMmfIpcMessage& aMessage)
1.101 + {
1.102 + if (iEventQSize > KEventQLimit)
1.103 + {
1.104 + aMessage.Panic(KMMFAudioPolicyPanicCategory, EMMFAudioPolicySessionEventQueueOverflow);
1.105 + return;
1.106 + }
1.107 +
1.108 + TBool complete = EFalse;
1.109 + switch(aMessage.Function())
1.110 + {
1.111 + case EMMFPolicyMakeRequest:
1.112 + MakeRequestL(aMessage);
1.113 + aMessage.Complete(KErrNone);
1.114 + break;
1.115 + case EMMFPolicySetDevSoundInfo:
1.116 + complete = SetDevSoundInfoL(aMessage);
1.117 + break;
1.118 + case EMMFPolicyUpdateState:
1.119 + complete = UpdateStateL(aMessage);
1.120 + break;
1.121 + case EMMFPolicyReceiveEvents:
1.122 + complete = ReceiveEventsL(aMessage);
1.123 + break;
1.124 + case EMMFPolicyCancelReceiveEvents:
1.125 + complete = CancelReceiveEvents();
1.126 + break;
1.127 + case EMMFPolicyGetPlayFormatsSupported:
1.128 + complete = GetPlayFormatsSupportedL(aMessage);
1.129 + break;
1.130 + case EMMFPolicyGetRecordFormatsSupported:
1.131 + complete = GetRecordFormatsSupportedL(aMessage);
1.132 + break;
1.133 + case EMMFPolicyGetPlayFormat:
1.134 + complete = GetPlayFormatL(aMessage);
1.135 + break;
1.136 + case EMMFPolicyGetRecordFormat:
1.137 + complete = GetRecordFormatL(aMessage);
1.138 + break;
1.139 + case EMMFPolicyLaunchRequests:
1.140 + complete = LaunchRequest();
1.141 + break;
1.142 + case EMMFPolicyRequestResourceNotification:
1.143 + complete = RequestResourceNotificationL(aMessage);
1.144 + break;
1.145 + case EMMFPolicyCancelRequestResourceNotification:
1.146 + complete = CancelRequestResourceNotificationL(aMessage);
1.147 + break;
1.148 + case EMMFPolicyStopNotification:
1.149 + complete = StopNotificationL(aMessage);
1.150 + break;
1.151 + case EMMFPolicyGetResourceNotificationEvent:
1.152 + complete = GetResourceNotificationEventL(aMessage);
1.153 + break;
1.154 + default:
1.155 + User::Leave(KErrNotSupported);
1.156 + break;
1.157 + }
1.158 + if(complete)
1.159 + {
1.160 + aMessage.Complete(KErrNone);
1.161 + }
1.162 + }
1.163 +
1.164 +void CMMFAudioPolicySession::MakeRequestL(const RMmfIpcMessage& aMessage)
1.165 + {
1.166 + TMMFAudioPolicyPrioritySettingsPckg settingsPckg;
1.167 + MmfMessageUtil::ReadL(aMessage, 0, settingsPckg);
1.168 +
1.169 + iAudioPolicyRequest->SetPriority(settingsPckg().iPriority);
1.170 + iAudioPolicyRequest->SetPref(settingsPckg().iPref);
1.171 + iAudioPolicyRequest->SetState(settingsPckg().iState);
1.172 +
1.173 + iAudioPolicyRequest->SetCapabilities(settingsPckg().iCapabilities);
1.174 +
1.175 + // Set session Id in Request
1.176 + iAudioPolicyRequest->SetPolicySessionId(iPolicySessionId);
1.177 + iAudioPolicy->MakeRequest(iAudioPolicyRequest);
1.178 + }
1.179 +
1.180 +TBool CMMFAudioPolicySession::UpdateStateL(const RMmfIpcMessage& aMessage)
1.181 + {
1.182 + TMMFAudioPolicyPrioritySettingsPckg settingsPckg;
1.183 + MmfMessageUtil::ReadL(aMessage, 0, settingsPckg);
1.184 +
1.185 + iAudioPolicy->ModifyEntry(iPolicySessionId, settingsPckg().iState);
1.186 + return ETrue;
1.187 + }
1.188 +
1.189 +void CMMFAudioPolicySession::SendEventToClient(const TMMFAudioPolicyEvent& aEvent)
1.190 + {
1.191 + if (iEventReceiver)
1.192 + {
1.193 + iEventReceiver->SendEvent(aEvent);
1.194 + delete iEventReceiver;
1.195 + iEventReceiver=NULL;
1.196 + }
1.197 + else
1.198 + {
1.199 + if (++iEventQSize > KEventQLimit) // check if Q is not full
1.200 + {
1.201 + return; // we'll panic that bad client later
1.202 + }
1.203 + TMMFAudioPolicyEventHolder* heldEvent = new TMMFAudioPolicyEventHolder(aEvent, ETrue);
1.204 +
1.205 + if (heldEvent==NULL && !iNoMemoryEventUsed)
1.206 + {
1.207 + heldEvent=&iNoMemoryEventHolder;
1.208 + iNoMemoryEventUsed = ETrue;
1.209 + }
1.210 + if (heldEvent)
1.211 + {
1.212 + iEventsQue.AddLast(*heldEvent);
1.213 + }
1.214 + }
1.215 + }
1.216 +
1.217 +TBool CMMFAudioPolicySession::SetDevSoundInfoL(const RMmfIpcMessage& aMessage)
1.218 + {
1.219 + TMMFDevSoundInfoPckg devSoundInfoPckg;
1.220 + MmfMessageUtil::ReadL(aMessage, 0, devSoundInfoPckg);
1.221 + iDevSoundId = devSoundInfoPckg().iDevSoundId;
1.222 + return ETrue;
1.223 + }
1.224 +
1.225 +TBool CMMFAudioPolicySession::ReceiveEventsL(const RMmfIpcMessage& aMessage)
1.226 + {
1.227 + if (iEventReceiver)
1.228 + User::Leave(KErrAlreadyExists);
1.229 + iEventReceiver = CMMFAudioPolicyEventReceiver::NewL(aMessage);
1.230 +#if defined(ALLOW_POLICY_DEBUG)
1.231 + RDebug::Print(_L("Sess. ID=%d listen to events"),iPolicySessionId);
1.232 +#endif
1.233 + //send the next cached event (if any) to the client
1.234 + if (!iEventsQue.IsEmpty())
1.235 + {
1.236 + TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First();
1.237 + iEventReceiver->SendEvent(heldEvent->iEvent);
1.238 + iEventsQue.Remove(*heldEvent);
1.239 + if (heldEvent == &iNoMemoryEventHolder)
1.240 + {
1.241 + iNoMemoryEventUsed = EFalse;
1.242 + }
1.243 + --iEventQSize;
1.244 + if (heldEvent->iShallBeDeleted)
1.245 + {
1.246 + delete heldEvent;
1.247 + }
1.248 + delete iEventReceiver;
1.249 + iEventReceiver=NULL;
1.250 + }
1.251 + return EFalse;
1.252 + }
1.253 +
1.254 +TBool CMMFAudioPolicySession::CancelReceiveEvents()
1.255 + {
1.256 + delete iEventReceiver;
1.257 + iEventReceiver = NULL;
1.258 + return ETrue;
1.259 + }
1.260 +
1.261 +TBool CMMFAudioPolicySession::GetPlayFormatsSupportedL(const RMmfIpcMessage& aMessage)
1.262 + {
1.263 + RMdaDevSound::TSoundFormatsSupportedBuf aPlayFormatsSupported;
1.264 + aPlayFormatsSupported = iAudioPolicy->MdaHwInfo()->GetPlayFormatsSupported();
1.265 + MmfMessageUtil::WriteL(aMessage, 0, aPlayFormatsSupported);
1.266 + return ETrue;
1.267 + }
1.268 +
1.269 +TBool CMMFAudioPolicySession::GetRecordFormatsSupportedL(const RMmfIpcMessage& aMessage)
1.270 + {
1.271 + RMdaDevSound::TSoundFormatsSupportedBuf aRecordFormatsSupported;
1.272 + aRecordFormatsSupported = iAudioPolicy->MdaHwInfo()->GetRecordFormatsSupported();
1.273 + MmfMessageUtil::WriteL(aMessage, 0, aRecordFormatsSupported);
1.274 + return ETrue;
1.275 + }
1.276 +
1.277 +TBool CMMFAudioPolicySession::GetPlayFormatL(const RMmfIpcMessage& aMessage)
1.278 + {
1.279 + RMdaDevSound::TCurrentSoundFormatBuf aPlayFormat;
1.280 + aPlayFormat = iAudioPolicy->MdaHwInfo()->GetPlayFormat();
1.281 + MmfMessageUtil::WriteL(aMessage, 0, aPlayFormat);
1.282 + return ETrue;
1.283 + }
1.284 +
1.285 +TBool CMMFAudioPolicySession::GetRecordFormatL(const RMmfIpcMessage& aMessage)
1.286 + {
1.287 + RMdaDevSound::TCurrentSoundFormatBuf aRecordFormat;
1.288 + aRecordFormat = iAudioPolicy->MdaHwInfo()->GetRecordFormat();
1.289 + MmfMessageUtil::WriteL(aMessage, 0, aRecordFormat);
1.290 + return ETrue;
1.291 + }
1.292 +
1.293 +TBool CMMFAudioPolicySession::LaunchRequest()
1.294 + {
1.295 + iAudioPolicy->LaunchRequest( iAudioPolicyRequest->PolicySessionId() );
1.296 + return ETrue;
1.297 + }
1.298 +
1.299 +TBool CMMFAudioPolicySession::RequestResourceNotificationL(const RMmfIpcMessage& aMessage)
1.300 + {
1.301 + TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
1.302 + MmfMessageUtil::ReadL(aMessage, 0, notificationPckg);
1.303 + iAudioPolicyRequest->SetNotificationEvent(notificationPckg().iNotificationUid);
1.304 + iAudioPolicyRequest->SetRequestDataL(notificationPckg().iNotificationDelay);
1.305 + iAudioPolicy->SetNotification(iPolicySessionId,notificationPckg().iNotificationUid);
1.306 + return ETrue;
1.307 + }
1.308 +
1.309 +TBool CMMFAudioPolicySession::CancelRequestResourceNotificationL(const RMmfIpcMessage& aMessage)
1.310 + {
1.311 + TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
1.312 + MmfMessageUtil::ReadL(aMessage, 0, notificationPckg);
1.313 + iAudioPolicyRequest->ResetNotificationEvent(notificationPckg().iNotificationUid);
1.314 + iAudioPolicy->SetNotification(iPolicySessionId,KNullUid);
1.315 + return ETrue;
1.316 + }
1.317 +
1.318 +TBool CMMFAudioPolicySession::StopNotificationL(const RMmfIpcMessage& /*aMessage*/)
1.319 + {
1.320 + iServer->StopNotificationTimer();
1.321 + return ETrue;
1.322 + }
1.323 +
1.324 +TBool CMMFAudioPolicySession::GetResourceNotificationEventL(const RMmfIpcMessage& aMessage) const
1.325 + {
1.326 + TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
1.327 + notificationPckg().iNotificationUid = iAudioPolicyRequest->NotificationEvent();
1.328 + MmfMessageUtil::WriteL(aMessage, 0, notificationPckg);
1.329 + return ETrue;
1.330 + }
1.331 +
1.332 +CMMFAudioPolicyEventReceiver* CMMFAudioPolicyEventReceiver::NewL(const RMmfIpcMessage& aMessage)
1.333 + {
1.334 + return new(ELeave) CMMFAudioPolicyEventReceiver(aMessage);
1.335 + }
1.336 +
1.337 +CMMFAudioPolicyEventReceiver::~CMMFAudioPolicyEventReceiver()
1.338 + {
1.339 + if (iNeedToCompleteMessage)
1.340 + {
1.341 + iMessage.Complete(KErrDied);
1.342 + }
1.343 + }
1.344 +
1.345 +void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFAudioPolicyEvent& aEvent)
1.346 + {
1.347 + TMMFAudioPolicyEventPckg eventpckg(aEvent);
1.348 + TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg);
1.349 + iMessage.Complete(err);
1.350 + iNeedToCompleteMessage = EFalse;
1.351 + }
1.352 +
1.353 +void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFEvent& aEvent)
1.354 + {
1.355 + TMMFEventPckg eventpckg(aEvent);
1.356 + TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg);
1.357 + iMessage.Complete(err);
1.358 + iNeedToCompleteMessage = EFalse;
1.359 + }
1.360 +
1.361 +CMMFAudioPolicyEventReceiver::CMMFAudioPolicyEventReceiver(const RMmfIpcMessage& aMessage) :
1.362 + iMessage(aMessage), iNeedToCompleteMessage(ETrue)
1.363 + {
1.364 + }
1.365 +
1.366 +CMMFAudioPolicyRequest::CMMFAudioPolicyRequest():
1.367 + iPolicySessionId(KErrNotFound),
1.368 + iReqDataPtr(KNullDesC8)
1.369 + {
1.370 + iNotificationEventUid = KNullUid;
1.371 + }
1.372 +
1.373 +CMMFAudioPolicyRequest::~CMMFAudioPolicyRequest()
1.374 + {
1.375 + delete iRequestData;
1.376 + }
1.377 +
1.378 +void CMMFAudioPolicyRequest::SetRequestDataL(const TDesC8& aRequestData)
1.379 + {
1.380 + iReqDataPtr.Set(KNullDesC8);
1.381 + if (aRequestData.Length() == 0)
1.382 + {
1.383 + return;
1.384 + }
1.385 + if (iRequestData==NULL || (iRequestData && iRequestData->Des().MaxLength()<aRequestData.Length()))
1.386 + {
1.387 + delete iRequestData;
1.388 + iRequestData = NULL;
1.389 + iRequestData = aRequestData.AllocL();
1.390 + }
1.391 + else
1.392 + {
1.393 + iRequestData->Des().Copy(aRequestData);
1.394 + }
1.395 + iReqDataPtr.Set(*iRequestData);
1.396 + }
1.397 +
1.398 +
1.399 +