First public contribution.
1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "SqlCompactTimer.h"
17 #include "SqlAssert.h"
18 #include "SqlCompactEntry.h"
19 #include "OstTraceDefinitions.h"
20 #ifdef OST_TRACE_COMPILER_IN_USE
21 #include "SqlCompactTimerTraces.h"
23 #include "SqlTraceDef.h"
26 Creates new CSqlCompactTimer instance.
28 @param aIntervalMs The timer intrerval (ms).
30 @panic SqlDb 4 In _DEBUG mode. Zero or negative aIntervalMs.
32 CSqlCompactTimer* CSqlCompactTimer::NewL(TInt aIntervalMs)
34 SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_NEWL_ENTRY, "Entry;0;CSqlCompactTimer::NewL;aIntervalMs=%d", aIntervalMs));
35 __ASSERT_DEBUG(aIntervalMs > 0, __SQLPANIC2(ESqlPanicBadArgument));
36 CSqlCompactTimer* self = new (ELeave) CSqlCompactTimer(aIntervalMs);
37 CleanupStack::PushL(self);
39 CleanupStack::Pop(self);
40 SQL_TRACE_COMPACT(OstTraceExt2(TRACE_INTERNALS, CSQLCOMPACTTIMER_NEWL_EXIT, "Exit;0x%X;CSqlCompactTimer::NewL;aIntervalMs=%d", (TUint)self, aIntervalMs));
47 CSqlCompactTimer::~CSqlCompactTimer()
49 SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_CSQLCOMPACTTIMER2, "0x%X;CSqlCompactTimer::~CSqlCompactTimer", (TUint)this));
54 If the queue is not empty, the timer will be restarted.
56 void CSqlCompactTimer::Restart()
58 SQLCOMPACTTIMER_INVARIANT();
62 After(iIntervalMicroSec);
64 SQLCOMPACTTIMER_INVARIANT();
68 Adds a database entry, that requires a background compaction, to the queue.
70 @param aEntry The database entry to be compacted.
74 void CSqlCompactTimer::Queue(CSqlCompactEntry& aEntry)
76 SQL_TRACE_COMPACT(OstTraceExt3(TRACE_INTERNALS, CSQLCOMPACTTIMER_QUEUE, "0x%X;CSqlCompactTimer::Queue;aEntry=0x%X;Name=%S", (TUint)this, (TUint)&aEntry,__SQLPRNSTR(aEntry.FullName())));
77 SQLCOMPACTTIMER_INVARIANT();
78 iQueue.AddFirst(aEntry);
81 After(iIntervalMicroSec);
83 SQLCOMPACTTIMER_INVARIANT();
87 Removes the specified database entry from the queue.
89 @param aEntry The database entry to be removed from the queue.
93 void CSqlCompactTimer::DeQueue(CSqlCompactEntry& aEntry)
95 SQL_TRACE_COMPACT(OstTraceExt2(TRACE_INTERNALS, CSQLCOMPACTTIMER_DEQUEUE, "0x%X;CSqlCompactTimer::DeQueue;aEntry=0x%X", (TUint)this, (TUint)&aEntry));
96 SQLCOMPACTTIMER_INVARIANT();
97 iQueue.Remove(aEntry);
102 SQLCOMPACTTIMER_INVARIANT();
106 Initializes the CSqlCompactTimer instance.
108 @param aIntervalMs The timer intrerval (ms).
110 @panic SqlDb 4 In _DEBUG mode. Zero or negative aIntervalMs.
112 CSqlCompactTimer::CSqlCompactTimer(TInt aIntervalMs) :
113 CTimer(CActive::EPriorityIdle),
114 iIntervalMicroSec(aIntervalMs * 1000),
115 iQueue(_FOFF(CSqlCompactEntry, iLink))
117 __ASSERT_DEBUG(aIntervalMs > 0, __SQLPANIC(ESqlPanicBadArgument));
121 Initializes the created CSqlCompactTimer instance.
123 void CSqlCompactTimer::ConstructL()
125 CTimer::ConstructL();
126 CActiveScheduler::Add(this);
127 SQLCOMPACTTIMER_INVARIANT();
131 CActive::RunL() implementation.
132 The RunL() implementation picks-up the last CSqlCompactEntry object from the queue and calls its Compact() method.
133 At the end of the call, if the queue is not empty (CSqlCompactEntry::Compact() may remove the object from the queue if
134 the compaction has been completed), the timer will be reactivated.
136 @panic SqlDb 7 The queue is empty.
137 @panic SqlDb 7 In _DEBUG mode. The last entry in the queue is NULL.
139 void CSqlCompactTimer::RunL()
141 SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_RUNL, "0x%X;CSqlCompactTimer::RunL", (TUint)this));
142 SQLCOMPACTTIMER_INVARIANT();
143 __ASSERT_ALWAYS(!iQueue.IsEmpty(), __SQLPANIC(ESqlPanicInternalError));
144 CSqlCompactEntry* entry = iQueue.Last();
145 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()));
146 __ASSERT_DEBUG(entry, __SQLPANIC(ESqlPanicInternalError));
147 (void)entry->Compact();
148 if(!iQueue.IsEmpty())
150 After(iIntervalMicroSec);
152 SQLCOMPACTTIMER_INVARIANT();
157 CSqlCompactTimer invariant.
159 void CSqlCompactTimer::Invariant() const
161 __ASSERT_DEBUG(iIntervalMicroSec > 0, __SQLPANIC(ESqlPanicInternalError));
162 if(!iQueue.IsEmpty())
164 CSqlCompactEntry* entry = iQueue.Last();
165 __ASSERT_DEBUG(entry != NULL, __SQLPANIC(ESqlPanicInternalError));