memspyui/ui/avkon/src/MemSpyDeviceWideOperationDialog.cpp
branchRCL_3
changeset 50 9b2cffad4b5e
parent 45 b3cee849fa46
equal deleted inserted replaced
49:f8280f3bfeb7 50:9b2cffad4b5e
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "MemSpyDeviceWideOperationDialog.h"
       
    19 
       
    20 // System includes
       
    21 #include <eikprogi.h>
       
    22 #include <AknWaitDialog.h>
       
    23 #include <AknQueryDialog.h>
       
    24 #include <coemain.h>
       
    25 #include <eikenv.h>
       
    26 #include <avkon.hrh>
       
    27 #include <memspyui.rsg>
       
    28 
       
    29 #include <memspysession.h>
       
    30 
       
    31 /*
       
    32 CMemSpyDeviceWideOperationDialog::CMemSpyDeviceWideOperationDialog( CMemSpyEngine& aEngine, MMemSpyDeviceWideOperationDialogObserver& aObserver )
       
    33 :   iEngine( aEngine ), iObserver( aObserver )
       
    34     {
       
    35     }
       
    36 
       
    37 CMemSpyDeviceWideOperationDialog::CMemSpyDeviceWideOperationDialog( RMemSpySession& aSession, MMemSpyDeviceWideOperationDialogObserver& aObserver )
       
    38 :   iSession( aSession ), iObserver( aObserver )
       
    39     {
       
    40     }    
       
    41 */
       
    42 
       
    43 CMemSpyDeviceWideOperationDialog::CMemSpyDeviceWideOperationDialog( RMemSpySession& aSession )
       
    44 :   iSession( aSession )
       
    45     {
       
    46     }    
       
    47 
       
    48 
       
    49 CMemSpyDeviceWideOperationDialog::~CMemSpyDeviceWideOperationDialog()
       
    50     {
       
    51 #ifdef _DEBUG
       
    52     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::~CMemSpyDeviceWideOperationDialog() - START - iForcedCancel: %d", iForcedCancel );
       
    53 #endif
       
    54 
       
    55 #ifdef _DEBUG
       
    56     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::~CMemSpyDeviceWideOperationDialog() - deleting operation...: 0x%08x", iOperation );
       
    57 #endif
       
    58     delete iOperation;
       
    59 
       
    60 #ifdef _DEBUG
       
    61     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::~CMemSpyDeviceWideOperationDialog() - deleting dialog...: 0x%08x", iProgressDialog );
       
    62 #endif
       
    63     iProgressInfo = NULL;
       
    64     delete iProgressDialog;
       
    65 
       
    66 #ifdef _DEBUG
       
    67     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::~CMemSpyDeviceWideOperationDialog() - sending EDialogDismissed to observer..." );
       
    68 #endif
       
    69 
       
    70     //iObserver.DWOperationCompleted(); //TODO
       
    71 
       
    72 #ifdef _DEBUG
       
    73     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::~CMemSpyDeviceWideOperationDialog() - END" );
       
    74 #endif
       
    75     }
       
    76 
       
    77 
       
    78 //void CMemSpyDeviceWideOperationDialog::ExecuteL( CMemSpyDeviceWideOperations::TOperation aOperation )
       
    79 void CMemSpyDeviceWideOperationDialog::ExecuteL( TDeviceWideOperation aOp )
       
    80     {
       
    81 	/*
       
    82 #ifdef _DEBUG
       
    83     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::ExecuteL() - START" );
       
    84 #endif
       
    85 
       
    86     iOperation = CMemSpyDeviceWideOperations::NewL( iEngine, *this, aOperation );
       
    87 
       
    88 #ifdef _DEBUG
       
    89     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::ExecuteL() - constructed operation..." );
       
    90 #endif
       
    91 
       
    92     ASSERT( iProgressDialog == NULL );
       
    93     iProgressDialog = new( ELeave ) CAknProgressDialog( reinterpret_cast< CEikDialog** >( &iProgressDialog ), ETrue );
       
    94     iProgressDialog->PrepareLC( R_MEMSPY_DEVICE_WIDE_OPERATION_PROGRESS_DIALOG );
       
    95     iProgressDialog->SetCallback( this );
       
    96     iProgressDialog->SetGloballyCapturing( ETrue );
       
    97     //
       
    98     iProgressInfo = iProgressDialog->GetProgressInfoL();
       
    99     iProgressInfo->SetFinalValue( iOperation->TotalOperationSize() );
       
   100     //
       
   101     iProgressDialog->RunLD();
       
   102 
       
   103 #ifdef _DEBUG
       
   104     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::ExecuteL() - END" );
       
   105 #endif
       
   106 	*/
       
   107     }
       
   108 
       
   109 void CMemSpyDeviceWideOperationDialog::ExecuteLD( RMemSpySession& aSession, TDeviceWideOperation aOp )
       
   110     {
       
   111     //CMemSpyDeviceWideOperationDialog* self = new(ELeave) CMemSpyDeviceWideOperationDialog( aSession, aObserver );
       
   112 	CMemSpyDeviceWideOperationDialog* self = new(ELeave) CMemSpyDeviceWideOperationDialog( aSession );
       
   113     CleanupStack::PushL( self );
       
   114     self->ExecuteL( aOp );
       
   115     CleanupStack::PopAndDestroy( self );
       
   116     }
       
   117 
       
   118 
       
   119 void CMemSpyDeviceWideOperationDialog::Cancel()
       
   120     {
       
   121 #ifdef _DEBUG
       
   122     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::Cancel() - START - iOperation: 0x%08x, iForcedCancel: %d", iOperation, iForcedCancel );
       
   123 #endif
       
   124 
       
   125     iForcedCancel = ETrue;
       
   126     //
       
   127     if  ( iOperation )
       
   128         {
       
   129         iOperation->Cancel();
       
   130         }
       
   131     //
       
   132     //iObserver.DWOperationCancelled();
       
   133 
       
   134 #ifdef _DEBUG
       
   135     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::Cancel() - END" );
       
   136 #endif
       
   137     }
       
   138 
       
   139 
       
   140 void CMemSpyDeviceWideOperationDialog::DialogDismissedL( TInt aButtonId )
       
   141     {
       
   142 #ifdef _DEBUG
       
   143     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::DialogDismissedL() - START - aButtonId: %d, iForcedCancel: %d", aButtonId, iForcedCancel );
       
   144 #else
       
   145     (void) aButtonId;
       
   146 #endif
       
   147 
       
   148     Cancel();
       
   149 
       
   150 #ifdef _DEBUG
       
   151     RDebug::Printf("[MemSpy] CMemSpyDeviceWideOperationDialog::DialogDismissedL() - END - aButtonId: %d, iForcedCancel: %d", aButtonId, iForcedCancel );
       
   152 #endif
       
   153     }
       
   154 
       
   155 
       
   156 void CMemSpyDeviceWideOperationDialog::HandleDeviceWideOperationEvent( TEvent aEvent, TInt aParam1, const TDesC& aParam2 )
       
   157     {
       
   158 #ifdef _DEBUG
       
   159     RDebug::Print( _L("[MemSpy] CMemSpyDeviceWideOperationDialog::HandleDeviceWideOperationEvent() - START - aEvent: %d, iProgressDialog: 0x%08x, aParam1: %d, aParam2: %S"), aEvent, iProgressDialog, aParam1, &aParam2 );
       
   160 #endif
       
   161 
       
   162     switch( aEvent )
       
   163         {
       
   164     case MMemSpyDeviceWideOperationsObserver::EOperationSized:
       
   165         break;
       
   166     case MMemSpyDeviceWideOperationsObserver::EOperationStarting:
       
   167         //iObserver.DWOperationStarted();
       
   168         break;
       
   169     case MMemSpyDeviceWideOperationsObserver::EOperationProgressStart:
       
   170         ASSERT( iProgressDialog != NULL );
       
   171         SetDialogCaptionL( aParam2 );
       
   172         break;
       
   173     case MMemSpyDeviceWideOperationsObserver::EOperationProgressEnd:
       
   174         ASSERT( iProgressDialog != NULL );
       
   175         iProgressInfo->IncrementAndDraw( aParam1 );
       
   176         break;
       
   177     case MMemSpyDeviceWideOperationsObserver::EOperationCancelled:
       
   178         break;
       
   179     case MMemSpyDeviceWideOperationsObserver::EOperationCompleting:
       
   180         {
       
   181         ASSERT( iProgressDialog != NULL );
       
   182         const TInt finalValue = iProgressInfo->Info().iFinalValue;
       
   183         iProgressInfo->SetAndDraw( finalValue );
       
   184         break;
       
   185         }
       
   186     case MMemSpyDeviceWideOperationsObserver::EOperationCompleted:
       
   187         if  ( iProgressDialog )
       
   188             {
       
   189             iProgressDialog->ProcessFinishedL();
       
   190             }
       
   191         break;
       
   192     default:
       
   193         break;
       
   194         }
       
   195 
       
   196 #ifdef _DEBUG
       
   197     RDebug::Print( _L("[MemSpy] CMemSpyDeviceWideOperationDialog::HandleDeviceWideOperationEvent() - END - aEvent: %d, aParam1: %d, aParam2: %S"), aEvent, aParam1, &aParam2 );
       
   198 #endif
       
   199     }
       
   200 
       
   201 
       
   202 void CMemSpyDeviceWideOperationDialog::SetDialogCaptionL( const TDesC& aText )
       
   203     {
       
   204     if  ( aText.Length() )
       
   205         {
       
   206         iProgressDialog->SetTextL( aText );
       
   207         iProgressDialog->DrawNow();
       
   208         }
       
   209     }
       
   210 
       
   211 CMemSpyDwoTracker* CMemSpyDeviceWideOperationDialog::CreateDeviceWideOperation( RMemSpySession& aSession, TDeviceWideOperation aOp )
       
   212 {
       
   213 	return new CMemSpyDwoTracker( aSession, aOp );
       
   214 }
       
   215 
       
   216 
       
   217 
       
   218 
       
   219 
       
   220 
       
   221 
       
   222 
       
   223 
       
   224 
       
   225 
       
   226 
       
   227 
       
   228 CMemSpyDwoProgressTracker::CMemSpyDwoProgressTracker(RMemSpySession &aSession) 
       
   229 	: CActive( EPriorityStandard ), iSession( aSession )
       
   230 	{
       
   231 	CActiveScheduler::Add(this);
       
   232 	}
       
   233 
       
   234 CMemSpyDwoProgressTracker::~CMemSpyDwoProgressTracker()
       
   235 	{
       
   236 	Cancel();	
       
   237 	}
       
   238 
       
   239 void CMemSpyDwoProgressTracker::Start()
       
   240 	{
       
   241 	ASSERT( iProgressDialog == NULL );
       
   242 	iProgressDialog = new( ELeave ) CAknProgressDialog( reinterpret_cast< CEikDialog** >( &iProgressDialog ), ETrue );
       
   243 	iProgressDialog->PrepareLC( R_MEMSPY_DEVICE_WIDE_OPERATION_PROGRESS_DIALOG );
       
   244 	iProgressDialog->SetCallback( this );
       
   245 	iProgressDialog->SetGloballyCapturing( ETrue );
       
   246 	iProgressInfo = iProgressDialog->GetProgressInfoL();	
       
   247 	
       
   248 	iSession.NotifyDeviceWideOperationProgress( iProgress, iStatus );
       
   249 	
       
   250 	UpdateProcessDialogL( iProgress.Progress(), iProgress.Description() );
       
   251 	
       
   252 	SetActive();
       
   253 	
       
   254 	iProgressDialog->RunLD();
       
   255 	}
       
   256 
       
   257 void CMemSpyDwoProgressTracker::Cancel()
       
   258 	{	
       
   259 	}
       
   260 
       
   261 void CMemSpyDwoProgressTracker::RunL()
       
   262     { 		
       
   263     // If an error occurred handle it in RunError().
       
   264     User::LeaveIfError(iStatus.Int());
       
   265  
       
   266     // Resubmit the request immediately    
       
   267     iSession.NotifyDeviceWideOperationProgress( iProgress, iStatus );     
       
   268     
       
   269     SetActive();            
       
   270     
       
   271     UpdateProcessDialogL( iProgress.Progress(), iProgress.Description() );    
       
   272     }
       
   273  
       
   274 void CMemSpyDwoProgressTracker::DoCancel()
       
   275 	{ 	
       
   276 	}
       
   277  
       
   278 TInt CMemSpyDwoProgressTracker::RunError(TInt aError)
       
   279 	{ 
       
   280 	// KErrNotReady and KErrCancel errors are OK, they just notify 
       
   281 	// us about the outstanding notification request that won't be 
       
   282 	// processed.		
       
   283     return KErrNone;
       
   284 	}
       
   285 
       
   286 void CMemSpyDwoProgressTracker::UpdateProcessDialogL( TInt aProgress, const TDesC& aProgressText )
       
   287 	{
       
   288 	if(iProgressDialog)
       
   289 		{
       
   290 		iProgressDialog->SetTextL( aProgressText );
       
   291 	    }
       
   292 	 
       
   293 	if(iProgressInfo)
       
   294 		{
       
   295 	    iProgressInfo->SetAndDraw( aProgress );	
       
   296 		}
       
   297 	}
       
   298 
       
   299 void CMemSpyDwoProgressTracker::DialogDismissedL(TInt aButtonId)
       
   300 	{
       
   301 	iProgressDialog = NULL;
       
   302 	iProgressInfo = NULL;	
       
   303 	 
       
   304 	Cancel();
       
   305 	}
       
   306 
       
   307 
       
   308 
       
   309 
       
   310 
       
   311 
       
   312 
       
   313 
       
   314 
       
   315 
       
   316 
       
   317 
       
   318 
       
   319 
       
   320 CMemSpyDwoTracker::CMemSpyDwoTracker( RMemSpySession &aSession, TDeviceWideOperation aOperation )
       
   321 :	CActive( EPriorityStandard ), 
       
   322 	iSession( aSession ),
       
   323 	iProgressTracker(new CMemSpyDwoProgressTracker( aSession )),
       
   324 	iOperation( aOperation )
       
   325 	{
       
   326 	CActiveScheduler::Add(this);
       
   327 	}
       
   328 
       
   329 CMemSpyDwoTracker::~CMemSpyDwoTracker()
       
   330 	{		
       
   331 	Cancel();
       
   332 	
       
   333 	delete iProgressTracker;
       
   334 	}
       
   335 
       
   336 void CMemSpyDwoTracker::Start()
       
   337 {	
       
   338 	void (RMemSpySession::*functions[])(TRequestStatus&) = { 
       
   339 		&RMemSpySession::OutputPhoneInfo,
       
   340 		&RMemSpySession::OutputDetailedPhoneInfo,
       
   341 		&RMemSpySession::OutputHeapInfo,
       
   342 		&RMemSpySession::OutputCompactHeapInfo,
       
   343 		&RMemSpySession::OutputHeapCellListing,
       
   344 		&RMemSpySession::OutputHeapData,
       
   345 		&RMemSpySession::OutputStackInfo,
       
   346 		&RMemSpySession::OutputCompactStackInfo,
       
   347 		&RMemSpySession::OutputUserStackData,
       
   348 		&RMemSpySession::OutputKernelStackData };
       
   349 		
       
   350 	(iSession.*functions[iOperation])(iStatus);			
       
   351 	
       
   352 	SetActive();
       
   353 	
       
   354 	iProgressTracker->Start();				
       
   355 }
       
   356 
       
   357 void CMemSpyDwoTracker::Cancel()
       
   358 {
       
   359 }
       
   360  
       
   361 void CMemSpyDwoTracker::RunL()
       
   362     { 
       
   363     // If an error occurred handle it in RunError().
       
   364     User::LeaveIfError(iStatus.Int());
       
   365  
       
   366     if( !IsActive() )
       
   367     	{
       
   368 		iProgressTracker->ProgressDialog()->ProcessFinishedL();
       
   369     	}
       
   370     }
       
   371  
       
   372 void CMemSpyDwoTracker::DoCancel()
       
   373 { 
       
   374 	// Cancel progress tracker
       
   375 	iProgressTracker->Cancel();
       
   376 	
       
   377 	iSession.CancelDeviceWideOperationL();	
       
   378 }
       
   379  
       
   380 TInt CMemSpyDwoTracker::RunError(TInt aError)
       
   381 { 
       
   382 	// Emit the finished(false) signal to notify user 
       
   383 	// operation was canceled
       
   384 	//emit finished(false); //TODO:
       
   385 	
       
   386     return KErrNone;
       
   387 }