persistentstorage/dbms/sdbms/Sd_DriveSpace.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 - CDriveSpace, RDriveSpaceCol, CDbsSessDriveSpace
       
    15 // classes declarations
       
    16 // 
       
    17 //
       
    18 
       
    19 #ifndef __SD_DRIVESPACE_H__
       
    20 #define __SD_DRIVESPACE_H__
       
    21 
       
    22 #include <f32file.h>
       
    23 
       
    24 //Forward declarations
       
    25 class RDriveSpaceCol;
       
    26 class CDbsSessDriveSpace;
       
    27 class CDbsServer;
       
    28 
       
    29 /**
       
    30 This class describes an object, which is responsible for handling
       
    31 "reserve/get access/release" requests for a particular drive.
       
    32 Since the drive is shared between many DBMS sessions and there is only one RFs instance,
       
    33 the current solution is that CDriveSpace objects reserve some predefined amount of disk space
       
    34 at the time of their creation and then the access to the reserved disk space is reference counted.
       
    35 There is one obvious disadvantage of this solution: if a bad application "forgets" to release
       
    36 the access to the reserved disk space, it may be used by the DBMS file session and at the moment,
       
    37 when some client will really need it to complete its "delete" transaction, it may happen that
       
    38 there is no reserved disk space at all, because it is already used. But I don't think there
       
    39 is an acceptable solution for this case, if there is only one shared file session.
       
    40 The class shall not be used directly, that's the reason its constructor and NewLC() are private.
       
    41 The class functionality shall be used by the controlling collection object - RDriveSpaceCol.
       
    42 @internalComponent
       
    43 */
       
    44 NONSHARABLE_CLASS(CDriveSpace) : public CBase
       
    45 	{
       
    46 	friend class RDriveSpaceCol;
       
    47 
       
    48 public:
       
    49 	inline TDriveNumber Drive() const;
       
    50 	void GrantAccessL();
       
    51 	void ReleaseAccess();
       
    52 
       
    53 private:
       
    54 	static CDriveSpace* NewLC(RFs& aFs, TDriveNumber aDrive);
       
    55 	CDriveSpace(RFs& aFs, TDriveNumber aDrive);
       
    56     virtual ~CDriveSpace();
       
    57     void ConstructL();
       
    58 
       
    59 private:
       
    60 	RFs& iFs;               //File session reference
       
    61 	TDriveNumber iDrive;    //Drive number
       
    62 	TInt iGrantAccessRefCnt;//"Get access" requests count
       
    63 
       
    64 	};
       
    65 
       
    66 /**
       
    67 @return The drive number, where the CDriveSpace object handles the reservation requests
       
    68 */
       
    69 inline TDriveNumber CDriveSpace::Drive() const
       
    70     {
       
    71     return iDrive;
       
    72     }
       
    73 
       
    74 /**
       
    75 This class describes a collection of CDriveSpace objects. Each CDriveSpace object in the
       
    76 collection is responsible for handling "reserve/get access/release" requests for a particular
       
    77 drive.
       
    78 Only one instace of RDriveSpaceCol class should be created and used in the DBMS server.
       
    79 An object of this class shall be created by the DBMS server, but the DBMS server is alloved only
       
    80 to close (destroy) it at the end. RDriveSpaceCol collection shall be used by CDbsSessDriveSpace
       
    81 instances, which shall be created/used/destroyed by the DBMS sessions.
       
    82 @see CDriveSpace
       
    83 @internalComponent
       
    84 */
       
    85 class RDriveSpaceCol
       
    86 	{
       
    87     friend class CDbsServer;
       
    88     friend class CDbsSessDriveSpace;
       
    89 
       
    90 private:
       
    91 	RDriveSpaceCol(RFs& aFs);
       
    92 	void Close();
       
    93     CDriveSpace* Find(TDriveNumber aDrive);
       
    94     CDriveSpace* CreateAddL(TDriveNumber aDrive);
       
    95 
       
    96 private:
       
    97 	RFs&				        iFs;            //File session reference
       
    98 	RPointerArray<CDriveSpace>	iDriveSpaceCol; //Collection of CDriveSpace objects: one per drive
       
    99 
       
   100 	};
       
   101 
       
   102 /**
       
   103 This structure describes an object, which handles all disk space related requests per
       
   104 DBMS session instance.
       
   105 Using it, the DBMS session can control the access to the reserved drive space for a 
       
   106 particular drive(s).
       
   107 Although it seems a good idea to save some binary code space and use directly CDriveSpace and
       
   108 RDriveSpaceCol classes - no, it is not that good.
       
   109 If you use directly CDriveSpace and RDriveSpaceCol, you have to control that every "Reserve"
       
   110 call is matched by a "Free" call and every "Get/GrantAcces" call is matched by a "ReleaseAccess"
       
   111 call. Also you have to take care about checking that the appropriate CDriveSpace object has
       
   112 been created already or if not - you have to create and add it to the RDriveSpaceCol colelction.
       
   113 All that is done in CDbsSessDriveSpace class.
       
   114 @internalComponent
       
   115 */
       
   116 NONSHARABLE_CLASS(CDbsSessDriveSpace) : public CBase
       
   117     {
       
   118 private:
       
   119     /**
       
   120     This structure describes the state of the disk space reservation requests, related to a 
       
   121     particular drive. It holds an information like: drive number, was the disk space 
       
   122     already reserved?, was an access to it already granted?
       
   123     Using the TDriveSpaceRq objects, the caller can ensure that every "Reserve" call is
       
   124     matched by a "Free" call, every "GetAccess" call is matched by a "ReleaseAccess" call.
       
   125     @internalComponent
       
   126     */
       
   127     struct TDriveSpaceRq
       
   128 	    {
       
   129         TDriveSpaceRq(CDriveSpace& aDriveSpace);
       
   130 	    CDriveSpace&    iDriveSpace;        //This object will handle the reservation requests
       
   131         TUint8	        iReserved:		1;  //If non-zero then the space was already reserved
       
   132         TUint8	        iAccessGranted: 1;  //If non-zero then an access to the space was already granted
       
   133 	    };
       
   134 
       
   135 public:
       
   136     static CDbsSessDriveSpace* NewL(RDriveSpaceCol& aDriveSpaceCol);
       
   137     virtual ~CDbsSessDriveSpace();
       
   138 
       
   139     void ReserveL(TDriveNumber aDrive);
       
   140     void Free(TDriveNumber aDrive);
       
   141 	void GrantAccessL(TDriveNumber aDrive);
       
   142 	void ReleaseAccess(TDriveNumber aDrive);
       
   143 
       
   144 private:
       
   145     CDbsSessDriveSpace(RDriveSpaceCol& aDriveSpaceCol);
       
   146     TDriveSpaceRq* Find(TDriveNumber aDrive);
       
   147     TDriveSpaceRq& CreateAddL(TDriveNumber aDrive);
       
   148     TDriveSpaceRq& GetL(TDriveNumber aDrive);
       
   149 
       
   150 private:
       
   151     RDriveSpaceCol&         iDriveSpaceCol;//Reference to the RDriveSpaceCol colelction.
       
   152     RArray<TDriveSpaceRq>   iDriveSpaceRqCol;//Collection of TDriveSpaceRq objects: one per drive
       
   153 
       
   154     };
       
   155 
       
   156 #endif//__SD_DRIVESPACE_H__