1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sql/SRC/Server/Compact/SqlCompactTimer.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,168 @@
1.4 +// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "SqlCompactTimer.h"
1.20 +#include "SqlAssert.h"
1.21 +#include "SqlCompactEntry.h"
1.22 +#include "OstTraceDefinitions.h"
1.23 +#ifdef OST_TRACE_COMPILER_IN_USE
1.24 +#include "SqlCompactTimerTraces.h"
1.25 +#endif
1.26 +#include "SqlTraceDef.h"
1.27 +
1.28 +/**
1.29 +Creates new CSqlCompactTimer instance.
1.30 +
1.31 +@param aIntervalMs The timer intrerval (ms).
1.32 +
1.33 +@panic SqlDb 4 In _DEBUG mode. Zero or negative aIntervalMs.
1.34 +*/
1.35 +CSqlCompactTimer* CSqlCompactTimer::NewL(TInt aIntervalMs)
1.36 + {
1.37 + SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_NEWL_ENTRY, "Entry;0;CSqlCompactTimer::NewL;aIntervalMs=%d", aIntervalMs));
1.38 + __ASSERT_DEBUG(aIntervalMs > 0, __SQLPANIC2(ESqlPanicBadArgument));
1.39 + CSqlCompactTimer* self = new (ELeave) CSqlCompactTimer(aIntervalMs);
1.40 + CleanupStack::PushL(self);
1.41 + self->ConstructL();
1.42 + CleanupStack::Pop(self);
1.43 + SQL_TRACE_COMPACT(OstTraceExt2(TRACE_INTERNALS, CSQLCOMPACTTIMER_NEWL_EXIT, "Exit;0x%X;CSqlCompactTimer::NewL;aIntervalMs=%d", (TUint)self, aIntervalMs));
1.44 + return self;
1.45 + }
1.46 +
1.47 +/**
1.48 +Destroys the object.
1.49 +*/
1.50 +CSqlCompactTimer::~CSqlCompactTimer()
1.51 + {
1.52 + SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_CSQLCOMPACTTIMER2, "0x%X;CSqlCompactTimer::~CSqlCompactTimer", (TUint)this));
1.53 + Cancel();
1.54 + }
1.55 +
1.56 +/**
1.57 +If the queue is not empty, the timer will be restarted.
1.58 +*/
1.59 +void CSqlCompactTimer::Restart()
1.60 + {
1.61 + SQLCOMPACTTIMER_INVARIANT();
1.62 + if(!iQueue.IsEmpty())
1.63 + {
1.64 + Cancel();
1.65 + After(iIntervalMicroSec);
1.66 + }
1.67 + SQLCOMPACTTIMER_INVARIANT();
1.68 + }
1.69 +
1.70 +/**
1.71 +Adds a database entry, that requires a background compaction, to the queue.
1.72 +
1.73 +@param aEntry The database entry to be compacted.
1.74 +
1.75 +@see CSqlCompactEntry
1.76 +*/
1.77 +void CSqlCompactTimer::Queue(CSqlCompactEntry& aEntry)
1.78 + {
1.79 + SQL_TRACE_COMPACT(OstTraceExt3(TRACE_INTERNALS, CSQLCOMPACTTIMER_QUEUE, "0x%X;CSqlCompactTimer::Queue;aEntry=0x%X;Name=%S", (TUint)this, (TUint)&aEntry,__SQLPRNSTR(aEntry.FullName())));
1.80 + SQLCOMPACTTIMER_INVARIANT();
1.81 + iQueue.AddFirst(aEntry);
1.82 + if(!IsActive())
1.83 + {
1.84 + After(iIntervalMicroSec);
1.85 + }
1.86 + SQLCOMPACTTIMER_INVARIANT();
1.87 + }
1.88 +
1.89 +/**
1.90 +Removes the specified database entry from the queue.
1.91 +
1.92 +@param aEntry The database entry to be removed from the queue.
1.93 +
1.94 +@see CSqlCompactEntry
1.95 +*/
1.96 +void CSqlCompactTimer::DeQueue(CSqlCompactEntry& aEntry)
1.97 + {
1.98 + SQL_TRACE_COMPACT(OstTraceExt2(TRACE_INTERNALS, CSQLCOMPACTTIMER_DEQUEUE, "0x%X;CSqlCompactTimer::DeQueue;aEntry=0x%X", (TUint)this, (TUint)&aEntry));
1.99 + SQLCOMPACTTIMER_INVARIANT();
1.100 + iQueue.Remove(aEntry);
1.101 + if(iQueue.IsEmpty())
1.102 + {
1.103 + Cancel();
1.104 + }
1.105 + SQLCOMPACTTIMER_INVARIANT();
1.106 + }
1.107 +
1.108 +/**
1.109 +Initializes the CSqlCompactTimer instance.
1.110 +
1.111 +@param aIntervalMs The timer intrerval (ms).
1.112 +
1.113 +@panic SqlDb 4 In _DEBUG mode. Zero or negative aIntervalMs.
1.114 +*/
1.115 +CSqlCompactTimer::CSqlCompactTimer(TInt aIntervalMs) :
1.116 + CTimer(CActive::EPriorityIdle),
1.117 + iIntervalMicroSec(aIntervalMs * 1000),
1.118 + iQueue(_FOFF(CSqlCompactEntry, iLink))
1.119 + {
1.120 + __ASSERT_DEBUG(aIntervalMs > 0, __SQLPANIC(ESqlPanicBadArgument));
1.121 + }
1.122 +
1.123 +/**
1.124 +Initializes the created CSqlCompactTimer instance.
1.125 +*/
1.126 +void CSqlCompactTimer::ConstructL()
1.127 + {
1.128 + CTimer::ConstructL();
1.129 + CActiveScheduler::Add(this);
1.130 + SQLCOMPACTTIMER_INVARIANT();
1.131 + }
1.132 +
1.133 +/**
1.134 +CActive::RunL() implementation.
1.135 +The RunL() implementation picks-up the last CSqlCompactEntry object from the queue and calls its Compact() method.
1.136 +At the end of the call, if the queue is not empty (CSqlCompactEntry::Compact() may remove the object from the queue if
1.137 +the compaction has been completed), the timer will be reactivated.
1.138 +
1.139 +@panic SqlDb 7 The queue is empty.
1.140 +@panic SqlDb 7 In _DEBUG mode. The last entry in the queue is NULL.
1.141 +*/
1.142 +void CSqlCompactTimer::RunL()
1.143 + {
1.144 + SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_RUNL, "0x%X;CSqlCompactTimer::RunL", (TUint)this));
1.145 + SQLCOMPACTTIMER_INVARIANT();
1.146 + __ASSERT_ALWAYS(!iQueue.IsEmpty(), __SQLPANIC(ESqlPanicInternalError));
1.147 + CSqlCompactEntry* entry = iQueue.Last();
1.148 + SQL_TRACE_COMPACT(OstTraceExt4(TRACE_INTERNALS, CSQLCOMPACTTIMER_RUNL2, "0x%X;CSqlCompactTimer::RunL;Compact;entry=0x%X;Name=%S;iQueue.IsEmpty()=%d", (TUint)this, (TUint)entry,__SQLPRNSTR(entry->FullName()), (TInt)iQueue.IsEmpty()));
1.149 + __ASSERT_DEBUG(entry, __SQLPANIC(ESqlPanicInternalError));
1.150 + (void)entry->Compact();
1.151 + if(!iQueue.IsEmpty())
1.152 + {
1.153 + After(iIntervalMicroSec);
1.154 + }
1.155 + SQLCOMPACTTIMER_INVARIANT();
1.156 + }
1.157 +
1.158 +#ifdef _DEBUG
1.159 +/**
1.160 +CSqlCompactTimer invariant.
1.161 +*/
1.162 +void CSqlCompactTimer::Invariant() const
1.163 + {
1.164 + __ASSERT_DEBUG(iIntervalMicroSec > 0, __SQLPANIC(ESqlPanicInternalError));
1.165 + if(!iQueue.IsEmpty())
1.166 + {
1.167 + CSqlCompactEntry* entry = iQueue.Last();
1.168 + __ASSERT_DEBUG(entry != NULL, __SQLPANIC(ESqlPanicInternalError));
1.169 + }
1.170 + }
1.171 +#endif//_DEBUG