os/mm/devsound/a3fdevsound/src/mmfaudioserver/mmfaudioserver.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
//mmfaudioserver.cpp
sl@0
     2
sl@0
     3
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     4
// All rights reserved.
sl@0
     5
// This component and the accompanying materials are made available
sl@0
     6
// under the terms of "Eclipse Public License v1.0"
sl@0
     7
// which accompanies this distribution, and is available
sl@0
     8
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     9
//
sl@0
    10
// Initial Contributors:
sl@0
    11
// Nokia Corporation - initial contribution.
sl@0
    12
//
sl@0
    13
// Contributors:
sl@0
    14
//
sl@0
    15
// Description:
sl@0
    16
// Portions Copyright Nokia-Symbian * Nokia Core OS *
sl@0
    17
// INCLUDE FILES
sl@0
    18
//
sl@0
    19
sl@0
    20
#include <e32math.h>
sl@0
    21
#include <mmf/common/mmfbase.hrh>
sl@0
    22
sl@0
    23
#include "mmfaudioserver.h"
sl@0
    24
#include "mmfaudioserverdecs.h"
sl@0
    25
#include "mmfdevsoundsession.h"
sl@0
    26
#include "mmfaudioserversession.h"
sl@0
    27
#include "mmfdevsoundserver.h"
sl@0
    28
#include "mmfdevsoundserverstart.h"
sl@0
    29
#include "mmfaudioserverfactory.h"
sl@0
    30
#include "devsoundsvrthreadpriorityconsts.h"
sl@0
    31
sl@0
    32
#ifdef _DEBUG
sl@0
    33
#include "e32debug.h"
sl@0
    34
#define SYMBIAN_DEBPRN0(str)    RDebug::Print(str, this)
sl@0
    35
#else
sl@0
    36
#define SYMBIAN_DEBPRN0(str)
sl@0
    37
#endif //_DEBUG
sl@0
    38
sl@0
    39
sl@0
    40
// Time delay that the audio server wait before shutdown itself when is detected that the last DevSoundSession is closed
sl@0
    41
const TInt KAudioServerShutDownDelay = 50000000; //50 sec
sl@0
    42
sl@0
    43
// ======== LOCAL FUNCTIONS ========
sl@0
    44
sl@0
    45
void Panic(TInt aPanicCode)
sl@0
    46
	{
sl@0
    47
	_LIT(KAudioServerPanicCategory, "mmfaudioserver");
sl@0
    48
	User::Panic(KAudioServerPanicCategory, aPanicCode);
sl@0
    49
	}
sl@0
    50
sl@0
    51
// ============================ MEMBER FUNCTIONS ===============================
sl@0
    52
sl@0
    53
// -----------------------------------------------------------------------------
sl@0
    54
// CMMFAudioServer::NewL
sl@0
    55
// Two-phased constructor.
sl@0
    56
// -----------------------------------------------------------------------------
sl@0
    57
//
sl@0
    58
CMMFAudioServer* CMMFAudioServer::NewL()
sl@0
    59
	{
sl@0
    60
	CMMFAudioServer* self = new(ELeave) CMMFAudioServer();
sl@0
    61
	CleanupStack::PushL(self);
sl@0
    62
	self->ConstructL();
sl@0
    63
	CleanupStack::Pop(self);
sl@0
    64
	return self;
sl@0
    65
	}
sl@0
    66
sl@0
    67
// -----------------------------------------------------------------------------
sl@0
    68
// CMMFAudioServer::CMMFAudioServer
sl@0
    69
// C++ default constructor can NOT contain any code, that
sl@0
    70
// might leave.
sl@0
    71
// -----------------------------------------------------------------------------
sl@0
    72
//
sl@0
    73
CMMFAudioServer::CMMFAudioServer()
sl@0
    74
	: CMmfIpcServer(EPriorityStandard)
sl@0
    75
	{
sl@0
    76
	}
sl@0
    77
sl@0
    78
// -----------------------------------------------------------------------------
sl@0
    79
// CMMFAudioServer::ConstructL
sl@0
    80
// Symbian 2nd phase constructor can leave.
sl@0
    81
// -----------------------------------------------------------------------------
sl@0
    82
//
sl@0
    83
