|
1 /* |
|
2 * Copyright (c) 2001-2010 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 the License "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: scheduler of EAP-server. |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 15 % |
|
20 */ |
|
21 |
|
22 #include "EapScheduler.h" |
|
23 #include "EapTraceSymbian.h" |
|
24 #include "EapServer.h" |
|
25 |
|
26 void CEapScheduler::TServerStart::SignalL() |
|
27 // |
|
28 // Signal the owning thread that the server has started successfully |
|
29 // This may itself fail |
|
30 // |
|
31 { |
|
32 EAP_TRACE_DEBUG_SYMBIAN((_L("TServerStart::SignalL()"))); |
|
33 TBuf<KMaxServerExe> ServerName; |
|
34 TBuf<KMaxServerExe> ServerExe; |
|
35 |
|
36 //EapClientIf * aClientIf = new (ELeave)EapClientIf(); |
|
37 |
|
38 GetServerNameAndExe(&ServerName, &ServerExe); |
|
39 TFindThread aProcess(ServerName); |
|
40 TFullName result; |
|
41 |
|
42 while(aProcess.Next(result) == KErrNone) |
|
43 { |
|
44 RThread starter; |
|
45 User::LeaveIfError(starter.Open(aProcess)); |
|
46 starter.RequestComplete(iStatus,KErrNone); |
|
47 starter.Close(); |
|
48 } |
|
49 EAP_TRACE_DEBUG_SYMBIAN((_L("TServerStart::SignalL(): end"))); |
|
50 } |
|
51 |
|
52 /* |
|
53 class CEapScheduler |
|
54 */ |
|
55 |
|
56 EAP_FUNC_EXPORT CEapScheduler* CEapScheduler::NewL() |
|
57 { |
|
58 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::NewL()"))); |
|
59 |
|
60 CEapScheduler* self = new(ELeave)CEapScheduler(); |
|
61 CleanupStack::PushL(self); |
|
62 |
|
63 TRequestStatus started; |
|
64 TServerStart start(started); |
|
65 |
|
66 self->ConstructL(start); |
|
67 |
|
68 CleanupStack::Pop(self); |
|
69 return self; |
|
70 |
|
71 } |
|
72 |
|
73 EAP_FUNC_EXPORT TInt CEapScheduler::LaunchFromClient(const TBuf<KMaxServerExe> Server) |
|
74 { |
|
75 TRequestStatus started; |
|
76 TServerStart start(started); |
|
77 |
|
78 EAP_TRACE_DEBUG_SYMBIAN((_L("TServerStart::LaunchFromClient()"))); |
|
79 |
|
80 // |
|
81 // EPOC is easy, we just create a new server process. Simultaneous |
|
82 // launching of two such processes should be detected when the |
|
83 // second one attempts to create the server object, failing with |
|
84 // KErrAlreadyExists. |
|
85 // |
|
86 RProcess server; |
|
87 TInt r=server.Create(Server,KNullDesC); |
|
88 |
|
89 if (r!=KErrNone) |
|
90 { |
|
91 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: TServerStart::LaunchFromClient(): server create error"))); |
|
92 return r; |
|
93 } |
|
94 EAP_TRACE_DEBUG_SYMBIAN((_L("TServerStart::LaunchFromClient(): server created"))); |
|
95 |
|
96 EAP_TRACE_DEBUG_SYMBIAN((_L("TServerStart::LaunchFromClient(): server.SetPriority(EPriorityHigh)"))); |
|
97 server.SetPriority(EPriorityHigh); |
|
98 |
|
99 TRequestStatus stat; |
|
100 server.Rendezvous( stat ); |
|
101 EAP_TRACE_DEBUG_SYMBIAN((_L("TServerStart::LaunchFromClient(): server.Rendezvous(), stat.Int()=%d"), |
|
102 stat.Int())); |
|
103 if ( stat!=KRequestPending ) |
|
104 { |
|
105 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: TServerStart::LaunchFromClient(): server.Kill()"))); |
|
106 server.Kill(0); // abort startup |
|
107 } |
|
108 else |
|
109 { |
|
110 EAP_TRACE_DEBUG_SYMBIAN((_L("TServerStart::LaunchFromClient(): server.Resume(), OK"))); |
|
111 server.Resume(); // logon OK - start the server |
|
112 } |
|
113 |
|
114 |
|
115 User::WaitForRequest(stat); |
|
116 EAP_TRACE_DEBUG_SYMBIAN((_L("TServerStart::LaunchFromClient(): User::WaitForRequest(stat), stat.Int()=%d"), |
|
117 stat.Int())); |
|
118 |
|
119 r = ( server.ExitType()==EExitPanic ) ? KErrGeneral : stat.Int(); |
|
120 |
|
121 server.Close(); |
|
122 |
|
123 return r; |
|
124 } |
|
125 |
|
126 EAP_FUNC_EXPORT TInt CEapScheduler::ThreadStart(TServerStart& aStart) |
|
127 { |
|
128 // get cleanup stack |
|
129 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::ThreadStart()"))); |
|
130 |
|
131 __UHEAP_MARK; |
|
132 |
|
133 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
134 |
|
135 // initialize all up to and including starting scheduler |
|
136 TInt err = KErrNoMemory; |
|
137 if (cleanup) |
|
138 { |
|
139 TRAP(err, ConstructL(aStart)); |
|
140 delete cleanup; |
|
141 } |
|
142 |
|
143 __UHEAP_MARKEND; |
|
144 |
|
145 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::ThreadStart end err=%d"), err)); |
|
146 return err; |
|
147 } |
|
148 |
|
149 void CEapScheduler::ConstructL(TServerStart& aStart) |
|
150 { |
|
151 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::ConstructL()"))); |
|
152 |
|
153 // construct active scheduler |
|
154 CEapScheduler* self=new(ELeave) CEapScheduler; |
|
155 CleanupStack::PushL(self); |
|
156 CActiveScheduler::Install(self); |
|
157 |
|
158 // construct server |
|
159 self->iServer=new(ELeave) CEapServer; |
|
160 self->iServer->ConstructL(); |
|
161 |
|
162 // Let the client know we've started OK |
|
163 aStart.SignalL(); |
|
164 |
|
165 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::ThreadStart Rendezvous"))); |
|
166 RProcess::Rendezvous(KErrNone); |
|
167 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::ThreadStart Rendezvous end"))); |
|
168 |
|
169 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::ConstructL(): CActiveScheduler::Start() starts"))); |
|
170 CActiveScheduler::Start(); |
|
171 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::ConstructL(): CActiveScheduler::Start() ends"))); |
|
172 |
|
173 // Destroy the scheduler |
|
174 CleanupStack::PopAndDestroy(self); |
|
175 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::ConstructL(): end"))); |
|
176 } |
|
177 |
|
178 CEapScheduler::~CEapScheduler() |
|
179 { |
|
180 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::~CEapScheduler()"))); |
|
181 |
|
182 delete iServer; |
|
183 } |
|
184 |
|
185 void CEapScheduler::Error(TInt aError) const |
|
186 { |
|
187 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapScheduler::Error(): aError=%d"), |
|
188 aError)); |
|
189 |
|
190 __DEBUGGER(); |
|
191 // PanicServer(EErrorFromNonClientObject); |
|
192 } |