contentstorage/srvsrc/caprogressnotifier.cpp
changeset 103 b99b84bcd2d1
child 99 7aaf39b772ac
equal deleted inserted replaced
83:156f692b1687 103:b99b84bcd2d1
       
     1 /*
       
     2  * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  ?Description
       
    15  *
       
    16  */
       
    17 
       
    18 #include "s32mem.h"
       
    19 
       
    20 #include <usif/usifcommon.h> 
       
    21 #include <usif/scr/scr.h>
       
    22 #include <usif/scr/screntries.h>
       
    23 
       
    24 #include "caprogressnotifier.h"
       
    25 #include "castorageproxy.h"
       
    26 #include "cainnerquery.h"
       
    27 #include "cainnerentry.h"
       
    28 #include "caarraycleanup.inl"
       
    29 
       
    30 using namespace Usif;
       
    31 
       
    32 //fake constants
       
    33 const TInt KMaxProgressValue = 100;
       
    34 const TInt KDelayTimeBetweenNotifications(500000);
       
    35 
       
    36 
       
    37 #ifdef COVERAGE_MEASUREMENT
       
    38 #pragma CTC SKIP
       
    39 #endif //COVERAGE_MEASUREMENT (fake notifier timer)
       
    40 
       
    41 EXPORT_C CCaFakeProgressNotifier* CCaFakeProgressNotifier::NewL(
       
    42         MCaFakeProgressListener& aListener )
       
    43     {
       
    44     CCaFakeProgressNotifier* self = new ( ELeave ) CCaFakeProgressNotifier( aListener );
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL( );
       
    47     CleanupStack::Pop( self );
       
    48     return self;
       
    49     }
       
    50 
       
    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 // ---------------------------------------------------------------------------
       
   124 //
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 CCaProgressNotifier::~CCaProgressNotifier()
       
   128     {
       
   129     // TODO: Commented out since USIF notifications do not 
       
   130     // work on MCL wk20
       
   131     /*
       
   132     iNotifier->CancelSubscribeL();
       
   133     delete iNotifier;
       
   134     */
       
   135     
       
   136     // needed for fake:
       
   137     delete iUsifUninstallNotifier;
       
   138     delete iJavaInstallNotifier;
       
   139     delete iFakeProgressNotifier;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 CCaProgressNotifier::CCaProgressNotifier()
       
   147     {
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CCaProgressNotifier::ConstructL( CCaStorageProxy& aCaStorageProxy )
       
   155     {
       
   156     // TODO: Commented out since USIF notifications do not 
       
   157     // work on MCL wk20
       
   158     /*
       
   159     iNotifier = CSifOperationsNotifier::NewL(*this);
       
   160     */
       
   161     
       
   162     iStorageProxy = &aCaStorageProxy;
       
   163     
       
   164     iUsifUninstallNotifier = CCaInstallNotifier::NewL( *this,
       
   165             CCaInstallNotifier::EUsifUninstallNotification );
       
   166 
       
   167     iJavaInstallNotifier = CCaInstallNotifier::NewL( *this,
       
   168                 CCaInstallNotifier::EJavaInstallNotification );
       
   169 
       
   170     iFakeProgressNotifier = CCaFakeProgressNotifier::NewL(*this);    
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 void CCaProgressNotifier::StartOperationHandler(TUint /*aKey*/, const CSifOperationStartData& /*aStartData*/)
       
   178     {
       
   179     // TODO: Commented out since USIF notifications do not 
       
   180     // work on MCL wk20
       
   181     /*
       
   182     iNotifier->SubscribeL( aKey, ETrue );
       
   183     */
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CCaProgressNotifier::EndOperationHandler(const CSifOperationEndData& /*aEndData*/)
       
   191     {
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CCaProgressNotifier::ProgressOperationHandler(const CSifOperationProgressData& /*aProgressData*/)
       
   199     {
       
   200     
       
   201     // TODO: Commented out since USIF notifications do not 
       
   202     // work on MCL wk20
       
   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;
       
   237     totalProgressBuf.CleanupClosePushL();
       
   238     totalProgressBuf.CreateL( sizeof(TComponentId) + 1 );
       
   239     totalProgressBuf.AppendNum( aProgressData.CurrentProgess() );
       
   240 
       
   241     if (resultArrayItems.Count() && aProgressData.Phase() == EUninstalling)
       
   242         {
       
   243         CCaInnerEntry* appEntry = resultArrayItems[0];
       
   244         appEntry->AddAttributeL(KCaAppUninstallProgress, totalProgressBuf);
       
   245 
       
   246         iStorageProxy->AddL(appEntry, ETrue, EItemUninstallProgressChanged );
       
   247         }
       
   248     CleanupStack::PopAndDestroy( &totalProgressBuf );
       
   249     CleanupStack::PopAndDestroy( &resultArrayItems );
       
   250     CleanupStack::PopAndDestroy( innerQuery );
       
   251     CleanupStack::PopAndDestroy( &componentIdBuf );
       
   252     */
       
   253     }
       
   254 
       
   255 void CCaProgressNotifier::HandleInstallNotifyL( TInt /*aUid*/)
       
   256     {
       
   257     // start sending fake notifications
       
   258     iFakeProgressNotifier->StartNotifying();
       
   259     }
       
   260 
       
   261 void CCaProgressNotifier::HandleFakeProgressNotifyL(TInt aCurrentProgress)
       
   262     {
       
   263     //update storage with new info
       
   264     
       
   265     // find entry by componentID
       
   266     CCaInnerQuery *innerQuery = CCaInnerQuery::NewLC();
       
   267     innerQuery->SetRole( CCaInnerQuery::Item );
       
   268     innerQuery->SetFlagsOn(EUninstall);
       
   269     
       
   270     RPointerArray<CCaInnerEntry> resultArrayItems;
       
   271     CleanupResetAndDestroyPushL( resultArrayItems );
       
   272     iStorageProxy->GetEntriesL( innerQuery, resultArrayItems );
       
   273     
       
   274     
       
   275     RBuf totalProgressBuf;
       
   276     totalProgressBuf.CleanupClosePushL();
       
   277     totalProgressBuf.CreateL( sizeof( TInt ) + 1 );
       
   278     totalProgressBuf.AppendNum( aCurrentProgress );
       
   279     
       
   280     for ( TInt i = 0; i<resultArrayItems.Count(); i++ )
       
   281        {
       
   282        CCaInnerEntry* appEntry = resultArrayItems[i];
       
   283        appEntry->AddAttributeL(KCaAppUninstallProgress, totalProgressBuf);
       
   284        iStorageProxy->AddL(appEntry, ETrue, EItemUninstallProgressChanged );
       
   285        }
       
   286     
       
   287     CleanupStack::PopAndDestroy( &totalProgressBuf );
       
   288     CleanupStack::PopAndDestroy( &resultArrayItems );
       
   289     CleanupStack::PopAndDestroy( innerQuery );
       
   290     }