void CMMFAudioServer::ConstructL()
sl@0
    84
	{
sl@0
    85
	SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::ConstructL - enter"));
sl@0
    86
sl@0
    87
	SetPinClientDescriptors(ETrue);
sl@0
    88
	// Call base class to Start server
sl@0
    89
	StartL(KAudioServerName);
sl@0
    90
sl@0
    91
	iFourCCConvertor = CFourCCConvertor::NewL();
sl@0
    92
	iDelayAudioServerShutDown = CDelayAudioServerShutDown::NewL();
sl@0
    93
sl@0
    94
	iFactory = CMMFAudioServerFactory::NewL();
sl@0
    95
	iFactory->StartL(*this);	
sl@0
    96
sl@0
    97
	SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::ConstructL - exit"));
sl@0
    98
	}
sl@0
    99
sl@0
   100
// -----------------------------------------------------------------------------
sl@0
   101
// CMMFAudioServer::~CMMFAudioServer
sl@0
   102
// Destructor
sl@0
   103
// -----------------------------------------------------------------------------
sl@0
   104
//
sl@0
   105
CMMFAudioServer::~CMMFAudioServer()
sl@0
   106
	{
sl@0
   107
	if (iDelayAudioServerShutDown)
sl@0
   108
		{
sl@0
   109
		iDelayAudioServerShutDown->Cancel();
sl@0
   110
		delete iDelayAudioServerShutDown;
sl@0
   111
		iDelayAudioServerShutDown = NULL;
sl@0
   112
		}
sl@0
   113
sl@0
   114
	for(TInt i=(iDevSoundServList.Count()-1); i >=0 ; i--)
sl@0
   115
		{
sl@0
   116
		CStartAndMonitorDevSoundThread* devSoundMonitorThread = iDevSoundServList[i];
sl@0
   117
		iDevSoundServList.Remove(i);
sl@0
   118
		delete devSoundMonitorThread;
sl@0
   119
		}
sl@0
   120
	iDevSoundServList.Close();
sl@0
   121
	delete iFourCCConvertor;
sl@0
   122
	if (iFactory)
sl@0
   123
		{
sl@0
   124
		iFactory->Stop(*this);
sl@0
   125
		delete iFactory;
sl@0
   126
		}
sl@0
   127
	}
sl@0
   128
sl@0
   129
// -----------------------------------------------------------------------------
sl@0
   130
// CMMFAudioServer::NewSessionL
sl@0
   131
// Creates a new session to handle requests by the client and returns it to the
sl@0
   132
// client server framework.
sl@0
   133
// -----------------------------------------------------------------------------
sl@0
   134
//
sl@0
   135
CMmfIpcSession* CMMFAudioServer::NewSessionL(const TVersion& aVersion) const
sl@0
   136
	{
sl@0
   137
	SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::NewSessionL - enter"));
sl@0
   138
	
sl@0
   139
	TVersion v(KMMFAudioServerVersion,
sl@0
   140
			KMMFAudioServerMinorVersionNumber,
sl@0
   141
			KMMFAudioServerBuildVersionNumber);
sl@0
   142
	if(!User::QueryVersionSupported(v, aVersion))
sl@0
   143
		{
sl@0
   144
		User::Leave(KErrNotSupported);
sl@0
   145
		}
sl@0
   146
	
sl@0
   147
	for(TInt i=(iDevSoundServList.Count()-1); i >=0 ; i--)
sl@0
   148
		{
sl@0
   149
		CStartAndMonitorDevSoundThread* devSoundMonitorThread = iDevSoundServList[i];
sl@0
   150
sl@0
   151
		if(!devSoundMonitorThread->IsActive())
sl@0
   152
			{
sl@0
   153
			iDevSoundServList.Remove(i);
sl@0
   154
			delete devSoundMonitorThread;
sl@0
   155
			}
sl@0
   156
		iDevSoundServList.Compress();
sl@0
   157
		}
sl@0
   158
sl@0
   159
	RMMFDevSoundServerProxy devSoundSessionHandle;
sl@0
   160
	User::LeaveIfError(StartDevSoundServer(devSoundSessionHandle));
sl@0
   161
	CMMFAudioServerSession* audioServerSession = CMMFAudioServerSession::NewL(devSoundSessionHandle);
sl@0
   162
	SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::NewSessionL - session created"));
sl@0
   163
	return audioServerSession;
sl@0
   164
	}
sl@0
   165
sl@0
   166
// -----------------------------------------------------------------------------
sl@0
   167
