connectivitymodules/SeCon/services/pcd/src/sconbrqueue.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:  Backup-Restore Queue implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "sconbrqueue.h"
       
    21 #include "sconbackuprestore.h"
       
    22 #include "sconpcdconsts.h"
       
    23 #include "sconinstqueue.h"
       
    24 #include "debug.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CSConBackupRestoreQueue::NewL( const TInt aMaxObjectSize )
       
    28 // Two-phase constructor
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CSConBackupRestoreQueue* CSConBackupRestoreQueue::NewL( const TInt aMaxObjectSize, RFs& aFs )
       
    32 	{
       
    33 	TRACE_FUNC_ENTRY;
       
    34 	CSConBackupRestoreQueue* self = new (ELeave) CSConBackupRestoreQueue();
       
    35 	CleanupStack::PushL( self );
       
    36 	self->ConstructL( aMaxObjectSize, aFs );
       
    37 	CleanupStack::Pop( self );
       
    38 	TRACE_FUNC_EXIT;
       
    39     return self;
       
    40 	}
       
    41 	
       
    42 // -----------------------------------------------------------------------------
       
    43 // CSConBackupRestoreQueue::CSConBackupRestoreQueue()
       
    44 // Destructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CSConBackupRestoreQueue::CSConBackupRestoreQueue() : 
       
    48 					CActive( EPriorityStandard )
       
    49 	{
       
    50 	}
       
    51 	
       
    52 // -----------------------------------------------------------------------------
       
    53 // CSConBackupRestoreQueue::ConstructL( const TInt aMaxObjectSize )
       
    54 // Initializes member data
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CSConBackupRestoreQueue::ConstructL( const TInt aMaxObjectSize, RFs& aFs )
       
    58 	{
       
    59 	TRACE_FUNC_ENTRY;
       
    60 	iBackupRestore = CSConBackupRestore::NewL( this, aMaxObjectSize, aFs );
       
    61 	CActiveScheduler::Add( iBackupRestore );
       
    62 	User::LeaveIfError( iTimer.CreateLocal() );
       
    63 	TRACE_FUNC_EXIT;
       
    64 	}
       
    65 	
       
    66 // -----------------------------------------------------------------------------
       
    67 // CSConBackupRestoreQueue::~CSConBackupRestoreQueue()
       
    68 // Destructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CSConBackupRestoreQueue::~CSConBackupRestoreQueue()
       
    72 	{
       
    73 	TRACE_FUNC_ENTRY;
       
    74 	Cancel();
       
    75 	if( iBackupRestore )
       
    76 		{
       
    77 		delete iBackupRestore;
       
    78 		iBackupRestore = NULL;
       
    79 		}
       
    80 	
       
    81 	TRACE_FUNC_EXIT;
       
    82 	}
       
    83 	
       
    84 // -----------------------------------------------------------------------------
       
    85 // CSConBackupRestoreQueue::StartQueue()
       
    86 // Starts queue polling
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CSConBackupRestoreQueue::StartQueue()	
       
    90 	{
       
    91 	TRACE_FUNC_ENTRY;
       
    92 	if( IsActive() )
       
    93 		{
       
    94 		Cancel();
       
    95 		}
       
    96 		
       
    97 	iTimer.After( iStatus, KSConTimerValue );
       
    98 	SetActive();
       
    99 	TRACE_FUNC_EXIT;
       
   100 	}
       
   101 	
       
   102 // -----------------------------------------------------------------------------
       
   103 // CSConBackupRestoreQueue::StopQueue()
       
   104 // Stops queue polling
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CSConBackupRestoreQueue::StopQueue()	
       
   108 	{
       
   109 	TRACE_FUNC_ENTRY;
       
   110 	iTimer.Cancel();
       
   111 	TRACE_FUNC_EXIT;
       
   112 	}
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CSConBackupRestoreQueue::AddNewTask( CSConTask*& aNewTask, TInt aTaskId )
       
   116 // Adds a new task to queue
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TInt CSConBackupRestoreQueue::AddNewTask( CSConTask*& aNewTask, TInt aTaskId )
       
   120 	{
       
   121 	LOGGER_WRITE_1( "CSConBackupRestoreQueue::AddNewTask aTaskId: %d", aTaskId );
       
   122 	TInt ret( KErrNone );
       
   123 	
       
   124 	aNewTask->iTaskId = aTaskId;
       
   125 	
       
   126 	//Set progress value "task accepted for execution"
       
   127 	aNewTask->SetProgressValue( KSConCodeTaskCreated );
       
   128 	aNewTask->SetCompleteValue( EFalse );
       
   129 	
       
   130 	//For RequestData and SupplyData
       
   131 	if( iQueue.Find( aNewTask, CSConTaskQueue::Match ) != KErrNotFound )
       
   132 		{
       
   133 		RemoveTask( aTaskId );
       
   134 		}
       
   135 	
       
   136 	if( iQueue.Count() == 0 )
       
   137 		{
       
   138 		StartQueue();
       
   139 		}
       
   140 
       
   141 	ret = iQueue.InsertInOrder( aNewTask, CSConTaskQueue::Compare );
       
   142 	LOGGER_WRITE_1( "CSConBackupRestoreQueue::AddNewTask() : returned %d", ret );
       
   143 	return ret;
       
   144 	}
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CSConBackupRestoreQueue::CancelTask( TInt aTask, TBool aAllTasks )
       
   148 // Cancels a task
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CSConBackupRestoreQueue::CancelTask( TInt aTask, TBool aAllTasks )
       
   152 	{
       
   153 	TRACE_FUNC_ENTRY;
       
   154 	//Stop backup/restore
       
   155 	if( aTask && !aAllTasks )
       
   156 		{
       
   157 		LOGGER_WRITE_1("CSConBackupRestoreQueue::CancelTask - Cancel task: %d", aTask);
       
   158 		iBackupRestore->StopBackupRestore( aTask );
       
   159 		}
       
   160 	
       
   161 	if( aAllTasks )
       
   162 		{
       
   163 		LOGGER_WRITE("CSConBackupRestoreQueue::CancelTask - Cancel All");
       
   164 		iBackupRestore->Cancel();
       
   165 		iBackupRestore->Reset();
       
   166 		}
       
   167 		
       
   168 	CSConTaskQueue::CancelTask( aTask, aAllTasks );
       
   169 	TRACE_FUNC_EXIT;
       
   170 	}
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CSConBackupRestoreQueue::Reset()
       
   174 // Resets the queue
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CSConBackupRestoreQueue::Reset()
       
   178 	{
       
   179 	TRACE_FUNC_ENTRY;
       
   180 	CSConTaskQueue::Reset();
       
   181 	iBackupRestore->Reset();
       
   182 	TRACE_FUNC_EXIT;
       
   183 	}
       
   184 	
       
   185 // -----------------------------------------------------------------------------
       
   186 // CSConBackupRestoreQueue::QueueAddress( CSConInstallerQueue*& aTaskQueue )
       
   187 // An address pointer to another queue
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CSConBackupRestoreQueue::QueueAddress( CSConInstallerQueue*& aTaskQueue )
       
   191 	{
       
   192 	TRACE_FUNC;
       
   193 	iInstQueueAddress = aTaskQueue;
       
   194 	}
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CSConBackupRestoreQueue::GetTaskMethod( TInt& aTaskId )
       
   198 // Returns the task type
       
   199 // -----------------------------------------------------------------------------
       
   200 //		
       
   201 TSConMethodName CSConBackupRestoreQueue::GetTaskMethodL( TInt aTaskId )
       
   202 	{
       
   203 	TRACE_FUNC_ENTRY;
       
   204 	CSConTask* task = NULL;
       
   205 	CSConTaskQueue::GetTask( aTaskId, task );
       
   206 	LOGGER_WRITE_1( "CSConBackupRestoreQueue::GetTaskMethodL( TInt aTaskId ) : returned %d",
       
   207         task->GetServiceId() );
       
   208 	return task->GetServiceId();
       
   209 	}
       
   210 	
       
   211 // -----------------------------------------------------------------------------
       
   212 // CSConBackupRestoreQueue::PollQueue()
       
   213 // Polls queue
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CSConBackupRestoreQueue::PollQueue()
       
   217 	{
       
   218 	// find and start next task if BR and installer is inactive
       
   219 	if( !iBackupRestore->BackupRestoreActive()
       
   220 		&& !iInstQueueAddress->QueueProcessActive() )
       
   221 		{
       
   222 		//find next task
       
   223 		for( TInt i = 0; i < iQueue.Count(); i++ )
       
   224 			{
       
   225 			TBool complete = iQueue[i]->GetCompleteValue();
       
   226 			
       
   227 			if( complete == EFalse )
       
   228 				{
       
   229 				iBackupRestore->StartBackupRestore( 
       
   230 				iQueue[i]->iTaskId );
       
   231 				i = iQueue.Count() + 1; // jump out from loop
       
   232 				}
       
   233 			}
       
   234 		}
       
   235 	}
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // Implementation of CActive::DoCancel()
       
   239 // Entry to CSConPCD
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 void CSConBackupRestoreQueue::DoCancel()
       
   243 	{
       
   244 	TRACE_FUNC_ENTRY;
       
   245 	iTimer.Cancel();
       
   246 	TRACE_FUNC_EXIT;
       
   247 	}
       
   248 	
       
   249 // -----------------------------------------------------------------------------
       
   250 // Implementation of CActive::RunL()
       
   251 // Entry to CSConPCD
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 void CSConBackupRestoreQueue::RunL()
       
   255 	{
       
   256 	TRACE_FUNC_ENTRY;
       
   257 	LOGGER_WRITE_1( "There are still %d tasks in this queue", iQueue.Count() );
       
   258 	if( iQueue.Count() > 0 )
       
   259 		{
       
   260 		PollQueue();
       
   261 		StartQueue();
       
   262 		}
       
   263 	TRACE_FUNC_EXIT;
       
   264 	}
       
   265 
       
   266 // End of file