Update contrib.
1 // Copyright (c) 2010 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 "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 // Client / server logging for Test Framework
15 // NOTE : does NOT include secure API changes in EKA2
20 // Test system includes
21 #include <testframework.h>
25 * Global : start a server
26 * NOTE. Function is global static as only one server will ever run at any time
27 * (there may be multiple client sessions)
30 * Error code (KErrNone if successful)
35 GLDEF_C TInt StartServer()
36 // Start the server process/thread which lives in an (EPOC)EXE object
38 const TUidType serverUid(KNullUid, KNullUid, KTestFrameworkServerUid3);
41 // EPOC is easy, we just create a new server process. Simultaneous launching
42 // of two such processes should be detected when the second one attempts to
43 // create the server object, failing with KErrAlreadyExists.
46 TInt r = server.Create(KTestFrameworkServerImg, KNullDesC, serverUid);
52 TRequestStatus rendezvous;
53 server.Rendezvous(rendezvous);
55 if (rendezvous!=KRequestPending)
65 User::WaitForRequest(rendezvous); // wait for start or death
67 // we can't use the 'exit reason' if the server panicked as this
68 // is the panic 'reason' and may be '0' which cannot be distinguished
70 if (rendezvous!=KErrNone)
75 // server started (at last). Cancel and consume the death-notification
76 // before reporting success
77 return rendezvous.Int();
82 * Constructor for RTestFrameworkClientSession
87 RTestFrameworkClientSession::RTestFrameworkClientSession()
93 * Client session : connect to server.
94 * Will start a new server session if no server exists
97 * Error code (KErrNone if connect successful)
102 TInt RTestFrameworkClientSession::Connect()
104 // NOTE : this loop is ugly and can probably be rewritten to be more graceful
105 const TInt KNumRetries = 2;
107 TInt retry = KNumRetries;
110 TInt r = CreateSession(KTestFrameworkServerName, TVersion(KTestFrameworkServerMajorVersionNumber,
111 KTestFrameworkServerMinorVersionNumber,
112 KTestFrameworkServerBuildVersionNumber));
115 #ifdef __IPC_V2_PRESENT__
118 r = Share(RSessionBase::EAutoAttach);
124 if (r != KErrNotFound && r != KErrServerTerminated)
131 if (r != KErrNone && r != KErrAlreadyExists)
138 * Request creation of an input window.
139 * NOTE. For initialisation of input console only - unlikely to
140 * be required by user
142 * @param "TRectBuf& aAllocatedWindow"
145 * @param "TRequestStatus& aReqStat"
151 void RTestFrameworkClientSession::CreateInputWindow(TRectBuf& aAllocatedWindow, TRequestStatus& aReqStat)
153 SendReceiveResult(ECreateInputWindow, aAllocatedWindow, aReqStat);
158 * Request window change notifications
159 * NOTE. For initialisation of input console only - unlikely to
160 * be required by user
162 * @param "TRectBuf& aNewWindow"
163 * New window dimensions
165 * @param "TRequestStatus& aReqStat"
171 void RTestFrameworkClientSession::NotifyIfWindowChange(TRectBuf& aNewWindow, TRequestStatus& aReqStat)
173 SendReceiveResult(ENotifyIfWindowChange, aNewWindow, aReqStat);
178 * Cancel window change notifications
179 * NOTE. For initialisation of input console only - unlikely to
180 * be required by user
183 * SendReceive error code
188 TInt RTestFrameworkClientSession::CancelNotifyIfWindowChange()
190 return SendReceive(ECancelNotifyIfWindowChange);
196 * Open a log server session
198 * @param "const TDesC& aLogName"
201 * @param "TInt aLogMode"
202 * The log mode (a bitmask of TTestFrameworkLogMode)
207 void RTestFrameworkClientSession::OpenLog(const TDesC& aLogName, TInt aLogMode)
209 (void) SendReceive(EOpenLog, aLogName, aLogMode);
214 * Write message string to log server session
216 * @param "const TDesC& aMsg"
219 * @param "TInt aLogMode"
220 * The log mode (a bitmask of TTestFrameworkLogMode)
225 void RTestFrameworkClientSession::WriteLog(const TDesC& aMsg, TInt aLogMode)
227 (void) SendReceive(EWriteLog, aMsg, aLogMode);
232 * Send close log message to server
237 void RTestFrameworkClientSession::CloseLog()
239 SendReceive(ECloseLog);
244 * Retrieve log status from server
247 * The log status (a bitmask of TTestFrameworkLogMode)
252 TInt RTestFrameworkClientSession::LogStatus()
256 TInt r = SendReceiveResult(ELogStatus, pckg);
259 // RTestFrameworkClientSession does not log -
260 // we can however return 0 to indicate an error (no outputs)