|
1 /* |
|
2 * Copyright (c) 2002 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: AlwaysOnline server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "AlwaysOnlineManagerServer.h" |
|
20 #include "AlwaysOnlineManagerServerSession.h" |
|
21 #include "AlwaysOnlineManagerStartupSignaller.h" |
|
22 #include "AlwaysOnlineManagerLogging.h" |
|
23 |
|
24 |
|
25 |
|
26 //constants |
|
27 |
|
28 //--------------------------------------------- |
|
29 // CAlwaysOnlineManagerServer() |
|
30 //--------------------------------------------- |
|
31 CAlwaysOnlineManagerServer::CAlwaysOnlineManagerServer( TInt aPriority ) |
|
32 : CPolicyServer( aPriority, KAOMServerPolicy ) |
|
33 { |
|
34 KAOMANAGER_LOGGER_FN1("CAlwaysOnlineManagerServer::CAlwaysOnlineManagerServer"); |
|
35 KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::CAlwaysOnlineManagerServer"); |
|
36 } |
|
37 |
|
38 //--------------------------------------------- |
|
39 // NewL() |
|
40 //--------------------------------------------- |
|
41 EXPORT_C CAlwaysOnlineManagerServer* CAlwaysOnlineManagerServer::NewL() |
|
42 { |
|
43 KAOMANAGER_LOGGER_FN1("CAlwaysOnlineManagerServer::NewL"); |
|
44 CAlwaysOnlineManagerServer* self = new (ELeave) |
|
45 CAlwaysOnlineManagerServer( EAlwaysOnlineManagerServerPriority ); |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop( self ); |
|
49 self->StartL( KAlwaysOnlineManagerServerName ); |
|
50 KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::NewL"); |
|
51 return self; |
|
52 } |
|
53 |
|
54 |
|
55 //--------------------------------------------- |
|
56 // ConstructL() |
|
57 //--------------------------------------------- |
|
58 void CAlwaysOnlineManagerServer::ConstructL() |
|
59 { |
|
60 KAOMANAGER_LOGGER_FN1("CAlwaysOnlineManagerServer::ConstructL"); |
|
61 iManager = NULL; |
|
62 |
|
63 TRAPD(err, iManager = CAlwaysOnlineManager::NewL(this) ); |
|
64 |
|
65 if( err==KErrNone ) |
|
66 { |
|
67 TRAPD(err2, iManager->DoStartL() ); |
|
68 if(err2!=KErrNone) |
|
69 { |
|
70 KAOMANAGER_LOGGER_WRITE_FORMAT("Manager Start failed, err2:%d", err2 ); |
|
71 PanicServer( EAOMServerStartFail ); |
|
72 } |
|
73 } |
|
74 else |
|
75 { |
|
76 KAOMANAGER_LOGGER_WRITE_FORMAT("Manager NewL failed, err:%d", err ); |
|
77 PanicServer( EAOMServerStartFail ); |
|
78 } |
|
79 KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::ConstructL"); |
|
80 } |
|
81 |
|
82 //--------------------------------------------- |
|
83 // ~CAlwaysOnlineManagerServer() |
|
84 //--------------------------------------------- |
|
85 CAlwaysOnlineManagerServer::~CAlwaysOnlineManagerServer() |
|
86 { |
|
87 KAOMANAGER_LOGGER_FN1("CAlwaysOnlineManagerServer::~"); |
|
88 //we should never come here while phone is switched on |
|
89 delete iManager; |
|
90 //delete iSession; |
|
91 KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::~"); |
|
92 } |
|
93 |
|
94 //--------------------------------------------- |
|
95 // HandleClientCommandL() |
|
96 //--------------------------------------------- |
|
97 // |
|
98 EXPORT_C void CAlwaysOnlineManagerServer::HandleClientCommandL( |
|
99 TAlwaysOnlineServerAPICommands aCommand, TDes8& aParameter ) |
|
100 { |
|
101 iManager->BroadcastClientCommandL( aCommand, aParameter ); |
|
102 } |
|
103 |
|
104 //--------------------------------------------- |
|
105 // NewSessionL() |
|
106 //--------------------------------------------- |
|
107 CSession2* CAlwaysOnlineManagerServer::NewSessionL(const TVersion &aVersion, |
|
108 const RMessage2& /*aMessage*/) const |
|
109 { |
|
110 KAOMANAGER_LOGGER_FN1("CAlwaysOnlineManagerServer::NewSessionL"); |
|
111 // check we're the right version |
|
112 TVersion v( KAlwaysOnlineMajorVersionNumber, |
|
113 KAlwaysOnlineMinorVersionNumber, |
|
114 KAlwaysOnlineVersionNumber ); |
|
115 |
|
116 if (!User::QueryVersionSupported( v, aVersion )) |
|
117 User::Leave( KErrNotSupported ); |
|
118 |
|
119 // make new session |
|
120 KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::NewSessionL"); |
|
121 return CAlwaysOnlineManagerServerSession::NewL( (CAlwaysOnlineManagerServer*)this ); |
|
122 } |
|
123 |
|
124 //--------------------------------------------- |
|
125 // PanicServer() |
|
126 //--------------------------------------------- |
|
127 void CAlwaysOnlineManagerServer::PanicServer( TAlwaysOnlineManagerPanic aPanic ) |
|
128 { |
|
129 _LIT(KTxtAlwaysOnlineManagerServer,"CAlwaysOnlineManagerServer"); |
|
130 User::Panic(KTxtAlwaysOnlineManagerServer, aPanic); |
|
131 } |
|
132 |
|
133 //********************************** |
|
134 //Global functions |
|
135 //********************************** |
|
136 |
|
137 |
|
138 //--------------------------------------------- |
|
139 // RunServer() |
|
140 //--------------------------------------------- |
|
141 TInt CAlwaysOnlineManagerServer::RunServer(TOAManagerStartupSignaller& aSignaller) |
|
142 { |
|
143 KAOMANAGER_LOGGER_FN1("CAlwaysOnlineManagerServer::RunServer"); |
|
144 __UHEAP_MARK; |
|
145 // |
|
146 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
147 TInt ret = KErrNoMemory; |
|
148 if (cleanup) |
|
149 { |
|
150 TRAP(ret, CAlwaysOnlineManagerServer::RunServerL(aSignaller)); |
|
151 delete cleanup; |
|
152 } |
|
153 // |
|
154 __UHEAP_MARKEND; |
|
155 KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::RunServer"); |
|
156 return ret; |
|
157 } |
|
158 |
|
159 |
|
160 |
|
161 //--------------------------------------------- |
|
162 // RunServer() |
|
163 //--------------------------------------------- |
|
164 void CAlwaysOnlineManagerServer::RunServerL(TOAManagerStartupSignaller& aSignaller) |
|
165 { |
|
166 KAOMANAGER_LOGGER_FN1("CAlwaysOnlineManagerServer::RunServerL"); |
|
167 // Naming the server thread after the server helps to debug panics |
|
168 User::LeaveIfError( User::RenameThread( KAlwaysOnlineManagerServerName ) ); |
|
169 |
|
170 // Create and install the active scheduler we need |
|
171 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; |
|
172 CleanupStack::PushL( scheduler ); |
|
173 __ASSERT_ALWAYS( scheduler,PanicServer( EMainSchedulerError ) ); |
|
174 CActiveScheduler::Install( scheduler ); |
|
175 |
|
176 // construct server, an active object |
|
177 CAlwaysOnlineManagerServer* server = CAlwaysOnlineManagerServer::NewL(); |
|
178 CleanupStack::PushL( server ); |
|
179 |
|
180 // Initialisation complete, now signal the client |
|
181 aSignaller.SignalL(); |
|
182 |
|
183 // Ready to run |
|
184 CActiveScheduler::Start(); // CSI: 3 # This is only easy way... |
|
185 |
|
186 // Cleanup the server and scheduler |
|
187 CleanupStack::PopAndDestroy( 2, scheduler ); // CSI: 47,12 # scheduler, server |
|
188 KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::RunServerL"); |
|
189 } |
|
190 |
|
191 //************************************************************************************* |
|
192 TInt CAlwaysOnlineManagerServer::ServerThreadFunction(TAny* aParameters) |
|
193 { |
|
194 KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::ServerThreadFunction"); |
|
195 TOAManagerStartupSignaller* parameters = static_cast<TOAManagerStartupSignaller*>(aParameters); |
|
196 TInt ret = RunServer(*parameters); |
|
197 KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::ServerThreadFunction"); |
|
198 return ret; |
|
199 } |
|
200 |
|
201 |
|
202 /////////////////////////////////////////////////////////////////////////////////////// |
|
203 // ----> TOAManagerStartupSignaller (source) |
|
204 /////////////////////////////////////////////////////////////////////////////////////// |
|
205 |
|
206 //************************************************************************************* |
|
207 void TOAManagerStartupSignaller::SignalL() |
|
208 { |
|
209 // Signal the owning thread that the server has started successfully |
|
210 // This may itself fail |
|
211 KAOMANAGER_LOGGER_FN1("TOAManagerStartupSignaller::SignalL"); |
|
212 RThread startingThread; |
|
213 User::LeaveIfError(startingThread.Open(iThreadId)); |
|
214 startingThread.RequestComplete(iStatus, KErrNone); |
|
215 startingThread.Close(); |
|
216 KAOMANAGER_LOGGER_FN2("TOAManagerStartupSignaller::SignalL"); |
|
217 } |
|
218 |
|
219 |
|
220 /////////////////////////////////////////////////////////////////////////////////////// |
|
221 // ----> Global kick-off methods (source) |
|
222 /////////////////////////////////////////////////////////////////////////////////////// |
|
223 |
|
224 |
|
225 //************************************************************************************* |
|
226 IMPORT_C TInt WinsMain(); |
|
227 EXPORT_C TInt WinsMain() |
|
228 { |
|
229 // WINS DLL entry-point. Just return the real thread function |
|
230 // cast to TInt |
|
231 return reinterpret_cast<TInt>(&CAlwaysOnlineManagerServer::ServerThreadFunction); |
|
232 } |
|
233 |
|
234 |
|
235 //************************************************************************************* |
|
236 |
|
237 |
|
238 //************************************************************************************* |
|
239 TInt TOAManagerStartupSignaller::GetCommand() |
|
240 { |
|
241 // Validate the size of the command line. |
|
242 KAOMANAGER_LOGGER_FN1("TOAManagerStartupSignaller::GetCommand"); |
|
243 |
|
244 if ( User::CommandLineLength() != |
|
245 sizeof( TOAManagerStartupSignaller ) / sizeof( TText ) ) |
|
246 { |
|
247 KAOMANAGER_LOGGER_FN2( "TOAManagerStartupSignaller::GetCommand error" ); |
|
248 return KErrGeneral; |
|
249 } |
|
250 |
|
251 // Get the command line |
|
252 TPtr pCommandLine( |
|
253 reinterpret_cast<TText*>( this ), 0, |
|
254 sizeof( TOAManagerStartupSignaller ) / sizeof( TText ) ); |
|
255 User::CommandLine( pCommandLine ); |
|
256 // |
|
257 KAOMANAGER_LOGGER_FN2( "TOAManagerStartupSignaller::GetCommand" ); |
|
258 return KErrNone; |
|
259 } |
|
260 |
|
261 //************************************************************************************* |
|
262 TInt E32Main() |
|
263 { |
|
264 // Fetch the startup parameters from the command line. |
|
265 KAOMANAGER_LOGGER_FN1("E32Main"); |
|
266 TOAManagerStartupSignaller signaller; |
|
267 TInt error = signaller.GetCommand(); |
|
268 |
|
269 // If there wasn't an error fetching the command line parameters |
|
270 // then we attempt to start the server. |
|
271 if (error == KErrNone) |
|
272 { |
|
273 error = CAlwaysOnlineManagerServer::RunServer(signaller); |
|
274 } |
|
275 KAOMANAGER_LOGGER_FN2("E32Main"); |
|
276 return error; |
|
277 } |
|
278 |
|
279 //#endif |
|
280 |
|
281 |
|
282 EXPORT_C GLDEF_C TInt CAlwaysOnlineManagerServer::ThreadFunction( TAny* aParameters ) |
|
283 { |
|
284 KAOMANAGER_LOGGER_FN1("CAlwaysOnlineManagerServer::ThreadFunction"); |
|
285 TOAManagerStartupSignaller* parameters = static_cast<TOAManagerStartupSignaller*>(aParameters); |
|
286 TInt retVal = RunServer(*parameters); |
|
287 KAOMANAGER_LOGGER_FN2("CAlwaysOnlineManagerServer::ThreadFunction"); |
|
288 return retVal; |
|
289 } |
|
290 |