|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This module contains the implementation of |
|
15 * CTestServerThreadStarter class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "TestServerThreadStarter.h" |
|
21 #include <stifinternal/TestServerClient.h> |
|
22 |
|
23 // EXTERNAL DATA STRUCTURES |
|
24 // None |
|
25 |
|
26 // EXTERNAL FUNCTION PROTOTYPES |
|
27 // None |
|
28 |
|
29 // CONSTANTS |
|
30 // None |
|
31 |
|
32 // MACROS |
|
33 // None |
|
34 |
|
35 /** |
|
36 * CTestServerThreadStarter thread heap size. |
|
37 */ |
|
38 const TUint KDefaultHeapSize = 0x10000; // 64 K |
|
39 |
|
40 /** |
|
41 * CTestServerThreadStarter thread max heap size. |
|
42 */ |
|
43 const TUint KMaxHeapSize = 0x20000; // 128 K |
|
44 |
|
45 // LOCAL CONSTANTS AND MACROS |
|
46 // None |
|
47 |
|
48 // MODULE DATA STRUCTURES |
|
49 // None |
|
50 |
|
51 // LOCAL FUNCTION PROTOTYPES |
|
52 // None |
|
53 |
|
54 // FORWARD DECLARATIONS |
|
55 // None |
|
56 |
|
57 |
|
58 // ================= MEMBER FUNCTIONS ========================================= |
|
59 |
|
60 /* |
|
61 ------------------------------------------------------------------------------- |
|
62 |
|
63 Class: CTestServerThreadStarter |
|
64 |
|
65 Method: TestServerStarterThreadFunction |
|
66 |
|
67 Description: CTestServerThreadStarter thread function. |
|
68 |
|
69 CTestServerThreadStarter thread function in which testserver creation code |
|
70 is executed. |
|
71 |
|
72 Parameters: TAny* aParameters: in: Pointer to CTestServerThreadStarter object |
|
73 |
|
74 Return Values: None. |
|
75 |
|
76 Errors/Exceptions: None. |
|
77 |
|
78 Status: Draft |
|
79 |
|
80 ------------------------------------------------------------------------------- |
|
81 */ |
|
82 TInt CTestServerThreadStarter::TestServerStarterThreadFunction( TAny* aParameters ) |
|
83 { |
|
84 RDebug::Printf( "UITESTING: CTestServerThreadStarter::TestServerStarterThreadFunction" ); |
|
85 |
|
86 CTestServerThreadStarter* testServerStarter = (CTestServerThreadStarter*)aParameters; |
|
87 TThreadId mainThreadId = testServerStarter->iMainThreadId; |
|
88 CTestThreadContainerRunnerFactory* testThreadContainerRunnerFactory = |
|
89 testServerStarter->iTestThreadContainerRunnerFactory; |
|
90 |
|
91 // Signal that all needed data is copied and main thread can continue its execution |
|
92 testServerStarter->iServerThreadStartedSemaphore.Signal(); |
|
93 |
|
94 // Get module name from command line |
|
95 const TInt length = User().CommandLineLength(); |
|
96 |
|
97 HBufC* cmdLine = HBufC::New( length ); |
|
98 |
|
99 if ( cmdLine == NULL ) |
|
100 { |
|
101 return KErrNoMemory; |
|
102 } |
|
103 |
|
104 TPtr moduleName = cmdLine->Des(); |
|
105 |
|
106 User().CommandLine( moduleName ); |
|
107 |
|
108 RDebug::Print (moduleName); |
|
109 |
|
110 // Open start-up synchronization semaphore |
|
111 RSemaphore startup; |
|
112 RDebug::Print(_L(" Openingstart-up semaphore")); |
|
113 TName semaphoreName = _L("startupSemaphore"); |
|
114 semaphoreName.Append( moduleName ); |
|
115 |
|
116 TInt res = startup.OpenGlobal(semaphoreName); |
|
117 RDebug::Print(_L("Opening result %d"), res); |
|
118 |
|
119 |
|
120 TFileName serverName; |
|
121 TInt r = StartNewServer ( moduleName, serverName, EFalse, startup, true, testThreadContainerRunnerFactory ); |
|
122 |
|
123 if ( r == KErrAlreadyExists ) |
|
124 { |
|
125 // Ok, server was already started |
|
126 RDebug::Print(_L("UI TestServer already started, signaling semaphore and existing")); |
|
127 startup.Signal(); |
|
128 |
|
129 delete cmdLine; |
|
130 |
|
131 return KErrNone; |
|
132 } |
|
133 else |
|
134 { |
|
135 RDebug::Print(_L("UI TestServer is finished, code %d"), r); |
|
136 } |
|
137 |
|
138 delete cmdLine; |
|
139 |
|
140 //delete testThreadContainerRunnerFactory; |
|
141 testThreadContainerRunnerFactory = NULL; |
|
142 |
|
143 // Kill main thread to end UITestServerStarter application |
|
144 // when testserver is finished |
|
145 RThread mainThread; |
|
146 TInt ret = mainThread.Open( mainThreadId ); |
|
147 if( ret != KErrNone ) |
|
148 { |
|
149 User::Panic( _L("ThreadHandleOpenError"), ret ); |
|
150 } |
|
151 mainThread.Kill( KErrNone ); |
|
152 |
|
153 return r; |
|
154 } |
|
155 |
|
156 /* |
|
157 ------------------------------------------------------------------------------- |
|
158 |
|
159 Class: CTestServerThreadStarter |
|
160 |
|
161 Method: NewL |
|
162 |
|
163 Description: NewL is first phase of two-phased constructor. |
|
164 |
|
165 NewL is first phase of two-phased constructor. |
|
166 |
|
167 Parameters: None. |
|
168 |
|
169 Return Values: Pointer to new CTestServerThreadStarter object. |
|
170 |
|
171 Errors/Exceptions: Leaves if new or ConstructL leaves. |
|
172 |
|
173 Status: Draft |
|
174 |
|
175 ------------------------------------------------------------------------------- |
|
176 */ |
|
177 CTestServerThreadStarter* CTestServerThreadStarter::NewL( ) |
|
178 { |
|
179 CTestServerThreadStarter* self = new(ELeave) CTestServerThreadStarter(); |
|
180 CleanupStack::PushL( self ); |
|
181 self->ConstructL(); |
|
182 CleanupStack::Pop( self ); |
|
183 return self; |
|
184 } |
|
185 |
|
186 /* |
|
187 ------------------------------------------------------------------------------- |
|
188 |
|
189 Class: CTestServerThreadStarter |
|
190 |
|
191 Method: CTestServerThreadStarter |
|
192 |
|
193 Description: Default constructor. |
|
194 |
|
195 Default constructor. |
|
196 |
|
197 Parameters: None. |
|
198 |
|
199 Return Values: None. |
|
200 |
|
201 Errors/Exceptions: None. |
|
202 |
|
203 Status: Draft |
|
204 |
|
205 ------------------------------------------------------------------------------- |
|
206 */ |
|
207 CTestServerThreadStarter::CTestServerThreadStarter() |
|
208 :CActive( EPriorityNormal ) |
|
209 { |
|
210 } |
|
211 |
|
212 /* |
|
213 ------------------------------------------------------------------------------- |
|
214 |
|
215 Class: CTestServerThreadStarter |
|
216 |
|
217 Method: NewL |
|
218 |
|
219 Description: Default destructor. |
|
220 |
|
221 Default destructor. |
|
222 |
|
223 Parameters: None. |
|
224 |
|
225 Return Values: None. |
|
226 |
|
227 Errors/Exceptions: None. |
|
228 |
|
229 Status: Draft |
|
230 |
|
231 ------------------------------------------------------------------------------- |
|
232 */ |
|
233 CTestServerThreadStarter::~CTestServerThreadStarter() |
|
234 { |
|
235 Cancel(); |
|
236 iTimer.Close(); |
|
237 } |
|
238 |
|
239 /* |
|
240 ------------------------------------------------------------------------------- |
|
241 |
|
242 Class: CTestServerThreadStarter |
|
243 |
|
244 Method: ConstructL |
|
245 |
|
246 Description: Second phase of two-phased constructor. |
|
247 |
|
248 Second phase of two-phased constructor. |
|
249 |
|
250 Parameters: None. |
|
251 |
|
252 Return Values: None. |
|
253 |
|
254 Errors/Exceptions: None. |
|
255 |
|
256 Status: Draft |
|
257 |
|
258 ------------------------------------------------------------------------------- |
|
259 */ |
|
260 void CTestServerThreadStarter::ConstructL() |
|
261 { |
|
262 TInt ret = iTimer.CreateLocal(); |
|
263 if ( ret != KErrNone ) |
|
264 { |
|
265 User::Leave( ret ); |
|
266 } |
|
267 |
|
268 CActiveScheduler::Add( this ); |
|
269 } |
|
270 |
|
271 /* |
|
272 ------------------------------------------------------------------------------- |
|
273 |
|
274 Class: CTestServerThreadStarter |
|
275 |
|
276 Method: RunTestServerThread |
|
277 |
|
278 Description: Starts-up testserver. |
|
279 |
|
280 Starts-up testserver. |
|
281 |
|
282 Parameters: None. |
|
283 |
|
284 Return Values: KErrNone when there was no error. |
|
285 |
|
286 Errors/Exceptions: None. |
|
287 |
|
288 Status: Draft |
|
289 |
|
290 ------------------------------------------------------------------------------- |
|
291 */ |
|
292 TInt CTestServerThreadStarter::RunTestServerThread( CTestThreadContainerRunnerFactory* aTestThreadContainerRunnerFactory ) |
|
293 { |
|
294 if ( IsActive() ) |
|
295 { |
|
296 User::Panic( _L("E32USER-CBase"), 42 ); |
|
297 } |
|
298 |
|
299 TInt ret = iServerThreadStartedSemaphore.CreateLocal( 0 ); |
|
300 if ( ret != KErrNone ) |
|
301 { |
|
302 User::Leave( ret ); |
|
303 } |
|
304 |
|
305 iTestThreadContainerRunnerFactory = aTestThreadContainerRunnerFactory; |
|
306 iMainThreadId = RThread().Id(); |
|
307 iReturnCode = KErrNone; |
|
308 |
|
309 iStatus = KRequestPending; |
|
310 |
|
311 SetActive(); |
|
312 iTimer.After( iStatus, 0 ); |
|
313 |
|
314 return KErrNone; |
|
315 } |
|
316 |
|
317 /* |
|
318 ------------------------------------------------------------------------------- |
|
319 |
|
320 Class: CTestServerThreadStarter |
|
321 |
|
322 Method: RunL |
|
323 |
|
324 Description: RunL derived from CActive handles the completed requests. |
|
325 |
|
326 RunL derived from CActive handles the completed requests. |
|
327 |
|
328 Parameters: None. |
|
329 |
|
330 Return Values: None. |
|
331 |
|
332 Errors/Exceptions: Leaves if one of the called method leavs. |
|
333 |
|
334 Status: Draft |
|
335 |
|
336 ------------------------------------------------------------------------------- |
|
337 */ |
|
338 void CTestServerThreadStarter::RunL() |
|
339 { |
|
340 RThread testServerStarterThread; |
|
341 TInt ret = testServerStarterThread.Create( _L("testserverstarterthread"), |
|
342 TestServerStarterThreadFunction, 10 * KDefaultStackSize, 10 * KDefaultHeapSize, 10 * KMaxHeapSize, this ); |
|
343 |
|
344 User::LeaveIfError( ret ); |
|
345 |
|
346 testServerStarterThread.Resume(); |
|
347 testServerStarterThread.Close(); |
|
348 |
|
349 iServerThreadStartedSemaphore.Wait(); |
|
350 iServerThreadStartedSemaphore.Close(); |
|
351 |
|
352 // Delete CTestServerThreadStarter after testserver is started |
|
353 delete this; |
|
354 } |
|
355 |
|
356 /* |
|
357 ------------------------------------------------------------------------------- |
|
358 |
|
359 Class: CTestServerThreadStarter |
|
360 |
|
361 Method: DoCancel |
|
362 |
|
363 Description: DoCancel derived from CActive handles the Cancel. |
|
364 |
|
365 DoCancel derived from CActive handles the Cancel. |
|
366 |
|
367 Parameters: None. |
|
368 |
|
369 Return Values: None. |
|
370 |
|
371 Errors/Exceptions: None. |
|
372 |
|
373 Status: Draft |
|
374 |
|
375 ------------------------------------------------------------------------------- |
|
376 */ |
|
377 void CTestServerThreadStarter::DoCancel() |
|
378 { |
|
379 if ( IsActive() ) |
|
380 { |
|
381 iTimer.Cancel(); |
|
382 } |
|
383 } |
|
384 |
|
385 // End of File |