// CMMFAudioServer::IncrementSessionId
sl@0
   168
// Increment the session Id.
sl@0
   169
// -----------------------------------------------------------------------------
sl@0
   170
//
sl@0
   171
void CMMFAudioServer::IncrementSessionId()
sl@0
   172
	{
sl@0
   173
	iAudioServerSessionId++;
sl@0
   174
	}
sl@0
   175
sl@0
   176
// -----------------------------------------------------------------------------
sl@0
   177
// CMMFAudioServer::DecrementSessionId
sl@0
   178
// Decrement the session Id.
sl@0
   179
// -----------------------------------------------------------------------------
sl@0
   180
//
sl@0
   181
void CMMFAudioServer::DecrementSessionId()
sl@0
   182
	{
sl@0
   183
	iAudioServerSessionId--;
sl@0
   184
	}
sl@0
   185
sl@0
   186
// -----------------------------------------------------------------------------
sl@0
   187
// CMMFAudioServer::IncrementDevSoundCount
sl@0
   188
// Increment the DevSound server counter. If there is atleast one DevSound
sl@0
   189
// server, it will cancel its shutdown timer.
sl@0
   190
// -----------------------------------------------------------------------------
sl@0
   191
//
sl@0
   192
void CMMFAudioServer::IncrementDevSoundCount()
sl@0
   193
	{
sl@0
   194
	iDevSoundCount++;
sl@0
   195
	//in the case we started the shutdown due to no more DevSound
sl@0
   196
	if(iDevSoundCount)
sl@0
   197
		{
sl@0
   198
		ASSERT(iDelayAudioServerShutDown);
sl@0
   199
		if (iDelayAudioServerShutDown)
sl@0
   200
			{
sl@0
   201
			iDelayAudioServerShutDown->Cancel();
sl@0
   202
			}
sl@0
   203
		}
sl@0
   204
	}
sl@0
   205
sl@0
   206
// -----------------------------------------------------------------------------
sl@0
   207
// CMMFAudioServer::DecrementDevSoundCount
sl@0
   208
// Decrement the DevSound server counter. Once the number of DevSound server's
sl@0
   209
// instances becomes zero, Audio Server will start its shutdown routine.
sl@0
   210
// -----------------------------------------------------------------------------
sl@0
   211
//
sl@0
   212
void CMMFAudioServer::DecrementDevSoundCount()
sl@0
   213
	{
sl@0
   214
	iDevSoundCount--;
sl@0
   215
	if (iDevSoundCount == 0)
sl@0
   216
		{
sl@0
   217
		ASSERT(iDelayAudioServerShutDown);
sl@0
   218
		if (iDelayAudioServerShutDown)
sl@0
   219
			{
sl@0
   220
			iDelayAudioServerShutDown->SetDelay(TTimeIntervalMicroSeconds32(KAudioServerShutDownDelay));
sl@0
   221
			}
sl@0
   222
		}
sl@0
   223
	}
sl@0
   224
sl@0
   225
// -----------------------------------------------------------------------------
sl@0
   226
// CMMFAudioServer::SendEventToClient
sl@0
   227
// Sends Event to DevSound client.
sl@0
   228
// -----------------------------------------------------------------------------
sl@0
   229
//
sl@0
   230
void CMMFAudioServer::SendEventToClient(TInt aSessionToAlert, TInt /*aSessionToBeLaunched*/)
sl@0
   231
	{
sl@0
   232
	// For the session requested, send event to client
sl@0
   233
	iSessionIter.SetToFirst();
sl@0
   234
	CMMFAudioServerSession* session = static_cast<CMMFAudioServerSession*>(iSessionIter++);
sl@0
   235
	while (session)
sl@0
   236
		{
sl@0
   237
		if (session->AudioServerSessionId() == aSessionToAlert)
sl@0
   238
			{
sl@0
   239
			break;  // Finished
sl@0
   240
			}
sl@0
   241
sl@0
   242
		session = static_cast<CMMFAudioServerSession*>(iSessionIter++);
sl@0
   243
		}
sl@0
   244
	}
sl@0
   245
sl@0
   246
// -----------------------------------------------------------------------------
sl@0
   247
// CMMFAudioServer::LaunchRequest
sl@0
   248
// Launches the DevSound servers waiting for Audio Policy.
sl@0
   249
