diff -r b99b84bcd2d1 -r 9b022b1f357c contentstorage/srvsrc/caprogressnotifier.cpp --- a/contentstorage/srvsrc/caprogressnotifier.cpp Wed Jun 23 18:33:40 2010 +0300 +++ b/contentstorage/srvsrc/caprogressnotifier.cpp Tue Jul 06 14:37:10 2010 +0300 @@ -15,9 +15,8 @@ * */ -#include "s32mem.h" +#include -#include #include #include @@ -29,83 +28,6 @@ using namespace Usif; -//fake constants -const TInt KMaxProgressValue = 100; -const TInt KDelayTimeBetweenNotifications(500000); - - -#ifdef COVERAGE_MEASUREMENT -#pragma CTC SKIP -#endif //COVERAGE_MEASUREMENT (fake notifier timer) - -EXPORT_C CCaFakeProgressNotifier* CCaFakeProgressNotifier::NewL( - MCaFakeProgressListener& aListener ) - { - CCaFakeProgressNotifier* self = new ( ELeave ) CCaFakeProgressNotifier( aListener ); - CleanupStack::PushL( self ); - self->ConstructL( ); - CleanupStack::Pop( self ); - return self; - } - -CCaFakeProgressNotifier::~CCaFakeProgressNotifier() - { - Cancel(); - iTimer.Close(); - } - -CCaFakeProgressNotifier::CCaFakeProgressNotifier( MCaFakeProgressListener& aListener ) : - CActive( EPriorityNormal ), iListener( aListener ), iCount( 0 ) - { - CActiveScheduler::Add( this ); - } - -void CCaFakeProgressNotifier::ConstructL( ) - { - User::LeaveIfError( iTimer.CreateLocal() ); - } - -void CCaFakeProgressNotifier::StartNotifying() - { - iCount = 0; - Cancel(); - iTimer.After( iStatus, TTimeIntervalMicroSeconds32( KDelayTimeBetweenNotifications ) ); - SetActive(); - } - -void CCaFakeProgressNotifier::DoCancel() - { - iTimer.Cancel(); - } - -void CCaFakeProgressNotifier::RunL() - { - User::LeaveIfError( iStatus.Int() ); - - if ( iCount <= KMaxProgressValue ) - { - if( iCount > 20 ) - { - iListener.HandleFakeProgressNotifyL(iCount); - } - iTimer.After( iStatus, TTimeIntervalMicroSeconds32( KDelayTimeBetweenNotifications ) ); - SetActive(); - iCount += 20; - } - } - -TInt CCaFakeProgressNotifier::RunError( TInt /*aError*/) - { - // No need to do anything - return KErrNone; - } - -#ifdef COVERAGE_MEASUREMENT -#pragma CTC ENDSKIP -#endif //COVERAGE_MEASUREMENT (fake notifier) - - - // --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- @@ -113,9 +35,10 @@ EXPORT_C CCaProgressNotifier* CCaProgressNotifier::NewL( CCaStorageProxy& aCaStorageProxy ) { - CCaProgressNotifier* self = new ( ELeave ) CCaProgressNotifier( ); + CCaProgressNotifier* self = new ( ELeave ) CCaProgressNotifier( + aCaStorageProxy ); CleanupStack::PushL( self ); - self->ConstructL( aCaStorageProxy ); + self->ConstructL(); CleanupStack::Pop( self ); return self; } @@ -126,68 +49,16 @@ // CCaProgressNotifier::~CCaProgressNotifier() { - // TODO: Commented out since USIF notifications do not - // work on MCL wk20 - /* - iNotifier->CancelSubscribeL(); delete iNotifier; - */ - - // needed for fake: - delete iUsifUninstallNotifier; - delete iJavaInstallNotifier; - delete iFakeProgressNotifier; - } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -CCaProgressNotifier::CCaProgressNotifier() - { + iResultArrayItems.ResetAndDestroy(); } // --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- // -void CCaProgressNotifier::ConstructL( CCaStorageProxy& aCaStorageProxy ) - { - // TODO: Commented out since USIF notifications do not - // work on MCL wk20 - /* - iNotifier = CSifOperationsNotifier::NewL(*this); - */ - - iStorageProxy = &aCaStorageProxy; - - iUsifUninstallNotifier = CCaInstallNotifier::NewL( *this, - CCaInstallNotifier::EUsifUninstallNotification ); - - iJavaInstallNotifier = CCaInstallNotifier::NewL( *this, - CCaInstallNotifier::EJavaInstallNotification ); - - iFakeProgressNotifier = CCaFakeProgressNotifier::NewL(*this); - } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -void CCaProgressNotifier::StartOperationHandler(TUint /*aKey*/, const CSifOperationStartData& /*aStartData*/) - { - // TODO: Commented out since USIF notifications do not - // work on MCL wk20 - /* - iNotifier->SubscribeL( aKey, ETrue ); - */ - } - -// --------------------------------------------------------------------------- -// -// --------------------------------------------------------------------------- -// -void CCaProgressNotifier::EndOperationHandler(const CSifOperationEndData& /*aEndData*/) +CCaProgressNotifier::CCaProgressNotifier( CCaStorageProxy& aCaStorageProxy ) : + iStorageProxy( aCaStorageProxy ) { } @@ -195,96 +66,143 @@ // // --------------------------------------------------------------------------- // -void CCaProgressNotifier::ProgressOperationHandler(const CSifOperationProgressData& /*aProgressData*/) +void CCaProgressNotifier::ConstructL() + { + iNotifier = CSifOperationsNotifier::NewL( *this ); + } + +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CCaProgressNotifier::StartOperationHandler( TUint aKey, + const CSifOperationStartData& aStartData ) { - - // TODO: Commented out since USIF notifications do not - // work on MCL wk20 - - /* - // extract component ID - TBuf8<20> globalIdBuf; - globalIdBuf.Copy( aProgressData.GlobalComponentId() ); - - RDesReadStream readStream( globalIdBuf ); - CleanupClosePushL( readStream ); - CGlobalComponentId *globalId = CGlobalComponentId::NewL( readStream ); - CleanupStack::PushL(globalId); - - RSoftwareComponentRegistry iScrSession; - TComponentId componentId = iScrSession.GetComponentIdL( globalId->GlobalIdName(), - globalId->SoftwareTypeName() ); + TInt err( KErrNone ); + TComponentId componentId; + iResultArrayItems.ResetAndDestroy(); + + TRAP(err, componentId = ComponentIdL( aStartData.GlobalComponentId(), + aStartData.SoftwareType() )); + if ( !err ) + TRAP(err, MarkEntrysForUnistallL(aKey, componentId)); + + } - CleanupStack::PopAndDestroy( globalId ); - CleanupStack::PopAndDestroy( &readStream ); - - RBuf componentIdBuf; - componentIdBuf.CleanupClosePushL(); - componentIdBuf.CreateL( sizeof(TComponentId) + 1 ); - componentIdBuf.AppendNum( componentId ); +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CCaProgressNotifier::EndOperationHandler( + const CSifOperationEndData& aEndData ) + { + TInt err = KErrNone; + TRAP(err, EndOperationL(aEndData.ErrorCode())); + iResultArrayItems.ResetAndDestroy(); + } - // find entry by componentID - CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); - innerQuery->SetRole( CCaInnerQuery::Item ); - innerQuery->AddAttributeL( KCaAttrComponentId, - componentIdBuf ); +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CCaProgressNotifier::ProgressOperationHandler( + const CSifOperationProgressData& aProgressData ) + { + TInt err = KErrNone; + TRAP(err, UpdateProgressL(aProgressData)); + } - RPointerArray resultArrayItems; - CleanupResetAndDestroyPushL( resultArrayItems ); - iStorageProxy->GetEntriesL( innerQuery, resultArrayItems ); - +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CCaProgressNotifier::UpdateProgressL( + const CSifOperationProgressData& aProgressData ) + { RBuf totalProgressBuf; totalProgressBuf.CleanupClosePushL(); totalProgressBuf.CreateL( sizeof(TComponentId) + 1 ); totalProgressBuf.AppendNum( aProgressData.CurrentProgess() ); - if (resultArrayItems.Count() && aProgressData.Phase() == EUninstalling) + if ( iResultArrayItems.Count() && aProgressData.Phase() == EUninstalling ) { - CCaInnerEntry* appEntry = resultArrayItems[0]; - appEntry->AddAttributeL(KCaAppUninstallProgress, totalProgressBuf); + for ( int i = 0; i < iResultArrayItems.Count(); i++ ) + { + iResultArrayItems[i]->AddAttributeL( KCaAppUninstallProgress, + totalProgressBuf ); + iStorageProxy.AddL( iResultArrayItems[i], ETrue, + EItemUninstallProgressChanged ); + } + } - iStorageProxy->AddL(appEntry, ETrue, EItemUninstallProgressChanged ); - } CleanupStack::PopAndDestroy( &totalProgressBuf ); - CleanupStack::PopAndDestroy( &resultArrayItems ); - CleanupStack::PopAndDestroy( innerQuery ); - CleanupStack::PopAndDestroy( &componentIdBuf ); - */ } -void CCaProgressNotifier::HandleInstallNotifyL( TInt /*aUid*/) +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CCaProgressNotifier::EndOperationL( TInt aError ) { - // start sending fake notifications - iFakeProgressNotifier->StartNotifying(); + if ( aError ) + { + for ( int i = 0; i < iResultArrayItems.Count(); i++ ) + { + iResultArrayItems[i]->SetFlags( iResultArrayItems[i]->GetFlags() + & ~EUninstall ); + iStorageProxy.AddL( iResultArrayItems[i] ); + } + } + iNotifier->CancelSubscribeL( iKey ); } -void CCaProgressNotifier::HandleFakeProgressNotifyL(TInt aCurrentProgress) +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +TComponentId CCaProgressNotifier::ComponentIdL( + const TDesC& aGlobalComponentId, const TDesC& aSwType ) { - //update storage with new info - + RSoftwareComponentRegistry registry; + User::LeaveIfError( registry.Connect() ); + CleanupClosePushL( registry ); + TComponentId componentId = registry.GetComponentIdL( aGlobalComponentId, + aSwType ); + CleanupStack::PopAndDestroy( ®istry ); // registry + return componentId; + } + +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CCaProgressNotifier::MarkEntrysForUnistallL( TUint aKey, + TComponentId aComponentId ) + { + RBuf componentIdBuf; + componentIdBuf.CleanupClosePushL(); + componentIdBuf.CreateL( sizeof(TComponentId) + 1 ); + componentIdBuf.AppendNum( aComponentId ); + // find entry by componentID CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC(); innerQuery->SetRole( CCaInnerQuery::Item ); - innerQuery->SetFlagsOn(EUninstall); - - RPointerArray resultArrayItems; - CleanupResetAndDestroyPushL( resultArrayItems ); - iStorageProxy->GetEntriesL( innerQuery, resultArrayItems ); - - - RBuf totalProgressBuf; - totalProgressBuf.CleanupClosePushL(); - totalProgressBuf.CreateL( sizeof( TInt ) + 1 ); - totalProgressBuf.AppendNum( aCurrentProgress ); - - for ( TInt i = 0; iAddAttributeL(KCaAppUninstallProgress, totalProgressBuf); - iStorageProxy->AddL(appEntry, ETrue, EItemUninstallProgressChanged ); - } - - CleanupStack::PopAndDestroy( &totalProgressBuf ); - CleanupStack::PopAndDestroy( &resultArrayItems ); + innerQuery->AddAttributeL( KCaAttrComponentId, componentIdBuf ); + + iStorageProxy.GetEntriesL( innerQuery, iResultArrayItems ); + + if ( iResultArrayItems.Count() ) + { + for ( int i = 0; i < iResultArrayItems.Count(); i++ ) + { + iResultArrayItems[i]->SetFlags( iResultArrayItems[i]->GetFlags() + | EUninstall ); + iStorageProxy.AddL( iResultArrayItems[i] ); + } + // subscribe for progress notifier + iKey = aKey; + iNotifier->SubscribeL( aKey, ETrue ); + } CleanupStack::PopAndDestroy( innerQuery ); + CleanupStack::PopAndDestroy( &componentIdBuf ); }