|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "mceclientserver.h" |
|
23 #include "mceservermain.h" |
|
24 #include "mceservercore.h" |
|
25 #include "mcesrvlogs.h" |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // MceServerMain::ThreadFunction |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 TInt MceServerMain::ThreadFunction (TAny* /*aNone*/) |
|
32 { |
|
33 TInt err = KErrNone; |
|
34 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
35 if (!cleanupStack) |
|
36 { |
|
37 PanicServer(ECreateTrapCleanup); |
|
38 } |
|
39 RSemaphore semaphore; |
|
40 err = semaphore.OpenGlobal(KMceServerSemaphoreName); |
|
41 if (err != KErrNone) |
|
42 { |
|
43 PanicServer(ESrvCreateServer); |
|
44 } |
|
45 TRAP(err, ThreadFunctionL(semaphore)); |
|
46 if (err != KErrNone) |
|
47 { |
|
48 semaphore.Signal(); |
|
49 semaphore.Close(); |
|
50 } |
|
51 |
|
52 delete cleanupStack; |
|
53 return err; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // MceServerMain::ThreadFunctionL |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 void MceServerMain::ThreadFunctionL (RSemaphore& aSemaphore) |
|
61 { |
|
62 // Give a name to this thread |
|
63 User::LeaveIfError(User::RenameThread(KMceServerName)); |
|
64 |
|
65 // Construct server |
|
66 CMceServerCore::NewLC(); |
|
67 |
|
68 // Server created ok |
|
69 aSemaphore.Signal(); |
|
70 aSemaphore.Close(); |
|
71 |
|
72 // Start handling requests |
|
73 CActiveScheduler::Start(); |
|
74 |
|
75 // This will be executed after the active scheduler has been stopped: |
|
76 CleanupStack::PopAndDestroy(1); // server |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // MceServerMain::PanicServer |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void MceServerMain::PanicServer (TMceServerPanic aPanic) |
|
84 { |
|
85 User::Panic(KMceServerPanic, aPanic); |
|
86 } |
|
87 |
|
88 |
|
89 #if ((defined (__WINS__) || defined(__WINSCW__)) && !defined (EKA2)) |
|
90 |
|
91 EXPORT_C TInt WinsMain() |
|
92 { |
|
93 MCESRV_DEBUG("MCE Server process started"); |
|
94 return reinterpret_cast<TInt>(&MceServerMain::ThreadFunction); |
|
95 } |
|
96 |
|
97 TInt E32Dll(TDllReason) |
|
98 { |
|
99 return KErrNone; |
|
100 } |
|
101 |
|
102 #else // HW build |
|
103 |
|
104 TInt E32Main() |
|
105 { |
|
106 MCESRV_DEBUG("MCE Server process started"); |
|
107 return MceServerMain::ThreadFunction(NULL); |
|
108 } |
|
109 |
|
110 #endif |
|
111 |