// -----------------------------------------------------------------------------
sl@0
   250
//
sl@0
   251
void CMMFAudioServer::LaunchRequest(TInt aSessionId)
sl@0
   252
	{
sl@0
   253
	iSessionIter.SetToFirst();
sl@0
   254
	CMMFAudioServerSession* session = static_cast<CMMFAudioServerSession*>(iSessionIter++);
sl@0
   255
sl@0
   256
	while (session)
sl@0
   257
		{
sl@0
   258
		if (session->AudioServerSessionId() == aSessionId)
sl@0
   259
			{
sl@0
   260
			break;  // Finished
sl@0
   261
			}
sl@0
   262
		session = static_cast<CMMFAudioServerSession*>(iSessionIter++);
sl@0
   263
		}
sl@0
   264
	}
sl@0
   265
sl@0
   266
// -----------------------------------------------------------------------------
sl@0
   267
// CMMFAudioServer::StartDevSoundServer
sl@0
   268
// Starts a new DevSound server instance.
sl@0
   269
// -----------------------------------------------------------------------------
sl@0
   270
//
sl@0
   271
TInt CMMFAudioServer::StartDevSoundServer(RMMFDevSoundServerProxy& aDevSoundSessionHandle) const
sl@0
   272
	{
sl@0
   273
	SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::StartDevSoundServer - enter"));
sl@0
   274
sl@0
   275
	RMessage2 message(Message());
sl@0
   276
	CStartAndMonitorDevSoundThread* monitorDevSound = NULL;
sl@0
   277
sl@0
   278
	TRAPD(err, monitorDevSound = CStartAndMonitorDevSoundThread::NewL(const_cast<CMMFAudioServer*>(this)));
sl@0
   279
	if(err != KErrNone)
sl@0
   280
		{
sl@0
   281
		delete monitorDevSound;
sl@0
   282
		return err;
sl@0
   283
		}
sl@0
   284
sl@0
   285
	err = iDevSoundServList.Append(monitorDevSound);
sl@0
   286
	if(err != KErrNone)
sl@0
   287
		{
sl@0
   288
		delete monitorDevSound;
sl@0
   289
		return err;
sl@0
   290
		}
sl@0
   291
	
sl@0
   292
	SYMBIAN_DEBPRN0(_L("CMMFAudioServer[0x%x]::StartDevSoundServer - exit"));
sl@0
   293
	return monitorDevSound->StartDevSoundServer(message, aDevSoundSessionHandle);
sl@0
   294
sl@0
   295
	}
sl@0
   296
sl@0
   297
// -----------------------------------------------------------------------------
sl@0
   298
// CMMFAudioServer::CDelayAudioServerShutDown::NewL
sl@0
   299
// Two-phased constructor.
sl@0
   300
// -----------------------------------------------------------------------------
sl@0
   301
//
sl@0
   302
CMMFAudioServer::CDelayAudioServerShutDown*
sl@0
   303
CMMFAudioServer::CDelayAudioServerShutDown::NewL()
sl@0
   304
	{
sl@0
   305
	CDelayAudioServerShutDown* self = new(ELeave) CDelayAudioServerShutDown;
sl@0
   306
	CleanupStack::PushL(self);
sl@0
   307
	self->ConstructL();
sl@0
   308
	CleanupStack::Pop(self);
sl@0
   309
	return self;
sl@0
   310
	}
sl@0
   311
sl@0
   312
// -----------------------------------------------------------------------------
sl@0
   313
// Constructor.
sl@0
   314
// -----------------------------------------------------------------------------
sl@0
   315
//
sl@0
   316
CMMFAudioServer::CDelayAudioServerShutDown::CDelayAudioServerShutDown()
sl@0
   317
	: CActive(0)
sl@0
   318
	{
sl@0
   319
	}
sl@0
   320
sl@0
   321
// -----------------------------------------------------------------------------
sl@0
   322
// CMMFAudioServer::CDelayAudioServerShutDown::ConstructL
sl@0
   323
// -----------------------------------------------------------------------------
sl@0
   324
//
sl@0
   325
void CMMFAudioServer::CDelayAudioServerShutDown::ConstructL()
sl@0
   326
	{
sl@0
   327
	User::LeaveIfError(iShutDownTimer.CreateLocal());
sl@0
   328
	CActiveScheduler::Add(this);
sl@0
   329
	}
sl@0
   330
