1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sql/SRC/Server/Compact/SqlCompact.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,187 @@
1.4 +/**
1.5 +* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* The main header file of the background compaction framework.
1.19 +* Includes the declarations of the following classes:
1.20 +* The CSqlCompactor is the main class controlling the background compaction.
1.21 +* Only one instance of that class should be created by the server.
1.22 +* The CSqlCompactor single instance manages a set of reference counted per-database entries and a CTimer compaction object.
1.23 +* The MSqlCompactConn interface acts as an abstraction layer between the compaction entries and the
1.24 +* real object with member functions that are used to perform the compaction.
1.25 +*
1.26 +*
1.27 +*/
1.28 +
1.29 +
1.30 +
1.31 +/**
1.32 + @file
1.33 + @see MSqlCompactConn
1.34 + @see CSqlCompactor
1.35 +*/
1.36 +#ifndef SQLCOMPACT_H
1.37 +#define SQLCOMPACT_H
1.38 +
1.39 +#include <e32base.h>
1.40 +
1.41 +//Forward declarations
1.42 +class CSqlCompactEntry;
1.43 +class CSqlCompactTimer;
1.44 +struct TSqlFreePageCallback;
1.45 +//A test class that has a direct access to all data members and functions of the background compaction framework classes
1.46 +class CSqlCompactTestActive;
1.47 +
1.48 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.49 +////////////////////////////// TSqlCompactSettings structure declaration //////////////////////////
1.50 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.51 +
1.52 +#ifdef _DEBUG
1.53 +#define SQLCOMPACTSETTINGS_INVARIANT() Invariant()
1.54 +#else
1.55 +#define SQLCOMPACTSETTINGS_INVARIANT() void(0)
1.56 +#endif
1.57 +
1.58 +/**
1.59 +Per-database background compaction settings/thresholds.
1.60 +They are:
1.61 +@code
1.62 + - The compaction step length in milliseconds;
1.63 + - The free pages threshold - the background compaction should be kicked-off if the free space in the free pages is
1.64 + above this threshold (in Kb);
1.65 +@endcode
1.66 +
1.67 +@internalComponent
1.68 +*/
1.69 +NONSHARABLE_STRUCT(TSqlCompactSettings)
1.70 + {
1.71 + TSqlCompactSettings();
1.72 + void Invariant() const;
1.73 +
1.74 + TInt iStepLength;
1.75 + TInt iFreePageThresholdKb;
1.76 + };
1.77 +
1.78 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.79 +////////////////////////////// MSqlCompactConn interface declaration //////////////////////////////
1.80 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.81 +
1.82 +/**
1.83 +The background compaction connection interface.
1.84 +The interface separates the CSqlCompactor entries from the object which does the compaction.
1.85 +The MSqlCompactConn interface exposes minimal set of methods needed to perform a compaction:
1.86 + - MSqlCompactConn::Compact(TInt aPageCount, TInt& aProcessedPageCount);
1.87 +
1.88 +As the interface name suffix ("Conn") suggests, the interface creates and maintains a
1.89 +connection with the database to be compacted.
1.90 +
1.91 +Interface creation:
1.92 + The TSqlCompactConnFactoryL() factory function should be used for that.
1.93 +
1.94 +Interface destruction:
1.95 + The MSqlCompactConn offers a Release() function for that.
1.96 +
1.97 +@see CSqlCompactor
1.98 +@see TSqlCompactConnFactoryL
1.99 +
1.100 +@internalComponent
1.101 +*/
1.102 +NONSHARABLE_CLASS(MSqlCompactConn)
1.103 + {
1.104 + friend class CSqlCompactTestActive;
1.105 +
1.106 +public:
1.107 + virtual void Release() = 0;
1.108 + virtual TInt Compact(TInt aPageCount, TInt& aProcessedPageCount, TInt aLength) = 0;
1.109 +
1.110 + };
1.111 +
1.112 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.113 +/////////////////// MSqlCompactConn factory function type declaration /////////////////////////////
1.114 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.115 +
1.116 +/**
1.117 +MSqlCompactConn interface - factory function type definition.
1.118 +
1.119 +@param aFullName The full name of the database to be compacted (including the path).
1.120 +@param aFreePageCallback Input/Output parameter. Object containing the free page callback parameters.
1.121 + aFreePageCallback.iThreshold must be set to be in Kb.
1.122 + If the function call completes successfully and the free pages space is above the threshold,
1.123 + the aFreePageCallback.iThreshold will be set to contain the free pages count.
1.124 + Otherwise aFreePageCallback.iThreshold will be initialized with zero.
1.125 +
1.126 +@return A pointer to the created MSqlCompactConn interface.
1.127 +
1.128 +@leave KErrNoMemory, an out of memory condition has occurred,
1.129 + KErrArgument, invalid data in the aFreePageCallback object;
1.130 + Note that the function may also leave with some other database specific
1.131 + errors categorised as ESqlDbError, and other system-wide error codes.
1.132 +
1.133 +@see MSqlCompactConn
1.134 +
1.135 +@internalComponent
1.136 +*/
1.137 +typedef MSqlCompactConn* (*TSqlCompactConnFactoryL)(const TDesC& aFullName, TSqlFreePageCallback& aFreePageCallback);
1.138 +
1.139 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.140 +////////////////////////////// CSqlCompactor class declaration ////////////////////////////////////
1.141 +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.142 +
1.143 +#ifdef _DEBUG
1.144 +#define SQLCOMPACTOR_INVARIANT() Invariant()
1.145 +#else
1.146 +#define SQLCOMPACTOR_INVARIANT() void(0)
1.147 +#endif
1.148 +
1.149 +/**
1.150 +The main class of the background compaction framework, that acts as a container of reference counted
1.151 +per-database entries.
1.152 +Only one instance of this class should be created by the SQL server.
1.153 +Using the CSqlCompactor instance:
1.154 + - A new background compaction entry can be added to the container - the CSqlCompactor::AddEntryL() method.
1.155 + If an entry with the same name does exist, no new entry is created, the reference counter of the existing one
1.156 + is incremented;
1.157 + - An existing background compaction entry can be removed from the container with CSqlCompactor::ReleaseEntry().
1.158 + The entry is reference-counted and when the reference counter reaches 0, the entry will be removed from the container;
1.159 +
1.160 +@see MSqlCompactConn
1.161 +
1.162 +@internalComponent
1.163 +*/
1.164 +NONSHARABLE_CLASS(CSqlCompactor) : public CBase
1.165 + {
1.166 + friend class CSqlCompactTestActive;
1.167 +
1.168 +public:
1.169 + static CSqlCompactor* NewL(TSqlCompactConnFactoryL aConnFactoryL, TInt aCompactStepInterval);
1.170 + virtual ~CSqlCompactor();
1.171 + void RestartTimer();
1.172 + void AddEntryL(const TDesC& aFullName, const TSqlCompactSettings& aSettings);
1.173 + void ReleaseEntry(const TDesC& aFullName);
1.174 + void Invariant() const;
1.175 +
1.176 +private:
1.177 + CSqlCompactor(TSqlCompactConnFactoryL aConnFactoryL);
1.178 + void ConstructL(TInt aCompactStepInterval);
1.179 + static TInt Search(const TDesC* aFullName, const CSqlCompactEntry& aEntry);
1.180 + static TInt Compare(const CSqlCompactEntry& aLeft, const CSqlCompactEntry& aRight);
1.181 +
1.182 +private:
1.183 + TSqlCompactConnFactoryL iConnFactoryL;
1.184 + CSqlCompactTimer* iTimer;
1.185 + typedef RPointerArray<CSqlCompactEntry> RCompactEntryArray;
1.186 + RCompactEntryArray iEntries;
1.187 +
1.188 + };
1.189 +
1.190 +#endif//SQLCOMPACT_H