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