sl@0
   331
// -----------------------------------------------------------------------------
sl@0
   332
// CMMFAudioServer::CDelayAudioServerShutDown::~CDelayAudioServerShutDown
sl@0
   333
// -----------------------------------------------------------------------------
sl@0
   334
//
sl@0
   335
CMMFAudioServer::CDelayAudioServerShutDown::~CDelayAudioServerShutDown()
sl@0
   336
	{
sl@0
   337
	Cancel();
sl@0
   338
	iShutDownTimer.Close();
sl@0
   339
	}
sl@0
   340
sl@0
   341
// -----------------------------------------------------------------------------
sl@0
   342
// CMMFAudioServer::CDelayAudioServerShutDown::SetDelay
sl@0
   343
// Request a timeout after aDelay
sl@0
   344
// -----------------------------------------------------------------------------
sl@0
   345
//
sl@0
   346
void CMMFAudioServer::CDelayAudioServerShutDown::SetDelay(
sl@0
   347
	TTimeIntervalMicroSeconds32 aDelay)
sl@0
   348
	{
sl@0
   349
	__ASSERT_ALWAYS(!IsActive(), Panic(EMMFAudioServerIsActive));
sl@0
   350
	iShutDownTimer.After(iStatus, aDelay);
sl@0
   351
	SetActive();
sl@0
   352
	}
sl@0
   353
sl@0
   354
// -----------------------------------------------------------------------------
sl@0
   355
// CMMFAudioServer::CDelayAudioServerShutDown::RunL
sl@0
   356
// Called by Active object framework when timer times out.
sl@0
   357
// -----------------------------------------------------------------------------
sl@0
   358
//
sl@0
   359
void CMMFAudioServer::CDelayAudioServerShutDown::RunL()
sl@0
   360
	{
sl@0
   361
	CActiveScheduler::Stop();
sl@0
   362
	}
sl@0
   363
sl@0
   364
// -----------------------------------------------------------------------------
sl@0
   365
// CMMFAudioServer::CDelayAudioServerShutDown::DoCancel
sl@0
   366
// Called by the Active object framework when user cancels active object.
sl@0
   367
// -----------------------------------------------------------------------------
sl@0
   368
//
sl@0
   369
void CMMFAudioServer::CDelayAudioServerShutDown::DoCancel()
sl@0
   370
	{
sl@0
   371
	iShutDownTimer.Cancel();
sl@0
   372
	}
sl@0
   373
sl@0
   374
// -----------------------------------------------------------------------------
sl@0
   375
// CStartAndMonitorDevSoundThread::NewL
sl@0
   376
// -----------------------------------------------------------------------------
sl@0
   377
//
sl@0
   378
CStartAndMonitorDevSoundThread* CStartAndMonitorDevSoundThread::NewL(
sl@0
   379
	CMMFAudioServer* aAudioServer)
sl@0
   380
	{
sl@0
   381
	CStartAndMonitorDevSoundThread* self = new(ELeave) CStartAndMonitorDevSoundThread(aAudioServer);
sl@0
   382
	CleanupStack::PushL(self);
sl@0
   383
	self->ConstructL();
sl@0
   384
	CleanupStack::Pop(self);
sl@0
   385
	return self;
sl@0
   386
	}
sl@0
   387
sl@0
   388
// -----------------------------------------------------------------------------
sl@0
   389
// CStartAndMonitorDevSoundThread::ConstructL
sl@0
   390
// -----------------------------------------------------------------------------
sl@0
   391
//
sl@0
   392
void CStartAndMonitorDevSoundThread::ConstructL()
sl@0
   393
	{
sl@0
   394
	CActiveScheduler::Add(this);
sl@0
   395
	}
sl@0
   396
sl@0
   397
// -----------------------------------------------------------------------------
sl@0
   398
// CStartAndMonitorDevSoundThread::StartDevSoundServer
sl@0
   399
// Starts a new DevSound server.
sl@0
   400
// -----------------------------------------------------------------------------
sl@0
   401
//
sl@0
   402
TInt CStartAndMonitorDevSoundThread::StartDevSoundServer(
sl@0
   403
	RMessage2& aMessage,
sl@0
   404
	RMMFDevSoundServerProxy& aDevSoundSessionHandle)
