os/mm/devsound/sounddevbt/src/server/Policy/MmfBtAudioPolicySession.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 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "MmfBtAudioPolicySession.h"
    17 #include "MmfBtPolicyClientServer.h"
    18 #include "MmfBtAudioPolicyServer.h"
    19 #include "MmfBtDevSoundInfo.h"
    20 
    21 
    22 
    23 CMMFAudioPolicySession* CMMFAudioPolicySession::NewL()
    24 	{
    25 	CMMFAudioPolicySession* self = new(ELeave) CMMFAudioPolicySession();
    26 	CleanupStack::PushL(self);
    27 	self->ConstructL();
    28 	CleanupStack::Pop();
    29 	return self;
    30 	}
    31 
    32 void CMMFAudioPolicySession::ConstructL()
    33 	{
    34 	iAudioPolicyRequest = new (ELeave) CMMFAudioPolicyRequest();
    35 	}
    36 
    37 CMMFAudioPolicySession::CMMFAudioPolicySession() : iEventsQue(_FOFF(TMMFAudioPolicyEventHolder,iLink))
    38 	{
    39 	}
    40 
    41 void CMMFAudioPolicySession::CreateL(const CMmfIpcServer& aServer)
    42 	{
    43 	iServer = STATIC_CAST(CMMFAudioPolicyServer*, (CONST_CAST(CMmfIpcServer*, &aServer)));
    44 	iServer->IncrementSessionCount();
    45 	CMmfIpcSession::CreateL(aServer);
    46 	iServer->IncrementSessionId();
    47 	iPolicySessionId = iServer->PolicySessionId();
    48 	// Get ptr to AudioPolicy from the server
    49 	iAudioPolicy = iServer->AudioPolicy();
    50 	(iAudioPolicy->AudioPolicyRequestArray())->SetReserveL(iServer->PolicySessionCount());
    51 	}
    52 
    53 CMMFAudioPolicyServer* CMMFAudioPolicySession::Server()
    54 	{
    55 	return STATIC_CAST(CMMFAudioPolicyServer*, iServer);
    56 	}
    57 
    58 CMMFAudioPolicySession::~CMMFAudioPolicySession()
    59 	{
    60 	delete iEventReceiver;
    61 	delete iAudioPolicyRequest;
    62 	iEventReceiver=NULL;
    63 	if (!iEventsQue.IsEmpty())
    64 		{
    65 		TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First();
    66 		iEventsQue.Remove(*heldEvent);
    67 		delete heldEvent;
    68 		}
    69 	iAudioPolicyPrioritySettings.iState = EMMFStateClosed;
    70 	// Have session's CMMFAudioPolicyRequest object removed from list
    71 	iAudioPolicy->RemoveFromList(iPolicySessionId);
    72 	iServer->DecrementSessionCount();
    73 	iServer->StopNotificationTimer();
    74 	}
    75 
    76 void CMMFAudioPolicySession::ServiceL(const RMmfIpcMessage& aMessage)
    77 	{
    78 	TBool complete = EFalse;
    79 	switch(aMessage.Function())
    80 		{
    81 	case EMMFPolicyMakeRequest:
    82 		MakeRequestL(aMessage);
    83 		aMessage.Complete(KErrNone);
    84 		break;
    85 	case EMMFPolicySetDevSoundInfo:
    86 		complete = SetDevSoundInfoL(aMessage);
    87 		break;
    88 	case EMMFPolicyUpdateState:
    89 		complete = UpdateStateL(aMessage);
    90 		break;
    91 	case EMMFPolicyReceiveEvents:
    92 		complete = ReceiveEventsL(aMessage);
    93 		break;
    94 	case EMMFPolicyCancelReceiveEvents:
    95 		complete = CancelReceiveEvents();
    96 		break;
    97 	case EMMFPolicyGetPlayFormatsSupported:
    98 		complete = GetPlayFormatsSupportedL(aMessage);
    99 		break;
   100 	case EMMFPolicyGetRecordFormatsSupported:
   101 		complete = GetRecordFormatsSupportedL(aMessage);
   102 		break;
   103 	case EMMFPolicyGetPlayFormat:
   104 		complete = GetPlayFormatL(aMessage);
   105 		break;
   106 	case EMMFPolicyGetRecordFormat:
   107 		complete = GetRecordFormatL(aMessage);
   108 		break;
   109 	case EMMFPolicyLaunchRequests:
   110 		complete = LaunchRequest();
   111 		break;
   112 	case EMMFPolicyRequestResourceNotification:
   113 		complete = RequestResourceNotificationL(aMessage);
   114 		break;
   115 	case EMMFPolicyCancelRequestResourceNotification:
   116 		complete = CancelRequestResourceNotificationL(aMessage);
   117 		break;
   118 	case EMMFPolicyStopNotification:
   119 		complete = StopNotificationL(aMessage);
   120 		break;
   121 	case EMMFPolicyGetResourceNotificationEvent:
   122 		complete = GetResourceNotificationEventL(aMessage);
   123 		break;
   124 	default:
   125 		User::Leave(KErrNotSupported);
   126 		break;
   127 		}
   128 	if(complete)
   129 		{
   130 		aMessage.Complete(KErrNone);
   131 		}
   132 	}
   133 
   134 void CMMFAudioPolicySession::MakeRequestL(const RMmfIpcMessage& aMessage)
   135 	{
   136 	TMMFAudioPolicyPrioritySettingsPckg settingsPckg;
   137 	MmfMessageUtil::ReadL(aMessage, 0, settingsPckg);
   138 
   139 	iAudioPolicyRequest->SetPriority(settingsPckg().iPriority);
   140 	iAudioPolicyRequest->SetPref(settingsPckg().iPref);
   141 	iAudioPolicyRequest->SetState(settingsPckg().iState);
   142 
   143 	iAudioPolicyRequest->SetCapabilities(settingsPckg().iCapabilities);
   144 	
   145 	// Set session Id in Request
   146 	iAudioPolicyRequest->SetPolicySessionId(iPolicySessionId);
   147 	iAudioPolicy->MakeRequest(iAudioPolicyRequest);
   148 	}
   149 
   150 TBool CMMFAudioPolicySession::UpdateStateL(const RMmfIpcMessage& aMessage)
   151 	{
   152 	TMMFAudioPolicyPrioritySettingsPckg settingsPckg;
   153 	MmfMessageUtil::ReadL(aMessage, 0, settingsPckg);
   154 
   155 	iAudioPolicyRequest->SetState(settingsPckg().iState);
   156 	iAudioPolicy->ModifyEntry(iPolicySessionId, iAudioPolicyRequest); 
   157 	return ETrue;
   158 	}
   159 
   160 void CMMFAudioPolicySession::SendEventToClient(TMMFAudioPolicyEvent& aEvent)
   161 	{
   162 	if (iEventReceiver)
   163 		{
   164 		iEventReceiver->SendEvent(aEvent);
   165 		delete iEventReceiver;
   166 		iEventReceiver=NULL;
   167 		}
   168 	else 
   169 		{
   170 		TMMFAudioPolicyEventHolder* heldEvent = new TMMFAudioPolicyEventHolder(aEvent);
   171 		iEventsQue.AddLast(*heldEvent);
   172 		}
   173 	}
   174 
   175 TBool CMMFAudioPolicySession::SetDevSoundInfoL(const RMmfIpcMessage& aMessage)
   176 	{
   177 	TMMFDevSoundInfoPckg devSoundInfoPckg;
   178 	MmfMessageUtil::ReadL(aMessage, 0, devSoundInfoPckg);
   179 	iDevSoundId = devSoundInfoPckg().iDevSoundId;
   180 	return ETrue;
   181 	}
   182 
   183 TBool CMMFAudioPolicySession::ReceiveEventsL(const RMmfIpcMessage& aMessage)
   184 	{
   185 	if (iEventReceiver)
   186 		User::Leave(KErrAlreadyExists);
   187 	iEventReceiver = CMMFAudioPolicyEventReceiver::NewL(aMessage);
   188 	//send the next cached event (if any) to the client
   189 	if (!iEventsQue.IsEmpty())
   190 		{
   191 		TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First();
   192 		iEventReceiver->SendEvent(heldEvent->iEvent);
   193 		iEventsQue.Remove(*heldEvent);
   194 		delete iEventReceiver;
   195 		iEventReceiver=NULL;
   196 		}
   197 	return EFalse;
   198 	}
   199 
   200 TBool CMMFAudioPolicySession::CancelReceiveEvents()
   201 	{
   202 	delete iEventReceiver;
   203 	iEventReceiver = NULL;
   204 	return ETrue;
   205 	}
   206 
   207 TBool CMMFAudioPolicySession::GetPlayFormatsSupportedL(const RMmfIpcMessage& aMessage)
   208 	{
   209 	RMdaDevSound::TSoundFormatsSupportedBuf aPlayFormatsSupported;
   210 	aPlayFormatsSupported = iAudioPolicy->MdaHwInfo()->GetPlayFormatsSupported();
   211 	MmfMessageUtil::WriteL(aMessage, 0, aPlayFormatsSupported);
   212 	return ETrue;
   213 	}
   214 
   215 TBool CMMFAudioPolicySession::GetRecordFormatsSupportedL(const RMmfIpcMessage& aMessage)
   216 	{
   217 	RMdaDevSound::TSoundFormatsSupportedBuf aRecordFormatsSupported;
   218 	aRecordFormatsSupported = iAudioPolicy->MdaHwInfo()->GetRecordFormatsSupported();
   219 	MmfMessageUtil::WriteL(aMessage, 0, aRecordFormatsSupported);
   220 	return ETrue;
   221 	}
   222 
   223 TBool CMMFAudioPolicySession::GetPlayFormatL(const RMmfIpcMessage& aMessage)
   224 	{
   225 	RMdaDevSound::TCurrentSoundFormatBuf aPlayFormat;
   226 	aPlayFormat = iAudioPolicy->MdaHwInfo()->GetPlayFormat();
   227 	MmfMessageUtil::WriteL(aMessage, 0, aPlayFormat);
   228 	return ETrue;
   229 	}
   230 
   231 TBool CMMFAudioPolicySession::GetRecordFormatL(const RMmfIpcMessage& aMessage)
   232 	{
   233 	RMdaDevSound::TCurrentSoundFormatBuf aRecordFormat;
   234 	aRecordFormat = iAudioPolicy->MdaHwInfo()->GetRecordFormat();
   235 	MmfMessageUtil::WriteL(aMessage, 0, aRecordFormat);
   236 	return ETrue;
   237 	}
   238 
   239 TBool CMMFAudioPolicySession::LaunchRequest()
   240 	{
   241 	iAudioPolicy->LaunchRequest();
   242 	return ETrue;
   243 	}
   244 	
   245 TBool CMMFAudioPolicySession::RequestResourceNotificationL(const RMmfIpcMessage& aMessage)
   246 	{
   247 	TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
   248 	MmfMessageUtil::ReadL(aMessage, 0, notificationPckg);
   249 	iAudioPolicyRequest->SetNotificationEvent(notificationPckg().iNotificationUid);
   250 	iAudioPolicy->SetNotification(iPolicySessionId,notificationPckg().iNotificationUid);
   251 	return ETrue;
   252 	}
   253 
   254 TBool CMMFAudioPolicySession::CancelRequestResourceNotificationL(const RMmfIpcMessage& aMessage)
   255 	{
   256 	if(iServer->IsTimerActive() == EFalse)
   257 		{
   258 		iServer->StartNotificationTimer();
   259 		}
   260 	TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
   261 	MmfMessageUtil::ReadL(aMessage, 0, notificationPckg);
   262 	iAudioPolicyRequest->ResetNotificationEvent(notificationPckg().iNotificationUid);
   263 	iAudioPolicy->SetNotification(iPolicySessionId,KNullUid);
   264 	return ETrue;
   265 	}
   266 
   267 TBool CMMFAudioPolicySession::StopNotificationL(const RMmfIpcMessage& /*aMessage*/)
   268 	{
   269 	iServer->StopNotificationTimer();
   270 	return ETrue;
   271 	}
   272 	
   273 TBool CMMFAudioPolicySession::GetResourceNotificationEventL(const RMmfIpcMessage& aMessage)
   274 	{
   275 	TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
   276 	notificationPckg().iNotificationUid = iAudioPolicyRequest->NotificationEvent();
   277 	MmfMessageUtil::WriteL(aMessage, 0, notificationPckg);
   278 	return ETrue;
   279 	}
   280 	
   281 CMMFAudioPolicyEventReceiver* CMMFAudioPolicyEventReceiver::NewL(const RMmfIpcMessage& aMessage)
   282 	{
   283 	return new(ELeave) CMMFAudioPolicyEventReceiver(aMessage);
   284 	}
   285 
   286 CMMFAudioPolicyEventReceiver::~CMMFAudioPolicyEventReceiver()
   287 	{
   288 	if (iNeedToCompleteMessage)
   289 		iMessage.Complete(KErrDied);
   290 	}
   291 
   292 void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFAudioPolicyEvent& aEvent)
   293 	{
   294 	TMMFAudioPolicyEventPckg eventpckg(aEvent);
   295 	TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg);
   296 	iMessage.Complete(err);
   297 	iNeedToCompleteMessage = EFalse;			
   298 	}
   299 	
   300 void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFEvent& aEvent)
   301 	{
   302 	TMMFEventPckg eventpckg(aEvent);
   303 	TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg);
   304 	iMessage.Complete(err);
   305 	iNeedToCompleteMessage = EFalse;
   306 	}
   307 
   308 CMMFAudioPolicyEventReceiver::CMMFAudioPolicyEventReceiver(const RMmfIpcMessage& aMessage) : 
   309 	iMessage(aMessage), iNeedToCompleteMessage(ETrue)
   310 	{
   311 	}