sl@0
|
1 |
// Copyright (c) 2002-2009 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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <e32svr.h>
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "TestFrameworkServer.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "TestFrameworkServer.inl"
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <testframeworkipc.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
/**
|
sl@0
|
26 |
*
|
sl@0
|
27 |
* Initiate server exit when the timer expires
|
sl@0
|
28 |
*
|
sl@0
|
29 |
* @xxxx
|
sl@0
|
30 |
*
|
sl@0
|
31 |
*/
|
sl@0
|
32 |
void CTestFrameworkServerShutdown::RunL()
|
sl@0
|
33 |
{
|
sl@0
|
34 |
CActiveScheduler::Stop();
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
/**
|
sl@0
|
38 |
*
|
sl@0
|
39 |
* Test Framework server static constructor
|
sl@0
|
40 |
* NOTE : only one instance of the server process should run
|
sl@0
|
41 |
* during any Test Framework run; all client sessions
|
sl@0
|
42 |
* will use this one instance.
|
sl@0
|
43 |
*
|
sl@0
|
44 |
* @xxxx
|
sl@0
|
45 |
*
|
sl@0
|
46 |
*/
|
sl@0
|
47 |
CMmfIpcServer* CTestFrameworkServer::NewL()
|
sl@0
|
48 |
{
|
sl@0
|
49 |
CTestFrameworkServer* s = new(ELeave) CTestFrameworkServer;
|
sl@0
|
50 |
CleanupStack::PushL(s);
|
sl@0
|
51 |
s->ConstructL();
|
sl@0
|
52 |
CleanupStack::Pop();
|
sl@0
|
53 |
return s;
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
/**
|
sl@0
|
57 |
*
|
sl@0
|
58 |
* Test Framework server first-phase constructor
|
sl@0
|
59 |
*
|
sl@0
|
60 |
* @xxxx
|
sl@0
|
61 |
*
|
sl@0
|
62 |
*/
|
sl@0
|
63 |
CTestFrameworkServer::CTestFrameworkServer()
|
sl@0
|
64 |
:CMmfIpcServer(0, ESharableSessions)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
// set up so that iConsole is NULL. A call to OpenLogL will initialise the console
|
sl@0
|
69 |
// and file (if any)
|
sl@0
|
70 |
|
sl@0
|
71 |
/**
|
sl@0
|
72 |
*
|
sl@0
|
73 |
* Test Framework server second-phase constructor
|
sl@0
|
74 |
* Starts the server; does not initialise the log
|
sl@0
|
75 |
* (this must be done independently with a call to OpenLogL)
|
sl@0
|
76 |
*
|
sl@0
|
77 |
* @xxxx
|
sl@0
|
78 |
*
|
sl@0
|
79 |
*/
|
sl@0
|
80 |
void CTestFrameworkServer::ConstructL()
|
sl@0
|
81 |
{
|
sl@0
|
82 |
StartL(KTestFrameworkServerName);
|
sl@0
|
83 |
//Ensure that the server will exit even if the first client fails to connect
|
sl@0
|
84 |
iShutdown.ConstructL();
|
sl@0
|
85 |
iShutdown.Start();
|
sl@0
|
86 |
|
sl@0
|
87 |
iLogMode = 0; // initial value : not running any log
|
sl@0
|
88 |
iConsole = NULL;
|
sl@0
|
89 |
iFileLogger = NULL;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
/**
|
sl@0
|
93 |
*
|
sl@0
|
94 |
* Test Framework server destructor
|
sl@0
|
95 |
*
|
sl@0
|
96 |
* @xxxx
|
sl@0
|
97 |
*
|
sl@0
|
98 |
*/
|
sl@0
|
99 |
CTestFrameworkServer::~CTestFrameworkServer()
|
sl@0
|
100 |
{
|
sl@0
|
101 |
CloseLog();
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
/**
|
sl@0
|
105 |
*
|
sl@0
|
106 |
* Create new server session.
|
sl@0
|
107 |
*
|
sl@0
|
108 |
* @param "const TVersion &aVersion"
|
sl@0
|
109 |
* Server version (required)
|
sl@0
|
110 |
*
|
sl@0
|
111 |
* @return "CSharableSession*"
|
sl@0
|
112 |
* The created server session.
|
sl@0
|
113 |
*
|
sl@0
|
114 |
* @xxxx
|
sl@0
|
115 |
*
|
sl@0
|
116 |
*/
|
sl@0
|
117 |
CMmfIpcSession* CTestFrameworkServer::NewSessionL(const TVersion &aVersion) const
|
sl@0
|
118 |
{
|
sl@0
|
119 |
TVersion ver(KTestFrameworkServerMajorVersionNumber,
|
sl@0
|
120 |
KTestFrameworkServerMinorVersionNumber,
|
sl@0
|
121 |
KTestFrameworkServerBuildVersionNumber);
|
sl@0
|
122 |
if (!User::QueryVersionSupported(ver, aVersion))
|
sl@0
|
123 |
User::Leave(KErrNotSupported);
|
sl@0
|
124 |
// make new session
|
sl@0
|
125 |
return new(ELeave) CTestFrameworkServerSession();
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
/**
|
sl@0
|
129 |
*
|
sl@0
|
130 |
* Add a server session.
|
sl@0
|
131 |
*
|
sl@0
|
132 |
* @xxxx
|
sl@0
|
133 |
*
|
sl@0
|
134 |
*/
|
sl@0
|
135 |
void CTestFrameworkServer::AddSession()
|
sl@0
|
136 |
{
|
sl@0
|
137 |
++iSessionCount;
|
sl@0
|
138 |
iShutdown.Cancel();
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
/**
|
sl@0
|
142 |
*
|
sl@0
|
143 |
* Drop a server session.
|
sl@0
|
144 |
*
|
sl@0
|
145 |
* @xxxx
|
sl@0
|
146 |
*
|
sl@0
|
147 |
*/
|
sl@0
|
148 |
void CTestFrameworkServer::DropSession()
|
sl@0
|
149 |
{
|
sl@0
|
150 |
if (--iSessionCount <= 0)
|
sl@0
|
151 |
iShutdown.Start();
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
/**
|
sl@0
|
155 |
*
|
sl@0
|
156 |
* Add an input window (at request from client).
|
sl@0
|
157 |
*
|
sl@0
|
158 |
* @param "CTestFrameworkServerSession* aOwner"
|
sl@0
|
159 |
* Window owning server session
|
sl@0
|
160 |
*
|
sl@0
|
161 |
* @xxxx
|
sl@0
|
162 |
*
|
sl@0
|
163 |
*/
|
sl@0
|
164 |
void CTestFrameworkServer::AddInputWindowL(CTestFrameworkServerSession* aOwner)
|
sl@0
|
165 |
{
|
sl@0
|
166 |
if (iInputWindow.HasOwner())
|
sl@0
|
167 |
User::Leave(KErrAlreadyExists);
|
sl@0
|
168 |
// else
|
sl@0
|
169 |
iInputWindow.SetOwner(aOwner);
|
sl@0
|
170 |
TRect rect;
|
sl@0
|
171 |
rect.iTl = TPoint(0,0);
|
sl@0
|
172 |
rect.iBr = TPoint(KConsFullScreen, KConsFullScreen);
|
sl@0
|
173 |
iInputWindow.SetWinRectAndNotifyOwner(rect);
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
/**
|
sl@0
|
177 |
*
|
sl@0
|
178 |
* Remove an input window (at request from client).
|
sl@0
|
179 |
*
|
sl@0
|
180 |
* @param "CTestFrameworkServerSession* aOwner"
|
sl@0
|
181 |
* Window owning server session
|
sl@0
|
182 |
*
|
sl@0
|
183 |
* @xxxx
|
sl@0
|
184 |
*
|
sl@0
|
185 |
*/
|
sl@0
|
186 |
void CTestFrameworkServer::RemoveWindow(CTestFrameworkServerSession* aOwner)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
if (aOwner == iInputWindow.Owner())
|
sl@0
|
189 |
{
|
sl@0
|
190 |
iInputWindow.SetOwner(NULL);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
/**
|
sl@0
|
195 |
*
|
sl@0
|
196 |
* Open a log.
|
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 (as bitmask of TTestFrameworkLogMode)
|
sl@0
|
203 |
*
|
sl@0
|
204 |
* @xxxx
|
sl@0
|
205 |
*
|
sl@0
|
206 |
*/
|
sl@0
|
207 |
void CTestFrameworkServer::OpenLogL(const TDesC& aLogName, TInt aLogMode)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
// NB we need to check if a console is already open - if so, we do NOT
|
sl@0
|
210 |
// create another one. Ditto with file / port.
|
sl@0
|
211 |
|
sl@0
|
212 |
if(aLogMode & ELogToConsole)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
if(!iConsole)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
iConsole = CServerConsole::NewL(aLogName);
|
sl@0
|
217 |
|
sl@0
|
218 |
CConsoleBase* theConsole = iConsole->Console();
|
sl@0
|
219 |
theConsole->Printf(_L("%S : Server log starting\n"), &aLogName);
|
sl@0
|
220 |
|
sl@0
|
221 |
iLogMode |= ELogToConsole;
|
sl@0
|
222 |
|
sl@0
|
223 |
if (aLogMode & ELogConsoleFull)
|
sl@0
|
224 |
iLogMode |= ELogConsoleFull;
|
sl@0
|
225 |
}
|
sl@0
|
226 |
}
|
sl@0
|
227 |
|
sl@0
|
228 |
// NB relative paths will not work with TParse (there is no file server open).
|
sl@0
|
229 |
// Exception is a bare filename (with no path) : this will be found in root of C:
|
sl@0
|
230 |
|
sl@0
|
231 |
// NOTE! We have no mechanism to notify this error. The console will display
|
sl@0
|
232 |
// and then exit. The log file cannot be opened.
|
sl@0
|
233 |
|
sl@0
|
234 |
// TO BE ENHANCED - if console is made active, then we can pause
|
sl@0
|
235 |
|
sl@0
|
236 |
if(aLogMode & ELogToFile)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
if(!iFileLogger)
|
sl@0
|
239 |
{
|
sl@0
|
240 |
TRAPD(err, iFileLogger = CFileLogger::NewL());
|
sl@0
|
241 |
if(err != KErrNone)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
// if we can't create a logger, we panic
|
sl@0
|
244 |
User::Panic(_L("TestFrameworkServer"), 1);
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
_LIT(KLogPath, "C:\\Logs\\TestResults");
|
sl@0
|
248 |
_LIT(KDefault, "C:\\.htm");
|
sl@0
|
249 |
|
sl@0
|
250 |
TParse parseLogName;
|
sl@0
|
251 |
parseLogName.Set(aLogName, NULL, NULL);
|
sl@0
|
252 |
|
sl@0
|
253 |
TFileName logFilePath;
|
sl@0
|
254 |
logFilePath = KLogPath;
|
sl@0
|
255 |
|
sl@0
|
256 |
if(parseLogName.PathPresent())
|
sl@0
|
257 |
logFilePath.Append(parseLogName.Path());
|
sl@0
|
258 |
else
|
sl@0
|
259 |
logFilePath.Append(_L("\\"));
|
sl@0
|
260 |
|
sl@0
|
261 |
|
sl@0
|
262 |
// overwrite extension if supplied with .htm
|
sl@0
|
263 |
TParse logFileFullName;
|
sl@0
|
264 |
TInt returnCode = logFileFullName.Set(KDefault, &logFilePath, &aLogName);
|
sl@0
|
265 |
if (returnCode == KErrNone)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
TInt ret = iFileLogger->Connect();
|
sl@0
|
268 |
if (ret == KErrNone)
|
sl@0
|
269 |
{
|
sl@0
|
270 |
iFileLogger->CreateLog(logFilePath, logFileFullName.NameAndExt());
|
sl@0
|
271 |
iLogMode |= ELogToFile;
|
sl@0
|
272 |
}
|
sl@0
|
273 |
}
|
sl@0
|
274 |
}
|
sl@0
|
275 |
}
|
sl@0
|
276 |
|
sl@0
|
277 |
if(aLogMode & ELogToPort)
|
sl@0
|
278 |
{
|
sl@0
|
279 |
// RDebug::Print will deal with the serial port, we don't do anything special here
|
sl@0
|
280 |
iLogMode |= ELogToPort;
|
sl@0
|
281 |
}
|
sl@0
|
282 |
}
|
sl@0
|
283 |
|
sl@0
|
284 |
/**
|
sl@0
|
285 |
*
|
sl@0
|
286 |
* Write to the log.
|
sl@0
|
287 |
*
|
sl@0
|
288 |
* @param "const TDesC& aMsg"
|
sl@0
|
289 |
* The message string to write
|
sl@0
|
290 |
*
|
sl@0
|
291 |
* @param "TInt aLogMode"
|
sl@0
|
292 |
* The log mode (as bitmask of TTestFrameworkLogMode)
|
sl@0
|
293 |
*
|
sl@0
|
294 |
* @xxxx
|
sl@0
|
295 |
*
|
sl@0
|
296 |
*/
|
sl@0
|
297 |
void CTestFrameworkServer::WriteLog(const TDesC& aMsg, TInt aLogMode)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
if(aLogMode & ELogToConsole)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
if(iConsole)
|
sl@0
|
302 |
{
|
sl@0
|
303 |
CConsoleBase* theConsole = iConsole->Console();
|
sl@0
|
304 |
theConsole->Printf(aMsg);
|
sl@0
|
305 |
theConsole->Printf(_L("\n")); // add newline
|
sl@0
|
306 |
}
|
sl@0
|
307 |
}
|
sl@0
|
308 |
|
sl@0
|
309 |
if(aLogMode & ELogToFile)
|
sl@0
|
310 |
{
|
sl@0
|
311 |
if(iFileLogger)
|
sl@0
|
312 |
{
|
sl@0
|
313 |
iFileLogger->WriteLog(aMsg);
|
sl@0
|
314 |
}
|
sl@0
|
315 |
}
|
sl@0
|
316 |
|
sl@0
|
317 |
if(aLogMode & ELogToPort)
|
sl@0
|
318 |
{
|
sl@0
|
319 |
RDebug::Print(aMsg);
|
sl@0
|
320 |
}
|
sl@0
|
321 |
}
|
sl@0
|
322 |
|
sl@0
|
323 |
/**
|
sl@0
|
324 |
*
|
sl@0
|
325 |
* Close the log.
|
sl@0
|
326 |
*
|
sl@0
|
327 |
* @xxxx
|
sl@0
|
328 |
*
|
sl@0
|
329 |
*/
|
sl@0
|
330 |
void CTestFrameworkServer::CloseLog()
|
sl@0
|
331 |
{
|
sl@0
|
332 |
if (iFileLogger != NULL)
|
sl@0
|
333 |
iFileLogger->CloseLog();
|
sl@0
|
334 |
delete(iFileLogger);
|
sl@0
|
335 |
iFileLogger = NULL;
|
sl@0
|
336 |
delete(iConsole);
|
sl@0
|
337 |
iConsole = NULL;
|
sl@0
|
338 |
iLogMode = 0;
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
/**
|
sl@0
|
342 |
*
|
sl@0
|
343 |
* Get the log status.
|
sl@0
|
344 |
*
|
sl@0
|
345 |
* @return "TInt"
|
sl@0
|
346 |
* The log status (as bitmask of TTestFrameworkLogMode)
|
sl@0
|
347 |
*
|
sl@0
|
348 |
* @xxxx
|
sl@0
|
349 |
*
|
sl@0
|
350 |
*/
|
sl@0
|
351 |
TInt CTestFrameworkServer::LogStatus() const
|
sl@0
|
352 |
{
|
sl@0
|
353 |
return iLogMode;
|
sl@0
|
354 |
}
|
sl@0
|
355 |
|
sl@0
|
356 |
|
sl@0
|
357 |
/**
|
sl@0
|
358 |
*
|
sl@0
|
359 |
* Default window constructor (no owner)
|
sl@0
|
360 |
*
|
sl@0
|
361 |
* @xxxx
|
sl@0
|
362 |
*
|
sl@0
|
363 |
*/
|
sl@0
|
364 |
TWindow::TWindow()
|
sl@0
|
365 |
{
|
sl@0
|
366 |
iOwner = NULL;
|
sl@0
|
367 |
}
|
sl@0
|
368 |
|
sl@0
|
369 |
/**
|
sl@0
|
370 |
*
|
sl@0
|
371 |
* Default window constructor
|
sl@0
|
372 |
*
|
sl@0
|
373 |
* @param "CTestFrameworkServerSession* aOwner"
|
sl@0
|
374 |
* The window owner
|
sl@0
|
375 |
* @xxxx
|
sl@0
|
376 |
*
|
sl@0
|
377 |
*/
|
sl@0
|
378 |
TWindow::TWindow(CTestFrameworkServerSession* aOwner)
|
sl@0
|
379 |
{
|
sl@0
|
380 |
iOwner = aOwner;
|
sl@0
|
381 |
}
|
sl@0
|
382 |
|
sl@0
|
383 |
/**
|
sl@0
|
384 |
*
|
sl@0
|
385 |
* Set the window owner
|
sl@0
|
386 |
*
|
sl@0
|
387 |
* @param "CTestFrameworkServerSession* aOwner"
|
sl@0
|
388 |
* The window owner
|
sl@0
|
389 |
* @xxxx
|
sl@0
|
390 |
*
|
sl@0
|
391 |
*/
|
sl@0
|
392 |
void TWindow::SetOwner(CTestFrameworkServerSession* aOwner)
|
sl@0
|
393 |
{
|
sl@0
|
394 |
iOwner = aOwner;
|
sl@0
|
395 |
}
|
sl@0
|
396 |
|
sl@0
|
397 |
/**
|
sl@0
|
398 |
*
|
sl@0
|
399 |
* Set the window rectangle, and notify owner
|
sl@0
|
400 |
*
|
sl@0
|
401 |
* @param "const TRect& aWinRect"
|
sl@0
|
402 |
* The window rectangle
|
sl@0
|
403 |
* @xxxx
|
sl@0
|
404 |
*
|
sl@0
|
405 |
*/
|
sl@0
|
406 |
void TWindow::SetWinRectAndNotifyOwner(const TRect& aWinRect)
|
sl@0
|
407 |
{
|
sl@0
|
408 |
if (HasOwner())
|
sl@0
|
409 |
iOwner->NotifyWindowChanged(aWinRect);
|
sl@0
|
410 |
}
|
sl@0
|
411 |
|
sl@0
|
412 |
/**
|
sl@0
|
413 |
*
|
sl@0
|
414 |
* Does this window have an owner?
|
sl@0
|
415 |
*
|
sl@0
|
416 |
* @return "TBool"
|
sl@0
|
417 |
* ETrue if window has an owner
|
sl@0
|
418 |
* @xxxx
|
sl@0
|
419 |
*
|
sl@0
|
420 |
*/
|
sl@0
|
421 |
TBool TWindow::HasOwner()
|
sl@0
|
422 |
{
|
sl@0
|
423 |
if (iOwner)
|
sl@0
|
424 |
return ETrue;
|
sl@0
|
425 |
return EFalse;
|
sl@0
|
426 |
}
|
sl@0
|
427 |
|
sl@0
|
428 |
/**
|
sl@0
|
429 |
*
|
sl@0
|
430 |
* Server session first-phase constructor
|
sl@0
|
431 |
*
|
sl@0
|
432 |
* @xxxx
|
sl@0
|
433 |
*
|
sl@0
|
434 |
*/
|
sl@0
|
435 |
CTestFrameworkServerSession::CTestFrameworkServerSession()
|
sl@0
|
436 |
{
|
sl@0
|
437 |
}
|
sl@0
|
438 |
|
sl@0
|
439 |
/**
|
sl@0
|
440 |
*
|
sl@0
|
441 |
* Create a server session.
|
sl@0
|
442 |
*
|
sl@0
|
443 |
* @param "aServer"
|
sl@0
|
444 |
* The server to add this session to
|
sl@0
|
445 |
*
|
sl@0
|
446 |
* @xxxx
|
sl@0
|
447 |
*
|
sl@0
|
448 |
*/
|
sl@0
|
449 |
void CTestFrameworkServerSession::CreateL(const CMmfIpcServer& aServer)
|
sl@0
|
450 |
{
|
sl@0
|
451 |
CMmfIpcSession::CreateL(aServer); // does not leave
|
sl@0
|
452 |
//Add session to server first. If anything leaves, it will be removed by the destructor
|
sl@0
|
453 |
iServer = STATIC_CAST(CTestFrameworkServer*, (CONST_CAST(CMmfIpcServer*, &aServer)));
|
sl@0
|
454 |
iServer->AddSession();
|
sl@0
|
455 |
ConstructL();
|
sl@0
|
456 |
}
|
sl@0
|
457 |
|
sl@0
|
458 |
/**
|
sl@0
|
459 |
*
|
sl@0
|
460 |
* Server session second-phase constructor
|
sl@0
|
461 |
*
|
sl@0
|
462 |
* @xxxx
|
sl@0
|
463 |
*
|
sl@0
|
464 |
*/
|
sl@0
|
465 |
void CTestFrameworkServerSession::ConstructL()
|
sl@0
|
466 |
{
|
sl@0
|
467 |
}
|
sl@0
|
468 |
|
sl@0
|
469 |
/**
|
sl@0
|
470 |
*
|
sl@0
|
471 |
* Server session destructor
|
sl@0
|
472 |
*
|
sl@0
|
473 |
* @xxxx
|
sl@0
|
474 |
*
|
sl@0
|
475 |
*/
|
sl@0
|
476 |
CTestFrameworkServerSession::~CTestFrameworkServerSession()
|
sl@0
|
477 |
{
|
sl@0
|
478 |
iServer->RemoveWindow(this);
|
sl@0
|
479 |
iServer->DropSession();
|
sl@0
|
480 |
}
|
sl@0
|
481 |
|
sl@0
|
482 |
/**
|
sl@0
|
483 |
*
|
sl@0
|
484 |
* Server session service function
|
sl@0
|
485 |
*
|
sl@0
|
486 |
* @param "aMessage"
|
sl@0
|
487 |
* The message to be serviced.
|
sl@0
|
488 |
*
|
sl@0
|
489 |
* @xxxx
|
sl@0
|
490 |
*
|
sl@0
|
491 |
*/
|
sl@0
|
492 |
void CTestFrameworkServerSession::ServiceL(const RMmfIpcMessage& aMessage)
|
sl@0
|
493 |
{
|
sl@0
|
494 |
switch (aMessage.Function())
|
sl@0
|
495 |
{
|
sl@0
|
496 |
case ECreateInputWindow:
|
sl@0
|
497 |
SetOwnCopyOfWindowMessageL(aMessage);
|
sl@0
|
498 |
iServer->AddInputWindowL(this);
|
sl@0
|
499 |
break;
|
sl@0
|
500 |
case ENotifyIfWindowChange:
|
sl@0
|
501 |
SetOwnCopyOfWindowMessageL(aMessage);
|
sl@0
|
502 |
break;
|
sl@0
|
503 |
case ECancelNotifyIfWindowChange:
|
sl@0
|
504 |
CompleteOwnCopyOfWindowMessage(KErrCancel);
|
sl@0
|
505 |
aMessage.Complete(KErrNone);
|
sl@0
|
506 |
break;
|
sl@0
|
507 |
|
sl@0
|
508 |
// logging messages
|
sl@0
|
509 |
|
sl@0
|
510 |
case EOpenLog:
|
sl@0
|
511 |
{
|
sl@0
|
512 |
TBuf<KMaxLogFilenameLength> msgBuf;
|
sl@0
|
513 |
|
sl@0
|
514 |
TInt r = MmfMessageUtilX::Read(aMessage, 0, msgBuf);
|
sl@0
|
515 |
if (r != KErrNone)
|
sl@0
|
516 |
RunError(aMessage, r);
|
sl@0
|
517 |
else
|
sl@0
|
518 |
{
|
sl@0
|
519 |
iServer->OpenLogL(msgBuf, aMessage.Int1());
|
sl@0
|
520 |
aMessage.Complete(KErrNone);
|
sl@0
|
521 |
}
|
sl@0
|
522 |
}
|
sl@0
|
523 |
break;
|
sl@0
|
524 |
|
sl@0
|
525 |
case EWriteLog:
|
sl@0
|
526 |
{
|
sl@0
|
527 |
TBuf<KMaxLogLineLength> msgBuf;
|
sl@0
|
528 |
|
sl@0
|
529 |
TInt r = MmfMessageUtilX::Read(aMessage, 0, msgBuf);
|
sl@0
|
530 |
|
sl@0
|
531 |
if (r != KErrNone)
|
sl@0
|
532 |
RunError(aMessage, r);
|
sl@0
|
533 |
else
|
sl@0
|
534 |
{
|
sl@0
|
535 |
iServer->WriteLog(msgBuf, aMessage.Int1());
|
sl@0
|
536 |
aMessage.Complete(KErrNone);
|
sl@0
|
537 |
}
|
sl@0
|
538 |
}
|
sl@0
|
539 |
break;
|
sl@0
|
540 |
|
sl@0
|
541 |
case ECloseLog:
|
sl@0
|
542 |
iServer->CloseLog();
|
sl@0
|
543 |
aMessage.Complete(KErrNone);
|
sl@0
|
544 |
break;
|
sl@0
|
545 |
|
sl@0
|
546 |
case ELogStatus:
|
sl@0
|
547 |
{
|
sl@0
|
548 |
TPckgBuf<TInt> countPckg(iServer->LogStatus());
|
sl@0
|
549 |
TInt r = MmfMessageUtilX::Write(aMessage, 0, countPckg);
|
sl@0
|
550 |
if (r != KErrNone)
|
sl@0
|
551 |
RunError(aMessage, r);
|
sl@0
|
552 |
else
|
sl@0
|
553 |
aMessage.Complete(KErrNone);
|
sl@0
|
554 |
}
|
sl@0
|
555 |
break;
|
sl@0
|
556 |
|
sl@0
|
557 |
default:
|
sl@0
|
558 |
// ? should panic here
|
sl@0
|
559 |
break;
|
sl@0
|
560 |
}
|
sl@0
|
561 |
}
|
sl@0
|
562 |
|
sl@0
|
563 |
/**
|
sl@0
|
564 |
*
|
sl@0
|
565 |
* Error handler for server session.
|
sl@0
|
566 |
* Completes the pending message using the error code
|
sl@0
|
567 |
*
|
sl@0
|
568 |
* @param "TInt aError"
|
sl@0
|
569 |
* The error code
|
sl@0
|
570 |
*
|
sl@0
|
571 |
* @return "TInt"
|
sl@0
|
572 |
* The error code (always KErrNone)
|
sl@0
|
573 |
*
|
sl@0
|
574 |
* @xxxx
|
sl@0
|
575 |
*
|
sl@0
|
576 |
*/
|
sl@0
|
577 |
TInt CTestFrameworkServerSession::RunError(const RMmfIpcMessage& aMessage, TInt aError)
|
sl@0
|
578 |
{
|
sl@0
|
579 |
aMessage.Complete(aError);
|
sl@0
|
580 |
return KErrNone;
|
sl@0
|
581 |
}
|
sl@0
|
582 |
|
sl@0
|
583 |
/**
|
sl@0
|
584 |
*
|
sl@0
|
585 |
* Set own copy of message.
|
sl@0
|
586 |
* Helper function to enable window change notification.
|
sl@0
|
587 |
*
|
sl@0
|
588 |
* @param "aMessage"
|
sl@0
|
589 |
* The message to be serviced.
|
sl@0
|
590 |
*
|
sl@0
|
591 |
* @xxxx
|
sl@0
|
592 |
*
|
sl@0
|
593 |
*/
|
sl@0
|
594 |
void CTestFrameworkServerSession::SetOwnCopyOfWindowMessageL(const RMmfIpcMessage& aMessage)
|
sl@0
|
595 |
{
|
sl@0
|
596 |
if (iCanCompleteWindowMessage)
|
sl@0
|
597 |
User::Leave(KErrAlreadyExists);
|
sl@0
|
598 |
//else
|
sl@0
|
599 |
iWindowMessage = aMessage;
|
sl@0
|
600 |
iCanCompleteWindowMessage = ETrue;
|
sl@0
|
601 |
|
sl@0
|
602 |
if (iNeedToNotifyClientOfWindowSizeChange)
|
sl@0
|
603 |
{
|
sl@0
|
604 |
TInt err = MmfMessageUtil::Write(iWindowMessage, 0, iWinRectBuf);
|
sl@0
|
605 |
CompleteOwnCopyOfWindowMessage(err);
|
sl@0
|
606 |
iNeedToNotifyClientOfWindowSizeChange = EFalse;
|
sl@0
|
607 |
}
|
sl@0
|
608 |
}
|
sl@0
|
609 |
|
sl@0
|
610 |
/**
|
sl@0
|
611 |
*
|
sl@0
|
612 |
* Complete own copy of message.
|
sl@0
|
613 |
* Helper function to enable window change notification.
|
sl@0
|
614 |
*
|
sl@0
|
615 |
* @param "TInt aReason"
|
sl@0
|
616 |
* The message return code.
|
sl@0
|
617 |
*
|
sl@0
|
618 |
* @xxxx
|
sl@0
|
619 |
*
|
sl@0
|
620 |
*/
|
sl@0
|
621 |
void CTestFrameworkServerSession::CompleteOwnCopyOfWindowMessage(TInt aReason)
|
sl@0
|
622 |
{
|
sl@0
|
623 |
if (iCanCompleteWindowMessage)
|
sl@0
|
624 |
iWindowMessage.Complete(aReason);
|
sl@0
|
625 |
iCanCompleteWindowMessage = EFalse;
|
sl@0
|
626 |
}
|
sl@0
|
627 |
|
sl@0
|
628 |
/**
|
sl@0
|
629 |
*
|
sl@0
|
630 |
* Window change notification.
|
sl@0
|
631 |
*
|
sl@0
|
632 |
* @param "const TRect& aWinRect"
|
sl@0
|
633 |
* The window rectangle.
|
sl@0
|
634 |
*
|
sl@0
|
635 |
* @xxxx
|
sl@0
|
636 |
*
|
sl@0
|
637 |
*/
|
sl@0
|
638 |
void CTestFrameworkServerSession::NotifyWindowChanged(const TRect& aWinRect)
|
sl@0
|
639 |
{
|
sl@0
|
640 |
iWinRectBuf() = aWinRect;
|
sl@0
|
641 |
|
sl@0
|
642 |
if (iCanCompleteWindowMessage)
|
sl@0
|
643 |
{
|
sl@0
|
644 |
TInt err = MmfMessageUtilX::Write(iWindowMessage, 0, iWinRectBuf);
|
sl@0
|
645 |
CompleteOwnCopyOfWindowMessage(err);
|
sl@0
|
646 |
}
|
sl@0
|
647 |
else
|
sl@0
|
648 |
{
|
sl@0
|
649 |
iNeedToNotifyClientOfWindowSizeChange = ETrue;
|
sl@0
|
650 |
}
|
sl@0
|
651 |
}
|
sl@0
|
652 |
|
sl@0
|
653 |
// EXE/DLL initialisation
|
sl@0
|
654 |
|
sl@0
|
655 |
// NOTE! None of this should be built when compiling for Unit Testing
|
sl@0
|
656 |
#if !defined (__TSU_TESTFRAMEWORK__)
|
sl@0
|
657 |
|
sl@0
|
658 |
|
sl@0
|
659 |
/**
|
sl@0
|
660 |
*
|
sl@0
|
661 |
* Perform all server initialisation, in particular creation of the
|
sl@0
|
662 |
* scheduler and server; then run the scheduler
|
sl@0
|
663 |
*
|
sl@0
|
664 |
*
|
sl@0
|
665 |
* @xxxx
|
sl@0
|
666 |
*
|
sl@0
|
667 |
*/
|
sl@0
|
668 |
static void RunServerL()
|
sl@0
|
669 |
{
|
sl@0
|
670 |
// create and install the active scheduler we need
|
sl@0
|
671 |
CActiveScheduler* s = new(ELeave) CActiveScheduler;
|
sl@0
|
672 |
CleanupStack::PushL(s);
|
sl@0
|
673 |
CActiveScheduler::Install(s);
|
sl@0
|
674 |
//
|
sl@0
|
675 |
// create the server (leave it on the cleanup stack)
|
sl@0
|
676 |
CleanupStack::PushL(CTestFrameworkServer::NewL());
|
sl@0
|
677 |
//
|
sl@0
|
678 |
// Initialisation complete, now signal the client
|
sl@0
|
679 |
RProcess::Rendezvous(KErrNone);
|
sl@0
|
680 |
|
sl@0
|
681 |
//
|
sl@0
|
682 |
// Ready to run
|
sl@0
|
683 |
CActiveScheduler::Start();
|
sl@0
|
684 |
//
|
sl@0
|
685 |
// Cleanup the server and scheduler
|
sl@0
|
686 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
687 |
}
|
sl@0
|
688 |
|
sl@0
|
689 |
/**
|
sl@0
|
690 |
*
|
sl@0
|
691 |
* Main entry point for the server thread
|
sl@0
|
692 |
*
|
sl@0
|
693 |
* @param "TTestFrameworkServerStart& aStart"
|
sl@0
|
694 |
* The server starter.
|
sl@0
|
695 |
*
|
sl@0
|
696 |
* @xxxx
|
sl@0
|
697 |
*
|
sl@0
|
698 |
*/
|
sl@0
|
699 |
static TInt RunServer()
|
sl@0
|
700 |
{
|
sl@0
|
701 |
__UHEAP_MARK;
|
sl@0
|
702 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
703 |
TInt r = KErrNoMemory;
|
sl@0
|
704 |
if (cleanup)
|
sl@0
|
705 |
{
|
sl@0
|
706 |
TRAP(r, RunServerL());
|
sl@0
|
707 |
delete cleanup;
|
sl@0
|
708 |
}
|
sl@0
|
709 |
//
|
sl@0
|
710 |
__UHEAP_MARKEND;
|
sl@0
|
711 |
return r;
|
sl@0
|
712 |
}
|
sl@0
|
713 |
|
sl@0
|
714 |
|
sl@0
|
715 |
GLDEF_C TInt E32Main()
|
sl@0
|
716 |
|
sl@0
|
717 |
// Server process entry-point
|
sl@0
|
718 |
// Recover the startup parameters and run the server
|
sl@0
|
719 |
|
sl@0
|
720 |
{
|
sl@0
|
721 |
TInt r = RunServer();
|
sl@0
|
722 |
return r;
|
sl@0
|
723 |
}
|
sl@0
|
724 |
|
sl@0
|
725 |
|
sl@0
|
726 |
#endif // __TSU_TESTFRAMEWORK__
|