sl@0
   405
	{
sl@0
   406
	SYMBIAN_DEBPRN0(_L("CStartAndMonitorDevSoundThread[0x%x]::StartDevSoundServer - enter"));
sl@0
   407
	
sl@0
   408
	RThread clientThread;
sl@0
   409
	TInt err(KErrNone);
sl@0
   410
	
sl@0
   411
	// Open handle to client thread
sl@0
   412
	err = aMessage.Client(clientThread);
sl@0
   413
	if (err != KErrNone)
sl@0
   414
		{
sl@0
   415
		clientThread.Close();
sl@0
   416
		return err;
sl@0
   417
		}
sl@0
   418
	// Open a process-relative handle to the process which owns clientThread.
sl@0
   419
	RProcess clientProcess;
sl@0
   420
	err = clientThread.Process(clientProcess);
sl@0
   421
	
sl@0
   422
	if (err != KErrNone)
sl@0
   423
		{
sl@0
   424
		// Close client thread handle and return error
sl@0
   425
		clientThread.Close();
sl@0
   426
		return err;
sl@0
   427
		}
sl@0
   428
	
sl@0
   429
	// Get the client process id
sl@0
   430
	TProcessId clientProcessId(clientProcess.Id());
sl@0
   431
	
sl@0
   432
	// Close client thread and client process handles
sl@0
   433
	clientThread.Close();
sl@0
   434
	clientProcess.Close();
sl@0
   435
	
sl@0
   436
	RServer2 devSoundServerHandle;
sl@0
   437
	devSoundServerHandle.SetReturnedHandle(0);
sl@0
   438
	
sl@0
   439
	//Pass to DevSoundServer the clien't process ID
sl@0
   440
	TDevSoundServerStart start(iAudioServer,
sl@0
   441
								clientProcessId,
sl@0
   442
								devSoundServerHandle);
sl@0
   443
	
sl@0
   444
	TThreadFunction serverFunc=CMMFDevSoundServer::StartThread;
sl@0
   445
	
sl@0
   446
	// To deal with the unique thread (+semaphore!) naming in EPOC,
sl@0
   447
	// and that we may be trying to restart a server that has just
sl@0
   448
	// exited we attempt to create a unique thread name for the server.
sl@0
   449
#ifdef SYMBIAN_USE_SEPARATE_HEAPS
sl@0
   450
	err = iServer.Create(KNullDesC,serverFunc,KDevSoundServerStackSize*2,
sl@0
   451
						KDevSoundServerInitHeapSize,
sl@0
   452
						KDevSoundServerMaxHeapSize,
sl@0
   453
						&start,
sl@0
   454
						EOwnerProcess);
sl@0
   455
#else
sl@0
   456
	err = iServer.Create(KNullDesC,
sl@0
   457
						serverFunc,
sl@0
   458
						(KDevSoundServerStackSize*2),
sl@0
   459
						NULL,
sl@0
   460
						&start,
sl@0
   461
						EOwnerProcess);
sl@0
   462
#endif // SYMBIAN_USE_SEPARATE_HEAPS
sl@0
   463
	if(err != KErrNone)
sl@0
   464
		{
sl@0
   465
		return err;
sl@0
   466
		}
sl@0
   467
	iServer.SetPriority(KDevsoundSvrPriority);
sl@0
   468
sl@0
   469
	// Synchronise with the server
sl@0
   470
	TRequestStatus reqStatus;
sl@0
   471
	iServer.Rendezvous(reqStatus);
sl@0
   472
sl@0
   473
	if (reqStatus!=KRequestPending)
sl@0
   474
		{
sl@0
   475
		iServer.Kill(0);
sl@0
   476
		}
sl@0
   477
	else
sl@0
   478
		{
sl@0
   479
		// Start the test harness
sl@0
   480
		iServer.Resume();
sl@0
   481
		// Server will call the reciprocal static synchronise call
sl@0
   482
		}
sl@0
   483
sl@0
   484
	// note devSoundServerHandle really "owned" by client thread - just copied here
sl@0
   485
sl@0
   486
	User::WaitForRequest(reqStatus); // wait for start or death
sl@0
   487
	if(reqStatus.Int() != KErrNone)
sl@0
   488
		{
sl@0
   489
		// close our handle to the thread. If we reach here, the thread should have
sl@0
   490
		// closed anyway as continue Rendezvous is always KErrNone() 
sl@0
   491
		iServer.Close();
sl@0
   492
		return reqStatus.Int();
sl@0
   493
		}
sl@0
   494
sl@0
   495
	err = aDevSoundSessionHandle.Open(devSoundServerHandle);
sl@0
   496
sl@0
   497
	if(err != KErrNone)
sl@0
   498
		{
sl@0
   499
		// close our handle to the thread. If we reach here, this means that NewSessionL() failed
sl@0
   500
		// on server, and that action itself will asynchronously stop the thread
sl@0
   501
		iServer.Close();
sl@0
   502
		return err;
sl@0
   503
		}
sl@0
   504
sl@0
   505
	aDevSoundSessionHandle.ShareProtected();
sl@0
   506
	iServer.Logon(iStatus);
sl@0
   507
	SetActive();
sl@0
   508
sl@0
   509
	iAudioServer->IncrementDevSoundCount();
sl@0
   510
sl@0
   511
	SYMBIAN_DEBPRN0(_L("CStartAndMonitorDevSoundThread[0x%x]::StartDevSoundServer - exit"));
sl@0
   512
	return KErrNone;
sl@0
   513
	}
