os/mm/devsound/a3fdevsound/src/mmfdevsoundserver/mmfdevsoundsession.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <s32mem.h>
sl@0
    17
#include "mmfaudioclientserver.h"
sl@0
    18
#include "mmfaudioserver.h"
sl@0
    19
#include "mmfdevsoundserver.h"
sl@0
    20
#include "mmfdevsoundsession.h"
sl@0
    21
#include <mmf/plugin/mmfdevsoundcustominterface.hrh>
sl@0
    22
#include <mm/mmpluginutils.h>
sl@0
    23
#ifdef _DEBUG
sl@0
    24
#include "e32debug.h"
sl@0
    25
sl@0
    26
#define SYMBIAN_DEBPRN0(str)                RDebug::Print(str, this)
sl@0
    27
#define SYMBIAN_DEBPRN1(str, val1)          RDebug::Print(str, this, val1)
sl@0
    28
#define SYMBIAN_DEBPRN2(str, val1, val2)    RDebug::Print(str, this, val1, val2)
sl@0
    29
#define SYMBIAN_DEBPRN3(str, val1, val2, val3)    RDebug::Print(str, this, val1, val2, val3)
sl@0
    30
#else
sl@0
    31
#define SYMBIAN_DEBPRN0(str)
sl@0
    32
#define SYMBIAN_DEBPRN1(str, val1)
sl@0
    33
#define SYMBIAN_DEBPRN2(str, val1, val2)
sl@0
    34
#define SYMBIAN_DEBPRN3(str, val1, val2, val3)
sl@0
    35
#endif //_DEBUG
sl@0
    36
sl@0
    37
const TInt KMaxQueueRequest = 6;
sl@0
    38
sl@0
    39
//	MEMBER FUNCTIONS 
sl@0
    40
sl@0
    41
TMMFDevSoundRequest::TMMFDevSoundRequest() 
sl@0
    42
	: iMessageCompleted(EFalse), 
sl@0
    43
	iRequestType(EUndefinedType),
sl@0
    44
	iCallBackPF(KCallbackNone)
sl@0
    45
	{
sl@0
    46
	}
sl@0
    47
sl@0
    48
TMMFDevSoundRequest::TMMFDevSoundRequest(TInt aIsCallBack)
sl@0
    49
	: iMessageCompleted(EFalse), 
sl@0
    50
	iRequestType(ECallBackType),
sl@0
    51
	iCallBackPF(aIsCallBack)
sl@0
    52
	{
sl@0
    53
	}
sl@0
    54
sl@0
    55
TMMFDevSoundRequest::TMMFDevSoundRequest(const TMMFDevSoundRequest& aRequest)
sl@0
    56
	: iMessageCompleted(EFalse), 
sl@0
    57
	iMessage(aRequest.iMessage),
sl@0
    58
	iCallBackPF(aRequest.iCallBackPF)
sl@0
    59
	{
sl@0
    60
	iRequestType = ResolveType();
sl@0
    61
	}
sl@0
    62
sl@0
    63
TBool TMMFDevSoundRequest::operator==(const TMMFDevSoundRequest& aRequest) const
sl@0
    64
	{
sl@0
    65
	TBool retval = EFalse;
sl@0
    66
	if ( aRequest.Function() == Function() )
sl@0
    67
		{
sl@0
    68
		retval = ETrue;
sl@0
    69
		}
sl@0
    70
	else
sl@0
    71
		{
sl@0
    72
		retval = EFalse;
sl@0
    73
		}
sl@0
    74
	return retval;
sl@0
    75
	}
sl@0
    76
sl@0
    77
const RMmfIpcMessage& TMMFDevSoundRequest::Message() 
sl@0
    78
	{ 
sl@0
    79
	return iMessage; 
sl@0
    80
	}
sl@0
    81
sl@0
    82
void TMMFDevSoundRequest::SetMessage(const RMmfIpcMessage& aMessage) 
sl@0
    83
	{
sl@0
    84
	iMessageCompleted = EFalse;
sl@0
    85
	iMessage = aMessage;
sl@0
    86
	iRequestType = ResolveType();
sl@0
    87
	}
sl@0
    88
	
sl@0
    89
void TMMFDevSoundRequest::SetMessageCallback() 
sl@0
    90
	{
sl@0
    91
	iMessageCompleted = EFalse;
sl@0
    92
	iRequestType = ECallBackType;
sl@0
    93
	}	
sl@0
    94
sl@0
    95
TInt TMMFDevSoundRequest::IsCallBack() const
sl@0
    96
	{
sl@0
    97
	return iCallBackPF;	
sl@0
    98
	}
sl@0
    99
sl@0
   100
TMMFDevSoundRequest::TA3FDevSoundRequestType TMMFDevSoundRequest::ResolveType()
sl@0
   101
	{
sl@0
   102
	TA3FDevSoundRequestType type = EUndefinedType;
sl@0
   103
	switch(iMessage.Function())
sl@0
   104
		{
sl@0
   105
		case EMMFDevSoundProxyInitialize1:
sl@0
   106
		case EMMFDevSoundProxyInitialize2:
sl@0
   107
		case EMMFDevSoundProxyInitialize4:
sl@0
   108
		case EMMFDevSoundProxyPlayInit:
sl@0
   109
		case EMMFDevSoundProxyRecordInit:
sl@0
   110
		case EMMFDevSoundProxyPlayTone:
sl@0
   111
		case EMMFDevSoundProxyPlayDualTone:
sl@0
   112
		case EMMFDevSoundProxyPlayDTMFString:
sl@0
   113
		case EMMFDevSoundProxyPlayToneSequence:
sl@0
   114
		case EMMFDevSoundProxyPlayFixedSequence:
sl@0
   115
			type = EAction_PseudoAsynchronous;
sl@0
   116
			break;
sl@0
   117
sl@0
   118
		case EMMFDevSoundProxyStop:
sl@0
   119
		case EMMFDevSoundProxyPause:
sl@0
   120
		case EMMFDevSoundProxyClose:
sl@0
   121
		case EMMFDevSoundProxyCancelInitialize:
sl@0
   122
		case EMMFDevSoundProxyResume:
sl@0
   123
		case EMMFDevSoundProxyEmptyBuffers:
sl@0
   124
			type = EAction_Asynchronous;
sl@0
   125
			break;
sl@0
   126
sl@0
   127
		case EMMFDevSoundProxySetConfig:
sl@0
   128
		case EMMFDevSoundProxyPostOpen: // Although this is not a configure operation technically, it has same calling pattern.
sl@0
   129
		case EMMFDevSoundProxySetVolume:
sl@0
   130
		case EMMFDevSoundProxySetGain:
sl@0
   131
		case EMMFDevSoundProxySetPlayBalance:
sl@0
   132
		case EMMFDevSoundProxySetRecordBalance:
sl@0
   133
		case EMMFDevSoundProxySetVolumeRamp:
sl@0
   134
		case EMMFDevSoundProxySetPrioritySettings:
sl@0
   135
			type = EConfigure_Asynchronous;
sl@0
   136
			break;
sl@0
   137
			
sl@0
   138
		case EMMFDevSoundProxySetDTMFLengths:
sl@0
   139
		case EMMFDevSoundProxySetToneRepeats:
sl@0
   140
			type = EConfigure_Synchronous;	
sl@0
   141
			break;
sl@0
   142
		case EMMFDevSoundProxyCapabilities:
sl@0
   143
			type = EQuery_Asynchronous;
sl@0
   144
			break;
sl@0
   145
		case EMMFDevSoundProxyMaxVolume:
sl@0
   146
		case EMMFDevSoundProxyMaxGain:
sl@0
   147
		case EMMFDevSoundProxyConfig:
sl@0
   148
		case EMMFDevSoundProxyVolume:
sl@0
   149
		case EMMFDevSoundProxyGain:
sl@0
   150
		case EMMFDevSoundProxyPlayBalance:
sl@0
   151
		case EMMFDevSoundProxyRecordBalance:
sl@0
   152
		case EMMFDevSoundProxyGetSupportedInputDataTypes:
sl@0
   153
		case EMMFDevSoundProxyGetSupportedOutputDataTypes:
sl@0
   154
		case EMMFDevSoundProxyFixedSequenceName:
sl@0
   155
		case EMMFDevSoundProxyFixedSequenceCount:
sl@0
   156
		case EMMFDevSoundProxySamplesRecorded:
sl@0
   157
		case EMMFDevSoundProxySamplesPlayed:
sl@0
   158
		case EMMFDevSoundProxyCopyFourCCArrayData:
sl@0
   159
		case EMMFDevSoundProxyGetTimePlayed:
sl@0
   160
		case EMMFDevSoundProxyIsResumeSupported:
sl@0
   161
			type = EQuery_Synchronous;
sl@0
   162
			break;
sl@0
   163
		
sl@0
   164
		case EMMFDevSoundProxyBTBFData:
sl@0
   165
		case EMMFDevSoundProxyBTBEData:
sl@0
   166
		case EMMFDevSoundProxyPlayData:
sl@0
   167
		case EMMFDevSoundProxyRecordData:
sl@0
   168
			type = EBufferExchangeRelated;
sl@0
   169
			break;
sl@0
   170
sl@0
   171
		// Custom Interfaces
sl@0
   172
		case EMMFDevSoundProxySyncCustomCommand:
sl@0
   173
		case EMMFDevSoundProxySyncCustomCommandResult:
sl@0
   174
		case EMMFDevSoundProxyAsyncCustomCommand:
sl@0
   175
		case EMMFDevSoundProxyAsyncCustomCommandResult:
sl@0
   176
		case EMMFDevSoundProxyCustomInterface:
sl@0
   177
			type = ECustomInterfacesRelated;
sl@0
   178
			break;
sl@0
   179
		case RMessage2::EDisConnect:
sl@0
   180
			type = ESessionEvents;
sl@0
   181
			break;
sl@0
   182
		default:
sl@0
   183
			break;
sl@0
   184
		}
sl@0
   185
	return type;
sl@0
   186
	}
sl@0
   187
sl@0
   188
sl@0
   189
void TMMFDevSoundRequest::Complete(TInt aError)	
sl@0
   190
	{
sl@0
   191
	if(!iMessageCompleted && iRequestType != EUndefinedType && iRequestType != ECallBackType)	
sl@0
   192
		{
sl@0
   193
		iMessage.Complete(aError);
sl@0
   194
		iMessageCompleted = ETrue;
sl@0
   195
		iRequestType = EUndefinedType;
sl@0
   196
		}
sl@0
   197
	}
sl@0
   198
sl@0
   199
TInt TMMFDevSoundRequest::Function() const 
sl@0
   200
	{
sl@0
   201
	return iMessage.Function(); 
sl@0
   202
	}
sl@0
   203
sl@0
   204
TMMFDevSoundRequest::TA3FDevSoundRequestType TMMFDevSoundRequest::Type() const
sl@0
   205
	{
sl@0
   206
	return iRequestType;
sl@0
   207
	}
sl@0
   208
sl@0
   209
sl@0
   210
// 
sl@0
   211
// CMMFDevSoundSession::CreateL
sl@0
   212
// Creates a new object
sl@0
   213
// 
sl@0
   214
void CMMFDevSoundSession::CreateL(const CMmfIpcServer& aServer)
sl@0
   215
	{
sl@0
   216
	CMmfIpcSession::CreateL(aServer);
sl@0
   217
	CMMFDevSoundServer& server =
sl@0
   218
	const_cast<CMMFDevSoundServer&>(
sl@0
   219
			static_cast<const CMMFDevSoundServer&>(aServer));
sl@0
   220
	server.IncrementSessionId();
sl@0
   221
	iDevSoundSessionId = server.DevSoundSessionId();
sl@0
   222
	}
sl@0
   223
sl@0
   224
//
sl@0
   225
// NeedToQueue - mid-commit cycle or async queue start AO is active
sl@0
   226
//
sl@0
   227
TBool CMMFDevSoundSession::NeedToQueue() const
sl@0
   228
    {
sl@0
   229
    return iOperationCompletePending || iAsyncQueueStart->IsActive();
sl@0
   230
    }
sl@0
   231
sl@0
   232
//
sl@0
   233
// CMMFDevSoundSession::ServiceL
sl@0
   234
// (other items were commented in a header).
sl@0
   235
//
sl@0
   236
void CMMFDevSoundSession::ServiceL(const RMmfIpcMessage& aMessage)
sl@0
   237
	{
sl@0
   238
	SYMBIAN_DEBPRN2(_L("\nCMMFDevSoundSession[0x%x] NEW REQUEST %02x while pending=%d"),
sl@0
   239
	        aMessage.Function(), NeedToQueue());
sl@0
   240
	
sl@0
   241
	if(NeedToQueue())
sl@0
   242
		{
sl@0
   243
		// if not possible to service now, then queue request
sl@0
   244
		EnqueueRequest(aMessage);
sl@0
   245
		}
sl@0
   246
	else
sl@0
   247
		{
sl@0
   248
		// If there is no oustanding operation service inmediately
sl@0
   249
		TRAPD(err, DoServiceRequestL(aMessage));
sl@0
   250
		if (err)
sl@0
   251
		    {
sl@0
   252
            aMessage.Complete(err); // repeat normal ServiceL() behaviour since we may keep going
sl@0
   253
		    }
sl@0
   254
	    if (!iOperationCompletePending && iQueuedRequests.Count() != 0)
sl@0
   255
	        {
sl@0
   256
	        //dequeue next
sl@0
   257
	        DequeueRequest();
sl@0
   258
	        }
sl@0
   259
		}
sl@0
   260
	}
sl@0
   261
	
sl@0
   262
//
sl@0
   263
// CMMFDevSoundSession::DoServiceL
sl@0
   264
// (other items were commented in a header).
sl@0
   265
//
sl@0
   266
void CMMFDevSoundSession::DoServiceRequestL(const RMmfIpcMessage& aMessage)
sl@0
   267
	{
sl@0
   268
	iRequestBeingServiced.SetMessage(aMessage);
sl@0
   269
	iAsyncQueueStart->Cancel(); // just in case.
sl@0
   270
    ResetNotifiedError();
sl@0
   271
sl@0
   272
    if (aMessage.Function() == RMessage2::EDisConnect)
sl@0
   273
        {
sl@0
   274
        TBool complete = iAdapter->CloseDevSound();
sl@0
   275
        if(!complete)
sl@0
   276
            {
sl@0
   277
            iRequestBeingServiced.SetMessage(aMessage);
sl@0
   278
            iOperationCompletePending = ETrue;
sl@0
   279
            ResetNotifiedError();
sl@0
   280
            }
sl@0
   281
        else
sl@0
   282
            {
sl@0
   283
            // if we get here, iClosing wait will have been started and we'd be waiting
sl@0
   284
            iClosingWait->AsyncStop();
sl@0
   285
            }
sl@0
   286
        return;
sl@0
   287
        }
sl@0
   288
    
sl@0
   289
    TMMFMessageDestinationPckg destinationPckg;
sl@0
   290
	User::LeaveIfError(MessageRead(aMessage, 0, destinationPckg));
sl@0
   291
	SYMBIAN_DEBPRN2(_L("CMMFDevSoundSession[0x%x]::DoServiceRequestL - DestinationHandle [%d] InterfaceId [%d] "), destinationPckg().DestinationHandle(), destinationPckg().InterfaceId());
sl@0
   292
	if ((destinationPckg().DestinationHandle() == KMMFObjectHandleDevSound) &&
sl@0
   293
	    (destinationPckg().InterfaceId() == KUidInterfaceMMFDevSound))
sl@0
   294
		{
sl@0
   295
        SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoServiceRequestL - Request [%d]"), aMessage.Function());
sl@0
   296
		TBool complete = EFalse;
sl@0
   297
		switch(aMessage.Function())
sl@0
   298
			{
sl@0
   299
			case EMMFDevSoundProxyPostOpen:
sl@0
   300
				complete = DoPostOpenL(aMessage);
sl@0
   301
				break;
sl@0
   302
			case EMMFDevSoundProxyInitialize1:
sl@0
   303
				complete = DoInitialize1L(aMessage);
sl@0
   304
				break;
sl@0
   305
			case EMMFDevSoundProxyInitialize2:
sl@0
   306
				complete = DoInitialize2L(aMessage);
sl@0
   307
				break;
sl@0
   308
			case EMMFDevSoundProxyInitialize4:
sl@0
   309
				complete = DoInitialize4L(aMessage);
sl@0
   310
				break;
sl@0
   311
			case EMMFDevSoundProxyCapabilities:
sl@0
   312
				complete = DoCapabilitiesL(aMessage);
sl@0
   313
				break;
sl@0
   314
			case EMMFDevSoundProxyConfig:
sl@0
   315
				complete = DoConfigL(aMessage);
sl@0
   316
				break;
sl@0
   317
			case EMMFDevSoundProxySetConfig:
sl@0
   318
				complete = DoSetConfigL(aMessage);
sl@0
   319
				break;
sl@0
   320
			case EMMFDevSoundProxyMaxVolume:
sl@0
   321
				complete = DoMaxVolumeL(aMessage);
sl@0
   322
				break;
sl@0
   323
			case EMMFDevSoundProxyVolume:
sl@0
   324
				complete = DoVolumeL(aMessage);
sl@0
   325
				break;
sl@0
   326
			case EMMFDevSoundProxySetVolume:
sl@0
   327
				complete = DoSetVolumeL(aMessage);
sl@0
   328
				break;
sl@0
   329
			case EMMFDevSoundProxyMaxGain:
sl@0
   330
				complete = DoMaxGainL(aMessage);
sl@0
   331
				break;
sl@0
   332
			case EMMFDevSoundProxyGain:
sl@0
   333
				complete = DoGainL(aMessage);
sl@0
   334
				break;
sl@0
   335
			case EMMFDevSoundProxySetGain:
sl@0
   336
				complete = DoSetGainL(aMessage);
sl@0
   337
				break;
sl@0
   338
			case EMMFDevSoundProxyPlayBalance:
sl@0
   339
				complete = DoGetPlayBalanceL(aMessage);
sl@0
   340
				break;
sl@0
   341
			case EMMFDevSoundProxySetPlayBalance:
sl@0
   342
				complete = DoSetPlayBalanceL(aMessage);
sl@0
   343
				break;
sl@0
   344
			case EMMFDevSoundProxyRecordBalance:
sl@0
   345
				complete = DoGetRecordBalanceL(aMessage);
sl@0
   346
				break;
sl@0
   347
			case EMMFDevSoundProxySetRecordBalance:
sl@0
   348
				complete = DoSetRecordBalanceL(aMessage);
sl@0
   349
				break;
sl@0
   350
			case EMMFDevSoundProxyBTBFData:
sl@0
   351
				complete = DoBufferToBeFilledDataL(aMessage);
sl@0
   352
				break;
sl@0
   353
			case EMMFDevSoundProxyBTBEData:
sl@0
   354
				complete = DoBufferToBeEmptiedDataL(aMessage);
sl@0
   355
				break;
sl@0
   356
			case EMMFDevSoundProxyPlayInit:
sl@0
   357
				complete = DoPlayInitL(aMessage);
sl@0
   358
				break;
sl@0
   359
			case EMMFDevSoundProxyRecordInit:
sl@0
   360
				complete = DoRecordInitL(aMessage);
sl@0
   361
				break;
sl@0
   362
			case EMMFDevSoundProxyPlayData:
sl@0
   363
				complete = DoPlayDataL(aMessage);
sl@0
   364
				break;
sl@0
   365
			case EMMFDevSoundProxyRecordData:
sl@0
   366
				complete = DoRecordDataL(aMessage);
sl@0
   367
				break;
sl@0
   368
			case EMMFDevSoundProxyStop:
sl@0
   369
				complete = DoStopL(aMessage);
sl@0
   370
				break;
sl@0
   371
			case EMMFDevSoundProxyPause:
sl@0
   372
				complete = DoPauseL(aMessage);
sl@0
   373
				break;
sl@0
   374
			case EMMFDevSoundProxyPlayTone:
sl@0
   375
				complete = DoPlayToneL(aMessage);
sl@0
   376
				break;
sl@0
   377
			case EMMFDevSoundProxyPlayDualTone:
sl@0
   378
				complete = DoPlayDualToneL(aMessage);
sl@0
   379
				break;
sl@0
   380
			case EMMFDevSoundProxyPlayDTMFString:
sl@0
   381
				complete = DoPlayDTMFStringL(aMessage);
sl@0
   382
				break;
sl@0
   383
			case EMMFDevSoundProxyPlayToneSequence:
sl@0
   384
				complete = DoPlayToneSequenceL(aMessage);
sl@0
   385
				break;
sl@0
   386
			case EMMFDevSoundProxyPlayFixedSequence:
sl@0
   387
				complete = DoPlayFixedSequenceL(aMessage);
sl@0
   388
				break;
sl@0
   389
			case EMMFDevSoundProxySetDTMFLengths:
sl@0
   390
				complete = DoSetDTMFLengthsL(aMessage);
sl@0
   391
				break;
sl@0
   392
			case EMMFDevSoundProxySetVolumeRamp:
sl@0
   393
				complete = DoSetVolumeRampL(aMessage);
sl@0
   394
				break;
sl@0
   395
			case EMMFDevSoundProxyGetSupportedInputDataTypes:
sl@0
   396
				complete = DoGetSupportedInputDataTypesL(aMessage);
sl@0
   397
				break;
sl@0
   398
			case EMMFDevSoundProxyGetSupportedOutputDataTypes:
sl@0
   399
				complete = DoGetSupportedOutputDataTypesL(aMessage);
sl@0
   400
				break;
sl@0
   401
			case EMMFDevSoundProxyCopyFourCCArrayData:
sl@0
   402
				complete = DoCopyFourCCArrayDataL(aMessage);
sl@0
   403
				break;
sl@0
   404
			case EMMFDevSoundProxySamplesRecorded:
sl@0
   405
				complete = DoSamplesRecordedL(aMessage);
sl@0
   406
				break;
sl@0
   407
			case EMMFDevSoundProxySamplesPlayed:
sl@0
   408
				complete = DoSamplesPlayedL(aMessage);
sl@0
   409
				break;
sl@0
   410
			case EMMFDevSoundProxySetToneRepeats:
sl@0
   411
				complete = DoSetToneRepeatsL(aMessage);
sl@0
   412
				break;
sl@0
   413
			case EMMFDevSoundProxySetPrioritySettings:
sl@0
   414
				complete = DoSetPrioritySettingsL(aMessage);
sl@0
   415
				break;
sl@0
   416
			case EMMFDevSoundProxyFixedSequenceCount:
sl@0
   417
				complete = DoFixedSequenceCountL(aMessage);
sl@0
   418
				break;
sl@0
   419
			case EMMFDevSoundProxyCancelInitialize:
sl@0
   420
				complete = DoCancelInitializeL(aMessage);
sl@0
   421
				break;
sl@0
   422
			case EMMFDevSoundProxyEmptyBuffers:
sl@0
   423
				complete = DoEmptyBuffersL(aMessage);
sl@0
   424
				break;
sl@0
   425
			case EMMFDevSoundProxyGetTimePlayed:
sl@0
   426
				complete = DoGetTimePlayedL(aMessage);
sl@0
   427
				break;
sl@0
   428
			case EMMFDevSoundProxyIsResumeSupported:
sl@0
   429
				complete = DoQueryResumeSupportedL(aMessage);
sl@0
   430
				break;
sl@0
   431
			case EMMFDevSoundProxyResume:
sl@0
   432
				complete = DoResumeL(aMessage);
sl@0
   433
				break;
sl@0
   434
sl@0
   435
			// DevSound custom command support
sl@0
   436
			case EMMFDevSoundProxySyncCustomCommand:
sl@0
   437
			case EMMFDevSoundProxySyncCustomCommandResult:
sl@0
   438
			case EMMFDevSoundProxyAsyncCustomCommand:
sl@0
   439
			case EMMFDevSoundProxyAsyncCustomCommandResult:
sl@0
   440
				complete = DoCustomCommandL(aMessage);
sl@0
   441
				break;
sl@0
   442
			case EMMFDevSoundProxyClose:
sl@0
   443
				complete = DoPrepareCloseL(aMessage);
sl@0
   444
				break;
sl@0
   445
			case EMMFDevSoundProxyRequestResourceNotification:
sl@0
   446
				complete = DoRegisterAsClientL(aMessage);
sl@0
   447
				break;
sl@0
   448
			case EMMFDevSoundProxyCancelRequestResourceNotification:
sl@0
   449
				complete = DoCancelRegisterAsClientL(aMessage);
sl@0
   450
				break;
sl@0
   451
			case EMMFDevSoundProxyGetResourceNotificationData:
sl@0
   452
				complete = DoGetResourceNotificationDataL(aMessage);
sl@0
   453
				break;
sl@0
   454
			case EMMFDevSoundProxyWillResumePlay:
sl@0
   455
				complete = DoWillResumePlayL(aMessage);
sl@0
   456
				break;
sl@0
   457
			case EMMFDevSoundProxySetClientThreadInfo:
sl@0
   458
				complete = DoSetClientThreadInfoL(aMessage);
sl@0
   459
				break;						
sl@0
   460
			default:
sl@0
   461
				User::Leave(KErrNotSupported);
sl@0
   462
				break;
sl@0
   463
			}
sl@0
   464
sl@0
   465
		// Check if can complete the message now
sl@0
   466
		if (complete)
sl@0
   467
			{
sl@0
   468
			// Complete the message
sl@0
   469
			// Synchronous requests & Pseudo-asynchronous
sl@0
   470
			aMessage.Complete(KErrNone);
sl@0
   471
sl@0
   472
			// Store function if we need to re-apply it again due to pre-emption clash
sl@0
   473
			if(iRequestBeingServiced.Type() == TMMFDevSoundRequest::EAction_PseudoAsynchronous)
sl@0
   474
				{
sl@0
   475
				iRedoFunction = aMessage.Function();
sl@0
   476
				}
sl@0
   477
			}
sl@0
   478
		}
sl@0
   479
	else
sl@0
   480
		{
sl@0
   481
		// If there's a CI extension, see if that handles this request
sl@0
   482
		TInt err = KErrNotSupported;
sl@0
   483
		if (iCIExtension)
sl@0
   484
			{
sl@0
   485
            SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoServiceRequestL - CIExtensionRequest [%d]"), aMessage.Function());
sl@0
   486
            iOperationCompletePending = ETrue;
sl@0
   487
			iHandlingExtdCI = ETrue;
sl@0
   488
			TRAPD(err2, err = iCIExtension->HandleMessageL(aMessage));
sl@0
   489
			if (err2)
sl@0
   490
				{
sl@0
   491
				err = err2;
sl@0
   492
				}
sl@0
   493
			iOperationCompletePending = EFalse;
sl@0
   494
			iHandlingExtdCI = EFalse;
sl@0
   495
			SYMBIAN_DEBPRN2(_L("CMMFDevSoundSession[0x%x]::DoServiceRequestL - CIExtensionRequest[%d] - Exit with Error[%d] "), aMessage.Function(),err);
sl@0
   496
			}
sl@0
   497
sl@0
   498
		if (err != KErrNone)
sl@0
   499
			{
sl@0
   500
			// Not been handled, the request is not supported
sl@0
   501
			aMessage.Complete(KErrNotSupported);
sl@0
   502
			}
sl@0
   503
		}
sl@0
   504
	}
sl@0
   505
sl@0
   506
void CMMFDevSoundSession::DoServiceAlreadyCompletedRequestL(const TInt aFunction)
sl@0
   507
	{
sl@0
   508
    ResetNotifiedError();
sl@0
   509
sl@0
   510
	switch(aFunction)
sl@0
   511
		{
sl@0
   512
		case EMMFDevSoundProxyInitialize1:
sl@0
   513
			DoAlreadyCompletedInitialize1L();
sl@0
   514
			break;
sl@0
   515
		case EMMFDevSoundProxyInitialize2:
sl@0
   516
			DoAlreadyCompletedInitialize2L();
sl@0
   517
			break;
sl@0
   518
		case EMMFDevSoundProxyInitialize4:
sl@0
   519
			DoAlreadyCompletedInitialize4L();
sl@0
   520
			break;
sl@0
   521
		case EMMFDevSoundProxyPlayInit:
sl@0
   522
			DoAlreadyCompletedPlayInitL();
sl@0
   523
			break;
sl@0
   524
		case EMMFDevSoundProxyRecordInit:
sl@0
   525
			DoAlreadyCompletedRecordInitL();
sl@0
   526
			break;
sl@0
   527
		case EMMFDevSoundProxyPlayTone:
sl@0
   528
			DoAlreadyCompletedPlayToneL();
sl@0
   529
			break;
sl@0
   530
		case EMMFDevSoundProxyPlayDualTone:
sl@0
   531
			DoAlreadyCompletedPlayDualToneL();
sl@0
   532
			break;
sl@0
   533
		case EMMFDevSoundProxyPlayDTMFString:
sl@0
   534
			DoAlreadyCompletedPlayDTMFStringL();
sl@0
   535
			break;
sl@0
   536
		case EMMFDevSoundProxyPlayToneSequence:
sl@0
   537
			DoAlreadyCompletedPlayToneSequenceL();
sl@0
   538
			break;
sl@0
   539
		case EMMFDevSoundProxyPlayFixedSequence:
sl@0
   540
			DoAlreadyCompletedPlayFixedSequenceL();
sl@0
   541
			break;
sl@0
   542
		default:
sl@0
   543
			User::Leave(KErrNotSupported);
sl@0
   544
			break;
sl@0
   545
		}
sl@0
   546
sl@0
   547
	}
sl@0
   548
sl@0
   549
void CMMFDevSoundSession::HandleAlreadyCompletedRequest()
sl@0
   550
	{
sl@0
   551
	TRAPD(err,DoServiceAlreadyCompletedRequestL(iRedoFunction));
sl@0
   552
sl@0
   553
	if (err != KErrNone)
sl@0
   554
		{
sl@0
   555
		switch(iRedoFunction)
sl@0
   556
			{
sl@0
   557
			case EMMFDevSoundProxyInitialize1:
sl@0
   558
			case EMMFDevSoundProxyInitialize2:
sl@0
   559
			case EMMFDevSoundProxyInitialize4:
sl@0
   560
				InitializeComplete(err);
sl@0
   561
				break;
sl@0
   562
			case EMMFDevSoundProxyPlayInit:
sl@0
   563
				PlayError(err);
sl@0
   564
				break;
sl@0
   565
			case EMMFDevSoundProxyRecordInit:
sl@0
   566
				RecordError(err);
sl@0
   567
				break;
sl@0
   568
			case EMMFDevSoundProxyPlayTone:
sl@0
   569
			case EMMFDevSoundProxyPlayDualTone:
sl@0
   570
			case EMMFDevSoundProxyPlayDTMFString:
sl@0
   571
			case EMMFDevSoundProxyPlayToneSequence:
sl@0
   572
			case EMMFDevSoundProxyPlayFixedSequence:
sl@0
   573
				ToneFinished(err);
sl@0
   574
				break;
sl@0
   575
			default:
sl@0
   576
				break;
sl@0
   577
			}
sl@0
   578
		}
sl@0
   579
	}
sl@0
   580
sl@0
   581
void CMMFDevSoundSession::EnqueueRequest(const RMmfIpcMessage& aMessage)
sl@0
   582
	{
sl@0
   583
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::EnqueueRequest - Enter"));
sl@0
   584
	// Encapsule the request
sl@0
   585
	TMMFDevSoundRequest request;
sl@0
   586
	request.SetMessage(aMessage);
sl@0
   587
	// Append
sl@0
   588
	TInt error = iQueuedRequests.Append(request);
sl@0
   589
	__ASSERT_DEBUG(error == KErrNone, Panic(EQueueRequestsFailedToAppend));
sl@0
   590
	SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::EnqueueRequest - Exit"));
sl@0
   591
	}
sl@0
   592
sl@0
   593
//
sl@0
   594
// CMMFDevSoundSession::DoPostOpenL
sl@0
   595
//
sl@0
   596
TBool CMMFDevSoundSession::DoPostOpenL(const RMmfIpcMessage& /*aMessage*/)
sl@0
   597
	{
sl@0
   598
	iAdapter->PostOpenL();
sl@0
   599
	iOperationCompletePending = ETrue;
sl@0
   600
	return EFalse;
sl@0
   601
	}
sl@0
   602
sl@0
   603
//
sl@0
   604
// CMMFDevSoundSession::DoInitialize1L
sl@0
   605
// (other items were commented in a header).
sl@0
   606
//
sl@0
   607
TBool CMMFDevSoundSession::DoInitialize1L(const RMmfIpcMessage& aMessage)
sl@0
   608
	{
sl@0
   609
    iMsgQueue.Close(); // close if already open
sl@0
   610
	TInt err = iMsgQueue.Open(aMessage, 2, EOwnerThread); // a global queue but owned by thread
sl@0
   611
	User::LeaveIfError(err);
sl@0
   612
	DoSetClientConfigL();// added here instead of the CreateL()
sl@0
   613
	TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
   614
	User::LeaveIfError(MessageRead(aMessage,1,devSoundBuf));
sl@0
   615
	iCachedClientData = devSoundBuf;
sl@0
   616
	TMMFState mode = devSoundBuf().iMode;
sl@0
   617
	iAdapter->InitializeL(mode);
sl@0
   618
	iBufferPlay = NULL;
sl@0
   619
	iPlayErrorOccured = EFalse;
sl@0
   620
	// Flag to queue any further request 
sl@0
   621
	// but the message can be completed now
sl@0
   622
	iOperationCompletePending = ETrue;
sl@0
   623
	return ETrue;
sl@0
   624
	}
sl@0
   625
sl@0
   626
//
sl@0
   627
// CMMFDevSoundSession::DoAlreadyCompletedInitialize1L
sl@0
   628
// (other items were commented in a header).
sl@0
   629
//
sl@0
   630
void CMMFDevSoundSession::DoAlreadyCompletedInitialize1L()
sl@0
   631
	{
sl@0
   632
	TMMFState mode = iCachedClientData().iMode;
sl@0
   633
	iAdapter->InitializeL(mode);
sl@0
   634
	iBufferPlay = NULL;
sl@0
   635
	iPlayErrorOccured = EFalse;
sl@0
   636
	// Flag to queue any further request
sl@0
   637
	iOperationCompletePending = ETrue;
sl@0
   638
	}
sl@0
   639
sl@0
   640
//
sl@0
   641
// CMMFDevSoundSession::DoInitialize2L
sl@0
   642
// (other items were commented in a header).
sl@0
   643
//
sl@0
   644
TBool CMMFDevSoundSession::DoInitialize2L(const RMmfIpcMessage& aMessage)
sl@0
   645
	{
sl@0
   646
    iMsgQueue.Close(); // close if already open
sl@0
   647
	TInt err = iMsgQueue.Open(aMessage, 2, EOwnerThread); // a global queue but owned by thread
sl@0
   648
	User::LeaveIfError(err);
sl@0
   649
	DoSetClientConfigL();// added here instead of the CreateL()
sl@0
   650
	TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
   651
	User::LeaveIfError(MessageRead(aMessage,1,devSoundBuf));
sl@0
   652
	iCachedClientData = devSoundBuf;
sl@0
   653
	TUid HWDev = devSoundBuf().iHWDev;
sl@0
   654
	TMMFState mode = devSoundBuf().iMode;
sl@0
   655
	iAdapter->InitializeL(HWDev, mode);
sl@0
   656
	iBufferPlay = NULL;
sl@0
   657
	iPlayErrorOccured = EFalse;
sl@0
   658
	return ETrue;
sl@0
   659
	}
sl@0
   660
sl@0
   661
//
sl@0
   662
// CMMFDevSoundSession::DoAlreadyCompletedInitialize2L
sl@0
   663
// (other items were commented in a header).
sl@0
   664
//
sl@0
   665
void CMMFDevSoundSession::DoAlreadyCompletedInitialize2L()
sl@0
   666
	{
sl@0
   667
	TUid HWDev = iCachedClientData().iHWDev;
sl@0
   668
	TMMFState mode = iCachedClientData().iMode;
sl@0
   669
	iAdapter->InitializeL(HWDev, mode);
sl@0
   670
	iBufferPlay = NULL;
sl@0
   671
	iPlayErrorOccured = EFalse;
sl@0
   672
	}
sl@0
   673
sl@0
   674
//
sl@0
   675
// CMMFDevSoundSession::DoInitialize4L
sl@0
   676
// (other items were commented in a header).
sl@0
   677
//
sl@0
   678
