connectivitymodules/SeCon/services/pcd/src/sconinstqueue.cpp
branchRCL_3
changeset 20 4a793f564d72
parent 0 d0791faffa3f
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Installer Queue implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "sconinstqueue.h"
       
    21 #include "sconbrqueue.h"
       
    22 #include "sconinstaller.h"
       
    23 #include "sconpcdconsts.h"
       
    24 #include "debug.h"
       
    25 
       
    26 // ============================= MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CCSConInstallerQueue* CSConInstallerQueue::NewL()
       
    30 // Two-phase constructor
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CSConInstallerQueue* CSConInstallerQueue::NewL( RFs& aFs )
       
    34 	{
       
    35 	TRACE_FUNC_ENTRY;
       
    36 	CSConInstallerQueue* self = new (ELeave) CSConInstallerQueue( aFs );
       
    37 	CleanupStack::PushL( self );
       
    38 	self->ConstructL();
       
    39 	CleanupStack::Pop( self );
       
    40 	TRACE_FUNC_EXIT;
       
    41     return self;
       
    42 	}
       
    43 	
       
    44 // -----------------------------------------------------------------------------
       
    45 // CSConInstallerQueue::CSConInstallerQueue()
       
    46 // Constructor
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CSConInstallerQueue::CSConInstallerQueue( RFs& aFs ) : CActive( EPriorityStandard ), iFs( aFs )
       
    50 	{
       
    51 	}
       
    52 	
       
    53 // -----------------------------------------------------------------------------
       
    54 // CSConInstallerQueue::ConstructL()
       
    55 // Initializes member data
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CSConInstallerQueue::ConstructL()
       
    59 	{
       
    60 	TRACE_FUNC_ENTRY;
       
    61 	iInstaller = new (ELeave) CSConAppInstaller( this, iFs );
       
    62 	CActiveScheduler::Add( iInstaller );
       
    63 	User::LeaveIfError( iTimer.CreateLocal() );
       
    64 	TRACE_FUNC_EXIT;
       
    65 	}
       
    66 	
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSConInstallerQueue::~CSConInstallerQueue()
       
    69 // Destructor
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CSConInstallerQueue::~CSConInstallerQueue()
       
    73 	{
       
    74 	TRACE_FUNC_ENTRY;
       
    75 	Cancel();
       
    76 	if( iInstaller )
       
    77 		{
       
    78 		iInstaller->Cancel();
       
    79 		delete iInstaller;
       
    80 		iInstaller = NULL;
       
    81 		}
       
    82 	TRACE_FUNC_EXIT;
       
    83 	}
       
    84 	
       
    85 // -----------------------------------------------------------------------------
       
    86 // CSConInstallerQueue::StartQueue()
       
    87 // Starts queue polling
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CSConInstallerQueue::StartQueue()
       
    91 	{
       
    92 	TRACE_FUNC;
       
    93 	if( IsActive() )
       
    94 		{
       
    95 		Cancel();
       
    96 		}
       
    97 		
       
    98 	iTimer.After( iStatus, KSConTimerValue );
       
    99 	SetActive();
       
   100 	}
       
   101 	
       
   102 // -----------------------------------------------------------------------------
       
   103 // CSConInstallerQueue::StartQueue()
       
   104 // Stops queue polling
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CSConInstallerQueue::StopQueue()	
       
   108 	{
       
   109 	TRACE_FUNC_ENTRY;
       
   110 	iTimer.Cancel();
       
   111 	TRACE_FUNC_EXIT;
       
   112 	}
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CSConInstallerQueue::CancelTask( TInt aTask, TBool aAllTasks )
       
   116 // Cancels a task
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CSConInstallerQueue::CancelTask( TInt aTask, TBool aAllTasks )
       
   120 	{
       
   121 	TRACE_FUNC_ENTRY;
       
   122 	//Stop the installer
       
   123 	if( aTask && !aAllTasks )
       
   124 		{
       
   125 		iInstaller->StopInstaller( aTask );
       
   126 		}
       
   127 	
       
   128 	if( aAllTasks )
       
   129 		{
       
   130 		iInstaller->Cancel();
       
   131 		}
       
   132 	CSConTaskQueue::CancelTask( aTask, aAllTasks );
       
   133 	TRACE_FUNC_EXIT;
       
   134 	}
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CSConInstallerQueue::QueueAddress( CSConBackupRestoreQueue*& aTaskQueue )
       
   138 // An address pointer to another queue
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CSConInstallerQueue::QueueAddress( CSConBackupRestoreQueue*& aTaskQueue )
       
   142 	{
       
   143 	TRACE_FUNC;
       
   144 	iBRQueueAddress = aTaskQueue;
       
   145 	}
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CSConInstallerQueue::PollQueue()
       
   149 // Polls queue
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CSConInstallerQueue::PollQueue()
       
   153 	{
       
   154 	TRACE_FUNC_ENTRY;
       
   155 	// find and start next task if installer and BR is inactive
       
   156 	if( !iInstaller->InstallerActive()
       
   157 		&& !iBRQueueAddress->QueueProcessActive() )
       
   158 		{
       
   159 		//find next task
       
   160 		for( TInt i = 0; i < iQueue.Count(); i++ )
       
   161 			{
       
   162 			TBool complete = iQueue[i]->GetCompleteValue();
       
   163 			
       
   164 			if( complete == EFalse )
       
   165 				{
       
   166 				iInstaller->StartInstaller( iQueue[i]->iTaskId );
       
   167 				i = iQueue.Count() + 1; // jump out from loop
       
   168 				}
       
   169 			}
       
   170 		}
       
   171 	TRACE_FUNC_EXIT;
       
   172 	}
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CSConInstallerQueue::DoCancel()
       
   176 // Implementation of CActive::DoCancel()
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CSConInstallerQueue::DoCancel()
       
   180 	{
       
   181 	TRACE_FUNC;
       
   182 	iTimer.Cancel();
       
   183 	}
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CSConInstallerQueue::RunL()
       
   187 // Implementation of CActive::RunL()
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CSConInstallerQueue::RunL()
       
   191 	{
       
   192 	TRACE_FUNC_ENTRY;
       
   193 	LOGGER_WRITE_1( "There are still %d tasks in this queue", iQueue.Count() );
       
   194 	if( iQueue.Count() > 0 )
       
   195 		{
       
   196 		PollQueue();
       
   197 		StartQueue();
       
   198 		}
       
   199 	TRACE_FUNC_EXIT;
       
   200 	}
       
   201 
       
   202 // End of file