First public contribution.
1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test/mmu/t_shbuf_perfclient.cpp
21 #include <e32msgqueue.h>
24 #include "t_shbuf_perfserver.h"
25 #include "t_shbuf_perfclient.h"
31 * Client side APIs for a test server used for Performance Testing of shared buffers.
38 const TInt KRShBufTestServerMajorVersion = 1;
39 const TInt KRShBufTestServerMinorVersion = 0;
40 const TInt KRShBufTestServerBuildVersion = 1;
44 * Start the server process which lives in its own executable and rendezvous with it.
46 * @return KErrNone if successful, or an error code if not.
48 static TInt StartTestServer()
50 #ifdef CAN_TRANSFER_SHBUF_TO_ANOTHER_PROCESS
52 // Create a new server process. Simultaneous launching of two such
53 // processes should be detected when the second one attempts to
54 // create the server object, failing with KErrAlreadyExists.
56 _LIT(KTestServerExeImg, "T_SHBUF_PERFSERVER.EXE");
59 TInt ret = server.Create(KTestServerExeImg, KNullDesC);
66 // Start a thread with the server in it.
70 TInt ret = server.Create(_L("RShBufTestServerThread"), RShBufTestServerThread,
71 KDefaultStackSize, 0x10000, 0x10000, NULL);
79 // Rendezvous with the server or abort startup...
81 TRequestStatus status;
83 server.Rendezvous(status);
84 if (status != KRequestPending)
92 User::WaitForRequest(status);
95 // We can't use the 'exit reason' if the server panicked as this
96 // is the panic 'reason' and may be '0' which cannot be distinguished
99 if (server.ExitType() == EExitPanic)
103 else if (status.Int() != KErrAlreadyExists)
115 * Standard constructor.
117 EXPORT_C RShBufTestServerSession::RShBufTestServerSession()
120 } // RShBufTestServerSession::RShBufTestServerSession
124 * Connects the client to the test server.
126 * @return KErrNone if successful, a system-wide error code if not.
130 EXPORT_C TInt RShBufTestServerSession::Connect()
133 // Create a session with the server, but if it doesn't exist then start it and
134 // then create a session.
136 TInt result = CreateSession(KRShBufTestServerName,
137 TVersion(KRShBufTestServerMajorVersion,
138 KRShBufTestServerMinorVersion,
139 KRShBufTestServerBuildVersion));
140 if (result == KErrNotFound || result == KErrServerTerminated)
142 result = StartTestServer();
144 if(result == KErrNone)
146 result = CreateSession(KRShBufTestServerName,
147 TVersion(KRShBufTestServerMajorVersion,
148 KRShBufTestServerMinorVersion,
149 KRShBufTestServerBuildVersion));
154 // If the creation of the session fails clean up session data...
156 if (result != KErrNone)
162 } // RShBufTestServerSession::Connect
166 * Closes the client's session with the RShBuf Test Server.
170 EXPORT_C void RShBufTestServerSession::Close()
172 RSessionBase::Close();
173 } // RShBufTestServerSession::Close
177 * Returns the current version of the RShBuf Test Server.
179 * @return The version of the RShBuf Test Server.
183 EXPORT_C TVersion RShBufTestServerSession::Version() const
185 return(TVersion(KRShBufTestServerMajorVersion,
186 KRShBufTestServerMinorVersion,
187 KRShBufTestServerBuildVersion));
188 } // RShBufTestServerSession::Version
192 * Requests the shutdown of the server when the last client disconnects.
193 * There is no support for immediate shutdown functionality. This API call
194 * can only be executed if the server is compiled as a debug release.
196 * @return KErrNone if successful, a system-wide error code if not.
198 EXPORT_C TInt RShBufTestServerSession::ShutdownServer()
200 return SendReceive(EShBufServerShutdownServer, TIpcArgs());
201 } // RShBufTestServerSession::ShutdownServer
204 EXPORT_C TInt RShBufTestServerSession::FromTPtr8ProcessAndReturn(TDes8& aBuf, TUint aBufSize)
206 TIpcArgs args(&aBuf, aBufSize);
208 return SendReceive(EShBufServerFromTPtr8ProcessAndReturn, args);
209 } // RShBufTestServerSession::FromTPtr8ProcessAndReturn
212 EXPORT_C TInt RShBufTestServerSession::FromTPtr8ProcessAndRelease(const TDesC8& aBuf)
214 TIpcArgs args(&aBuf);
216 return SendReceive(EShBufServerFromTPtr8ProcessAndRelease, args);
217 } // RShBufTestServerSession::FromTPtr8ProcessAndRelease
220 EXPORT_C TInt RShBufTestServerSession::FromRShBufProcessAndReturn(RShBuf& aShBuf, TUint aBufSize)
224 TPckg<TInt> handlePckg(handle);
226 TIpcArgs args(&handlePckg, aBufSize);
228 r = SendReceive(EShBufServerFromRShBufProcessAndReturn, args);
231 aShBuf.SetReturnedHandle(handle);
234 } // RShBufTestServerSession::FromRShBufProcessAndReturn
237 EXPORT_C TInt RShBufTestServerSession::OpenRShBufPool(TInt aHandle, const TShPoolInfo& aShPoolInfo)
239 TPckg<TShPoolInfo> shPoolInfoPckg(aShPoolInfo);
240 TIpcArgs args(aHandle, &shPoolInfoPckg);
242 return SendReceive(EShBufServerOpenRShBufPool, args);
243 } // RShBufTestServerSession::OpenRShBufPool
246 EXPORT_C TInt RShBufTestServerSession::CloseRShBufPool(TInt aHandle)
248 TIpcArgs args(aHandle);
250 return SendReceive(EShBufServerCloseRShBufPool, args);
251 } // RShBufTestServerSession::CloseRShBufPool
254 EXPORT_C TInt RShBufTestServerSession::FromRShBufProcessAndRelease(RShBuf& aShBuf)
256 TIpcArgs args(aShBuf.Handle());
258 return SendReceive(EShBufServerFromRShBufProcessAndRelease, args);
259 } // RShBufTestServerSession::FromRShBufProcessAndRelease
263 * Set a heap mark in the RShBuf Test Server thread.
267 EXPORT_C TInt RShBufTestServerSession::__DbgMarkHeap()
269 TIpcArgs args(TIpcArgs::ENothing);
271 return SendReceive(EShBufServerDbgMarkHeap, args);
272 } // RShBufTestServerSession::__DbgMarkHeap
276 * Performs a heap mark check in the RShBuf Test Server thread.
278 * @param aCount The number of heap cells expected to be allocated at
279 * the current nest level.
283 EXPORT_C TInt RShBufTestServerSession::__DbgCheckHeap(TInt aCount)
285 TIpcArgs args(aCount);
287 return SendReceive(EShBufServerDbgCheckHeap, args);
288 } // RShBufTestServerSession::__DbgCheckHeap
292 * Perfom a heap mark end check in the RShBuf Test Server thread.
294 * @param aCount The number of heap cells expected to remain allocated
295 * at the current nest level.
299 EXPORT_C TInt RShBufTestServerSession::__DbgMarkEnd(TInt aCount)
301 TIpcArgs args(aCount);
303 return SendReceive(EShBufServerDbgMarkEnd, args);
304 } // RShBufTestServerSession::__DbgMarkEnd
308 * Set a heap fail next condition in the RShBuf Test Server thread.
310 * @param aCount Determines when the allocation will fail.
314 EXPORT_C TInt RShBufTestServerSession::__DbgFailNext(TInt aCount)
316 TIpcArgs args(aCount);
318 return SendReceive(EShBufServerDbgFailNext, args);
319 } // RShBufTestServerSession::__DbgFailNext