TBool CMMFDevSoundSession::DoInitialize4L(const RMmfIpcMessage& aMessage)
sl@0
   679
	{
sl@0
   680
    iMsgQueue.Close();
sl@0
   681
	TInt err = iMsgQueue.Open(aMessage, 2, EOwnerThread); // a global queue but owned by thread
sl@0
   682
	User::LeaveIfError(err);
sl@0
   683
	DoSetClientConfigL();// added here instead of the CreateL()
sl@0
   684
	TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
   685
	User::LeaveIfError(MessageRead(aMessage, TInt(1), devSoundBuf));
sl@0
   686
	iCachedClientData = devSoundBuf;
sl@0
   687
	TFourCC desiredFourCC = devSoundBuf().iDesiredFourCC;
sl@0
   688
	TMMFState mode = devSoundBuf().iMode;
sl@0
   689
	iAdapter->InitializeL(desiredFourCC, mode);
sl@0
   690
	iBufferPlay = NULL;
sl@0
   691
	iPlayErrorOccured = EFalse;
sl@0
   692
	// Flag to queue any further request 
sl@0
   693
	// but the message can be completed now
sl@0
   694
	iOperationCompletePending = ETrue;
sl@0
   695
	return ETrue;
sl@0
   696
	}
sl@0
   697
sl@0
   698
//
sl@0
   699
// CMMFDevSoundSession::DoAlreadyCompletedInitialize4L
sl@0
   700
// (other items were commented in a header).
sl@0
   701
//
sl@0
   702
void CMMFDevSoundSession::DoAlreadyCompletedInitialize4L()
sl@0
   703
	{
sl@0
   704
	TFourCC desiredFourCC = iCachedClientData().iDesiredFourCC;
sl@0
   705
	TMMFState mode = iCachedClientData().iMode;
sl@0
   706
	iAdapter->InitializeL(desiredFourCC, mode);
sl@0
   707
	iBufferPlay = NULL;
sl@0
   708
	iPlayErrorOccured = EFalse;
sl@0
   709
	// Flag to queue any further request
sl@0
   710
	iOperationCompletePending = ETrue;
sl@0
   711
	}
sl@0
   712
sl@0
   713
//
sl@0
   714
// CMMFDevSoundSession::DoCancelInitialize
sl@0
   715
// (other items were commented in a header).
sl@0
   716
//
sl@0
   717
TBool CMMFDevSoundSession::DoCancelInitializeL(const RMmfIpcMessage& aMessage)
sl@0
   718
	{
sl@0
   719
	TInt err=iAdapter->CancelInitialize();
sl@0
   720
sl@0
   721
	if (err != KErrNone)
sl@0
   722
		{
sl@0
   723
		aMessage.Complete(err);
sl@0
   724
		iOperationCompletePending = EFalse;
sl@0
   725
		return ETrue;
sl@0
   726
		}
sl@0
   727
	else
sl@0
   728
		{
sl@0
   729
		iOperationCompletePending = ETrue;
sl@0
   730
		}
sl@0
   731
	return EFalse;
sl@0
   732
	}
sl@0
   733
sl@0
   734
//
sl@0
   735
// CMMFDevSoundSession::DoCapabilitiesL
sl@0
   736
// (other items were commented in a header).
sl@0
   737
//
sl@0
   738
TBool CMMFDevSoundSession::DoCapabilitiesL(const RMmfIpcMessage& aMessage)
sl@0
   739
	{
sl@0
   740
	TInt err = iAdapter->Capabilities(iDevSoundCapabilities);
sl@0
   741
	if(err != KErrNone)
sl@0
   742
		{
sl@0
   743
		aMessage.Complete(err);
sl@0
   744
		iOperationCompletePending = EFalse;
sl@0
   745
		}
sl@0
   746
	else
sl@0
   747
		{
sl@0
   748
		iOperationCompletePending = ETrue;
sl@0
   749
		}
sl@0
   750
	return EFalse;
sl@0
   751
	}
sl@0
   752
sl@0
   753
//
sl@0
   754
// CMMFDevSoundSession::DoConfigL
sl@0
   755
// (other items were commented in a header).
sl@0
   756
//
sl@0
   757
TBool CMMFDevSoundSession::DoConfigL(const RMmfIpcMessage& aMessage)
sl@0
   758
	{
sl@0
   759
	TMMFDevSoundProxySettings devSoundSet;
sl@0
   760
	devSoundSet.iConfig = iAdapter->Config();
sl@0
   761
	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
sl@0
   762
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
   763
	return ETrue;
sl@0
   764
	}
sl@0
   765
sl@0
   766
//
sl@0
   767
// CMMFDevSoundSession::DoSetConfigL
sl@0
   768
// (other items were commented in a header).
sl@0
   769
//
sl@0
   770
TBool CMMFDevSoundSession::DoSetConfigL(const RMmfIpcMessage& aMessage)
sl@0
   771
	{
sl@0
   772
	TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
   773
	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
sl@0
   774
	TMMFCapabilities config = devSoundBuf().iConfig;
sl@0
   775
	iAdapter->SetConfigL(config);
sl@0
   776
	iOperationCompletePending = ETrue;
sl@0
   777
	return EFalse;
sl@0
   778
	}
sl@0
   779
sl@0
   780
//
sl@0
   781
// CMMFDevSoundSession::axVolumeL
sl@0
   782
// (other items were commented in a header).
sl@0
   783
//
sl@0
   784
TBool CMMFDevSoundSession::DoMaxVolumeL(const RMmfIpcMessage& aMessage)
sl@0
   785
	{
sl@0
   786
	TMMFDevSoundProxySettings devSoundSet;
sl@0
   787
	devSoundSet.iMaxVolume = iAdapter->MaxVolume();
sl@0
   788
	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
sl@0
   789
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
   790
	return ETrue;
sl@0
   791
	}
sl@0
   792
sl@0
   793
//
sl@0
   794
// CMMFDevSoundSession::DoVolumeL
sl@0
   795
// (other items were commented in a header).
sl@0
   796
//
sl@0
   797
TBool CMMFDevSoundSession::DoVolumeL(const RMmfIpcMessage& aMessage)
sl@0
   798
	{
sl@0
   799
	TMMFDevSoundProxySettings devSoundSet;
sl@0
   800
	devSoundSet.iVolume = iAdapter->Volume();
sl@0
   801
	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
sl@0
   802
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
   803
	return ETrue;
sl@0
   804
	}
sl@0
   805
sl@0
   806
//
sl@0
   807
// CMMFDevSoundSession::DoSetVolumeL
sl@0
   808
// (other items were commented in a header).
sl@0
   809
//
sl@0
   810
TBool CMMFDevSoundSession::DoSetVolumeL(const RMmfIpcMessage& aMessage)
sl@0
   811
	{
sl@0
   812
	TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
   813
	User::LeaveIfError(MessageRead(aMessage, TInt(1),devSoundBuf));
sl@0
   814
	TInt volume = devSoundBuf().iVolume;
sl@0
   815
	TBool asyncOperation;
sl@0
   816
	User::LeaveIfError(iAdapter->SetVolume(volume, asyncOperation));
sl@0
   817
	iOperationCompletePending = asyncOperation;
sl@0
   818
	return !asyncOperation;
sl@0
   819
	}
sl@0
   820
sl@0
   821
//
sl@0
   822
// CMMFDevSoundSession::DoMaxGainL
sl@0
   823
// (other items were commented in a header).
sl@0
   824
//
sl@0
   825
TBool CMMFDevSoundSession::DoMaxGainL(const RMmfIpcMessage& aMessage)
sl@0
   826
	{
sl@0
   827
	TMMFDevSoundProxySettings devSoundSet;
sl@0
   828
	devSoundSet.iMaxGain = iAdapter->MaxGain();
sl@0
   829
	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
sl@0
   830
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
   831
	return ETrue;
sl@0
   832
	}
sl@0
   833
sl@0
   834
//
sl@0
   835
// CMMFDevSoundSession::DoGainL
sl@0
   836
// (other items were commented in a header).
sl@0
   837
//
sl@0
   838
TBool CMMFDevSoundSession::DoGainL(const RMmfIpcMessage& aMessage)
sl@0
   839
	{
sl@0
   840
	TMMFDevSoundProxySettings devSoundSet;
sl@0
   841
	devSoundSet.iGain = iAdapter->Gain();
sl@0
   842
	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
sl@0
   843
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
   844
	return ETrue;
sl@0
   845
	}
sl@0
   846
sl@0
   847
//
sl@0
   848
// CMMFDevSoundSession::DoSetGainL
sl@0
   849
// (other items were commented in a header).
sl@0
   850
//
sl@0
   851
TBool CMMFDevSoundSession::DoSetGainL(const RMmfIpcMessage& aMessage)
sl@0
   852
	{
sl@0
   853
	TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
   854
	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
sl@0
   855
	TInt gain = devSoundBuf().iGain;
sl@0
   856
	TBool asyncOperation;
sl@0
   857
	User::LeaveIfError(iAdapter->SetGain(gain, asyncOperation));
sl@0
   858
	iOperationCompletePending = asyncOperation;
sl@0
   859
	return !asyncOperation;
sl@0
   860
	}
sl@0
   861
sl@0
   862
//
sl@0
   863
// CMMFDevSoundSession::DoGetPlayBalanceL
sl@0
   864
// (other items were commented in a header).
sl@0
   865
//
sl@0
   866
TBool CMMFDevSoundSession::DoGetPlayBalanceL(const RMmfIpcMessage& aMessage)
sl@0
   867
	{
sl@0
   868
	TMMFDevSoundProxySettings devSoundSet;
sl@0
   869
	iAdapter->GetPlayBalanceL(devSoundSet.iLeftPercentage, devSoundSet.iRightPercentage);
sl@0
   870
	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
sl@0
   871
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
   872
	return ETrue;
sl@0
   873
	}
sl@0
   874
sl@0
   875
//
sl@0
   876
// CMMFDevSoundSession::DoSetPlayBalanceL
sl@0
   877
// (other items were commented in a header).
sl@0
   878
//
sl@0
   879
TBool CMMFDevSoundSession::DoSetPlayBalanceL(const RMmfIpcMessage& aMessage)
sl@0
   880
	{
sl@0
   881
	TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
   882
    User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
sl@0
   883
	TInt leftPercentage = devSoundBuf().iLeftPercentage;
sl@0
   884
	TInt rightPercentage = devSoundBuf().iRightPercentage;
sl@0
   885
	TBool asyncOperation;
sl@0
   886
	iAdapter->SetPlayBalanceL(leftPercentage, rightPercentage, asyncOperation);
sl@0
   887
	iOperationCompletePending = asyncOperation;
sl@0
   888
	return !asyncOperation;
sl@0
   889
	}
sl@0
   890
sl@0
   891
//
sl@0
   892
// CMMFDevSoundSession::DoGetRecordBalanceL
sl@0
   893
// (other items were commented in a header).
sl@0
   894
//
sl@0
   895
TBool CMMFDevSoundSession::DoGetRecordBalanceL(const RMmfIpcMessage& aMessage)
sl@0
   896
	{
sl@0
   897
	TMMFDevSoundProxySettings devSoundSet;
sl@0
   898
	iAdapter->GetRecordBalanceL(devSoundSet.iLeftPercentage, devSoundSet.iRightPercentage);
sl@0
   899
	TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
sl@0
   900
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
   901
	return ETrue;
sl@0
   902
	}
sl@0
   903
sl@0
   904
//
sl@0
   905
// CMMFDevSoundSession::DoSetRecordBalanceL
sl@0
   906
// (other items were commented in a header).
sl@0
   907
//
sl@0
   908
TBool CMMFDevSoundSession::DoSetRecordBalanceL(const RMmfIpcMessage& aMessage)
sl@0
   909
	{
sl@0
   910
	TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
   911
	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
sl@0
   912
	TInt leftPercentage = devSoundBuf().iLeftPercentage;
sl@0
   913
	TInt rightPercentage = devSoundBuf().iRightPercentage;
sl@0
   914
	TBool asyncOperation;
sl@0
   915
	iAdapter->SetRecordBalanceL(leftPercentage, rightPercentage, asyncOperation);
sl@0
   916
	iOperationCompletePending = asyncOperation;
sl@0
   917
	return !asyncOperation;
sl@0
   918
	}
sl@0
   919
sl@0
   920
//
sl@0
   921
// CMMFDevSoundSession::DoPlayInitL
sl@0
   922
// (other items were commented in a header).
sl@0
   923
//
sl@0
   924
TBool CMMFDevSoundSession::DoPlayInitL(const RMmfIpcMessage& /*aMessage*/)
sl@0
   925
	{
sl@0
   926
	iAdapter->PlayInitL();
sl@0
   927
	iOperationCompletePending = ETrue;
sl@0
   928
	return ETrue;
sl@0
   929
	}
sl@0
   930
sl@0
   931
//
sl@0
   932
// CMMFDevSoundSession::DoAlreadyCompletedPlayInitL
sl@0
   933
// (other items were commented in a header).
sl@0
   934
//
sl@0
   935
void CMMFDevSoundSession::DoAlreadyCompletedPlayInitL()
sl@0
   936
	{
sl@0
   937
	iAdapter->PlayInitL();
sl@0
   938
	iOperationCompletePending = ETrue;
sl@0
   939
	}
sl@0
   940
sl@0
   941
//
sl@0
   942
// CMMFDevSoundSession::DoRecordInitL
sl@0
   943
// (other items were commented in a header).
sl@0
   944
//
sl@0
   945
TBool CMMFDevSoundSession::DoRecordInitL(const RMmfIpcMessage& /*aMessage*/)
sl@0
   946
	{
sl@0
   947
	iAdapter->RecordInitL();
sl@0
   948
	iOperationCompletePending = ETrue;
sl@0
   949
	return ETrue;
sl@0
   950
	}
sl@0
   951
sl@0
   952
//
sl@0
   953
// CMMFDevSoundSession::DoAlreadyCompletedRecordInitL
sl@0
   954
// (other items were commented in a header).
sl@0
   955
//
sl@0
   956
void CMMFDevSoundSession::DoAlreadyCompletedRecordInitL()
sl@0
   957
	{
sl@0
   958
	iAdapter->RecordInitL();
sl@0
   959
	iOperationCompletePending = ETrue;
sl@0
   960
	}
sl@0
   961
sl@0
   962
//
sl@0
   963
// CMMFDevSoundSession::DoPlayDataL
sl@0
   964
// (other items were commented in a header).
sl@0
   965
//
sl@0
   966
TBool CMMFDevSoundSession::DoPlayDataL(const RMmfIpcMessage& aMessage)
sl@0
   967
	{
sl@0
   968
	SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayDataL - Enter"));
sl@0
   969
sl@0
   970
	if( iPlayErrorOccured )
sl@0
   971
		{
sl@0
   972
		SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayDataL - Ignore and Exit"));
sl@0
   973
		return ETrue;
sl@0
   974
		}
sl@0
   975
sl@0
   976
	TMMFDevSoundProxyHwBufPckg devSoundBuf;
sl@0
   977
	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
sl@0
   978
	iBufferPlay->SetLastBuffer(devSoundBuf().iLastBuffer);
sl@0
   979
sl@0
   980
	TPtr8 dataPtr(iChunk.Base(), devSoundBuf().iBufferSize, devSoundBuf().iBufferSize);
sl@0
   981
	// Copy data over from chunk
sl@0
   982
	iBufferPlay->Data().Copy(dataPtr);
sl@0
   983
	iAdapter->PlayData();
sl@0
   984
	SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayDataL - Exit"));
sl@0
   985
	return ETrue;
sl@0
   986
	}
sl@0
   987
sl@0
   988
//
sl@0
   989
// CMMFDevSoundSession::DoRecordDataL
sl@0
   990
// (other items were commented in a header).
sl@0
   991
//
sl@0
   992
TBool CMMFDevSoundSession::DoRecordDataL(const RMmfIpcMessage& /*aMessage*/)
sl@0
   993
	{
sl@0
   994
	iAdapter->RecordData();
sl@0
   995
	return ETrue;
sl@0
   996
	}
sl@0
   997
sl@0
   998
//
sl@0
   999
// CMMFDevSoundSession::DoStopL
sl@0
  1000
// (other items were commented in a header).
sl@0
  1001
//
sl@0
  1002
TBool CMMFDevSoundSession::DoStopL(const RMmfIpcMessage& /*aMessage*/)
sl@0
  1003
	{
sl@0
  1004
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoStopL - Enter"));
sl@0
  1005
    // Sometimes Stop is not involved on a commit cycle
sl@0
  1006
	TBool completed = iAdapter->Stop();
sl@0
  1007
	if (completed)
sl@0
  1008
		{
sl@0
  1009
        FlushQueuedRequests();
sl@0
  1010
		FlushEventQueue(); // completed returned here means we were idle to start with. TODO could possibly skip this flush
sl@0
  1011
		iChunk.Close();
sl@0
  1012
		}
sl@0
  1013
	iOperationCompletePending = !completed;
sl@0
  1014
	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoStopL - Exit. Return value is [%d]"), completed);
sl@0
  1015
	return completed;
sl@0
  1016
	}
sl@0
  1017
sl@0
  1018
//
sl@0
  1019
// CMMFDevSoundSession::DoPauseL
sl@0
  1020
// (other items were commented in a header).
sl@0
  1021
//
sl@0
  1022
TBool CMMFDevSoundSession::DoPauseL(const RMmfIpcMessage& /*aMessage*/)
sl@0
  1023
	{
sl@0
  1024
	User::LeaveIfError(iAdapter->Pause());
sl@0
  1025
	iOperationCompletePending = ETrue;
sl@0
  1026
	return EFalse;
sl@0
  1027
	}
sl@0
  1028
sl@0
  1029
//
sl@0
  1030
// CMMFDevSoundSession::DoPlayToneL
sl@0
  1031
// (other items were commented in a header).
sl@0
  1032
//
sl@0
  1033
TBool CMMFDevSoundSession::DoPlayToneL(const RMmfIpcMessage& aMessage)
sl@0
  1034
	{
sl@0
  1035
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayToneL - Enter"));
sl@0
  1036
    TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
  1037
	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
sl@0
  1038
	iCachedClientData = devSoundBuf;
sl@0
  1039
	TInt frequency = devSoundBuf().iFrequencyOne;
sl@0
  1040
	TTimeIntervalMicroSeconds duration(devSoundBuf().iDuration);
sl@0
  1041
	iAdapter->PlayToneL(frequency, duration);
sl@0
  1042
	iOperationCompletePending = ETrue;
sl@0
  1043
	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoPlayToneL - Exit. Return value is [%d]"), ETrue);
sl@0
  1044
	return ETrue;
sl@0
  1045
	}
sl@0
  1046
sl@0
  1047
//
sl@0
  1048
// CMMFDevSoundSession::DoAlreadyCompletedPlayToneL
sl@0
  1049
// (other items were commented in a header).
sl@0
  1050
//
sl@0
  1051
