1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/featuremgmt/featuremgr/src/serverexe/featmgrserver.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,819 @@
1.4 +// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +
1.20 +
1.21 +
1.22 +// INCLUDE FILES
1.23 +#include <ecom/ecom.h>
1.24 +#include <e32uid.h>
1.25 +#include "featmgrconfiguration.h"
1.26 +#include "featmgrserver.h"
1.27 +#include "featmgrsession.h"
1.28 +#include "featmgrpluginhandler.h"
1.29 +#include "featmgrdebug.h"
1.30 +#include "featmgrsecuritypolicy.h"
1.31 +#include <f32file.h>
1.32 +#include <s32file.h>
1.33 +
1.34 +_LIT(KPanicCategory, "FeatMgrServer");
1.35 +
1.36 +// ============================ MEMBER FUNCTIONS ===============================
1.37 +
1.38 +// -----------------------------------------------------------------------------
1.39 +// CFeatMgrServer::CFeatMgrServer
1.40 +// C++ default constructor can NOT contain any code, that
1.41 +// might leave.
1.42 +// -----------------------------------------------------------------------------
1.43 +//
1.44 +CFeatMgrServer::CFeatMgrServer( const TInt aPriority, const TServerType aType )
1.45 + :
1.46 + CPolicyServer( aPriority, KFeatMgrPlatSecPolicy, aType ), iBurState(this),
1.47 + iBURInProgress(EFalse),
1.48 + iPluginsReady(EFalse),
1.49 + iPluginsDeleted( EFalse ),
1.50 + iPendingRequests( ETrue ),
1.51 + iFeaturesReady(EFalse)
1.52 +
1.53 + {
1.54 + // Nothing to do
1.55 + }
1.56 +
1.57 +// -----------------------------------------------------------------------------
1.58 +// CFeatMgrServer::ConstructL
1.59 +// Symbian 2nd phase constructor can leave.
1.60 +// -----------------------------------------------------------------------------
1.61 +//
1.62 +void CFeatMgrServer::ConstructL()
1.63 + {
1.64 + FUNC_LOG
1.65 +
1.66 +#ifndef EXTENDED_FEATURE_MANAGER_TEST
1.67 + // Set server process system critical
1.68 + User::SetProcessCritical(User::ESystemCritical);
1.69 +#else
1.70 + iShutdown.ConstructL();
1.71 + // ensure the server still exits even if the 1st client fails to connect
1.72 + if( !iShutdown.IsActive() )
1.73 + {
1.74 + iShutdown.Start();
1.75 + }
1.76 +#endif
1.77 +
1.78 + // Add server to active scheduler
1.79 + StartL( KServerProcessName );
1.80 +
1.81 + // Connect to file server.
1.82 + User::LeaveIfError( iFs.Connect() );
1.83 +
1.84 + // register BUR
1.85 + iBackupNotification = CBaBackupSessionWrapper::NewL();
1.86 +
1.87 + // register the file
1.88 + TFileName temp( iRegistry->GetFeaturesFilePathAndName() );
1.89 + iBackupNotification->RegisterFileL( temp, *this );
1.90 +
1.91 + // feature registry
1.92 + iRegistry = CFeatMgrFeatureRegistry::NewL( iFs, *this );
1.93 +
1.94 + TRAPD(err,iRegistry->ReadFeatureFilesL());
1.95 + switch (err)
1.96 + {
1.97 + case KErrNotFound:
1.98 + ERROR_LOG( "CFeatMgrServer::ConstructL() - no feature files found in ROM - going to panic");
1.99 + ::FmgrFatalErrorL(err, KPanicCategory, EPanicNoFeatureFiles);
1.100 + break;
1.101 + case KErrCorrupt:
1.102 + ERROR_LOG( "CFeatMgrServer::ConstructL() - feature information in ROM is invalid - going to panic");
1.103 + ::FmgrFatalErrorL(err, KPanicCategory, EPanicInvalidFeatureInfo);
1.104 + break;
1.105 + default:
1.106 + User::LeaveIfError(err);
1.107 + break;
1.108 + }
1.109 +
1.110 + // List and load plugins and feature info.
1.111 + TBool found = LoadPluginsL();
1.112 +
1.113 + if( found )
1.114 + {
1.115 + // Timer for deleting plugins and for comparing feature lists.
1.116 + iTimer = CFeatMgrTimer::NewL( *this );
1.117 + }
1.118 + else
1.119 + {
1.120 + iRegistry->ReadRuntimeFeaturesL( iFeaturesReady );
1.121 + }
1.122 + }
1.123 +
1.124 +// -----------------------------------------------------------------------------
1.125 +// CFeatMgrServer::NewLC
1.126 +// Two-phased constructor.
1.127 +// -----------------------------------------------------------------------------
1.128 +//
1.129 +CFeatMgrServer* CFeatMgrServer::NewLC(const TInt aPriority)
1.130 + {
1.131 + FUNC_LOG
1.132 +
1.133 + CFeatMgrServer* self = new( ELeave ) CFeatMgrServer(aPriority, EUnsharableSessions);
1.134 +
1.135 + CleanupStack::PushL( self );
1.136 + self->ConstructL();
1.137 +
1.138 + return self;
1.139 + }
1.140 +
1.141 +#ifdef EXTENDED_FEATURE_MANAGER_TEST
1.142 +// -----------------------------------------------------------------------------
1.143 +// A new session is being created
1.144 +// Cancel the shutdown timer if it was running
1.145 +// -----------------------------------------------------------------------------
1.146 +//
1.147 +void CFeatMgrServer::AddSession()
1.148 + {
1.149 + FUNC_LOG
1.150 +
1.151 + ++iSessionCount;
1.152 + iShutdown.Cancel();
1.153 + }
1.154 +
1.155 +// -----------------------------------------------------------------------------
1.156 +// A session is being destroyed
1.157 +// Start the shutdown timer if it is the last session.
1.158 +// -----------------------------------------------------------------------------
1.159 +//
1.160 +void CFeatMgrServer::DropSession()
1.161 + {
1.162 + FUNC_LOG
1.163 +
1.164 + if (--iSessionCount==0)
1.165 + {
1.166 + if( !iShutdown.IsActive() )
1.167 + {
1.168 + iShutdown.Start();
1.169 + }
1.170 + }
1.171 + }
1.172 +
1.173 +// ---------------------------------------------------------------------------
1.174 +// CShutDown
1.175 +// ---------------------------------------------------------------------------
1.176 +inline CShutdown::CShutdown()
1.177 + :CTimer(-1)
1.178 + {
1.179 + CActiveScheduler::Add(this);
1.180 + }
1.181 +
1.182 +inline void CShutdown::ConstructL()
1.183 + {
1.184 + CTimer::ConstructL();
1.185 + }
1.186 +
1.187 +inline void CShutdown::Start()
1.188 + {
1.189 + FUNC_LOG
1.190 + After(KShutdownTimeout);
1.191 + }
1.192 +
1.193 +void CShutdown::RunL()
1.194 + {
1.195 + FUNC_LOG
1.196 + CActiveScheduler::Stop();
1.197 + }
1.198 +
1.199 +#endif // EXTENDED_FEATURE_MANAGER_TEST
1.200 +
1.201 +// -----------------------------------------------------------------------------
1.202 +// Destructor
1.203 +// -----------------------------------------------------------------------------
1.204 +//
1.205 +CFeatMgrServer::~CFeatMgrServer()
1.206 + {
1.207 + FUNC_LOG
1.208 +
1.209 + // Close all open sessions
1.210 + CFeatMgrSession* session=NULL;
1.211 + iSessionIter.SetToFirst();
1.212 +
1.213 + while( (session = static_cast<CFeatMgrSession*>(iSessionIter++)) != NULL )
1.214 + {
1.215 + delete session;
1.216 + }
1.217 +
1.218 + // Delete plugin handlers
1.219 + if ( !iPluginsDeleted )
1.220 + {
1.221 + iPendingRequests = EFalse; // No need to serve pending requests
1.222 + iFeaturesReady = ETrue; // No need to read files anymore
1.223 + DeletePlugins();
1.224 + }
1.225 +
1.226 + delete iTimer;
1.227 + iPluginList.Close();
1.228 +
1.229 + // De register Backup and Restore and cleanup memory
1.230 + if( iBackupNotification )
1.231 + {
1.232 + TFileName temp( iRegistry->GetFeaturesFilePathAndName() );
1.233 + iBackupNotification->DeregisterFile( temp );
1.234 + delete iBackupNotification;
1.235 + iBackupNotification = NULL;
1.236 + }
1.237 +
1.238 + delete iRegistry;
1.239 + iFs.Close();
1.240 + }
1.241 +
1.242 +
1.243 +// -----------------------------------------------------------------------------
1.244 +// CFeatMgrServer::NewSessionL
1.245 +// Creates a new CSession2
1.246 +// -----------------------------------------------------------------------------
1.247 +//
1.248 +CSession2* CFeatMgrServer::NewSessionL( const TVersion& aVersion,
1.249 + const RMessage2& /*aMessage*/ ) const
1.250 + {
1.251 + FUNC_LOG
1.252 +
1.253 + if ( !User::QueryVersionSupported( TVersion( KServerVersionMajor,
1.254 + KServerVersionMinor,
1.255 + KServerVersionBuild ),
1.256 + aVersion ) )
1.257 + {
1.258 + User::Leave( KErrNotSupported );
1.259 + }
1.260 +
1.261 + CSession2* session = CFeatMgrSession::NewL(*const_cast<CFeatMgrServer*>(this), *iRegistry );
1.262 +
1.263 + return( session );
1.264 + }
1.265 +
1.266 +// -----------------------------------------------------------------------------
1.267 +// CFeatMgrServer::TimerFired
1.268 +// Handles timer firing.
1.269 +// -----------------------------------------------------------------------------
1.270 +//
1.271 +void CFeatMgrServer::TimerFired()
1.272 + {
1.273 + FUNC_LOG
1.274 +
1.275 + // Delete plugin handlers. Plugin handler deletes the plugin.
1.276 + if ( !iPluginsDeleted )
1.277 + {
1.278 + DeletePlugins();
1.279 + }
1.280 + }
1.281 +
1.282 +// -----------------------------------------------------------------------------
1.283 +// CFeatMgrServer::HandleFeatureChange()
1.284 +// -----------------------------------------------------------------------------
1.285 +//
1.286 +void CFeatMgrServer::HandleFeatureChange( TFeatureServerEntry& aFeature, TFeatureChangeType aType )
1.287 + {
1.288 + FUNC_LOG
1.289 +
1.290 + CFeatMgrSession* session=NULL;
1.291 + TDblQueIter<CSession2> local_iSessionIter = iSessionIter;
1.292 + local_iSessionIter.SetToFirst();
1.293 +
1.294 + while( (session = static_cast<CFeatMgrSession*>(local_iSessionIter++)) != NULL )
1.295 + {
1.296 + session->ServiceNotifications( aFeature, aType );
1.297 + }
1.298 + }
1.299 +
1.300 +// ---------------------------------------------------------------------------
1.301 +// CFeatMgrServer::ResetAndDestroyArray
1.302 +// ---------------------------------------------------------------------------
1.303 +//
1.304 +static void ResetAndDestroyArray( TAny* aPtr )
1.305 + {
1.306 + RImplInfoPtrArray* array = static_cast< RImplInfoPtrArray* >( aPtr );
1.307 + array->ResetAndDestroy();
1.308 + array->Close();
1.309 + }
1.310 +
1.311 +// -----------------------------------------------------------------------------
1.312 +// CFeatMgrServer::LoadPluginsL()
1.313 +// -----------------------------------------------------------------------------
1.314 +//
1.315 +TBool CFeatMgrServer::LoadPluginsL()
1.316 + {
1.317 + FUNC_LOG
1.318 +
1.319 + RImplInfoPtrArray implInfoArray;
1.320 + TBool ret( EFalse );
1.321 +
1.322 + // Use ECom to read information about existing interface implementations
1.323 +#ifndef EXTENDED_FEATURE_MANAGER_TEST
1.324 + _LIT8( KResolverString, "" );
1.325 +#else
1.326 + _LIT8( KResolverString, "efmtestplugin" ); //In test server we only want test plugins.
1.327 +#endif
1.328 + TEComResolverParams resolverParams;
1.329 + resolverParams.SetDataType (KResolverString);
1.330 + resolverParams.SetWildcardMatch (ETrue);
1.331 +
1.332 + TCleanupItem cleanupItem( ResetAndDestroyArray, &implInfoArray );
1.333 + CleanupStack::PushL( cleanupItem );
1.334 +
1.335 + TIMESTAMP( "CFeatMgrServer::LoadPluginsL - ListImplementationsL start: " )
1.336 + REComSession::ListImplementationsL( KFeatureInfoPluginInterfaceUid,
1.337 + resolverParams,
1.338 +#ifndef EXTENDED_FEATURE_MANAGER_TEST
1.339 + KRomOnlyResolverUid,
1.340 +#endif
1.341 + implInfoArray);
1.342 + TIMESTAMP( "CFeatMgrServer::LoadPluginsL - ListImplementationsL end: " )
1.343 +
1.344 + // Check if any plugin was found.
1.345 + TInt count = implInfoArray.Count();
1.346 + if(count == 0)
1.347 + {
1.348 + iPluginsReady = ETrue; // Plugins not found.
1.349 + INFO_LOG1("CFeatMgrServer::LoadPluginsL - interfaceUid.iUid == 0x%x, return plugins not found", KFeatureInfoPluginInterfaceUid);
1.350 + ret = EFalse;
1.351 + }
1.352 + else
1.353 + {
1.354 + for(TInt i=0;i<count;++i)
1.355 + {
1.356 + CFeatMgrPluginHandler* pluginHandler = NULL;
1.357 + TRAPD(err, pluginHandler = CFeatMgrPluginHandler::NewL(implInfoArray[i]->ImplementationUid(), *this));
1.358 + if(err == KErrNone)
1.359 + {
1.360 + CleanupStack::PushL(pluginHandler);
1.361 + TRAP(err, pluginHandler->SendCommandL(FeatureInfoCommand::ELoadFeatureInfoCmdId));
1.362 + if(err == KErrNotSupported)
1.363 + {
1.364 + TRAP(err, pluginHandler->SendCommandL(FeatureInfoCommand::ELoadEnhancedFeatureInfoCmdId));
1.365 + }
1.366 + }
1.367 + if(err == KErrNoMemory)
1.368 + {
1.369 + User::Leave(err);
1.370 + }
1.371 + else if(err != KErrNone)
1.372 + {
1.373 + ERROR_LOG2("CFeatMgrServer::LoadPluginsL() - implementationUid: 0x%x, error: %d - going to panic", implInfoArray[i]->ImplementationUid(), err);
1.374 + ::FmgrFatalErrorL(err, KPanicCategory, EPanicLoadPluginError);
1.375 + }
1.376 + // Add information of the plugin to the plugin list. Set all plugins as not ready initially.
1.377 + SFeatMgrPluginInfo plugin;
1.378 + plugin.iPluginHandler = pluginHandler;
1.379 + plugin.iPluginReady = EFalse;
1.380 + User::LeaveIfError(iPluginList.Append(plugin));
1.381 + CleanupStack::Pop(pluginHandler);
1.382 + }
1.383 + INFO_LOG1("CFeatMgrServer::LoadPluginsL - interfaceUid.iUid == 0x%x, return plugins found", KFeatureInfoPluginInterfaceUid);
1.384 + ret = ETrue;
1.385 + }
1.386 +
1.387 + CleanupStack::PopAndDestroy(&implInfoArray);
1.388 +
1.389 + return ret;
1.390 + }
1.391 +
1.392 +
1.393 +// -----------------------------------------------------------------------------
1.394 +// CFeatMgrServer::PluginsReady()
1.395 +// -----------------------------------------------------------------------------
1.396 +
1.397 +TBool CFeatMgrServer::PluginsReady() const
1.398 + {
1.399 + FUNC_LOG
1.400 + return(iPluginsReady);
1.401 + }
1.402 +
1.403 +// -----------------------------------------------------------------------------
1.404 +// CFeatMgrServer::BackupIsInProgress()
1.405 +// -----------------------------------------------------------------------------
1.406 +TBool CFeatMgrServer::BURIsInProgress() const
1.407 + {
1.408 + FUNC_LOG
1.409 + return(iBURInProgress);
1.410 + }
1.411 +
1.412 +// -----------------------------------------------------------------------------
1.413 +// CFeatMgrServer::ServicePendingRequests()
1.414 +// -----------------------------------------------------------------------------
1.415 +
1.416 +void CFeatMgrServer::ServicePendingRequests()
1.417 + {
1.418 + FUNC_LOG
1.419 +
1.420 + CFeatMgrSession* session=NULL;
1.421 + iSessionIter.SetToFirst();
1.422 +
1.423 + while( (session = static_cast<CFeatMgrSession*>(iSessionIter++)) != NULL )
1.424 + {
1.425 + TRAPD( err, session->ServicePendingRequestsL() );
1.426 + LOG_IF_ERROR1( err, "CFeatMgrServer::ServicePendingRequests - err %d", err );
1.427 + }
1.428 +
1.429 + iPendingRequests = EFalse;
1.430 + }
1.431 +
1.432 +// -----------------------------------------------------------------------------
1.433 +// CFeatMgrServer::DeletePlugins()
1.434 +// -----------------------------------------------------------------------------
1.435 +
1.436 +void CFeatMgrServer::DeletePlugins()
1.437 + {
1.438 + FUNC_LOG
1.439 +
1.440 + // Set iPluginsReady to ETrue because plugins will be deleted.
1.441 + iPluginsReady = ETrue;
1.442 + TInt err( KErrNone );
1.443 +
1.444 + // Load runtimefeatures.txt if not loaded yet.
1.445 + if ( !iFeaturesReady )
1.446 + {
1.447 + TRAP( err, iRegistry->ReadRuntimeFeaturesL( iFeaturesReady ) );
1.448 +
1.449 + LOG_IF_ERROR1( err, "CFeatMgrServer::DeletePlugins() - ReadRuntimeFeaturesL err %d", err );
1.450 + }
1.451 +
1.452 + // Service pending requests before deleting plugins if not serviced yet.
1.453 + if ( iPendingRequests )
1.454 + {
1.455 + ServicePendingRequests();
1.456 + }
1.457 +
1.458 + // Delete plugin handlers
1.459 + TInt count = iPluginList.Count();
1.460 +
1.461 + for ( TInt i = 0 ; i < count; i++ )
1.462 + {
1.463 + delete iPluginList[i].iPluginHandler;
1.464 + iPluginList[i].iPluginHandler = NULL;
1.465 + }
1.466 +
1.467 + // Reset list of plugins
1.468 + iPluginList.Reset();
1.469 +
1.470 + // Signal final closure of ecom session
1.471 + REComSession::FinalClose();
1.472 +
1.473 + // All plugin handlers deleted
1.474 + iPluginsDeleted = ETrue;
1.475 + }
1.476 +
1.477 +// -----------------------------------------------------------------------------
1.478 +// CFeatMgrServer::FeatureInfoL()
1.479 +// -----------------------------------------------------------------------------
1.480 +
1.481 +void CFeatMgrServer::FeatureInfoL( RArray<FeatureInfoCommand::TFeature>& aFeatureList,
1.482 + CFeatMgrPluginHandler* aPluginHandler )
1.483 + {
1.484 + FUNC_LOG
1.485 +
1.486 + // Save feature info received from the plugin
1.487 + TInt pluginCount = iPluginList.Count();
1.488 +
1.489 + for ( TInt i = 0; i < pluginCount; i ++ )
1.490 + {
1.491 + if ( iPluginList[i].iPluginHandler == aPluginHandler )
1.492 + {
1.493 + iRegistry->MergePluginFeaturesL( aFeatureList );
1.494 + // Send command to load enhanced feature info
1.495 + TRAPD( err, iPluginList[i].iPluginHandler->SendCommandL(
1.496 + FeatureInfoCommand::ELoadEnhancedFeatureInfoCmdId ) );
1.497 + // Panic if error sth else than not supported
1.498 + if ( err != KErrNone && err != KErrNotSupported )
1.499 + {
1.500 + ERROR_LOG1( "CFeatMgrServer::FeatureInfoL() - panicing due error %d", err );
1.501 + ::FmgrFatalErrorL(err, KPanicCategory, EPanicLoadPluginError);
1.502 + }
1.503 + // At this point we have simple feature supported by the plugin.
1.504 + // If no enhanced feature is supported, but a simple one is, then
1.505 + // the plugin is ready to be used. Otherwise continue to add the
1.506 + // enhanced features.
1.507 + else if( err == KErrNotSupported )
1.508 + {
1.509 + iPluginList[i].iPluginReady = ETrue;
1.510 + }
1.511 + }
1.512 + else
1.513 + {
1.514 + INFO_LOG( "CFeatMgrServer::FeatureInfo - unknown plugin handler") ;
1.515 + }
1.516 + }
1.517 +
1.518 + CheckPluginsReadyL();
1.519 + }
1.520 +
1.521 +// -----------------------------------------------------------------------------
1.522 +// CFeatMgrServer::FeatureInfoL()
1.523 +// -----------------------------------------------------------------------------
1.524 +
1.525 +void CFeatMgrServer::FeatureInfoL( RFeatureArray& aFeatureList,
1.526 + CFeatMgrPluginHandler* aPluginHandler )
1.527 + {
1.528 + FUNC_LOG
1.529 +
1.530 + // Save feature info received from the plugin
1.531 + TInt pluginCount = iPluginList.Count();
1.532 +
1.533 + for ( TInt i = 0; i < pluginCount; i ++ )
1.534 + {
1.535 + if ( iPluginList[i].iPluginHandler == aPluginHandler )
1.536 + {
1.537 + iRegistry->MergePluginFeaturesL( aFeatureList );
1.538 + // Send another command if something left to process
1.539 + iPluginList[i].iPluginReady = ETrue;
1.540 + }
1.541 + else
1.542 + {
1.543 + INFO_LOG( "CFeatMgrServer::FeatureInfo - unknown plugin handler") ;
1.544 + }
1.545 + }
1.546 +
1.547 + CheckPluginsReadyL();
1.548 + }
1.549 +
1.550 +// -----------------------------------------------------------------------------
1.551 +// CFeatMgrServer::CheckPluginsReadyL()
1.552 +// -----------------------------------------------------------------------------
1.553 +
1.554 +void CFeatMgrServer::CheckPluginsReadyL()
1.555 + {
1.556 + FUNC_LOG
1.557 +
1.558 + // If all plugins has responsed iPluginsReady is ETrue
1.559 + // else iPluginsReady is EFalse;
1.560 + TInt pluginCount = iPluginList.Count();
1.561 +
1.562 + for ( TInt i = 0; i < pluginCount; i ++ )
1.563 + {
1.564 + if ( iPluginList[i].iPluginReady )
1.565 + {
1.566 + iPluginsReady = ETrue;
1.567 + }
1.568 + else
1.569 + {
1.570 + iPluginsReady = EFalse;
1.571 + break;
1.572 + }
1.573 + }
1.574 +
1.575 + // If plugins ready, read runtime features and call ServicePendingRequests of sessions.
1.576 + if ( iPluginsReady )
1.577 + {
1.578 + // Load runtimefeatures.txt
1.579 + if ( !iFeaturesReady )
1.580 + {
1.581 + iRegistry->ReadRuntimeFeaturesL( iFeaturesReady );
1.582 + }
1.583 +
1.584 + if ( iPendingRequests )
1.585 + {
1.586 + ServicePendingRequests();
1.587 + }
1.588 + }
1.589 + }
1.590 +
1.591 +/**
1.592 + * Implementation of the pure virtual function.
1.593 + */
1.594 +void CFeatMgrServer::HandleBackupOperationEventL( const TBackupOperationAttributes& /* aBackupOperationAttributes */ )
1.595 + {
1.596 + return;
1.597 + }
1.598 +
1.599 +/**
1.600 + * There is a flag state variable being passed into Feature Manager as type MBackupObserver::TFileLockFlags.
1.601 + * Only certain combinations of these flags are valid for Feature Manager and if the combination is
1.602 + * not valid, then because there is no way of returning an error it will just set the internal state
1.603 + * machine into an "error" state.
1.604 + * Given our current state and our goto state (i.e. where we are at the moment and where we want to goto)
1.605 + * the state machine checks that this is a valid path in our state machine and then perform the correct
1.606 + * operations to get us to the next valid state. It also calls the correct Feature manager functions to
1.607 + * accomplish this operation.
1.608 + */
1.609 +void CFeatMgrServer::ChangeFileLockL( const TDesC& /* aFileName */, TFileLockFlags aFlags )
1.610 + {
1.611 + // There is only one file we are concerned with, so
1.612 + // don't check the filename matches
1.613 + // Default TOperationType type to ENone (we are ignoring this value)
1.614 + TBackupOperationAttributes attribs( aFlags, ENone );
1.615 + iBurState.BUROperationL( attribs );
1.616 +
1.617 + return;
1.618 + }
1.619 +
1.620 +
1.621 +/**
1.622 + * Generic return function, to return the state of the machine back to normal.
1.623 + * This can only occur from certain states.
1.624 + */
1.625 +BURStatus CFeatMgrServer::Goto_NormalState( BURStatus /* aCurrent */ )
1.626 + {
1.627 + return EFeatMgrBURState_None; // all roads lead to normal state
1.628 + }
1.629 +
1.630 +/**
1.631 + * This function handles error recovery from an invalid state. It will return the feature
1.632 + * maneger back to normal, in both it's internal state machine state, and it's internal
1.633 + * variables.
1.634 + */
1.635 +BURStatus CFeatMgrServer::Goto_ErrorState( BURStatus aCurrent )
1.636 + {
1.637 + BURStatus aNewState = EFeatMgrBURState_None; // fail safe: all roads lead to normal state
1.638 +
1.639 + switch( aCurrent )
1.640 + {
1.641 + case( EFeatMgrBURState_BackupStarted ) :
1.642 + iBURInProgress = EFalse;
1.643 + ServicePendingRequests();
1.644 + break;
1.645 + case( EFeatMgrBURState_RestoreStarted ) :
1.646 + iPluginsReady = EFalse;
1.647 + iPluginsDeleted = EFalse;
1.648 + iPendingRequests = ETrue;
1.649 + iFeaturesReady = EFalse;
1.650 + // re-read the new features;
1.651 + TRAP_IGNORE(ClearFeaturesL() );
1.652 + TRAP_IGNORE(LoadFeaturesL() );
1.653 + // Stop queuing
1.654 + iPluginsReady = ETrue;
1.655 + // commit the pending change requests
1.656 + ServicePendingRequests();
1.657 + break;
1.658 + case( EFeatMgrBURState_BackupEnded ) :
1.659 + case( EFeatMgrBURState_RestoreEnded ) :
1.660 + break;
1.661 + default :
1.662 + break;
1.663 + }
1.664 +
1.665 + aNewState = EFeatMgrBURState_Error; // state++
1.666 + return aNewState;
1.667 + }
1.668 +
1.669 +BURStatus CFeatMgrServer::Goto_StartBackupState( BURStatus /* aCurrent */ )
1.670 + {
1.671 + BURStatus aNewState = EFeatMgrBURState_BackupStarted; // state++
1.672 + iBURInProgress = ETrue;
1.673 + return aNewState;
1.674 + }
1.675 +
1.676 +BURStatus CFeatMgrServer::Goto_EndBackupState( BURStatus /* aCurrent */ )
1.677 + {
1.678 + BURStatus aNewState = EFeatMgrBURState_BackupEnded; // state++
1.679 +
1.680 + iBURInProgress = EFalse;
1.681 + ServicePendingRequests();
1.682 + // no error from ServicePendingRequests() is possible
1.683 +
1.684 + return aNewState;
1.685 + }
1.686 +
1.687 +BURStatus CFeatMgrServer::Goto_StartRestoreState( BURStatus /* aCurrent */ )
1.688 + {
1.689 + // remarkably like Goto_StartBackupState
1.690 + BURStatus aNewState = EFeatMgrBURState_RestoreStarted; // state++
1.691 + iBURInProgress = ETrue;
1.692 + return aNewState;
1.693 + }
1.694 +
1.695 +BURStatus CFeatMgrServer::Goto_EndRestoreState( BURStatus /* aCurrent */ )
1.696 + {
1.697 + BURStatus aNewState = EFeatMgrBURState_Error; // fail safe
1.698 + TInt err( KErrNone );
1.699 + iBURInProgress = EFalse;
1.700 + iPluginsReady = EFalse;
1.701 + iPluginsDeleted = EFalse;
1.702 + iPendingRequests = ETrue;
1.703 + iFeaturesReady = EFalse;
1.704 +
1.705 + // re-read the new features
1.706 + // Only call the next function if the previous one was
1.707 + // successfully completed.
1.708 + TRAP(err, ClearFeaturesL() );
1.709 + if (err == KErrNone)
1.710 + {
1.711 + TRAP(err, LoadFeaturesL() );
1.712 + }
1.713 +
1.714 + if(err == KErrNone)
1.715 + {
1.716 + TRAP(err, HandleRestoredNotificationsL() );
1.717 + }
1.718 +
1.719 + if(err == KErrNone)
1.720 + {
1.721 + // Stop queuing
1.722 + iPluginsReady = ETrue;
1.723 +
1.724 + // commit the pending change requests
1.725 + ServicePendingRequests();
1.726 +
1.727 + // Change state machine
1.728 + aNewState = EFeatMgrBURState_RestoreEnded;
1.729 + }
1.730 + else
1.731 + {
1.732 + // error condition
1.733 + aNewState = EFeatMgrBURState_Error;
1.734 + }
1.735 +
1.736 + return aNewState;
1.737 + }
1.738 +
1.739 +/**
1.740 + * This function will load features from files and plugins
1.741 + */
1.742 +void CFeatMgrServer::LoadFeaturesL( void )
1.743 + {
1.744 + // Load ROM (Z)
1.745 + TRAPD( err, iRegistry->ReadFeatureFilesL() );
1.746 + if( KErrNotFound == err)
1.747 + {
1.748 + ERROR_LOG( "CFeatMgrServer::ConstructL() & CallReadFeatureFilesL() - no feature files found in ROM - going to panic");
1.749 + ::FmgrFatalErrorL(err, KPanicCategory, EPanicNoFeatureFiles);
1.750 + }
1.751 + else
1.752 + {
1.753 + User::LeaveIfError(err);
1.754 + }
1.755 +
1.756 + // Load RAM (C)
1.757 + // List and load plugins and feature info.
1.758 + TBool found = LoadPluginsL();
1.759 +
1.760 + if( found )
1.761 + {
1.762 + // Timer for deleting plugins and for comparing feature lists.
1.763 + iTimer = CFeatMgrTimer::NewL( *this );
1.764 + }
1.765 + else
1.766 + {
1.767 + TRAPD( err, iRegistry->ReadRuntimeFeaturesL( iFeaturesReady ) );
1.768 + if( KErrNotFound == err)
1.769 + {
1.770 + ::FmgrFatalErrorL(err, KPanicCategory, EPanicNoFeatureFiles);
1.771 + }
1.772 + else
1.773 + {
1.774 + User::LeaveIfError(err);
1.775 + }
1.776 + }
1.777 +
1.778 + return;
1.779 +}
1.780 +
1.781 +
1.782 +/**
1.783 + * Discover which features have changes wrt the restore operation
1.784 + */
1.785 +void CFeatMgrServer::HandleRestoredNotificationsL( void )
1.786 + {
1.787 + iRegistry->HandleRestoredFeatureNotificationsL();
1.788 + }
1.789 +
1.790 +/**
1.791 + * This function will clear features from RAM
1.792 + */
1.793 +void CFeatMgrServer::ClearFeaturesL( void )
1.794 + {
1.795 + // Delete plugin handlers
1.796 + if ( !iPluginsDeleted )
1.797 + {
1.798 + // Delete plugin handlers
1.799 + TInt count = iPluginList.Count();
1.800 + for ( TInt i = 0 ; i < count; i++ )
1.801 + {
1.802 + delete iPluginList[i].iPluginHandler;
1.803 + iPluginList[i].iPluginHandler = NULL;
1.804 + }
1.805 +
1.806 + // Reset list of plugins
1.807 + iPluginList.Reset();
1.808 + iPluginList.Close();
1.809 +
1.810 + // All plugin handlers deleted
1.811 + iPluginsDeleted = EFalse;
1.812 + }
1.813 +
1.814 + if( NULL != iRegistry )
1.815 + {
1.816 + iRegistry->ResetFeaturesL();
1.817 + }
1.818 +
1.819 + return;
1.820 +}
1.821 +
1.822 +// End of File