os/persistentdata/persistentstorage/sql/SRC/Server/SqlSrvDriveSpace.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Reserving/Accessing/Releasing drive space - CSqlDriveSpace and RSqlDriveSpaceCol classes declarations
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#ifndef __SQLSRVDRIVESPACE_H__
sl@0
    19
#define __SQLSRVDRIVESPACE_H__
sl@0
    20
sl@0
    21
#include <f32file.h>
sl@0
    22
sl@0
    23
//Forward declarations
sl@0
    24
class RSqlDriveSpaceCol;
sl@0
    25
class CSqlServer;
sl@0
    26
sl@0
    27
#ifdef _DEBUG
sl@0
    28
#define SQLDRIVESPACE_INVARIANT() Invariant()
sl@0
    29
#define SQLDRIVESPACECOL_INVARIANT() Invariant()
sl@0
    30
#else
sl@0
    31
#define SQLDRIVESPACE_INVARIANT() void(0)
sl@0
    32
#define SQLDRIVESPACECOL_INVARIANT() void(0)
sl@0
    33
#endif
sl@0
    34
sl@0
    35
/**
sl@0
    36
This class describes an object, which is responsible for handling
sl@0
    37
"reserve/get access/release" requests for a particular drive.
sl@0
    38
sl@0
    39
Since the drive may be shared between more than one server side session and there is only one RFs instance,
sl@0
    40
the current solution is that CSqlDriveSpace objects reserve some predefined amount of disk space
sl@0
    41
at the time of their creation and then the access to the reserved disk space is reference counted.
sl@0
    42
    There is one obvious disadvantage of this solution: if a bad application "forgets" to release
sl@0
    43
the access to the reserved disk space, then the reserved (but not released) disk space may be used by the server.
sl@0
    44
At the moment, when some client will really need the reserved disk space to complete its "delete" transaction, 
sl@0
    45
it may happen that there is no reserved disk space at all. 
sl@0
    46
sl@0
    47
@see RSqlDriveSpaceCol
sl@0
    48
@internalComponent
sl@0
    49
*/
sl@0
    50
NONSHARABLE_CLASS(CSqlDriveSpace) : public CBase
sl@0
    51
	{
sl@0
    52
public:
sl@0
    53
	static CSqlDriveSpace* NewLC(RFs& aFs, TDriveNumber aDrive);
sl@0
    54
    virtual ~CSqlDriveSpace();
sl@0
    55
	inline TDriveNumber Drive() const;
sl@0
    56
	void GetAccessL();
sl@0
    57
	void ReleaseAccess();
sl@0
    58
	void Invariant() const;
sl@0
    59
sl@0
    60
private:
sl@0
    61
	CSqlDriveSpace(RFs& aFs, TDriveNumber aDrive);
sl@0
    62
    void ConstructL();
sl@0
    63
sl@0
    64
private:
sl@0
    65
	RFs& 			iFs;               	//File session reference
sl@0
    66
	TDriveNumber 	iDrive;    			//Drive number
sl@0
    67
	TInt 			iGetAccessRefCnt;	//"Get access" requests count
sl@0
    68
sl@0
    69
	};
sl@0
    70
sl@0
    71
/**
sl@0
    72
@return The drive number, where the CSqlDriveSpace object handles the reservation requests
sl@0
    73
*/
sl@0
    74
inline TDriveNumber CSqlDriveSpace::Drive() const
sl@0
    75
    {
sl@0
    76
    return iDrive;
sl@0
    77
    }
sl@0
    78
sl@0
    79
/**
sl@0
    80
This class describes a collection of CSqlDriveSpace objects. Each CSqlDriveSpace object in the
sl@0
    81
collection is responsible for handling "reserve/get access/release" requests for a particular
sl@0
    82
drive.
sl@0
    83
sl@0
    84
Only one RSqlDriveSpaceCol instance should be created (resp. destroyed) by the CSqlServer object.
sl@0
    85
sl@0
    86
@see CSqlServer
sl@0
    87
@see CSqlDriveSpace
sl@0
    88
sl@0
    89
@internalComponent
sl@0
    90
*/
sl@0
    91
NONSHARABLE_CLASS(RSqlDriveSpaceCol)
sl@0
    92
	{
sl@0
    93
public:
sl@0
    94
	RSqlDriveSpaceCol();
sl@0
    95
	void Create(RFs& aFs);
sl@0
    96
	void ResetAndDestroy();
sl@0
    97
    CSqlDriveSpace* Find(TDriveNumber aDrive);
sl@0
    98
    CSqlDriveSpace* AddL(TDriveNumber aDrive);
sl@0
    99
	void Invariant() const;
sl@0
   100
sl@0
   101
private:
sl@0
   102
	RFs*				        	iFs;            //File session reference
sl@0
   103
	RPointerArray<CSqlDriveSpace>	iDriveSpaceCol; //Collection of CSqlDriveSpace objects: one per drive
sl@0
   104
sl@0
   105
	};
sl@0
   106
sl@0
   107
#endif//__SQLSRVDRIVESPACE_H__