2
|
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 contain implementation of RSettingServer
|
|
15 |
* class member functions.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include <e32svr.h>
|
|
21 |
#include <SettingServerClient.h>
|
|
22 |
#include "SettingServerClientServer.h"
|
|
23 |
#include "SettingServer.h"
|
|
24 |
|
|
25 |
// EXTERNAL DATA STRUCTURES
|
|
26 |
|
|
27 |
// EXTERNAL FUNCTION PROTOTYPES
|
|
28 |
|
|
29 |
// CONSTANTS
|
|
30 |
_LIT( KSettingServerName, "StifSettingServer" );
|
|
31 |
|
|
32 |
// MACROS
|
|
33 |
|
|
34 |
// LOCAL CONSTANTS AND MACROS
|
|
35 |
|
|
36 |
// MODULE DATA STRUCTURES
|
|
37 |
|
|
38 |
// LOCAL FUNCTION PROTOTYPES
|
|
39 |
|
|
40 |
// FORWARD DECLARATIONS
|
|
41 |
|
|
42 |
// ==================== LOCAL FUNCTIONS =======================================
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Panics settings server thread
|
|
46 |
*/
|
|
47 |
void PanicSettingServer( const TSettingServerPanic aPanic )
|
|
48 |
{
|
|
49 |
RDebug::Print( _L( "CSettingServer::PanicServer" ) );
|
|
50 |
_LIT( KTxtServer,"CSettingServer" );
|
|
51 |
User::Panic( KTxtServer,aPanic );
|
|
52 |
}
|
|
53 |
|
|
54 |
/*
|
|
55 |
-------------------------------------------------------------------------------
|
|
56 |
|
|
57 |
Class: None
|
|
58 |
|
|
59 |
Method: SettingServerThreadFunction
|
|
60 |
|
|
61 |
Description: The thread function, where Setting Server lives in
|
|
62 |
|
|
63 |
Parameters: TAny* aStartInfo aName: in: Start-up information
|
|
64 |
|
|
65 |
Return Values: TInt: Result from server start
|
|
66 |
|
|
67 |
Errors/Exceptions: Panics current thread if:
|
|
68 |
Invalid start-up information
|
|
69 |
Clean-up stack can't be created
|
|
70 |
Setting Server can't be started
|
|
71 |
|
|
72 |
Status: Proposal
|
|
73 |
|
|
74 |
-------------------------------------------------------------------------------
|
|
75 |
*/
|
|
76 |
TInt SettingServerThreadFunction( TAny* aStarted )
|
|
77 |
{
|
|
78 |
__UHEAP_MARK;
|
|
79 |
|
|
80 |
// Get start-up information
|
|
81 |
TThreadStartSetting* startInfo = ( TThreadStartSetting* ) aStarted;
|
|
82 |
__ASSERT_ALWAYS( startInfo,PanicSettingServer( ENoStartupInformation ) );
|
|
83 |
|
|
84 |
// Create clean-up stack
|
|
85 |
CTrapCleanup* tc = CTrapCleanup::New();
|
|
86 |
__ASSERT_ALWAYS( tc, PanicSettingServer(ECreateTrapCleanup));
|
|
87 |
|
|
88 |
// Construct and install active scheduler
|
|
89 |
CActiveScheduler* scheduler = new CActiveScheduler;
|
|
90 |
__ASSERT_ALWAYS( scheduler, PanicSettingServer( EMainSchedulerError ) );
|
|
91 |
CActiveScheduler::Install( scheduler );
|
|
92 |
|
|
93 |
// Construct server
|
|
94 |
CSettingServer* server = NULL;
|
|
95 |
RDebug::Print( startInfo->iName );
|
|
96 |
TRAPD( err, server = CSettingServer::NewL( startInfo->iName ) );
|
|
97 |
__ASSERT_ALWAYS( !err, PanicSettingServer( ESvrCreateServer ) );
|
|
98 |
|
|
99 |
// Inform that we are up and running
|
|
100 |
startInfo->iStartupResult = KErrNone;
|
|
101 |
startInfo->iStarted.Signal();
|
|
102 |
|
|
103 |
// Start handling requests
|
|
104 |
CActiveScheduler::Start();
|
|
105 |
|
|
106 |
// Execution continues from here after CActiveScheduler::Stop
|
|
107 |
|
|
108 |
// Delete the server. This should be deleted before scheduler,
|
|
109 |
// if server still has any active objects
|
|
110 |
delete server;
|
|
111 |
server = NULL;
|
|
112 |
|
|
113 |
// Delete scheduler.
|
|
114 |
delete scheduler;
|
|
115 |
scheduler = NULL;
|
|
116 |
|
|
117 |
// Delete clean-up stack
|
|
118 |
delete tc;
|
|
119 |
tc = NULL;
|
|
120 |
|
|
121 |
__UHEAP_MARKEND;
|
|
122 |
|
|
123 |
return KErrNone;
|
|
124 |
|
|
125 |
}
|
|
126 |
|
|
127 |
/*
|
|
128 |
-------------------------------------------------------------------------------
|
|
129 |
|
|
130 |
Class: -
|
|
131 |
|
|
132 |
Method: StartNewServer
|
|
133 |
|
|
134 |
Description: Starts a new server. Server will be running its own
|
|
135 |
thread and this functions returns when server is up and running or
|
|
136 |
server start-up fails.
|
|
137 |
|
|
138 |
Parameters: TName& aServerName: inout: The name of the server
|
|
139 |
|
|
140 |
Return Values: TInt: Symbian error code
|
|
141 |
|
|
142 |
Errors/Exceptions: None
|
|
143 |
|
|
144 |
Status: Proposal
|
|
145 |
|
|
146 |
-------------------------------------------------------------------------------
|
|
147 |
*/
|
|
148 |
EXPORT_C TInt StartNewSettingServer()
|
|
149 |
{
|
|
150 |
__UHEAP_MARK;
|
|
151 |
|
|
152 |
//Ccheck server not already started
|
|
153 |
TFindServer findServer( KSettingServerName );
|
|
154 |
TFullName name;
|
|
155 |
if( findServer.Next( name ) == KErrNone )
|
|
156 |
{
|
|
157 |
// Server already started, nothing to do
|
|
158 |
__UHEAP_MARKEND;
|
|
159 |
return KErrAlreadyExists;
|
|
160 |
}
|
|
161 |
|
|
162 |
// Construct start-up information object
|
|
163 |
TThreadStartSetting* startInfo = new TThreadStartSetting();
|
|
164 |
if( startInfo == NULL )
|
|
165 |
{
|
|
166 |
__UHEAP_MARKEND;
|
|
167 |
return KErrNoMemory;
|
|
168 |
}
|
|
169 |
|
|
170 |
// Fill the start-up information
|
|
171 |
startInfo->iName = KSettingServerName;
|
|
172 |
startInfo->iStartupResult = KErrNone;
|
|
173 |
startInfo->iStarted.CreateLocal( 0 );
|
|
174 |
|
|
175 |
// Create thread
|
|
176 |
TInt res = startInfo->iServerThread.Create(
|
|
177 |
startInfo->iName , // Name of thread
|
|
178 |
SettingServerThreadFunction, // Thread function
|
|
179 |
KDefaultStackSize, // Stack size
|
|
180 |
KDefaultHeapSize, // Heap initial size
|
|
181 |
KMaxHeapSize, // Heap start max size
|
|
182 |
startInfo // Parameter to thread function
|
|
183 |
);
|
|
184 |
|
|
185 |
// If thread creation failed
|
|
186 |
if( res != KErrNone )
|
|
187 |
{
|
|
188 |
startInfo->iStarted.Close(); // Close semaphore
|
|
189 |
delete startInfo;
|
|
190 |
startInfo = NULL;
|
|
191 |
__UHEAP_MARKEND;
|
|
192 |
return res;
|
|
193 |
}
|
|
194 |
|
|
195 |
// Now start thread
|
|
196 |
startInfo->iServerThread.SetPriority( EPriorityMuchMore );
|
|
197 |
startInfo->iServerThread.Resume();
|
|
198 |
|
|
199 |
// Wait until the thread is started
|
|
200 |
startInfo->iStarted.Wait();
|
|
201 |
|
|
202 |
// Free memory
|
|
203 |
TInt r = startInfo->iStartupResult;
|
|
204 |
startInfo->iServerThread.Close();
|
|
205 |
startInfo->iStarted.Close();
|
|
206 |
delete startInfo;
|
|
207 |
startInfo = NULL;
|
|
208 |
|
|
209 |
__UHEAP_MARKEND;
|
|
210 |
|
|
211 |
// Return start-up result.
|
|
212 |
return r;
|
|
213 |
|
|
214 |
}
|
|
215 |
|
|
216 |
// ================= MEMBER FUNCTIONS =========================================
|
|
217 |
|
|
218 |
/*
|
|
219 |
-------------------------------------------------------------------------------
|
|
220 |
|
|
221 |
Class: RSettingServer
|
|
222 |
|
|
223 |
Method: RSettingServer
|
|
224 |
|
|
225 |
Description: Default constructor
|
|
226 |
|
|
227 |
C++ default constructor can NOT contain any code, that
|
|
228 |
might leave.
|
|
229 |
|
|
230 |
Parameters: None
|
|
231 |
|
|
232 |
Return Values: None
|
|
233 |
|
|
234 |
Errors/Exceptions: None
|
|
235 |
|
|
236 |
Status: Proposal
|
|
237 |
|
|
238 |
-------------------------------------------------------------------------------
|
|
239 |
*/
|
|
240 |
EXPORT_C RSettingServer::RSettingServer()
|
|
241 |
{
|
|
242 |
|
|
243 |
}
|
|
244 |
|
|
245 |
/*
|
|
246 |
-------------------------------------------------------------------------------
|
|
247 |
|
|
248 |
Class: RSettingServer
|
|
249 |
|
|
250 |
Method: Connect
|
|
251 |
|
|
252 |
Description: Connect method creates new RSettingServer session.
|
|
253 |
First the server is tried to start. If start is successfull or server is
|
|
254 |
already started, then a new session is created.
|
|
255 |
|
|
256 |
Parameters: None
|
|
257 |
|
|
258 |
Return Values: TInt: Error code
|
|
259 |
|
|
260 |
Errors/Exceptions: None
|
|
261 |
|
|
262 |
Status: Proposal
|
|
263 |
|
|
264 |
-------------------------------------------------------------------------------
|
|
265 |
*/
|
|
266 |
EXPORT_C TInt RSettingServer::Connect()
|
|
267 |
{
|
|
268 |
TInt ret = StartNewSettingServer();
|
|
269 |
|
|
270 |
if( ret == KErrNone || ret == KErrAlreadyExists )
|
|
271 |
{
|
|
272 |
ret = CreateSession( KSettingServerName, Version() );
|
|
273 |
}
|
|
274 |
|
|
275 |
return ret;
|
|
276 |
|
|
277 |
}
|
|
278 |
|
|
279 |
/*
|
|
280 |
-------------------------------------------------------------------------------
|
|
281 |
|
|
282 |
Class: RSettingServer
|
|
283 |
|
|
284 |
Method: Version
|
|
285 |
|
|
286 |
Description: Return client side version.
|
|
287 |
|
|
288 |
Parameters: None
|
|
289 |
|
|
290 |
Return Values: TVersion: Version number
|
|
291 |
|
|
292 |
Errors/Exceptions: None
|
|
293 |
|
|
294 |
Status: Proposal
|
|
295 |
|
|
296 |
-------------------------------------------------------------------------------
|
|
297 |
*/
|
|
298 |
EXPORT_C TVersion RSettingServer::Version() const
|
|
299 |
{
|
|
300 |
return( TVersion( KSettingServerMajorVersionNumber,
|
|
301 |
KSettingServerMinorVersionNumber,
|
|
302 |
KSettingServerVersionNumber
|
|
303 |
) );
|
|
304 |
|
|
305 |
}
|
|
306 |
|
|
307 |
/*
|
|
308 |
-------------------------------------------------------------------------------
|
|
309 |
|
|
310 |
Class: RSettingServer
|
|
311 |
|
|
312 |
Method: Close
|
|
313 |
|
|
314 |
Description: Closes the RSettingServer session.
|
|
315 |
|
|
316 |
Parameters: None
|
|
317 |
|
|
318 |
Return Values: None
|
|
319 |
|
|
320 |
Errors/Exceptions: None
|
|
321 |
|
|
322 |
Status: Proposal
|
|
323 |
|
|
324 |
-------------------------------------------------------------------------------
|
|
325 |
*/
|
|
326 |
EXPORT_C void RSettingServer::Close()
|
|
327 |
{
|
|
328 |
// Check that server is connected and send close message to it if possible.
|
|
329 |
if( Handle() != 0 )
|
|
330 |
{
|
|
331 |
TIpcArgs args( TIpcArgs::ENothing, TIpcArgs::ENothing, TIpcArgs::ENothing );
|
|
332 |
// Goes to CSettingServer's DispatchMessageL() method
|
|
333 |
SendReceive( ESettingServerCloseSession, args );
|
|
334 |
}
|
|
335 |
|
|
336 |
RSessionBase::Close();
|
|
337 |
|
|
338 |
}
|
|
339 |
|
|
340 |
/*
|
|
341 |
-------------------------------------------------------------------------------
|
|
342 |
|
|
343 |
Class: RSettingServer
|
|
344 |
|
|
345 |
Method: ReadLoggerSettingsFromIniFile
|
|
346 |
|
|
347 |
Description: Read Logger setting from initialization file. Mainly use from
|
|
348 |
TestEngine side.
|
|
349 |
|
|
350 |
Parameters: TLoggerSettings& aLoggerSettings: inout: Logger's overwrite
|
|
351 |
struct
|
|
352 |
|
|
353 |
Return Values: TInt: Symbian error code
|
|
354 |
|
|
355 |
Errors/Exceptions: None
|
|
356 |
|
|
357 |
Status: Proposal
|
|
358 |
|
|
359 |
-------------------------------------------------------------------------------
|
|
360 |
*/
|
|
361 |
EXPORT_C TInt RSettingServer::LoadLoggerSettingsFromIniFile( TLoggerSettings& aLoggerSettings,
|
|
362 |
const TDesC& aIniFile,
|
|
363 |
TBool aOverwritePreviousSettings )
|
|
364 |
{
|
|
365 |
// Package
|
|
366 |
TPckg<TLoggerSettings> loggerSettingsPckg( aLoggerSettings );
|
|
367 |
|
|
368 |
TIpcArgs args( &aIniFile, &loggerSettingsPckg, aOverwritePreviousSettings );
|
|
369 |
// Goes to CSettingServer's DispatchMessageL() method
|
|
370 |
SendReceive( ELoadLoggerSettingsFromIniFile, args );
|
|
371 |
|
|
372 |
return KErrNone;
|
|
373 |
|
|
374 |
}
|
|
375 |
|
|
376 |
/*
|
|
377 |
-------------------------------------------------------------------------------
|
|
378 |
|
|
379 |
Class: RSettingServer
|
|
380 |
|
|
381 |
Method: LoadLoggerSettingsFromCommandLine
|
|
382 |
|
|
383 |
Description: Read Logger setting from command line. Mainly use from
|
|
384 |
TestEngine side.
|
|
385 |
|
|
386 |
Parameters: TDesC& aLoggerSettings: inout: Logger's overwrite
|
|
387 |
struct
|
|
388 |
|
|
389 |
Return Values: TInt: Symbian error code
|
|
390 |
|
|
391 |
Errors/Exceptions: None
|
|
392 |
|
|
393 |
Status: Proposal
|
|
394 |
|
|
395 |
-------------------------------------------------------------------------------
|
|
396 |
*/
|
|
397 |
EXPORT_C TInt RSettingServer::LoadLoggerSettingsFromCommandLine(TDesC& aLoggerSettings)
|
|
398 |
{
|
|
399 |
TIpcArgs args( &aLoggerSettings, TIpcArgs::ENothing, TIpcArgs::ENothing );
|
|
400 |
return SendReceive( ELoadLoggerSettingsFromCommandLine, args );
|
|
401 |
}
|
|
402 |
|
|
403 |
/*
|
|
404 |
-------------------------------------------------------------------------------
|
|
405 |
|
|
406 |
Class: RSettingServer
|
|
407 |
|
|
408 |
Method: GetLoggerSettings
|
|
409 |
|
|
410 |
Description: Get Logger settings. Mainly use from Logger side.
|
|
411 |
|
|
412 |
Parameters: TLoggerSettings& aLoggerSettings: in: Logger's overwrite struct
|
|
413 |
|
|
414 |
Return Values: TInt: Symbian error code
|
|
415 |
|
|
416 |
Errors/Exceptions: None
|
|
417 |
|
|
418 |
Status: Proposal
|
|
419 |
|
|
420 |
-------------------------------------------------------------------------------
|
|
421 |
*/
|
|
422 |
EXPORT_C TInt RSettingServer::GetLoggerSettings(
|
|
423 |
TLoggerSettings& aLoggerSettings )
|
|
424 |
{
|
|
425 |
// Package
|
|
426 |
TPckg<TLoggerSettings> loggerSettingsPckg( aLoggerSettings );
|
|
427 |
|
|
428 |
TIpcArgs args( &loggerSettingsPckg, TIpcArgs::ENothing, TIpcArgs::ENothing );
|
|
429 |
// Goes to CSettingServer's DispatchMessageL() method
|
|
430 |
return SendReceive( EGetLoggerSettings, args );
|
|
431 |
}
|
|
432 |
|
|
433 |
/*
|
|
434 |
-------------------------------------------------------------------------------
|
|
435 |
|
|
436 |
Class: RSettingServer
|
|
437 |
|
|
438 |
Method: SetIniFileSetting
|
|
439 |
|
|
440 |
Description: Set new initialization file setting(e.g. SetAttribute).
|
|
441 |
|
|
442 |
Parameters: TName& aNewIniFileSetting: in: New setting
|
|
443 |
|
|
444 |
Return Values: TInt: Symbian error code
|
|
445 |
|
|
446 |
Errors/Exceptions: None
|
|
447 |
|
|
448 |
Status: Proposal
|
|
449 |
|
|
450 |
-------------------------------------------------------------------------------
|
|
451 |
*/
|
|
452 |
EXPORT_C TInt RSettingServer::SetLoggerOutputPath( const TDesC& aLoggerOutputPath )
|
|
453 |
{
|
|
454 |
TIpcArgs args( &aLoggerOutputPath, TIpcArgs::ENothing, TIpcArgs::ENothing );
|
|
455 |
// Goes to CSettingServer's DispatchMessageL() method
|
|
456 |
return SendReceive( ESetLoggerOutputPath, args );
|
|
457 |
}
|
|
458 |
|
|
459 |
EXPORT_C TInt RSettingServer::ResetLoggerSettings()
|
|
460 |
{
|
|
461 |
return SendReceive( EResetLoggerSettings, TIpcArgs() );
|
|
462 |
}
|
|
463 |
|
|
464 |
// End of File
|