void CMMFDevSoundSession::DoAlreadyCompletedPlayToneL()
sl@0
  1052
	{
sl@0
  1053
	TInt frequency = iCachedClientData().iFrequencyOne;
sl@0
  1054
	TTimeIntervalMicroSeconds duration(iCachedClientData().iDuration);
sl@0
  1055
	iAdapter->PlayToneL(frequency, duration);
sl@0
  1056
	iOperationCompletePending = ETrue;
sl@0
  1057
	}
sl@0
  1058
sl@0
  1059
//
sl@0
  1060
// CMMFDevSoundSession::DoPlayDualToneL
sl@0
  1061
// (other items were commented in a header).	
sl@0
  1062
//
sl@0
  1063
TBool CMMFDevSoundSession::DoPlayDualToneL(const RMmfIpcMessage& aMessage)
sl@0
  1064
	{
sl@0
  1065
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayDualToneL - Enter"));
sl@0
  1066
    TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
  1067
	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
sl@0
  1068
	iCachedClientData = devSoundBuf;
sl@0
  1069
	TInt frequencyOne = devSoundBuf().iFrequencyOne;
sl@0
  1070
	TInt frequencyTwo = devSoundBuf().iFrequencyTwo;
sl@0
  1071
	TTimeIntervalMicroSeconds duration(devSoundBuf().iDuration);
sl@0
  1072
	iAdapter->PlayDualToneL(frequencyOne, frequencyTwo, duration);
sl@0
  1073
	iOperationCompletePending = ETrue;
sl@0
  1074
	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoPlayDualToneL - Exit. Return value is [%d]"), ETrue);
sl@0
  1075
	return ETrue;
sl@0
  1076
	}
sl@0
  1077
sl@0
  1078
//
sl@0
  1079
// CMMFDevSoundSession::DoAlreadyCompletedPlayDualToneL
sl@0
  1080
// (other items were commented in a header).
sl@0
  1081
//
sl@0
  1082
void CMMFDevSoundSession::DoAlreadyCompletedPlayDualToneL()
sl@0
  1083
	{
sl@0
  1084
	TInt frequencyOne = iCachedClientData().iFrequencyOne;
sl@0
  1085
	TInt frequencyTwo = iCachedClientData().iFrequencyTwo;
sl@0
  1086
	TTimeIntervalMicroSeconds duration(iCachedClientData().iDuration);
sl@0
  1087
	iAdapter->PlayDualToneL(frequencyOne, frequencyTwo, duration);
sl@0
  1088
	iOperationCompletePending = ETrue;
sl@0
  1089
	}
sl@0
  1090
sl@0
  1091
//
sl@0
  1092
// CMMFDevSoundSession::DoPlayDTMFStringL
sl@0
  1093
// (other items were commented in a header).
sl@0
  1094
//
sl@0
  1095
TBool CMMFDevSoundSession::DoPlayDTMFStringL(const RMmfIpcMessage& aMessage)
sl@0
  1096
	{
sl@0
  1097
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayDTMFStringL - Enter"));
sl@0
  1098
    TInt dtmfLength = aMessage.GetDesLength(2);
sl@0
  1099
	
sl@0
  1100
	if(iDtmfString)
sl@0
  1101
		{
sl@0
  1102
		delete iDtmfString;
sl@0
  1103
		iDtmfString = NULL;
sl@0
  1104
		}
sl@0
  1105
sl@0
  1106
	iDtmfString = HBufC::NewL(dtmfLength);
sl@0
  1107
	TPtr dtmfPtr = iDtmfString->Des();
sl@0
  1108
    User::LeaveIfError(MessageRead(aMessage, TInt(2), dtmfPtr));
sl@0
  1109
	iAdapter->PlayDTMFStringL(*iDtmfString);
sl@0
  1110
	iOperationCompletePending = ETrue;
sl@0
  1111
	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoPlayDTMFStringL - Exit. Return value is [%d]"), ETrue);
sl@0
  1112
	return ETrue;
sl@0
  1113
	}
sl@0
  1114
sl@0
  1115
//
sl@0
  1116
// CMMFDevSoundSession::DoAlreadyCompletedPlayDTMFStringL
sl@0
  1117
// (other items were commented in a header).
sl@0
  1118
//
sl@0
  1119
void CMMFDevSoundSession::DoAlreadyCompletedPlayDTMFStringL()
sl@0
  1120
	{
sl@0
  1121
	iAdapter->PlayDTMFStringL(*iDtmfString);
sl@0
  1122
	iOperationCompletePending = ETrue;
sl@0
  1123
	}
sl@0
  1124
sl@0
  1125
//
sl@0
  1126
// CMMFDevSoundSession::DoPlayToneSequenceL
sl@0
  1127
// (other items were commented in a header).
sl@0
  1128
//
sl@0
  1129
TBool CMMFDevSoundSession::DoPlayToneSequenceL(const RMmfIpcMessage& aMessage)
sl@0
  1130
	{
sl@0
  1131
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayToneSequenceL - Enter"));
sl@0
  1132
    TInt toneLength = aMessage.GetDesLength(1);
sl@0
  1133
sl@0
  1134
	if(iToneSeqBuf)
sl@0
  1135
		{
sl@0
  1136
		delete iToneSeqBuf;
sl@0
  1137
		iToneSeqBuf = NULL;
sl@0
  1138
		}
sl@0
  1139
sl@0
  1140
	iToneSeqBuf = HBufC8::NewL(toneLength);
sl@0
  1141
	TPtr8 toneSeqPtr = iToneSeqBuf->Des();
sl@0
  1142
	User::LeaveIfError(MessageRead(aMessage,TInt(1), toneSeqPtr));
sl@0
  1143
sl@0
  1144
	iAdapter->PlayToneSequenceL(*iToneSeqBuf);
sl@0
  1145
	iOperationCompletePending = ETrue;
sl@0
  1146
	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoPlayToneSequenceL - Exit. Return value is [%d]"), ETrue);
sl@0
  1147
	return ETrue;
sl@0
  1148
	}
sl@0
  1149
sl@0
  1150
//
sl@0
  1151
// CMMFDevSoundSession::DoAlreadyCompletedPlayToneSequenceL
sl@0
  1152
// (other items were commented in a header).
sl@0
  1153
//
sl@0
  1154
void CMMFDevSoundSession::DoAlreadyCompletedPlayToneSequenceL()
sl@0
  1155
	{
sl@0
  1156
	iAdapter->PlayToneSequenceL(*iToneSeqBuf);
sl@0
  1157
	iOperationCompletePending = ETrue;
sl@0
  1158
	}
sl@0
  1159
sl@0
  1160
//
sl@0
  1161
// CMMFDevSoundSession::DoPlayFixedSequenceL
sl@0
  1162
// (other items were commented in a header).
sl@0
  1163
//
sl@0
  1164
TBool CMMFDevSoundSession::DoPlayFixedSequenceL(const RMmfIpcMessage& aMessage)
sl@0
  1165
	{
sl@0
  1166
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoPlayFixedSequenceL - Enter"));
sl@0
  1167
    TPckgBuf<TInt> buf;
sl@0
  1168
	User::LeaveIfError(MessageRead(aMessage,TInt(1),buf));
sl@0
  1169
	TInt seqNum = buf();
sl@0
  1170
	iSeqNum = seqNum;
sl@0
  1171
	iAdapter->PlayFixedSequenceL(seqNum);
sl@0
  1172
	iOperationCompletePending = ETrue;
sl@0
  1173
	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoPlayFixedSequenceL - Exit. Return value is [%d]"), ETrue);
sl@0
  1174
	return ETrue;
sl@0
  1175
	}
sl@0
  1176
sl@0
  1177
//
sl@0
  1178
// CMMFDevSoundSession::DoAlreadyCompletedPlayFixedSequenceL
sl@0
  1179
// (other items were commented in a header).
sl@0
  1180
//
sl@0
  1181
void CMMFDevSoundSession::DoAlreadyCompletedPlayFixedSequenceL()
sl@0
  1182
	{
sl@0
  1183
	iAdapter->PlayFixedSequenceL(iSeqNum);
sl@0
  1184
	iOperationCompletePending = ETrue;
sl@0
  1185
	}
sl@0
  1186
sl@0
  1187
//
sl@0
  1188
// CMMFDevSoundSession::DoSetDTMFLengthsL
sl@0
  1189
// (other items were commented in a header).
sl@0
  1190
//
sl@0
  1191
TBool CMMFDevSoundSession::DoSetDTMFLengthsL(const RMmfIpcMessage& aMessage)
sl@0
  1192
	{
sl@0
  1193
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoSetDTMFLengthsL - Enter"));
sl@0
  1194
    TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
  1195
	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
sl@0
  1196
	TTimeIntervalMicroSeconds32 toneOnLength = devSoundBuf().iToneOnLength;
sl@0
  1197
	TTimeIntervalMicroSeconds32 toneOffLength = devSoundBuf().iToneOffLength;
sl@0
  1198
	TTimeIntervalMicroSeconds32 pauseLength = devSoundBuf().iPauseLength;
sl@0
  1199
	User::LeaveIfError(iAdapter->SetDTMFLengths(toneOnLength, toneOffLength, pauseLength));
sl@0
  1200
    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoSetDTMFLengthsL - Exit. Return value is [%d]"), ETrue);
sl@0
  1201
	return ETrue;
sl@0
  1202
	}
sl@0
  1203
sl@0
  1204
//
sl@0
  1205
// CMMFDevSoundSession::DoSetVolumeRampL
sl@0
  1206
// (other items were commented in a header).
sl@0
  1207
//
sl@0
  1208
TBool CMMFDevSoundSession::DoSetVolumeRampL(const RMmfIpcMessage& aMessage)
sl@0
  1209
	{
sl@0
  1210
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoSetVolumeRampL - Enter"));
sl@0
  1211
    TMMFDevSoundProxySettingsPckg devSoundBuf;
sl@0
  1212
	User::LeaveIfError(MessageRead(aMessage,TInt(1),devSoundBuf));
sl@0
  1213
	TTimeIntervalMicroSeconds duration = devSoundBuf().iDuration;
sl@0
  1214
	User::LeaveIfError(iAdapter->SetVolumeRamp(duration));
sl@0
  1215
	iOperationCompletePending = EFalse; // Volume ramp doesn't result on commit
sl@0
  1216
    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoSetVolumeRampL - Exit. Return value is [%d]"), ETrue);
sl@0
  1217
	return ETrue; // operation complete
sl@0
  1218
	}
sl@0
  1219
sl@0
  1220
//
sl@0
  1221
// CMMFDevSoundSession::DoGetSupportedInputDataTypesL
sl@0
  1222
// (other items were commented in a header).
sl@0
  1223
//
sl@0
  1224
TBool CMMFDevSoundSession::DoGetSupportedInputDataTypesL(
sl@0
  1225
							const RMmfIpcMessage& aMessage)
sl@0
  1226
	{
sl@0
  1227
	iArray.Reset();
sl@0
  1228
sl@0
  1229
	TMMFPrioritySettingsPckg prioritySetBuf;
sl@0
  1230
	User::LeaveIfError(MessageRead(aMessage,TInt(1),prioritySetBuf));
sl@0
  1231
	TMMFPrioritySettings prioritySet = prioritySetBuf();
sl@0
  1232
sl@0
  1233
	iAdapter->GetSupportedInputDataTypesL(iArray, prioritySet);
sl@0
  1234
sl@0
  1235
	TPckgBuf<TInt> pckg;
sl@0
  1236
	pckg() = iArray.Count();
sl@0
  1237
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
  1238
sl@0
  1239
	return ETrue;
sl@0
  1240
	}
sl@0
  1241
sl@0
  1242
//
sl@0
  1243
// CMMFDevSoundSession::DoGetSupportedOutputDataTypesL
sl@0
  1244
// (other items were commented in a header).
sl@0
  1245
//
sl@0
  1246
TBool CMMFDevSoundSession::DoGetSupportedOutputDataTypesL(
sl@0
  1247
							const RMmfIpcMessage& aMessage)
sl@0
  1248
	{
sl@0
  1249
	iArray.Reset();
sl@0
  1250
sl@0
  1251
	TMMFPrioritySettingsPckg prioritySetBuf;
sl@0
  1252
	User::LeaveIfError(MessageRead(aMessage,TInt(1),prioritySetBuf));
sl@0
  1253
	TMMFPrioritySettings prioritySet = prioritySetBuf();
sl@0
  1254
sl@0
  1255
	iAdapter->GetSupportedOutputDataTypesL(iArray, prioritySet);
sl@0
  1256
sl@0
  1257
	TPckgBuf<TInt> pckg;
sl@0
  1258
	pckg() = iArray.Count();
sl@0
  1259
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
  1260
sl@0
  1261
	return ETrue;
sl@0
  1262
	}
sl@0
  1263
sl@0
  1264
//
sl@0
  1265
// CMMFDevSoundSession::DoSamplesRecordedL
sl@0
  1266
// (other items were commented in a header).
sl@0
  1267
//
sl@0
  1268
TBool CMMFDevSoundSession::DoSamplesRecordedL(const RMmfIpcMessage& aMessage)
sl@0
  1269
	{
sl@0
  1270
	TPckgBuf<TInt> pckg;
sl@0
  1271
	pckg() = iAdapter->SamplesRecorded();
sl@0
  1272
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
  1273
	return ETrue;
sl@0
  1274
	}
sl@0
  1275
sl@0
  1276
//
sl@0
  1277
// CMMFDevSoundSession::DoSamplesPlayedL
sl@0
  1278
// (other items were commented in a header).
sl@0
  1279
//
sl@0
  1280
TBool CMMFDevSoundSession::DoSamplesPlayedL(const RMmfIpcMessage& aMessage)
sl@0
  1281
	{
sl@0
  1282
	TPckgBuf<TInt> pckg;
sl@0
  1283
	pckg() = iAdapter->SamplesPlayed();
sl@0
  1284
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),pckg));
sl@0
  1285
	return ETrue;
sl@0
  1286
	}
sl@0
  1287
sl@0
  1288
//
sl@0
  1289
// CMMFDevSoundSession::DoSetToneRepeatsL
sl@0
  1290
// (other items were commented in a header).
sl@0
  1291
//
sl@0
  1292
TBool CMMFDevSoundSession::DoSetToneRepeatsL(const RMmfIpcMessage& aMessage)
sl@0
  1293
	{
sl@0
  1294
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoSetToneRepeatsL - Enter"));
sl@0
  1295
    TPckgBuf<TInt> countRepeat;
sl@0
  1296
	User::LeaveIfError(MessageRead(aMessage,TInt(1),countRepeat));
sl@0
  1297
sl@0
  1298
	TPckgBuf<TTimeIntervalMicroSeconds> repeatTS;
sl@0
  1299
	User::LeaveIfError(MessageRead(aMessage,TInt(2),repeatTS));
sl@0
  1300
	User::LeaveIfError(iAdapter->SetToneRepeats(countRepeat(), repeatTS()));
sl@0
  1301
    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoSetToneRepeatsL - Exit. Return value is [%d]"), ETrue);
sl@0
  1302
	return ETrue;
sl@0
  1303
	}
sl@0
  1304
sl@0
  1305
//
sl@0
  1306
// CMMFDevSoundSession::DoSetPrioritySettingsL
sl@0
  1307
// (other items were commented in a header).
sl@0
  1308
//
sl@0
  1309
TBool CMMFDevSoundSession::DoSetPrioritySettingsL(
sl@0
  1310
						const RMmfIpcMessage& aMessage)
sl@0
  1311
	{
sl@0
  1312
	TPckgBuf<TMMFPrioritySettings> prioritySet;
sl@0
  1313
	User::LeaveIfError(MessageRead(aMessage,TInt(1),prioritySet));
sl@0
  1314
sl@0
  1315
	User::LeaveIfError(iAdapter->SetPrioritySettings(prioritySet()));
sl@0
  1316
	iOperationCompletePending = EFalse;
sl@0
  1317
	return ETrue;
sl@0
  1318
	}
sl@0
  1319
sl@0
  1320
//
sl@0
  1321
// CMMFDevSoundSession::DoFixedSequenceCountL
sl@0
  1322
// (other items were commented in a header).
sl@0
  1323
//
sl@0
  1324
TBool CMMFDevSoundSession::DoFixedSequenceCountL(
sl@0
  1325
					const RMmfIpcMessage& aMessage)
sl@0
  1326
	{
sl@0
  1327
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DoFixedSequenceCountL - Enter"));
sl@0
  1328
    TPckgBuf<TInt> fixSeqCountPckg;
sl@0
  1329
	TInt fixSeqCount = iAdapter->FixedSequenceCount();
sl@0
  1330
	fixSeqCountPckg = fixSeqCount;
sl@0
  1331
sl@0
  1332
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),fixSeqCountPckg));
sl@0
  1333
    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::DoFixedSequenceCountL - Exit. Return value is [%d]"), ETrue);
sl@0
  1334
	return ETrue;
sl@0
  1335
	}
sl@0
  1336
sl@0
  1337
sl@0
  1338
//
sl@0
  1339
// CMMFDevSoundSession::DoCopyFourCCArrayDataL
sl@0
  1340
// (other items were commented in a header).
sl@0
  1341
//
sl@0
  1342
TBool CMMFDevSoundSession::DoCopyFourCCArrayDataL(
sl@0
  1343
						const RMmfIpcMessage& aMessage)
sl@0
  1344
	{
sl@0
  1345
	const TInt KBufExpandSize8 = 8;//two TInts
sl@0
  1346
	CBufFlat* dataCopyBuffer = CBufFlat::NewL(KBufExpandSize8);
sl@0
  1347
	CleanupStack::PushL(dataCopyBuffer);
sl@0
  1348
	RBufWriteStream stream;
sl@0
  1349
	stream.Open(*dataCopyBuffer);
sl@0
  1350
	CleanupClosePushL(stream);
sl@0
  1351
	
sl@0
  1352
	TInt i = 0;
sl@0
  1353
	TInt count = iArray.Count();
sl@0
  1354
	
sl@0
  1355
	while (i < count)
sl@0
  1356
		{
sl@0
  1357
		stream.WriteInt32L(iArray[i].FourCC());
sl@0
  1358
		i++;
sl@0
  1359
		}
sl@0
  1360
	User::LeaveIfError(MessageWrite(aMessage, TInt(2), dataCopyBuffer->Ptr(0)));
sl@0
  1361
	stream.Close();
sl@0
  1362
	CleanupStack::PopAndDestroy(&stream);
sl@0
  1363
	CleanupStack::PopAndDestroy(dataCopyBuffer);
sl@0
  1364
	return ETrue;
sl@0
  1365
	}
sl@0
  1366
sl@0
  1367
sl@0
  1368
