contentstorage/srvsrc/caprogressnotifier.cpp
changeset 104 9b022b1f357c
parent 103 b99b84bcd2d1
equal deleted inserted replaced
103:b99b84bcd2d1 104:9b022b1f357c
    13  *
    13  *
    14  * Description:  ?Description
    14  * Description:  ?Description
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include "s32mem.h"
    18 #include <s32mem.h>
    19 
    19 
    20 #include <usif/usifcommon.h> 
       
    21 #include <usif/scr/scr.h>
    20 #include <usif/scr/scr.h>
    22 #include <usif/scr/screntries.h>
    21 #include <usif/scr/screntries.h>
    23 
    22 
    24 #include "caprogressnotifier.h"
    23 #include "caprogressnotifier.h"
    25 #include "castorageproxy.h"
    24 #include "castorageproxy.h"
    27 #include "cainnerentry.h"
    26 #include "cainnerentry.h"
    28 #include "caarraycleanup.inl"
    27 #include "caarraycleanup.inl"
    29 
    28 
    30 using namespace Usif;
    29 using namespace Usif;
    31 
    30 
    32 //fake constants
    31 // ---------------------------------------------------------------------------
    33 const TInt KMaxProgressValue = 100;
    32 //
    34 const TInt KDelayTimeBetweenNotifications(500000);
    33 // ---------------------------------------------------------------------------
    35 
    34 //
    36 
    35 EXPORT_C CCaProgressNotifier* CCaProgressNotifier::NewL(
    37 #ifdef COVERAGE_MEASUREMENT
    36         CCaStorageProxy& aCaStorageProxy )
    38 #pragma CTC SKIP
    37     {
    39 #endif //COVERAGE_MEASUREMENT (fake notifier timer)
    38     CCaProgressNotifier* self = new ( ELeave ) CCaProgressNotifier(
    40 
    39             aCaStorageProxy );
    41 EXPORT_C CCaFakeProgressNotifier* CCaFakeProgressNotifier::NewL(
       
    42         MCaFakeProgressListener& aListener )
       
    43     {
       
    44     CCaFakeProgressNotifier* self = new ( ELeave ) CCaFakeProgressNotifier( aListener );
       
    45     CleanupStack::PushL( self );
    40     CleanupStack::PushL( self );
    46     self->ConstructL( );
    41     self->ConstructL();
    47     CleanupStack::Pop( self );
    42     CleanupStack::Pop( self );
    48     return self;
    43     return self;
    49     }
    44     }
    50 
    45 
    51 CCaFakeProgressNotifier::~CCaFakeProgressNotifier()
       
    52     {
       
    53     Cancel();
       
    54     iTimer.Close();
       
    55     }
       
    56 
       
    57 CCaFakeProgressNotifier::CCaFakeProgressNotifier( MCaFakeProgressListener& aListener ) :
       
    58     CActive( EPriorityNormal ), iListener( aListener ), iCount( 0 ) 
       
    59     {
       
    60     CActiveScheduler::Add( this );
       
    61     }
       
    62 
       
    63 void CCaFakeProgressNotifier::ConstructL(  )
       
    64     {
       
    65     User::LeaveIfError( iTimer.CreateLocal() );
       
    66     }
       
    67 
       
    68 void CCaFakeProgressNotifier::StartNotifying()
       
    69     {
       
    70     iCount = 0;
       
    71     Cancel();
       
    72     iTimer.After( iStatus, TTimeIntervalMicroSeconds32( KDelayTimeBetweenNotifications ) );
       
    73     SetActive();
       
    74     }
       
    75 
       
    76 void CCaFakeProgressNotifier::DoCancel()
       
    77     {    
       
    78     iTimer.Cancel();
       
    79     }
       
    80 
       
    81 void CCaFakeProgressNotifier::RunL()
       
    82     {
       
    83     User::LeaveIfError( iStatus.Int() );
       
    84     
       
    85     if ( iCount <= KMaxProgressValue )
       
    86         {
       
    87         if( iCount > 20 )
       
    88             {            
       
    89             iListener.HandleFakeProgressNotifyL(iCount); 
       
    90             }     
       
    91         iTimer.After( iStatus, TTimeIntervalMicroSeconds32( KDelayTimeBetweenNotifications ) );
       
    92         SetActive();
       
    93         iCount += 20;
       
    94         }
       
    95     }
       
    96 
       
    97 TInt CCaFakeProgressNotifier::RunError( TInt /*aError*/)
       
    98     {
       
    99     // No need to do anything
       
   100     return KErrNone;
       
   101     }
       
   102 
       
   103 #ifdef COVERAGE_MEASUREMENT
       
   104 #pragma CTC ENDSKIP
       
   105 #endif //COVERAGE_MEASUREMENT  (fake notifier)
       
   106 
       
   107 
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 EXPORT_C CCaProgressNotifier* CCaProgressNotifier::NewL(
       
   114         CCaStorageProxy& aCaStorageProxy )
       
   115     {
       
   116     CCaProgressNotifier* self = new ( ELeave ) CCaProgressNotifier(  );
       
   117     CleanupStack::PushL( self );
       
   118     self->ConstructL( aCaStorageProxy );
       
   119     CleanupStack::Pop( self );
       
   120     return self;
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
    46 // ---------------------------------------------------------------------------
   124 //
    47 //
   125 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
   126 //
    49 //
   127 CCaProgressNotifier::~CCaProgressNotifier()
    50 CCaProgressNotifier::~CCaProgressNotifier()
   128     {
    51     {
   129     // TODO: Commented out since USIF notifications do not 
       
   130     // work on MCL wk20
       
   131     /*
       
   132     iNotifier->CancelSubscribeL();
       
   133     delete iNotifier;
    52     delete iNotifier;
   134     */
    53     iResultArrayItems.ResetAndDestroy();
   135     
    54     }
   136     // needed for fake:
    55 
   137     delete iUsifUninstallNotifier;
    56 // ---------------------------------------------------------------------------
   138     delete iJavaInstallNotifier;
    57 //
   139     delete iFakeProgressNotifier;
    58 // ---------------------------------------------------------------------------
   140     }
    59 //
   141 
    60 CCaProgressNotifier::CCaProgressNotifier( CCaStorageProxy& aCaStorageProxy ) :
   142 // ---------------------------------------------------------------------------
    61     iStorageProxy( aCaStorageProxy )
   143 //
    62     {
   144 // ---------------------------------------------------------------------------
    63     }
   145 //
    64 
   146 CCaProgressNotifier::CCaProgressNotifier()
    65 // ---------------------------------------------------------------------------
   147     {
    66 //
   148     }
    67 // ---------------------------------------------------------------------------
   149 
    68 //
   150 // ---------------------------------------------------------------------------
    69 void CCaProgressNotifier::ConstructL()
   151 //
    70     {
   152 // ---------------------------------------------------------------------------
    71     iNotifier = CSifOperationsNotifier::NewL( *this );
   153 //
    72     }
   154 void CCaProgressNotifier::ConstructL( CCaStorageProxy& aCaStorageProxy )
    73 
   155     {
    74 // ---------------------------------------------------------------------------
   156     // TODO: Commented out since USIF notifications do not 
    75 //
   157     // work on MCL wk20
    76 // ---------------------------------------------------------------------------
   158     /*
    77 //
   159     iNotifier = CSifOperationsNotifier::NewL(*this);
    78 void CCaProgressNotifier::StartOperationHandler( TUint aKey,
   160     */
    79         const CSifOperationStartData& aStartData )
   161     
    80     {
   162     iStorageProxy = &aCaStorageProxy;
    81     TInt err( KErrNone );
   163     
    82     TComponentId componentId;
   164     iUsifUninstallNotifier = CCaInstallNotifier::NewL( *this,
    83     iResultArrayItems.ResetAndDestroy();
   165             CCaInstallNotifier::EUsifUninstallNotification );
    84 
   166 
    85     TRAP(err, componentId = ComponentIdL( aStartData.GlobalComponentId(),
   167     iJavaInstallNotifier = CCaInstallNotifier::NewL( *this,
    86                     aStartData.SoftwareType() ));
   168                 CCaInstallNotifier::EJavaInstallNotification );
    87     if ( !err )
   169 
    88         TRAP(err, MarkEntrysForUnistallL(aKey, componentId));
   170     iFakeProgressNotifier = CCaFakeProgressNotifier::NewL(*this);    
    89 
   171     }
    90     }
   172 
    91 
   173 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
   174 //
    93 //
   175 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
   176 //
    95 //
   177 void CCaProgressNotifier::StartOperationHandler(TUint /*aKey*/, const CSifOperationStartData& /*aStartData*/)
    96 void CCaProgressNotifier::EndOperationHandler(
   178     {
    97         const CSifOperationEndData& aEndData )
   179     // TODO: Commented out since USIF notifications do not 
    98     {
   180     // work on MCL wk20
    99     TInt err = KErrNone;
   181     /*
   100     TRAP(err, EndOperationL(aEndData.ErrorCode()));
   182     iNotifier->SubscribeL( aKey, ETrue );
   101     iResultArrayItems.ResetAndDestroy();
   183     */
   102     }
   184     }
   103 
   185 
   104 // ---------------------------------------------------------------------------
   186 // ---------------------------------------------------------------------------
   105 //
   187 //
   106 // ---------------------------------------------------------------------------
   188 // ---------------------------------------------------------------------------
   107 //
   189 //
   108 void CCaProgressNotifier::ProgressOperationHandler(
   190 void CCaProgressNotifier::EndOperationHandler(const CSifOperationEndData& /*aEndData*/)
   109         const CSifOperationProgressData& aProgressData )
   191     {
   110     {
   192     }
   111     TInt err = KErrNone;
   193 
   112     TRAP(err, UpdateProgressL(aProgressData));
   194 // ---------------------------------------------------------------------------
   113     }
   195 //
   114 
   196 // ---------------------------------------------------------------------------
   115 // ---------------------------------------------------------------------------
   197 //
   116 //
   198 void CCaProgressNotifier::ProgressOperationHandler(const CSifOperationProgressData& /*aProgressData*/)
   117 // ---------------------------------------------------------------------------
   199     {
   118 //
   200     
   119 void CCaProgressNotifier::UpdateProgressL(
   201     // TODO: Commented out since USIF notifications do not 
   120         const CSifOperationProgressData& aProgressData )
   202     // work on MCL wk20
   121     {
   203     
       
   204     /* 
       
   205     // extract component ID
       
   206     TBuf8<20> globalIdBuf;
       
   207     globalIdBuf.Copy( aProgressData.GlobalComponentId() );
       
   208     
       
   209     RDesReadStream readStream( globalIdBuf );
       
   210     CleanupClosePushL( readStream );
       
   211     CGlobalComponentId *globalId = CGlobalComponentId::NewL( readStream );
       
   212     CleanupStack::PushL(globalId);
       
   213      
       
   214     RSoftwareComponentRegistry iScrSession;
       
   215     TComponentId componentId = iScrSession.GetComponentIdL( globalId->GlobalIdName(), 
       
   216             globalId->SoftwareTypeName() );
       
   217 
       
   218     CleanupStack::PopAndDestroy( globalId );
       
   219     CleanupStack::PopAndDestroy( &readStream );
       
   220 
       
   221     RBuf componentIdBuf;
       
   222     componentIdBuf.CleanupClosePushL();
       
   223     componentIdBuf.CreateL( sizeof(TComponentId) + 1 );
       
   224     componentIdBuf.AppendNum( componentId );
       
   225 
       
   226     // find entry by componentID
       
   227     CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC();
       
   228     innerQuery->SetRole( CCaInnerQuery::Item );
       
   229     innerQuery->AddAttributeL( KCaAttrComponentId,
       
   230             componentIdBuf );
       
   231 
       
   232     RPointerArray<CCaInnerEntry> resultArrayItems;
       
   233     CleanupResetAndDestroyPushL( resultArrayItems );
       
   234     iStorageProxy->GetEntriesL( innerQuery, resultArrayItems );
       
   235    
       
   236     RBuf totalProgressBuf;
   122     RBuf totalProgressBuf;
   237     totalProgressBuf.CleanupClosePushL();
   123     totalProgressBuf.CleanupClosePushL();
   238     totalProgressBuf.CreateL( sizeof(TComponentId) + 1 );
   124     totalProgressBuf.CreateL( sizeof(TComponentId) + 1 );
   239     totalProgressBuf.AppendNum( aProgressData.CurrentProgess() );
   125     totalProgressBuf.AppendNum( aProgressData.CurrentProgess() );
   240 
   126 
   241     if (resultArrayItems.Count() && aProgressData.Phase() == EUninstalling)
   127     if ( iResultArrayItems.Count() && aProgressData.Phase() == EUninstalling )
   242         {
   128         {
   243         CCaInnerEntry* appEntry = resultArrayItems[0];
   129         for ( int i = 0; i < iResultArrayItems.Count(); i++ )
   244         appEntry->AddAttributeL(KCaAppUninstallProgress, totalProgressBuf);
   130             {
   245 
   131             iResultArrayItems[i]->AddAttributeL( KCaAppUninstallProgress,
   246         iStorageProxy->AddL(appEntry, ETrue, EItemUninstallProgressChanged );
   132                     totalProgressBuf );
       
   133             iStorageProxy.AddL( iResultArrayItems[i], ETrue,
       
   134                     EItemUninstallProgressChanged );
       
   135             }
   247         }
   136         }
       
   137 
   248     CleanupStack::PopAndDestroy( &totalProgressBuf );
   138     CleanupStack::PopAndDestroy( &totalProgressBuf );
   249     CleanupStack::PopAndDestroy( &resultArrayItems );
   139     }
   250     CleanupStack::PopAndDestroy( innerQuery );
   140 
   251     CleanupStack::PopAndDestroy( &componentIdBuf );
   141 // ---------------------------------------------------------------------------
   252     */
   142 //
   253     }
   143 // ---------------------------------------------------------------------------
   254 
   144 //
   255 void CCaProgressNotifier::HandleInstallNotifyL( TInt /*aUid*/)
   145 void CCaProgressNotifier::EndOperationL( TInt aError )
   256     {
   146     {
   257     // start sending fake notifications
   147     if ( aError )
   258     iFakeProgressNotifier->StartNotifying();
   148         {
   259     }
   149         for ( int i = 0; i < iResultArrayItems.Count(); i++ )
   260 
   150             {
   261 void CCaProgressNotifier::HandleFakeProgressNotifyL(TInt aCurrentProgress)
   151             iResultArrayItems[i]->SetFlags( iResultArrayItems[i]->GetFlags()
   262     {
   152                     & ~EUninstall );
   263     //update storage with new info
   153             iStorageProxy.AddL( iResultArrayItems[i] );
   264     
   154             }
       
   155         }
       
   156     iNotifier->CancelSubscribeL( iKey );
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 TComponentId CCaProgressNotifier::ComponentIdL(
       
   164         const TDesC& aGlobalComponentId, const TDesC& aSwType )
       
   165     {
       
   166     RSoftwareComponentRegistry registry;
       
   167     User::LeaveIfError( registry.Connect() );
       
   168     CleanupClosePushL( registry );
       
   169     TComponentId componentId = registry.GetComponentIdL( aGlobalComponentId,
       
   170             aSwType );
       
   171     CleanupStack::PopAndDestroy( &registry ); // registry    
       
   172     return componentId;
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CCaProgressNotifier::MarkEntrysForUnistallL( TUint aKey,
       
   180         TComponentId aComponentId )
       
   181     {
       
   182     RBuf componentIdBuf;
       
   183     componentIdBuf.CleanupClosePushL();
       
   184     componentIdBuf.CreateL( sizeof(TComponentId) + 1 );
       
   185     componentIdBuf.AppendNum( aComponentId );
       
   186 
   265     // find entry by componentID
   187     // find entry by componentID
   266     CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC();
   188     CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC();
   267     innerQuery->SetRole( CCaInnerQuery::Item );
   189     innerQuery->SetRole( CCaInnerQuery::Item );
   268     innerQuery->SetFlagsOn(EUninstall);
   190     innerQuery->AddAttributeL( KCaAttrComponentId, componentIdBuf );
   269     
   191 
   270     RPointerArray<CCaInnerEntry> resultArrayItems;
   192     iStorageProxy.GetEntriesL( innerQuery, iResultArrayItems );
   271     CleanupResetAndDestroyPushL( resultArrayItems );
   193 
   272     iStorageProxy->GetEntriesL( innerQuery, resultArrayItems );
   194     if ( iResultArrayItems.Count() )
   273     
   195         {
   274     
   196         for ( int i = 0; i < iResultArrayItems.Count(); i++ )
   275     RBuf totalProgressBuf;
   197             {
   276     totalProgressBuf.CleanupClosePushL();
   198             iResultArrayItems[i]->SetFlags( iResultArrayItems[i]->GetFlags()
   277     totalProgressBuf.CreateL( sizeof( TInt ) + 1 );
   199                     | EUninstall );
   278     totalProgressBuf.AppendNum( aCurrentProgress );
   200             iStorageProxy.AddL( iResultArrayItems[i] );
   279     
   201             }
   280     for ( TInt i = 0; i<resultArrayItems.Count(); i++ )
   202         // subscribe for progress notifier
   281        {
   203         iKey = aKey;
   282        CCaInnerEntry* appEntry = resultArrayItems[i];
   204         iNotifier->SubscribeL( aKey, ETrue );
   283        appEntry->AddAttributeL(KCaAppUninstallProgress, totalProgressBuf);
   205         }
   284        iStorageProxy->AddL(appEntry, ETrue, EItemUninstallProgressChanged );
       
   285        }
       
   286     
       
   287     CleanupStack::PopAndDestroy( &totalProgressBuf );
       
   288     CleanupStack::PopAndDestroy( &resultArrayItems );
       
   289     CleanupStack::PopAndDestroy( innerQuery );
   206     CleanupStack::PopAndDestroy( innerQuery );
   290     }
   207     CleanupStack::PopAndDestroy( &componentIdBuf );
       
   208     }