sl@0
   514
sl@0
   515
// -----------------------------------------------------------------------------
sl@0
   516
// CStartAndMonitorDevSoundThread::CStartAndMonitorDevSoundThread
sl@0
   517
// Constructor
sl@0
   518
// -----------------------------------------------------------------------------
sl@0
   519
//
sl@0
   520
CStartAndMonitorDevSoundThread::CStartAndMonitorDevSoundThread(
sl@0
   521
	CMMFAudioServer* aAudioServer)
sl@0
   522
	: CActive(EPriorityStandard),iAudioServer(aAudioServer)
sl@0
   523
	{
sl@0
   524
sl@0
   525
	}
sl@0
   526
sl@0
   527
// Desctructor
sl@0
   528
CStartAndMonitorDevSoundThread::~CStartAndMonitorDevSoundThread()
sl@0
   529
	{
sl@0
   530
	Cancel();
sl@0
   531
	}
sl@0
   532
sl@0
   533
// -----------------------------------------------------------------------------
sl@0
   534
// CStartAndMonitorDevSoundThread::RunL
sl@0
   535
// Called by Active Object framework when DevSound server is destroyed.
sl@0
   536
// -----------------------------------------------------------------------------
sl@0
   537
//
sl@0
   538
void CStartAndMonitorDevSoundThread::RunL()
sl@0
   539
	{
sl@0
   540
	iServer.Close();
sl@0
   541
	iAudioServer->DecrementDevSoundCount();
sl@0
   542
	}
sl@0
   543
sl@0
   544
// -----------------------------------------------------------------------------
sl@0
   545
// CStartAndMonitorDevSoundThread::DoCancel
sl@0
   546
// Called by Active Object framework when client cancels active object.
sl@0
   547
// -----------------------------------------------------------------------------
sl@0
   548
//
sl@0
   549
void CStartAndMonitorDevSoundThread::DoCancel()
sl@0
   550
	{
sl@0
   551
	iServer.LogonCancel(iStatus);
sl@0
   552
	}
sl@0
   553
sl@0
   554
sl@0
   555
// -----------------------------------------------------------------------------
sl@0
   556
// RMMFDevSoundServerProxy::Open
sl@0
   557
// Creates new audio server session for the devsound server.
sl@0
   558
// -----------------------------------------------------------------------------
sl@0
   559
//
sl@0
   560
TInt RMMFDevSoundServerProxy::Open(RServer2& aDevSoundServerHandle)
sl@0
   561
	{
sl@0
   562
	SYMBIAN_DEBPRN0(_L("RMMFDevSoundServerProxy[0x%x]::Open - enter"));
sl@0
   563
	TInt err = CreateSession(aDevSoundServerHandle, TVersion(KMMFDevSoundServerVersion,
sl@0
   564
							KMMFDevSoundServerMinorVersionNumber,
sl@0
   565
							KMMFDevSoundServerBuildVersionNumber),
sl@0
   566
							-1, EIpcSession_GlobalSharable);
sl@0
   567
sl@0
   568
	SYMBIAN_DEBPRN0(_L("RMMFDevSoundServerProxy[0x%x]::Open - exit"));
sl@0
   569
	return err;
sl@0
   570
	}
sl@0
   571
sl@0
   572
//  End of File