First public contribution.
2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * The main header file of the background compaction framework.
16 * Includes the declarations of the following classes:
17 * The CSqlCompactor is the main class controlling the background compaction.
18 * Only one instance of that class should be created by the server.
19 * The CSqlCompactor single instance manages a set of reference counted per-database entries and a CTimer compaction object.
20 * The MSqlCompactConn interface acts as an abstraction layer between the compaction entries and the
21 * real object with member functions that are used to perform the compaction.
38 //Forward declarations
39 class CSqlCompactEntry;
40 class CSqlCompactTimer;
41 struct TSqlFreePageCallback;
42 //A test class that has a direct access to all data members and functions of the background compaction framework classes
43 class CSqlCompactTestActive;
45 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
46 ////////////////////////////// TSqlCompactSettings structure declaration //////////////////////////
47 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50 #define SQLCOMPACTSETTINGS_INVARIANT() Invariant()
52 #define SQLCOMPACTSETTINGS_INVARIANT() void(0)
56 Per-database background compaction settings/thresholds.
59 - The compaction step length in milliseconds;
60 - The free pages threshold - the background compaction should be kicked-off if the free space in the free pages is
61 above this threshold (in Kb);
66 NONSHARABLE_STRUCT(TSqlCompactSettings)
68 TSqlCompactSettings();
69 void Invariant() const;
72 TInt iFreePageThresholdKb;
75 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ////////////////////////////// MSqlCompactConn interface declaration //////////////////////////////
77 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
80 The background compaction connection interface.
81 The interface separates the CSqlCompactor entries from the object which does the compaction.
82 The MSqlCompactConn interface exposes minimal set of methods needed to perform a compaction:
83 - MSqlCompactConn::Compact(TInt aPageCount, TInt& aProcessedPageCount);
85 As the interface name suffix ("Conn") suggests, the interface creates and maintains a
86 connection with the database to be compacted.
89 The TSqlCompactConnFactoryL() factory function should be used for that.
91 Interface destruction:
92 The MSqlCompactConn offers a Release() function for that.
95 @see TSqlCompactConnFactoryL
99 NONSHARABLE_CLASS(MSqlCompactConn)
101 friend class CSqlCompactTestActive;
104 virtual void Release() = 0;
105 virtual TInt Compact(TInt aPageCount, TInt& aProcessedPageCount, TInt aLength) = 0;
109 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110 /////////////////// MSqlCompactConn factory function type declaration /////////////////////////////
111 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
114 MSqlCompactConn interface - factory function type definition.
116 @param aFullName The full name of the database to be compacted (including the path).
117 @param aFreePageCallback Input/Output parameter. Object containing the free page callback parameters.
118 aFreePageCallback.iThreshold must be set to be in Kb.
119 If the function call completes successfully and the free pages space is above the threshold,
120 the aFreePageCallback.iThreshold will be set to contain the free pages count.
121 Otherwise aFreePageCallback.iThreshold will be initialized with zero.
123 @return A pointer to the created MSqlCompactConn interface.
125 @leave KErrNoMemory, an out of memory condition has occurred,
126 KErrArgument, invalid data in the aFreePageCallback object;
127 Note that the function may also leave with some other database specific
128 errors categorised as ESqlDbError, and other system-wide error codes.
134 typedef MSqlCompactConn* (*TSqlCompactConnFactoryL)(const TDesC& aFullName, TSqlFreePageCallback& aFreePageCallback);
136 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
137 ////////////////////////////// CSqlCompactor class declaration ////////////////////////////////////
138 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
141 #define SQLCOMPACTOR_INVARIANT() Invariant()
143 #define SQLCOMPACTOR_INVARIANT() void(0)
147 The main class of the background compaction framework, that acts as a container of reference counted
148 per-database entries.
149 Only one instance of this class should be created by the SQL server.
150 Using the CSqlCompactor instance:
151 - A new background compaction entry can be added to the container - the CSqlCompactor::AddEntryL() method.
152 If an entry with the same name does exist, no new entry is created, the reference counter of the existing one
154 - An existing background compaction entry can be removed from the container with CSqlCompactor::ReleaseEntry().
155 The entry is reference-counted and when the reference counter reaches 0, the entry will be removed from the container;
161 NONSHARABLE_CLASS(CSqlCompactor) : public CBase
163 friend class CSqlCompactTestActive;
166 static CSqlCompactor* NewL(TSqlCompactConnFactoryL aConnFactoryL, TInt aCompactStepInterval);
167 virtual ~CSqlCompactor();
169 void AddEntryL(const TDesC& aFullName, const TSqlCompactSettings& aSettings);
170 void ReleaseEntry(const TDesC& aFullName);
171 void Invariant() const;
174 CSqlCompactor(TSqlCompactConnFactoryL aConnFactoryL);
175 void ConstructL(TInt aCompactStepInterval);
176 static TInt Search(const TDesC* aFullName, const CSqlCompactEntry& aEntry);
177 static TInt Compare(const CSqlCompactEntry& aLeft, const CSqlCompactEntry& aRight);
180 TSqlCompactConnFactoryL iConnFactoryL;
181 CSqlCompactTimer* iTimer;
182 typedef RPointerArray<CSqlCompactEntry> RCompactEntryArray;
183 RCompactEntryArray iEntries;