|
1 /* |
|
2 * Copyright (c) 2003 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 #include "CdlServer.h" |
|
20 |
|
21 const TInt KShutdownPriority = CActive::EPriorityStandard-1; |
|
22 |
|
23 CShutdown::CShutdown() |
|
24 :CTimer(KShutdownPriority) |
|
25 { |
|
26 CActiveScheduler::Add(this); |
|
27 } |
|
28 |
|
29 void CShutdown::ConstructL() |
|
30 { |
|
31 CTimer::ConstructL(); |
|
32 } |
|
33 |
|
34 void CShutdown::Start() |
|
35 { |
|
36 After(KCdlShutdownDelay); |
|
37 } |
|
38 |
|
39 void CShutdown::RunL() |
|
40 { |
|
41 CActiveScheduler::Stop(); |
|
42 } |
|
43 |
|
44 |
|
45 /////////////////////// |
|
46 |
|
47 void PanicClient(const RMessagePtr2& aMessage,TCdlPanic aPanic) |
|
48 // |
|
49 // RMessage::Panic() also completes the message. This is: |
|
50 // (a) important for efficient cleanup within the kernel |
|
51 // (b) a problem if the message is completed a second time |
|
52 // |
|
53 { |
|
54 _LIT(KPanic,"CdlServer"); |
|
55 aMessage.Panic(KPanic,aPanic); |
|
56 } |
|
57 |
|
58 void Panic(TCdlPanic aPanic) |
|
59 { |
|
60 User::Panic(KCdlServerName(), aPanic); |
|
61 } |
|
62 |
|
63 static void RunServerL() |
|
64 // |
|
65 // Perform all server initialisation, in particular creation of the |
|
66 // scheduler and server and then run the scheduler |
|
67 // |
|
68 { |
|
69 // |
|
70 // naming the server thread after the server helps to debug panics |
|
71 User::LeaveIfError(User::RenameThread(KCdlServerName)); |
|
72 // create and install the active scheduler we need |
|
73 CActiveScheduler* s=new(ELeave) CActiveScheduler; |
|
74 CleanupStack::PushL(s); |
|
75 CActiveScheduler::Install(s); |
|
76 // |
|
77 // create the server (leave it on the cleanup stack) |
|
78 (void)CCdlServer::NewLC(); |
|
79 // |
|
80 // Initialisation complete, now signal the client |
|
81 #ifdef __CDLSERVER_NO_PROCESSES__ |
|
82 RThread::Rendezvous(KErrNone); |
|
83 #else |
|
84 RProcess::Rendezvous(KErrNone); |
|
85 #endif |
|
86 // |
|
87 // Ready to run |
|
88 CActiveScheduler::Start(); |
|
89 // |
|
90 // Cleanup the server and scheduler |
|
91 CleanupStack::PopAndDestroy(2); |
|
92 } |
|
93 |
|
94 TInt E32Main() |
|
95 // |
|
96 // Server process entry-point |
|
97 // |
|
98 { |
|
99 __UHEAP_MARK; |
|
100 // |
|
101 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
102 TInt r=KErrNoMemory; |
|
103 if (cleanup) |
|
104 { |
|
105 TRAP(r,RunServerL()); |
|
106 delete cleanup; |
|
107 } |
|
108 // |
|
109 __UHEAP_MARKEND; |
|
110 return r; |
|
111 } |
|
112 |
|
113 |
|
114 #ifdef __CDLSERVER_NO_PROCESSES__ |
|
115 |
|
116 // The server binary is an "EPOCEXE" target type |
|
117 // Thus the server parameter passing and startup code for WINS and EPOC are |
|
118 // significantly different. |
|
119 // |
|
120 // In EKA1 WINS, the EPOCEXE target is a DLL with an entry point called WinsMain, |
|
121 // taking no parameters and returning TInt. This is not really valid as a thread |
|
122 // function which takes a TAny* parameter which we need. |
|
123 // |
|
124 // So the DLL entry-point WinsMain() is used to return a TInt representing the |
|
125 // real thread function within the DLL. This is good as long as |
|
126 // sizeof(TInt)>=sizeof(TThreadFunction). |
|
127 // |
|
128 |
|
129 static TInt ThreadFunction(TAny*) |
|
130 // |
|
131 // WINS thread entry-point function. |
|
132 // |
|
133 { |
|
134 return E32Main(); |
|
135 } |
|
136 |
|
137 IMPORT_C TInt WinsMain(); |
|
138 EXPORT_C TInt WinsMain() |
|
139 // |
|
140 // WINS DLL entry-point. Just return the real thread function |
|
141 // cast to TInt |
|
142 // |
|
143 { |
|
144 return reinterpret_cast<TInt>(&ThreadFunction); |
|
145 } |
|
146 |
|
147 TInt E32Dll(TDllReason) |
|
148 { |
|
149 return KErrNone; |
|
150 } |
|
151 |
|
152 #endif |
|
153 |