persistentstorage/sql/SRC/Server/SqlSrvDriveSpace.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
     1 // Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14 // Reserving/Accessing/Releasing drive space - CSqlDriveSpace and RSqlDriveSpaceCol classes implementations
    14 // Reserving/Accessing/Releasing drive space - CSqlDriveSpace and RSqlDriveSpaceCol classes implementations
    15 // 
    15 // 
    16 //
    16 //
    17 
    17 
    18 #include "SqlSrvDriveSpace.h"
    18 #include "SqlSrvDriveSpace.h"
    19 #include "SqlAssert.h"
    19 #include "SqlPanic.h"
    20 #include "OstTraceDefinitions.h"
       
    21 #ifdef OST_TRACE_COMPILER_IN_USE
       
    22 #include "SqlSrvDriveSpaceTraces.h"
       
    23 #endif
       
    24 #include "SqlTraceDef.h"
       
    25 
    20 
    26 /**
    21 /**
    27 The amount of the disk space, which will be reserved at the moment of creation of
    22 The amount of the disk space, which will be reserved at the moment of creation of
    28 each CDriveSpace object.
    23 each CDriveSpace object.
    29 It should be enough for the most of "delete" transactions, if they do not require a rollback transaction
    24 It should be enough for the most of "delete" transactions, if they do not require a rollback transaction
    55 	   
    50 	   
    56 @see RFs::ReserveDriveSpace()
    51 @see RFs::ReserveDriveSpace()
    57 */
    52 */
    58 CSqlDriveSpace* CSqlDriveSpace::NewLC(RFs& aFs, TDriveNumber aDrive)
    53 CSqlDriveSpace* CSqlDriveSpace::NewLC(RFs& aFs, TDriveNumber aDrive)
    59     {
    54     {
    60 	SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLDRIVESPACE_NEWLC_ENTRY, "Entry;0;CSqlDriveSpace::NewLC;aFs.Handle()=0x%X;aDrive=%d", (TUint)aFs.Handle(), (TInt)aDrive));
    55 	__SQLASSERT(aDrive >= EDriveA && aDrive <= EDriveZ, ESqlPanicBadArgument);
    61 	__ASSERT_DEBUG(aDrive >= EDriveA && aDrive <= EDriveZ, __SQLPANIC2(ESqlPanicBadArgument));
       
    62     CSqlDriveSpace* self = new (ELeave) CSqlDriveSpace(aFs, aDrive);
    56     CSqlDriveSpace* self = new (ELeave) CSqlDriveSpace(aFs, aDrive);
    63     CleanupStack::PushL(self);
    57     CleanupStack::PushL(self);
    64     self->ConstructL();
    58     self->ConstructL();
    65 	SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLDRIVESPACE_NEWLC_EXIT, "Exit;0x%X;CSqlDriveSpace::NewLC", (TUint)self));
       
    66     return self;
    59     return self;
    67     }
    60     }
    68 
    61 
    69 /**
    62 /**
    70 Frees the reserved disk space.
    63 Frees the reserved disk space.
    71 */
    64 */
    72 CSqlDriveSpace::~CSqlDriveSpace()
    65 CSqlDriveSpace::~CSqlDriveSpace()
    73     {
    66     {
    74 	SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLDRIVESPACE_CSQLDRIVESPACE2, "0x%X;CSqlDriveSpace::~CSqlDriveSpace;iDrive=%d;iGetAccessRefCnt=%d", (TUint)this, (TInt)iDrive, iGetAccessRefCnt));
       
    75 	SQLDRIVESPACE_INVARIANT();
    67 	SQLDRIVESPACE_INVARIANT();
    76 	(void)iFs.ReleaseReserveAccess(static_cast <TInt> (iDrive));
    68 	(void)iFs.ReleaseReserveAccess(static_cast <TInt> (iDrive));
    77 	(void)iFs.ReserveDriveSpace(static_cast <TInt> (iDrive), 0);
    69 	(void)iFs.ReserveDriveSpace(static_cast <TInt> (iDrive), 0);
    78     }
    70     }
    79 
    71 
    88 
    80 
    89 @panic SqlDb 12 In _DEBUG mode if iGetAccessRefCnt < 0
    81 @panic SqlDb 12 In _DEBUG mode if iGetAccessRefCnt < 0
    90 */
    82 */
    91 void CSqlDriveSpace::GetAccessL()
    83 void CSqlDriveSpace::GetAccessL()
    92 	{
    84 	{
    93 	SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLDRIVESPACE_GETACCESSL_ENTRY, "Entry;0x%X;CSqlDriveSpace::GetAccessL;iDrive=%d;iGetAccessRefCnt=%d", (TUint)this, (TInt)iDrive, iGetAccessRefCnt));
       
    94 	SQLDRIVESPACE_INVARIANT();
    85 	SQLDRIVESPACE_INVARIANT();
    95 	//Gets an access only once, there is only one RFs session instance.
    86 	//Gets an access only once, there is only one RFs session instance.
    96 	if(iGetAccessRefCnt == 0)
    87 	if(iGetAccessRefCnt == 0)
    97 		{
    88 		{
    98 		__SQLLEAVE_IF_ERROR(iFs.GetReserveAccess(static_cast <TInt> (iDrive)));
    89 		__SQLLEAVE_IF_ERROR(iFs.GetReserveAccess(static_cast <TInt> (iDrive)));
    99 		}
    90 		}
   100 	++iGetAccessRefCnt;
    91 	++iGetAccessRefCnt;
   101 	SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLDRIVESPACE_GETACCESSL_EXIT, "Exit;0x%X;CSqlDriveSpace::GetAccessL;iDrive=%d;iGetAccessRefCnt=%d", (TUint)this, (TInt)iDrive, iGetAccessRefCnt));
       
   102 	SQLDRIVESPACE_INVARIANT();
    92 	SQLDRIVESPACE_INVARIANT();
   103 	}
    93 	}
   104 
    94 
   105 /**
    95 /**
   106 Revokes access to the reserved drive space.
    96 Revokes access to the reserved drive space.
   111 
   101 
   112 @panic SqlDb 12 In _DEBUG mode if iGetAccessRefCnt < 0
   102 @panic SqlDb 12 In _DEBUG mode if iGetAccessRefCnt < 0
   113 */
   103 */
   114 void CSqlDriveSpace::ReleaseAccess()
   104 void CSqlDriveSpace::ReleaseAccess()
   115 	{
   105 	{
   116 	SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLDRIVESPACE_RELEASEACCESS, "0x%X;CSqlDriveSpace::ReleaseAccess;iDrive=%d;iGetAccessRefCnt=%d", (TUint)this, (TInt)iDrive, iGetAccessRefCnt));
       
   117 	SQLDRIVESPACE_INVARIANT();
   106 	SQLDRIVESPACE_INVARIANT();
   118     if(iGetAccessRefCnt == 0)
   107     if(iGetAccessRefCnt == 0)
   119         {
   108         {
   120         return;
   109         return;
   121         }
   110         }
   136 */
   125 */
   137 CSqlDriveSpace::CSqlDriveSpace(RFs& aFs, TDriveNumber aDrive) :
   126 CSqlDriveSpace::CSqlDriveSpace(RFs& aFs, TDriveNumber aDrive) :
   138 	iFs(aFs),
   127 	iFs(aFs),
   139 	iDrive(aDrive)
   128 	iDrive(aDrive)
   140 	{
   129 	{
   141 	__ASSERT_DEBUG(aDrive >= EDriveA && aDrive <= EDriveZ, __SQLPANIC(ESqlPanicBadArgument));
   130 	__SQLASSERT(aDrive >= EDriveA && aDrive <= EDriveZ, ESqlPanicBadArgument);
   142 	}
   131 	}
   143 
   132 
   144 /**
   133 /**
   145 Standard phase-two construction method for creation of CSqlDriveSpace objects.
   134 Standard phase-two construction method for creation of CSqlDriveSpace objects.
   146 
   135 
   161 /**
   150 /**
   162 CSqlDriveSpace invariant.
   151 CSqlDriveSpace invariant.
   163 */
   152 */
   164 void CSqlDriveSpace::Invariant() const
   153 void CSqlDriveSpace::Invariant() const
   165 	{
   154 	{
   166 	__ASSERT_DEBUG(iDrive >= EDriveA && iDrive <= EDriveZ, __SQLPANIC(ESqlPanicInternalError));
   155 	__SQLASSERT(iDrive >= EDriveA && iDrive <= EDriveZ, ESqlPanicInternalError);
   167 	__ASSERT_DEBUG(iGetAccessRefCnt >= 0, __SQLPANIC(ESqlPanicMisuse));
   156 	__SQLASSERT(iGetAccessRefCnt >= 0, ESqlPanicMisuse);
   168 	}
   157 	}
   169 #endif//_DEBUG
   158 #endif//_DEBUG
   170 
   159 
   171 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   160 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   172 ////////////////////////////////    RSqlDriveSpaceCol class    ///////////////////////////////////////////////////
   161 ////////////////////////////////    RSqlDriveSpaceCol class    ///////////////////////////////////////////////////
   211 
   200 
   212 @panic SqlDb 4 In _DEBUG mode if aDrive is invalid
   201 @panic SqlDb 4 In _DEBUG mode if aDrive is invalid
   213 */
   202 */
   214 CSqlDriveSpace* RSqlDriveSpaceCol::Find(TDriveNumber aDrive)
   203 CSqlDriveSpace* RSqlDriveSpaceCol::Find(TDriveNumber aDrive)
   215     {
   204     {
   216 	__ASSERT_DEBUG(aDrive >= EDriveA && aDrive <= EDriveZ, __SQLPANIC(ESqlPanicBadArgument));
   205 	__SQLASSERT(aDrive >= EDriveA && aDrive <= EDriveZ, ESqlPanicBadArgument);
   217 	SQLDRIVESPACECOL_INVARIANT();
   206 	SQLDRIVESPACECOL_INVARIANT();
   218     for(TInt index=iDriveSpaceCol.Count()-1;index>=0;--index)
   207     for(TInt index=iDriveSpaceCol.Count()-1;index>=0;--index)
   219         {
   208         {
   220         if(iDriveSpaceCol[index]->Drive() == aDrive)
   209         if(iDriveSpaceCol[index]->Drive() == aDrive)
   221             {
   210             {
   239 @panic SqlDb 4, In _DEBUG mode if aDrive is invalid.
   228 @panic SqlDb 4, In _DEBUG mode if aDrive is invalid.
   240 @panic SqlDb 12, In _DEBUG mode if a CDriveSpace object already exists for aDrive.
   229 @panic SqlDb 12, In _DEBUG mode if a CDriveSpace object already exists for aDrive.
   241 */
   230 */
   242 CSqlDriveSpace* RSqlDriveSpaceCol::AddL(TDriveNumber aDrive)
   231 CSqlDriveSpace* RSqlDriveSpaceCol::AddL(TDriveNumber aDrive)
   243 	{
   232 	{
   244 	__ASSERT_DEBUG(aDrive >= EDriveA && aDrive <= EDriveZ, __SQLPANIC(ESqlPanicBadArgument));
   233 	__SQLASSERT(aDrive >= EDriveA && aDrive <= EDriveZ, ESqlPanicBadArgument);
   245     __ASSERT_DEBUG(!Find(aDrive), __SQLPANIC(ESqlPanicMisuse));
   234     __SQLASSERT(!Find(aDrive), ESqlPanicMisuse);
   246 	SQLDRIVESPACECOL_INVARIANT();
   235 	SQLDRIVESPACECOL_INVARIANT();
   247     CSqlDriveSpace* drvSpace = CSqlDriveSpace::NewLC(*iFs, aDrive);
   236     CSqlDriveSpace* drvSpace = CSqlDriveSpace::NewLC(*iFs, aDrive);
   248     __SQLLEAVE_IF_ERROR(iDriveSpaceCol.Append(drvSpace));
   237     __SQLLEAVE_IF_ERROR(iDriveSpaceCol.Append(drvSpace));
   249     CleanupStack::Pop(drvSpace);
   238     CleanupStack::Pop(drvSpace);
   250 	SQLDRIVESPACECOL_INVARIANT();
   239 	SQLDRIVESPACECOL_INVARIANT();
   255 /**
   244 /**
   256 RSqlDriveSpaceCol invariant.
   245 RSqlDriveSpaceCol invariant.
   257 */
   246 */
   258 void RSqlDriveSpaceCol::Invariant() const
   247 void RSqlDriveSpaceCol::Invariant() const
   259 	{
   248 	{
   260 	__ASSERT_DEBUG(iFs != NULL, __SQLPANIC(ESqlPanicInternalError));
   249 	__SQLASSERT(iFs != NULL, ESqlPanicInternalError);
   261     for(TInt index=iDriveSpaceCol.Count()-1;index>=0;--index)
   250     for(TInt index=iDriveSpaceCol.Count()-1;index>=0;--index)
   262     	{
   251     	{
   263 		iDriveSpaceCol[index]->Invariant();
   252 		iDriveSpaceCol[index]->Invariant();
   264     	}
   253     	}
   265 	}
   254 	}