os/persistentdata/persistentstorage/dbms/sdbms/Sd_DriveSpace.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/dbms/sdbms/Sd_DriveSpace.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,156 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Reserving/Accessing/Releasing drive space - CDriveSpace, RDriveSpaceCol, CDbsSessDriveSpace
    1.18 +// classes declarations
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#ifndef __SD_DRIVESPACE_H__
    1.23 +#define __SD_DRIVESPACE_H__
    1.24 +
    1.25 +#include <f32file.h>
    1.26 +
    1.27 +//Forward declarations
    1.28 +class RDriveSpaceCol;
    1.29 +class CDbsSessDriveSpace;
    1.30 +class CDbsServer;
    1.31 +
    1.32 +/**
    1.33 +This class describes an object, which is responsible for handling
    1.34 +"reserve/get access/release" requests for a particular drive.
    1.35 +Since the drive is shared between many DBMS sessions and there is only one RFs instance,
    1.36 +the current solution is that CDriveSpace objects reserve some predefined amount of disk space
    1.37 +at the time of their creation and then the access to the reserved disk space is reference counted.
    1.38 +There is one obvious disadvantage of this solution: if a bad application "forgets" to release
    1.39 +the access to the reserved disk space, it may be used by the DBMS file session and at the moment,
    1.40 +when some client will really need it to complete its "delete" transaction, it may happen that
    1.41 +there is no reserved disk space at all, because it is already used. But I don't think there
    1.42 +is an acceptable solution for this case, if there is only one shared file session.
    1.43 +The class shall not be used directly, that's the reason its constructor and NewLC() are private.
    1.44 +The class functionality shall be used by the controlling collection object - RDriveSpaceCol.
    1.45 +@internalComponent
    1.46 +*/
    1.47 +NONSHARABLE_CLASS(CDriveSpace) : public CBase
    1.48 +	{
    1.49 +	friend class RDriveSpaceCol;
    1.50 +
    1.51 +public:
    1.52 +	inline TDriveNumber Drive() const;
    1.53 +	void GrantAccessL();
    1.54 +	void ReleaseAccess();
    1.55 +
    1.56 +private:
    1.57 +	static CDriveSpace* NewLC(RFs& aFs, TDriveNumber aDrive);
    1.58 +	CDriveSpace(RFs& aFs, TDriveNumber aDrive);
    1.59 +    virtual ~CDriveSpace();
    1.60 +    void ConstructL();
    1.61 +
    1.62 +private:
    1.63 +	RFs& iFs;               //File session reference
    1.64 +	TDriveNumber iDrive;    //Drive number
    1.65 +	TInt iGrantAccessRefCnt;//"Get access" requests count
    1.66 +
    1.67 +	};
    1.68 +
    1.69 +/**
    1.70 +@return The drive number, where the CDriveSpace object handles the reservation requests
    1.71 +*/
    1.72 +inline TDriveNumber CDriveSpace::Drive() const
    1.73 +    {
    1.74 +    return iDrive;
    1.75 +    }
    1.76 +
    1.77 +/**
    1.78 +This class describes a collection of CDriveSpace objects. Each CDriveSpace object in the
    1.79 +collection is responsible for handling "reserve/get access/release" requests for a particular
    1.80 +drive.
    1.81 +Only one instace of RDriveSpaceCol class should be created and used in the DBMS server.
    1.82 +An object of this class shall be created by the DBMS server, but the DBMS server is alloved only
    1.83 +to close (destroy) it at the end. RDriveSpaceCol collection shall be used by CDbsSessDriveSpace
    1.84 +instances, which shall be created/used/destroyed by the DBMS sessions.
    1.85 +@see CDriveSpace
    1.86 +@internalComponent
    1.87 +*/
    1.88 +class RDriveSpaceCol
    1.89 +	{
    1.90 +    friend class CDbsServer;
    1.91 +    friend class CDbsSessDriveSpace;
    1.92 +
    1.93 +private:
    1.94 +	RDriveSpaceCol(RFs& aFs);
    1.95 +	void Close();
    1.96 +    CDriveSpace* Find(TDriveNumber aDrive);
    1.97 +    CDriveSpace* CreateAddL(TDriveNumber aDrive);
    1.98 +
    1.99 +private:
   1.100 +	RFs&				        iFs;            //File session reference
   1.101 +	RPointerArray<CDriveSpace>	iDriveSpaceCol; //Collection of CDriveSpace objects: one per drive
   1.102 +
   1.103 +	};
   1.104 +
   1.105 +/**
   1.106 +This structure describes an object, which handles all disk space related requests per
   1.107 +DBMS session instance.
   1.108 +Using it, the DBMS session can control the access to the reserved drive space for a 
   1.109 +particular drive(s).
   1.110 +Although it seems a good idea to save some binary code space and use directly CDriveSpace and
   1.111 +RDriveSpaceCol classes - no, it is not that good.
   1.112 +If you use directly CDriveSpace and RDriveSpaceCol, you have to control that every "Reserve"
   1.113 +call is matched by a "Free" call and every "Get/GrantAcces" call is matched by a "ReleaseAccess"
   1.114 +call. Also you have to take care about checking that the appropriate CDriveSpace object has
   1.115 +been created already or if not - you have to create and add it to the RDriveSpaceCol colelction.
   1.116 +All that is done in CDbsSessDriveSpace class.
   1.117 +@internalComponent
   1.118 +*/
   1.119 +NONSHARABLE_CLASS(CDbsSessDriveSpace) : public CBase
   1.120 +    {
   1.121 +private:
   1.122 +    /**
   1.123 +    This structure describes the state of the disk space reservation requests, related to a 
   1.124 +    particular drive. It holds an information like: drive number, was the disk space 
   1.125 +    already reserved?, was an access to it already granted?
   1.126 +    Using the TDriveSpaceRq objects, the caller can ensure that every "Reserve" call is
   1.127 +    matched by a "Free" call, every "GetAccess" call is matched by a "ReleaseAccess" call.
   1.128 +    @internalComponent
   1.129 +    */
   1.130 +    struct TDriveSpaceRq
   1.131 +	    {
   1.132 +        TDriveSpaceRq(CDriveSpace& aDriveSpace);
   1.133 +	    CDriveSpace&    iDriveSpace;        //This object will handle the reservation requests
   1.134 +        TUint8	        iReserved:		1;  //If non-zero then the space was already reserved
   1.135 +        TUint8	        iAccessGranted: 1;  //If non-zero then an access to the space was already granted
   1.136 +	    };
   1.137 +
   1.138 +public:
   1.139 +    static CDbsSessDriveSpace* NewL(RDriveSpaceCol& aDriveSpaceCol);
   1.140 +    virtual ~CDbsSessDriveSpace();
   1.141 +
   1.142 +    void ReserveL(TDriveNumber aDrive);
   1.143 +    void Free(TDriveNumber aDrive);
   1.144 +	void GrantAccessL(TDriveNumber aDrive);
   1.145 +	void ReleaseAccess(TDriveNumber aDrive);
   1.146 +
   1.147 +private:
   1.148 +    CDbsSessDriveSpace(RDriveSpaceCol& aDriveSpaceCol);
   1.149 +    TDriveSpaceRq* Find(TDriveNumber aDrive);
   1.150 +    TDriveSpaceRq& CreateAddL(TDriveNumber aDrive);
   1.151 +    TDriveSpaceRq& GetL(TDriveNumber aDrive);
   1.152 +
   1.153 +private:
   1.154 +    RDriveSpaceCol&         iDriveSpaceCol;//Reference to the RDriveSpaceCol colelction.
   1.155 +    RArray<TDriveSpaceRq>   iDriveSpaceRqCol;//Collection of TDriveSpaceRq objects: one per drive
   1.156 +
   1.157 +    };
   1.158 +
   1.159 +#endif//__SD_DRIVESPACE_H__