diff -r 3ab5c078b490 -r c63ee96dbe5f contentstorage/tsrc/testutils/src/t_cainstaller.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contentstorage/tsrc/testutils/src/t_cainstaller.cpp Thu Sep 16 12:11:40 2010 +0100 @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: ?Description + * + */ + +#include +#include + +#include "t_cainstaller.h" + +using namespace Usif; + +// ================= MEMBER FUNCTIONS ======================= + +// --------------------------------------------------------------------------- +// T_CaInstaller::~T_CaInstaller +// --------------------------------------------------------------------------- +// +T_CaInstaller::~T_CaInstaller() + { + Cancel(); + iFs.Close(); + delete iArguments; + delete iResults; + iInstaller.Close(); + iSoftwareRegistry.Close(); + } + +// --------------------------------------------------------------------------- +// T_CaInstaller::NewL +// --------------------------------------------------------------------------- +// +T_CaInstaller *T_CaInstaller::NewL(TInt aPriority) + { + T_CaInstaller *self = new (ELeave) T_CaInstaller( + aPriority ); + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop( self ); + return self; + } + +// --------------------------------------------------------------------------- +// T_CaInstaller::T_CaInstaller +// --------------------------------------------------------------------------- +// +T_CaInstaller::T_CaInstaller( TInt aPriority ) : + CActive( aPriority ), iInstaller() + { + CActiveScheduler::Add( this ); + } + +// --------------------------------------------------------------------------- +// T_CaInstaller::ConstructL +// --------------------------------------------------------------------------- +// +void T_CaInstaller::ConstructL() + { + User::LeaveIfError( iInstaller.Connect() ); + User::LeaveIfError( iSoftwareRegistry.Connect() ); + User::LeaveIfError( iFs.Connect() ); + + iArguments = COpaqueNamedParams::NewL(); + iResults = COpaqueNamedParams::NewL(); + + iArguments->AddIntL( KSifInParam_InstallInactive, ETrue ); + iArguments->AddIntL( KSifInParam_InstallSilently, ETrue ); + } + +// --------------------------------------------------------------------------- +// T_CaInstallOperation::ConstructL +// --------------------------------------------------------------------------- +// +void T_CaInstaller::InstallL( const TDesC& aFileName ) + { + if (IsActive()) + { + User::Leave(KErrInUse); + } + + iInstaller.Install( aFileName, *iArguments, *iResults, iStatus ); + + SetActive(); + + iSchedulerWait.Start(); + + } + +// --------------------------------------------------------------------------- +// T_CaInstaller::UnistallL +// --------------------------------------------------------------------------- +// +void T_CaInstaller::UninstallL(TComponentId aComponentId) + { + if (IsActive()) + { + User::Leave( KErrInUse ); + } + + if (aComponentId >= 1) + { + iInstaller.Uninstall( aComponentId, *iArguments, *iResults, iStatus ); + + SetActive(); + + iSchedulerWait.Start(); + } + + } + +// --------------------------------------------------------------------------- +// T_CaInstaller::UnistallL +// --------------------------------------------------------------------------- +// +void T_CaInstaller::UninstallL(const TDesC& aFileName) + { + UninstallL( GetComponentIdL(aFileName) ); + } + +// --------------------------------------------------------------------------- +// T_CaInstaller::UnistallL +// --------------------------------------------------------------------------- +// +void T_CaInstaller::UninstallL( TUint32 aUid ) + { + UninstallL( GetComponentIdL( aUid ) ); + } + +TComponentId T_CaInstaller::GetComponentIdL( const TDesC& aFileName ) + { + CComponentFilter* const fileNameFilter = CComponentFilter::NewLC(); + fileNameFilter->SetFileL( aFileName ); + + RArray componentIds; + CleanupClosePushL( componentIds ); + iSoftwareRegistry.GetComponentIdsL( componentIds, fileNameFilter ); + + TComponentId componentId( 0 ); + + if ( componentIds.Count() == 1 ) + { + componentId = componentIds[0]; + } + else if ( componentIds.Count() >= 2 ) + { + User::Leave( KErrGeneral ); + } + + CleanupStack::PopAndDestroy( &componentIds ); + CleanupStack::PopAndDestroy( fileNameFilter ); + + return componentId; + } + +TComponentId T_CaInstaller::GetComponentIdForAppIdL( const TDesC& aAppId ) + { + CComponentFilter* const appIdFilter = CComponentFilter::NewLC(); + appIdFilter->AddPropertyL( _L("AppId"), aAppId ); + + RArray componentIds; + CleanupClosePushL( componentIds ); + iSoftwareRegistry.GetComponentIdsL( componentIds, appIdFilter ); + + TComponentId componentId( 0 ); + + if ( componentIds.Count() == 1 ) + { + componentId = componentIds[0]; + } + else if ( componentIds.Count() >= 2 ) + { + User::Leave( KErrGeneral ); + } + + CleanupStack::PopAndDestroy( &componentIds ); + CleanupStack::PopAndDestroy( appIdFilter ); + + return componentId; + } + + +TComponentId T_CaInstaller::GetComponentIdL( TInt32 aUid ) + { + TUid uid; + TComponentId componentId = iSoftwareRegistry.GetComponentIdForAppL( + uid.Uid( aUid ) ); + + if ( componentId <= 0 ) + { + User::Leave( KErrGeneral ); + } + return componentId; + } +// --------------------------------------------------------------------------- +// T_CaInstaller::RunL +// --------------------------------------------------------------------------- +// +void T_CaInstaller::RunL() + { + iSchedulerWait.AsyncStop(); + } + +// --------------------------------------------------------------------------- +// T_CaInstaller::DoCancel +// --------------------------------------------------------------------------- +// +void T_CaInstaller::DoCancel() + { + iInstaller.CancelOperation(); + iSchedulerWait.AsyncStop(); + } + +// --------------------------------------------------------------------------- +// T_CaInstaller::RunError +// --------------------------------------------------------------------------- +// +TInt T_CaInstaller::RunError(TInt /* aError */) + { + return KErrNone; + }