sl@0: // Copyright (c) 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 the License "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: // e32test/mmu/t_shbuf_perfclient.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "t_shbuf_perfserver.h" sl@0: #include "t_shbuf_perfclient.h" sl@0: sl@0: sl@0: /** sl@0: * @file sl@0: * sl@0: * Client side APIs for a test server used for Performance Testing of shared buffers. sl@0: */ sl@0: sl@0: sl@0: /** sl@0: * Test API version. sl@0: */ sl@0: const TInt KRShBufTestServerMajorVersion = 1; sl@0: const TInt KRShBufTestServerMinorVersion = 0; sl@0: const TInt KRShBufTestServerBuildVersion = 1; sl@0: sl@0: sl@0: /** sl@0: * Start the server process which lives in its own executable and rendezvous with it. sl@0: * sl@0: * @return KErrNone if successful, or an error code if not. sl@0: */ sl@0: static TInt StartTestServer() sl@0: { sl@0: #ifdef CAN_TRANSFER_SHBUF_TO_ANOTHER_PROCESS sl@0: // sl@0: // Create a new server process. Simultaneous launching of two such sl@0: // processes should be detected when the second one attempts to sl@0: // create the server object, failing with KErrAlreadyExists. sl@0: // sl@0: _LIT(KTestServerExeImg, "T_SHBUF_PERFSERVER.EXE"); sl@0: RProcess server; sl@0: sl@0: TInt ret = server.Create(KTestServerExeImg, KNullDesC); sl@0: if (ret != KErrNone) sl@0: { sl@0: return ret; sl@0: } sl@0: #else sl@0: // sl@0: // Start a thread with the server in it. sl@0: // sl@0: RThread server; sl@0: sl@0: TInt ret = server.Create(_L("RShBufTestServerThread"), RShBufTestServerThread, sl@0: KDefaultStackSize, 0x10000, 0x10000, NULL); sl@0: if (ret != KErrNone) sl@0: { sl@0: return ret; sl@0: } sl@0: #endif sl@0: sl@0: // sl@0: // Rendezvous with the server or abort startup... sl@0: // sl@0: TRequestStatus status; sl@0: sl@0: server.Rendezvous(status); sl@0: if (status != KRequestPending) sl@0: { sl@0: server.Kill(0); sl@0: } sl@0: else sl@0: { sl@0: server.Resume(); sl@0: } sl@0: User::WaitForRequest(status); sl@0: sl@0: // sl@0: // We can't use the 'exit reason' if the server panicked as this sl@0: // is the panic 'reason' and may be '0' which cannot be distinguished sl@0: // from KErrNone. sl@0: // sl@0: if (server.ExitType() == EExitPanic) sl@0: { sl@0: ret = KErrGeneral; sl@0: } sl@0: else if (status.Int() != KErrAlreadyExists) sl@0: { sl@0: ret = status.Int(); sl@0: } sl@0: sl@0: server.Close(); sl@0: sl@0: return ret; sl@0: } // StartTestServer sl@0: sl@0: sl@0: /** sl@0: * Standard constructor. sl@0: */ sl@0: EXPORT_C RShBufTestServerSession::RShBufTestServerSession() sl@0: { sl@0: // NOP sl@0: } // RShBufTestServerSession::RShBufTestServerSession sl@0: sl@0: sl@0: /** sl@0: * Connects the client to the test server. sl@0: * sl@0: * @return KErrNone if successful, a system-wide error code if not. sl@0: * sl@0: * @capability None sl@0: */ sl@0: EXPORT_C TInt RShBufTestServerSession::Connect() sl@0: { sl@0: // sl@0: // Create a session with the server, but if it doesn't exist then start it and sl@0: // then create a session. sl@0: // sl@0: TInt result = CreateSession(KRShBufTestServerName, sl@0: TVersion(KRShBufTestServerMajorVersion, sl@0: KRShBufTestServerMinorVersion, sl@0: KRShBufTestServerBuildVersion)); sl@0: if (result == KErrNotFound || result == KErrServerTerminated) sl@0: { sl@0: result = StartTestServer(); sl@0: sl@0: if(result == KErrNone) sl@0: { sl@0: result = CreateSession(KRShBufTestServerName, sl@0: TVersion(KRShBufTestServerMajorVersion, sl@0: KRShBufTestServerMinorVersion, sl@0: KRShBufTestServerBuildVersion)); sl@0: } sl@0: } sl@0: sl@0: // sl@0: // If the creation of the session fails clean up session data... sl@0: // sl@0: if (result != KErrNone) sl@0: { sl@0: Close(); sl@0: } sl@0: sl@0: return result; sl@0: } // RShBufTestServerSession::Connect sl@0: sl@0: sl@0: /** sl@0: * Closes the client's session with the RShBuf Test Server. sl@0: * sl@0: * @capability None sl@0: */ sl@0: EXPORT_C void RShBufTestServerSession::Close() sl@0: { sl@0: RSessionBase::Close(); sl@0: } // RShBufTestServerSession::Close sl@0: sl@0: sl@0: /** sl@0: * Returns the current version of the RShBuf Test Server. sl@0: * sl@0: * @return The version of the RShBuf Test Server. sl@0: * sl@0: * @capability None sl@0: */ sl@0: EXPORT_C TVersion RShBufTestServerSession::Version() const sl@0: { sl@0: return(TVersion(KRShBufTestServerMajorVersion, sl@0: KRShBufTestServerMinorVersion, sl@0: KRShBufTestServerBuildVersion)); sl@0: } // RShBufTestServerSession::Version sl@0: sl@0: sl@0: /** sl@0: * Requests the shutdown of the server when the last client disconnects. sl@0: * There is no support for immediate shutdown functionality. This API call sl@0: * can only be executed if the server is compiled as a debug release. sl@0: * sl@0: * @return KErrNone if successful, a system-wide error code if not. sl@0: */ sl@0: EXPORT_C TInt RShBufTestServerSession::ShutdownServer() sl@0: { sl@0: return SendReceive(EShBufServerShutdownServer, TIpcArgs()); sl@0: } // RShBufTestServerSession::ShutdownServer sl@0: sl@0: sl@0: EXPORT_C TInt RShBufTestServerSession::FromTPtr8ProcessAndReturn(TDes8& aBuf, TUint aBufSize) sl@0: { sl@0: TIpcArgs args(&aBuf, aBufSize); sl@0: sl@0: return SendReceive(EShBufServerFromTPtr8ProcessAndReturn, args); sl@0: } // RShBufTestServerSession::FromTPtr8ProcessAndReturn sl@0: sl@0: sl@0: EXPORT_C TInt RShBufTestServerSession::FromTPtr8ProcessAndRelease(const TDesC8& aBuf) sl@0: { sl@0: TIpcArgs args(&aBuf); sl@0: sl@0: return SendReceive(EShBufServerFromTPtr8ProcessAndRelease, args); sl@0: } // RShBufTestServerSession::FromTPtr8ProcessAndRelease sl@0: sl@0: sl@0: EXPORT_C TInt RShBufTestServerSession::FromRShBufProcessAndReturn(RShBuf& aShBuf, TUint aBufSize) sl@0: { sl@0: TInt r; sl@0: TInt handle; sl@0: TPckg handlePckg(handle); sl@0: sl@0: TIpcArgs args(&handlePckg, aBufSize); sl@0: sl@0: r = SendReceive(EShBufServerFromRShBufProcessAndReturn, args); sl@0: sl@0: if (r == KErrNone) sl@0: aShBuf.SetReturnedHandle(handle); sl@0: sl@0: return r; sl@0: } // RShBufTestServerSession::FromRShBufProcessAndReturn sl@0: sl@0: sl@0: EXPORT_C TInt RShBufTestServerSession::OpenRShBufPool(TInt aHandle, const TShPoolInfo& aShPoolInfo) sl@0: { sl@0: TPckg shPoolInfoPckg(aShPoolInfo); sl@0: TIpcArgs args(aHandle, &shPoolInfoPckg); sl@0: sl@0: return SendReceive(EShBufServerOpenRShBufPool, args); sl@0: } // RShBufTestServerSession::OpenRShBufPool sl@0: sl@0: sl@0: EXPORT_C TInt RShBufTestServerSession::CloseRShBufPool(TInt aHandle) sl@0: { sl@0: TIpcArgs args(aHandle); sl@0: sl@0: return SendReceive(EShBufServerCloseRShBufPool, args); sl@0: } // RShBufTestServerSession::CloseRShBufPool sl@0: sl@0: sl@0: EXPORT_C TInt RShBufTestServerSession::FromRShBufProcessAndRelease(RShBuf& aShBuf) sl@0: { sl@0: TIpcArgs args(aShBuf.Handle()); sl@0: sl@0: return SendReceive(EShBufServerFromRShBufProcessAndRelease, args); sl@0: } // RShBufTestServerSession::FromRShBufProcessAndRelease sl@0: sl@0: sl@0: /** sl@0: * Set a heap mark in the RShBuf Test Server thread. sl@0: * sl@0: * @capability None sl@0: */ sl@0: EXPORT_C TInt RShBufTestServerSession::__DbgMarkHeap() sl@0: { sl@0: TIpcArgs args(TIpcArgs::ENothing); sl@0: sl@0: return SendReceive(EShBufServerDbgMarkHeap, args); sl@0: } // RShBufTestServerSession::__DbgMarkHeap sl@0: sl@0: sl@0: /** sl@0: * Performs a heap mark check in the RShBuf Test Server thread. sl@0: * sl@0: * @param aCount The number of heap cells expected to be allocated at sl@0: * the current nest level. sl@0: * sl@0: * @capability None sl@0: */ sl@0: EXPORT_C TInt RShBufTestServerSession::__DbgCheckHeap(TInt aCount) sl@0: { sl@0: TIpcArgs args(aCount); sl@0: sl@0: return SendReceive(EShBufServerDbgCheckHeap, args); sl@0: } // RShBufTestServerSession::__DbgCheckHeap sl@0: sl@0: sl@0: /** sl@0: * Perfom a heap mark end check in the RShBuf Test Server thread. sl@0: * sl@0: * @param aCount The number of heap cells expected to remain allocated sl@0: * at the current nest level. sl@0: * sl@0: * @capability None sl@0: */ sl@0: EXPORT_C TInt RShBufTestServerSession::__DbgMarkEnd(TInt aCount) sl@0: { sl@0: TIpcArgs args(aCount); sl@0: sl@0: return SendReceive(EShBufServerDbgMarkEnd, args); sl@0: } // RShBufTestServerSession::__DbgMarkEnd sl@0: sl@0: sl@0: /** sl@0: * Set a heap fail next condition in the RShBuf Test Server thread. sl@0: * sl@0: * @param aCount Determines when the allocation will fail. sl@0: * sl@0: * @capability None sl@0: */ sl@0: EXPORT_C TInt RShBufTestServerSession::__DbgFailNext(TInt aCount) sl@0: { sl@0: TIpcArgs args(aCount); sl@0: sl@0: return SendReceive(EShBufServerDbgFailNext, args); sl@0: } // RShBufTestServerSession::__DbgFailNext sl@0: sl@0: