os/mm/devsound/devsoundrefplugin/src/server/Policy/MmfAudioPolicyProxy.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 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 <f32file.h>
    17 #include <e32math.h>
    18 #include "mmfAudioPolicyProxy.h"
    19 #include "MmfAudioPolicyStart.h"
    20 #include "MmfBase.hrh"
    21 #include "MmfDevSoundInfo.h"
    22 #include "MmfAudioPolicyServer.h"
    23 
    24 
    25 
    26 EXPORT_C TInt RMMFAudioPolicyProxy::Open(RServer2& aPolicyServerHandle)
    27 	{
    28 	ASSERT(aPolicyServerHandle.Handle());
    29 	
    30 	// Server is already running and attempt to create a session
    31 	// 4 message slots
    32 	TInt err = CreateSession(aPolicyServerHandle, TVersion(KMMFAudioPolicyVersion,
    33 													KMMFAudioPolicyMinorVersionNumber,
    34 													KMMFAudioPolicyBuildVersionNumber));		
    35 	return err;		
    36 	}
    37 
    38 EXPORT_C TInt RMMFAudioPolicyProxy::CreateServer(RServer2& aPolicyServerHandle)
    39 	{
    40 	TServerStart start(aPolicyServerHandle);
    41 	TThreadFunction serverFunc = CMMFAudioPolicyServer::StartThread;
    42 	RThread server;
    43 	TInt err = server.Create(_L(""),serverFunc, KAudioPolicyServerStackSize,
    44 							KAudioPolicyServerInitHeapSize, KAudioPolicyServerMaxHeapSize,
    45 							&start, EOwnerProcess);
    46 	if(err != KErrNone)
    47 		{
    48 		return err;
    49 		}		
    50 		// Synchronise with the server
    51 	TRequestStatus reqStatus;
    52 	server.Rendezvous(reqStatus);
    53 	if (reqStatus!=KRequestPending)
    54 		{
    55 		server.Kill(0);
    56 		}
    57 	else 
    58 		{
    59 		// Start the test harness
    60 		server.Resume();
    61 		// Server will call the reciprocal static synchronise call
    62 		}
    63 	User::WaitForRequest(reqStatus); // wait for start or death
    64 	server.Close();
    65 	if(reqStatus.Int() != KErrNone)
    66 		{
    67 		return reqStatus.Int();
    68 		}
    69 	return err;		
    70 	}
    71 
    72 EXPORT_C TInt RMMFAudioPolicyProxy::SetDevSoundInfo(TMMFDevSoundInfo& aDevSoundInfo)
    73 	{
    74 	TMMFDevSoundInfoPckg psPckg(aDevSoundInfo);
    75 	return SendReceive(EMMFPolicySetDevSoundInfo, psPckg);
    76 	}
    77 
    78 EXPORT_C void RMMFAudioPolicyProxy::MakeRequest(TMMFAudioPolicyPrioritySettings& aPrioritySettings)
    79 	{
    80 	iPsPckg().iState = aPrioritySettings.iState;
    81 	iPsPckg().iPref = aPrioritySettings.iPref;
    82 	iPsPckg().iPriority = aPrioritySettings.iPriority;
    83 	iPsPckg().iCapabilities = aPrioritySettings.iCapabilities;
    84 	SendReceive(EMMFPolicyMakeRequest, iPsPckg);
    85 	}
    86 
    87 EXPORT_C TInt RMMFAudioPolicyProxy::UpdateState(TMMFAudioPolicyPrioritySettings& aPrioritySettings)
    88 	{
    89 	TMMFAudioPolicyPrioritySettingsPckg psPckg(aPrioritySettings);
    90 	return SendReceive(EMMFPolicyUpdateState, psPckg);
    91 	}
    92 
    93 EXPORT_C void RMMFAudioPolicyProxy::ReceiveEvents(TMMFAudioPolicyEventPckg& aEventPckg, TRequestStatus& aStatus)
    94 	{
    95 	SendReceiveResult(EMMFPolicyReceiveEvents, aEventPckg, aStatus);
    96 	}
    97 
    98 EXPORT_C TInt RMMFAudioPolicyProxy::CancelReceiveEvents()
    99 	{
   100 	return SendReceive(EMMFPolicyCancelReceiveEvents);
   101 	}
   102 
   103 EXPORT_C TInt RMMFAudioPolicyProxy::GetPlayFormatsSupported(RMdaDevSound::TSoundFormatsSupportedBuf& aPlayFormatsSupported) 
   104 	{
   105 	RMdaDevSound::TSoundFormatsSupportedBuf playFormatsSupported;
   106 	TInt err = SendReceiveResult(EMMFPolicyGetPlayFormatsSupported, playFormatsSupported);
   107 	if (!err)
   108 		aPlayFormatsSupported = playFormatsSupported;
   109 	return  err;
   110 	}
   111 
   112 EXPORT_C TInt RMMFAudioPolicyProxy::GetRecordFormatsSupported(RMdaDevSound::TSoundFormatsSupportedBuf& aRecordFormatsSupported) 
   113 	{
   114 	RMdaDevSound::TSoundFormatsSupportedBuf recordFormatsSupported;
   115 	TInt err = SendReceiveResult(EMMFPolicyGetRecordFormatsSupported, recordFormatsSupported);
   116 	if (!err)
   117 		aRecordFormatsSupported = recordFormatsSupported;
   118 	return  err;
   119 	}
   120 
   121 EXPORT_C TInt RMMFAudioPolicyProxy::GetPlayFormat(RMdaDevSound::TCurrentSoundFormatBuf& aPlayFormat) 
   122 	{
   123 	RMdaDevSound::TCurrentSoundFormatBuf playFormat;
   124 	TInt err = SendReceiveResult(EMMFPolicyGetPlayFormat, playFormat);
   125 	if (!err)
   126 		aPlayFormat = playFormat;
   127 	return  err;
   128 	}
   129 
   130 EXPORT_C TInt RMMFAudioPolicyProxy::GetRecordFormat(RMdaDevSound::TCurrentSoundFormatBuf& aRecordFormat) 
   131 	{
   132 	RMdaDevSound::TCurrentSoundFormatBuf recordFormat;
   133 	TInt err = SendReceiveResult(EMMFPolicyGetRecordFormat, recordFormat);
   134 	if (!err)
   135 		aRecordFormat = recordFormat;
   136 	return  err;
   137 	}
   138 
   139 EXPORT_C TInt RMMFAudioPolicyProxy::LaunchRequests()
   140 	{
   141 	return SendReceive(EMMFPolicyLaunchRequests);
   142 	}
   143 
   144 EXPORT_C TInt RMMFAudioPolicyProxy::RequestResourceNotification(TUid aNotificationEventUid, const TDesC8& aNotificationDelay)
   145 	{
   146 	TUid eventType = KNullUid;
   147 	TMMFAudioPolicyResourceNotificationSettingsPckg pckg;
   148 	pckg().iNotificationUid = eventType;
   149 	TInt err = SendReceiveResult(EMMFPolicyGetResourceNotificationEvent, pckg);
   150 	eventType = pckg().iNotificationUid;
   151 	if(!err)
   152 		{
   153 		if(eventType != aNotificationEventUid )
   154 			{
   155 			pckg().iNotificationUid = aNotificationEventUid;
   156 			pckg().iNotificationDelay = aNotificationDelay;
   157 			return SendReceive(EMMFPolicyRequestResourceNotification, pckg);		
   158 			}
   159 		else
   160 			{
   161 			return KErrAlreadyExists;
   162 			}
   163 		}
   164 	return err;	
   165 	}
   166 	
   167 EXPORT_C TInt RMMFAudioPolicyProxy::CancelRequestResourceNotification(TUid aNotificationEventUid)
   168 	{
   169 	TUid eventType = KNullUid;
   170 	TMMFAudioPolicyResourceNotificationSettingsPckg pckg;
   171 	pckg().iNotificationUid = eventType;
   172 	TInt err = SendReceiveResult(EMMFPolicyGetResourceNotificationEvent, pckg);
   173 	eventType = pckg().iNotificationUid;
   174 	if(!err)
   175 		{
   176 		if(eventType == aNotificationEventUid )
   177 			{
   178 			pckg().iNotificationUid = aNotificationEventUid;
   179 			return SendReceive(EMMFPolicyCancelRequestResourceNotification, pckg);	
   180 			}
   181 		else
   182 			{
   183 			return KErrCancel;
   184 			}
   185 		}
   186 	return err;
   187 	}
   188 	
   189 EXPORT_C TInt RMMFAudioPolicyProxy::StopNotification()
   190 	{
   191 	return SendReceive(EMMFPolicyStopNotification);
   192 	}
   193 
   194 EXPORT_C TInt RMMFAudioPolicyProxy::IsRegisteredResourceNotification(TUid aEventType)
   195 	{
   196 	TUid eventType = KNullUid;
   197 	TMMFAudioPolicyResourceNotificationSettingsPckg pckg;
   198 	pckg().iNotificationUid = eventType;
   199 	TInt err = SendReceiveResult(EMMFPolicyGetResourceNotificationEvent, pckg);
   200 	if(err != KErrNone)
   201 		{
   202 		return err;
   203 		}
   204 	eventType = pckg().iNotificationUid;
   205 	if(eventType == aEventType)
   206 		{
   207 		return KErrNone;
   208 		}
   209 	return KErrNotSupported;
   210 	}
   211