|
1 /* |
|
2 * Copyright (c) 2007 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: Implementation of CGbaServer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32svr.h> |
|
20 #include <e32math.h> |
|
21 #include <s32file.h> |
|
22 #include "GbaServer.h" |
|
23 #include "GbaSession.h" |
|
24 #include "GBALogger.h" |
|
25 |
|
26 _LIT(KGBAStoreStandardDrive, "C:"); |
|
27 _LIT(KGbaIniFileName, "GbaConf.ini"); |
|
28 |
|
29 const TInt KPrivateFilepathLength = 20; |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CGbaServer::CGbaServer() |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CGbaServer::CGbaServer():CPolicyServer( EPriorityStandard, GBAPolicy, ESharableSessions ) |
|
36 { |
|
37 // Implementation not required |
|
38 } |
|
39 |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CGbaServer::~CGbaServer() |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CGbaServer::~CGbaServer() |
|
46 { |
|
47 GBA_TRACE_DEBUG(("CGbaServer::~CGbaServer")); |
|
48 } |
|
49 |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CGbaServer::NewL() |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CGbaServer* CGbaServer::NewL() |
|
56 { |
|
57 CGbaServer* self = CGbaServer::NewLC(); |
|
58 CleanupStack::Pop( self ) ; |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CGbaServer::NewLC() |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CGbaServer* CGbaServer::NewLC() |
|
68 { |
|
69 CGbaServer* self = new (ELeave) CGbaServer(); |
|
70 CleanupStack::PushL( self ) ; |
|
71 self->ConstructL() ; |
|
72 return self; |
|
73 } |
|
74 |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CGbaServer::ConstructL() |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CGbaServer::ConstructL() |
|
81 { |
|
82 StartL( KGbaServerName ) ; |
|
83 iShutdown.ConstructL(); |
|
84 if(!iShutdown.IsActive()) |
|
85 { |
|
86 iShutdown.Start(); |
|
87 } |
|
88 } |
|
89 |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CGbaServer::ConstructL() |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CSession2* CGbaServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const |
|
96 { |
|
97 GBA_TRACE_DEBUG(("Creating NewSessionL")); |
|
98 // check we're the right version |
|
99 if (!User::QueryVersionSupported(TVersion(KGbaServMajorVersionNumber, |
|
100 KGbaServMinorVersionNumber, |
|
101 KGbaServBuildVersionNumber), |
|
102 aVersion)) |
|
103 { |
|
104 GBA_TRACE_DEBUG(("Version isn't supported")); |
|
105 User::Leave(KErrNotSupported); |
|
106 } |
|
107 CGbaServerSession* session = CGbaServerSession::NewL(); |
|
108 return session; |
|
109 |
|
110 } |
|
111 |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CGbaServer::IncrementSessions() |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CGbaServer::IncrementSessions() |
|
118 { |
|
119 GBA_TRACE_DEBUG(("CGbaServer::IncrementSessions")); |
|
120 iSessionCount++; |
|
121 iShutdown.Cancel(); |
|
122 } |
|
123 |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CGbaServer::DecrementSessions() |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CGbaServer::DecrementSessions() |
|
130 { |
|
131 GBA_TRACE_DEBUG(("CGbaServer::DecrementSessions")); |
|
132 if ( --iSessionCount == 0 ) |
|
133 { |
|
134 if(!iShutdown.IsActive()) |
|
135 { |
|
136 iShutdown.Start(); |
|
137 } |
|
138 } |
|
139 GBA_TRACE_DEBUG(("CGbaServer::DecrementSessions END")); |
|
140 } |
|
141 |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CGbaServer::ReadOptionL() |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 TBool CGbaServer::ReadOptionL(const TUid& aOptionID, TDes8& aValue) const |
|
148 { |
|
149 GBA_TRACE_DEBUG(("ReadOptionL")); |
|
150 TInt pushCount = 0; |
|
151 TInt result = EFalse; |
|
152 RFs fs; |
|
153 |
|
154 User::LeaveIfError( fs.Connect() ); |
|
155 CleanupClosePushL( fs ); |
|
156 pushCount++; |
|
157 TFindFile folder( fs ); |
|
158 |
|
159 TFileName fullPath; |
|
160 MakePrivateFilenameL(fs, KGbaIniFileName, fullPath); |
|
161 |
|
162 TInt err = folder.FindByDir( fullPath, KNullDesC); |
|
163 |
|
164 if ( err != KErrNone ) |
|
165 { |
|
166 CleanupStack::PopAndDestroy( pushCount ); |
|
167 return result; |
|
168 } |
|
169 else |
|
170 { |
|
171 CDictionaryFileStore* pStore = CDictionaryFileStore::OpenLC( fs, fullPath , KGbaIniUid ); |
|
172 pushCount++; |
|
173 |
|
174 if ( pStore->IsPresentL( aOptionID ) ) |
|
175 { |
|
176 RDictionaryReadStream drs; |
|
177 CleanupClosePushL( drs ); |
|
178 drs.OpenL(*pStore,aOptionID); |
|
179 |
|
180 TInt length = drs.ReadInt32L(); |
|
181 drs.ReadL(aValue,length); |
|
182 CleanupStack::PopAndDestroy( &drs ); |
|
183 result = ETrue; |
|
184 } |
|
185 } |
|
186 |
|
187 CleanupStack::PopAndDestroy( pushCount ); |
|
188 return result; |
|
189 } |
|
190 |
|
191 |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CGbaServer::WriteOptionL() |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CGbaServer::WriteOptionL(const TUid& aOptionID, const TDesC8& aValue) const |
|
198 { |
|
199 GBA_TRACE_DEBUG(("WriteOptionL")); |
|
200 TInt pushCount = 0; |
|
201 RFs fs; |
|
202 User::LeaveIfError(fs.Connect()); |
|
203 CleanupClosePushL( fs ); |
|
204 pushCount++; |
|
205 TFindFile folder( fs ); |
|
206 |
|
207 TFileName fullPath; |
|
208 MakePrivateFilenameL(fs, KGbaIniFileName, fullPath); |
|
209 EnsurePathL(fs, fullPath ); |
|
210 |
|
211 GBA_TRACE_DEBUG(fullPath); |
|
212 |
|
213 TInt err = folder.FindByDir( fullPath, KNullDesC); |
|
214 |
|
215 if ( err == KErrNotFound || err == KErrNone ) |
|
216 { |
|
217 CDictionaryFileStore* pStore = CDictionaryFileStore::OpenLC( fs, fullPath, KGbaIniUid ); |
|
218 pushCount++; |
|
219 |
|
220 RDictionaryWriteStream wrs; |
|
221 CleanupClosePushL( wrs ); |
|
222 wrs.AssignL(*pStore,aOptionID); |
|
223 |
|
224 wrs.WriteInt32L(aValue.Length()); |
|
225 wrs.WriteL(aValue); |
|
226 wrs.CommitL(); |
|
227 |
|
228 pStore->CommitL(); |
|
229 CleanupStack::PopAndDestroy( &wrs ); |
|
230 CleanupStack::PopAndDestroy( pushCount ); |
|
231 GBA_TRACE_DEBUG(aValue); |
|
232 } |
|
233 else |
|
234 { |
|
235 CleanupStack::PopAndDestroy( pushCount ); |
|
236 User::LeaveIfError( err ); |
|
237 } |
|
238 } |
|
239 |
|
240 |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // CGbaServer::MakePrivateFilenameL() |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 void CGbaServer::MakePrivateFilenameL(RFs& aFs, const TDesC& aLeafName, |
|
247 TDes& aNameOut) const |
|
248 { |
|
249 aNameOut.Copy(KGBAStoreStandardDrive); |
|
250 // Get private path |
|
251 TBuf<KPrivateFilepathLength> privatePath; |
|
252 aFs.PrivatePath(privatePath); |
|
253 aNameOut.Append(privatePath); |
|
254 aNameOut.Append(aLeafName); |
|
255 } |
|
256 |
|
257 |
|
258 // --------------------------------------------------------------------------- |
|
259 // CGbaServer::EnsurePathL() |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 void CGbaServer::EnsurePathL( RFs& aFs, const TDesC& aFile ) const |
|
263 { |
|
264 TInt err = aFs.MkDirAll(aFile); |
|
265 if (err != KErrNone && err != KErrAlreadyExists) |
|
266 { |
|
267 User::Leave(err); |
|
268 } |
|
269 } |
|
270 |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CShutdown::CShutdown |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 inline CShutdown::CShutdown() |
|
277 :CTimer(-1) |
|
278 { |
|
279 CActiveScheduler::Add(this); |
|
280 } |
|
281 |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CShutdown::ConstructL |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 inline void CShutdown::ConstructL() |
|
288 { |
|
289 CTimer::ConstructL(); |
|
290 } |
|
291 |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CShutdown::Start |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 inline void CShutdown::Start() |
|
298 { |
|
299 GBA_TRACE_DEBUG(("GbaServer: starting shutdown timeout")); |
|
300 After( EGbaServerShutdownDelay ); |
|
301 } |
|
302 |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CShutdown::RunL |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void CShutdown::RunL() |
|
309 { |
|
310 GBA_TRACE_DEBUG(("GbaServer: server timeout ... closing")); |
|
311 CActiveScheduler::Stop(); |
|
312 } |
|
313 |
|
314 // ======== LOCAL FUNCTIONS ======== |
|
315 |
|
316 // -------------------------------------------- |
|
317 // PanicClient() |
|
318 // -------------------------------------------- |
|
319 // |
|
320 void PanicClient( const RMessage2& aMessage, TInt aPanic ) |
|
321 { |
|
322 aMessage.Panic( KGbaServer, aPanic ); |
|
323 } |
|
324 |
|
325 |
|
326 // -------------------------------------------- |
|
327 // PanicServer() |
|
328 // -------------------------------------------- |
|
329 // |
|
330 void PanicServer( TInt aPanic ) |
|
331 { |
|
332 User::Panic( KGbaServer, aPanic ); |
|
333 } |
|
334 |
|
335 |
|
336 // -------------------------------------------- |
|
337 // RunServerL() |
|
338 // -------------------------------------------- |
|
339 // |
|
340 static void RunServerL() |
|
341 { |
|
342 // Construct active scheduler |
|
343 CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler; |
|
344 CleanupStack::PushL(activeScheduler) ; |
|
345 CActiveScheduler::Install(activeScheduler); |
|
346 // Construct our server |
|
347 CGbaServer* server = CGbaServer::NewLC(); |
|
348 RProcess::Rendezvous(KErrNone); |
|
349 // Start handling requests |
|
350 CActiveScheduler::Start(); |
|
351 CleanupStack::PopAndDestroy( server ); |
|
352 CleanupStack::PopAndDestroy( activeScheduler ); |
|
353 } |
|
354 |
|
355 |
|
356 // -------------------------------------------- |
|
357 // E32Main:() |
|
358 // -------------------------------------------- |
|
359 // |
|
360 TInt E32Main() |
|
361 { |
|
362 __UHEAP_MARK; |
|
363 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
364 |
|
365 TInt err = KErrNoMemory; |
|
366 |
|
367 if ( cleanup ) |
|
368 { |
|
369 TRAP(err, RunServerL()); |
|
370 delete cleanup; |
|
371 } |
|
372 __UHEAP_MARKEND; |
|
373 return err; |
|
374 } |
|
375 |
|
376 //EOF |
|
377 |