sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "MmfAudioServerProxy.h" sl@0: #include "MmfAudioServerStart.h" sl@0: #include "MmfBase.hrh" sl@0: #include "MmfAudioClientServer.h" sl@0: sl@0: #define KMaxServerNameLength 256 sl@0: sl@0: static const TUid KUidAudioServer = {KUidMmfAudioServerDllUnicodeDefine}; sl@0: const TInt KRetries = 5; sl@0: const TInt KInitialTime = 100000; //100ms sl@0: const TInt KTimeIncrement = 50000; // 50ms sl@0: sl@0: sl@0: EXPORT_C TInt RMMFAudioServerProxy::Open() sl@0: { sl@0: sl@0: const TUidType serverUid(KNullUid,KNullUid,KUidAudioServer); sl@0: sl@0: // Assume the server is already running and attempt to create a session sl@0: // 4 message slots sl@0: TInt err = CreateSession(KAudioServerName, TVersion(KMMFAudioServerVersion, sl@0: KMMFAudioServerMinorVersionNumber, sl@0: KMMFAudioServerBuildVersionNumber)); sl@0: if(err == KErrNotFound) sl@0: { sl@0: // Server not running sl@0: // Construct the server binary name sl@0: TBuf serverFile; sl@0: RProcess server; sl@0: sl@0: _LIT(KEmpty,""); sl@0: sl@0: err = server.Create(KAudioServerFileName, KEmpty, serverUid); sl@0: if(err != KErrNone) sl@0: return err; sl@0: // Synchronise with the server sl@0: TRequestStatus reqStatus; sl@0: server.Rendezvous(reqStatus); sl@0: sl@0: if (reqStatus!=KRequestPending) sl@0: { sl@0: server.Kill(0); sl@0: } sl@0: else sl@0: { sl@0: // Start the test harness sl@0: server.Resume(); sl@0: // Server will call the reciprocal static synchronise call sl@0: } sl@0: User::WaitForRequest(reqStatus); // wait for rendezvous or death sl@0: server.Close(); sl@0: TInt reqStatusValue = reqStatus.Int(); sl@0: if(reqStatusValue != KErrNone) sl@0: { sl@0: if(reqStatusValue == KErrNoMemory || reqStatusValue == KErrNotFound) sl@0: { sl@0: // All error codes except KErrNoMemory and KErrNotFound are assumed sl@0: // to be a duplicate server instance dying, then keep trying connection sl@0: // to the server. This can happen when two servers attempt to start sl@0: // at the same time. sl@0: return reqStatusValue; sl@0: } sl@0: //Wait for sometime, then retry and creation session sl@0: TInt waitTime = KInitialTime; sl@0: for(TInt retries=0;retries