|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <ecom/ecom.h> |
|
21 #include <e32uid.h> |
|
22 #include "featmgrconfiguration.h" |
|
23 #include "featmgrserver.h" |
|
24 #include "featmgrsession.h" |
|
25 #include "featmgrpluginhandler.h" |
|
26 #include "featmgrdebug.h" |
|
27 #include "featmgrsecuritypolicy.h" |
|
28 #include <f32file.h> |
|
29 #include <s32file.h> |
|
30 |
|
31 // LOCAL CONSTANTS AND MACROS |
|
32 #ifdef EXTENDED_FEATURE_MANAGER_TEST |
|
33 _LIT( KPanicCategory, "EnhancedFeatMgrServer" ); |
|
34 #else |
|
35 _LIT( KPanicCategory, "FeatMgrServer" ); |
|
36 #endif // EXTENDED_FEATURE_MANAGER_TEST |
|
37 |
|
38 // LOCAL FUNCTION PROTOTYPES |
|
39 TInt E32Main(); // Process entry point |
|
40 |
|
41 // ============================ MEMBER FUNCTIONS =============================== |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CFeatMgrServer::CFeatMgrServer |
|
45 // C++ default constructor can NOT contain any code, that |
|
46 // might leave. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CFeatMgrServer::CFeatMgrServer( const TInt aPriority, const TServerType aType ) |
|
50 : |
|
51 CPolicyServer( aPriority, KFeatMgrPlatSecPolicy, aType ), iBurState(this), |
|
52 iPluginsReady(EFalse), |
|
53 iPluginsDeleted( EFalse ), |
|
54 iPendingRequests( ETrue ), |
|
55 iFeaturesReady(EFalse) |
|
56 |
|
57 { |
|
58 // Nothing to do |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CFeatMgrServer::ConstructL |
|
63 // Symbian 2nd phase constructor can leave. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void CFeatMgrServer::ConstructL() |
|
67 { |
|
68 FUNC_LOG |
|
69 |
|
70 #ifndef EXTENDED_FEATURE_MANAGER_TEST |
|
71 // Set server process system critical |
|
72 User::SetProcessCritical(User::ESystemCritical); |
|
73 #else |
|
74 iShutdown.ConstructL(); |
|
75 // ensure the server still exits even if the 1st client fails to connect |
|
76 if( !iShutdown.IsActive() ) |
|
77 { |
|
78 iShutdown.Start(); |
|
79 } |
|
80 #endif |
|
81 |
|
82 // Add server to active scheduler |
|
83 StartL( KServerProcessName ); |
|
84 |
|
85 // Connect to file server. |
|
86 User::LeaveIfError( iFs.Connect() ); |
|
87 |
|
88 // register BUR |
|
89 iBackupNotification = CBaBackupSessionWrapper::NewL(); |
|
90 |
|
91 // register the file |
|
92 TFileName temp( iRegistry->GetFeaturesFilePathAndName() ); |
|
93 iBackupNotification->RegisterFileL( temp, *this ); |
|
94 |
|
95 // feature registry |
|
96 iRegistry = CFeatMgrFeatureRegistry::NewL( iFs, *this ); |
|
97 |
|
98 TRAPD(err,iRegistry->ReadFeatureFilesL()); |
|
99 switch (err) |
|
100 { |
|
101 case KErrNotFound: |
|
102 ERROR_LOG( "CFeatMgrServer::ConstructL() - no feature files found in ROM - going to panic"); |
|
103 User::Panic( KPanicCategory, EPanicNoFeatureFiles ); |
|
104 break; |
|
105 case KErrCorrupt: |
|
106 ERROR_LOG( "CFeatMgrServer::ConstructL() - feature information in ROM is invalid - going to panic"); |
|
107 User::Panic( KPanicCategory, EPanicInvalidFeatureInfo ); |
|
108 break; |
|
109 default: |
|
110 User::LeaveIfError(err); |
|
111 break; |
|
112 } |
|
113 |
|
114 // List and load plugins and feature info. |
|
115 TBool found = LoadPluginsL(); |
|
116 |
|
117 if( found ) |
|
118 { |
|
119 // Timer for deleting plugins and for comparing feature lists. |
|
120 iTimer = CFeatMgrTimer::NewL( *this ); |
|
121 } |
|
122 else |
|
123 { |
|
124 iRegistry->ReadRuntimeFeaturesL( iFeaturesReady ); |
|
125 } |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CFeatMgrServer::NewLC |
|
130 // Two-phased constructor. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 CFeatMgrServer* CFeatMgrServer::NewLC(const TInt aPriority) |
|
134 { |
|
135 FUNC_LOG |
|
136 |
|
137 CFeatMgrServer* self = new( ELeave ) CFeatMgrServer(aPriority, EUnsharableSessions); |
|
138 |
|
139 CleanupStack::PushL( self ); |
|
140 self->ConstructL(); |
|
141 |
|
142 return self; |
|
143 } |
|
144 |
|
145 #ifdef EXTENDED_FEATURE_MANAGER_TEST |
|
146 // ----------------------------------------------------------------------------- |
|
147 // A new session is being created |
|
148 // Cancel the shutdown timer if it was running |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CFeatMgrServer::AddSession() |
|
152 { |
|
153 FUNC_LOG |
|
154 |
|
155 ++iSessionCount; |
|
156 iShutdown.Cancel(); |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // A session is being destroyed |
|
161 // Start the shutdown timer if it is the last session. |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void CFeatMgrServer::DropSession() |
|
165 { |
|
166 FUNC_LOG |
|
167 |
|
168 if (--iSessionCount==0) |
|
169 { |
|
170 if( !iShutdown.IsActive() ) |
|
171 { |
|
172 iShutdown.Start(); |
|
173 } |
|
174 } |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CShutDown |
|
179 // --------------------------------------------------------------------------- |
|
180 inline CShutdown::CShutdown() |
|
181 :CTimer(-1) |
|
182 { |
|
183 CActiveScheduler::Add(this); |
|
184 } |
|
185 |
|
186 inline void CShutdown::ConstructL() |
|
187 { |
|
188 CTimer::ConstructL(); |
|
189 } |
|
190 |
|
191 inline void CShutdown::Start() |
|
192 { |
|
193 FUNC_LOG |
|
194 After(KShutdownTimeout); |
|
195 } |
|
196 |
|
197 void CShutdown::RunL() |
|
198 { |
|
199 FUNC_LOG |
|
200 CActiveScheduler::Stop(); |
|
201 } |
|
202 |
|
203 #endif // EXTENDED_FEATURE_MANAGER_TEST |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // Destructor |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 CFeatMgrServer::~CFeatMgrServer() |
|
210 { |
|
211 FUNC_LOG |
|
212 |
|
213 // Close all open sessions |
|
214 CFeatMgrSession* session=NULL; |
|
215 iSessionIter.SetToFirst(); |
|
216 |
|
217 while( (session = static_cast<CFeatMgrSession*>(iSessionIter++)) != NULL ) |
|
218 { |
|
219 delete session; |
|
220 } |
|
221 |
|
222 // Delete plugin handlers |
|
223 if ( !iPluginsDeleted ) |
|
224 { |
|
225 iPendingRequests = EFalse; // No need to serve pending requests |
|
226 iFeaturesReady = ETrue; // No need to read files anymore |
|
227 DeletePlugins(); |
|
228 } |
|
229 |
|
230 delete iTimer; |
|
231 iFs.Close(); |
|
232 iPluginList.Close(); |
|
233 |
|
234 // De register Backup and Restore and cleanup memory |
|
235 if( iBackupNotification ) |
|
236 { |
|
237 TFileName temp( iRegistry->GetFeaturesFilePathAndName() ); |
|
238 iBackupNotification->DeregisterFile( temp ); |
|
239 delete iBackupNotification; |
|
240 iBackupNotification = NULL; |
|
241 } |
|
242 |
|
243 delete iRegistry; |
|
244 } |
|
245 |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CFeatMgrServer::NewSessionL |
|
249 // Creates a new CSession2 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 CSession2* CFeatMgrServer::NewSessionL( const TVersion& aVersion, |
|
253 const RMessage2& /*aMessage*/ ) const |
|
254 { |
|
255 FUNC_LOG |
|
256 |
|
257 if ( !User::QueryVersionSupported( TVersion( KServerVersionMajor, |
|
258 KServerVersionMinor, |
|
259 KServerVersionBuild ), |
|
260 aVersion ) ) |
|
261 { |
|
262 User::Leave( KErrNotSupported ); |
|
263 } |
|
264 |
|
265 CSession2* session = CFeatMgrSession::NewL(*const_cast<CFeatMgrServer*>(this), *iRegistry ); |
|
266 |
|
267 return( session ); |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CFeatMgrServer::TimerFired |
|
272 // Handles timer firing. |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CFeatMgrServer::TimerFired() |
|
276 { |
|
277 FUNC_LOG |
|
278 |
|
279 // Delete plugin handlers. Plugin handler deletes the plugin. |
|
280 if ( !iPluginsDeleted ) |
|
281 { |
|
282 DeletePlugins(); |
|
283 } |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CFeatMgrServer::HandleFeatureChange() |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void CFeatMgrServer::HandleFeatureChange( TFeatureServerEntry& aFeature, TFeatureChangeType aType ) |
|
291 { |
|
292 FUNC_LOG |
|
293 |
|
294 CFeatMgrSession* session=NULL; |
|
295 TDblQueIter<CSession2> local_iSessionIter = iSessionIter; |
|
296 local_iSessionIter.SetToFirst(); |
|
297 |
|
298 while( (session = static_cast<CFeatMgrSession*>(local_iSessionIter++)) != NULL ) |
|
299 { |
|
300 session->ServiceNotifications( aFeature, aType ); |
|
301 } |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------------------------- |
|
305 // CFeatMgrServer::ResetAndDestroyArray |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 static void ResetAndDestroyArray( TAny* aPtr ) |
|
309 { |
|
310 RImplInfoPtrArray* array = static_cast< RImplInfoPtrArray* >( aPtr ); |
|
311 array->ResetAndDestroy(); |
|
312 array->Close(); |
|
313 } |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // CFeatMgrServer::LoadPluginsL() |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 TBool CFeatMgrServer::LoadPluginsL() |
|
320 { |
|
321 FUNC_LOG |
|
322 |
|
323 RImplInfoPtrArray implInfoArray; |
|
324 TBool ret( EFalse ); |
|
325 |
|
326 // Use ECom to read information about existing interface implementations |
|
327 _LIT8( KEmptyString, "" ); |
|
328 TEComResolverParams resolverParams; |
|
329 resolverParams.SetDataType (KEmptyString); |
|
330 resolverParams.SetWildcardMatch (ETrue); |
|
331 |
|
332 TCleanupItem cleanupItem( ResetAndDestroyArray, &implInfoArray ); |
|
333 CleanupStack::PushL( cleanupItem ); |
|
334 |
|
335 TIMESTAMP( "CFeatMgrServer::LoadPluginsL - ListImplementationsL start: " ) |
|
336 REComSession::ListImplementationsL( KFeatureInfoPluginInterfaceUid, |
|
337 #ifndef EXTENDED_FEATURE_MANAGER_TEST |
|
338 resolverParams, |
|
339 |
|
340 KRomOnlyResolverUid, |
|
341 #endif |
|
342 implInfoArray); |
|
343 TIMESTAMP( "CFeatMgrServer::LoadPluginsL - ListImplementationsL end: " ) |
|
344 |
|
345 // Check if any plugin was found. |
|
346 TInt count = implInfoArray.Count(); |
|
347 |
|
348 if ( count > 0 ) |
|
349 { |
|
350 |
|
351 for(TInt i = 0; i < count; i ++) |
|
352 { |
|
353 CFeatMgrPluginHandler* pluginHandler = NULL; |
|
354 TInt err( KErrNone ); |
|
355 |
|
356 // Create handler |
|
357 TRAP( err, pluginHandler = CFeatMgrPluginHandler::NewL( |
|
358 implInfoArray[i]->ImplementationUid(), *this) ); |
|
359 |
|
360 LOG_IF_ERROR1( err, "CFeatMgrServer::LoadPluginsL() - pluginHandler creation err %d", err ); |
|
361 |
|
362 // Apply first request for plugin to process |
|
363 if ( err == KErrNone ) |
|
364 { |
|
365 TRAP( err, pluginHandler->SendCommandL( |
|
366 FeatureInfoCommand::ELoadFeatureInfoCmdId ) ); |
|
367 } |
|
368 |
|
369 // Panic if error sth else than not supported |
|
370 if ( err != KErrNone && err != KErrNotSupported ) |
|
371 { |
|
372 ERROR_LOG2( "CFeatMgrServer::LoadPluginsL() - implementationUid: 0x%x, error: %d - going to panic", |
|
373 implInfoArray[i]->ImplementationUid(), err ); |
|
374 User::Panic( KPanicCategory, EPanicLoadPluginError ); |
|
375 } |
|
376 // If simple features are not supported by the plugin search for enhanced ones |
|
377 else if ( err == KErrNotSupported ) |
|
378 { |
|
379 // Reset error code |
|
380 err = KErrNone; |
|
381 TRAP( err, pluginHandler->SendCommandL( |
|
382 FeatureInfoCommand::ELoadEnhancedFeatureInfoCmdId ) ); |
|
383 |
|
384 // Panic if error since in this case the plugin does not support any feature |
|
385 if ( err != KErrNone ) |
|
386 { |
|
387 ERROR_LOG2( "CFeatMgrServer::LoadPluginsL() - implementationUid: 0x%x, error: %d - going to panic", |
|
388 implInfoArray[i]->ImplementationUid(), err ); |
|
389 User::Panic( KPanicCategory, EPanicLoadPluginError ); |
|
390 } |
|
391 } |
|
392 // If a simple or enhanced feature is supported by the plugin then append the plugin to the list |
|
393 if ( err == KErrNone ) |
|
394 { |
|
395 INFO_LOG1( "CFeatMgrServer::LoadPluginsL() - Add info of implementationUid: 0x%x", |
|
396 implInfoArray[i]->ImplementationUid() ); |
|
397 |
|
398 // Add information of the plugin to the plugin list |
|
399 SFeatMgrPluginInfo plugin; |
|
400 plugin.iPluginHandler = pluginHandler; |
|
401 // Set all plugins as not ready initially |
|
402 plugin.iPluginReady = EFalse; |
|
403 |
|
404 TInt err = iPluginList.Append(plugin); |
|
405 |
|
406 if ( err != KErrNone ) |
|
407 { |
|
408 ERROR_LOG2( "CFeatMgrServer::LoadPluginsL() - Saving plugin info of implementationUid: 0x%x, err %d", |
|
409 implInfoArray[i]->ImplementationUid(), err ); |
|
410 User::Leave( err ); |
|
411 } |
|
412 } |
|
413 } |
|
414 INFO_LOG1( "CFeatMgrServer::LoadPluginsL - interfaceUid.iUid == 0x%x, return plugins found", |
|
415 KFeatureInfoPluginInterfaceUid ); |
|
416 ret = ETrue; |
|
417 } |
|
418 |
|
419 else |
|
420 { |
|
421 iPluginsReady = ETrue; // Plugins not found. |
|
422 INFO_LOG1( "CFeatMgrServer::LoadPluginsL - interfaceUid.iUid == 0x%x, return plugins not found", |
|
423 KFeatureInfoPluginInterfaceUid ); |
|
424 ret = EFalse; |
|
425 } |
|
426 |
|
427 CleanupStack::PopAndDestroy(&implInfoArray); |
|
428 |
|
429 return ret; |
|
430 } |
|
431 |
|
432 |
|
433 // ----------------------------------------------------------------------------- |
|
434 // CFeatMgrServer::PluginsReady() |
|
435 // ----------------------------------------------------------------------------- |
|
436 |
|
437 TBool CFeatMgrServer::PluginsReady() const |
|
438 { |
|
439 FUNC_LOG |
|
440 return(iPluginsReady); |
|
441 } |
|
442 |
|
443 // ----------------------------------------------------------------------------- |
|
444 // CFeatMgrServer::ServicePendingRequests() |
|
445 // ----------------------------------------------------------------------------- |
|
446 |
|
447 void CFeatMgrServer::ServicePendingRequests() |
|
448 { |
|
449 FUNC_LOG |
|
450 |
|
451 CFeatMgrSession* session=NULL; |
|
452 iSessionIter.SetToFirst(); |
|
453 |
|
454 while( (session = static_cast<CFeatMgrSession*>(iSessionIter++)) != NULL ) |
|
455 { |
|
456 TRAPD( err, session->ServicePendingRequestsL() ); |
|
457 LOG_IF_ERROR1( err, "CFeatMgrServer::ServicePendingRequests - err %d", err ); |
|
458 } |
|
459 |
|
460 iPendingRequests = EFalse; |
|
461 } |
|
462 |
|
463 // ----------------------------------------------------------------------------- |
|
464 // CFeatMgrServer::DeletePlugins() |
|
465 // ----------------------------------------------------------------------------- |
|
466 |
|
467 void CFeatMgrServer::DeletePlugins() |
|
468 { |
|
469 FUNC_LOG |
|
470 |
|
471 // Set iPluginsReady to ETrue because plugins will be deleted. |
|
472 iPluginsReady = ETrue; |
|
473 TInt err( KErrNone ); |
|
474 |
|
475 // Load runtimefeatures.txt if not loaded yet. |
|
476 if ( !iFeaturesReady ) |
|
477 { |
|
478 TRAP( err, iRegistry->ReadRuntimeFeaturesL( iFeaturesReady ) ); |
|
479 |
|
480 LOG_IF_ERROR1( err, "CFeatMgrServer::DeletePlugins() - ReadRuntimeFeaturesL err %d", err ); |
|
481 } |
|
482 |
|
483 // Service pending requests before deleting plugins if not serviced yet. |
|
484 if ( iPendingRequests ) |
|
485 { |
|
486 ServicePendingRequests(); |
|
487 } |
|
488 |
|
489 // Delete plugin handlers |
|
490 TInt count = iPluginList.Count(); |
|
491 |
|
492 for ( TInt i = 0 ; i < count; i++ ) |
|
493 { |
|
494 delete iPluginList[i].iPluginHandler; |
|
495 iPluginList[i].iPluginHandler = NULL; |
|
496 } |
|
497 |
|
498 // Reset list of plugins |
|
499 iPluginList.Reset(); |
|
500 |
|
501 // Signal final closure of ecom session |
|
502 REComSession::FinalClose(); |
|
503 |
|
504 // All plugin handlers deleted |
|
505 iPluginsDeleted = ETrue; |
|
506 } |
|
507 |
|
508 // ----------------------------------------------------------------------------- |
|
509 // CFeatMgrServer::FeatureInfoL() |
|
510 // ----------------------------------------------------------------------------- |
|
511 |
|
512 void CFeatMgrServer::FeatureInfoL( RArray<FeatureInfoCommand::TFeature>& aFeatureList, |
|
513 CFeatMgrPluginHandler* aPluginHandler ) |
|
514 { |
|
515 FUNC_LOG |
|
516 |
|
517 // Save feature info received from the plugin |
|
518 TInt pluginCount = iPluginList.Count(); |
|
519 |
|
520 for ( TInt i = 0; i < pluginCount; i ++ ) |
|
521 { |
|
522 if ( iPluginList[i].iPluginHandler == aPluginHandler ) |
|
523 { |
|
524 iRegistry->MergePluginFeatures( aFeatureList ); |
|
525 // Send command to load enhanced feature info |
|
526 TRAPD( err, iPluginList[i].iPluginHandler->SendCommandL( |
|
527 FeatureInfoCommand::ELoadEnhancedFeatureInfoCmdId ) ); |
|
528 // Panic if error sth else than not supported |
|
529 if ( err != KErrNone && err != KErrNotSupported ) |
|
530 { |
|
531 ERROR_LOG1( "CFeatMgrServer::FeatureInfoL() - panicing due error %d", err ); |
|
532 User::Panic( KPanicCategory, EPanicLoadPluginError ); |
|
533 } |
|
534 // At this point we have simple feature supported by the plugin. |
|
535 // If no enhanced feature is supported, but a simple one is, then |
|
536 // the plugin is ready to be used. Otherwise continue to add the |
|
537 // enhanced features. |
|
538 else if( err == KErrNotSupported ) |
|
539 { |
|
540 iPluginList[i].iPluginReady = ETrue; |
|
541 } |
|
542 } |
|
543 else |
|
544 { |
|
545 INFO_LOG( "CFeatMgrServer::FeatureInfo - unknown plugin handler") ; |
|
546 } |
|
547 } |
|
548 |
|
549 CheckPluginsReadyL(); |
|
550 } |
|
551 |
|
552 // ----------------------------------------------------------------------------- |
|
553 // CFeatMgrServer::FeatureInfoL() |
|
554 // ----------------------------------------------------------------------------- |
|
555 |
|
556 void CFeatMgrServer::FeatureInfoL( RFeatureArray& aFeatureList, |
|
557 CFeatMgrPluginHandler* aPluginHandler ) |
|
558 { |
|
559 FUNC_LOG |
|
560 |
|
561 // Save feature info received from the plugin |
|
562 TInt pluginCount = iPluginList.Count(); |
|
563 |
|
564 for ( TInt i = 0; i < pluginCount; i ++ ) |
|
565 { |
|
566 if ( iPluginList[i].iPluginHandler == aPluginHandler ) |
|
567 { |
|
568 iRegistry->MergePluginFeatures( aFeatureList ); |
|
569 // Send another command if something left to process |
|
570 iPluginList[i].iPluginReady = ETrue; |
|
571 } |
|
572 else |
|
573 { |
|
574 INFO_LOG( "CFeatMgrServer::FeatureInfo - unknown plugin handler") ; |
|
575 } |
|
576 } |
|
577 |
|
578 CheckPluginsReadyL(); |
|
579 } |
|
580 |
|
581 // ----------------------------------------------------------------------------- |
|
582 // CFeatMgrServer::CheckPluginsReadyL() |
|
583 // ----------------------------------------------------------------------------- |
|
584 |
|
585 void CFeatMgrServer::CheckPluginsReadyL() |
|
586 { |
|
587 FUNC_LOG |
|
588 |
|
589 // If all plugins has responsed iPluginsReady is ETrue |
|
590 // else iPluginsReady is EFalse; |
|
591 TInt pluginCount = iPluginList.Count(); |
|
592 |
|
593 for ( TInt i = 0; i < pluginCount; i ++ ) |
|
594 { |
|
595 if ( iPluginList[i].iPluginReady ) |
|
596 { |
|
597 iPluginsReady = ETrue; |
|
598 } |
|
599 else |
|
600 { |
|
601 iPluginsReady = EFalse; |
|
602 break; |
|
603 } |
|
604 } |
|
605 |
|
606 // If plugins ready, read runtime features and call ServicePendingRequests of sessions. |
|
607 if ( iPluginsReady ) |
|
608 { |
|
609 // Load runtimefeatures.txt |
|
610 if ( !iFeaturesReady ) |
|
611 { |
|
612 iRegistry->ReadRuntimeFeaturesL( iFeaturesReady ); |
|
613 } |
|
614 |
|
615 if ( iPendingRequests ) |
|
616 { |
|
617 ServicePendingRequests(); |
|
618 } |
|
619 } |
|
620 } |
|
621 |
|
622 /** |
|
623 * Implementation of the pure virtual function. |
|
624 */ |
|
625 void CFeatMgrServer::HandleBackupOperationEventL( const TBackupOperationAttributes& /* aBackupOperationAttributes */ ) |
|
626 { |
|
627 return; |
|
628 } |
|
629 |
|
630 /** |
|
631 * There is a flag state variable being passed into Feature Manager as type MBackupObserver::TFileLockFlags. |
|
632 * Only certain combinations of these flags are valid for Feature Manager and if the combination is |
|
633 * not valid, then because there is no way of returning an error it will just set the internal state |
|
634 * machine into an "error" state. |
|
635 * Given our current state and our goto state (i.e. where we are at the moment and where we want to goto) |
|
636 * the state machine checks that this is a valid path in our state machine and then perform the correct |
|
637 * operations to get us to the next valid state. It also calls the correct Feature manager functions to |
|
638 * accomplish this operation. |
|
639 */ |
|
640 void CFeatMgrServer::ChangeFileLockL( const TDesC& /* aFileName */, TFileLockFlags aFlags ) |
|
641 { |
|
642 // There is only one file we are concerned with, so |
|
643 // don't check the filename matches |
|
644 // Default TOperationType type to ENone (we are ignoring this value) |
|
645 TBackupOperationAttributes attribs( aFlags, ENone ); |
|
646 iBurState.BUROperationL( attribs ); |
|
647 |
|
648 return; |
|
649 } |
|
650 |
|
651 |
|
652 /** |
|
653 * Generic return function, to return the state of the machine back to normal. |
|
654 * This can only occur from certain states. |
|
655 */ |
|
656 BURStatus CFeatMgrServer::Goto_NormalState( BURStatus /* aCurrent */ ) |
|
657 { |
|
658 return EFeatMgrBURState_None; // all roads lead to normal state |
|
659 } |
|
660 |
|
661 /** |
|
662 * This function handles error recovery from an invalid state. It will return the feature |
|
663 * maneger back to normal, in both it's internal state machine state, and it's internal |
|
664 * variables. |
|
665 */ |
|
666 BURStatus CFeatMgrServer::Goto_ErrorState( BURStatus aCurrent ) |
|
667 { |
|
668 BURStatus aNewState = EFeatMgrBURState_None; // fail safe: all roads lead to normal state |
|
669 TInt err( KErrNone ); |
|
670 |
|
671 switch( aCurrent ) |
|
672 { |
|
673 case( EFeatMgrBURState_BackupStarted ) : |
|
674 iPluginsReady = ETrue; |
|
675 ServicePendingRequests(); |
|
676 break; |
|
677 case( EFeatMgrBURState_RestoreStarted ) : |
|
678 iPluginsReady = EFalse; |
|
679 iPluginsDeleted = EFalse; |
|
680 iPendingRequests = ETrue; |
|
681 iFeaturesReady = EFalse; |
|
682 // re-read the new features; |
|
683 ClearFeatures(); |
|
684 TRAP( err, LoadFeaturesL() ); |
|
685 // Stop queuing |
|
686 iPluginsReady = ETrue; |
|
687 // commit the pending change requests |
|
688 ServicePendingRequests(); |
|
689 break; |
|
690 case( EFeatMgrBURState_BackupEnded ) : |
|
691 case( EFeatMgrBURState_RestoreEnded ) : |
|
692 break; |
|
693 default : |
|
694 break; |
|
695 } |
|
696 |
|
697 aNewState = EFeatMgrBURState_Error; // state++ |
|
698 return aNewState; |
|
699 } |
|
700 |
|
701 BURStatus CFeatMgrServer::Goto_StartBackupState( BURStatus /* aCurrent */ ) |
|
702 { |
|
703 BURStatus aNewState = EFeatMgrBURState_BackupStarted; // state++ |
|
704 iPluginsReady = EFalse; |
|
705 return aNewState; |
|
706 } |
|
707 |
|
708 BURStatus CFeatMgrServer::Goto_EndBackupState( BURStatus /* aCurrent */ ) |
|
709 { |
|
710 BURStatus aNewState = EFeatMgrBURState_BackupEnded; // state++ |
|
711 |
|
712 iPluginsReady = ETrue; |
|
713 ServicePendingRequests(); |
|
714 // no error from ServicePendingRequests() is possible |
|
715 |
|
716 return aNewState; |
|
717 } |
|
718 |
|
719 BURStatus CFeatMgrServer::Goto_StartRestoreState( BURStatus /* aCurrent */ ) |
|
720 { |
|
721 // remarkably like Goto_StartBackupState |
|
722 BURStatus aNewState = EFeatMgrBURState_RestoreStarted; // state++ |
|
723 iPluginsReady = EFalse; |
|
724 return aNewState; |
|
725 } |
|
726 |
|
727 BURStatus CFeatMgrServer::Goto_EndRestoreState( BURStatus /* aCurrent */ ) |
|
728 { |
|
729 BURStatus aNewState = EFeatMgrBURState_Error; // fail safe |
|
730 TInt err( KErrNone ); |
|
731 |
|
732 iPluginsReady = EFalse; |
|
733 iPluginsDeleted = EFalse; |
|
734 iPendingRequests = ETrue; |
|
735 iFeaturesReady = EFalse; |
|
736 |
|
737 // re-read the new features |
|
738 // Only call the next function if the previous one was |
|
739 // successfully completed. |
|
740 ClearFeatures(); |
|
741 TRAP( err, LoadFeaturesL() ); |
|
742 if( err == KErrNone ) |
|
743 { |
|
744 TRAP( err, HandleRestoredNotificationsL() ); |
|
745 } |
|
746 |
|
747 if( err != KErrNone ) |
|
748 { |
|
749 // error condition |
|
750 aNewState = EFeatMgrBURState_Error; |
|
751 } |
|
752 else |
|
753 { |
|
754 // Stop queuing |
|
755 iPluginsReady = ETrue; |
|
756 |
|
757 // commit the pending change requests |
|
758 ServicePendingRequests(); |
|
759 |
|
760 // Change state machine |
|
761 aNewState = EFeatMgrBURState_RestoreEnded; |
|
762 } |
|
763 |
|
764 return aNewState; |
|
765 } |
|
766 |
|
767 /** |
|
768 * This function will load features from files and plugins |
|
769 */ |
|
770 void CFeatMgrServer::LoadFeaturesL( void ) |
|
771 { |
|
772 // Load ROM (Z) |
|
773 TRAPD( err, iRegistry->ReadFeatureFilesL() ); |
|
774 if( KErrNotFound == err) |
|
775 { |
|
776 ERROR_LOG( "CFeatMgrServer::ConstructL() & CallReadFeatureFilesL() - no feature files found in ROM - going to panic"); |
|
777 User::Panic( KPanicCategory, EPanicNoFeatureFiles ); |
|
778 } |
|
779 else |
|
780 { |
|
781 User::LeaveIfError(err); |
|
782 } |
|
783 |
|
784 // Load RAM (C) |
|
785 // List and load plugins and feature info. |
|
786 TBool found = LoadPluginsL(); |
|
787 |
|
788 if( found ) |
|
789 { |
|
790 // Timer for deleting plugins and for comparing feature lists. |
|
791 iTimer = CFeatMgrTimer::NewL( *this ); |
|
792 } |
|
793 else |
|
794 { |
|
795 TRAPD( err, iRegistry->ReadRuntimeFeaturesL( iFeaturesReady ) ); |
|
796 if( KErrNotFound == err) |
|
797 { |
|
798 User::Panic( KPanicCategory, EPanicNoFeatureFiles ); |
|
799 } |
|
800 else |
|
801 { |
|
802 User::LeaveIfError(err); |
|
803 } |
|
804 } |
|
805 |
|
806 return; |
|
807 } |
|
808 |
|
809 |
|
810 /** |
|
811 * Discover which features have changes wrt the restore operation |
|
812 */ |
|
813 void CFeatMgrServer::HandleRestoredNotificationsL( void ) |
|
814 { |
|
815 iRegistry->HandleRestoredFeatureNotificationsL(); |
|
816 |
|
817 return; |
|
818 } |
|
819 |
|
820 /** |
|
821 * This function will clear features from RAM |
|
822 */ |
|
823 void CFeatMgrServer::ClearFeatures( void ) |
|
824 { |
|
825 // Delete plugin handlers |
|
826 if ( !iPluginsDeleted ) |
|
827 { |
|
828 // Delete plugin handlers |
|
829 TInt count = iPluginList.Count(); |
|
830 for ( TInt i = 0 ; i < count; i++ ) |
|
831 { |
|
832 delete iPluginList[i].iPluginHandler; |
|
833 iPluginList[i].iPluginHandler = NULL; |
|
834 } |
|
835 |
|
836 // Reset list of plugins |
|
837 iPluginList.Reset(); |
|
838 iPluginList.Close(); |
|
839 |
|
840 // All plugin handlers deleted |
|
841 iPluginsDeleted = EFalse; |
|
842 } |
|
843 |
|
844 if( NULL != iRegistry ) |
|
845 { |
|
846 iRegistry->ResetFeatures(); |
|
847 } |
|
848 |
|
849 return; |
|
850 } |
|
851 |
|
852 |
|
853 // ============================= LOCAL FUNCTIONS =============================== |
|
854 |
|
855 // ----------------------------------------------------------------------------- |
|
856 // Function that starts the FeatMgrServer. |
|
857 // ----------------------------------------------------------------------------- |
|
858 // |
|
859 static void RunServerL() |
|
860 { |
|
861 FUNC_LOG |
|
862 |
|
863 // Naming the server thread after the startup helps to debug panics |
|
864 User::LeaveIfError( User::RenameProcess( KServerProcessName ) ); |
|
865 |
|
866 User::LeaveIfError( User::RenameThread( KServerProcessName ) ); |
|
867 |
|
868 // Create and install the active scheduler we need |
|
869 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; |
|
870 CleanupStack::PushL( scheduler ); |
|
871 |
|
872 CActiveScheduler::Install( scheduler ); |
|
873 |
|
874 // Now we are ready to instantiate the actual CServer2 instance |
|
875 CFeatMgrServer* server = CFeatMgrServer::NewLC( KServerCActivePriority ); |
|
876 |
|
877 // Initialisation complete, now signal the client |
|
878 RProcess::Rendezvous(KErrNone); |
|
879 |
|
880 INFO_LOG( "RunServerL() - Starting scheduler..." ); |
|
881 |
|
882 // Ready to run |
|
883 CActiveScheduler::Start(); |
|
884 |
|
885 INFO_LOG( "RunServerL() - Scheduler stopped" ); |
|
886 |
|
887 // Cleanup the server and scheduler |
|
888 CleanupStack::PopAndDestroy( server ); |
|
889 CleanupStack::PopAndDestroy( scheduler ); |
|
890 } |
|
891 |
|
892 // ----------------------------------------------------------------------------- |
|
893 // Main function |
|
894 // ----------------------------------------------------------------------------- |
|
895 // |
|
896 TInt E32Main() |
|
897 { |
|
898 FUNC_LOG |
|
899 |
|
900 __UHEAP_MARK; |
|
901 |
|
902 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
903 TInt ret = KErrNoMemory; |
|
904 |
|
905 if ( cleanup ) |
|
906 { |
|
907 TRAP( ret, RunServerL() ); |
|
908 delete cleanup; |
|
909 } |
|
910 |
|
911 __UHEAP_MARKEND; |
|
912 |
|
913 return ret; |
|
914 } |
|
915 |
|
916 // End of File |