//
sl@0
  1369
// CMMFDevSoundSession::DoBufferToBeFilledDataL
sl@0
  1370
// (other items were commented in a header).
sl@0
  1371
//
sl@0
  1372
TBool CMMFDevSoundSession::DoBufferToBeFilledDataL(
sl@0
  1373
							const RMmfIpcMessage& aMessage)
sl@0
  1374
	{
sl@0
  1375
	// if CMMFDevSoundSession::PlayError() has been called, RChunk would have got closed.
sl@0
  1376
	// Need to check if Chunk Handle is still valid. If it is not,complete the message immediately and send a error to the Client.
sl@0
  1377
	if(!iChunk.Handle())
sl@0
  1378
		{
sl@0
  1379
		aMessage.Complete(KErrBadHandle);
sl@0
  1380
		return EFalse;	
sl@0
  1381
		}
sl@0
  1382
	TPckgBuf<TInt> requestChunkBuf;
sl@0
  1383
	User::LeaveIfError(MessageRead(aMessage, TInt(1), requestChunkBuf));
sl@0
  1384
	TBool requestChunk = requestChunkBuf();
sl@0
  1385
	if (requestChunk)
sl@0
  1386
		{
sl@0
  1387
		// if the client requests, always do EOpen
sl@0
  1388
		iHwBufPckgFill().iChunkOp = EOpen;
sl@0
  1389
		}
sl@0
  1390
	TInt err = MessageWrite(aMessage, TInt(2), iHwBufPckgFill);
sl@0
  1391
	if ( (err == KErrNone) && (iHwBufPckgFill().iChunkOp == EOpen) )
sl@0
  1392
		{
sl@0
  1393
		aMessage.Complete(iChunk);
sl@0
  1394
		}
sl@0
  1395
	else
sl@0
  1396
		{
sl@0
  1397
		aMessage.Complete(err);
sl@0
  1398
		}
sl@0
  1399
	return EFalse;
sl@0
  1400
	}
sl@0
  1401
sl@0
  1402
// CMMFDevSoundSession::DoBufferToBeEmptiedDataL
sl@0
  1403
// (other items were commented in a header).
sl@0
  1404
//
sl@0
  1405
TBool CMMFDevSoundSession::DoBufferToBeEmptiedDataL(
sl@0
  1406
						const RMmfIpcMessage& aMessage)
sl@0
  1407
	{
sl@0
  1408
	// if CMMFDevSoundSession::RecordError() has been called, RChunk would have got closed.
sl@0
  1409
	// Need to check if Chunk Handle is still valid. If it is not,complete the message immediately and send a error to the Client.
sl@0
  1410
	if(!iChunk.Handle())
sl@0
  1411
		{
sl@0
  1412
		aMessage.Complete(KErrBadHandle);
sl@0
  1413
		return EFalse;	
sl@0
  1414
		}
sl@0
  1415
	
sl@0
  1416
	TInt err = MessageWrite(aMessage, TInt(2), iHwBufPckgEmpty);
sl@0
  1417
	if ( (err == KErrNone) && (iHwBufPckgEmpty().iChunkOp == EOpen) )
sl@0
  1418
		{
sl@0
  1419
		aMessage.Complete(iChunk);
sl@0
  1420
		}
sl@0
  1421
	else
sl@0
  1422
		{
sl@0
  1423
		aMessage.Complete(err);
sl@0
  1424
		}
sl@0
  1425
	return EFalse;
sl@0
  1426
	}
sl@0
  1427
sl@0
  1428
//
sl@0
  1429
// CMMFDevSoundSession::DoEmptyBuffersL
sl@0
  1430
// (other items were commented in a header).
sl@0
  1431
//
sl@0
  1432
sl@0
  1433
TBool CMMFDevSoundSession::DoEmptyBuffersL(const RMmfIpcMessage& aMessage)
sl@0
  1434
	{
sl@0
  1435
	TInt err = KErrNone;
sl@0
  1436
	FilterQueueEvent(EMMFDevSoundProxyBTBFEvent);
sl@0
  1437
	// This is now asynchronous
sl@0
  1438
	err = iAdapter->EmptyBuffers();
sl@0
  1439
	if (err != KErrNone)
sl@0
  1440
		{
sl@0
  1441
		aMessage.Complete(err);
sl@0
  1442
		return EFalse;
sl@0
  1443
		}
sl@0
  1444
	iOperationCompletePending = ETrue;
sl@0
  1445
	return EFalse;
sl@0
  1446
	}
sl@0
  1447
//
sl@0
  1448
// CMMFDevSoundSession::DoGetTimePlayedL
sl@0
  1449
// (other items were commented in a header).
sl@0
  1450
//
sl@0
  1451
TBool CMMFDevSoundSession::DoGetTimePlayedL(const RMmfIpcMessage& aMessage)
sl@0
  1452
	{
sl@0
  1453
	TInt err = KErrNone;
sl@0
  1454
	TTimeIntervalMicroSeconds time(0);
sl@0
  1455
	TPckgBuf<TTimeIntervalMicroSeconds> timePckg(time);
sl@0
  1456
	err = iAdapter->GetTimePlayed(timePckg());
sl@0
  1457
	if (err != KErrNone)
sl@0
  1458
		{
sl@0
  1459
		aMessage.Complete(err);
sl@0
  1460
		return EFalse;		
sl@0
  1461
		}
sl@0
  1462
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),timePckg));
sl@0
  1463
	return ETrue;
sl@0
  1464
	}
sl@0
  1465
sl@0
  1466
TBool CMMFDevSoundSession::DoQueryResumeSupportedL(const RMmfIpcMessage& aMessage)
sl@0
  1467
	{
sl@0
  1468
	TBool isSupported = EFalse;
sl@0
  1469
	TPckgBuf<TBool> isSupportedPckg(isSupported);
sl@0
  1470
	isSupportedPckg() = iAdapter->IsResumeSupported();
sl@0
  1471
	User::LeaveIfError(MessageWrite(aMessage,TInt(2),isSupportedPckg));
sl@0
  1472
	return ETrue;
sl@0
  1473
	}
sl@0
  1474
sl@0
  1475
TBool CMMFDevSoundSession::DoResumeL(const RMmfIpcMessage& /*aMessage*/)
sl@0
  1476
	{
sl@0
  1477
	User::LeaveIfError( iAdapter->Resume() );
sl@0
  1478
	iOperationCompletePending = ETrue;
sl@0
  1479
	FilterQueueEvent(EMMFDevSoundProxyPausedRecordCompleteEvent);
sl@0
  1480
	return EFalse;
sl@0
  1481
	}
sl@0
  1482
sl@0
  1483
TBool CMMFDevSoundSession::DoPrepareCloseL(const RMmfIpcMessage& /*aMessage*/)
sl@0
  1484
	{
sl@0
  1485
	TBool complete = iAdapter->CloseDevSound();
sl@0
  1486
	if(!complete)
sl@0
  1487
		{
sl@0
  1488
		iOperationCompletePending = ETrue;	
sl@0
  1489
		}
sl@0
  1490
	return complete;
sl@0
  1491
	}
sl@0
  1492
sl@0
  1493
sl@0
  1494
TBool CMMFDevSoundSession::DoCustomCommandL(const RMmfIpcMessage& aMessage)
sl@0
  1495
	{
sl@0
  1496
	TInt retVal = KErrNone;
sl@0
  1497
	TRAPD(err, retVal = iDeMuxUtility->ProcessCustomInterfaceCommandL(aMessage));
sl@0
  1498
	if (err != KErrNone)
sl@0
  1499
		{
sl@0
  1500
		// the framework left with an error condition
sl@0
  1501
		// so we complete the message with this error
sl@0
  1502
		// irrespective of whether its a Sync or Async custom command
sl@0
  1503
		aMessage.Complete(err);
sl@0
  1504
		}
sl@0
  1505
	else
sl@0
  1506
		{
sl@0
  1507
		TInt messageType = aMessage.Function();
sl@0
  1508
		if ((messageType == EMMFDevSoundProxySyncCustomCommand) ||
sl@0
  1509
			(messageType == EMMFDevSoundProxySyncCustomCommandResult))
sl@0
  1510
			{
sl@0
  1511
			// If its a sync custom command
sl@0
  1512
			// we can pass back valid values here since command
sl@0
  1513
			// has been handled by the DeMux framework
sl@0
  1514
			aMessage.Complete(retVal);	
sl@0
  1515
			}
sl@0
  1516
		}
sl@0
  1517
	
sl@0
  1518
	// we complete our own message so don't need the framework to do so
sl@0
  1519
	return EFalse;
sl@0
  1520
	}
sl@0
  1521
	
sl@0
  1522
sl@0
  1523
//
sl@0
  1524
// CMMFDevSoundSession::CMMFDevSoundSession
sl@0
  1525
// (other items were commented in a header).
sl@0
  1526
//
sl@0
  1527
CMMFDevSoundSession::CMMFDevSoundSession() :
sl@0
  1528
	iSetClientConfigApplied (EFalse),
sl@0
  1529
	iDisconnecting (EFalse)
sl@0
  1530
	{
sl@0
  1531
	}
sl@0
  1532
sl@0
  1533
//
sl@0
  1534
// CMMFDevSoundSession::~CMMFDevSoundSession
sl@0
  1535
// (other items were commented in a header).
sl@0
  1536
//
sl@0
  1537
CMMFDevSoundSession::~CMMFDevSoundSession()
sl@0
  1538
	{
sl@0
  1539
	delete iAsyncQueueStart;
sl@0
  1540
	// clear the array of custom interfaces
sl@0
  1541
	TInt count = iCustomInterfaceArray.Count();
sl@0
  1542
	for (TInt i = 0; i < count; i++)
sl@0
  1543
		{
sl@0
  1544
		// we could have already deleted interfaces without
sl@0
  1545
		// removing them from the array so check for this
sl@0
  1546
		// and only delete release plugin if non-null
sl@0
  1547
		MMMFDevSoundCustomInterfaceDeMuxPlugin* ptr = iCustomInterfaceArray[i].iInterface;
sl@0
  1548
		if (ptr)
sl@0
  1549
			{
sl@0
  1550
			iCustomInterfaceArray[i].iInterface->Release();	
sl@0
  1551
			}
sl@0
  1552
		}
sl@0
  1553
	iCustomInterfaceArray.Reset();
sl@0
  1554
	iCustomInterfaceArray.Close();
sl@0
  1555
		
sl@0
  1556
	delete iDeMuxUtility;
sl@0
  1557
	
sl@0
  1558
	if (iCIExtension)
sl@0
  1559
		{
sl@0
  1560
		iCIExtension->Release();
sl@0
  1561
		iCIExtension = NULL;
sl@0
  1562
		}
sl@0
  1563
sl@0
  1564
	iMsgQueue.Close();
sl@0
  1565
	iArray.Close();
sl@0
  1566
	iQueuedRequests.Close();
sl@0
  1567
	delete iDtmfString;
sl@0
  1568
	delete iToneSeqBuf;
sl@0
  1569
	delete iAdapter;
sl@0
  1570
	delete iClosingWait;
sl@0
  1571
sl@0
  1572
	CMMFDevSoundServer* server =
sl@0
  1573
			const_cast<CMMFDevSoundServer*>(
sl@0
  1574
			static_cast<const CMMFDevSoundServer*>(Server()));
sl@0
  1575
sl@0
  1576
	if (server)
sl@0
  1577
		{
sl@0
  1578
		server->DecrementSessionId();
sl@0
  1579
		}
sl@0
  1580
sl@0
  1581
//	delete iCustomCommandParserManager;
sl@0
  1582
//	delete iMMFObjectContainer;
sl@0
  1583
sl@0
  1584
	// Close chunk
sl@0
  1585
	iChunk.Close();
sl@0
  1586
	}
sl@0
  1587
sl@0
  1588
//
sl@0
  1589
// CMMFDevSoundSession::FlushEventQueue()
sl@0
  1590
//
sl@0
  1591
void CMMFDevSoundSession::FlushEventQueue()
sl@0
  1592
	{
sl@0
  1593
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::FlushEventQueue - Enter"));
sl@0
  1594
    if(iMsgQueue.Handle() != 0)
sl@0
  1595
		{
sl@0
  1596
		TMMFDevSoundQueueItem queueItem;
sl@0
  1597
		TInt err = KErrNone;
sl@0
  1598
		while(err != KErrUnderflow)
sl@0
  1599
			{
sl@0
  1600
			err = iMsgQueue.Receive(queueItem);
sl@0
  1601
			}
sl@0
  1602
		}
sl@0
  1603
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::FlushEventQueue - Exit"));
sl@0
  1604
	}
sl@0
  1605
sl@0
  1606
void CMMFDevSoundSession::FilterQueueEvent(TMMFDevSoundProxyRequest aRequest)
sl@0
  1607
	{
sl@0
  1608
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::FilterQueueEvent - Enter"));
sl@0
  1609
    if(iMsgQueue.Handle() != 0)
sl@0
  1610
		{
sl@0
  1611
		// Pop and push events result at the queue 
sl@0
  1612
		// can be seen as "circular list"
sl@0
  1613
		// set a mark to traverse it safely 
sl@0
  1614
		TMMFDevSoundQueueItem markItem;
sl@0
  1615
		markItem.iRequest = EMMFDevSoundProxyMarkEvent;
sl@0
  1616
		// assumes sufficient space in the queue
sl@0
  1617
		TInt err = iMsgQueue.Send(markItem);
sl@0
  1618
		__ASSERT_DEBUG(err == KErrNone, Panic(EMsgQueueFailedToSendMsg));
sl@0
  1619
		
sl@0
  1620
		while(ETrue)
sl@0
  1621
			{
sl@0
  1622
			// At least the markEvent is at the queue so ignore the error
sl@0
  1623
			TMMFDevSoundQueueItem queueItem;
sl@0
  1624
			err = iMsgQueue.Receive(queueItem);
sl@0
  1625
			if(queueItem.iRequest == EMMFDevSoundProxyMarkEvent)
sl@0
  1626
				{
sl@0
  1627
				break;
sl@0
  1628
				}
sl@0
  1629
			// Look for the specific event
sl@0
  1630
			else if(queueItem.iRequest != aRequest)
sl@0
  1631
				{
sl@0
  1632
				// assumes sufficient space in the queue
sl@0
  1633
				err = iMsgQueue.Send(queueItem);
sl@0
  1634
				}
sl@0
  1635
			}
sl@0
  1636
		}
sl@0
  1637
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::FilterQueueEvent - Exit"));
sl@0
  1638
	}
sl@0
  1639
sl@0
  1640
//
sl@0
  1641
// CMMFDevSoundSession::Disconnect
sl@0
  1642
// (other items were commented in a header).
sl@0
  1643
//
sl@0
  1644
void CMMFDevSoundSession::Disconnect(const RMessage2& aMessage)
sl@0
  1645
	{
sl@0
  1646
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::Disconnect - Enter"));
sl@0
  1647
    iDisconnecting = ETrue;
sl@0
  1648
	
sl@0
  1649
    if (NeedToQueue())
sl@0
  1650
        {
sl@0
  1651
        // if we are in the middle of something, enqueue and wait
sl@0
  1652
        SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::Disconnect - Add to queue"));
sl@0
  1653
        EnqueueRequest(aMessage);
sl@0
  1654
        iClosingWait->Start();
sl@0
  1655
        }
sl@0
  1656
    else
sl@0
  1657
        {
sl@0
  1658
        // else do now. Enter ActiveSchedulerWait to wait for AsyncOpComplete
sl@0
  1659
        TBool complete = iAdapter->CloseDevSound();
sl@0
  1660
        if(!complete)
sl@0
  1661
            {
sl@0
  1662
            iRequestBeingServiced.SetMessage(aMessage);
sl@0
  1663
            iOperationCompletePending = ETrue;
sl@0
  1664
            ResetNotifiedError();
sl@0
  1665
            iClosingWait->Start();
sl@0
  1666
            }
sl@0
  1667
        }
sl@0
  1668
	CSession2::Disconnect(aMessage);
sl@0
  1669
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::Disconnect - Exit"));
sl@0
  1670
	}
sl@0
  1671
sl@0
  1672
sl@0
  1673
//
sl@0
  1674
// CMMFDevSoundSession::NewL
sl@0
  1675
// (other items were commented in a header).
sl@0
  1676
//
sl@0
  1677
CMMFDevSoundSession* CMMFDevSoundSession::NewL(MGlobalProperties& aGlobalProperties)
sl@0
  1678
	{
sl@0
  1679
	CMMFDevSoundSession* self = new (ELeave) CMMFDevSoundSession;
sl@0
  1680
	CleanupStack::PushL(self);
sl@0
  1681
	self->ConstructL(aGlobalProperties);
sl@0
  1682
	CleanupStack::Pop(self);
sl@0
  1683
	return self;
sl@0
  1684
	}
sl@0
  1685
sl@0
  1686
//
sl@0
  1687
// CMMFDevSoundSession::ConstructL
sl@0
  1688
// (other items were commented in a header).
sl@0
  1689
//
sl@0
  1690
void CMMFDevSoundSession::ConstructL(MGlobalProperties& aGlobalProperties)
sl@0
  1691
	{
sl@0
  1692
	iAdapter = CMMFDevSoundAdaptation::NewL(*this, aGlobalProperties);
sl@0
  1693
sl@0
  1694
	iClosingWait = new(ELeave) CActiveSchedulerWait();
sl@0
  1695
	
sl@0
  1696
	// Create the Custom Interface DeMux Utility
sl@0
  1697
	iDeMuxUtility = CMMFDevSoundCIDeMuxUtility::NewL(this);
sl@0
  1698
	
sl@0
  1699
	// Create the Custom Interface extension
sl@0
  1700
	TUid implUid = {KMmfUidCIServerExtensionImpl};
sl@0
  1701
	TInt uidAsInteger = implUid.iUid;
sl@0
  1702
	const TInt KCIExtTempBufferSize = 20;
sl@0
  1703
	TBuf8<KCIExtTempBufferSize> tempBuffer;
sl@0
  1704
	tempBuffer.Num(uidAsInteger, EHex);
sl@0
  1705
	TUid interfaceUid = {KUidDevSoundCIServerExtension};
sl@0
  1706
	TUid destructorKey;
sl@0
  1707
	TRAPD(err, iCIExtension = static_cast<MDevSoundCIServerExtension*>
sl@0
  1708
		 (MmPluginUtils::CreateImplementationL(interfaceUid, destructorKey, tempBuffer, KRomOnlyResolverUid)));
sl@0
  1709
	if (KErrNotSupported == err)
sl@0
  1710
		{
sl@0
  1711
		iCIExtension = NULL;
sl@0
  1712
		}
sl@0
  1713
	else
sl@0
  1714
		{
sl@0
  1715
		User::LeaveIfError(err);
sl@0
  1716
		}
sl@0
  1717
	if (iCIExtension)
sl@0
  1718
		{
sl@0
  1719
		// Extension exists. Complete the setup
sl@0
  1720
		iCIExtension->PassDestructorKey(destructorKey);
sl@0
  1721
		User::LeaveIfError(iCIExtension->Setup(*this));
sl@0
  1722
		}
sl@0
  1723
sl@0
  1724
	iQueuedRequests.ReserveL(KMaxQueueRequest);
sl@0
  1725
	iAsyncQueueStart = new (ELeave) CAsyncCallBack(CActive::EPriorityStandard);
sl@0
  1726
	TCallBack asyncCallback(AsyncQueueStartCallback, this);
sl@0
  1727
	iAsyncQueueStart->Set(asyncCallback);
sl@0
  1728
	}
