diff -r 000000000000 -r 2f259fa3e83a uifw/tsrc/public/basic/AknSoundServerStifTest/src/AknSoundServerSession.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uifw/tsrc/public/basic/AknSoundServerStifTest/src/AknSoundServerSession.cpp Tue Feb 02 01:00:49 2010 +0200 @@ -0,0 +1,248 @@ +/* +* Copyright (c) 2002-2007 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: RAknSoundServerSession implementation. Direct copy from +* aknsoundplayer.cpp. +* +*/ + +#include +#include +#include +#include "aknsoundserversession.h" + +// CONSTANTS +const TInt KAknResourceBufferSize = 512; + +// RAknSoundServerSession + +TInt RAknSoundServerSession::Connect() + { + iKeySoundServerExists = EFalse; + + // Create a session with zero message slots (since we have no asycronous calls) + TInt ret=CreateSession(__KEYSOUND_SERVER_NAME,TVersion(KKeySoundServMajorVN,KKeySoundServMinorVN,KKeySoundServBuildVN),0); + if ( ret == KErrNone ) + { + iKeySoundServerExists = ETrue; + } + return KErrNone; + } + +TInt RAknSoundServerSession::ServerRequest(TInt aFunction,const TIpcArgs& aArgs) + { + TInt err = KErrServerTerminated; + if (Handle()) + { + err = SendReceive(aFunction, aArgs); + } + + if (err == KErrServerTerminated) + { + // Try to reconnect, if the keysound server has been shutdown + Connect(); + if ( iKeySoundServerExists ) + { + err = SendReceive(aFunction, aArgs); + } + else + { + return KErrNone; // We couldn't start KeySoundServer, just omit the error.. + } + } + return err; + } + +TBool RAknSoundServerSession::Init(TInt aUid) + { + // Initialise returnCode to ETrue because ServerRequest may fail to set it if sound + // server is broken, and in that case we do not want to attempt to load sounds from + // resource, which may happen if the uninitialised value == EFalse. + TPckgBuf returnCode(ETrue); + + TIpcArgs args ( &returnCode, aUid ); + ServerRequest(EKeySoundServerInit,args); + return returnCode(); + } + +#pragma warning( disable : 4244 ) +//\S60\AVKON\SRC\Aknsoundplayer.cpp(404) : warning C4244: '=' : conversion from 'int' to 'short', possible loss of data + +void RAknSoundServerSession::AddSoundInfoResourceL(TInt aUid, TResourceReader aReader) + { + // Read information from resource read, and package up as a buffer + CBufFlat* buffer = CBufFlat::NewL(KAknResourceBufferSize); + CleanupStack::PushL(buffer); + + RBufWriteStream bufStream; + bufStream.Open(*buffer); + + CleanupClosePushL(bufStream); + + TInt count = aReader.ReadInt16(); + + bufStream.WriteUint16L(count); + + for (TInt ii=0; iiPtr(0); + TIpcArgs args (aUid, bufPtr.Length(), &bufPtr); + User::LeaveIfError( ServerRequest(EKeySoundServerAddSIDS,args) ); + + CleanupStack::PopAndDestroy(); // buffer + } + +void RAknSoundServerSession::PushContextL(TInt aUid, TResourceReader& aReader, TInt aResourceId) + { + TInt items = aReader.ReadInt16(); + // RDebug::Print(_L("Items:%d"), items); + + TInt resSize = (items * 5); + + CBufFlat* buffer = CBufFlat::NewL(resSize); + CleanupStack::PushL(buffer); + + RBufWriteStream bufStream; + bufStream.Open(*buffer); + + CleanupClosePushL(bufStream); + + for (TInt ii=0; iiPtr(0); + TIpcArgs args (items, &bufPtr, aUid, aResourceId); + User::LeaveIfError(ServerRequest(EKeySoundServerPushContext,args)); + CleanupStack::PopAndDestroy(); // buffer + } + +void RAknSoundServerSession::PopContext() + { + ServerRequest(EKeySoundServerPopContext,TIpcArgs()); + } + +void RAknSoundServerSession::PlaySound(TInt aSid) + { + ServerRequest(EKeySoundServerPlaySID,TIpcArgs(aSid)); + } + +void RAknSoundServerSession::StopSound(TInt aSid) + { + ServerRequest(EKeySoundServerStopCurrentTone,TIpcArgs(aSid)); + } + +void RAknSoundServerSession::KeyPressed(TInt aKey, TBool aRepeat) + { + TIpcArgs args (aKey,aRepeat); + ServerRequest(EKeySoundServerPlayKey,args); + } + +void RAknSoundServerSession::BringToForeground() + { + ServerRequest(EKeySoundServerBringToForeground,TIpcArgs()); + } + +void RAknSoundServerSession::LockContext() + { + ServerRequest(EKeySoundServerLockContext,TIpcArgs()); + } + +void RAknSoundServerSession::ReleaseContext() + { + ServerRequest(EKeySoundServerReleaseContext,TIpcArgs()); + } + +TInt RAknSoundServerSession::TopContext() + { + TInt aContextResourceId = 0; + TPckg pckg(aContextResourceId); + ServerRequest(EKeySoundServerTopContext,TIpcArgs(&pckg)); + return aContextResourceId; + } + +// End of file