os/mm/devsound/sounddevbt/src/server/Policy/MmfBtAudioPolicyProxy.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/MmfBtAudioPolicyProxy.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,217 @@
     1.4 +// Copyright (c) 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 <f32file.h>
    1.20 +#include <e32math.h>
    1.21 +#include "MmfBtAudioPolicyProxy.h"
    1.22 +#include "MmfBtAudioPolicyStart.h"
    1.23 +#include "../../../inc/common/mmfBtBase.hrh"
    1.24 +#include "mdasound.h"
    1.25 +#include "MmfBtDevSoundInfo.h"
    1.26 +#include "MmfBtAudioPolicyServer.h"
    1.27 +
    1.28 +
    1.29 +
    1.30 +EXPORT_C TInt RMMFAudioPolicyProxy::Open(RServer2& aPolicyServerHandle)
    1.31 +	{
    1.32 +	TServerStart start(aPolicyServerHandle);
    1.33 +	TInt err = KErrNone;
    1.34 +	if(aPolicyServerHandle.Handle())
    1.35 +		{
    1.36 +		// Server is already running and attempt to create a session
    1.37 +		// 4 message slots
    1.38 +		err = CreateSession(aPolicyServerHandle, TVersion(KMMFAudioPolicyVersion,
    1.39 +														KMMFAudioPolicyMinorVersionNumber,
    1.40 +														KMMFAudioPolicyBuildVersionNumber));
    1.41 +		if(err != KErrNone)
    1.42 +			{
    1.43 +			return err;	
    1.44 +			}
    1.45 +		}
    1.46 +	else
    1.47 +		{
    1.48 +		TThreadFunction serverFunc = CMMFAudioPolicyServer::StartThread;
    1.49 +		RThread server;
    1.50 +		err = server.Create(_L(""),serverFunc, KAudioPolicyServerStackSize,
    1.51 +						KAudioPolicyServerInitHeapSize, KAudioPolicyServerMaxHeapSize,
    1.52 +						&start, EOwnerProcess);
    1.53 +		if(err != KErrNone)
    1.54 +			return err;
    1.55 +			// Synchronise with the server
    1.56 +		TRequestStatus reqStatus;
    1.57 +		server.Rendezvous(reqStatus);
    1.58 +		if (reqStatus!=KRequestPending)
    1.59 +			{
    1.60 +			server.Kill(0);
    1.61 +			}
    1.62 +		else 
    1.63 +			{
    1.64 +			// Start the test harness
    1.65 +			server.Resume();
    1.66 +			// Server will call the reciprocal static synchronise call
    1.67 +			}
    1.68 +		User::WaitForRequest(reqStatus); // wait for start or death
    1.69 +		server.Close();
    1.70 +		if(reqStatus.Int() != KErrNone)
    1.71 +			{
    1.72 +			return reqStatus.Int();
    1.73 +			}
    1.74 +		err = CreateSession(aPolicyServerHandle, TVersion(KMMFAudioPolicyVersion,
    1.75 +								 KMMFAudioPolicyMinorVersionNumber,
    1.76 +								 KMMFAudioPolicyBuildVersionNumber));
    1.77 +		}
    1.78 +	return err;		
    1.79 +	}
    1.80 +
    1.81 +EXPORT_C TInt RMMFAudioPolicyProxy::SetDevSoundInfo(TMMFDevSoundInfo& aDevSoundInfo)
    1.82 +	{
    1.83 +	TMMFDevSoundInfoPckg psPckg(aDevSoundInfo);
    1.84 +	return SendReceive(EMMFPolicySetDevSoundInfo, psPckg);
    1.85 +	}
    1.86 +
    1.87 +EXPORT_C void RMMFAudioPolicyProxy::MakeRequest(TMMFAudioPolicyPrioritySettings& aPrioritySettings)
    1.88 +	{
    1.89 +	iPsPckg().iState = aPrioritySettings.iState;
    1.90 +	iPsPckg().iPref = aPrioritySettings.iPref;
    1.91 +	iPsPckg().iPriority = aPrioritySettings.iPriority;
    1.92 +	iPsPckg().iCapabilities = aPrioritySettings.iCapabilities;
    1.93 +	SendReceive(EMMFPolicyMakeRequest, iPsPckg);
    1.94 +	}
    1.95 +
    1.96 +EXPORT_C TInt RMMFAudioPolicyProxy::UpdateState(TMMFAudioPolicyPrioritySettings& aPrioritySettings)
    1.97 +	{
    1.98 +	TMMFAudioPolicyPrioritySettingsPckg psPckg(aPrioritySettings);
    1.99 +	return SendReceive(EMMFPolicyUpdateState, psPckg);
   1.100 +	}
   1.101 +
   1.102 +EXPORT_C void RMMFAudioPolicyProxy::ReceiveEvents(TMMFAudioPolicyEventPckg& aEventPckg, TRequestStatus& aStatus)
   1.103 +	{
   1.104 +	SendReceiveResult(EMMFPolicyReceiveEvents, aEventPckg, aStatus);
   1.105 +	}
   1.106 +
   1.107 +EXPORT_C TInt RMMFAudioPolicyProxy::CancelReceiveEvents()
   1.108 +	{
   1.109 +	return SendReceive(EMMFPolicyCancelReceiveEvents);
   1.110 +	}
   1.111 +
   1.112 +EXPORT_C TInt RMMFAudioPolicyProxy::GetPlayFormatsSupported(RMdaDevSound::TSoundFormatsSupportedBuf& aPlayFormatsSupported) 
   1.113 +	{
   1.114 +	RMdaDevSound::TSoundFormatsSupportedBuf playFormatsSupported;
   1.115 +	TInt err = SendReceiveResult(EMMFPolicyGetPlayFormatsSupported, playFormatsSupported);
   1.116 +	if (!err)
   1.117 +		aPlayFormatsSupported = playFormatsSupported;
   1.118 +	return  err;
   1.119 +	}
   1.120 +
   1.121 +EXPORT_C TInt RMMFAudioPolicyProxy::GetRecordFormatsSupported(RMdaDevSound::TSoundFormatsSupportedBuf& aRecordFormatsSupported) 
   1.122 +	{
   1.123 +	RMdaDevSound::TSoundFormatsSupportedBuf recordFormatsSupported;
   1.124 +	TInt err = SendReceiveResult(EMMFPolicyGetRecordFormatsSupported, recordFormatsSupported);
   1.125 +	if (!err)
   1.126 +		aRecordFormatsSupported = recordFormatsSupported;
   1.127 +	return  err;
   1.128 +	}
   1.129 +
   1.130 +EXPORT_C TInt RMMFAudioPolicyProxy::GetPlayFormat(RMdaDevSound::TCurrentSoundFormatBuf& aPlayFormat) 
   1.131 +	{
   1.132 +	RMdaDevSound::TCurrentSoundFormatBuf playFormat;
   1.133 +	TInt err = SendReceiveResult(EMMFPolicyGetPlayFormat, playFormat);
   1.134 +	if (!err)
   1.135 +		aPlayFormat = playFormat;
   1.136 +	return  err;
   1.137 +	}
   1.138 +
   1.139 +EXPORT_C TInt RMMFAudioPolicyProxy::GetRecordFormat(RMdaDevSound::TCurrentSoundFormatBuf& aRecordFormat) 
   1.140 +	{
   1.141 +	RMdaDevSound::TCurrentSoundFormatBuf recordFormat;
   1.142 +	TInt err = SendReceiveResult(EMMFPolicyGetRecordFormat, recordFormat);
   1.143 +	if (!err)
   1.144 +		aRecordFormat = recordFormat;
   1.145 +	return  err;
   1.146 +	}
   1.147 +
   1.148 +EXPORT_C TInt RMMFAudioPolicyProxy::LaunchRequests()
   1.149 +	{
   1.150 +	return SendReceive(EMMFPolicyLaunchRequests);
   1.151 +	}
   1.152 +
   1.153 +EXPORT_C TInt RMMFAudioPolicyProxy::RequestResourceNotification(TUid aNotificationEventUid, const TDesC8& aNotificationDelay)
   1.154 +	{
   1.155 +	TUid eventType = KNullUid;
   1.156 +	TMMFAudioPolicyResourceNotificationSettingsPckg pckg;
   1.157 +	pckg().iNotificationUid = eventType;
   1.158 +	TInt err = SendReceiveResult(EMMFPolicyGetResourceNotificationEvent, pckg);
   1.159 +	eventType = pckg().iNotificationUid;
   1.160 +	if(!err)
   1.161 +		{
   1.162 +		if(eventType != aNotificationEventUid )
   1.163 +			{
   1.164 +			pckg().iNotificationUid = aNotificationEventUid;
   1.165 +			pckg().iNotificationDelay = aNotificationDelay;
   1.166 +			return SendReceive(EMMFPolicyRequestResourceNotification, pckg);		
   1.167 +			}
   1.168 +		else
   1.169 +			{
   1.170 +			return KErrAlreadyExists;
   1.171 +			}
   1.172 +		}
   1.173 +	return err;	
   1.174 +	}
   1.175 +	
   1.176 +EXPORT_C TInt RMMFAudioPolicyProxy::CancelRequestResourceNotification(TUid aNotificationEventUid)
   1.177 +	{
   1.178 +	TUid eventType = KNullUid;
   1.179 +	TMMFAudioPolicyResourceNotificationSettingsPckg pckg;
   1.180 +	pckg().iNotificationUid = eventType;
   1.181 +	TInt err = SendReceiveResult(EMMFPolicyGetResourceNotificationEvent, pckg);
   1.182 +	eventType = pckg().iNotificationUid;
   1.183 +	if(!err)
   1.184 +		{
   1.185 +		if(eventType == aNotificationEventUid )
   1.186 +			{
   1.187 +			pckg().iNotificationUid = aNotificationEventUid;
   1.188 +			return SendReceive(EMMFPolicyCancelRequestResourceNotification, pckg);	
   1.189 +			}
   1.190 +		else
   1.191 +			{
   1.192 +			return KErrCancel;
   1.193 +			}
   1.194 +		}
   1.195 +	return err;
   1.196 +	}
   1.197 +	
   1.198 +EXPORT_C TInt RMMFAudioPolicyProxy::StopNotification()
   1.199 +	{
   1.200 +	return SendReceive(EMMFPolicyStopNotification);
   1.201 +	}
   1.202 +
   1.203 +EXPORT_C TInt RMMFAudioPolicyProxy::IsRegisteredResourceNotification(TUid aEventType)
   1.204 +	{
   1.205 +	TUid eventType = KNullUid;
   1.206 +	TMMFAudioPolicyResourceNotificationSettingsPckg pckg;
   1.207 +	pckg().iNotificationUid = eventType;
   1.208 +	TInt err = SendReceiveResult(EMMFPolicyGetResourceNotificationEvent, pckg);
   1.209 +	if(err != KErrNone)
   1.210 +		{
   1.211 +		return err;
   1.212 +		}
   1.213 +	eventType = pckg().iNotificationUid;
   1.214 +	if(eventType == aEventType)
   1.215 +		{
   1.216 +		return KErrNone;
   1.217 +		}
   1.218 +	return KErrNotSupported;
   1.219 +	}
   1.220 +