sl@0
  1729
sl@0
  1730
// CMMFDevSoundSession::InitializeComplete
sl@0
  1731
// (other items were commented in a header).
sl@0
  1732
//
sl@0
  1733
void CMMFDevSoundSession::InitializeComplete(TInt aError)
sl@0
  1734
	{
sl@0
  1735
	// this may be a re-initialization and so we need to
sl@0
  1736
	// re-get our custom interfaces on the DeMux plugins
sl@0
  1737
	TInt count = iCustomInterfaceArray.Count();
sl@0
  1738
	for (TInt i = 0; i < count; i++)
sl@0
  1739
		{
sl@0
  1740
		// we could have already deleted interfaces without
sl@0
  1741
		// removing them from the array so check for this
sl@0
  1742
		// and only refresh plugin if non-null
sl@0
  1743
		MMMFDevSoundCustomInterfaceDeMuxPlugin* ptr = iCustomInterfaceArray[i].iInterface;
sl@0
  1744
		if (ptr)
sl@0
  1745
			{
sl@0
  1746
			// we can't keep track of..
sl@0
  1747
			// 1. where a custom interface is implemented
sl@0
  1748
			// 2. the uid of the custom interface to be refreshed
sl@0
  1749
			// so assume all have to be refreshed
sl@0
  1750
			TRAPD(err, ptr->RefreshL());	
sl@0
  1751
			
sl@0
  1752
			// Error indicates this is no longer a valid interface
sl@0
  1753
			if (err != KErrNone)
sl@0
  1754
				{
sl@0
  1755
				TMMFEvent event;
sl@0
  1756
				TMMFDevSoundQueueItem item;
sl@0
  1757
				item.iRequest = EMMFDevSoundCustomCommandCloseMuxDemuxPair;
sl@0
  1758
				item.iErrorCode = err;
sl@0
  1759
				event.iEventType.iUid = i+1;
sl@0
  1760
				item.iEventPckg() = event;
sl@0
  1761
				TInt lErr = iMsgQueue.Send(item);
sl@0
  1762
				__ASSERT_DEBUG(lErr == KErrNone, Panic(EMsgQueueFailedToSendMsg));
sl@0
  1763
sl@0
  1764
// NB proper panic code required here for this part.
sl@0
  1765
				}
sl@0
  1766
			}
sl@0
  1767
		}
sl@0
  1768
	TMMFDevSoundQueueItem item;
sl@0
  1769
	item.iRequest = EMMFDevSoundProxyICEvent;
sl@0
  1770
	item.iErrorCode = aError;
sl@0
  1771
	// assumes sufficient space in the queue so ignores the return value
sl@0
  1772
	iMsgQueue.Send(item); 
sl@0
  1773
	}
sl@0
  1774
sl@0
  1775
// 
sl@0
  1776
// CMMFDevSoundSession::ToneFinished
sl@0
  1777
// (other items were commented in a header).
sl@0
  1778
//
sl@0
  1779
void CMMFDevSoundSession::ToneFinished(TInt aError)
sl@0
  1780
	{
sl@0
  1781
    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::ToneFinished - Enter. Error [%d]"), aError);
sl@0
  1782
    TMMFDevSoundQueueItem item;
sl@0
  1783
	item.iRequest = EMMFDevSoundProxyTFEvent;
sl@0
  1784
	item.iErrorCode = aError;
sl@0
  1785
	// assumes sufficient space in the queue so ignores the return value
sl@0
  1786
	iMsgQueue.Send(item);
sl@0
  1787
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::ToneFinished - Exit"));
sl@0
  1788
	}
sl@0
  1789
sl@0
  1790
//
sl@0
  1791
// CMMFDevSoundSession::BufferToBeFilled
sl@0
  1792
// (other items were commented in a header).
sl@0
  1793
//
sl@0
  1794
void CMMFDevSoundSession::BufferToBeFilled(CMMFBuffer* aBuffer)
sl@0
  1795
	{
sl@0
  1796
	SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::BufferToBeFilled - Enter"));
sl@0
  1797
sl@0
  1798
	// Set play error flag to false 
sl@0
  1799
	iPlayErrorOccured = EFalse;
sl@0
  1800
sl@0
  1801
	// Store pointer to the buffer to use it later with PlayData
sl@0
  1802
	iBufferPlay = reinterpret_cast<CMMFDataBuffer*>(aBuffer);
sl@0
  1803
	TInt status = CreateChunk(iHwBufPckgFill, iBufferPlay->RequestSize());
sl@0
  1804
	iHwBufPckgFill().iRequestSize = iBufferPlay->RequestSize();
sl@0
  1805
	iHwBufPckgFill().iBufferSize = iBufferPlay->Data().MaxLength();
sl@0
  1806
	iHwBufPckgFill().iLastBuffer = iBufferPlay->LastBuffer();
sl@0
  1807
	TMMFDevSoundQueueItem queueItem;
sl@0
  1808
	if ( status != KErrNone )
sl@0
  1809
		{
sl@0
  1810
		BufferErrorEvent();
sl@0
  1811
		PlayError(status);
sl@0
  1812
		}
sl@0
  1813
	else
sl@0
  1814
		{
sl@0
  1815
		queueItem.iRequest = EMMFDevSoundProxyBTBFEvent;
sl@0
  1816
		// assumes sufficient space in the queue so ignores the return value
sl@0
  1817
		status = iMsgQueue.Send(queueItem);
sl@0
  1818
		}
sl@0
  1819
sl@0
  1820
	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::BufferToBeFilled - Exit [%d]"), status);
sl@0
  1821
	}
sl@0
  1822
sl@0
  1823
//
sl@0
  1824
// CMMFDevSoundSession::PlayError
sl@0
  1825
// (other items were commented in a header).
sl@0
  1826
//
sl@0
  1827
void CMMFDevSoundSession::PlayError(TInt aError)
sl@0
  1828
	{
sl@0
  1829
    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::PlayError - Enter [%d]"), aError);
sl@0
  1830
sl@0
  1831
	// Set play error flag to ignore following PlayData requests
sl@0
  1832
	iPlayErrorOccured = ETrue;
sl@0
  1833
sl@0
  1834
	TMMFDevSoundQueueItem item;
sl@0
  1835
	item.iRequest = EMMFDevSoundProxyPEEvent;
sl@0
  1836
	item.iErrorCode = aError;
sl@0
  1837
	iChunk.Close();
sl@0
  1838
	// assumes sufficient space in the queue so ignores the return value
sl@0
  1839
	iMsgQueue.Send(item);
sl@0
  1840
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PlayError - Exit"));
sl@0
  1841
	}
sl@0
  1842
sl@0
  1843
//
sl@0
  1844
// CMMFDevSoundSession::BufferToBeEmptied
sl@0
  1845
// (other items were commented in a header).
sl@0
  1846
//
sl@0
  1847
void CMMFDevSoundSession::BufferToBeEmptied(CMMFBuffer* aBuffer)
sl@0
  1848
	{
sl@0
  1849
	// Store pointer to the buffer to use it later with RecordData
sl@0
  1850
	iBufferRecord = reinterpret_cast<CMMFDataBuffer*>(aBuffer);
sl@0
  1851
	TInt status = CreateChunk(iHwBufPckgEmpty, iBufferRecord->RequestSize());
sl@0
  1852
	
sl@0
  1853
	if ( status != KErrNone )
sl@0
  1854
		{
sl@0
  1855
		BufferErrorEvent();
sl@0
  1856
		RecordError(status);
sl@0
  1857
		}
sl@0
  1858
	else
sl@0
  1859
		{
sl@0
  1860
		iHwBufPckgEmpty().iRequestSize = iBufferRecord->RequestSize();
sl@0
  1861
		iHwBufPckgEmpty().iBufferSize = iBufferRecord->Data().MaxLength();
sl@0
  1862
		iHwBufPckgEmpty().iLastBuffer = iBufferRecord->LastBuffer();
sl@0
  1863
		//copy the data into the chunk    
sl@0
  1864
		Mem::Copy(iChunk.Base(),iBufferRecord->Data().Ptr(),iBufferRecord->RequestSize());
sl@0
  1865
	    TMMFDevSoundQueueItem queueItem;
sl@0
  1866
		queueItem.iRequest = EMMFDevSoundProxyBTBEEvent;
sl@0
  1867
		// assumes sufficient space in the queue so ignores the return value
sl@0
  1868
		iMsgQueue.Send(queueItem);
sl@0
  1869
		}
sl@0
  1870
	}
sl@0
  1871
sl@0
  1872
// CMMFDevSoundSession::RecordError
sl@0
  1873
// (other items were commented in a header).
sl@0
  1874
//
sl@0
  1875
void CMMFDevSoundSession::RecordError(TInt aError)
sl@0
  1876
	{
sl@0
  1877
	SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::Record Error [%d]"), aError);
sl@0
  1878
	TMMFDevSoundQueueItem item;
sl@0
  1879
	item.iRequest = EMMFDevSoundProxyREEvent;
sl@0
  1880
	item.iErrorCode = aError;
sl@0
  1881
	iChunk.Close();
sl@0
  1882
	// assumes sufficient space in the queue so ignores the return value
sl@0
  1883
	iMsgQueue.Send(item);
sl@0
  1884
	}
sl@0
  1885
sl@0
  1886
//
sl@0
  1887
// CMMFDevSoundSession::DeviceMessage
sl@0
  1888
// (other items were commented in a header).
sl@0
  1889
//
sl@0
  1890
void CMMFDevSoundSession::DeviceMessage(TUid /*aMessageType*/,
sl@0
  1891
									const TDesC8& /*aMsg*/)
sl@0
  1892
	{
sl@0
  1893
	// Not used
sl@0
  1894
	}
sl@0
  1895
sl@0
  1896
void CMMFDevSoundSession::InterfaceDeleted(TUid aInterfaceId)
sl@0
  1897
	{
sl@0
  1898
	MMMFDevSoundCustomInterfaceDeMuxPlugin* ptr = InterfaceFromUid(aInterfaceId);
sl@0
  1899
	if (ptr == NULL)
sl@0
  1900
		{
sl@0
  1901
		// Not found
sl@0
  1902
		return;
sl@0
  1903
		}
sl@0
  1904
	TRAPD(err, ptr->RefreshL());
sl@0
  1905
	if (err != KErrNone)
sl@0
  1906
		{
sl@0
  1907
		// Refresh failed, so tear down Mux/DeMux pair
sl@0
  1908
		TMMFEvent event;
sl@0
  1909
		TMMFDevSoundQueueItem item;
sl@0
  1910
		item.iRequest = EMMFDevSoundCustomCommandCloseMuxDemuxPair;
sl@0
  1911
		item.iErrorCode = err;
sl@0
  1912
		event.iEventType = aInterfaceId;
sl@0
  1913
		item.iEventPckg() = event;
sl@0
  1914
		iMsgQueue.Send(item);
sl@0
  1915
		}
sl@0
  1916
	}
sl@0
  1917
sl@0
  1918
//
sl@0
  1919
// CMMFDevSoundSession::CallbackFromAdaptorReceived
sl@0
  1920
// (other items were commented in a header).
sl@0
  1921
//
sl@0
  1922
void CMMFDevSoundSession::CallbackFromAdaptorReceived(TInt aType, TInt aError)
sl@0
  1923
	{
sl@0
  1924
    SYMBIAN_DEBPRN2(_L("CMMFDevSoundSession[0x%x]::CallbackFromAdaptorReceived - Enter. Type[%d] Error[%d]"), aType, aError);
sl@0
  1925
	if(aType == KCallbackRecordPauseComplete)
sl@0
  1926
		{
sl@0
  1927
		TMMFDevSoundQueueItem item;
sl@0
  1928
		item.iRequest = EMMFDevSoundProxyPausedRecordCompleteEvent;
sl@0
  1929
		item.iErrorCode = KErrNone;
sl@0
  1930
		TInt status = iMsgQueue.Send(item);
sl@0
  1931
		}
sl@0
  1932
	else if(aType == KCallbackAutoPauseResume)
sl@0
  1933
		{
sl@0
  1934
		TMMFEvent event;
sl@0
  1935
		event.iErrorCode = KErrNone;
sl@0
  1936
		event.iEventType = KMMFEventCategoryAudioResourceAvailable;
sl@0
  1937
		SendEventToClient(event);
sl@0
  1938
		//coverity[uninit_use_in_call]
sl@0
  1939
		// Disabled Coverity warning, since it complains about iReserved1 member in TMMFEvent being uninitialised
sl@0
  1940
		}
sl@0
  1941
	else if (aType == KCallbackFlushComplete)
sl@0
  1942
		{
sl@0
  1943
		if(!iHandlingExtdCI && iRequestBeingServiced.Function()==EMMFDevSoundProxyEmptyBuffers)
sl@0
  1944
			{
sl@0
  1945
			//If we come here then it is due to a EMMFDevSoundProxyEmptyBuffers request from client.
sl@0
  1946
			SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::CallbackFromAdaptorReceived - Calling TMMFDevSoundRequest::Complete on iRequestBeingServiced"));
sl@0
  1947
		    iRequestBeingServiced.Complete(aError);
sl@0
  1948
		    iOperationCompletePending = EFalse;
sl@0
  1949
			}
sl@0
  1950
		}
sl@0
  1951
	else
sl@0
  1952
		{
sl@0
  1953
		if( NeedToQueue() )
sl@0
  1954
			{
sl@0
  1955
			// If not possible to service now, then queue request
sl@0
  1956
			// Encapsule the request
sl@0
  1957
			TMMFDevSoundRequest request(aType);
sl@0
  1958
			// assumes sufficient space in the queue so ignores the return value
sl@0
  1959
			iQueuedRequests.Insert(request, 0);
sl@0
  1960
			}
sl@0
  1961
		else
sl@0
  1962
			{
sl@0
  1963
			// If there is no oustanding operation service inmediately
sl@0
  1964
			if (aType == KCallbackProcessingFinished)
sl@0
  1965
				{
sl@0
  1966
				DoProcessingFinished();
sl@0
  1967
				}
sl@0
  1968
			else if(aType == KCallbackProcessingUnitError)
sl@0
  1969
				{
sl@0
  1970
				DoProcessingError();
sl@0
  1971
				}
sl@0
  1972
			}
sl@0
  1973
		}
sl@0
  1974
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::CallbackFromAdaptorReceived - Exit"));
sl@0
  1975
	}
sl@0
  1976
sl@0
  1977
sl@0
  1978
//
sl@0
  1979
// CMMFDevSoundSession::PreemptionStartedCallbackReceived
sl@0
  1980
// (other items were commented in a header).
sl@0
  1981
//
sl@0
  1982
void CMMFDevSoundSession::PreemptionStartedCallbackReceived()
sl@0
  1983
	{
sl@0
  1984
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PreemptionStartedCallbackReceived - Enter"));
sl@0
  1985
    // Solution: Enqueue any request that arrives before preemption is completed
sl@0
  1986
	iOperationCompletePending = ETrue;
sl@0
  1987
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PreemptionStartedCallbackReceived - Exit"));
sl@0
  1988
	}
sl@0
  1989
sl@0
  1990
//
sl@0
  1991
// CMMFDevSoundSession::PreemptionFinishedCallbackReceived
sl@0
  1992
// (other items were commented in a header).
sl@0
  1993
//
sl@0
  1994
void CMMFDevSoundSession::PreemptionFinishedCallbackReceived(TBool aCanStartNewOperation)
sl@0
  1995
	{
sl@0
  1996
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PreemptionFinishedCallbackReceived - Enter"));
sl@0
  1997
    if (iHandlingExtdCI)
sl@0
  1998
        {
sl@0
  1999
        // we are in the middle of handling a CI, so ignore - will handle later when unwinding
sl@0
  2000
        SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PreemptionFinishedCallbackReceived - Exit. Exiting from if block for CI"));
sl@0
  2001
		return;
sl@0
  2002
        }
sl@0
  2003
	iOperationCompletePending = EFalse;
sl@0
  2004
	if ( aCanStartNewOperation && iQueuedRequests.Count() != 0 )
sl@0
  2005
		{
sl@0
  2006
		DequeueRequest();
sl@0
  2007
		}
sl@0
  2008
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::PreemptionFinishedCallbackReceived - Exit"));
sl@0
  2009
	}
sl@0
  2010
sl@0
  2011
//
sl@0
  2012
// CMMFDevSoundSession::PreemptionClash
sl@0
  2013
// (other items were commented in a header).
sl@0
  2014
//
sl@0
  2015
void CMMFDevSoundSession::PreemptionClash()
sl@0
  2016
	{
sl@0
  2017
	//assumes sufficient space in the queue so ignore the return value
sl@0
  2018
	iQueuedRequests.Insert(iRequestBeingServiced, 0);
sl@0
  2019
	iPreemptionClash=ETrue;
sl@0
  2020
	}
sl@0
  2021
sl@0
  2022
//
sl@0
  2023
// CMMFDevSoundSession::PreemptionClashWithStateChange
sl@0
  2024
// (other items were commented in a header).
sl@0
  2025
//
sl@0
  2026
void CMMFDevSoundSession::PreemptionClashWithStateChange()
sl@0
  2027
	{
sl@0
  2028
	#ifdef _DEBUG
sl@0
  2029
		TMMFDevSoundRequest msg = iQueuedRequests[0];
sl@0
  2030
		// message being removed should be the one we previously pushed via PreemptionClash()
sl@0
  2031
		__ASSERT_DEBUG(iRequestBeingServiced==msg, Panic(ERequestBeingServicedMismatch));
sl@0
  2032
	#endif
sl@0
  2033
	// remove without processing request with AsynchronousOperationComplete() completing the message
sl@0
  2034
	iQueuedRequests.Remove(0);
sl@0
  2035
	iPreemptionClash=EFalse;
sl@0
  2036
	}
