1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/frame/Registrar.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,412 @@
1.4 +// Copyright (c) 1997-2009 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 +// Implementation of the registrar class
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @internalComponent
1.23 + @file
1.24 +*/
1.25 +
1.26 +#include <barsc2.h> // CResourceFile
1.27 +#include <barsread2.h> // RResourceReader
1.28 +#include <bautils.h>
1.29 +#include <e32uid.h>
1.30 +#include <startup.hrh> // for EStartupStateNonCritical
1.31 +
1.32 +#include "ecompanics.h"
1.33 +#include "EComDebug.h"
1.34 +#include <ecom/ecom.h>
1.35 +#include <ecom/ecomerrorcodes.h>
1.36 +#include <ecom/ecomresolverparams.h>
1.37 +#include "TestUtilities.h" // For __FILE__LINE__
1.38 +#include "Registrar.h"
1.39 +#include "Discoverer.h"
1.40 +#include "BackupNotifier.h"
1.41 +#include "RegistryData.h"
1.42 +#include "EComUidCodes.h"
1.43 +#include "RegistrarObserver.h"
1.44 +#include "DriveInfo.h"
1.45 +#include "ParseImplementationData.h"
1.46 +#include "EComInternalErrorCodes.h"
1.47 +
1.48 +const TInt KMinBuffAllocSize = 1;
1.49 +
1.50 +
1.51 +#define UNUSED_VAR(a) a = a
1.52 +
1.53 +
1.54 +CRegistrar* CRegistrar::NewL(CRegistryData& aRegistry, MRegistrarObserver& aRegistrarObserver, RFs& aFs)
1.55 + {
1.56 + CRegistrar* self = new(ELeave) CRegistrar(aRegistry,aRegistrarObserver,aFs);
1.57 + CleanupStack::PushL(self);
1.58 + self->ConstructL();
1.59 + CleanupStack::Pop(self);
1.60 + return self;
1.61 + }
1.62 +
1.63 +// Default d'tor
1.64 +
1.65 +CRegistrar::~CRegistrar()
1.66 + {
1.67 + delete iBackupNotifier;
1.68 + delete iDiscoverer;
1.69 + delete iCachedDriveInfo;
1.70 + }
1.71 +
1.72 +// Default c'tor
1.73 +
1.74 +CRegistrar::CRegistrar(CRegistryData& aRegistry, MRegistrarObserver& aRegistrarObserver, RFs& aFs)
1.75 +: CBase(), iRegistry(aRegistry), iRegistrarObserver(aRegistrarObserver), iFs(aFs), iState(EReg_Undefined)
1.76 + {
1.77 + }
1.78 +
1.79 +
1.80 +void CRegistrar::ConstructL()
1.81 + {
1.82 + iCachedDriveInfo = CEComCachedDriveInfo::NewL(iFs);
1.83 +
1.84 + // Instantiate the discoverer
1.85 + iDiscoverer = CDiscoverer::NewL(*this, iFs);
1.86 + InitialiseEvent();
1.87 + }
1.88 +
1.89 +
1.90 +TInt CRegistrar::Disable(TUid aImplementationUid)
1.91 + {
1.92 + return iRegistry.SetEnabledState(aImplementationUid, EFalse);
1.93 + }
1.94 +
1.95 +
1.96 +TInt CRegistrar::Enable(TUid aImplementationUid)
1.97 + {
1.98 + return iRegistry.SetEnabledState(aImplementationUid, ETrue);
1.99 + }
1.100 +
1.101 +
1.102 +TInt CRegistrar::Resume()
1.103 + {
1.104 + return iDiscoverer->Resume();
1.105 + }
1.106 +
1.107 +
1.108 +TInt CRegistrar::Suspend()
1.109 + {
1.110 + return iDiscoverer->Suspend();
1.111 + }
1.112 +
1.113 +
1.114 +void CRegistrar::DriveRemovedL(TDriveUnit aDrive)
1.115 + {
1.116 + iRegistry.TemporaryUninstallL(aDrive);
1.117 + }
1.118 +
1.119 +
1.120 +void CRegistrar::DriveReinstatedL(TDriveUnit aDrive)
1.121 + {
1.122 + iRegistry.UndoTemporaryUninstallL(aDrive);
1.123 + }
1.124 +
1.125 +TBool CRegistrar::IsAnyDllRegisteredWithDriveL(const TDriveUnit aDrive)const
1.126 + {
1.127 + return iRegistry.IsAnyDllRegisteredWithDriveL(aDrive);
1.128 + }
1.129 +
1.130 +void CRegistrar::RegisterDiscoveryL(const TDriveName& aDrive,CPluginBase*& aDirEntry, TBool aAnyDllDiscovered)
1.131 + {
1.132 + TBool found = EFalse;
1.133 + TBool update = EFalse;
1.134 + TInt registryDriveIndex = KErrNotFound;
1.135 +
1.136 + // Find the appropriate drive entry
1.137 + TChar driveLetter = User::UpperCase(aDrive[0]) - 'A';
1.138 + TDriveUnit driveUnit = EDriveA + driveLetter;
1.139 + CRegistryData::CDriveData* drive =NULL;
1.140 +
1.141 + // Get the drive data in the registry.
1.142 + registryDriveIndex = iRegistry.FindDriveL(driveUnit, drive);
1.143 + if(registryDriveIndex == KErrNotFound)
1.144 + {
1.145 + User::Leave(KEComErrDriveNotFound);
1.146 + }
1.147 +
1.148 +
1.149 + // Get the registry to return enough data so that the Add and Update routines
1.150 + // can be optimised to avoid rescanning the registry data.
1.151 + // This means that registryDriveIndex MUST remain valid until after
1.152 + // the ParseRegistrationDataL call below.
1.153 +
1.154 + // IsRegisteredWithDate will be called if the this drive is NOT
1.155 + // under its initial discovery. If any Dll is discovered in the drive, then
1.156 + // this drive is NOT in its initial discovery.
1.157 +
1.158 + // In read-only drive with SPI enable, aAnyDllDiscovered will be always false.
1.159 + // If language downgrade path has been changed, IsRegisteredWithDate will be
1.160 + // called to check whether current localised file need to be updated.
1.161 + if((aAnyDllDiscovered) || (iRegistry.HasLanguageChanged()))
1.162 + {
1.163 + found = iRegistry.IsRegisteredWithDate(aDirEntry->iDllThirdUid, aDirEntry->iDllModifiedTime, update, drive);
1.164 + }
1.165 +
1.166 + if(!found || update || iRegistry.HasLanguageChanged())
1.167 + {
1.168 + if(found && !update && iRegistry.HasLanguageChanged())
1.169 + {
1.170 + // If we got here because the language has changed
1.171 + // ensure the existing registry data is updated rather than a new entry added
1.172 + update = ETrue;
1.173 + }
1.174 + ParseRegistrationDataL(aDirEntry,driveUnit, update, registryDriveIndex, drive);
1.175 + }
1.176 + }
1.177 +
1.178 +
1.179 +void CRegistrar::DiscoveriesBegin()
1.180 + {
1.181 + // We are about to receive registrations so inform the registry that its index
1.182 + // is about to be invalid
1.183 + iRegistry.DiscoveriesBeginning();
1.184 + }
1.185 +
1.186 +
1.187 +void CRegistrar::DiscoveriesComplete(TBool aSuccessful, TPluginProcessingTypeIdentifier aProcessingType)
1.188 + {
1.189 +
1.190 + TBool doesRegChanged = EFalse;
1.191 +
1.192 + // Successfully completed, if registry data has been changed, update
1.193 + TRAPD(error,iRegistry.DiscoveriesCompleteL(aSuccessful, aProcessingType,doesRegChanged));
1.194 + UNUSED_VAR(error);
1.195 + // Notify if the registry data has been changed.
1.196 + if(doesRegChanged)
1.197 + {
1.198 + // Notify that we have updated the registry
1.199 + iRegistrarObserver.Notification(KErrNone);
1.200 + }
1.201 + }
1.202 +
1.203 +void CRegistrar::SetDiscoveryFlagL(const TDriveUnit& aDriveUnit)
1.204 + {
1.205 + //set the drive flag to indicate it has changes.
1.206 + iRegistry.SetDiscoveryFlagL(aDriveUnit);
1.207 + }
1.208 +
1.209 +TBool CRegistrar::NotifiedWithErrorCode(TInt aError)
1.210 + {
1.211 + // Test the safe error codes
1.212 + return (aError == KErrNotReady || // Drive removed?
1.213 + aError == KErrPathNotFound); // Directory deleted?
1.214 + }
1.215 +
1.216 +void CRegistrar::ParseRegistrationDataL(CPluginBase*& aEntry,
1.217 + const TDriveUnit& aDrive,
1.218 + TBool aUpdate,
1.219 + TInt aRegistryDriveIndex,
1.220 + CRegistryData::CDriveData* aDriveData)
1.221 + {
1.222 + // Ok we intend installing this item so
1.223 + // create the Interface Implementation Collection entry first
1.224 + CRegistryData::CDllData* dll = CRegistryData::CDllData::NewLC(*(aEntry->iDllName),aEntry->iDllModifiedTime,aEntry->iDllSecondUid,aEntry->iDllThirdUid,aDriveData);
1.225 +
1.226 +#ifdef ECOM_TRACE
1.227 + static int counter = 0; counter++;
1.228 + TFileName fullFileName(aDrive.Name());
1.229 + fullFileName.Append(_L("\\sys\\bin\\"));
1.230 + fullFileName.Append(*(aEntry->iDllName));
1.231 + __ECOM_TRACE2("ECOM: Plugin discovered (%04d) %S", counter, &fullFileName);
1.232 +#endif
1.233 +
1.234 + // update resource ext info
1.235 + HBufC* resourceExt = aEntry->RscFileExt();
1.236 + if(resourceExt)
1.237 + dll->SetResourceExtL(*resourceExt);
1.238 +
1.239 + // Don't automatically leave during the parse of the implementation
1.240 + // collection's registration data.
1.241 + // If we did then there would be a cascade of leaves which stop the
1.242 + // entire registration process for all discoveries remaining on the list.
1.243 + // Check to see if there is a problem specifically with the registration data
1.244 + // OR if its a general problem. In the latter case leave.
1.245 + TInt error=KErrNone;
1.246 +
1.247 + TRAP(error, ParseL(aEntry,*dll));
1.248 + if (error==KErrNoMemory)
1.249 + User::LeaveNoMemory();
1.250 + if(error == KErrNone)
1.251 + {
1.252 + if(aUpdate)
1.253 + {
1.254 + iRegistry.UpdateDllDataL(aDrive, aRegistryDriveIndex, dll);
1.255 + }
1.256 + else
1.257 + {
1.258 + iRegistry.AddDllDataL(aDrive, aRegistryDriveIndex, dll);
1.259 + }
1.260 + // Remove dll from CleanupStack as ownership has been passed in one of
1.261 + // the two functions above
1.262 + CleanupStack::Pop(dll);
1.263 + }
1.264 + else
1.265 + {
1.266 + // This interface implementation collection
1.267 + // cannot be registered correctly.
1.268 + CleanupStack::PopAndDestroy(dll);
1.269 + }
1.270 + }
1.271 +
1.272 +void CRegistrar::GetResourceFormatVersionL(RResourceReader& aReader, TInt& aResourceFormatVersion)
1.273 + {
1.274 + aResourceFormatVersion = 1;
1.275 + TUid dllUid(KNullUid);
1.276 + TUid uid = {aReader.ReadInt32L()};
1.277 + if(uid==KUidEComResourceFormatV2)
1.278 + {
1.279 + aResourceFormatVersion = 2;
1.280 + dllUid.iUid = aReader.ReadInt32L();
1.281 + }
1.282 + else if(uid==KUidEComResourceFormatV3)
1.283 + {
1.284 + aResourceFormatVersion = 3;
1.285 + dllUid.iUid = aReader.ReadInt32L();
1.286 + }
1.287 + else
1.288 + dllUid = uid;
1.289 + }
1.290 +
1.291 +
1.292 +void CRegistrar::ParseL(CPluginBase*& aEntry,CRegistryData::CDllData& aDll)
1.293 + {
1.294 +// Read the resource file starting at offset:0 section size:0
1.295 + CResourceFile* regFile =aEntry->RscFile();
1.296 +// Note : There may be an issue here with resource reading when the
1.297 +// file is not in the ROM. The solution would be to call
1.298 +// regFile.ConfirmSignatureL(regFile.SignatureL());
1.299 +// However for 6.2 interface implementation collections will ALL
1.300 +// be within the ROM. and future development will move to an
1.301 +// XML parsed solution @ build time.
1.302 +// IF this situation changes, place the fix here.
1.303 + RResourceReader theReader;
1.304 + theReader.OpenLC(regFile, KMinBuffAllocSize);
1.305 + TInt resourceFormatVersion = 0;
1.306 + GetResourceFormatVersionL(theReader,resourceFormatVersion);
1.307 +
1.308 + TDriveUnit drive(aDll.iParent->iDrive);
1.309 + TBool romBased = iCachedDriveInfo->DriveIsReadOnlyInternalL(drive);
1.310 + const TInt numInterfaces = theReader.ReadInt16L();
1.311 + if (resourceFormatVersion == 3 && numInterfaces > KMaxInterfacesInResV3)
1.312 + {
1.313 + User::Leave(KErrNotSupported);
1.314 + }
1.315 + for(TInt iface = 0; iface < numInterfaces; ++iface)
1.316 + {
1.317 + // Read the interface uid
1.318 + const TUid interfaceUid = {theReader.ReadInt32L()};
1.319 + CRegistryData::CInterfaceData* interfaceList = CRegistryData::CInterfaceData::NewLC(interfaceUid,&aDll);
1.320 + aDll.AddL(interfaceList);
1.321 + CleanupStack::Pop(interfaceList); // Now owned by aDll
1.322 + const TInt numImplementations = theReader.ReadInt16L();
1.323 + if (resourceFormatVersion == 3 && numImplementations > KMaxImplementationsForEachInterfacesInResV3)
1.324 + {
1.325 + User::Leave(KErrNotSupported);
1.326 + }
1.327 + for(TInt index = 0; index < numImplementations; ++index)
1.328 + {
1.329 + TUid implementationUid;
1.330 + TInt versionNo;
1.331 + TInt infoFormat;
1.332 + TBool romOnly;
1.333 + RExtendedInterfacesArray* extendedInterfaces = NULL;
1.334 + HBufC* name = NULL;
1.335 + HBufC8* defaultData = NULL;
1.336 + HBufC8* opaqueData = NULL;
1.337 + CParseImplementationData* parseImplementationData = CParseImplementationData::NewLC(resourceFormatVersion);
1.338 + parseImplementationData->ParseL(theReader,
1.339 + infoFormat,
1.340 + implementationUid,
1.341 + versionNo,
1.342 + name,
1.343 + defaultData,
1.344 + opaqueData,
1.345 + extendedInterfaces,
1.346 + romOnly);
1.347 + CleanupStack::PopAndDestroy(parseImplementationData);
1.348 +
1.349 + CleanupStack::PushL(TCleanupItem(CloseAndDeleteArray, extendedInterfaces));
1.350 + CleanupStack::PushL(name);
1.351 + CleanupStack::PushL(defaultData);
1.352 + CleanupStack::PushL(opaqueData);
1.353 + if (romOnly && !(romBased))
1.354 + {
1.355 + // pop and destroy opaquedata, defaultdata,name and extendedInterfaces
1.356 + CleanupStack::PopAndDestroy(4,extendedInterfaces);
1.357 + }
1.358 + else
1.359 + {
1.360 + CRegistryData::CImplementationData* implData = CRegistryData::CImplementationData::NewL(interfaceList,
1.361 + implementationUid,
1.362 + versionNo,
1.363 + name,
1.364 + defaultData,
1.365 + opaqueData,
1.366 + drive,
1.367 + romOnly,
1.368 + romBased,
1.369 + extendedInterfaces);
1.370 + CleanupStack::Pop(4,extendedInterfaces); // opaqueData,defaultData,name,extendedInterfaces owned by implData
1.371 + CleanupStack::PushL(implData);
1.372 + interfaceList->AddL(implData); // Now owned by interfaceList
1.373 + CleanupStack::Pop(implData);
1.374 + }
1.375 + }
1.376 + }
1.377 + CleanupStack::PopAndDestroy(&theReader);
1.378 + }
1.379 +
1.380 +
1.381 +CRegistrar::TRegistrarState CRegistrar::State()const
1.382 + {
1.383 + return iState;
1.384 + }
1.385 +
1.386 +void CRegistrar::ProcessSSAEventL(TStartupStateIdentifier aKnownState)
1.387 + {
1.388 + iDiscoverer->ProcessSSAEventL(aKnownState);
1.389 + if(aKnownState == EStartupStateNonCritical && iState == EReg_StartupInProgess)
1.390 + {
1.391 + __ECOM_TRACE("ECOM: CRegistrar::ProcessSSAEventL(): EStartupStateNonCritical is reached.");
1.392 +
1.393 + iState = EReg_StartupComplete;
1.394 + iBackupNotifier = CBackupNotifier::NewL(*this);
1.395 + }
1.396 + }
1.397 +void CRegistrar::InitialiseEvent()
1.398 + {
1.399 + iState = EReg_StartupInProgess;
1.400 + }
1.401 +
1.402 +void CRegistrar::LanguageChangedL(TBool& aLanguageChanged)
1.403 + {
1.404 + iRegistry.LanguageChangedL(aLanguageChanged);
1.405 + }
1.406 +
1.407 +void CRegistrar::InstallSwiEventCallBack(const TCallBackWithArg& aCallBack)
1.408 + {
1.409 + iDiscoverer->SetSwiChangeCallBack(aCallBack);
1.410 + }
1.411 +
1.412 +void CRegistrar::InstallBurEventCallBack(const TCallBackWithArg& aCallBack)
1.413 + {
1.414 + iDiscoverer->SetBurChangeCallBack(aCallBack);
1.415 + }