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