sl@0
  2037
sl@0
  2038
//
sl@0
  2039
// CMMFDevSoundSession::AdaptorControlsContext()
sl@0
  2040
//
sl@0
  2041
sl@0
  2042
TBool CMMFDevSoundSession::AdaptorControlsContext() const
sl@0
  2043
    {
sl@0
  2044
    return !iHandlingExtdCI;
sl@0
  2045
    }
sl@0
  2046
sl@0
  2047
MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFDevSoundSession::InterfaceFromUid(TUid aUid)
sl@0
  2048
	{
sl@0
  2049
	TInt count = iCustomInterfaceArray.Count();
sl@0
  2050
	TInt id = aUid.iUid;
sl@0
  2051
	MMMFDevSoundCustomInterfaceDeMuxPlugin* interface = NULL;
sl@0
  2052
	for (TInt i = 0; i < count; i++)
sl@0
  2053
		{
sl@0
  2054
		if (id == iCustomInterfaceArray[i].iId.iUid)
sl@0
  2055
			{
sl@0
  2056
			interface = iCustomInterfaceArray[i].iInterface;
sl@0
  2057
			break;
sl@0
  2058
			}
sl@0
  2059
		}
sl@0
  2060
	return interface;
sl@0
  2061
	}
sl@0
  2062
sl@0
  2063
//
sl@0
  2064
// CMMFDevSoundSession::SendEventToClient
sl@0
  2065
// (other items were commented in a header).
sl@0
  2066
//
sl@0
  2067
void CMMFDevSoundSession::SendEventToClient(const TMMFEvent& aEvent)
sl@0
  2068
	{
sl@0
  2069
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::SendEventToClient - Enter"));
sl@0
  2070
    TMMFDevSoundQueueItem item;
sl@0
  2071
	item.iRequest = EMMFDevSoundProxySETCEvent;
sl@0
  2072
	item.iErrorCode = KErrNone;
sl@0
  2073
	item.iEventPckg() = aEvent;
sl@0
  2074
	// assumes sufficient space in the queue so ignores the return value
sl@0
  2075
	TInt err = iMsgQueue.Send(item);
sl@0
  2076
    __ASSERT_DEBUG(err == KErrNone, Panic(EMsgQueueFailedToSendMsg));
sl@0
  2077
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::SendEventToClient - Exit"));
sl@0
  2078
	}
sl@0
  2079
sl@0
  2080
void CMMFDevSoundSession::AsynchronousOperationComplete(TInt aError, TBool aCanStartNewOperation)
sl@0
  2081
	{
sl@0
  2082
    __ASSERT_DEBUG(!iHandlingExtdCI, Panic(EUnexpectedAsyncOpCompleteHandlingCI));
sl@0
  2083
        // when handling CIs we should not reach here
sl@0
  2084
sl@0
  2085
    TInt error = aError;
sl@0
  2086
    if (!error)
sl@0
  2087
        {
sl@0
  2088
        // if have no error payload, use notified error. It will be KErrNone if not set, so just use.
sl@0
  2089
        error = NotifiedError();
sl@0
  2090
        }
sl@0
  2091
sl@0
  2092
	switch (iRequestBeingServiced.Type())
sl@0
  2093
		{
sl@0
  2094
		case TMMFDevSoundRequest::ESessionEvents:
sl@0
  2095
			{
sl@0
  2096
			SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x] ==== ClosingDueException ==== "));
sl@0
  2097
			iOperationCompletePending = EFalse;
sl@0
  2098
			if(iClosingWait->IsStarted())
sl@0
  2099
				{
sl@0
  2100
				iClosingWait->AsyncStop();
sl@0
  2101
				}
sl@0
  2102
			return;
sl@0
  2103
			}
sl@0
  2104
		// Complete the message for asynchronous requests
sl@0
  2105
		case TMMFDevSoundRequest::EConfigure_Asynchronous:
sl@0
  2106
		case TMMFDevSoundRequest::EAction_Asynchronous:
sl@0
  2107
		case TMMFDevSoundRequest::EQuery_Asynchronous:
sl@0
  2108
		case TMMFDevSoundRequest::ECustomInterfacesRelated:
sl@0
  2109
			{
sl@0
  2110
			if(iOperationCompletePending && aCanStartNewOperation)
sl@0
  2111
				{
sl@0
  2112
				if (iRequestBeingServiced.Function()==EMMFDevSoundProxyStop)
sl@0
  2113
					{
sl@0
  2114
					// flush the queue - will have removed any stale items added between initial call and MMRC's reaction
sl@0
  2115
                    FlushQueuedRequests();
sl@0
  2116
					FlushEventQueue();
sl@0
  2117
					iChunk.Close();
sl@0
  2118
					}
sl@0
  2119
					
sl@0
  2120
				if(iRequestBeingServiced.Function()==EMMFDevSoundProxyCapabilities)
sl@0
  2121
					{
sl@0
  2122
					TMMFDevSoundProxySettings devSoundSet;
sl@0
  2123
					devSoundSet.iCaps = iDevSoundCapabilities;
sl@0
  2124
					TMMFDevSoundProxySettingsPckg pckg(devSoundSet);
sl@0
  2125
					MessageWrite(iRequestBeingServiced.Message(),TInt(2),pckg);
sl@0
  2126
					}
sl@0
  2127
				
sl@0
  2128
				if(iRequestBeingServiced.Function()==EMMFDevSoundProxyCancelInitialize)
sl@0
  2129
					{
sl@0
  2130
					FlushEventQueue();
sl@0
  2131
					}
sl@0
  2132
				
sl@0
  2133
				iRequestBeingServiced.Complete(error);
sl@0
  2134
				iOperationCompletePending = EFalse;
sl@0
  2135
				}
sl@0
  2136
			}
sl@0
  2137
			break;
sl@0
  2138
		case TMMFDevSoundRequest::EAction_PseudoAsynchronous:
sl@0
  2139
			{
sl@0
  2140
			if(iOperationCompletePending && aCanStartNewOperation)
sl@0
  2141
				{
sl@0
  2142
				iOperationCompletePending = EFalse;
sl@0
  2143
				}
sl@0
  2144
			}
sl@0
  2145
			break;
sl@0
  2146
		case TMMFDevSoundRequest::EQuery_Synchronous:
sl@0
  2147
		case TMMFDevSoundRequest::EConfigure_Synchronous:
sl@0
  2148
		case TMMFDevSoundRequest::EBufferExchangeRelated:
sl@0
  2149
			break;
sl@0
  2150
		case TMMFDevSoundRequest::ECallBackType:
sl@0
  2151
			{
sl@0
  2152
			if(iOperationCompletePending && aCanStartNewOperation)
sl@0
  2153
				{
sl@0
  2154
				iOperationCompletePending = EFalse;
sl@0
  2155
				}	
sl@0
  2156
			}
sl@0
  2157
			break;
sl@0
  2158
		default:
sl@0
  2159
			break;
sl@0
  2160
		}
sl@0
  2161
	
sl@0
  2162
	if(iRequestBeingServiced.Type() == TMMFDevSoundRequest::ECallBackType )
sl@0
  2163
	    {	    
sl@0
  2164
	    SYMBIAN_DEBPRN2(_L("CMMFDevSoundSession[0x%x] AsynchronousOperationComplete CallbackPF=%d pending=%d"),
sl@0
  2165
	            iRequestBeingServiced.IsCallBack(), iOperationCompletePending );
sl@0
  2166
	    }
sl@0
  2167
	else
sl@0
  2168
	    {
sl@0
  2169
	    SYMBIAN_DEBPRN3(_L("CMMFDevSoundSession[0x%x] AsynchronousOperationComplete %x pending=%d Requestype=%d"),
sl@0
  2170
	            iRequestBeingServiced.Function(), iOperationCompletePending, iRequestBeingServiced.Type() );
sl@0
  2171
	    }
sl@0
  2172
sl@0
  2173
	    
sl@0
  2174
	if ( aCanStartNewOperation && iQueuedRequests.Count() != 0 )
sl@0
  2175
		{
sl@0
  2176
		DequeueRequest();
sl@0
  2177
		}
sl@0
  2178
	}
sl@0
  2179
sl@0
  2180
void CMMFDevSoundSession::DequeueRequest()
sl@0
  2181
	{
sl@0
  2182
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DequeueRequest - Enter"));
sl@0
  2183
    iAsyncQueueStart->Cancel(); // if we're in here cancel any background request
sl@0
  2184
sl@0
  2185
	TMMFDevSoundRequest msg = iQueuedRequests[0];
sl@0
  2186
sl@0
  2187
	if (msg.IsCallBack() > 0)
sl@0
  2188
		{
sl@0
  2189
		iRequestBeingServiced.SetMessageCallback();
sl@0
  2190
		//Call iPf function
sl@0
  2191
		SYMBIAN_DEBPRN0(_L("\n CMMFDevSoundSession[0x%x] ======== Service a queued request\n"));
sl@0
  2192
		if (msg.IsCallBack() == KCallbackProcessingFinished)
sl@0
  2193
			{
sl@0
  2194
			iQueuedRequests.Remove(0);
sl@0
  2195
			DoProcessingFinished();
sl@0
  2196
			}
sl@0
  2197
		else if(msg.IsCallBack() == KCallbackProcessingUnitError)
sl@0
  2198
		    {
sl@0
  2199
		    iQueuedRequests.Remove(0);
sl@0
  2200
		    DoProcessingError();
sl@0
  2201
		    }
sl@0
  2202
sl@0
  2203
		}
sl@0
  2204
sl@0
  2205
	if (iQueuedRequests.Count()>0)
sl@0
  2206
		{
sl@0
  2207
		// Some rules about what request can be followed
sl@0
  2208
		SYMBIAN_DEBPRN0(_L("\n CMMFDevSoundSession[0x%x]======== Flag can service new request\n"));
sl@0
  2209
		iAsyncQueueStart->CallBack();
sl@0
  2210
		}
sl@0
  2211
	SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::DequeueRequest - Exit"));
sl@0
  2212
	}
sl@0
  2213
	
sl@0
  2214
// 	AsyncQueueStartCallback
sl@0
  2215
sl@0
  2216
sl@0
  2217
TInt CMMFDevSoundSession::AsyncQueueStartCallback(TAny* aPtr)
sl@0
  2218
	{
sl@0
  2219
	CMMFDevSoundSession* self = static_cast<CMMFDevSoundSession*>(aPtr);
sl@0
  2220
	self->AsyncQueueStartCallback();
sl@0
  2221
	return KErrNone;
sl@0
  2222
	}
sl@0
  2223
	
sl@0
  2224
void CMMFDevSoundSession::AsyncQueueStartCallback()
sl@0
  2225
	{
sl@0
  2226
	SYMBIAN_DEBPRN0(_L("\n CMMFDevSoundSession[0x%x]======== Service a queued request\n"));
sl@0
  2227
	TMMFDevSoundRequest msg = iQueuedRequests[0];
sl@0
  2228
	iQueuedRequests.Remove(0);
sl@0
  2229
	TInt err = KErrNone;
sl@0
  2230
	TBool doRequest = ETrue;
sl@0
  2231
	if(iPreemptionClash)
sl@0
  2232
		{
sl@0
  2233
		SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::AsyncQueueStartCallback - Re-applying client request due to Pre-emption clash"));
sl@0
  2234
		iPreemptionClash=EFalse; // clear flag before reading next request in queue
sl@0
  2235
		iAdapter->RollbackAdaptorActiveStateToBeforeCommit();
sl@0
  2236
		if ((iRequestBeingServiced.Type() == TMMFDevSoundRequest::EAction_PseudoAsynchronous))
sl@0
  2237
			{
sl@0
  2238
		    doRequest = EFalse;
sl@0
  2239
		    HandleAlreadyCompletedRequest();
sl@0
  2240
			}
sl@0
  2241
		}
sl@0
  2242
sl@0
  2243
	if (doRequest)
sl@0
  2244
		{
sl@0
  2245
		TRAP(err,DoServiceRequestL(msg.Message()));
sl@0
  2246
		if(err != KErrNone)
sl@0
  2247
			{
sl@0
  2248
			msg.Complete(err);
sl@0
  2249
			}
sl@0
  2250
		}
sl@0
  2251
sl@0
  2252
	if (!iOperationCompletePending && iQueuedRequests.Count() != 0)
sl@0
  2253
		{
sl@0
  2254
		//dequeue next
sl@0
  2255
		DequeueRequest();
sl@0
  2256
		}
sl@0
  2257
	}
sl@0
  2258
sl@0
  2259
// CMMFDevSoundSession::CustomInterface()
sl@0
  2260
// Returns a pointer reference to custom interface implementation returned by
sl@0
  2261
// adaptation::CustomInterface method.
sl@0
  2262
// Note this method is called indirectly by CI server-side plugins - both DeMux and 
sl@0
  2263
// CIServerExtension call this variously via MMMFDevSoundCustomInterfaceTarget or MCustomInterface 
sl@0
  2264
//
sl@0
  2265
TAny* CMMFDevSoundSession::CustomInterface(TUid aInterfaceId)
sl@0
  2266
	{
sl@0
  2267
	TInt err = DoSetClientConfig(); // if required, this will connect to MMRC etc
sl@0
  2268
	if (err)
sl@0
  2269
		{
sl@0
  2270
		return NULL; // on any error, return NULL - not much more we can do
sl@0
  2271
		}
sl@0
  2272
	return iAdapter->CustomInterface(aInterfaceId);
sl@0
  2273
	}
sl@0
  2274
sl@0
  2275
//
sl@0
  2276
// CMMFDevSoundSession::DoProcessingFinished()
sl@0
  2277
//
sl@0
  2278
void CMMFDevSoundSession::DoProcessingFinished()
sl@0
  2279
	{
sl@0
  2280
    ResetNotifiedError();
sl@0
  2281
sl@0
  2282
	TBool asyncOperation = EFalse;
sl@0
  2283
	//ProcessingFinished should never fail
sl@0
  2284
	__ASSERT_ALWAYS(KErrNone, iAdapter->ProcessingFinishedReceived(asyncOperation));
sl@0
  2285
	iOperationCompletePending = asyncOperation;
sl@0
  2286
	if (iOperationCompletePending)
sl@0
  2287
		{
sl@0
  2288
		iRequestBeingServiced.SetMessageCallback();
sl@0
  2289
		}
sl@0
  2290
	}
sl@0
  2291
sl@0
  2292
//
sl@0
  2293
// CMMFDevSoundSession::DoProcessingError()
sl@0
  2294
//
sl@0
  2295
void CMMFDevSoundSession::DoProcessingError()
sl@0
  2296
    {
sl@0
  2297
    ResetNotifiedError();
sl@0
  2298
sl@0
  2299
    TBool asyncOperation = EFalse;
sl@0
  2300
    //ProcessingFinished should never fail
sl@0
  2301
    __ASSERT_ALWAYS(KErrNone, iAdapter->ProcessingError(asyncOperation));
sl@0
  2302
    iOperationCompletePending = asyncOperation;
sl@0
  2303
    if (iOperationCompletePending)
sl@0
  2304
        {
sl@0
  2305
        iRequestBeingServiced.SetMessageCallback();
sl@0
  2306
        }
sl@0
  2307
    }
sl@0
  2308
sl@0
  2309
//
sl@0
  2310
// CMMFDevSoundSession::DoSetClientConfigL()
sl@0
  2311
// Sets client configuration information to Adaptation.
sl@0
  2312
//
sl@0
  2313
TInt CMMFDevSoundSession::DoSetClientConfig()
sl@0
  2314
	{
sl@0
  2315
	TInt err = KErrNone;
sl@0
  2316
	if(!iSetClientConfigApplied)
sl@0
  2317
		{
sl@0
  2318
		CMMFDevSoundServer* server =
sl@0
  2319
			const_cast<CMMFDevSoundServer*>(
sl@0
  2320
				static_cast<const CMMFDevSoundServer*>(Server()));
sl@0
  2321
			
sl@0
  2322
		ASSERT(server); // session should always have a server!
sl@0
  2323
		
sl@0
  2324
		TProcessId actualProcessId = server->ActualProcessId();
sl@0
  2325
		TProcessId processId = server->ProcessId();
sl@0
  2326
		
sl@0
  2327
		if (actualProcessId!=processId)
sl@0
  2328
		    {
sl@0
  2329
            // we have a differing actual process id, so pass that to the adaptor too
sl@0
  2330
            err = iAdapter->SetClientConfig(actualProcessId, processId);
sl@0
  2331
		    }
sl@0
  2332
		else
sl@0
  2333
		    {
sl@0
  2334
            err = iAdapter->SetClientConfig(processId);
sl@0
  2335
		    }
sl@0
  2336
sl@0
  2337
		if (!err)
sl@0
  2338
			{
sl@0
  2339
			iSetClientConfigApplied = ETrue;
sl@0
  2340
			}
sl@0
  2341
		}
sl@0
  2342
	return err;
sl@0
  2343
	}
sl@0
  2344
sl@0
  2345
// CMMFDevSoundSession::DoSetClientConfigL()
sl@0
  2346
// Sets client configuration information to Adaptation.
sl@0
  2347
//
sl@0
  2348
void CMMFDevSoundSession::DoSetClientConfigL()
sl@0
  2349
	{
sl@0
  2350
	User::LeaveIfError(DoSetClientConfig());
sl@0
  2351
	}
sl@0
  2352
sl@0
  2353
// 
sl@0
  2354
// CMMFDevSoundSession::CreateChunk()
sl@0
  2355
// Requests kernel to create global RChunk
sl@0
  2356
// 
sl@0
  2357
