connectivitymodules/SeCon/services/pcd/src/sconqueue.cpp
changeset 0 d0791faffa3f
child 1 f8e15b44d440
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     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                 progress = KSConCodeConflict;
       
   269                 break;
       
   270             }
       
   271             
       
   272         iQueue[index]->SetProgressValue( progress );
       
   273         }
       
   274     StartQueue();
       
   275     }
       
   276     
       
   277 // -----------------------------------------------------------------------------
       
   278 // CSConTaskQueue::SetTaskProgress( TInt aTask, TInt aProgressValue )
       
   279 // Set the task progress value
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CSConTaskQueue::SetTaskProgress( TInt aTask, TInt aProgressValue )
       
   283     {
       
   284     TInt index( KErrNotFound );
       
   285 
       
   286     CSConTask* temp = new CSConTask();
       
   287     temp->iTaskId = aTask;
       
   288     index = iQueue.Find( temp, CSConTaskQueue::Match );
       
   289     delete temp;
       
   290     
       
   291     if ( index != KErrNotFound )
       
   292         {
       
   293         iQueue[index]->SetProgressValue( aProgressValue );
       
   294         }
       
   295     }
       
   296     
       
   297 // -----------------------------------------------------------------------------
       
   298 // CSConTaskQueue::GetTask( TInt aTaskId, CSConTask*& aTask )
       
   299 // Receives a specified task
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 TInt CSConTaskQueue::GetTask( TInt aTaskId, CSConTask*& aTask )
       
   303     {
       
   304     TInt ret( KErrNone );
       
   305     TInt index;
       
   306     
       
   307     CSConTask* temp = new CSConTask();
       
   308     temp->iTaskId = aTaskId;
       
   309     index = iQueue.Find( temp, CSConTaskQueue::Match );
       
   310     delete temp;
       
   311 
       
   312     if ( index != KErrNotFound )
       
   313         {
       
   314         aTask = iQueue[index];
       
   315         }
       
   316     else
       
   317         {
       
   318         ret = KErrNotFound;
       
   319         }
       
   320     return ret;
       
   321     }
       
   322     
       
   323 // -----------------------------------------------------------------------------
       
   324 // CSConTaskQueue::RemoveTask( TInt aTask )
       
   325 // Removes a task from the queue
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 void CSConTaskQueue::RemoveTask( TInt aTask )
       
   329     {
       
   330     TInt index( KErrNotFound );
       
   331     
       
   332     CSConTask* temp = new CSConTask();
       
   333     temp->iTaskId = aTask;
       
   334     index = iQueue.Find( temp, CSConTaskQueue::Match );
       
   335     delete temp;
       
   336     
       
   337     if ( index != KErrNotFound ) 
       
   338         {
       
   339         delete iQueue[index];
       
   340         iQueue.Remove( index );
       
   341         iQueue.Compress();
       
   342         }
       
   343     
       
   344     if ( iQueue.Count() == 0 )
       
   345         {
       
   346         StopQueue();
       
   347         iQueue.Reset();
       
   348         }
       
   349     }
       
   350     
       
   351 // -----------------------------------------------------------------------------
       
   352 // CSConTaskQueue::CancelTask( TInt aTask, TBool aAllTasks )
       
   353 // Cancels a task
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 void CSConTaskQueue::CancelTask( TInt aTask, TBool aAllTasks )
       
   357     {
       
   358     TRACE_FUNC_ENTRY;
       
   359     
       
   360     //Remove the task from the queue
       
   361     if ( aTask > 0 && !aAllTasks )
       
   362         {
       
   363         RemoveTask( aTask );
       
   364         }
       
   365         
       
   366     //Remove all tasks from the queue
       
   367     if ( aAllTasks )
       
   368         {
       
   369         iQueue.ResetAndDestroy();
       
   370         }
       
   371     
       
   372     TRACE_FUNC_EXIT;
       
   373     }
       
   374     
       
   375 // -----------------------------------------------------------------------------
       
   376 // CSConTaskQueue::QueueProcessActive()
       
   377 // The status of the process
       
   378 // -----------------------------------------------------------------------------
       
   379 //  
       
   380 TBool CSConTaskQueue::QueueProcessActive() const
       
   381     {
       
   382     return iQueueProcessActive;
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CSConTaskQueue::ChangeQueueProcessStatus()
       
   387 // Changes the status of the queue process
       
   388 // -----------------------------------------------------------------------------
       
   389 //  
       
   390 void CSConTaskQueue::ChangeQueueProcessStatus()
       
   391     {
       
   392     iQueueProcessActive = !iQueueProcessActive;
       
   393     }
       
   394     
       
   395 // -----------------------------------------------------------------------------
       
   396 // CSConTaskQueue::Reset()
       
   397 // Resets the queue
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 void CSConTaskQueue::Reset()
       
   401     {
       
   402     TRACE_FUNC_ENTRY;
       
   403     iTimer.Cancel();
       
   404     iQueue.ResetAndDestroy();
       
   405     TRACE_FUNC_EXIT;
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------
       
   409 // CSConTaskQueue::Compare( const CSConTask& aFirst, 
       
   410 //                          const CSConTask& aSecond )
       
   411 // Compares task numbers
       
   412 // ---------------------------------------------------------    
       
   413 TInt CSConTaskQueue::Compare( const CSConTask& aFirst, 
       
   414                             const CSConTask& aSecond )
       
   415     {
       
   416     if ( aFirst.iTaskId < aSecond.iTaskId )
       
   417         {
       
   418         return -1;
       
   419         }
       
   420     else if ( aFirst.iTaskId > aSecond.iTaskId )
       
   421         {
       
   422         return 1;
       
   423         }
       
   424     
       
   425     return 0;
       
   426     }
       
   427     
       
   428 // -----------------------------------------------------------------------------
       
   429 // CSConTaskQueue::Match( const CSConTask& aFirst, const CSConTask& aSecond )
       
   430 // Matches the task numbers
       
   431 // -----------------------------------------------------------------------------
       
   432 //
       
   433 TInt CSConTaskQueue::Match( const CSConTask& aFirst, const CSConTask& aSecond )
       
   434     {
       
   435     if ( aFirst.iTaskId == aSecond.iTaskId )
       
   436         {
       
   437         return ETrue;
       
   438         }
       
   439         
       
   440     return EFalse;
       
   441     }
       
   442 // End of file