|
1 /* |
|
2 * Copyright (c) 2007 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: Contains methods handling startup of the server process. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include "psmsrvserver.h" |
|
21 #include "psmdefines.h" |
|
22 #include "psmtrace.h" |
|
23 |
|
24 |
|
25 TInt E32Main( void ); // Process entry point |
|
26 |
|
27 // ============================= LOCAL FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // Function that starts the psmserver. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 static void RunServerL() |
|
34 { |
|
35 COMPONENT_TRACE( ( _L( "PSM Server - RunServer()" ) ) ); |
|
36 |
|
37 // Naming the server process and thread after the startup helps to debug panics |
|
38 // No error checking as names are not critical for operation |
|
39 User::RenameProcess( KPsmProcessName ); |
|
40 User::RenameThread( KPsmMainThreadName ); |
|
41 |
|
42 // Use process default priority (EPriorityForgeround) |
|
43 |
|
44 // Create and install the active scheduler we need |
|
45 CActiveScheduler* scheduler = new ( ELeave ) CActiveScheduler(); |
|
46 CleanupStack::PushL( scheduler ); |
|
47 |
|
48 CActiveScheduler::Install( scheduler ); |
|
49 |
|
50 // Now we are ready to instantiate the actual server instance |
|
51 CPsmSrvServer* server = CPsmSrvServer::NewLC(); |
|
52 |
|
53 // Initialisation complete, now signal the client |
|
54 RProcess::Rendezvous( KErrNone ); |
|
55 |
|
56 // Ready to run |
|
57 COMPONENT_TRACE( ( _L( "PSM Server - RunServer() - Starting scheduler..." ) ) ); |
|
58 CActiveScheduler::Start(); |
|
59 COMPONENT_TRACE( ( _L( "PSM Server - RunServer() - Scheduler stopped" ) ) ); |
|
60 |
|
61 // Cleanup |
|
62 CleanupStack::PopAndDestroy( server ); |
|
63 CleanupStack::PopAndDestroy( scheduler ); |
|
64 |
|
65 COMPONENT_TRACE( ( _L( "PSM Server - RunServer() - return" ) ) ); |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // Main function |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 TInt E32Main() |
|
73 { |
|
74 COMPONENT_TRACE( ( _L( "PSM Server - E32Main()" ) ) ); |
|
75 |
|
76 __UHEAP_MARK; |
|
77 |
|
78 #ifdef MEMORY_TRACE_DEBUG |
|
79 // TRACE heap usage |
|
80 TInt heapSize = User::Heap().Size(); |
|
81 TInt biggestBlock(0); |
|
82 TInt heapAvail = User::Heap().Available( biggestBlock ); |
|
83 TInt used( heapSize-heapAvail ); |
|
84 MEMORY_TRACE( ( _L( "#### PSM Server, main thread starting - HEAP: Size: %d, Available: %d, Used: %d" ), heapSize, heapAvail, used ) ); |
|
85 #endif |
|
86 |
|
87 TInt err( KErrNone ); |
|
88 |
|
89 // Start server. |
|
90 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
91 err = KErrNoMemory; |
|
92 |
|
93 if ( cleanup ) |
|
94 { |
|
95 TRAP( err, RunServerL() ); |
|
96 delete cleanup; |
|
97 cleanup = NULL; |
|
98 } |
|
99 |
|
100 COMPONENT_TRACE( ( _L( "PSM Server - E32Main - return %d" ), err ) ); |
|
101 |
|
102 #ifdef MEMORY_TRACE_DEBUG |
|
103 // TRACE heap usage |
|
104 heapSize = User::Heap().Size(); |
|
105 heapAvail = User::Heap().Available( biggestBlock ); |
|
106 TInt newUsed( heapSize-heapAvail ); |
|
107 MEMORY_TRACE( ( _L( "#### PSM Server, main thread exit - HEAP: Size: %d, Available: %d, Used: %d, Change in used: %d" ), heapSize, heapAvail, newUsed, newUsed - used ) ); |
|
108 // Print out the heap contents |
|
109 #endif |
|
110 |
|
111 __UHEAP_MARKEND; |
|
112 |
|
113 return err; |
|
114 } |
|
115 |
|
116 // End of File |