sl@0
|
1 |
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Client / server logging for Test Framework
|
sl@0
|
15 |
// NOTE : does NOT include secure API changes in EKA2
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
// Test system includes
|
sl@0
|
21 |
#include <testframework.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
/**
|
sl@0
|
24 |
*
|
sl@0
|
25 |
* Global : start a server
|
sl@0
|
26 |
* NOTE. Function is global static as only one server will ever run at any time
|
sl@0
|
27 |
* (there may be multiple client sessions)
|
sl@0
|
28 |
*
|
sl@0
|
29 |
* @return "TInt"
|
sl@0
|
30 |
* Error code (KErrNone if successful)
|
sl@0
|
31 |
*
|
sl@0
|
32 |
* @xxxx
|
sl@0
|
33 |
*
|
sl@0
|
34 |
*/
|
sl@0
|
35 |
GLDEF_C TInt StartServer()
|
sl@0
|
36 |
// Start the server process/thread which lives in an (EPOC)EXE object
|
sl@0
|
37 |
{
|
sl@0
|
38 |
const TUidType serverUid(KNullUid, KNullUid, KTestFrameworkServerUid3);
|
sl@0
|
39 |
|
sl@0
|
40 |
|
sl@0
|
41 |
// EPOC is easy, we just create a new server process. Simultaneous launching
|
sl@0
|
42 |
// of two such processes should be detected when the second one attempts to
|
sl@0
|
43 |
// create the server object, failing with KErrAlreadyExists.
|
sl@0
|
44 |
|
sl@0
|
45 |
RProcess server;
|
sl@0
|
46 |
TInt r = server.Create(KTestFrameworkServerImg, KNullDesC, serverUid);
|
sl@0
|
47 |
|
sl@0
|
48 |
if (r != KErrNone)
|
sl@0
|
49 |
return r;
|
sl@0
|
50 |
|
sl@0
|
51 |
|
sl@0
|
52 |
TRequestStatus rendezvous;
|
sl@0
|
53 |
server.Rendezvous(rendezvous);
|
sl@0
|
54 |
|
sl@0
|
55 |
if (rendezvous!=KRequestPending)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
server.Kill(0);
|
sl@0
|
58 |
}
|
sl@0
|
59 |
else
|
sl@0
|
60 |
{
|
sl@0
|
61 |
server.Resume();
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
|
sl@0
|
65 |
User::WaitForRequest(rendezvous); // wait for start or death
|
sl@0
|
66 |
|
sl@0
|
67 |
// we can't use the 'exit reason' if the server panicked as this
|
sl@0
|
68 |
// is the panic 'reason' and may be '0' which cannot be distinguished
|
sl@0
|
69 |
// from KErrNone
|
sl@0
|
70 |
if (rendezvous!=KErrNone)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
server.Close();
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
// server started (at last). Cancel and consume the death-notification
|
sl@0
|
76 |
// before reporting success
|
sl@0
|
77 |
return rendezvous.Int();
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
/**
|
sl@0
|
81 |
*
|
sl@0
|
82 |
* Constructor for RTestFrameworkClientSession
|
sl@0
|
83 |
*
|
sl@0
|
84 |
* @xxxx
|
sl@0
|
85 |
*
|
sl@0
|
86 |
*/
|
sl@0
|
87 |
RTestFrameworkClientSession::RTestFrameworkClientSession()
|
sl@0
|
88 |
{
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
/**
|
sl@0
|
92 |
*
|
sl@0
|
93 |
* Client session : connect to server.
|
sl@0
|
94 |
* Will start a new server session if no server exists
|
sl@0
|
95 |
*
|
sl@0
|
96 |
* @return "TInt"
|
sl@0
|
97 |
* Error code (KErrNone if connect successful)
|
sl@0
|
98 |
*
|
sl@0
|
99 |
* @xxxx
|
sl@0
|
100 |
*
|
sl@0
|
101 |
*/
|
sl@0
|
102 |
TInt RTestFrameworkClientSession::Connect()
|
sl@0
|
103 |
{
|
sl@0
|
104 |
// NOTE : this loop is ugly and can probably be rewritten to be more graceful
|
sl@0
|
105 |
const TInt KNumRetries = 2;
|
sl@0
|
106 |
|
sl@0
|
107 |
TInt retry = KNumRetries;
|
sl@0
|
108 |
for (;;)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
TInt r = CreateSession(KTestFrameworkServerName, TVersion(KTestFrameworkServerMajorVersionNumber,
|
sl@0
|
111 |
KTestFrameworkServerMinorVersionNumber,
|
sl@0
|
112 |
KTestFrameworkServerBuildVersionNumber));
|
sl@0
|
113 |
if (r == KErrNone)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
#ifdef __IPC_V2_PRESENT__
|
sl@0
|
116 |
r = ShareAuto();
|
sl@0
|
117 |
#else
|
sl@0
|
118 |
r = Share(RSessionBase::EAutoAttach);
|
sl@0
|
119 |
#endif
|
sl@0
|
120 |
if (r!=KErrNone)
|
sl@0
|
121 |
Close();
|
sl@0
|
122 |
return r;
|
sl@0
|
123 |
}
|
sl@0
|
124 |
if (r != KErrNotFound && r != KErrServerTerminated)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
return r;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
if (--retry == 0)
|
sl@0
|
129 |
return r;
|
sl@0
|
130 |
r = StartServer();
|
sl@0
|
131 |
if (r != KErrNone && r != KErrAlreadyExists)
|
sl@0
|
132 |
return r;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
/**
|
sl@0
|
137 |
*
|
sl@0
|
138 |
* Request creation of an input window.
|
sl@0
|
139 |
* NOTE. For initialisation of input console only - unlikely to
|
sl@0
|
140 |
* be required by user
|
sl@0
|
141 |
*
|
sl@0
|
142 |
* @param "TRectBuf& aAllocatedWindow"
|
sl@0
|
143 |
* Window dimensions
|
sl@0
|
144 |
*
|
sl@0
|
145 |
* @param "TRequestStatus& aReqStat"
|
sl@0
|
146 |
* Request status
|
sl@0
|
147 |
*
|
sl@0
|
148 |
* @xxxx
|
sl@0
|
149 |
*
|
sl@0
|
150 |
*/
|
sl@0
|
151 |
void RTestFrameworkClientSession::CreateInputWindow(TRectBuf& aAllocatedWindow, TRequestStatus& aReqStat)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
SendReceiveResult(ECreateInputWindow, aAllocatedWindow, aReqStat);
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
/**
|
sl@0
|
157 |
*
|
sl@0
|
158 |
* Request window change notifications
|
sl@0
|
159 |
* NOTE. For initialisation of input console only - unlikely to
|
sl@0
|
160 |
* be required by user
|
sl@0
|
161 |
*
|
sl@0
|
162 |
* @param "TRectBuf& aNewWindow"
|
sl@0
|
163 |
* New window dimensions
|
sl@0
|
164 |
*
|
sl@0
|
165 |
* @param "TRequestStatus& aReqStat"
|
sl@0
|
166 |
* Request status
|
sl@0
|
167 |
*
|
sl@0
|
168 |
* @xxxx
|
sl@0
|
169 |
*
|
sl@0
|
170 |
*/
|
sl@0
|
171 |
void RTestFrameworkClientSession::NotifyIfWindowChange(TRectBuf& aNewWindow, TRequestStatus& aReqStat)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
SendReceiveResult(ENotifyIfWindowChange, aNewWindow, aReqStat);
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
/**
|
sl@0
|
177 |
*
|
sl@0
|
178 |
* Cancel window change notifications
|
sl@0
|
179 |
* NOTE. For initialisation of input console only - unlikely to
|
sl@0
|
180 |
* be required by user
|
sl@0
|
181 |
*
|
sl@0
|
182 |
* @return "TInt"
|
sl@0
|
183 |
* SendReceive error code
|
sl@0
|
184 |
*
|
sl@0
|
185 |
* @xxxx
|
sl@0
|
186 |
*
|
sl@0
|
187 |
*/
|
sl@0
|
188 |
TInt RTestFrameworkClientSession::CancelNotifyIfWindowChange()
|
sl@0
|
189 |
{
|
sl@0
|
190 |
return SendReceive(ECancelNotifyIfWindowChange);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
|
sl@0
|
194 |
/**
|
sl@0
|
195 |
*
|
sl@0
|
196 |
* Open a log server session
|
sl@0
|
197 |
*
|
sl@0
|
198 |
* @param "const TDesC& aLogName"
|
sl@0
|
199 |
* The log name
|
sl@0
|
200 |
*
|
sl@0
|
201 |
* @param "TInt aLogMode"
|
sl@0
|
202 |
* The log mode (a bitmask of TTestFrameworkLogMode)
|
sl@0
|
203 |
*
|
sl@0
|
204 |
* @xxxx
|
sl@0
|
205 |
*
|
sl@0
|
206 |
*/
|
sl@0
|
207 |
void RTestFrameworkClientSession::OpenLog(const TDesC& aLogName, TInt aLogMode)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
(void) SendReceive(EOpenLog, aLogName, aLogMode);
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
/**
|
sl@0
|
213 |
*
|
sl@0
|
214 |
* Write message string to log server session
|
sl@0
|
215 |
*
|
sl@0
|
216 |
* @param "const TDesC& aMsg"
|
sl@0
|
217 |
* The message string
|
sl@0
|
218 |
*
|
sl@0
|
219 |
* @param "TInt aLogMode"
|
sl@0
|
220 |
* The log mode (a bitmask of TTestFrameworkLogMode)
|
sl@0
|
221 |
*
|
sl@0
|
222 |
* @xxxx
|
sl@0
|
223 |
*
|
sl@0
|
224 |
*/
|
sl@0
|
225 |
void RTestFrameworkClientSession::WriteLog(const TDesC& aMsg, TInt aLogMode)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
(void) SendReceive(EWriteLog, aMsg, aLogMode);
|
sl@0
|
228 |
}
|
sl@0
|
229 |
|
sl@0
|
230 |
/**
|
sl@0
|
231 |
*
|
sl@0
|
232 |
* Send close log message to server
|
sl@0
|
233 |
*
|
sl@0
|
234 |
* @xxxx
|
sl@0
|
235 |
*
|
sl@0
|
236 |
*/
|
sl@0
|
237 |
void RTestFrameworkClientSession::CloseLog()
|
sl@0
|
238 |
{
|
sl@0
|
239 |
SendReceive(ECloseLog);
|
sl@0
|
240 |
}
|
sl@0
|
241 |
|
sl@0
|
242 |
/**
|
sl@0
|
243 |
*
|
sl@0
|
244 |
* Retrieve log status from server
|
sl@0
|
245 |
*
|
sl@0
|
246 |
* @return "TInt"
|
sl@0
|
247 |
* The log status (a bitmask of TTestFrameworkLogMode)
|
sl@0
|
248 |
*
|
sl@0
|
249 |
* @xxxx
|
sl@0
|
250 |
*
|
sl@0
|
251 |
*/
|
sl@0
|
252 |
TInt RTestFrameworkClientSession::LogStatus()
|
sl@0
|
253 |
{
|
sl@0
|
254 |
TInt res = 0;
|
sl@0
|
255 |
TPckgBuf<TInt> pckg;
|
sl@0
|
256 |
TInt r = SendReceiveResult(ELogStatus, pckg);
|
sl@0
|
257 |
if (r != KErrNone)
|
sl@0
|
258 |
{
|
sl@0
|
259 |
// RTestFrameworkClientSession does not log -
|
sl@0
|
260 |
// we can however return 0 to indicate an error (no outputs)
|
sl@0
|
261 |
res = 0;
|
sl@0
|
262 |
}
|
sl@0
|
263 |
else
|
sl@0
|
264 |
res = pckg();
|
sl@0
|
265 |
return res;
|
sl@0
|
266 |
}
|