diff -r 000000000000 -r 40261b775718 devsound/a3fdevsound/src/mmfaudioserverproxy/mmfaudioserverproxy.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/devsound/a3fdevsound/src/mmfaudioserverproxy/mmfaudioserverproxy.cpp Tue Feb 02 01:56:55 2010 +0200 @@ -0,0 +1,137 @@ +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + + + +#include +#include +#include + +#include "mmfaudioserverproxy.h" +#include "mmfaudioserverdecs.h" +#include + + +static const TUid KUidAudioServer = {KUidA3fAudioServerUID}; +const TInt KRetries = 5; +const TInt KInitialTime = 100000; //100ms +const TInt KTimeIncrement = 50000; // 50ms + +// ----------------------------------------------------------------------------- +// RMMFAudioServerProxy::Open +// +// ----------------------------------------------------------------------------- +// +EXPORT_C TInt RMMFAudioServerProxy::Open() + { + const TUidType serverUid(KNullUid,KNullUid,KUidAudioServer); + // Assume the server is already running and attempt to create a session + // 4 message slots + TInt err = CreateSession(KAudioServerName, + TVersion(KMMFAudioServerVersion, + KMMFAudioServerMinorVersionNumber, + KMMFAudioServerBuildVersionNumber)); + + if(err == KErrNotFound) + { + // Server not running + // Construct the server binary name + RProcess server; + + _LIT(KEmpty,""); + + err = server.Create(KAudioServerFileName, KEmpty, serverUid); + if(err != KErrNone) + { + return err; + } + // Synchronise with the server + TRequestStatus reqStatus; + server.Rendezvous(reqStatus); + + if (reqStatus!=KRequestPending) + { + server.Kill(0); + } + else + { + // Start the test harness + server.Resume(); + // Server will call the reciprocal static synchronise call + } + + User::WaitForRequest(reqStatus); // wait for rendezvous or death + server.Close(); + TInt reqStatusValue = reqStatus.Int(); + + if(reqStatusValue != KErrNone) + { + if(reqStatusValue == KErrNoMemory || reqStatusValue == KErrNotFound) + { + // All error codes except KErrNoMemory and KErrNotFound are assumed + // to be a duplicate server instance dying, then keep trying + // connection to the server. This can happen when two servers + // attempt to start at the same time. + return reqStatusValue; + } + //Wait for sometime, then retry and creation session + TInt waitTime = KInitialTime; + for(TInt retries=0;retries