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