os/mm/devsound/a3fdevsound/src/mmfdevsoundserver/mmfdevsoundsession.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/a3fdevsound/src/mmfdevsoundserver/mmfdevsoundsession.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2710 @@
     1.4 +// Copyright (c) 2006-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 <s32mem.h>
    1.20 +#include "mmfaudioclientserver.h"
    1.21 +#include "mmfaudioserver.h"
    1.22 +#include "mmfdevsoundserver.h"
    1.23 +#include "mmfdevsoundsession.h"
    1.24 +#include <mmf/plugin/mmfdevsoundcustominterface.hrh>
    1.25 +#include <mm/mmpluginutils.h>
    1.26 +#ifdef _DEBUG
    1.27 +#include "e32debug.h"
    1.28 +
    1.29 +#define SYMBIAN_DEBPRN0(str)                RDebug::Print(str, this)
    1.30 +#define SYMBIAN_DEBPRN1(str, val1)          RDebug::Print(str, this, val1)
    1.31 +#define SYMBIAN_DEBPRN2(str, val1, val2)    RDebug::Print(str, this, val1, val2)
    1.32 +#define SYMBIAN_DEBPRN3(str, val1, val2, val3)    RDebug::Print(str, this, val1, val2, val3)
    1.33 +#else
    1.34 +#define SYMBIAN_DEBPRN0(str)
    1.35 +#define SYMBIAN_DEBPRN1(str, val1)
    1.36 +#define SYMBIAN_DEBPRN2(str, val1, val2)
    1.37 +#define SYMBIAN_DEBPRN3(str, val1, val2, val3)
    1.38 +#endif //_DEBUG
    1.39 +
    1.40 +const TInt KMaxQueueRequest = 6;
    1.41 +
    1.42 +//	MEMBER FUNCTIONS 
    1.43 +
    1.44 +TMMFDevSoundRequest::TMMFDevSoundRequest() 
    1.45 +	: iMessageCompleted(EFalse), 
    1.46 +	iRequestType(EUndefinedType),
    1.47 +	iCallBackPF(KCallbackNone)
    1.48 +	{
    1.49 +	}
    1.50 +
    1.51 +TMMFDevSoundRequest::TMMFDevSoundRequest(TInt aIsCallBack)
    1.52 +	: iMessageCompleted(EFalse), 
    1.53 +	iRequestType(ECallBackType),
    1.54 +	iCallBackPF(aIsCallBack)
    1.55 +	{
    1.56 +	}
    1.57 +
    1.58 +TMMFDevSoundRequest::TMMFDevSoundRequest(const TMMFDevSoundRequest& aRequest)
    1.59 +	: iMessageCompleted(EFalse), 
    1.60 +	iMessage(aRequest.iMessage),
    1.61 +	iCallBackPF(aRequest.iCallBackPF)
    1.62 +	{
    1.63 +	iRequestType = ResolveType();
    1.64 +	}
    1.65 +
    1.66 +TBool TMMFDevSoundRequest::operator==(const TMMFDevSoundRequest& aRequest) const
    1.67 +	{
    1.68 +	TBool retval = EFalse;
    1.69 +	if ( aRequest.Function() == Function() )
    1.70 +		{
    1.71 +		retval = ETrue;
    1.72 +		}
    1.73 +	else
    1.74 +		{
    1.75 +		retval = EFalse;
    1.76 +		}
    1.77 +	return retval;
    1.78 +	}
    1.79 +
    1.80 +const RMmfIpcMessage& TMMFDevSoundRequest::Message() 
    1.81 +	{ 
    1.82 +	return iMessage; 
    1.83 +	}
    1.84 +
    1.85 +void TMMFDevSoundRequest::SetMessage(const RMmfIpcMessage& aMessage) 
    1.86 +	{
    1.87 +	iMessageCompleted = EFalse;
    1.88 +	iMessage = aMessage;
    1.89 +	iRequestType = ResolveType();
    1.90 +	}
    1.91 +	
    1.92 +void TMMFDevSoundRequest::SetMessageCallback() 
    1.93 +	{
    1.94 +	iMessageCompleted = EFalse;
    1.95 +	iRequestType = ECallBackType;
    1.96 +	}	
    1.97 +
    1.98 +TInt TMMFDevSoundRequest::IsCallBack() const
    1.99 +	{
   1.100 +	return iCallBackPF;	
   1.101 +	}
   1.102 +
   1.103 +TMMFDevSoundRequest::TA3FDevSoundRequestType TMMFDevSoundRequest::ResolveType()
   1.104 +	{
   1.105 +	TA3FDevSoundRequestType type = EUndefinedType;
   1.106 +	switch(iMessage.Function())
   1.107 +		{
   1.108 +		case EMMFDevSoundProxyInitialize1:
   1.109 +		case EMMFDevSoundProxyInitialize2:
   1.110 +		case EMMFDevSoundProxyInitialize4:
   1.111 +		case EMMFDevSoundProxyPlayInit:
   1.112 +		case EMMFDevSoundProxyRecordInit:
   1.113 +		case EMMFDevSoundProxyPlayTone:
   1.114 +		case EMMFDevSoundProxyPlayDualTone:
   1.115 +		case EMMFDevSoundProxyPlayDTMFString:
   1.116 +		case EMMFDevSoundProxyPlayToneSequence:
   1.117 +		case EMMFDevSoundProxyPlayFixedSequence:
   1.118 +			type = EAction_PseudoAsynchronous;
   1.119 +			break;
   1.120 +
   1.121 +		case EMMFDevSoundProxyStop:
   1.122 +		case EMMFDevSoundProxyPause:
   1.123 +		case EMMFDevSoundProxyClose:
   1.124 +		case EMMFDevSoundProxyCancelInitialize:
   1.125 +		case EMMFDevSoundProxyResume:
   1.126 +		case EMMFDevSoundProxyEmptyBuffers:
   1.127 +			type = EAction_Asynchronous;
   1.128 +			break;
   1.129 +
   1.130 +		case EMMFDevSoundProxySetConfig:
   1.131 +		case EMMFDevSoundProxyPostOpen: // Although this is not a configure operation technically, it has same calling pattern.
   1.132 +		case EMMFDevSoundProxySetVolume:
   1.133 +		case EMMFDevSoundProxySetGain:
   1.134 +		case EMMFDevSoundProxySetPlayBalance:
   1.135 +		case EMMFDevSoundProxySetRecordBalance:
   1.136 +		case EMMFDevSoundProxySetVolumeRamp:
   1.137 +		case EMMFDevSoundProxySetPrioritySettings:
   1.138 +			type = EConfigure_Asynchronous;
   1.139 +			break;
   1.140 +			
   1.141 +		case EMMFDevSoundProxySetDTMFLengths:
   1.142 +		case EMMFDevSoundProxySetToneRepeats:
   1.143 +			type = EConfigure_Synchronous;	
   1.144 +			break;
   1.145 +		case EMMFDevSoundProxyCapabilities:
   1.146 +			type = EQuery_Asynchronous;
   1.147 +			break;
   1.148 +		case EMMFDevSoundProxyMaxVolume:
   1.149 +		case EMMFDevSoundProxyMaxGain:
   1.150 +		case EMMFDevSoundProxyConfig:
   1.151 +		case EMMFDevSoundProxyVolume:
   1.152 +		case EMMFDevSoundProxyGain:
   1.153 +		case EMMFDevSoundProxyPlayBalance:
   1.154 +		case EMMFDevSoundProxyRecordBalance:
   1.155 +		case EMMFDevSoundProxyGetSupportedInputDataTypes:
   1.156 +		case EMMFDevSoundProxyGetSupportedOutputDataTypes:
   1.157 +		case EMMFDevSoundProxyFixedSequenceName:
   1.158 +		case EMMFDevSoundProxyFixedSequenceCount:
   1.159 +		case EMMFDevSoundProxySamplesRecorded:
   1.160 +		case EMMFDevSoundProxySamplesPlayed:
   1.161 +		case EMMFDevSoundProxyCopyFourCCArrayData:
   1.162 +		case EMMFDevSoundProxyGetTimePlayed:
   1.163 +		case EMMFDevSoundProxyIsResumeSupported:
   1.164 +			type = EQuery_Synchronous;
   1.165 +			break;
   1.166 +		
   1.167 +		case EMMFDevSoundProxyBTBFData:
   1.168 +		case EMMFDevSoundProxyBTBEData:
   1.169 +		case EMMFDevSoundProxyPlayData:
   1.170 +		case EMMFDevSoundProxyRecordData:
   1.171 +			type = EBufferExchangeRelated;
   1.172 +			break;
   1.173 +
   1.174 +		// Custom Interfaces
   1.175 +		case EMMFDevSoundProxySyncCustomCommand:
   1.176 +		case EMMFDevSoundProxySyncCustomCommandResult:
   1.177 +		case EMMFDevSoundProxyAsyncCustomCommand:
   1.178 +		case EMMFDevSoundProxyAsyncCustomCommandResult:
   1.179 +		case EMMFDevSoundProxyCustomInterface:
   1.180 +			type = ECustomInterfacesRelated;
   1.181 +			break;
   1.182 +		case RMessage2::EDisConnect:
   1.183 +			type = ESessionEvents;
   1.184 +			break;
   1.185 +		default:
   1.186 +			break;
   1.187 +		}
   1.188 +	return type;
   1.189 +	}
   1.190 +
   1.191 +
   1.192 +void TMMFDevSoundRequest::Complete(TInt aError)	
   1.193 +	{
   1.194 +	if(!iMessageCompleted && iRequestType != EUndefinedType && iRequestType != ECallBackType)	
   1.195 +		{
   1.196 +		iMessage.Complete(aError);
   1.197 +		iMessageCompleted = ETrue;
   1.198 +		iRequestType = EUndefinedType;
   1.199 +		}
   1.200 +	}
   1.201 +
   1.202 +TInt TMMFDevSoundRequest::Function() const 
   1.203 +	{
   1.204 +	return iMessage.Function(); 
   1.205 +	}
   1.206 +
   1.207 +TMMFDevSoundRequest::TA3FDevSoundRequestType TMMFDevSoundRequest::Type() const
   1.208 +	{
   1.209 +	return iRequestType;
   1.210 +	}
   1.211 +
   1.212 +
   1.213 +// 
   1.214 +// CMMFDevSoundSession::CreateL
   1.215 +// Creates a new object
   1.216 +// 
   1.217 +void CMMFDevSoundSession::CreateL(const CMmfIpcServer& aServer)
   1.218 +	{
   1.219 +	CMmfIpcSession::CreateL(aServer);
   1.220 +	CMMFDevSoundServer& server =
   1.221 +	const_cast<CMMFDevSoundServer&>(
   1.222 +			static_cast<const CMMFDevSoundServer&>(aServer));
   1.223 +	server.IncrementSessionId();
   1.224 +	iDevSoundSessionId = server.DevSoundSessionId();
   1.225 +	}
   1.226 +
   1.227 +//
   1.228 +// NeedToQueue - mid-commit cycle or async queue start AO is active
   1.229 +//
   1.230 +TBool CMMFDevSoundSession::NeedToQueue() const
   1.231 +    {
   1.232 +    return iOperationCompletePending || iAsyncQueueStart->IsActive();
   1.233 +    }
   1.234 +
   1.235 +//
   1.236 +// CMMFDevSoundSession::ServiceL
   1.237 +// (other items were commented in a header).
   1.238 +//
   1.239 +void CMMFDevSoundSession::ServiceL(const RMmfIpcMessage& aMessage)
   1.240 +	{
   1.241 +	SYMBIAN_DEBPRN2(_L("\nCMMFDevSoundSession[0x%x] NEW REQUEST %02x while pending=%d"),
   1.242 +	        aMessage.Function(), NeedToQueue());
   1.243 +	
   1.244 +	if(NeedToQueue())
   1.245 +		{
   1.246 +		// if not possible to service now, then queue request
   1.247 +		EnqueueRequest(aMessage);
   1.248 +		}
   1.249 +	else
   1.250 +		{
   1.251 +		// If there is no oustanding operation service inmediately
   1.252 +		TRAPD(err, DoServiceRequestL(aMessage));
   1.253 +		if (err)
   1.254 +		    {
   1.255 +            aMessage.Complete(err); // repeat normal ServiceL() behaviour since we may keep going
   1.256 +		    }
   1.257 +	    if (!iOperationCompletePending && iQueuedRequests.Count() != 0)
   1.258 +	        {
   1.259 +	        //dequeue next
   1.260 +	        DequeueRequest();
   1.261 +	        }
   1.262 +		}
   1.263 +	}
   1.264 +	
   1.265 +//
   1.266 +// CMMFDevSoundSession::DoServiceL
   1.267 +// (other items were commented in a header).
   1.268 +//
   1.269 +void CMMFDevSoundSession::DoServiceRequestL(const RMmfIpcMessage& aMessage)
   1.270 +	{
   1.271 +	iRequestBeingServiced.SetMessage(aMessage);
   1.272 +	iAsyncQueueStart->Cancel(); // just in case.
   1.273 +    ResetNotifiedError();
   1.274 +
   1.275 +    if (aMessage.Function() == RMessage2::EDisConnect)
   1.276 +        {
   1.277 +        TBool complete = iAdapter->CloseDevSound();
   1.278 +        if(!complete)
   1.279 +            {
   1.280 +            iRequestBeingServiced.SetMessage(aMessage);
   1.281 +            iOperationCompletePending = ETrue;
   1.282 +            ResetNotifiedError();
   1.283 +            }
   1.284 +        else
   1.285 +            {
   1.286 +            // if we get here, iClosing wait will have been started and we'd be waiting
   1.287 +            iClosingWait->AsyncStop();
   1.288 +            }
   1.289 +        return;
   1.290 +        }
   1.291 +    
   1.292 +    TMMFMessageDestinationPckg destinationPckg;
   1.293 +	User::LeaveIfError(MessageRead(aMessage, 0, destinationPckg));
   1.294 +	SYMBIAN_DEBPRN2(_L("CMMFDevSoundSession[0x%x]::DoServiceRequestL - DestinationHandle [%d] InterfaceId [%d] "), destinationPckg().DestinationHandle(), destinationPckg().InterfaceId());
   1.295 +	if ((destinationPckg().DestinationHandle() == KMMFObjectHandleDevSound) &&
   1.296 +	    (destinationPckg().InterfaceId() == KUidInterfaceMMFDevSound))
   1.297 +		{
   1.298 +        SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoServiceRequestL - Request [%d]"), aMessage.Function());
   1.299 +		TBool complete = EFalse;
   1.300 +		switch(aMessage.Function())
   1.301 +			{
   1.302 +			case EMMFDevSoundProxyPostOpen:
   1.303 +				complete = DoPostOpenL(aMessage);
   1.304 +				break;
   1.305 +			case EMMFDevSoundProxyInitialize1:
   1.306 +				complete = DoInitialize1L(aMessage);
   1.307 +				break;
   1.308 +			case EMMFDevSoundProxyInitialize2:
   1.309 +				complete = DoInitialize2L(aMessage);
   1.310 +				break;
   1.311 +			case EMMFDevSoundProxyInitialize4:
   1.312 +				complete = DoInitialize4L(aMessage);
   1.313 +				break;
   1.314 +			case EMMFDevSoundProxyCapabilities:
   1.315 +				complete = DoCapabilitiesL(aMessage);
   1.316 +				break;
   1.317 +			case EMMFDevSoundProxyConfig:
   1.318 +				complete = DoConfigL(aMessage);
   1.319 +				break;
   1.320 +			case EMMFDevSoundProxySetConfig:
   1.321 +				complete = DoSetConfigL(aMessage);
   1.322 +				break;
   1.323 +			case EMMFDevSoundProxyMaxVolume:
   1.324 +				complete = DoMaxVolumeL(aMessage);
   1.325 +				break;
   1.326 +			case EMMFDevSoundProxyVolume:
   1.327 +				complete = DoVolumeL(aMessage);
   1.328 +				break;
   1.329 +			case EMMFDevSoundProxySetVolume:
   1.330 +				complete = DoSetVolumeL(aMessage);
   1.331 +				break;
   1.332 +			case EMMFDevSoundProxyMaxGain:
   1.333 +				complete = DoMaxGainL(aMessage);
   1.334 +				break;
   1.335 +			case EMMFDevSoundProxyGain:
   1.336 +				complete = DoGainL(aMessage);
   1.337 +				break;
   1.338 +			case EMMFDevSoundProxySetGain:
   1.339 +				complete = DoSetGainL(aMessage);
   1.340 +				break;
   1.341 +			case EMMFDevSoundProxyPlayBalance:
   1.342 +				complete = DoGetPlayBalanceL(aMessage);
   1.343 +				break;
   1.344 +			case EMMFDevSoundProxySetPlayBalance:
   1.345 +				complete = DoSetPlayBalanceL(aMessage);
   1.346 +				break;
   1.347 +			case EMMFDevSoundProxyRecordBalance:
   1.348 +				complete = DoGetRecordBalanceL(aMessage);
   1.349 +				break;
   1.350 +			case EMMFDevSoundProxySetRecordBalance:
   1.351 +				complete = DoSetRecordBalanceL(aMessage);
   1.352 +				break;
   1.353 +			case EMMFDevSoundProxyBTBFData:
   1.354 +				complete = DoBufferToBeFilledDataL(aMessage);
   1.355 +				break;
   1.356 +			case EMMFDevSoundProxyBTBEData:
   1.357 +				complete = DoBufferToBeEmptiedDataL(aMessage);
   1.358 +				break;
   1.359 +			case EMMFDevSoundProxyPlayInit:
   1.360 +				complete = DoPlayInitL(aMessage);
   1.361 +				break;
   1.362 +			case EMMFDevSoundProxyRecordInit:
   1.363 +				complete = DoRecordInitL(aMessage);
   1.364 +				break;
   1.365 +			case EMMFDevSoundProxyPlayData:
   1.366 +				complete = DoPlayDataL(aMessage);
   1.367 +				break;
   1.368 +			case EMMFDevSoundProxyRecordData:
   1.369 +				complete = DoRecordDataL(aMessage);
   1.370 +				break;
   1.371 +			case EMMFDevSoundProxyStop:
   1.372 +				complete = DoStopL(aMessage);
   1.373 +				break;
   1.374 +			case EMMFDevSoundProxyPause:
   1.375 +				complete = DoPauseL(aMessage);
   1.376 +				break;
   1.377 +			case EMMFDevSoundProxyPlayTone:
   1.378 +				complete = DoPlayToneL(aMessage);
   1.379 +				break;
   1.380 +			case EMMFDevSoundProxyPlayDualTone:
   1.381 +				complete = DoPlayDualToneL(aMessage);
   1.382 +				break;
   1.383 +			case EMMFDevSoundProxyPlayDTMFString:
   1.384 +				complete = DoPlayDTMFStringL(aMessage);
   1.385 +				break;
   1.386 +			case EMMFDevSoundProxyPlayToneSequence:
   1.387 +				complete = DoPlayToneSequenceL(aMessage);
   1.388 +				break;
   1.389 +			case EMMFDevSoundProxyPlayFixedSequence:
   1.390 +				complete = DoPlayFixedSequenceL(aMessage);
   1.391 +				break;
   1.392 +			case EMMFDevSoundProxySetDTMFLengths:
   1.393 +				complete = DoSetDTMFLengthsL(aMessage);
   1.394 +				break;
   1.395 +			case EMMFDevSoundProxySetVolumeRamp:
   1.396 +				complete = DoSetVolumeRampL(aMessage);
   1.397 +				break;
   1.398 +			case EMMFDevSoundProxyGetSupportedInputDataTypes:
   1.399 +				complete = DoGetSupportedInputDataTypesL(aMessage);
   1.400 +				break;
   1.401 +			case EMMFDevSoundProxyGetSupportedOutputDataTypes:
   1.402 +				complete = DoGetSupportedOutputDataTypesL(aMessage);
   1.403 +				break;
   1.404 +			case EMMFDevSoundProxyCopyFourCCArrayData:
   1.405 +				complete = DoCopyFourCCArrayDataL(aMessage);
   1.406 +				break;
   1.407 +			case EMMFDevSoundProxySamplesRecorded:
   1.408 +				complete = DoSamplesRecordedL(aMessage);
   1.409 +				break;
   1.410 +			case EMMFDevSoundProxySamplesPlayed:
   1.411 +				complete = DoSamplesPlayedL(aMessage);
   1.412 +				break;
   1.413 +			case EMMFDevSoundProxySetToneRepeats:
   1.414 +				complete = DoSetToneRepeatsL(aMessage);
   1.415 +				break;
   1.416 +			case EMMFDevSoundProxySetPrioritySettings:
   1.417 +				complete = DoSetPrioritySettingsL(aMessage);
   1.418 +				break;
   1.419 +			case EMMFDevSoundProxyFixedSequenceCount:
   1.420 +				complete = DoFixedSequenceCountL(aMessage);
   1.421 +				break;
   1.422 +			case EMMFDevSoundProxyCancelInitialize:
   1.423 +				complete = DoCancelInitializeL(aMessage);
   1.424 +				break;
   1.425 +			case EMMFDevSoundProxyEmptyBuffers:
   1.426 +				complete = DoEmptyBuffersL(aMessage);
   1.427 +				break;
   1.428 +			case EMMFDevSoundProxyGetTimePlayed:
   1.429 +				complete = DoGetTimePlayedL(aMessage);
   1.430 +				break;
   1.431 +			case EMMFDevSoundProxyIsResumeSupported:
   1.432 +				complete = DoQueryResumeSupportedL(aMessage);
   1.433 +				break;
   1.434 +			case EMMFDevSoundProxyResume:
   1.435 +				complete = DoResumeL(aMessage);
   1.436 +				break;
   1.437 +
   1.438 +			// DevSound custom command support
   1.439 +			case EMMFDevSoundProxySyncCustomCommand:
   1.440 +			case EMMFDevSoundProxySyncCustomCommandResult:
   1.441 +			case EMMFDevSoundProxyAsyncCustomCommand:
   1.442 +			case EMMFDevSoundProxyAsyncCustomCommandResult:
   1.443 +				complete = DoCustomCommandL(aMessage);
   1.444 +				break;
   1.445 +			case EMMFDevSoundProxyClose:
   1.446 +				complete = DoPrepareCloseL(aMessage);
   1.447 +				break;
   1.448 +			case EMMFDevSoundProxyRequestResourceNotification:
   1.449 +				complete = DoRegisterAsClientL(aMessage);
   1.450 +				break;
   1.451 +			case EMMFDevSoundProxyCancelRequestResourceNotification:
   1.452 +				complete = DoCancelRegisterAsClientL(aMessage);
   1.453 +				break;
   1.454 +			case EMMFDevSoundProxyGetResourceNotificationData:
   1.455 +				complete = DoGetResourceNotificationDataL(aMessage);
   1.456 +				break;
   1.457 +			case EMMFDevSoundProxyWillResumePlay:
   1.458 +				complete = DoWillResumePlayL(aMessage);
   1.459 +				break;
   1.460 +			case EMMFDevSoundProxySetClientThreadInfo:
   1.461 +				complete = DoSetClientThreadInfoL(aMessage);
   1.462 +				break;						
   1.463 +			default:
   1.464 +				User::Leave(KErrNotSupported);
   1.465 +				break;
   1.466 +			}
   1.467 +
   1.468 +		// Check if can complete the message now
   1.469 +		if (complete)
   1.470 +			{
   1.471 +			// Complete the message
   1.472 +			// Synchronous requests & Pseudo-asynchronous
   1.473 +			aMessage.Complete(KErrNone);
   1.474 +
   1.475 +			// Store function if we need to re-apply it again due to pre-emption clash
   1.476 +			if(iRequestBeingServiced.Type() == TMMFDevSoundRequest::EAction_PseudoAsynchronous)
   1.477 +				{
   1.478 +				iRedoFunction = aMessage.Function();
   1.479 +				}
   1.480 +			}
   1.481 +		}
   1.482 +	else
   1.483 +		{
   1.484 +		// If there's a CI extension, see if that handles this request
   1.485 +		TInt err = KErrNotSupported;
   1.486 +		if (iCIExtension)
   1.487 +			{
   1.488 +            SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoServiceRequestL - CIExtensionRequest [%d]"), aMessage.Function());
   1.489 +            iOperationCompletePending = ETrue;
   1.490 +			iHandlingExtdCI = ETrue;
   1.491 +			TRAPD(err2, err = iCIExtension->HandleMessageL(aMessage));
   1.492 +			if (err2)
   1.493 +				{
   1.494 +				err = err2;
   1.495 +				}
   1.496 +			iOperationCompletePending = EFalse;
   1.497 +			iHandlingExtdCI = EFalse;
   1.498 +			SYMBIAN_DEBPRN2(_L("CMMFDevSoundSession[0x%x]::DoServiceRequestL - CIExtensionRequest[%d] - Exit with Error[%d] "), aMessage.Function(),err);
   1.499 +			}
   1.500 +
   1.501 +		if (err != KErrNone)
   1.502 +			{
   1.503 +			// Not been handled, the request is not supported
   1.504 +			aMessage.Complete(KErrNotSupported);
   1.505 +			}
   1.506 +		}
   1.507 +	}
   1.508 +
   1.509 +void CMMFDevSoundSession::DoServiceAlreadyCompletedRequestL(const TInt aFunction)
   1.510 +	{
   1.511 +    ResetNotifiedError();
   1.512 +
   1.513 +	switch(aFunction)
   1.514 +		{
   1.515 +		case EMMFDevSoundProxyInitialize1:
   1.516 +			DoAlreadyCompletedInitialize1L();
   1.517 +			break;
   1.518 +		case EMMFDevSoundProxyInitialize2:
   1.519 +			DoAlreadyCompletedInitialize2L();
   1.520 +			break;
   1.521 +		case EMMFDevSoundProxyInitialize4:
   1.522 +			DoAlreadyCompletedInitialize4L();
   1.523 +			break;
   1.524 +		case EMMFDevSoundProxyPlayInit:
   1.525 +			DoAlreadyCompletedPlayInitL();
   1.526 +			break;
   1.527 +		case EMMFDevSoundProxyRecordInit:
   1.528 +			DoAlreadyCompletedRecordInitL();
   1.529 +			break;
   1.530 +		case EMMFDevSoundProxyPlayTone:
   1.531 +			DoAlreadyCompletedPlayToneL();
   1.532 +			break;
   1.533 +		case EMMFDevSoundProxyPlayDualTone:
   1.534 +			DoAlreadyCompletedPlayDualToneL();
   1.535 +			break;
   1.536 +		case EMMFDevSoundProxyPlayDTMFString:
   1.537 +			DoAlreadyCompletedPlayDTMFStringL();
   1.538 +			break;
   1.539 +		case EMMFDevSoundProxyPlayToneSequence:
   1.540 +			DoAlreadyCompletedPlayToneSequenceL();
   1.541 +			break;
   1.542 +		case EMMFDevSoundProxyPlayFixedSequence:
   1.543 +			DoAlreadyCompletedPlayFixedSequenceL();
   1.544 +			break;
   1.545 +		default:
   1.546 +			User::Leave(KErrNotSupported);
   1.547 +			break;
   1.548 +		}
   1.549 +
   1.550 +	}
   1.551 +
   1.552 +void CMMFDevSoundSession::HandleAlreadyCompletedRequest()
   1.553 +	{
   1.554 +	TRAPD(err,DoServiceAlreadyCompletedRequestL(iRedoFunction));
   1.555 +
   1.556 +	if (err != KErrNone)
   1.557 +		{
   1.558 +		switch(iRedoFunction)
   1.559 +			{
   1.560 +			case EMMFDevSoundProxyInitialize1:
   1.561 +			case EMMFDevSoundProxyInitialize2:
   1.562 +			case EMMFDevSoundProxyInitialize4:
   1.563 +				InitializeComplete(err);
   1.564 +				break;
   1.565 +			case EMMFDevSoundProxyPlayInit:
   1.566 +				PlayError(err);
   1.567 +				break;
   1.568 +			case EMMFDevSoundProxyRecordInit:
   1.569 +				RecordError(err);
   1.570 +				break;
   1.571 +			case EMMFDevSoundProxyPlayTone:
   1.572 +			case EMMFDevSoundProxyPlayDualTone:
   1.573 +			case EMMFDevSoundProxyPlayDTMFString:
   1.574 +			case EMMFDevSoundProxyPlayToneSequence:
   1.575 +			case EMMFDevSoundProxyPlayFixedSequence:
   1.576 +				ToneFinished(err);
   1.577 +				break;
   1.578 +			default:
   1.579 +				break;
   1.580 +			}
   1.581 +		}
   1.582 +	}
   1.583 +
   1.584 +void CMMFDevSoundSession::EnqueueRequest(const RMmfIpcMessage& aMessage)
   1.585 +	{
   1.586 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::EnqueueRequest - Enter"));
   1.587 +	// Encapsule the request
   1.588 +	TMMFDevSoundRequest request;
   1.589 +	request.SetMessage(aMessage);
   1.590 +	// Append
   1.591 +	TInt error = iQueuedRequests.Append(request);
   1.592 +	__ASSERT_DEBUG(error == KErrNone, Panic(EQueueRequestsFailedToAppend));
   1.593 +	SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::EnqueueRequest - Exit"));
   1.594 +	}
   1.595 +
   1.596 +//
   1.597 +// CMMFDevSoundSession::DoPostOpenL
   1.598 +//
   1.599 +TBool CMMFDevSoundSession::DoPostOpenL(const RMmfIpcMessage& /*aMessage*/)
   1.600 +	{
   1.601 +	iAdapter->PostOpenL();
   1.602 +	iOperationCompletePending = ETrue;
   1.603 +	return EFalse;
   1.604 +	}
   1.605 +
   1.606 +//
   1.607 +// CMMFDevSoundSession::DoInitialize1L
   1.608 +// (other items were commented in a header).
   1.609 +//
   1.610 +TBool CMMFDevSoundSession::DoInitialize1L(const RMmfIpcMessage& aMessage)
   1.611 +	{
   1.612 +    iMsgQueue.Close(); // close if already open
   1.613 +	TInt err = iMsgQueue.Open(aMessage, 2, EOwnerThread); // a global queue but owned by thread
   1.614 +	User::LeaveIfError(err);
   1.615 +	DoSetClientConfigL();// added here instead of the CreateL()
   1.616 +	TMMFDevSoundProxySettingsPckg devSoundBuf;
   1.617 +	User::LeaveIfError(MessageRead(aMessage,1,devSoundBuf));
   1.618 +	iCachedClientData = devSoundBuf;
   1.619 +	TMMFState mode = devSoundBuf().iMode;
   1.620 +	iAdapter->InitializeL(mode);
   1.621 +	iBufferPlay = NULL;
   1.622 +	iPlayErrorOccured = EFalse;
   1.623 +	// Flag to queue any further request 
   1.624 +	// but the message can be completed now
   1.625 +	iOperationCompletePending = ETrue;
   1.626 +	return ETrue;
   1.627 +	}
   1.628 +
   1.629 +//
   1.630 +// CMMFDevSoundSession::DoAlreadyCompletedInitialize1L
   1.631 +// (other items were commented in a header).
   1.632 +//
   1.633 +void CMMFDevSoundSession::DoAlreadyCompletedInitialize1L()
   1.634 +	{
   1.635 +	TMMFState mode = iCachedClientData().iMode;
   1.636 +	iAdapter->InitializeL(mode);
   1.637 +	iBufferPlay = NULL;
   1.638 +	iPlayErrorOccured = EFalse;
   1.639 +	// Flag to queue any further request
   1.640 +	iOperationCompletePending = ETrue;
   1.641 +	}
   1.642 +
   1.643 +//
   1.644 +// CMMFDevSoundSession::DoInitialize2L
   1.645 +// (other items were commented in a header).
   1.646 +//
   1.647 +TBool CMMFDevSoundSession::DoInitialize2L(const RMmfIpcMessage& aMessage)
   1.648 +	{
   1.649 +    iMsgQueue.Close(); // close if already open
   1.650 +	TInt err = iMsgQueue.Open(aMessage, 2, EOwnerThread); // a global queue but owned by thread
   1.651 +	User::LeaveIfError(err);
   1.652 +	DoSetClientConfigL();// added here instead of the CreateL()
   1.653 +	TMMFDevSoundProxySettingsPckg devSoundBuf;
   1.654 +	User::LeaveIfError(MessageRead(aMessage,1,devSoundBuf));
   1.655 +	iCachedClientData = devSoundBuf;
   1.656 +	TUid HWDev = devSoundBuf().iHWDev;
   1.657 +	TMMFState mode = devSoundBuf().iMode;
   1.658 +	iAdapter->InitializeL(HWDev, mode);
   1.659 +	iBufferPlay = NULL;
   1.660 +	iPlayErrorOccured = EFalse;
   1.661 +	return ETrue;
   1.662 +	}
   1.663 +
   1.664 +//
   1.665 +// CMMFDevSoundSession::DoAlreadyCompletedInitialize2L
   1.666 +// (other items were commented in a header).
   1.667 +//
   1.668 +void CMMFDevSoundSession::DoAlreadyCompletedInitialize2L()
   1.669 +	{
   1.670 +	TUid HWDev = iCachedClientData().iHWDev;
   1.671 +	TMMFState mode = iCachedClientData().iMode;
   1.672 +	iAdapter->InitializeL(HWDev, mode);
   1.673 +	iBufferPlay = NULL;
   1.674 +	iPlayErrorOccured = EFalse;
   1.675 +	}
   1.676 +
   1.677 +//
   1.678 +// CMMFDevSoundSession::DoInitialize4L
   1.679 +// (other items were commented in a header).
   1.680 +//
   1.681 +TBool CMMFDevSoundSession::DoInitialize4L(const RMmfIpcMessage& aMessage)
   1.682 +	{
   1.683 +    iMsgQueue.Close();
   1.684 +	TInt err = iMsgQueue.Open(aMessage, 2, EOwnerThread); // a global queue but owned by thread
   1.685 +	User::LeaveIfError(err);
   1.686 +	DoSetClientConfigL();// added here instead of the CreateL()
   1.687 +	TMMFDevSoundProxySettingsPckg devSoundBuf;
   1.688 +	User::LeaveIfError(MessageRead(aMessage, TInt(1), devSoundBuf));
   1.689 +	iCachedClientData = devSoundBuf;
   1.690 +	TFourCC desiredFourCC = devSoundBuf().iDesiredFourCC;
   1.691 +	TMMFState mode = devSoundBuf().iMode;
   1.692 +	iAdapter->InitializeL(desiredFourCC, mode);
   1.693 +	iBufferPlay = NULL;
   1.694 +	iPlayErrorOccured = EFalse;
   1.695 +	// Flag to queue any further request 
   1.696 +	// but the message can be completed now
   1.697 +	iOperationCompletePending = ETrue;
   1.698 +	return ETrue;
   1.699 +	}
   1.700 +
   1.701 +//
   1.702 +// CMMFDevSoundSession::DoAlreadyCompletedInitialize4L
   1.703 +// (other items were commented in a header).
   1.704 +//
   1.705 +void CMMFDevSoundSession::DoAlreadyCompletedInitialize4L()
   1.706 +	{
   1.707 +	TFourCC desiredFourCC = iCachedClientData().iDesiredFourCC;
   1.708 +	TMMFState mode = iCachedClientData().iMode;
   1.709 +	iAdapter->InitializeL(desiredFourCC, mode);
   1.710 +	iBufferPlay = NULL;
   1.711 +	iPlayErrorOccured = EFalse;
   1.712 +	// Flag to queue any further request
   1.713 +	iOperationCompletePending = ETrue;
   1.714 +	}
   1.715 +
   1.716 +//
   1.717 +// CMMFDevSoundSession::DoCancelInitialize
   1.718 +// (other items were commented in a header).
   1.719 +//
   1.720 +TBool CMMFDevSoundSession::DoCancelInitializeL(const RMmfIpcMessage& aMessage)
   1.721 +	{
   1.722 +	TInt err=iAdapter->CancelInitialize();
   1.723 +
   1.724 +	if (err != KErrNone)
   1.725 +		{
   1.726 +		aMessage.Complete(err);
   1.727 +		iOperationCompletePending = EFalse;
   1.728 +		return ETrue;
   1.729 +		}
   1.730 +	else
   1.731 +		{
   1.732 +		iOperationCompletePending = ETrue;
   1.733 +		}
   1.734 +	return EFalse;
   1.735 +	}
   1.736 +
   1.737 +//
   1.738 +// CMMFDevSoundSession::DoCapabilitiesL
   1.739 +// (other items were commented in a header).
   1.740 +//
   1.741 +TBool CMMFDevSoundSession::DoCapabilitiesL(const RMmfIpcMessage& aMessage)
   1.742 +	{
   1.743 +	TInt err = iAdapter->Capabilities(iDevSoundCapabilities);
   1.744 +	if(err != KErrNone)
   1.745 +		{
   1.746 +		aMessage.Complete(err);
   1.747 +		iOperationCompletePending = EFalse;
   1.748 +		}
   1.749 +	else
   1.750 +		{
   1.751 +		iOperationCompletePending = ETrue;
   1.752 +		}
   1.753 +	return EFalse;
   1.754 +	}
   1.755 +
   1.756 +//
   1.757 +// CMMFDevSoundSession::DoConfigL
   1.758 +// (other items were commented in a header).
   1.759 +//
   1.760 +TBool CMMFDevSoundSession::DoConfigL(const RMmfIpcMessage& aMessage)
   1.761 +	{
   1.762 +	TMMFDevSoundProxySettings devSoundSet;
   1.763 +	devSoundSet.iConfig = iAdapter->Config();
   1.764 +	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
   1.765 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
   1.766 +	return ETrue;
   1.767 +	}
   1.768 +
   1.769 +//
   1.770 +// CMMFDevSoundSession::DoSetConfigL
   1.771 +// (other items were commented in a header).
   1.772 +//
   1.773 +TBool CMMFDevSoundSession::DoSetConfigL(const RMmfIpcMessage& aMessage)
   1.774 +	{
   1.775 +	TMMFDevSoundProxySettingsPckg devSoundBuf;
   1.776 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
   1.777 +	TMMFCapabilities config = devSoundBuf().iConfig;
   1.778 +	iAdapter->SetConfigL(config);
   1.779 +	iOperationCompletePending = ETrue;
   1.780 +	return EFalse;
   1.781 +	}
   1.782 +
   1.783 +//
   1.784 +// CMMFDevSoundSession::axVolumeL
   1.785 +// (other items were commented in a header).
   1.786 +//
   1.787 +TBool CMMFDevSoundSession::DoMaxVolumeL(const RMmfIpcMessage& aMessage)
   1.788 +	{
   1.789 +	TMMFDevSoundProxySettings devSoundSet;
   1.790 +	devSoundSet.iMaxVolume = iAdapter->MaxVolume();
   1.791 +	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
   1.792 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
   1.793 +	return ETrue;
   1.794 +	}
   1.795 +
   1.796 +//
   1.797 +// CMMFDevSoundSession::DoVolumeL
   1.798 +// (other items were commented in a header).
   1.799 +//
   1.800 +TBool CMMFDevSoundSession::DoVolumeL(const RMmfIpcMessage& aMessage)
   1.801 +	{
   1.802 +	TMMFDevSoundProxySettings devSoundSet;
   1.803 +	devSoundSet.iVolume = iAdapter->Volume();
   1.804 +	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
   1.805 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
   1.806 +	return ETrue;
   1.807 +	}
   1.808 +
   1.809 +//
   1.810 +// CMMFDevSoundSession::DoSetVolumeL
   1.811 +// (other items were commented in a header).
   1.812 +//
   1.813 +TBool CMMFDevSoundSession::DoSetVolumeL(const RMmfIpcMessage& aMessage)
   1.814 +	{
   1.815 +	TMMFDevSoundProxySettingsPckg devSoundBuf;
   1.816 +	User::LeaveIfError(MessageRead(aMessage, TInt(1),devSoundBuf));
   1.817 +	TInt volume = devSoundBuf().iVolume;
   1.818 +	TBool asyncOperation;
   1.819 +	User::LeaveIfError(iAdapter->SetVolume(volume, asyncOperation));
   1.820 +	iOperationCompletePending = asyncOperation;
   1.821 +	return !asyncOperation;
   1.822 +	}
   1.823 +
   1.824 +//
   1.825 +// CMMFDevSoundSession::DoMaxGainL
   1.826 +// (other items were commented in a header).
   1.827 +//
   1.828 +TBool CMMFDevSoundSession::DoMaxGainL(const RMmfIpcMessage& aMessage)
   1.829 +	{
   1.830 +	TMMFDevSoundProxySettings devSoundSet;
   1.831 +	devSoundSet.iMaxGain = iAdapter->MaxGain();
   1.832 +	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
   1.833 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
   1.834 +	return ETrue;
   1.835 +	}
   1.836 +
   1.837 +//
   1.838 +// CMMFDevSoundSession::DoGainL
   1.839 +// (other items were commented in a header).
   1.840 +//
   1.841 +TBool CMMFDevSoundSession::DoGainL(const RMmfIpcMessage& aMessage)
   1.842 +	{
   1.843 +	TMMFDevSoundProxySettings devSoundSet;
   1.844 +	devSoundSet.iGain = iAdapter->Gain();
   1.845 +	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
   1.846 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
   1.847 +	return ETrue;
   1.848 +	}
   1.849 +
   1.850 +//
   1.851 +// CMMFDevSoundSession::DoSetGainL
   1.852 +// (other items were commented in a header).
   1.853 +//
   1.854 +TBool CMMFDevSoundSession::DoSetGainL(const RMmfIpcMessage& aMessage)
   1.855 +	{
   1.856 +	TMMFDevSoundProxySettingsPckg devSoundBuf;
   1.857 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
   1.858 +	TInt gain = devSoundBuf().iGain;
   1.859 +	TBool asyncOperation;
   1.860 +	User::LeaveIfError(iAdapter->SetGain(gain, asyncOperation));
   1.861 +	iOperationCompletePending = asyncOperation;
   1.862 +	return !asyncOperation;
   1.863 +	}
   1.864 +
   1.865 +//
   1.866 +// CMMFDevSoundSession::DoGetPlayBalanceL
   1.867 +// (other items were commented in a header).
   1.868 +//
   1.869 +TBool CMMFDevSoundSession::DoGetPlayBalanceL(const RMmfIpcMessage& aMessage)
   1.870 +	{
   1.871 +	TMMFDevSoundProxySettings devSoundSet;
   1.872 +	iAdapter->GetPlayBalanceL(devSoundSet.iLeftPercentage, devSoundSet.iRightPercentage);
   1.873 +	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
   1.874 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
   1.875 +	return ETrue;
   1.876 +	}
   1.877 +
   1.878 +//
   1.879 +// CMMFDevSoundSession::DoSetPlayBalanceL
   1.880 +// (other items were commented in a header).
   1.881 +//
   1.882 +TBool CMMFDevSoundSession::DoSetPlayBalanceL(const RMmfIpcMessage& aMessage)
   1.883 +	{
   1.884 +	TMMFDevSoundProxySettingsPckg devSoundBuf;
   1.885 +    User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
   1.886 +	TInt leftPercentage = devSoundBuf().iLeftPercentage;
   1.887 +	TInt rightPercentage = devSoundBuf().iRightPercentage;
   1.888 +	TBool asyncOperation;
   1.889 +	iAdapter->SetPlayBalanceL(leftPercentage, rightPercentage, asyncOperation);
   1.890 +	iOperationCompletePending = asyncOperation;
   1.891 +	return !asyncOperation;
   1.892 +	}
   1.893 +
   1.894 +//
   1.895 +// CMMFDevSoundSession::DoGetRecordBalanceL
   1.896 +// (other items were commented in a header).
   1.897 +//
   1.898 +TBool CMMFDevSoundSession::DoGetRecordBalanceL(const RMmfIpcMessage& aMessage)
   1.899 +	{
   1.900 +	TMMFDevSoundProxySettings devSoundSet;
   1.901 +	iAdapter->GetRecordBalanceL(devSoundSet.iLeftPercentage, devSoundSet.iRightPercentage);
   1.902 +	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
   1.903 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
   1.904 +	return ETrue;
   1.905 +	}
   1.906 +
   1.907 +//
   1.908 +// CMMFDevSoundSession::DoSetRecordBalanceL
   1.909 +// (other items were commented in a header).
   1.910 +//
   1.911 +TBool CMMFDevSoundSession::DoSetRecordBalanceL(const RMmfIpcMessage& aMessage)
   1.912 +	{
   1.913 +	TMMFDevSoundProxySettingsPckg devSoundBuf;
   1.914 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
   1.915 +	TInt leftPercentage = devSoundBuf().iLeftPercentage;
   1.916 +	TInt rightPercentage = devSoundBuf().iRightPercentage;
   1.917 +	TBool asyncOperation;
   1.918 +	iAdapter->SetRecordBalanceL(leftPercentage, rightPercentage, asyncOperation);
   1.919 +	iOperationCompletePending = asyncOperation;
   1.920 +	return !asyncOperation;
   1.921 +	}
   1.922 +
   1.923 +//
   1.924 +// CMMFDevSoundSession::DoPlayInitL
   1.925 +// (other items were commented in a header).
   1.926 +//
   1.927 +TBool CMMFDevSoundSession::DoPlayInitL(const RMmfIpcMessage& /*aMessage*/)
   1.928 +	{
   1.929 +	iAdapter->PlayInitL();
   1.930 +	iOperationCompletePending = ETrue;
   1.931 +	return ETrue;
   1.932 +	}
   1.933 +
   1.934 +//
   1.935 +// CMMFDevSoundSession::DoAlreadyCompletedPlayInitL
   1.936 +// (other items were commented in a header).
   1.937 +//
   1.938 +void CMMFDevSoundSession::DoAlreadyCompletedPlayInitL()
   1.939 +	{
   1.940 +	iAdapter->PlayInitL();
   1.941 +	iOperationCompletePending = ETrue;
   1.942 +	}
   1.943 +
   1.944 +//
   1.945 +// CMMFDevSoundSession::DoRecordInitL
   1.946 +// (other items were commented in a header).
   1.947 +//
   1.948 +TBool CMMFDevSoundSession::DoRecordInitL(const RMmfIpcMessage& /*aMessage*/)
   1.949 +	{
   1.950 +	iAdapter->RecordInitL();
   1.951 +	iOperationCompletePending = ETrue;
   1.952 +	return ETrue;
   1.953 +	}
   1.954 +
   1.955 +//
   1.956 +// CMMFDevSoundSession::DoAlreadyCompletedRecordInitL
   1.957 +// (other items were commented in a header).
   1.958 +//
   1.959 +void CMMFDevSoundSession::DoAlreadyCompletedRecordInitL()
   1.960 +	{
   1.961 +	iAdapter->RecordInitL();
   1.962 +	iOperationCompletePending = ETrue;
   1.963 +	}
   1.964 +
   1.965 +//
   1.966 +// CMMFDevSoundSession::DoPlayDataL
   1.967 +// (other items were commented in a header).
   1.968 +//
   1.969 +TBool CMMFDevSoundSession::DoPlayDataL(const RMmfIpcMessage& aMessage)
   1.970 +	{
   1.971 +	SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayDataL - Enter"));
   1.972 +
   1.973 +	if( iPlayErrorOccured )
   1.974 +		{
   1.975 +		SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayDataL - Ignore and Exit"));
   1.976 +		return ETrue;
   1.977 +		}
   1.978 +
   1.979 +	TMMFDevSoundProxyHwBufPckg devSoundBuf;
   1.980 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
   1.981 +	iBufferPlay->SetLastBuffer(devSoundBuf().iLastBuffer);
   1.982 +
   1.983 +	TPtr8 dataPtr(iChunk.Base(), devSoundBuf().iBufferSize, devSoundBuf().iBufferSize);
   1.984 +	// Copy data over from chunk
   1.985 +	iBufferPlay->Data().Copy(dataPtr);
   1.986 +	iAdapter->PlayData();
   1.987 +	SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayDataL - Exit"));
   1.988 +	return ETrue;
   1.989 +	}
   1.990 +
   1.991 +//
   1.992 +// CMMFDevSoundSession::DoRecordDataL
   1.993 +// (other items were commented in a header).
   1.994 +//
   1.995 +TBool CMMFDevSoundSession::DoRecordDataL(const RMmfIpcMessage& /*aMessage*/)
   1.996 +	{
   1.997 +	iAdapter->RecordData();
   1.998 +	return ETrue;
   1.999 +	}
  1.1000 +
  1.1001 +//
  1.1002 +// CMMFDevSoundSession::DoStopL
  1.1003 +// (other items were commented in a header).
  1.1004 +//
  1.1005 +TBool CMMFDevSoundSession::DoStopL(const RMmfIpcMessage& /*aMessage*/)
  1.1006 +	{
  1.1007 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoStopL - Enter"));
  1.1008 +    // Sometimes Stop is not involved on a commit cycle
  1.1009 +	TBool completed = iAdapter->Stop();
  1.1010 +	if (completed)
  1.1011 +		{
  1.1012 +        FlushQueuedRequests();
  1.1013 +		FlushEventQueue(); // completed returned here means we were idle to start with. TODO could possibly skip this flush
  1.1014 +		iChunk.Close();
  1.1015 +		}
  1.1016 +	iOperationCompletePending = !completed;
  1.1017 +	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoStopL - Exit. Return value is [%d]"), completed);
  1.1018 +	return completed;
  1.1019 +	}
  1.1020 +
  1.1021 +//
  1.1022 +// CMMFDevSoundSession::DoPauseL
  1.1023 +// (other items were commented in a header).
  1.1024 +//
  1.1025 +TBool CMMFDevSoundSession::DoPauseL(const RMmfIpcMessage& /*aMessage*/)
  1.1026 +	{
  1.1027 +	User::LeaveIfError(iAdapter->Pause());
  1.1028 +	iOperationCompletePending = ETrue;
  1.1029 +	return EFalse;
  1.1030 +	}
  1.1031 +
  1.1032 +//
  1.1033 +// CMMFDevSoundSession::DoPlayToneL
  1.1034 +// (other items were commented in a header).
  1.1035 +//
  1.1036 +TBool CMMFDevSoundSession::DoPlayToneL(const RMmfIpcMessage& aMessage)
  1.1037 +	{
  1.1038 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayToneL - Enter"));
  1.1039 +    TMMFDevSoundProxySettingsPckg devSoundBuf;
  1.1040 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
  1.1041 +	iCachedClientData = devSoundBuf;
  1.1042 +	TInt frequency = devSoundBuf().iFrequencyOne;
  1.1043 +	TTimeIntervalMicroSeconds duration(devSoundBuf().iDuration);
  1.1044 +	iAdapter->PlayToneL(frequency, duration);
  1.1045 +	iOperationCompletePending = ETrue;
  1.1046 +	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoPlayToneL - Exit. Return value is [%d]"), ETrue);
  1.1047 +	return ETrue;
  1.1048 +	}
  1.1049 +
  1.1050 +//
  1.1051 +// CMMFDevSoundSession::DoAlreadyCompletedPlayToneL
  1.1052 +// (other items were commented in a header).
  1.1053 +//
  1.1054 +void CMMFDevSoundSession::DoAlreadyCompletedPlayToneL()
  1.1055 +	{
  1.1056 +	TInt frequency = iCachedClientData().iFrequencyOne;
  1.1057 +	TTimeIntervalMicroSeconds duration(iCachedClientData().iDuration);
  1.1058 +	iAdapter->PlayToneL(frequency, duration);
  1.1059 +	iOperationCompletePending = ETrue;
  1.1060 +	}
  1.1061 +
  1.1062 +//
  1.1063 +// CMMFDevSoundSession::DoPlayDualToneL
  1.1064 +// (other items were commented in a header).	
  1.1065 +//
  1.1066 +TBool CMMFDevSoundSession::DoPlayDualToneL(const RMmfIpcMessage& aMessage)
  1.1067 +	{
  1.1068 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayDualToneL - Enter"));
  1.1069 +    TMMFDevSoundProxySettingsPckg devSoundBuf;
  1.1070 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
  1.1071 +	iCachedClientData = devSoundBuf;
  1.1072 +	TInt frequencyOne = devSoundBuf().iFrequencyOne;
  1.1073 +	TInt frequencyTwo = devSoundBuf().iFrequencyTwo;
  1.1074 +	TTimeIntervalMicroSeconds duration(devSoundBuf().iDuration);
  1.1075 +	iAdapter->PlayDualToneL(frequencyOne, frequencyTwo, duration);
  1.1076 +	iOperationCompletePending = ETrue;
  1.1077 +	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoPlayDualToneL - Exit. Return value is [%d]"), ETrue);
  1.1078 +	return ETrue;
  1.1079 +	}
  1.1080 +
  1.1081 +//
  1.1082 +// CMMFDevSoundSession::DoAlreadyCompletedPlayDualToneL
  1.1083 +// (other items were commented in a header).
  1.1084 +//
  1.1085 +void CMMFDevSoundSession::DoAlreadyCompletedPlayDualToneL()
  1.1086 +	{
  1.1087 +	TInt frequencyOne = iCachedClientData().iFrequencyOne;
  1.1088 +	TInt frequencyTwo = iCachedClientData().iFrequencyTwo;
  1.1089 +	TTimeIntervalMicroSeconds duration(iCachedClientData().iDuration);
  1.1090 +	iAdapter->PlayDualToneL(frequencyOne, frequencyTwo, duration);
  1.1091 +	iOperationCompletePending = ETrue;
  1.1092 +	}
  1.1093 +
  1.1094 +//
  1.1095 +// CMMFDevSoundSession::DoPlayDTMFStringL
  1.1096 +// (other items were commented in a header).
  1.1097 +//
  1.1098 +TBool CMMFDevSoundSession::DoPlayDTMFStringL(const RMmfIpcMessage& aMessage)
  1.1099 +	{
  1.1100 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayDTMFStringL - Enter"));
  1.1101 +    TInt dtmfLength = aMessage.GetDesLength(2);
  1.1102 +	
  1.1103 +	if(iDtmfString)
  1.1104 +		{
  1.1105 +		delete iDtmfString;
  1.1106 +		iDtmfString = NULL;
  1.1107 +		}
  1.1108 +
  1.1109 +	iDtmfString = HBufC::NewL(dtmfLength);
  1.1110 +	TPtr dtmfPtr = iDtmfString->Des();
  1.1111 +    User::LeaveIfError(MessageRead(aMessage, TInt(2), dtmfPtr));
  1.1112 +	iAdapter->PlayDTMFStringL(*iDtmfString);
  1.1113 +	iOperationCompletePending = ETrue;
  1.1114 +	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoPlayDTMFStringL - Exit. Return value is [%d]"), ETrue);
  1.1115 +	return ETrue;
  1.1116 +	}
  1.1117 +
  1.1118 +//
  1.1119 +// CMMFDevSoundSession::DoAlreadyCompletedPlayDTMFStringL
  1.1120 +// (other items were commented in a header).
  1.1121 +//
  1.1122 +void CMMFDevSoundSession::DoAlreadyCompletedPlayDTMFStringL()
  1.1123 +	{
  1.1124 +	iAdapter->PlayDTMFStringL(*iDtmfString);
  1.1125 +	iOperationCompletePending = ETrue;
  1.1126 +	}
  1.1127 +
  1.1128 +//
  1.1129 +// CMMFDevSoundSession::DoPlayToneSequenceL
  1.1130 +// (other items were commented in a header).
  1.1131 +//
  1.1132 +TBool CMMFDevSoundSession::DoPlayToneSequenceL(const RMmfIpcMessage& aMessage)
  1.1133 +	{
  1.1134 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayToneSequenceL - Enter"));
  1.1135 +    TInt toneLength = aMessage.GetDesLength(1);
  1.1136 +
  1.1137 +	if(iToneSeqBuf)
  1.1138 +		{
  1.1139 +		delete iToneSeqBuf;
  1.1140 +		iToneSeqBuf = NULL;
  1.1141 +		}
  1.1142 +
  1.1143 +	iToneSeqBuf = HBufC8::NewL(toneLength);
  1.1144 +	TPtr8 toneSeqPtr = iToneSeqBuf->Des();
  1.1145 +	User::LeaveIfError(MessageRead(aMessage,TInt(1), toneSeqPtr));
  1.1146 +
  1.1147 +	iAdapter->PlayToneSequenceL(*iToneSeqBuf);
  1.1148 +	iOperationCompletePending = ETrue;
  1.1149 +	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoPlayToneSequenceL - Exit. Return value is [%d]"), ETrue);
  1.1150 +	return ETrue;
  1.1151 +	}
  1.1152 +
  1.1153 +//
  1.1154 +// CMMFDevSoundSession::DoAlreadyCompletedPlayToneSequenceL
  1.1155 +// (other items were commented in a header).
  1.1156 +//
  1.1157 +void CMMFDevSoundSession::DoAlreadyCompletedPlayToneSequenceL()
  1.1158 +	{
  1.1159 +	iAdapter->PlayToneSequenceL(*iToneSeqBuf);
  1.1160 +	iOperationCompletePending = ETrue;
  1.1161 +	}
  1.1162 +
  1.1163 +//
  1.1164 +// CMMFDevSoundSession::DoPlayFixedSequenceL
  1.1165 +// (other items were commented in a header).
  1.1166 +//
  1.1167 +TBool CMMFDevSoundSession::DoPlayFixedSequenceL(const RMmfIpcMessage& aMessage)
  1.1168 +	{
  1.1169 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayFixedSequenceL - Enter"));
  1.1170 +    TPckgBuf<TInt> buf;
  1.1171 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),buf));
  1.1172 +	TInt seqNum = buf();
  1.1173 +	iSeqNum = seqNum;
  1.1174 +	iAdapter->PlayFixedSequenceL(seqNum);
  1.1175 +	iOperationCompletePending = ETrue;
  1.1176 +	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoPlayFixedSequenceL - Exit. Return value is [%d]"), ETrue);
  1.1177 +	return ETrue;
  1.1178 +	}
  1.1179 +
  1.1180 +//
  1.1181 +// CMMFDevSoundSession::DoAlreadyCompletedPlayFixedSequenceL
  1.1182 +// (other items were commented in a header).
  1.1183 +//
  1.1184 +void CMMFDevSoundSession::DoAlreadyCompletedPlayFixedSequenceL()
  1.1185 +	{
  1.1186 +	iAdapter->PlayFixedSequenceL(iSeqNum);
  1.1187 +	iOperationCompletePending = ETrue;
  1.1188 +	}
  1.1189 +
  1.1190 +//
  1.1191 +// CMMFDevSoundSession::DoSetDTMFLengthsL
  1.1192 +// (other items were commented in a header).
  1.1193 +//
  1.1194 +TBool CMMFDevSoundSession::DoSetDTMFLengthsL(const RMmfIpcMessage& aMessage)
  1.1195 +	{
  1.1196 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoSetDTMFLengthsL - Enter"));
  1.1197 +    TMMFDevSoundProxySettingsPckg devSoundBuf;
  1.1198 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
  1.1199 +	TTimeIntervalMicroSeconds32 toneOnLength = devSoundBuf().iToneOnLength;
  1.1200 +	TTimeIntervalMicroSeconds32 toneOffLength = devSoundBuf().iToneOffLength;
  1.1201 +	TTimeIntervalMicroSeconds32 pauseLength = devSoundBuf().iPauseLength;
  1.1202 +	User::LeaveIfError(iAdapter->SetDTMFLengths(toneOnLength, toneOffLength, pauseLength));
  1.1203 +    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoSetDTMFLengthsL - Exit. Return value is [%d]"), ETrue);
  1.1204 +	return ETrue;
  1.1205 +	}
  1.1206 +
  1.1207 +//
  1.1208 +// CMMFDevSoundSession::DoSetVolumeRampL
  1.1209 +// (other items were commented in a header).
  1.1210 +//
  1.1211 +TBool CMMFDevSoundSession::DoSetVolumeRampL(const RMmfIpcMessage& aMessage)
  1.1212 +	{
  1.1213 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoSetVolumeRampL - Enter"));
  1.1214 +    TMMFDevSoundProxySettingsPckg devSoundBuf;
  1.1215 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
  1.1216 +	TTimeIntervalMicroSeconds duration = devSoundBuf().iDuration;
  1.1217 +	User::LeaveIfError(iAdapter->SetVolumeRamp(duration));
  1.1218 +	iOperationCompletePending = EFalse; // Volume ramp doesn't result on commit
  1.1219 +    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoSetVolumeRampL - Exit. Return value is [%d]"), ETrue);
  1.1220 +	return ETrue; // operation complete
  1.1221 +	}
  1.1222 +
  1.1223 +//
  1.1224 +// CMMFDevSoundSession::DoGetSupportedInputDataTypesL
  1.1225 +// (other items were commented in a header).
  1.1226 +//
  1.1227 +TBool CMMFDevSoundSession::DoGetSupportedInputDataTypesL(
  1.1228 +							const RMmfIpcMessage& aMessage)
  1.1229 +	{
  1.1230 +	iArray.Reset();
  1.1231 +
  1.1232 +	TMMFPrioritySettingsPckg prioritySetBuf;
  1.1233 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),prioritySetBuf));
  1.1234 +	TMMFPrioritySettings prioritySet = prioritySetBuf();
  1.1235 +
  1.1236 +	iAdapter->GetSupportedInputDataTypesL(iArray, prioritySet);
  1.1237 +
  1.1238 +	TPckgBuf<TInt> pckg;
  1.1239 +	pckg() = iArray.Count();
  1.1240 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
  1.1241 +
  1.1242 +	return ETrue;
  1.1243 +	}
  1.1244 +
  1.1245 +//
  1.1246 +// CMMFDevSoundSession::DoGetSupportedOutputDataTypesL
  1.1247 +// (other items were commented in a header).
  1.1248 +//
  1.1249 +TBool CMMFDevSoundSession::DoGetSupportedOutputDataTypesL(
  1.1250 +							const RMmfIpcMessage& aMessage)
  1.1251 +	{
  1.1252 +	iArray.Reset();
  1.1253 +
  1.1254 +	TMMFPrioritySettingsPckg prioritySetBuf;
  1.1255 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),prioritySetBuf));
  1.1256 +	TMMFPrioritySettings prioritySet = prioritySetBuf();
  1.1257 +
  1.1258 +	iAdapter->GetSupportedOutputDataTypesL(iArray, prioritySet);
  1.1259 +
  1.1260 +	TPckgBuf<TInt> pckg;
  1.1261 +	pckg() = iArray.Count();
  1.1262 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
  1.1263 +
  1.1264 +	return ETrue;
  1.1265 +	}
  1.1266 +
  1.1267 +//
  1.1268 +// CMMFDevSoundSession::DoSamplesRecordedL
  1.1269 +// (other items were commented in a header).
  1.1270 +//
  1.1271 +TBool CMMFDevSoundSession::DoSamplesRecordedL(const RMmfIpcMessage& aMessage)
  1.1272 +	{
  1.1273 +	TPckgBuf<TInt> pckg;
  1.1274 +	pckg() = iAdapter->SamplesRecorded();
  1.1275 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
  1.1276 +	return ETrue;
  1.1277 +	}
  1.1278 +
  1.1279 +//
  1.1280 +// CMMFDevSoundSession::DoSamplesPlayedL
  1.1281 +// (other items were commented in a header).
  1.1282 +//
  1.1283 +TBool CMMFDevSoundSession::DoSamplesPlayedL(const RMmfIpcMessage& aMessage)
  1.1284 +	{
  1.1285 +	TPckgBuf<TInt> pckg;
  1.1286 +	pckg() = iAdapter->SamplesPlayed();
  1.1287 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
  1.1288 +	return ETrue;
  1.1289 +	}
  1.1290 +
  1.1291 +//
  1.1292 +// CMMFDevSoundSession::DoSetToneRepeatsL
  1.1293 +// (other items were commented in a header).
  1.1294 +//
  1.1295 +TBool CMMFDevSoundSession::DoSetToneRepeatsL(const RMmfIpcMessage& aMessage)
  1.1296 +	{
  1.1297 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoSetToneRepeatsL - Enter"));
  1.1298 +    TPckgBuf<TInt> countRepeat;
  1.1299 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),countRepeat));
  1.1300 +
  1.1301 +	TPckgBuf<TTimeIntervalMicroSeconds> repeatTS;
  1.1302 +	User::LeaveIfError(MessageRead(aMessage,TInt(2),repeatTS));
  1.1303 +	User::LeaveIfError(iAdapter->SetToneRepeats(countRepeat(), repeatTS()));
  1.1304 +    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoSetToneRepeatsL - Exit. Return value is [%d]"), ETrue);
  1.1305 +	return ETrue;
  1.1306 +	}
  1.1307 +
  1.1308 +//
  1.1309 +// CMMFDevSoundSession::DoSetPrioritySettingsL
  1.1310 +// (other items were commented in a header).
  1.1311 +//
  1.1312 +TBool CMMFDevSoundSession::DoSetPrioritySettingsL(
  1.1313 +						const RMmfIpcMessage& aMessage)
  1.1314 +	{
  1.1315 +	TPckgBuf<TMMFPrioritySettings> prioritySet;
  1.1316 +	User::LeaveIfError(MessageRead(aMessage,TInt(1),prioritySet));
  1.1317 +
  1.1318 +	User::LeaveIfError(iAdapter->SetPrioritySettings(prioritySet()));
  1.1319 +	iOperationCompletePending = EFalse;
  1.1320 +	return ETrue;
  1.1321 +	}
  1.1322 +
  1.1323 +//
  1.1324 +// CMMFDevSoundSession::DoFixedSequenceCountL
  1.1325 +// (other items were commented in a header).
  1.1326 +//
  1.1327 +TBool CMMFDevSoundSession::DoFixedSequenceCountL(
  1.1328 +					const RMmfIpcMessage& aMessage)
  1.1329 +	{
  1.1330 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoFixedSequenceCountL - Enter"));
  1.1331 +    TPckgBuf<TInt> fixSeqCountPckg;
  1.1332 +	TInt fixSeqCount = iAdapter->FixedSequenceCount();
  1.1333 +	fixSeqCountPckg = fixSeqCount;
  1.1334 +
  1.1335 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),fixSeqCountPckg));
  1.1336 +    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoFixedSequenceCountL - Exit. Return value is [%d]"), ETrue);
  1.1337 +	return ETrue;
  1.1338 +	}
  1.1339 +
  1.1340 +
  1.1341 +//
  1.1342 +// CMMFDevSoundSession::DoCopyFourCCArrayDataL
  1.1343 +// (other items were commented in a header).
  1.1344 +//
  1.1345 +TBool CMMFDevSoundSession::DoCopyFourCCArrayDataL(
  1.1346 +						const RMmfIpcMessage& aMessage)
  1.1347 +	{
  1.1348 +	const TInt KBufExpandSize8 = 8;//two TInts
  1.1349 +	CBufFlat* dataCopyBuffer = CBufFlat::NewL(KBufExpandSize8);
  1.1350 +	CleanupStack::PushL(dataCopyBuffer);
  1.1351 +	RBufWriteStream stream;
  1.1352 +	stream.Open(*dataCopyBuffer);
  1.1353 +	CleanupClosePushL(stream);
  1.1354 +	
  1.1355 +	TInt i = 0;
  1.1356 +	TInt count = iArray.Count();
  1.1357 +	
  1.1358 +	while (i < count)
  1.1359 +		{
  1.1360 +		stream.WriteInt32L(iArray[i].FourCC());
  1.1361 +		i++;
  1.1362 +		}
  1.1363 +	User::LeaveIfError(MessageWrite(aMessage, TInt(2), dataCopyBuffer->Ptr(0)));
  1.1364 +	stream.Close();
  1.1365 +	CleanupStack::PopAndDestroy(&stream);
  1.1366 +	CleanupStack::PopAndDestroy(dataCopyBuffer);
  1.1367 +	return ETrue;
  1.1368 +	}
  1.1369 +
  1.1370 +
  1.1371 +//
  1.1372 +// CMMFDevSoundSession::DoBufferToBeFilledDataL
  1.1373 +// (other items were commented in a header).
  1.1374 +//
  1.1375 +TBool CMMFDevSoundSession::DoBufferToBeFilledDataL(
  1.1376 +							const RMmfIpcMessage& aMessage)
  1.1377 +	{
  1.1378 +	// if CMMFDevSoundSession::PlayError() has been called, RChunk would have got closed.
  1.1379 +	// Need to check if Chunk Handle is still valid. If it is not,complete the message immediately and send a error to the Client.
  1.1380 +	if(!iChunk.Handle())
  1.1381 +		{
  1.1382 +		aMessage.Complete(KErrBadHandle);
  1.1383 +		return EFalse;	
  1.1384 +		}
  1.1385 +	TPckgBuf<TInt> requestChunkBuf;
  1.1386 +	User::LeaveIfError(MessageRead(aMessage, TInt(1), requestChunkBuf));
  1.1387 +	TBool requestChunk = requestChunkBuf();
  1.1388 +	if (requestChunk)
  1.1389 +		{
  1.1390 +		// if the client requests, always do EOpen
  1.1391 +		iHwBufPckgFill().iChunkOp = EOpen;
  1.1392 +		}
  1.1393 +	TInt err = MessageWrite(aMessage, TInt(2), iHwBufPckgFill);
  1.1394 +	if ( (err == KErrNone) && (iHwBufPckgFill().iChunkOp == EOpen) )
  1.1395 +		{
  1.1396 +		aMessage.Complete(iChunk);
  1.1397 +		}
  1.1398 +	else
  1.1399 +		{
  1.1400 +		aMessage.Complete(err);
  1.1401 +		}
  1.1402 +	return EFalse;
  1.1403 +	}
  1.1404 +
  1.1405 +// CMMFDevSoundSession::DoBufferToBeEmptiedDataL
  1.1406 +// (other items were commented in a header).
  1.1407 +//
  1.1408 +TBool CMMFDevSoundSession::DoBufferToBeEmptiedDataL(
  1.1409 +						const RMmfIpcMessage& aMessage)
  1.1410 +	{
  1.1411 +	// if CMMFDevSoundSession::RecordError() has been called, RChunk would have got closed.
  1.1412 +	// Need to check if Chunk Handle is still valid. If it is not,complete the message immediately and send a error to the Client.
  1.1413 +	if(!iChunk.Handle())
  1.1414 +		{
  1.1415 +		aMessage.Complete(KErrBadHandle);
  1.1416 +		return EFalse;	
  1.1417 +		}
  1.1418 +	
  1.1419 +	TInt err = MessageWrite(aMessage, TInt(2), iHwBufPckgEmpty);
  1.1420 +	if ( (err == KErrNone) && (iHwBufPckgEmpty().iChunkOp == EOpen) )
  1.1421 +		{
  1.1422 +		aMessage.Complete(iChunk);
  1.1423 +		}
  1.1424 +	else
  1.1425 +		{
  1.1426 +		aMessage.Complete(err);
  1.1427 +		}
  1.1428 +	return EFalse;
  1.1429 +	}
  1.1430 +
  1.1431 +//
  1.1432 +// CMMFDevSoundSession::DoEmptyBuffersL
  1.1433 +// (other items were commented in a header).
  1.1434 +//
  1.1435 +
  1.1436 +TBool CMMFDevSoundSession::DoEmptyBuffersL(const RMmfIpcMessage& aMessage)
  1.1437 +	{
  1.1438 +	TInt err = KErrNone;
  1.1439 +	FilterQueueEvent(EMMFDevSoundProxyBTBFEvent);
  1.1440 +	// This is now asynchronous
  1.1441 +	err = iAdapter->EmptyBuffers();
  1.1442 +	if (err != KErrNone)
  1.1443 +		{
  1.1444 +		aMessage.Complete(err);
  1.1445 +		return EFalse;
  1.1446 +		}
  1.1447 +	iOperationCompletePending = ETrue;
  1.1448 +	return EFalse;
  1.1449 +	}
  1.1450 +//
  1.1451 +// CMMFDevSoundSession::DoGetTimePlayedL
  1.1452 +// (other items were commented in a header).
  1.1453 +//
  1.1454 +TBool CMMFDevSoundSession::DoGetTimePlayedL(const RMmfIpcMessage& aMessage)
  1.1455 +	{
  1.1456 +	TInt err = KErrNone;
  1.1457 +	TTimeIntervalMicroSeconds time(0);
  1.1458 +	TPckgBuf<TTimeIntervalMicroSeconds> timePckg(time);
  1.1459 +	err = iAdapter->GetTimePlayed(timePckg());
  1.1460 +	if (err != KErrNone)
  1.1461 +		{
  1.1462 +		aMessage.Complete(err);
  1.1463 +		return EFalse;		
  1.1464 +		}
  1.1465 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),timePckg));
  1.1466 +	return ETrue;
  1.1467 +	}
  1.1468 +
  1.1469 +TBool CMMFDevSoundSession::DoQueryResumeSupportedL(const RMmfIpcMessage& aMessage)
  1.1470 +	{
  1.1471 +	TBool isSupported = EFalse;
  1.1472 +	TPckgBuf<TBool> isSupportedPckg(isSupported);
  1.1473 +	isSupportedPckg() = iAdapter->IsResumeSupported();
  1.1474 +	User::LeaveIfError(MessageWrite(aMessage,TInt(2),isSupportedPckg));
  1.1475 +	return ETrue;
  1.1476 +	}
  1.1477 +
  1.1478 +TBool CMMFDevSoundSession::DoResumeL(const RMmfIpcMessage& /*aMessage*/)
  1.1479 +	{
  1.1480 +	User::LeaveIfError( iAdapter->Resume() );
  1.1481 +	iOperationCompletePending = ETrue;
  1.1482 +	FilterQueueEvent(EMMFDevSoundProxyPausedRecordCompleteEvent);
  1.1483 +	return EFalse;
  1.1484 +	}
  1.1485 +
  1.1486 +TBool CMMFDevSoundSession::DoPrepareCloseL(const RMmfIpcMessage& /*aMessage*/)
  1.1487 +	{
  1.1488 +	TBool complete = iAdapter->CloseDevSound();
  1.1489 +	if(!complete)
  1.1490 +		{
  1.1491 +		iOperationCompletePending = ETrue;	
  1.1492 +		}
  1.1493 +	return complete;
  1.1494 +	}
  1.1495 +
  1.1496 +
  1.1497 +TBool CMMFDevSoundSession::DoCustomCommandL(const RMmfIpcMessage& aMessage)
  1.1498 +	{
  1.1499 +	TInt retVal = KErrNone;
  1.1500 +	TRAPD(err, retVal = iDeMuxUtility->ProcessCustomInterfaceCommandL(aMessage));
  1.1501 +	if (err != KErrNone)
  1.1502 +		{
  1.1503 +		// the framework left with an error condition
  1.1504 +		// so we complete the message with this error
  1.1505 +		// irrespective of whether its a Sync or Async custom command
  1.1506 +		aMessage.Complete(err);
  1.1507 +		}
  1.1508 +	else
  1.1509 +		{
  1.1510 +		TInt messageType = aMessage.Function();
  1.1511 +		if ((messageType == EMMFDevSoundProxySyncCustomCommand) ||
  1.1512 +			(messageType == EMMFDevSoundProxySyncCustomCommandResult))
  1.1513 +			{
  1.1514 +			// If its a sync custom command
  1.1515 +			// we can pass back valid values here since command
  1.1516 +			// has been handled by the DeMux framework
  1.1517 +			aMessage.Complete(retVal);	
  1.1518 +			}
  1.1519 +		}
  1.1520 +	
  1.1521 +	// we complete our own message so don't need the framework to do so
  1.1522 +	return EFalse;
  1.1523 +	}
  1.1524 +	
  1.1525 +
  1.1526 +//
  1.1527 +// CMMFDevSoundSession::CMMFDevSoundSession
  1.1528 +// (other items were commented in a header).
  1.1529 +//
  1.1530 +CMMFDevSoundSession::CMMFDevSoundSession() :
  1.1531 +	iSetClientConfigApplied (EFalse),
  1.1532 +	iDisconnecting (EFalse)
  1.1533 +	{
  1.1534 +	}
  1.1535 +
  1.1536 +//
  1.1537 +// CMMFDevSoundSession::~CMMFDevSoundSession
  1.1538 +// (other items were commented in a header).
  1.1539 +//
  1.1540 +CMMFDevSoundSession::~CMMFDevSoundSession()
  1.1541 +	{
  1.1542 +	delete iAsyncQueueStart;
  1.1543 +	// clear the array of custom interfaces
  1.1544 +	TInt count = iCustomInterfaceArray.Count();
  1.1545 +	for (TInt i = 0; i < count; i++)
  1.1546 +		{
  1.1547 +		// we could have already deleted interfaces without
  1.1548 +		// removing them from the array so check for this
  1.1549 +		// and only delete release plugin if non-null
  1.1550 +		MMMFDevSoundCustomInterfaceDeMuxPlugin* ptr = iCustomInterfaceArray[i].iInterface;
  1.1551 +		if (ptr)
  1.1552 +			{
  1.1553 +			iCustomInterfaceArray[i].iInterface->Release();	
  1.1554 +			}
  1.1555 +		}
  1.1556 +	iCustomInterfaceArray.Reset();
  1.1557 +	iCustomInterfaceArray.Close();
  1.1558 +		
  1.1559 +	delete iDeMuxUtility;
  1.1560 +	
  1.1561 +	if (iCIExtension)
  1.1562 +		{
  1.1563 +		iCIExtension->Release();
  1.1564 +		iCIExtension = NULL;
  1.1565 +		}
  1.1566 +
  1.1567 +	iMsgQueue.Close();
  1.1568 +	iArray.Close();
  1.1569 +	iQueuedRequests.Close();
  1.1570 +	delete iDtmfString;
  1.1571 +	delete iToneSeqBuf;
  1.1572 +	delete iAdapter;
  1.1573 +	delete iClosingWait;
  1.1574 +
  1.1575 +	CMMFDevSoundServer* server =
  1.1576 +			const_cast<CMMFDevSoundServer*>(
  1.1577 +			static_cast<const CMMFDevSoundServer*>(Server()));
  1.1578 +
  1.1579 +	if (server)
  1.1580 +		{
  1.1581 +		server->DecrementSessionId();
  1.1582 +		}
  1.1583 +
  1.1584 +//	delete iCustomCommandParserManager;
  1.1585 +//	delete iMMFObjectContainer;
  1.1586 +
  1.1587 +	// Close chunk
  1.1588 +	iChunk.Close();
  1.1589 +	}
  1.1590 +
  1.1591 +//
  1.1592 +// CMMFDevSoundSession::FlushEventQueue()
  1.1593 +//
  1.1594 +void CMMFDevSoundSession::FlushEventQueue()
  1.1595 +	{
  1.1596 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::FlushEventQueue - Enter"));
  1.1597 +    if(iMsgQueue.Handle() != 0)
  1.1598 +		{
  1.1599 +		TMMFDevSoundQueueItem queueItem;
  1.1600 +		TInt err = KErrNone;
  1.1601 +		while(err != KErrUnderflow)
  1.1602 +			{
  1.1603 +			err = iMsgQueue.Receive(queueItem);
  1.1604 +			}
  1.1605 +		}
  1.1606 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::FlushEventQueue - Exit"));
  1.1607 +	}
  1.1608 +
  1.1609 +void CMMFDevSoundSession::FilterQueueEvent(TMMFDevSoundProxyRequest aRequest)
  1.1610 +	{
  1.1611 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::FilterQueueEvent - Enter"));
  1.1612 +    if(iMsgQueue.Handle() != 0)
  1.1613 +		{
  1.1614 +		// Pop and push events result at the queue 
  1.1615 +		// can be seen as "circular list"
  1.1616 +		// set a mark to traverse it safely 
  1.1617 +		TMMFDevSoundQueueItem markItem;
  1.1618 +		markItem.iRequest = EMMFDevSoundProxyMarkEvent;
  1.1619 +		// assumes sufficient space in the queue
  1.1620 +		TInt err = iMsgQueue.Send(markItem);
  1.1621 +		__ASSERT_DEBUG(err == KErrNone, Panic(EMsgQueueFailedToSendMsg));
  1.1622 +		
  1.1623 +		while(ETrue)
  1.1624 +			{
  1.1625 +			// At least the markEvent is at the queue so ignore the error
  1.1626 +			TMMFDevSoundQueueItem queueItem;
  1.1627 +			err = iMsgQueue.Receive(queueItem);
  1.1628 +			if(queueItem.iRequest == EMMFDevSoundProxyMarkEvent)
  1.1629 +				{
  1.1630 +				break;
  1.1631 +				}
  1.1632 +			// Look for the specific event
  1.1633 +			else if(queueItem.iRequest != aRequest)
  1.1634 +				{
  1.1635 +				// assumes sufficient space in the queue
  1.1636 +				err = iMsgQueue.Send(queueItem);
  1.1637 +				}
  1.1638 +			}
  1.1639 +		}
  1.1640 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::FilterQueueEvent - Exit"));
  1.1641 +	}
  1.1642 +
  1.1643 +//
  1.1644 +// CMMFDevSoundSession::Disconnect
  1.1645 +// (other items were commented in a header).
  1.1646 +//
  1.1647 +void CMMFDevSoundSession::Disconnect(const RMessage2& aMessage)
  1.1648 +	{
  1.1649 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::Disconnect - Enter"));
  1.1650 +    iDisconnecting = ETrue;
  1.1651 +	
  1.1652 +    if (NeedToQueue())
  1.1653 +        {
  1.1654 +        // if we are in the middle of something, enqueue and wait
  1.1655 +        SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::Disconnect - Add to queue"));
  1.1656 +        EnqueueRequest(aMessage);
  1.1657 +        iClosingWait->Start();
  1.1658 +        }
  1.1659 +    else
  1.1660 +        {
  1.1661 +        // else do now. Enter ActiveSchedulerWait to wait for AsyncOpComplete
  1.1662 +        TBool complete = iAdapter->CloseDevSound();
  1.1663 +        if(!complete)
  1.1664 +            {
  1.1665 +            iRequestBeingServiced.SetMessage(aMessage);
  1.1666 +            iOperationCompletePending = ETrue;
  1.1667 +            ResetNotifiedError();
  1.1668 +            iClosingWait->Start();
  1.1669 +            }
  1.1670 +        }
  1.1671 +	CSession2::Disconnect(aMessage);
  1.1672 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::Disconnect - Exit"));
  1.1673 +	}
  1.1674 +
  1.1675 +
  1.1676 +//
  1.1677 +// CMMFDevSoundSession::NewL
  1.1678 +// (other items were commented in a header).
  1.1679 +//
  1.1680 +CMMFDevSoundSession* CMMFDevSoundSession::NewL(MGlobalProperties& aGlobalProperties)
  1.1681 +	{
  1.1682 +	CMMFDevSoundSession* self = new (ELeave) CMMFDevSoundSession;
  1.1683 +	CleanupStack::PushL(self);
  1.1684 +	self->ConstructL(aGlobalProperties);
  1.1685 +	CleanupStack::Pop(self);
  1.1686 +	return self;
  1.1687 +	}
  1.1688 +
  1.1689 +//
  1.1690 +// CMMFDevSoundSession::ConstructL
  1.1691 +// (other items were commented in a header).
  1.1692 +//
  1.1693 +void CMMFDevSoundSession::ConstructL(MGlobalProperties& aGlobalProperties)
  1.1694 +	{
  1.1695 +	iAdapter = CMMFDevSoundAdaptation::NewL(*this, aGlobalProperties);
  1.1696 +
  1.1697 +	iClosingWait = new(ELeave) CActiveSchedulerWait();
  1.1698 +	
  1.1699 +	// Create the Custom Interface DeMux Utility
  1.1700 +	iDeMuxUtility = CMMFDevSoundCIDeMuxUtility::NewL(this);
  1.1701 +	
  1.1702 +	// Create the Custom Interface extension
  1.1703 +	TUid implUid = {KMmfUidCIServerExtensionImpl};
  1.1704 +	TInt uidAsInteger = implUid.iUid;
  1.1705 +	const TInt KCIExtTempBufferSize = 20;
  1.1706 +	TBuf8<KCIExtTempBufferSize> tempBuffer;
  1.1707 +	tempBuffer.Num(uidAsInteger, EHex);
  1.1708 +	TUid interfaceUid = {KUidDevSoundCIServerExtension};
  1.1709 +	TUid destructorKey;
  1.1710 +	TRAPD(err, iCIExtension = static_cast<MDevSoundCIServerExtension*>
  1.1711 +		 (MmPluginUtils::CreateImplementationL(interfaceUid, destructorKey, tempBuffer, KRomOnlyResolverUid)));
  1.1712 +	if (KErrNotSupported == err)
  1.1713 +		{
  1.1714 +		iCIExtension = NULL;
  1.1715 +		}
  1.1716 +	else
  1.1717 +		{
  1.1718 +		User::LeaveIfError(err);
  1.1719 +		}
  1.1720 +	if (iCIExtension)
  1.1721 +		{
  1.1722 +		// Extension exists. Complete the setup
  1.1723 +		iCIExtension->PassDestructorKey(destructorKey);
  1.1724 +		User::LeaveIfError(iCIExtension->Setup(*this));
  1.1725 +		}
  1.1726 +
  1.1727 +	iQueuedRequests.ReserveL(KMaxQueueRequest);
  1.1728 +	iAsyncQueueStart = new (ELeave) CAsyncCallBack(CActive::EPriorityStandard);
  1.1729 +	TCallBack asyncCallback(AsyncQueueStartCallback, this);
  1.1730 +	iAsyncQueueStart->Set(asyncCallback);
  1.1731 +	}
  1.1732 +
  1.1733 +// CMMFDevSoundSession::InitializeComplete
  1.1734 +// (other items were commented in a header).
  1.1735 +//
  1.1736 +void CMMFDevSoundSession::InitializeComplete(TInt aError)
  1.1737 +	{
  1.1738 +	// this may be a re-initialization and so we need to
  1.1739 +	// re-get our custom interfaces on the DeMux plugins
  1.1740 +	TInt count = iCustomInterfaceArray.Count();
  1.1741 +	for (TInt i = 0; i < count; i++)
  1.1742 +		{
  1.1743 +		// we could have already deleted interfaces without
  1.1744 +		// removing them from the array so check for this
  1.1745 +		// and only refresh plugin if non-null
  1.1746 +		MMMFDevSoundCustomInterfaceDeMuxPlugin* ptr = iCustomInterfaceArray[i].iInterface;
  1.1747 +		if (ptr)
  1.1748 +			{
  1.1749 +			// we can't keep track of..
  1.1750 +			// 1. where a custom interface is implemented
  1.1751 +			// 2. the uid of the custom interface to be refreshed
  1.1752 +			// so assume all have to be refreshed
  1.1753 +			TRAPD(err, ptr->RefreshL());	
  1.1754 +			
  1.1755 +			// Error indicates this is no longer a valid interface
  1.1756 +			if (err != KErrNone)
  1.1757 +				{
  1.1758 +				TMMFEvent event;
  1.1759 +				TMMFDevSoundQueueItem item;
  1.1760 +				item.iRequest = EMMFDevSoundCustomCommandCloseMuxDemuxPair;
  1.1761 +				item.iErrorCode = err;
  1.1762 +				event.iEventType.iUid = i+1;
  1.1763 +				item.iEventPckg() = event;
  1.1764 +				TInt lErr = iMsgQueue.Send(item);
  1.1765 +				__ASSERT_DEBUG(lErr == KErrNone, Panic(EMsgQueueFailedToSendMsg));
  1.1766 +
  1.1767 +// NB proper panic code required here for this part.
  1.1768 +				}
  1.1769 +			}
  1.1770 +		}
  1.1771 +	TMMFDevSoundQueueItem item;
  1.1772 +	item.iRequest = EMMFDevSoundProxyICEvent;
  1.1773 +	item.iErrorCode = aError;
  1.1774 +	// assumes sufficient space in the queue so ignores the return value
  1.1775 +	iMsgQueue.Send(item); 
  1.1776 +	}
  1.1777 +
  1.1778 +// 
  1.1779 +// CMMFDevSoundSession::ToneFinished
  1.1780 +// (other items were commented in a header).
  1.1781 +//
  1.1782 +void CMMFDevSoundSession::ToneFinished(TInt aError)
  1.1783 +	{
  1.1784 +    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::ToneFinished - Enter. Error [%d]"), aError);
  1.1785 +    TMMFDevSoundQueueItem item;
  1.1786 +	item.iRequest = EMMFDevSoundProxyTFEvent;
  1.1787 +	item.iErrorCode = aError;
  1.1788 +	// assumes sufficient space in the queue so ignores the return value
  1.1789 +	iMsgQueue.Send(item);
  1.1790 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::ToneFinished - Exit"));
  1.1791 +	}
  1.1792 +
  1.1793 +//
  1.1794 +// CMMFDevSoundSession::BufferToBeFilled
  1.1795 +// (other items were commented in a header).
  1.1796 +//
  1.1797 +void CMMFDevSoundSession::BufferToBeFilled(CMMFBuffer* aBuffer)
  1.1798 +	{
  1.1799 +	SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::BufferToBeFilled - Enter"));
  1.1800 +
  1.1801 +	// Set play error flag to false 
  1.1802 +	iPlayErrorOccured = EFalse;
  1.1803 +
  1.1804 +	// Store pointer to the buffer to use it later with PlayData
  1.1805 +	iBufferPlay = reinterpret_cast<CMMFDataBuffer*>(aBuffer);
  1.1806 +	TInt status = CreateChunk(iHwBufPckgFill, iBufferPlay->RequestSize());
  1.1807 +	iHwBufPckgFill().iRequestSize = iBufferPlay->RequestSize();
  1.1808 +	iHwBufPckgFill().iBufferSize = iBufferPlay->Data().MaxLength();
  1.1809 +	iHwBufPckgFill().iLastBuffer = iBufferPlay->LastBuffer();
  1.1810 +	TMMFDevSoundQueueItem queueItem;
  1.1811 +	if ( status != KErrNone )
  1.1812 +		{
  1.1813 +		BufferErrorEvent();
  1.1814 +		PlayError(status);
  1.1815 +		}
  1.1816 +	else
  1.1817 +		{
  1.1818 +		queueItem.iRequest = EMMFDevSoundProxyBTBFEvent;
  1.1819 +		// assumes sufficient space in the queue so ignores the return value
  1.1820 +		status = iMsgQueue.Send(queueItem);
  1.1821 +		}
  1.1822 +
  1.1823 +	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::BufferToBeFilled - Exit [%d]"), status);
  1.1824 +	}
  1.1825 +
  1.1826 +//
  1.1827 +// CMMFDevSoundSession::PlayError
  1.1828 +// (other items were commented in a header).
  1.1829 +//
  1.1830 +void CMMFDevSoundSession::PlayError(TInt aError)
  1.1831 +	{
  1.1832 +    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::PlayError - Enter [%d]"), aError);
  1.1833 +
  1.1834 +	// Set play error flag to ignore following PlayData requests
  1.1835 +	iPlayErrorOccured = ETrue;
  1.1836 +
  1.1837 +	TMMFDevSoundQueueItem item;
  1.1838 +	item.iRequest = EMMFDevSoundProxyPEEvent;
  1.1839 +	item.iErrorCode = aError;
  1.1840 +	iChunk.Close();
  1.1841 +	// assumes sufficient space in the queue so ignores the return value
  1.1842 +	iMsgQueue.Send(item);
  1.1843 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PlayError - Exit"));
  1.1844 +	}
  1.1845 +
  1.1846 +//
  1.1847 +// CMMFDevSoundSession::BufferToBeEmptied
  1.1848 +// (other items were commented in a header).
  1.1849 +//
  1.1850 +void CMMFDevSoundSession::BufferToBeEmptied(CMMFBuffer* aBuffer)
  1.1851 +	{
  1.1852 +	// Store pointer to the buffer to use it later with RecordData
  1.1853 +	iBufferRecord = reinterpret_cast<CMMFDataBuffer*>(aBuffer);
  1.1854 +	TInt status = CreateChunk(iHwBufPckgEmpty, iBufferRecord->RequestSize());
  1.1855 +	
  1.1856 +	if ( status != KErrNone )
  1.1857 +		{
  1.1858 +		BufferErrorEvent();
  1.1859 +		RecordError(status);
  1.1860 +		}
  1.1861 +	else
  1.1862 +		{
  1.1863 +		iHwBufPckgEmpty().iRequestSize = iBufferRecord->RequestSize();
  1.1864 +		iHwBufPckgEmpty().iBufferSize = iBufferRecord->Data().MaxLength();
  1.1865 +		iHwBufPckgEmpty().iLastBuffer = iBufferRecord->LastBuffer();
  1.1866 +		//copy the data into the chunk    
  1.1867 +		Mem::Copy(iChunk.Base(),iBufferRecord->Data().Ptr(),iBufferRecord->RequestSize());
  1.1868 +	    TMMFDevSoundQueueItem queueItem;
  1.1869 +		queueItem.iRequest = EMMFDevSoundProxyBTBEEvent;
  1.1870 +		// assumes sufficient space in the queue so ignores the return value
  1.1871 +		iMsgQueue.Send(queueItem);
  1.1872 +		}
  1.1873 +	}
  1.1874 +
  1.1875 +// CMMFDevSoundSession::RecordError
  1.1876 +// (other items were commented in a header).
  1.1877 +//
  1.1878 +void CMMFDevSoundSession::RecordError(TInt aError)
  1.1879 +	{
  1.1880 +	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::Record Error [%d]"), aError);
  1.1881 +	TMMFDevSoundQueueItem item;
  1.1882 +	item.iRequest = EMMFDevSoundProxyREEvent;
  1.1883 +	item.iErrorCode = aError;
  1.1884 +	iChunk.Close();
  1.1885 +	// assumes sufficient space in the queue so ignores the return value
  1.1886 +	iMsgQueue.Send(item);
  1.1887 +	}
  1.1888 +
  1.1889 +//
  1.1890 +// CMMFDevSoundSession::DeviceMessage
  1.1891 +// (other items were commented in a header).
  1.1892 +//
  1.1893 +void CMMFDevSoundSession::DeviceMessage(TUid /*aMessageType*/,
  1.1894 +									const TDesC8& /*aMsg*/)
  1.1895 +	{
  1.1896 +	// Not used
  1.1897 +	}
  1.1898 +
  1.1899 +void CMMFDevSoundSession::InterfaceDeleted(TUid aInterfaceId)
  1.1900 +	{
  1.1901 +	MMMFDevSoundCustomInterfaceDeMuxPlugin* ptr = InterfaceFromUid(aInterfaceId);
  1.1902 +	if (ptr == NULL)
  1.1903 +		{
  1.1904 +		// Not found
  1.1905 +		return;
  1.1906 +		}
  1.1907 +	TRAPD(err, ptr->RefreshL());
  1.1908 +	if (err != KErrNone)
  1.1909 +		{
  1.1910 +		// Refresh failed, so tear down Mux/DeMux pair
  1.1911 +		TMMFEvent event;
  1.1912 +		TMMFDevSoundQueueItem item;
  1.1913 +		item.iRequest = EMMFDevSoundCustomCommandCloseMuxDemuxPair;
  1.1914 +		item.iErrorCode = err;
  1.1915 +		event.iEventType = aInterfaceId;
  1.1916 +		item.iEventPckg() = event;
  1.1917 +		iMsgQueue.Send(item);
  1.1918 +		}
  1.1919 +	}
  1.1920 +
  1.1921 +//
  1.1922 +// CMMFDevSoundSession::CallbackFromAdaptorReceived
  1.1923 +// (other items were commented in a header).
  1.1924 +//
  1.1925 +void CMMFDevSoundSession::CallbackFromAdaptorReceived(TInt aType, TInt aError)
  1.1926 +	{
  1.1927 +    SYMBIAN_DEBPRN2(_L("CMMFDevSoundSession[0x%x]::CallbackFromAdaptorReceived - Enter. Type[%d] Error[%d]"), aType, aError);
  1.1928 +	if(aType == KCallbackRecordPauseComplete)
  1.1929 +		{
  1.1930 +		TMMFDevSoundQueueItem item;
  1.1931 +		item.iRequest = EMMFDevSoundProxyPausedRecordCompleteEvent;
  1.1932 +		item.iErrorCode = KErrNone;
  1.1933 +		TInt status = iMsgQueue.Send(item);
  1.1934 +		}
  1.1935 +	else if(aType == KCallbackAutoPauseResume)
  1.1936 +		{
  1.1937 +		TMMFEvent event;
  1.1938 +		event.iErrorCode = KErrNone;
  1.1939 +		event.iEventType = KMMFEventCategoryAudioResourceAvailable;
  1.1940 +		SendEventToClient(event);
  1.1941 +		//coverity[uninit_use_in_call]
  1.1942 +		// Disabled Coverity warning, since it complains about iReserved1 member in TMMFEvent being uninitialised
  1.1943 +		}
  1.1944 +	else if (aType == KCallbackFlushComplete)
  1.1945 +		{
  1.1946 +		if(!iHandlingExtdCI && iRequestBeingServiced.Function()==EMMFDevSoundProxyEmptyBuffers)
  1.1947 +			{
  1.1948 +			//If we come here then it is due to a EMMFDevSoundProxyEmptyBuffers request from client.
  1.1949 +			SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::CallbackFromAdaptorReceived - Calling TMMFDevSoundRequest::Complete on iRequestBeingServiced"));
  1.1950 +		    iRequestBeingServiced.Complete(aError);
  1.1951 +		    iOperationCompletePending = EFalse;
  1.1952 +			}
  1.1953 +		}
  1.1954 +	else
  1.1955 +		{
  1.1956 +		if( NeedToQueue() )
  1.1957 +			{
  1.1958 +			// If not possible to service now, then queue request
  1.1959 +			// Encapsule the request
  1.1960 +			TMMFDevSoundRequest request(aType);
  1.1961 +			// assumes sufficient space in the queue so ignores the return value
  1.1962 +			iQueuedRequests.Insert(request, 0);
  1.1963 +			}
  1.1964 +		else
  1.1965 +			{
  1.1966 +			// If there is no oustanding operation service inmediately
  1.1967 +			if (aType == KCallbackProcessingFinished)
  1.1968 +				{
  1.1969 +				DoProcessingFinished();
  1.1970 +				}
  1.1971 +			else if(aType == KCallbackProcessingUnitError)
  1.1972 +				{
  1.1973 +				DoProcessingError();
  1.1974 +				}
  1.1975 +			}
  1.1976 +		}
  1.1977 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::CallbackFromAdaptorReceived - Exit"));
  1.1978 +	}
  1.1979 +
  1.1980 +
  1.1981 +//
  1.1982 +// CMMFDevSoundSession::PreemptionStartedCallbackReceived
  1.1983 +// (other items were commented in a header).
  1.1984 +//
  1.1985 +void CMMFDevSoundSession::PreemptionStartedCallbackReceived()
  1.1986 +	{
  1.1987 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PreemptionStartedCallbackReceived - Enter"));
  1.1988 +    // Solution: Enqueue any request that arrives before preemption is completed
  1.1989 +	iOperationCompletePending = ETrue;
  1.1990 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PreemptionStartedCallbackReceived - Exit"));
  1.1991 +	}
  1.1992 +
  1.1993 +//
  1.1994 +// CMMFDevSoundSession::PreemptionFinishedCallbackReceived
  1.1995 +// (other items were commented in a header).
  1.1996 +//
  1.1997 +void CMMFDevSoundSession::PreemptionFinishedCallbackReceived(TBool aCanStartNewOperation)
  1.1998 +	{
  1.1999 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PreemptionFinishedCallbackReceived - Enter"));
  1.2000 +    if (iHandlingExtdCI)
  1.2001 +        {
  1.2002 +        // we are in the middle of handling a CI, so ignore - will handle later when unwinding
  1.2003 +        SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PreemptionFinishedCallbackReceived - Exit. Exiting from if block for CI"));
  1.2004 +		return;
  1.2005 +        }
  1.2006 +	iOperationCompletePending = EFalse;
  1.2007 +	if ( aCanStartNewOperation && iQueuedRequests.Count() != 0 )
  1.2008 +		{
  1.2009 +		DequeueRequest();
  1.2010 +		}
  1.2011 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PreemptionFinishedCallbackReceived - Exit"));
  1.2012 +	}
  1.2013 +
  1.2014 +//
  1.2015 +// CMMFDevSoundSession::PreemptionClash
  1.2016 +// (other items were commented in a header).
  1.2017 +//
  1.2018 +void CMMFDevSoundSession::PreemptionClash()
  1.2019 +	{
  1.2020 +	//assumes sufficient space in the queue so ignore the return value
  1.2021 +	iQueuedRequests.Insert(iRequestBeingServiced, 0);
  1.2022 +	iPreemptionClash=ETrue;
  1.2023 +	}
  1.2024 +
  1.2025 +//
  1.2026 +// CMMFDevSoundSession::PreemptionClashWithStateChange
  1.2027 +// (other items were commented in a header).
  1.2028 +//
  1.2029 +void CMMFDevSoundSession::PreemptionClashWithStateChange()
  1.2030 +	{
  1.2031 +	#ifdef _DEBUG
  1.2032 +		TMMFDevSoundRequest msg = iQueuedRequests[0];
  1.2033 +		// message being removed should be the one we previously pushed via PreemptionClash()
  1.2034 +		__ASSERT_DEBUG(iRequestBeingServiced==msg, Panic(ERequestBeingServicedMismatch));
  1.2035 +	#endif
  1.2036 +	// remove without processing request with AsynchronousOperationComplete() completing the message
  1.2037 +	iQueuedRequests.Remove(0);
  1.2038 +	iPreemptionClash=EFalse;
  1.2039 +	}
  1.2040 +
  1.2041 +//
  1.2042 +// CMMFDevSoundSession::AdaptorControlsContext()
  1.2043 +//
  1.2044 +
  1.2045 +TBool CMMFDevSoundSession::AdaptorControlsContext() const
  1.2046 +    {
  1.2047 +    return !iHandlingExtdCI;
  1.2048 +    }
  1.2049 +
  1.2050 +MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFDevSoundSession::InterfaceFromUid(TUid aUid)
  1.2051 +	{
  1.2052 +	TInt count = iCustomInterfaceArray.Count();
  1.2053 +	TInt id = aUid.iUid;
  1.2054 +	MMMFDevSoundCustomInterfaceDeMuxPlugin* interface = NULL;
  1.2055 +	for (TInt i = 0; i < count; i++)
  1.2056 +		{
  1.2057 +		if (id == iCustomInterfaceArray[i].iId.iUid)
  1.2058 +			{
  1.2059 +			interface = iCustomInterfaceArray[i].iInterface;
  1.2060 +			break;
  1.2061 +			}
  1.2062 +		}
  1.2063 +	return interface;
  1.2064 +	}
  1.2065 +
  1.2066 +//
  1.2067 +// CMMFDevSoundSession::SendEventToClient
  1.2068 +// (other items were commented in a header).
  1.2069 +//
  1.2070 +void CMMFDevSoundSession::SendEventToClient(const TMMFEvent& aEvent)
  1.2071 +	{
  1.2072 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::SendEventToClient - Enter"));
  1.2073 +    TMMFDevSoundQueueItem item;
  1.2074 +	item.iRequest = EMMFDevSoundProxySETCEvent;
  1.2075 +	item.iErrorCode = KErrNone;
  1.2076 +	item.iEventPckg() = aEvent;
  1.2077 +	// assumes sufficient space in the queue so ignores the return value
  1.2078 +	TInt err = iMsgQueue.Send(item);
  1.2079 +    __ASSERT_DEBUG(err == KErrNone, Panic(EMsgQueueFailedToSendMsg));
  1.2080 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::SendEventToClient - Exit"));
  1.2081 +	}
  1.2082 +
  1.2083 +void CMMFDevSoundSession::AsynchronousOperationComplete(TInt aError, TBool aCanStartNewOperation)
  1.2084 +	{
  1.2085 +    __ASSERT_DEBUG(!iHandlingExtdCI, Panic(EUnexpectedAsyncOpCompleteHandlingCI));
  1.2086 +        // when handling CIs we should not reach here
  1.2087 +
  1.2088 +    TInt error = aError;
  1.2089 +    if (!error)
  1.2090 +        {
  1.2091 +        // if have no error payload, use notified error. It will be KErrNone if not set, so just use.
  1.2092 +        error = NotifiedError();
  1.2093 +        }
  1.2094 +
  1.2095 +	switch (iRequestBeingServiced.Type())
  1.2096 +		{
  1.2097 +		case TMMFDevSoundRequest::ESessionEvents:
  1.2098 +			{
  1.2099 +			SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x] ==== ClosingDueException ==== "));
  1.2100 +			iOperationCompletePending = EFalse;
  1.2101 +			if(iClosingWait->IsStarted())
  1.2102 +				{
  1.2103 +				iClosingWait->AsyncStop();
  1.2104 +				}
  1.2105 +			return;
  1.2106 +			}
  1.2107 +		// Complete the message for asynchronous requests
  1.2108 +		case TMMFDevSoundRequest::EConfigure_Asynchronous:
  1.2109 +		case TMMFDevSoundRequest::EAction_Asynchronous:
  1.2110 +		case TMMFDevSoundRequest::EQuery_Asynchronous:
  1.2111 +		case TMMFDevSoundRequest::ECustomInterfacesRelated:
  1.2112 +			{
  1.2113 +			if(iOperationCompletePending && aCanStartNewOperation)
  1.2114 +				{
  1.2115 +				if (iRequestBeingServiced.Function()==EMMFDevSoundProxyStop)
  1.2116 +					{
  1.2117 +					// flush the queue - will have removed any stale items added between initial call and MMRC's reaction
  1.2118 +                    FlushQueuedRequests();
  1.2119 +					FlushEventQueue();
  1.2120 +					iChunk.Close();
  1.2121 +					}
  1.2122 +					
  1.2123 +				if(iRequestBeingServiced.Function()==EMMFDevSoundProxyCapabilities)
  1.2124 +					{
  1.2125 +					TMMFDevSoundProxySettings devSoundSet;
  1.2126 +					devSoundSet.iCaps = iDevSoundCapabilities;
  1.2127 +					TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
  1.2128 +					MessageWrite(iRequestBeingServiced.Message(),TInt(2),pckg);
  1.2129 +					}
  1.2130 +				
  1.2131 +				if(iRequestBeingServiced.Function()==EMMFDevSoundProxyCancelInitialize)
  1.2132 +					{
  1.2133 +					FlushEventQueue();
  1.2134 +					}
  1.2135 +				
  1.2136 +				iRequestBeingServiced.Complete(error);
  1.2137 +				iOperationCompletePending = EFalse;
  1.2138 +				}
  1.2139 +			}
  1.2140 +			break;
  1.2141 +		case TMMFDevSoundRequest::EAction_PseudoAsynchronous:
  1.2142 +			{
  1.2143 +			if(iOperationCompletePending && aCanStartNewOperation)
  1.2144 +				{
  1.2145 +				iOperationCompletePending = EFalse;
  1.2146 +				}
  1.2147 +			}
  1.2148 +			break;
  1.2149 +		case TMMFDevSoundRequest::EQuery_Synchronous:
  1.2150 +		case TMMFDevSoundRequest::EConfigure_Synchronous:
  1.2151 +		case TMMFDevSoundRequest::EBufferExchangeRelated:
  1.2152 +			break;
  1.2153 +		case TMMFDevSoundRequest::ECallBackType:
  1.2154 +			{
  1.2155 +			if(iOperationCompletePending && aCanStartNewOperation)
  1.2156 +				{
  1.2157 +				iOperationCompletePending = EFalse;
  1.2158 +				}	
  1.2159 +			}
  1.2160 +			break;
  1.2161 +		default:
  1.2162 +			break;
  1.2163 +		}
  1.2164 +	
  1.2165 +	if(iRequestBeingServiced.Type() == TMMFDevSoundRequest::ECallBackType )
  1.2166 +	    {	    
  1.2167 +	    SYMBIAN_DEBPRN2(_L("CMMFDevSoundSession[0x%x] AsynchronousOperationComplete CallbackPF=%d pending=%d"),
  1.2168 +	            iRequestBeingServiced.IsCallBack(), iOperationCompletePending );
  1.2169 +	    }
  1.2170 +	else
  1.2171 +	    {
  1.2172 +	    SYMBIAN_DEBPRN3(_L("CMMFDevSoundSession[0x%x] AsynchronousOperationComplete %x pending=%d Requestype=%d"),
  1.2173 +	            iRequestBeingServiced.Function(), iOperationCompletePending, iRequestBeingServiced.Type() );
  1.2174 +	    }
  1.2175 +
  1.2176 +	    
  1.2177 +	if ( aCanStartNewOperation && iQueuedRequests.Count() != 0 )
  1.2178 +		{
  1.2179 +		DequeueRequest();
  1.2180 +		}
  1.2181 +	}
  1.2182 +
  1.2183 +void CMMFDevSoundSession::DequeueRequest()
  1.2184 +	{
  1.2185 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DequeueRequest - Enter"));
  1.2186 +    iAsyncQueueStart->Cancel(); // if we're in here cancel any background request
  1.2187 +
  1.2188 +	TMMFDevSoundRequest msg = iQueuedRequests[0];
  1.2189 +
  1.2190 +	if (msg.IsCallBack() > 0)
  1.2191 +		{
  1.2192 +		iRequestBeingServiced.SetMessageCallback();
  1.2193 +		//Call iPf function
  1.2194 +		SYMBIAN_DEBPRN0(_L("\n CMMFDevSoundSession[0x%x] ======== Service a queued request\n"));
  1.2195 +		if (msg.IsCallBack() == KCallbackProcessingFinished)
  1.2196 +			{
  1.2197 +			iQueuedRequests.Remove(0);
  1.2198 +			DoProcessingFinished();
  1.2199 +			}
  1.2200 +		else if(msg.IsCallBack() == KCallbackProcessingUnitError)
  1.2201 +		    {
  1.2202 +		    iQueuedRequests.Remove(0);
  1.2203 +		    DoProcessingError();
  1.2204 +		    }
  1.2205 +
  1.2206 +		}
  1.2207 +
  1.2208 +	if (iQueuedRequests.Count()>0)
  1.2209 +		{
  1.2210 +		// Some rules about what request can be followed
  1.2211 +		SYMBIAN_DEBPRN0(_L("\n CMMFDevSoundSession[0x%x]======== Flag can service new request\n"));
  1.2212 +		iAsyncQueueStart->CallBack();
  1.2213 +		}
  1.2214 +	SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DequeueRequest - Exit"));
  1.2215 +	}
  1.2216 +	
  1.2217 +// 	AsyncQueueStartCallback
  1.2218 +
  1.2219 +
  1.2220 +TInt CMMFDevSoundSession::AsyncQueueStartCallback(TAny* aPtr)
  1.2221 +	{
  1.2222 +	CMMFDevSoundSession* self = static_cast<CMMFDevSoundSession*>(aPtr);
  1.2223 +	self->AsyncQueueStartCallback();
  1.2224 +	return KErrNone;
  1.2225 +	}
  1.2226 +	
  1.2227 +void CMMFDevSoundSession::AsyncQueueStartCallback()
  1.2228 +	{
  1.2229 +	SYMBIAN_DEBPRN0(_L("\n CMMFDevSoundSession[0x%x]======== Service a queued request\n"));
  1.2230 +	TMMFDevSoundRequest msg = iQueuedRequests[0];
  1.2231 +	iQueuedRequests.Remove(0);
  1.2232 +	TInt err = KErrNone;
  1.2233 +	TBool doRequest = ETrue;
  1.2234 +	if(iPreemptionClash)
  1.2235 +		{
  1.2236 +		SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::AsyncQueueStartCallback - Re-applying client request due to Pre-emption clash"));
  1.2237 +		iPreemptionClash=EFalse; // clear flag before reading next request in queue
  1.2238 +		iAdapter->RollbackAdaptorActiveStateToBeforeCommit();
  1.2239 +		if ((iRequestBeingServiced.Type() == TMMFDevSoundRequest::EAction_PseudoAsynchronous))
  1.2240 +			{
  1.2241 +		    doRequest = EFalse;
  1.2242 +		    HandleAlreadyCompletedRequest();
  1.2243 +			}
  1.2244 +		}
  1.2245 +
  1.2246 +	if (doRequest)
  1.2247 +		{
  1.2248 +		TRAP(err,DoServiceRequestL(msg.Message()));
  1.2249 +		if(err != KErrNone)
  1.2250 +			{
  1.2251 +			msg.Complete(err);
  1.2252 +			}
  1.2253 +		}
  1.2254 +
  1.2255 +	if (!iOperationCompletePending && iQueuedRequests.Count() != 0)
  1.2256 +		{
  1.2257 +		//dequeue next
  1.2258 +		DequeueRequest();
  1.2259 +		}
  1.2260 +	}
  1.2261 +
  1.2262 +// CMMFDevSoundSession::CustomInterface()
  1.2263 +// Returns a pointer reference to custom interface implementation returned by
  1.2264 +// adaptation::CustomInterface method.
  1.2265 +// Note this method is called indirectly by CI server-side plugins - both DeMux and 
  1.2266 +// CIServerExtension call this variously via MMMFDevSoundCustomInterfaceTarget or MCustomInterface 
  1.2267 +//
  1.2268 +TAny* CMMFDevSoundSession::CustomInterface(TUid aInterfaceId)
  1.2269 +	{
  1.2270 +	TInt err = DoSetClientConfig(); // if required, this will connect to MMRC etc
  1.2271 +	if (err)
  1.2272 +		{
  1.2273 +		return NULL; // on any error, return NULL - not much more we can do
  1.2274 +		}
  1.2275 +	return iAdapter->CustomInterface(aInterfaceId);
  1.2276 +	}
  1.2277 +
  1.2278 +//
  1.2279 +// CMMFDevSoundSession::DoProcessingFinished()
  1.2280 +//
  1.2281 +void CMMFDevSoundSession::DoProcessingFinished()
  1.2282 +	{
  1.2283 +    ResetNotifiedError();
  1.2284 +
  1.2285 +	TBool asyncOperation = EFalse;
  1.2286 +	//ProcessingFinished should never fail
  1.2287 +	__ASSERT_ALWAYS(KErrNone, iAdapter->ProcessingFinishedReceived(asyncOperation));
  1.2288 +	iOperationCompletePending = asyncOperation;
  1.2289 +	if (iOperationCompletePending)
  1.2290 +		{
  1.2291 +		iRequestBeingServiced.SetMessageCallback();
  1.2292 +		}
  1.2293 +	}
  1.2294 +
  1.2295 +//
  1.2296 +// CMMFDevSoundSession::DoProcessingError()
  1.2297 +//
  1.2298 +void CMMFDevSoundSession::DoProcessingError()
  1.2299 +    {
  1.2300 +    ResetNotifiedError();
  1.2301 +
  1.2302 +    TBool asyncOperation = EFalse;
  1.2303 +    //ProcessingFinished should never fail
  1.2304 +    __ASSERT_ALWAYS(KErrNone, iAdapter->ProcessingError(asyncOperation));
  1.2305 +    iOperationCompletePending = asyncOperation;
  1.2306 +    if (iOperationCompletePending)
  1.2307 +        {
  1.2308 +        iRequestBeingServiced.SetMessageCallback();
  1.2309 +        }
  1.2310 +    }
  1.2311 +
  1.2312 +//
  1.2313 +// CMMFDevSoundSession::DoSetClientConfigL()
  1.2314 +// Sets client configuration information to Adaptation.
  1.2315 +//
  1.2316 +TInt CMMFDevSoundSession::DoSetClientConfig()
  1.2317 +	{
  1.2318 +	TInt err = KErrNone;
  1.2319 +	if(!iSetClientConfigApplied)
  1.2320 +		{
  1.2321 +		CMMFDevSoundServer* server =
  1.2322 +			const_cast<CMMFDevSoundServer*>(
  1.2323 +				static_cast<const CMMFDevSoundServer*>(Server()));
  1.2324 +			
  1.2325 +		ASSERT(server); // session should always have a server!
  1.2326 +		
  1.2327 +		TProcessId actualProcessId = server->ActualProcessId();
  1.2328 +		TProcessId processId = server->ProcessId();
  1.2329 +		
  1.2330 +		if (actualProcessId!=processId)
  1.2331 +		    {
  1.2332 +            // we have a differing actual process id, so pass that to the adaptor too
  1.2333 +            err = iAdapter->SetClientConfig(actualProcessId, processId);
  1.2334 +		    }
  1.2335 +		else
  1.2336 +		    {
  1.2337 +            err = iAdapter->SetClientConfig(processId);
  1.2338 +		    }
  1.2339 +
  1.2340 +		if (!err)
  1.2341 +			{
  1.2342 +			iSetClientConfigApplied = ETrue;
  1.2343 +			}
  1.2344 +		}
  1.2345 +	return err;
  1.2346 +	}
  1.2347 +
  1.2348 +// CMMFDevSoundSession::DoSetClientConfigL()
  1.2349 +// Sets client configuration information to Adaptation.
  1.2350 +//
  1.2351 +void CMMFDevSoundSession::DoSetClientConfigL()
  1.2352 +	{
  1.2353 +	User::LeaveIfError(DoSetClientConfig());
  1.2354 +	}
  1.2355 +
  1.2356 +// 
  1.2357 +// CMMFDevSoundSession::CreateChunk()
  1.2358 +// Requests kernel to create global RChunk
  1.2359 +// 
  1.2360 +TInt CMMFDevSoundSession::CreateChunk(TMMFDevSoundProxyHwBufPckg& aBufPckg, TInt aRequestedSize)
  1.2361 +	{
  1.2362 +	TInt status(KErrNone);
  1.2363 +	
  1.2364 +	if ( iChunk.Handle() )
  1.2365 +		{
  1.2366 +		// If the DevSound Adaptation component requests a buffer size
  1.2367 +		// that can fit into current chunk's size, then re-use chunk.
  1.2368 +		if ( aRequestedSize <= iChunk.Size() )
  1.2369 +			{
  1.2370 +			if (iForceSendOfChunkHandle)
  1.2371 +				{
  1.2372 +				iForceSendOfChunkHandle = EFalse;
  1.2373 +				aBufPckg().iChunkOp = EOpen;
  1.2374 +				}
  1.2375 +			else
  1.2376 +				{
  1.2377 +				aBufPckg().iChunkOp = ENull;
  1.2378 +				}
  1.2379 +			return status;
  1.2380 +			}
  1.2381 +		// The new request size exceeds the current chunk's area, close it. We
  1.2382 +		// will be creating new one in the following sequences. Note we could
  1.2383 +		// try to Adjust() the chunk, and see if the existing chunk could be
  1.2384 +		// extended instead, but this is assumed too rare an event for this 
  1.2385 +		// optimisation
  1.2386 +		else
  1.2387 +			{
  1.2388 +			iChunk.Close();
  1.2389 +			}
  1.2390 +		}
  1.2391 +	
  1.2392 +	// Request kernel to create global RChunk if needed
  1.2393 +	if ( !iChunk.Handle() )
  1.2394 +		{
  1.2395 +		status = iChunk.CreateGlobal(KNullDesC, aRequestedSize, aRequestedSize, EOwnerThread);
  1.2396 +		if ( status == KErrNone )
  1.2397 +			{
  1.2398 +			aBufPckg().iChunkOp = EOpen;
  1.2399 +			}
  1.2400 +		else
  1.2401 +			{
  1.2402 +			aBufPckg().iChunkOp = ENull;
  1.2403 +			}
  1.2404 +		}
  1.2405 +	iForceSendOfChunkHandle = EFalse;
  1.2406 +	return status;
  1.2407 +	}
  1.2408 +
  1.2409 +
  1.2410 +// Custom Interface //
  1.2411 +TInt CMMFDevSoundSession::DoOpenSlaveL(TUid aInterface, const TDesC8& aPackageBuf)
  1.2412 +	{
  1.2413 +	// it shouldn't be necessary to check if we have already instantiated this
  1.2414 +	// interface since the client would already know - however this is something
  1.2415 +	// that a licensee could implement if they required additional functionality
  1.2416 +	// e.g. many : 1 mappings between client and DevSound.
  1.2417 +
  1.2418 +	MMMFDevSoundCustomInterfaceDeMuxPlugin* ptr = NULL;
  1.2419 +		
  1.2420 +	// try and instantiate a plugin tunnelling
  1.2421 +	// pair to support this Custom Interface
  1.2422 +	ptr = iDeMuxUtility->CreateCustomInterfaceDeMuxL(aInterface);
  1.2423 +	
  1.2424 +	TInt handle = KNullHandle;
  1.2425 +	
  1.2426 +	if (ptr)
  1.2427 +		{
  1.2428 +		TMMFDevSoundCustomInterfaceDeMuxData data;
  1.2429 +		data.iInterface = ptr;
  1.2430 +		data.iId = aInterface;
  1.2431 +			
  1.2432 +		CleanupReleasePushL(*ptr);
  1.2433 +			
  1.2434 +		// setup demux plugin
  1.2435 +		ptr->SetInterfaceTarget(this);
  1.2436 +			
  1.2437 +		// try and open interface
  1.2438 +		// this will fetch the interface from the svr implementation
  1.2439 +		ptr->DoOpenSlaveL(aInterface, aPackageBuf);
  1.2440 +		User::LeaveIfError(iCustomInterfaceArray.Append(data));
  1.2441 +			
  1.2442 +		CleanupStack::Pop();	// ptr
  1.2443 +			
  1.2444 +		handle = iCustomInterfaceArray.Count();
  1.2445 +		return handle;
  1.2446 +		}
  1.2447 +
  1.2448 +	// we couldn't set up the interface correctly so return a NULL
  1.2449 +	// handle to the client
  1.2450 +	return KNullHandle;
  1.2451 +	}
  1.2452 +	
  1.2453 +void CMMFDevSoundSession::DoCloseSlaveL(TInt aHandle)
  1.2454 +	{
  1.2455 +	if (aHandle==KNullHandle)
  1.2456 +		{
  1.2457 +		// null-handle -> NOP
  1.2458 +		return;
  1.2459 +		}
  1.2460 +		
  1.2461 +	if (aHandle<KNullHandle || aHandle > iCustomInterfaceArray.Count())
  1.2462 +		{
  1.2463 +		// handle out of range - should not happen, but leave to show error
  1.2464 +		User::Leave(KErrBadHandle);
  1.2465 +		}
  1.2466 +		
  1.2467 +	TMMFDevSoundCustomInterfaceDeMuxData& data = iCustomInterfaceArray[aHandle-1];
  1.2468 +	
  1.2469 +	// close and delete the plugin
  1.2470 +	MMMFDevSoundCustomInterfaceDeMuxPlugin* ptr = data.iInterface;
  1.2471 +	ptr->DoCloseSlaveL(aHandle);
  1.2472 +	ptr->Release();
  1.2473 +	
  1.2474 +	// clear the entry
  1.2475 +	data.iInterface = NULL;
  1.2476 +	data.iId.iUid = 0;
  1.2477 +	}
  1.2478 +	
  1.2479 +TInt CMMFDevSoundSession::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
  1.2480 +	{
  1.2481 +	// use the demux utility to get the handle
  1.2482 +	TMMFDevSoundCIMessageData data;
  1.2483 +	iDeMuxUtility->GetSyncMessageDataL(aMessage, data);
  1.2484 +	
  1.2485 +	TInt handle = data.iHandle;
  1.2486 +	
  1.2487 +	if ((handle <= 0) || (handle > (iCustomInterfaceArray.Count())))
  1.2488 +		{
  1.2489 +		
  1.2490 +		User::Leave(KErrBadHandle);
  1.2491 +		}
  1.2492 +	
  1.2493 +	// call on demux plugin
  1.2494 +	return iCustomInterfaceArray[handle-1].iInterface->DoSendSlaveSyncCommandL(aMessage);	
  1.2495 +	}
  1.2496 +	
  1.2497 +TInt CMMFDevSoundSession::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)
  1.2498 +	{
  1.2499 +	// use the demux utility to get the handle
  1.2500 +	TMMFDevSoundCIMessageData data;
  1.2501 +	iDeMuxUtility->GetSyncMessageDataL(aMessage, data);
  1.2502 +	
  1.2503 +	TInt handle = data.iHandle;
  1.2504 +	
  1.2505 +	if ((handle <= 0) || (handle > (iCustomInterfaceArray.Count())))
  1.2506 +		{
  1.2507 +		
  1.2508 +		User::Leave(KErrBadHandle);
  1.2509 +		}
  1.2510 +	
  1.2511 +	// call on demux plugin
  1.2512 +	return iCustomInterfaceArray[handle-1].iInterface->DoSendSlaveSyncCommandResultL(aMessage);	
  1.2513 +	}
  1.2514 +	
  1.2515 +void CMMFDevSoundSession::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& aMessage)
  1.2516 +	{
  1.2517 +	// use the demux utility to get the handle
  1.2518 +	TMMFDevSoundCIMessageData data;
  1.2519 +	iDeMuxUtility->GetAsyncMessageDataL(aMessage, data);
  1.2520 +	
  1.2521 +	TInt handle = data.iHandle;
  1.2522 +	
  1.2523 +	if ((handle <= 0) || (handle > (iCustomInterfaceArray.Count())))
  1.2524 +		{
  1.2525 +		User::Leave(KErrBadHandle);
  1.2526 +		}
  1.2527 +	
  1.2528 +	// call on demux plugin
  1.2529 +	iCustomInterfaceArray[handle-1].iInterface->DoSendSlaveAsyncCommandL(aMessage);	
  1.2530 +	}
  1.2531 +	
  1.2532 +void CMMFDevSoundSession::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& aMessage)
  1.2533 +	{
  1.2534 +	// use the demux utility to get the handle
  1.2535 +	TMMFDevSoundCIMessageData data;
  1.2536 +	iDeMuxUtility->GetAsyncMessageDataL(aMessage, data);
  1.2537 +	
  1.2538 +	TInt handle = data.iHandle;
  1.2539 +	
  1.2540 +	if ((handle <= 0) || (handle > (iCustomInterfaceArray.Count())))
  1.2541 +		{
  1.2542 +		User::Leave(KErrBadHandle);
  1.2543 +		}
  1.2544 +	
  1.2545 +	// call on demux plugin
  1.2546 +	iCustomInterfaceArray[handle-1].iInterface->DoSendSlaveAsyncCommandResultL(aMessage);	
  1.2547 +	}
  1.2548 +
  1.2549 +
  1.2550 +TBool CMMFDevSoundSession::DoRegisterAsClientL(const RMmfIpcMessage& aMessage)
  1.2551 +	{
  1.2552 +	TMMFDevSoundProxySettingsPckg buf;
  1.2553 +	User::LeaveIfError(MessageRead(aMessage,0,buf));
  1.2554 +	HBufC8* notificationRegistrationData = NULL;
  1.2555 +	notificationRegistrationData = HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLengthL(1)));
  1.2556 +	TPtr8 dataPtr(notificationRegistrationData->Des());  	
  1.2557 +	User::LeaveIfError(MessageRead(aMessage,1,dataPtr));
  1.2558 +	DoSetClientConfigL();// added here instead of the CreateL()
  1.2559 +	TInt err = KErrNone;
  1.2560 +	err = iAdapter->RegisterAsClient(buf().iNotificationEventUid,dataPtr);
  1.2561 +	CleanupStack::PopAndDestroy(1); // Notification Registeration data
  1.2562 +	if (err != KErrNone)
  1.2563 +		{
  1.2564 +		aMessage.Complete(err);
  1.2565 +		return EFalse;		
  1.2566 +		}
  1.2567 +	return ETrue;
  1.2568 +	}
  1.2569 +	
  1.2570 +TBool CMMFDevSoundSession::DoCancelRegisterAsClientL(const RMmfIpcMessage& aMessage)
  1.2571 +	{
  1.2572 +	TMMFDevSoundProxySettingsPckg buf;
  1.2573 +	User::LeaveIfError(MessageRead(aMessage,0,buf));
  1.2574 +	TInt err = KErrNone;
  1.2575 +	err = iAdapter->CancelRegisterAsClient(buf().iNotificationEventUid);
  1.2576 +	if (err != KErrNone)
  1.2577 +		{
  1.2578 +		aMessage.Complete(err);
  1.2579 +		return EFalse;		
  1.2580 +		}
  1.2581 +	return ETrue;
  1.2582 +	}
  1.2583 +
  1.2584 +TBool CMMFDevSoundSession::DoGetResourceNotificationDataL(const RMmfIpcMessage& aMessage)
  1.2585 +	{
  1.2586 +	TMMFDevSoundProxySettingsPckg buf;
  1.2587 +	User::LeaveIfError(MessageRead(aMessage,0,buf));
  1.2588 +	HBufC8* notificationData = NULL;
  1.2589 +	notificationData = HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesMaxLengthL(2)));
  1.2590 +	TPtr8 dataPtr(notificationData->Des());  	
  1.2591 +	User::LeaveIfError(MessageRead(aMessage,2,dataPtr));
  1.2592 +	TInt err = KErrNone;
  1.2593 +	err = iAdapter->GetResourceNotificationData(buf().iNotificationEventUid,dataPtr);
  1.2594 +	User::LeaveIfError(MessageWrite(aMessage,2,*notificationData));
  1.2595 +	CleanupStack::PopAndDestroy(1); // Notification data
  1.2596 +	if (err != KErrNone)
  1.2597 +		{
  1.2598 +		aMessage.Complete(err);
  1.2599 +		return EFalse;		
  1.2600 +		}
  1.2601 +	return ETrue;
  1.2602 +	}
  1.2603 +
  1.2604 +TBool CMMFDevSoundSession::DoWillResumePlayL(const RMmfIpcMessage& aMessage)
  1.2605 +	{
  1.2606 +	TInt err = KErrNone;
  1.2607 +	err = iAdapter->WillResumePlay();
  1.2608 +	if (err != KErrNone)
  1.2609 +		{
  1.2610 +		aMessage.Complete(err);
  1.2611 +		return EFalse;		
  1.2612 +		}
  1.2613 +	return ETrue;
  1.2614 +	}
  1.2615 +
  1.2616 +TBool CMMFDevSoundSession::DoSetClientThreadInfoL(const RMmfIpcMessage& aMessage)
  1.2617 +	{
  1.2618 +	if(!iSetClientConfigApplied)
  1.2619 +		{
  1.2620 +		if (aMessage.HasCapability(ECapabilityMultimediaDD) && aMessage.HasCapability(ECapabilityUserEnvironment))
  1.2621 +			{
  1.2622 +			TPckgBuf<TThreadId> threadId;
  1.2623 +			User::LeaveIfError(MessageRead(aMessage, 1, threadId));
  1.2624 +			
  1.2625 +			CMMFDevSoundServer* server = 
  1.2626 +				const_cast<CMMFDevSoundServer*>(static_cast<const CMMFDevSoundServer*>(Server()));
  1.2627 +			server->SetClientProcessIdL(threadId()); 
  1.2628 +			}
  1.2629 +		else
  1.2630 +			{
  1.2631 +			User::Leave(KErrPermissionDenied);
  1.2632 +			}
  1.2633 +		}
  1.2634 +	else
  1.2635 +		{
  1.2636 +		User::Leave(KErrNotReady);
  1.2637 +		}
  1.2638 +	return ETrue;
  1.2639 +	}
  1.2640 +	
  1.2641 +void CMMFDevSoundSession::Panic(TMMFDevSoundSessionPanicCodes aCode)
  1.2642 +	{
  1.2643 +    User::Panic(KMMFDevSoundSessionPanicCategory, aCode);
  1.2644 +	}
  1.2645 +
  1.2646 +void CMMFDevSoundSession::BufferErrorEvent()
  1.2647 +	{
  1.2648 +	// this will generate an processing error event and callback
  1.2649 +	iAdapter->BufferErrorEvent();
  1.2650 +	}
  1.2651 +
  1.2652 +void CMMFDevSoundSession::FlushQueuedRequests()
  1.2653 +    {
  1.2654 +    for (TInt queueIndex = (iQueuedRequests.Count() - 1); queueIndex >= 0; --queueIndex)
  1.2655 +        {
  1.2656 +        if ((iQueuedRequests[queueIndex].Type() == TMMFDevSoundRequest::ESessionEvents) && 
  1.2657 +                (iQueuedRequests[queueIndex].Function() == RMessage2::EDisConnect))
  1.2658 +            {
  1.2659 +            continue;
  1.2660 +            }
  1.2661 +        iQueuedRequests.Remove(queueIndex);
  1.2662 +        }    
  1.2663 +    }
  1.2664 +
  1.2665 +TInt CMMFDevSoundSession::MessageRead(const RMmfIpcMessage& aMessage, TInt aParam, TDes8& aResult)
  1.2666 +    {
  1.2667 +    if (!iDisconnecting)
  1.2668 +        {
  1.2669 +        return MmfMessageUtil::Read(aMessage, aParam, aResult);    
  1.2670 +        }
  1.2671 +    return KErrBadHandle;
  1.2672 +    }
  1.2673 +
  1.2674 +TInt CMMFDevSoundSession::MessageRead(const RMmfIpcMessage& aMessage, TInt aParam, TDes16& aResult)
  1.2675 +    {
  1.2676 +    if (!iDisconnecting)
  1.2677 +        {
  1.2678 +        return aMessage.Read(aParam, aResult);    
  1.2679 +        }
  1.2680 +    return KErrBadHandle;
  1.2681 +    }
  1.2682 +
  1.2683 +TInt CMMFDevSoundSession::MessageWrite(const RMmfIpcMessage& aMessage, TInt aParam, const TDesC8& aValue)
  1.2684 +    {
  1.2685 +    if (!iDisconnecting)
  1.2686 +        {
  1.2687 +        return MmfMessageUtil::Write(aMessage, aParam, aValue);
  1.2688 +        }
  1.2689 +    return KErrBadHandle;
  1.2690 +    }
  1.2691 +
  1.2692 +void CMMFDevSoundSession::ResetNotifiedError()
  1.2693 +// called at beginning of commit cycle, so any error will be from callbacks
  1.2694 +    {
  1.2695 +    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::ResetNotifiedError"));
  1.2696 +    iNotifiedError = KErrNone;
  1.2697 +    }
  1.2698 +
  1.2699 +TInt CMMFDevSoundSession::NotifiedError() const
  1.2700 +// NotifiedError property
  1.2701 +    {
  1.2702 +    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::NotifiedError(%d)"), iNotifiedError);
  1.2703 +    return iNotifiedError;
  1.2704 +    }
  1.2705 +
  1.2706 +void CMMFDevSoundSession::NotifyError(TInt aError)
  1.2707 +// cache notified error
  1.2708 +    {
  1.2709 +    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::NotifyError(%d)"), aError);
  1.2710 +    iNotifiedError = aError;
  1.2711 +    }
  1.2712 +
  1.2713 +// End of file