connectivitymodules/SeCon/services/pcd/src/sconqueue.cpp
branchRCL_3
changeset 20 4a793f564d72
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Queue implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "sconqueue.h"
       
    22 #include "sconpcdconsts.h"
       
    23 #include "debug.h"
       
    24 #include <SWInstDefs.h> // installer errors
       
    25 
       
    26 // ============================= MEMBER FUNCTIONS ===============================
       
    27 
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CSConTaskQueue::~CSConTaskQueue()
       
    31 // Destructor
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CSConTaskQueue::~CSConTaskQueue()
       
    35     {
       
    36     TRACE_FUNC;
       
    37     iQueue.ResetAndDestroy();
       
    38     iQueue.Close(); 
       
    39     iTimer.Close();
       
    40     }
       
    41     
       
    42 // -----------------------------------------------------------------------------
       
    43 // CSConTaskQueue::GetQueueStatus( TInt aTask, TBool aAllTasks, 
       
    44 //                                  CSConStatusReply*& aStatus )
       
    45 // Returns the status of a specified task / all tasks
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CSConTaskQueue::GetQueueStatusL( TInt aTask, TBool aAllTasks, 
       
    49                                     CSConStatusReply*& aStatus )
       
    50     {
       
    51     RArray<TInt> completedTasks;
       
    52     CleanupClosePushL( completedTasks );
       
    53     if ( aAllTasks )
       
    54         {
       
    55         //if there are tasks
       
    56         if ( iQueue.Count() > 0 )
       
    57             {
       
    58             //set iNoTasks as EFalse
       
    59             aStatus->iNoTasks = EFalse;
       
    60             for ( TInt i = 0; i < iQueue.Count(); i++ )
       
    61                 {
       
    62                 //Fill reply object
       
    63                 CSConTaskReply* taskReply = new (ELeave) CSConTaskReply();
       
    64                 CleanupStack::PushL( taskReply );
       
    65                 taskReply->InitializeL( *iQueue[i] );
       
    66                 User::LeaveIfError( aStatus->iTasks.Append( taskReply ) );
       
    67                 CleanupStack::Pop( taskReply );
       
    68                 TBool complete = iQueue[i]->GetComplete();
       
    69 
       
    70                 //Collect completed task numbers to array for deleting
       
    71                 if ( complete )
       
    72                     {
       
    73                     completedTasks.Append( iQueue[i]->iTaskId );
       
    74                     }
       
    75                 //Otherwise clean all unneccessary data from the reply packet
       
    76                 else
       
    77                     {
       
    78                     taskReply->CleanTaskData(); 
       
    79                     }
       
    80                 }
       
    81             }
       
    82         else
       
    83             {
       
    84             //no task in the queue
       
    85             aStatus->iNoTasks = ETrue;
       
    86             }
       
    87 
       
    88         //Remove completed tasks from queue
       
    89         for ( TInt j = 0; j < completedTasks.Count(); j++ )
       
    90             {
       
    91             RemoveTask( completedTasks[j] );
       
    92             }
       
    93         }
       
    94     else if ( aTask > 0 )
       
    95         {
       
    96         CSConTask* temp = new (ELeave) CSConTask();
       
    97         temp->iTaskId = aTask;
       
    98         TInt index = iQueue.Find( temp, CSConTaskQueue::Match );
       
    99         delete temp;
       
   100         
       
   101         TBool complete = EFalse;
       
   102         CSConTaskReply* taskReply(NULL);
       
   103 
       
   104         if ( index != KErrNotFound )
       
   105             {
       
   106             aStatus->iNoTasks = EFalse;
       
   107             //Fill reply object
       
   108             taskReply = new (ELeave) CSConTaskReply();
       
   109             CleanupStack::PushL( taskReply );
       
   110             taskReply->InitializeL( *iQueue[index] );
       
   111             User::LeaveIfError( aStatus->iTasks.Append( taskReply ) );
       
   112             CleanupStack::Pop( taskReply );
       
   113             complete = iQueue[index]->GetComplete();
       
   114             }
       
   115         else
       
   116             {
       
   117             //no task in the queue
       
   118             aStatus->iNoTasks = ETrue;
       
   119             }        
       
   120         
       
   121         //Delete completed tasks from queue
       
   122         if ( complete )
       
   123             {
       
   124             RemoveTask( aTask );
       
   125             }
       
   126         //Otherwise clean all unneccessary data from the reply packet
       
   127         else if ( taskReply )
       
   128             {
       
   129             taskReply->CleanTaskData(); 
       
   130             }
       
   131         }
       
   132     else
       
   133         {
       
   134         //no task in the queue
       
   135         aStatus->iNoTasks = ETrue;
       
   136         }
       
   137     CleanupStack::PopAndDestroy( &completedTasks ); // close
       
   138     }   
       
   139     
       
   140 // -----------------------------------------------------------------------------
       
   141 // CSConTaskQueue::AddNewTask( CSConTask*& aNewTask, TInt aTaskId )
       
   142 // Adds a new task to queue
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 TInt CSConTaskQueue::AddNewTask( CSConTask*& aNewTask, TInt aTaskId )
       
   146     {
       
   147     TInt ret( KErrNone );
       
   148     
       
   149     aNewTask->iTaskId = aTaskId;
       
   150     
       
   151     //Set progress value "task accepted for execution"
       
   152     aNewTask->SetProgressValue( KSConCodeTaskCreated );
       
   153     aNewTask->SetCompleteValue( EFalse );
       
   154     
       
   155     if ( iQueue.Count() == 0 )
       
   156         {
       
   157         StartQueue();
       
   158         }
       
   159     ret = iQueue.InsertInOrder( aNewTask, CSConTaskQueue::Compare );
       
   160     return ret;
       
   161     }
       
   162     
       
   163 // -----------------------------------------------------------------------------
       
   164 // CSConTaskQueue::CompleteTask( TInt aTask, TInt aError )
       
   165 // Set the task to completed -mode
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CSConTaskQueue::CompleteTask( TInt aTask, TInt aError )
       
   169     {
       
   170     LOGGER_WRITE_1( "CSConTaskQueue::CompleteTask aError: %d", aError );
       
   171     TInt index( KErrNotFound );
       
   172     
       
   173     CSConTask* temp = new CSConTask();
       
   174     temp->iTaskId = aTask;
       
   175     index = iQueue.Find( temp, CSConTaskQueue::Match );
       
   176     delete temp;
       
   177     
       
   178     if ( index != KErrNotFound )
       
   179         {
       
   180         TBool complete( ETrue );
       
   181         TBool notComplete( EFalse );
       
   182         TInt progress( KSConCodeTaskCompleted );        
       
   183         
       
   184         switch( aError )
       
   185             {
       
   186             case KErrNone :
       
   187                 iQueue[index]->SetCompleteValue( complete );
       
   188                 progress =  KSConCodeTaskCompleted;
       
   189                 break;
       
   190             case KErrNotFound :
       
   191                 iQueue[index]->SetCompleteValue( complete );
       
   192                 progress =  KSConCodeNotFound;
       
   193                 break;
       
   194             case KErrCompletion :
       
   195                 iQueue[index]->SetCompleteValue( notComplete );
       
   196                 progress = KSConCodeTaskPartiallyCompleted;
       
   197                 break;
       
   198 
       
   199             // installer specific errors
       
   200             case SwiUI::KSWInstErrUserCancel:
       
   201             	LOGGER_WRITE("User cancelled the operation");
       
   202             	iQueue[index]->SetCompleteValue( complete );
       
   203             	progress = KSConCodeInstErrUserCancel;
       
   204             	break;
       
   205             case SwiUI::KSWInstErrFileCorrupted:
       
   206             	LOGGER_WRITE("File is corrupted");
       
   207             	iQueue[index]->SetCompleteValue( complete );
       
   208             	progress = KSConCodeInstErrFileCorrupted;
       
   209             	break;
       
   210             case SwiUI::KSWInstErrInsufficientMemory:
       
   211             	LOGGER_WRITE("Insufficient free memory in the drive to perform the operation");
       
   212 	            iQueue[index]->SetCompleteValue( complete );
       
   213 	            progress = KSConCodeInstErrInsufficientMemory;	
       
   214 	            break;
       
   215             case SwiUI::KSWInstErrPackageNotSupported:
       
   216             	LOGGER_WRITE("Installation of the package is not supported");
       
   217             	iQueue[index]->SetCompleteValue( complete );
       
   218             	progress = KSConCodeInstErrPackageNotSupported;
       
   219             	break;
       
   220             case SwiUI::KSWInstErrSecurityFailure:
       
   221             	LOGGER_WRITE("Package cannot be installed due to security error");
       
   222             	iQueue[index]->SetCompleteValue( complete );
       
   223             	progress = KSConCodeInstErrSecurityFailure;
       
   224             	break;
       
   225             case SwiUI::KSWInstErrMissingDependency:
       
   226             	LOGGER_WRITE("Package cannot be installed due to missing dependency");
       
   227             	iQueue[index]->SetCompleteValue( complete );
       
   228             	progress = KSConCodeInstErrMissingDependency;
       
   229             	break;
       
   230             case SwiUI::KSWInstErrFileInUse:
       
   231             	LOGGER_WRITE("Mandatory file is in use and prevents the operation");
       
   232             	iQueue[index]->SetCompleteValue( complete );
       
   233             	progress = KSConCodeInstErrFileInUse;
       
   234             	break;
       
   235             case SwiUI::KSWInstErrGeneralError:
       
   236             	LOGGER_WRITE("Unknown error");
       
   237             	iQueue[index]->SetCompleteValue( complete );
       
   238             	progress = KSConCodeInstErrGeneralError;
       
   239             	break;
       
   240             case SwiUI::KSWInstErrNoRights:
       
   241             	LOGGER_WRITE("The package has no rights to perform the operation");
       
   242             	iQueue[index]->SetCompleteValue( complete );
       
   243             	progress = KSConCodeInstErrNoRights;
       
   244             	break;
       
   245             case SwiUI::KSWInstErrNetworkFailure:
       
   246             	LOGGER_WRITE("Indicates that network failure aborted the operation");
       
   247             	iQueue[index]->SetCompleteValue( complete );
       
   248             	progress = KSConCodeInstErrNetworkFailure;
       
   249             	break;
       
   250             case SwiUI::KSWInstErrBusy:
       
   251             	LOGGER_WRITE("Installer is busy doing some other operation");
       
   252             	iQueue[index]->SetCompleteValue( complete );
       
   253         		progress = KSConCodeInstErrBusy;
       
   254             	break;
       
   255             case SwiUI::KSWInstErrAccessDenied:
       
   256             	LOGGER_WRITE("Target location of package is not accessible");
       
   257             	iQueue[index]->SetCompleteValue( complete );
       
   258             	progress = KSConCodeInstErrAccessDenied;
       
   259             	break;
       
   260             case SwiUI::KSWInstUpgradeError:
       
   261             	LOGGER_WRITE("The package is an invalid upgrade");
       
   262             	iQueue[index]->SetCompleteValue( complete );
       
   263             	progress = KSConCodeInstUpgradeError;
       
   264             	break;
       
   265             
       
   266             default :
       
   267                 iQueue[index]->SetCompleteValue( complete );
       
   268                 if ( aError < KErrNone && aError >= KErrCorruptSurrogateFound )
       
   269                     {
       
   270                     // aError is always negative
       
   271                     //  -> returned errorcode is from KSConCodeFirstSymbianErr...n
       
   272                     progress = KSConCodeFirstSymbianErr - aError;
       
   273                     }
       
   274                 else
       
   275                     {
       
   276                     progress = KSConCodeConflict;
       
   277                     }
       
   278                 
       
   279                 break;
       
   280             }
       
   281             
       
   282         iQueue[index]->SetProgressValue( progress );
       
   283         }
       
   284     StartQueue();
       
   285     }
       
   286     
       
   287 // -----------------------------------------------------------------------------
       
   288 // CSConTaskQueue::SetTaskProgress( TInt aTask, TInt aProgressValue )
       
   289 // Set the task progress value
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 void CSConTaskQueue::SetTaskProgress( TInt aTask, TInt aProgressValue )
       
   293     {
       
   294     TInt index( KErrNotFound );
       
   295 
       
   296     CSConTask* temp = new CSConTask();
       
   297     temp->iTaskId = aTask;
       
   298     index = iQueue.Find( temp, CSConTaskQueue::Match );
       
   299     delete temp;
       
   300     
       
   301     if ( index != KErrNotFound )
       
   302         {
       
   303         iQueue[index]->SetProgressValue( aProgressValue );
       
   304         }
       
   305     }
       
   306     
       
   307 // -----------------------------------------------------------------------------
       
   308 // CSConTaskQueue::GetTask( TInt aTaskId, CSConTask*& aTask )
       
   309 // Receives a specified task
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 TInt CSConTaskQueue::GetTask( TInt aTaskId, CSConTask*& aTask )
       
   313     {
       
   314     TInt ret( KErrNone );
       
   315     TInt index;
       
   316     
       
   317     CSConTask* temp = new CSConTask();
       
   318     temp->iTaskId = aTaskId;
       
   319     index = iQueue.Find( temp, CSConTaskQueue::Match );
       
   320     delete temp;
       
   321 
       
   322     if ( index != KErrNotFound )
       
   323         {
       
   324         aTask = iQueue[index];
       
   325         }
       
   326     else
       
   327         {
       
   328         ret = KErrNotFound;
       
   329         }
       
   330     return ret;
       
   331     }
       
   332     
       
   333 // -----------------------------------------------------------------------------
       
   334 // CSConTaskQueue::RemoveTask( TInt aTask )
       
   335 // Removes a task from the queue
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 void CSConTaskQueue::RemoveTask( TInt aTask )
       
   339     {
       
   340     TInt index( KErrNotFound );
       
   341     
       
   342     CSConTask* temp = new CSConTask();
       
   343     temp->iTaskId = aTask;
       
   344     index = iQueue.Find( temp, CSConTaskQueue::Match );
       
   345     delete temp;
       
   346     
       
   347     if ( index != KErrNotFound ) 
       
   348         {
       
   349         delete iQueue[index];
       
   350         iQueue.Remove( index );
       
   351         iQueue.Compress();
       
   352         }
       
   353     
       
   354     if ( iQueue.Count() == 0 )
       
   355         {
       
   356         StopQueue();
       
   357         iQueue.Reset();
       
   358         }
       
   359     }
       
   360     
       
   361 // -----------------------------------------------------------------------------
       
   362 // CSConTaskQueue::CancelTask( TInt aTask, TBool aAllTasks )
       
   363 // Cancels a task
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 void CSConTaskQueue::CancelTask( TInt aTask, TBool aAllTasks )
       
   367     {
       
   368     TRACE_FUNC_ENTRY;
       
   369     
       
   370     //Remove the task from the queue
       
   371     if ( aTask > 0 && !aAllTasks )
       
   372         {
       
   373         RemoveTask( aTask );
       
   374         }
       
   375         
       
   376     //Remove all tasks from the queue
       
   377     if ( aAllTasks )
       
   378         {
       
   379         iQueue.ResetAndDestroy();
       
   380         }
       
   381     
       
   382     TRACE_FUNC_EXIT;
       
   383     }
       
   384     
       
   385 // -----------------------------------------------------------------------------
       
   386 // CSConTaskQueue::QueueProcessActive()
       
   387 // The status of the process
       
   388 // -----------------------------------------------------------------------------
       
   389 //  
       
   390 TBool CSConTaskQueue::QueueProcessActive() const
       
   391     {
       
   392     return iQueueProcessActive;
       
   393     }
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // CSConTaskQueue::ChangeQueueProcessStatus()
       
   397 // Changes the status of the queue process
       
   398 // -----------------------------------------------------------------------------
       
   399 //  
       
   400 void CSConTaskQueue::ChangeQueueProcessStatus()
       
   401     {
       
   402     iQueueProcessActive = !iQueueProcessActive;
       
   403     }
       
   404     
       
   405 // -----------------------------------------------------------------------------
       
   406 // CSConTaskQueue::Reset()
       
   407 // Resets the queue
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 void CSConTaskQueue::Reset()
       
   411     {
       
   412     TRACE_FUNC_ENTRY;
       
   413     iTimer.Cancel();
       
   414     iQueue.ResetAndDestroy();
       
   415     TRACE_FUNC_EXIT;
       
   416     }
       
   417 
       
   418 // ---------------------------------------------------------
       
   419 // CSConTaskQueue::Compare( const CSConTask& aFirst, 
       
   420 //                          const CSConTask& aSecond )
       
   421 // Compares task numbers
       
   422 // ---------------------------------------------------------    
       
   423 TInt CSConTaskQueue::Compare( const CSConTask& aFirst, 
       
   424                             const CSConTask& aSecond )
       
   425     {
       
   426     if ( aFirst.iTaskId < aSecond.iTaskId )
       
   427         {
       
   428         return -1;
       
   429         }
       
   430     else if ( aFirst.iTaskId > aSecond.iTaskId )
       
   431         {
       
   432         return 1;
       
   433         }
       
   434     
       
   435     return 0;
       
   436     }
       
   437     
       
   438 // -----------------------------------------------------------------------------
       
   439 // CSConTaskQueue::Match( const CSConTask& aFirst, const CSConTask& aSecond )
       
   440 // Matches the task numbers
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 TInt CSConTaskQueue::Match( const CSConTask& aFirst, const CSConTask& aSecond )
       
   444     {
       
   445     if ( aFirst.iTaskId == aSecond.iTaskId )
       
   446         {
       
   447         return ETrue;
       
   448         }
       
   449         
       
   450     return EFalse;
       
   451     }
       
   452 // End of file