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