TInt CMMFDevSoundSession::CreateChunk(TMMFDevSoundProxyHwBufPckg& aBufPckg, TInt aRequestedSize)
sl@0
  2358
	{
sl@0
  2359
	TInt status(KErrNone);
sl@0
  2360
	
sl@0
  2361
	if ( iChunk.Handle() )
sl@0
  2362
		{
sl@0
  2363
		// If the DevSound Adaptation component requests a buffer size
sl@0
  2364
		// that can fit into current chunk's size, then re-use chunk.
sl@0
  2365
		if ( aRequestedSize <= iChunk.Size() )
sl@0
  2366
			{
sl@0
  2367
			if (iForceSendOfChunkHandle)
sl@0
  2368
				{
sl@0
  2369
				iForceSendOfChunkHandle = EFalse;
sl@0
  2370
				aBufPckg().iChunkOp = EOpen;
sl@0
  2371
				}
sl@0
  2372
			else
sl@0
  2373
				{
sl@0
  2374
				aBufPckg().iChunkOp = ENull;
sl@0
  2375
				}
sl@0
  2376
			return status;
sl@0
  2377
			}
sl@0
  2378
		// The new request size exceeds the current chunk's area, close it. We
sl@0
  2379
		// will be creating new one in the following sequences. Note we could
sl@0
  2380
		// try to Adjust() the chunk, and see if the existing chunk could be
sl@0
  2381
		// extended instead, but this is assumed too rare an event for this 
sl@0
  2382
		// optimisation
sl@0
  2383
		else
sl@0
  2384
			{
sl@0
  2385
			iChunk.Close();
sl@0
  2386
			}
sl@0
  2387
		}
sl@0
  2388
	
sl@0
  2389
	// Request kernel to create global RChunk if needed
sl@0
  2390
	if ( !iChunk.Handle() )
sl@0
  2391
		{
sl@0
  2392
		status = iChunk.CreateGlobal(KNullDesC, aRequestedSize, aRequestedSize, EOwnerThread);
sl@0
  2393
		if ( status == KErrNone )
sl@0
  2394
			{
sl@0
  2395
			aBufPckg().iChunkOp = EOpen;
sl@0
  2396
			}
sl@0
  2397
		else
sl@0
  2398
			{
sl@0
  2399
			aBufPckg().iChunkOp = ENull;
sl@0
  2400
			}
sl@0
  2401
		}
sl@0
  2402
	iForceSendOfChunkHandle = EFalse;
sl@0
  2403
	return status;
sl@0
  2404
	}
sl@0
  2405
sl@0
  2406
sl@0
  2407
// Custom Interface //
sl@0
  2408
TInt CMMFDevSoundSession::DoOpenSlaveL(TUid aInterface, const TDesC8& aPackageBuf)
sl@0
  2409
	{
sl@0
  2410
	// it shouldn't be necessary to check if we have already instantiated this
sl@0
  2411
	// interface since the client would already know - however this is something
sl@0
  2412
	// that a licensee could implement if they required additional functionality
sl@0
  2413
	// e.g. many : 1 mappings between client and DevSound.
sl@0
  2414
sl@0
  2415
	MMMFDevSoundCustomInterfaceDeMuxPlugin* ptr = NULL;
sl@0
  2416
		
sl@0
  2417
	// try and instantiate a plugin tunnelling
sl@0
  2418
	// pair to support this Custom Interface
sl@0
  2419
	ptr = iDeMuxUtility->CreateCustomInterfaceDeMuxL(aInterface);
sl@0
  2420
	
sl@0
  2421
	TInt handle = KNullHandle;
sl@0
  2422
	
sl@0
  2423
	if (ptr)
sl@0
  2424
		{
sl@0
  2425
		TMMFDevSoundCustomInterfaceDeMuxData data;
sl@0
  2426
		data.iInterface = ptr;
sl@0
  2427
		data.iId = aInterface;
sl@0
  2428
			
sl@0
  2429
		CleanupReleasePushL(*ptr);
sl@0
  2430
			
sl@0
  2431
		// setup demux plugin
sl@0
  2432
		ptr->SetInterfaceTarget(this);
sl@0
  2433
			
sl@0
  2434
		// try and open interface
sl@0
  2435
		// this will fetch the interface from the svr implementation
sl@0
  2436
		ptr->DoOpenSlaveL(aInterface, aPackageBuf);
sl@0
  2437
		User::LeaveIfError(iCustomInterfaceArray.Append(data));
sl@0
  2438
			
sl@0
  2439
		CleanupStack::Pop();	// ptr
sl@0
  2440
			
sl@0
  2441
		handle = iCustomInterfaceArray.Count();
sl@0
  2442
		return handle;
sl@0
  2443
		}
sl@0
  2444
sl@0
  2445
	// we couldn't set up the interface correctly so return a NULL
sl@0
  2446
	// handle to the client
sl@0
  2447
	return KNullHandle;
sl@0
  2448
	}
sl@0
  2449
	
sl@0
  2450
void CMMFDevSoundSession::DoCloseSlaveL(TInt aHandle)
sl@0
  2451
	{
sl@0
  2452
	if (aHandle==KNullHandle)
sl@0
  2453
		{
sl@0
  2454
		// null-handle -> NOP
sl@0
  2455
		return;
sl@0
  2456
		}
sl@0
  2457
		
sl@0
  2458
	if (aHandle<KNullHandle || aHandle > iCustomInterfaceArray.Count())
sl@0
  2459
		{
sl@0
  2460
		// handle out of range - should not happen, but leave to show error
sl@0
  2461
		User::Leave(KErrBadHandle);
sl@0
  2462
		}
sl@0
  2463
		
sl@0
  2464
	TMMFDevSoundCustomInterfaceDeMuxData& data = iCustomInterfaceArray[aHandle-1];
sl@0
  2465
	
sl@0
  2466
	// close and delete the plugin
sl@0
  2467
	MMMFDevSoundCustomInterfaceDeMuxPlugin* ptr = data.iInterface;
sl@0
  2468
	ptr->DoCloseSlaveL(aHandle);
sl@0
  2469
	ptr->Release();
sl@0
  2470
	
sl@0
  2471
	// clear the entry
sl@0
  2472
	data.iInterface = NULL;
sl@0
  2473
	data.iId.iUid = 0;
sl@0
  2474
	}
sl@0
  2475
	
sl@0
  2476
TInt CMMFDevSoundSession::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
sl@0
  2477
	{
sl@0
  2478
	// use the demux utility to get the handle
sl@0
  2479
	TMMFDevSoundCIMessageData data;
sl@0
  2480
	iDeMuxUtility->GetSyncMessageDataL(aMessage, data);
sl@0
  2481
	
sl@0
  2482
	TInt handle = data.iHandle;
sl@0
  2483
	
sl@0
  2484
	if ((handle <= 0) || (handle > (iCustomInterfaceArray.Count())))
sl@0
  2485
		{
sl@0
  2486
		
sl@0
  2487
		User::Leave(KErrBadHandle);
sl@0
  2488
		}
sl@0
  2489
	
sl@0
  2490
	// call on demux plugin
sl@0
  2491
	return iCustomInterfaceArray[handle-1].iInterface->DoSendSlaveSyncCommandL(aMessage);	
sl@0
  2492
	}
sl@0
  2493
	
sl@0
  2494
TInt CMMFDevSoundSession::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)
sl@0
  2495
	{
sl@0
  2496
	// use the demux utility to get the handle
sl@0
  2497
	TMMFDevSoundCIMessageData data;
sl@0
  2498
	iDeMuxUtility->GetSyncMessageDataL(aMessage, data);
sl@0
  2499
	
sl@0
  2500
	TInt handle = data.iHandle;
sl@0
  2501
	
sl@0
  2502
	if ((handle <= 0) || (handle > (iCustomInterfaceArray.Count())))
sl@0
  2503
		{
sl@0
  2504
		
sl@0
  2505
		User::Leave(KErrBadHandle);
sl@0
  2506
		}
sl@0
  2507
	
sl@0
  2508
	// call on demux plugin
sl@0
  2509
	return iCustomInterfaceArray[handle-1].iInterface->DoSendSlaveSyncCommandResultL(aMessage);	
sl@0
  2510
	}
sl@0
  2511
	
sl@0
  2512
void CMMFDevSoundSession::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& aMessage)
sl@0
  2513
	{
sl@0
  2514
	// use the demux utility to get the handle
sl@0
  2515
	TMMFDevSoundCIMessageData data;
sl@0
  2516
	iDeMuxUtility->GetAsyncMessageDataL(aMessage, data);
sl@0
  2517
	
sl@0
  2518
	TInt handle = data.iHandle;
sl@0
  2519
	
sl@0
  2520
	if ((handle <= 0) || (handle > (iCustomInterfaceArray.Count())))
sl@0
  2521
		{
sl@0
  2522
		User::Leave(KErrBadHandle);
sl@0
  2523
		}
sl@0
  2524
	
sl@0
  2525
	// call on demux plugin
sl@0
  2526
	iCustomInterfaceArray[handle-1].iInterface->DoSendSlaveAsyncCommandL(aMessage);	
sl@0
  2527
	}
sl@0
  2528
	
sl@0
  2529
void CMMFDevSoundSession::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& aMessage)
sl@0
  2530
	{
sl@0
  2531
	// use the demux utility to get the handle
sl@0
  2532
	TMMFDevSoundCIMessageData data;
sl@0
  2533
	iDeMuxUtility->GetAsyncMessageDataL(aMessage, data);
sl@0
  2534
	
sl@0
  2535
	TInt handle = data.iHandle;
sl@0
  2536
	
sl@0
  2537
	if ((handle <= 0) || (handle > (iCustomInterfaceArray.Count())))
sl@0
  2538
		{
sl@0
  2539
		User::Leave(KErrBadHandle);
sl@0
  2540
		}
sl@0
  2541
	
sl@0
  2542
	// call on demux plugin
sl@0
  2543
	iCustomInterfaceArray[handle-1].iInterface->DoSendSlaveAsyncCommandResultL(aMessage);	
sl@0
  2544
	}
sl@0
  2545
sl@0
  2546
sl@0
  2547
TBool CMMFDevSoundSession::DoRegisterAsClientL(const RMmfIpcMessage& aMessage)
sl@0
  2548
	{
sl@0
  2549
	TMMFDevSoundProxySettingsPckg buf;
sl@0
  2550
	User::LeaveIfError(MessageRead(aMessage,0,buf));
sl@0
  2551
	HBufC8* notificationRegistrationData = NULL;
sl@0
  2552
	notificationRegistrationData = HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLengthL(1)));
sl@0
  2553
	TPtr8 dataPtr(notificationRegistrationData->Des());  	
sl@0
  2554
	User::LeaveIfError(MessageRead(aMessage,1,dataPtr));
sl@0
  2555
	DoSetClientConfigL();// added here instead of the CreateL()
sl@0
  2556
	TInt err = KErrNone;
sl@0
  2557
	err = iAdapter->RegisterAsClient(buf().iNotificationEventUid,dataPtr);
sl@0
  2558
	CleanupStack::PopAndDestroy(1); // Notification Registeration data
sl@0
  2559
	if (err != KErrNone)
sl@0
  2560
		{
sl@0
  2561
		aMessage.Complete(err);
sl@0
  2562
		return EFalse;		
sl@0
  2563
		}
sl@0
  2564
	return ETrue;
sl@0
  2565
	}
sl@0
  2566
	
sl@0
  2567
TBool CMMFDevSoundSession::DoCancelRegisterAsClientL(const RMmfIpcMessage& aMessage)
sl@0
  2568
	{
sl@0
  2569
	TMMFDevSoundProxySettingsPckg buf;
sl@0
  2570
	User::LeaveIfError(MessageRead(aMessage,0,buf));
sl@0
  2571
	TInt err = KErrNone;
sl@0
  2572
	err = iAdapter->CancelRegisterAsClient(buf().iNotificationEventUid);
sl@0
  2573
	if (err != KErrNone)
sl@0
  2574
		{
sl@0
  2575
		aMessage.Complete(err);
sl@0
  2576
		return EFalse;		
sl@0
  2577
		}
sl@0
  2578
	return ETrue;
sl@0
  2579
	}
sl@0
  2580
sl@0
  2581
TBool CMMFDevSoundSession::DoGetResourceNotificationDataL(const RMmfIpcMessage& aMessage)
sl@0
  2582
	{
sl@0
  2583
	TMMFDevSoundProxySettingsPckg buf;
sl@0
  2584
	User::LeaveIfError(MessageRead(aMessage,0,buf));
sl@0
  2585
	HBufC8* notificationData = NULL;
sl@0
  2586
	notificationData = HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesMaxLengthL(2)));
sl@0
  2587
	TPtr8 dataPtr(notificationData->Des());  	
sl@0
  2588
	User::LeaveIfError(MessageRead(aMessage,2,dataPtr));
sl@0
  2589
	TInt err = KErrNone;
sl@0
  2590
	err = iAdapter->GetResourceNotificationData(buf().iNotificationEventUid,dataPtr);
sl@0
  2591
	User::LeaveIfError(MessageWrite(aMessage,2,*notificationData));
sl@0
  2592
	CleanupStack::PopAndDestroy(1); // Notification data
sl@0
  2593
	if (err != KErrNone)
sl@0
  2594
		{
sl@0
  2595
		aMessage.Complete(err);
sl@0
  2596
		return EFalse;		
sl@0
  2597
		}
sl@0
  2598
	return ETrue;
sl@0
  2599
	}
sl@0
  2600
sl@0
  2601
TBool CMMFDevSoundSession::DoWillResumePlayL(const RMmfIpcMessage& aMessage)
sl@0
  2602
	{
sl@0
  2603
	TInt err = KErrNone;
sl@0
  2604
	err = iAdapter->WillResumePlay();
sl@0
  2605
	if (err != KErrNone)
sl@0
  2606
		{
sl@0
  2607
		aMessage.Complete(err);
sl@0
  2608
		return EFalse;		
sl@0
  2609
		}
sl@0
  2610
	return ETrue;
sl@0
  2611
	}
sl@0
  2612
sl@0
  2613
TBool CMMFDevSoundSession::DoSetClientThreadInfoL(const RMmfIpcMessage& aMessage)
sl@0
  2614
	{
sl@0
  2615
	if(!iSetClientConfigApplied)
sl@0
  2616
		{
sl@0
  2617
		if (aMessage.HasCapability(ECapabilityMultimediaDD) && aMessage.HasCapability(ECapabilityUserEnvironment))
sl@0
  2618
			{
sl@0
  2619
			TPckgBuf<TThreadId> threadId;
sl@0
  2620
			User::LeaveIfError(MessageRead(aMessage, 1, threadId));
sl@0
  2621
			
sl@0
  2622
			CMMFDevSoundServer* server = 
sl@0
  2623
				const_cast<CMMFDevSoundServer*>(static_cast<const CMMFDevSoundServer*>(Server()));
sl@0
  2624
			server->SetClientProcessIdL(threadId()); 
sl@0
  2625
			}
sl@0
  2626
		else
sl@0
  2627
			{
sl@0
  2628
			User::Leave(KErrPermissionDenied);
sl@0
  2629
			}
sl@0
  2630
		}
sl@0
  2631
	else
sl@0
  2632
		{
sl@0
  2633
		User::Leave(KErrNotReady);
sl@0
  2634
		}
sl@0
  2635
	return ETrue;
sl@0
  2636
	}
sl@0
  2637
	
sl@0
  2638
void CMMFDevSoundSession::Panic(TMMFDevSoundSessionPanicCodes aCode)
sl@0
  2639
	{
sl@0
  2640
    User::Panic(KMMFDevSoundSessionPanicCategory, aCode);
sl@0
  2641
	}
sl@0
  2642
sl@0
  2643
void CMMFDevSoundSession::BufferErrorEvent()
sl@0
  2644
	{
sl@0
  2645
	// this will generate an processing error event and callback
sl@0
  2646
	iAdapter->BufferErrorEvent();
sl@0
  2647
	}
sl@0
  2648
sl@0
  2649
void CMMFDevSoundSession::FlushQueuedRequests()
sl@0
  2650
    {
sl@0
  2651
    for (TInt queueIndex = (iQueuedRequests.Count() - 1); queueIndex >= 0; --queueIndex)
sl@0
  2652
        {
sl@0
  2653
        if ((iQueuedRequests[queueIndex].Type() == TMMFDevSoundRequest::ESessionEvents) && 
sl@0
  2654
                (iQueuedRequests[queueIndex].Function() == RMessage2::EDisConnect))
sl@0
  2655
            {
sl@0
  2656
            continue;
sl@0
  2657
            }
sl@0
  2658
        iQueuedRequests.Remove(queueIndex);
sl@0
  2659
        }    
sl@0
  2660
    }
sl@0
  2661
sl@0
  2662
TInt CMMFDevSoundSession::MessageRead(const RMmfIpcMessage& aMessage, TInt aParam, TDes8& aResult)
sl@0
  2663
    {
sl@0
  2664
    if (!iDisconnecting)
sl@0
  2665
        {
sl@0
  2666
        return MmfMessageUtil::Read(aMessage, aParam, aResult);    
sl@0
  2667
        }
sl@0
  2668
    return KErrBadHandle;
sl@0
  2669
    }
sl@0
  2670
sl@0
  2671
TInt CMMFDevSoundSession::MessageRead(const RMmfIpcMessage& aMessage, TInt aParam, TDes16& aResult)
sl@0
  2672
    {
sl@0
  2673
    if (!iDisconnecting)
sl@0
  2674
        {
sl@0
  2675
        return aMessage.Read(aParam, aResult);    
sl@0
  2676
        }
sl@0
  2677
    return KErrBadHandle;
sl@0
  2678
    }
sl@0
  2679
sl@0
  2680
TInt CMMFDevSoundSession::MessageWrite(const RMmfIpcMessage& aMessage, TInt aParam, const TDesC8& aValue)
sl@0
  2681
    {
sl@0
  2682
    if (!iDisconnecting)
sl@0
  2683
        {
sl@0
  2684
        return MmfMessageUtil::Write(aMessage, aParam, aValue);
sl@0
  2685
        }
sl@0
  2686
    return KErrBadHandle;
sl@0
  2687
    }
sl@0
  2688
sl@0
  2689
void CMMFDevSoundSession::ResetNotifiedError()
sl@0
  2690
// called at beginning of commit cycle, so any error will be from callbacks
sl@0
  2691
    {
sl@0
  2692
    SYMBIAN_DEBPRN0(_L("CMMFDevSoundSession[0x%x]::ResetNotifiedError"));
sl@0
  2693
    iNotifiedError = KErrNone;
sl@0
  2694
    }
sl@0
  2695
sl@0
  2696
TInt CMMFDevSoundSession::NotifiedError() const
sl@0
  2697
// NotifiedError property
sl@0
  2698
    {
sl@0
  2699
    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::NotifiedError(%d)"), iNotifiedError);
sl@0
  2700
    return iNotifiedError;
sl@0
  2701
    }
sl@0
  2702
sl@0
  2703
void CMMFDevSoundSession::NotifyError(TInt aError)
sl@0
  2704
// cache notified error
sl@0
  2705
    {
sl@0
  2706
    SYMBIAN_DEBPRN1(_L("CMMFDevSoundSession[0x%x]::NotifyError(%d)"), aError);
sl@0
  2707
    iNotifiedError = aError;
sl@0
  2708
    }
sl@0
  2709
sl@0
  2710
// End of file