1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/store/UFILE/UF_PERM.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,202 @@
1.4 +// Copyright (c) 1998-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 +//
1.18 +
1.19 +#include "UF_STD.H"
1.20 +
1.21 +const TInt KBaseOffset=KFileStoreStartOffset-KPermanentStoreHeaderOffset;
1.22 +#if defined(__NO_CLASS_CONSTS__)
1.23 +#define KBase TStreamPos(KBaseOffset)
1.24 +#else
1.25 +const TStreamPos KBase=TStreamPos(KBaseOffset);
1.26 +#endif
1.27 +
1.28 +EXPORT_C TUid CPermanentFileStore::Layout() const
1.29 +/** Gets the UID that uniquely identifies this file store as a permanent file store.
1.30 +
1.31 +@return KPermanentFileStoreLayoutUid. */
1.32 + {
1.33 + return KPermanentFileStoreLayoutUid;
1.34 + }
1.35 +
1.36 +EXPORT_C CPermanentFileStore::CPermanentFileStore(RFile& aFile)
1.37 +//
1.38 +// Constructor creating a new file store.
1.39 +//
1.40 + : CFileStore(aFile)/*,iCoord(NULL)*/
1.41 + {}
1.42 +
1.43 +EXPORT_C CPermanentFileStore::CPermanentFileStore(RFileBuf& aBuf,const TUidType& aType)
1.44 +//
1.45 +// Constructor opening an existing file store.
1.46 +//
1.47 + : CFileStore(aBuf,aType)/*,iCoord(NULL)*/
1.48 + {}
1.49 +
1.50 +EXPORT_C void CPermanentFileStore::MarshalL()
1.51 + {
1.52 + __ASSERT_DEBUG(iCoord==NULL,User::Invariant());
1.53 + iCoord=new(ELeave) CPermanentStoreCoord(KBase,Host());
1.54 + CFileStore::MarshalL();
1.55 + iRoot=Coord().PrimaryL();
1.56 + }
1.57 +
1.58 +EXPORT_C CPermanentFileStore::~CPermanentFileStore()
1.59 +/** Frees resources owned by the object, prior to its destruction. */
1.60 + {
1.61 + Destruct();
1.62 + delete iCoord;
1.63 + }
1.64 +
1.65 +EXPORT_C MStreamBuf* CPermanentFileStore::DoReadL(TStreamId anId) const
1.66 + {
1.67 + if (iCoord==NULL)
1.68 + __LEAVE(KErrNotFound);
1.69 +//
1.70 + return HPermanentStoreBuf::OpenL(CoordL(),anId,HPermanentStoreBuf::ERead);
1.71 + }
1.72 +
1.73 +EXPORT_C MStreamBuf* CPermanentFileStore::DoCreateL(TStreamId& anId)
1.74 + {
1.75 + return HPermanentStoreBuf::CreateL(TrimL(),anId);
1.76 + }
1.77 +
1.78 +EXPORT_C MStreamBuf* CPermanentFileStore::DoWriteL(TStreamId anId)
1.79 + {
1.80 + if (iCoord==NULL)
1.81 + __LEAVE(KErrNotFound);
1.82 +//
1.83 + return HPermanentStoreBuf::OpenL(CoordL(),anId);
1.84 + }
1.85 +
1.86 +EXPORT_C MStreamBuf* CPermanentFileStore::DoReplaceL(TStreamId anId)
1.87 + {
1.88 + if (iCoord==NULL)
1.89 + __LEAVE(KErrNotFound);
1.90 +//
1.91 + return HPermanentStoreBuf::ReplaceL(TrimL(),anId);
1.92 + }
1.93 +
1.94 +EXPORT_C void CPermanentFileStore::ExternalizeL(RWriteStream& aStream) const
1.95 +//
1.96 +// Externalize this store's structure, during construction only.
1.97 +//
1.98 + {
1.99 + __ASSERT_DEBUG(!Host().IsActive()&&iCoord==NULL,User::Invariant());
1.100 + TUint8 buf[-KPermanentStoreHeaderOffset];
1.101 + Mem::FillZ(buf,sizeof(buf));
1.102 + aStream.WriteL(buf,sizeof(buf));
1.103 + }
1.104 +
1.105 +EXPORT_C void CPermanentFileStore::InternalizeL(RReadStream& aStream)
1.106 +//
1.107 +// Internalize this store's structure, during marshalling or refreshment.
1.108 +//
1.109 + {
1.110 + __ASSERT_DEBUG(!Host().IsActive(),User::Invariant());
1.111 + Coord().InternalizeL(aStream);
1.112 + }
1.113 +
1.114 +EXPORT_C void CPermanentFileStore::DoSetRootL(TStreamId anId)
1.115 +//
1.116 +// Set the root stream id.
1.117 +//
1.118 + {
1.119 + CoordL().ChangedL();
1.120 + iRoot=anId;
1.121 + }
1.122 +
1.123 +EXPORT_C TStreamId CPermanentFileStore::DoExtendL()
1.124 + {
1.125 + return CoordL().ExtendL();
1.126 + }
1.127 +
1.128 +EXPORT_C void CPermanentFileStore::DoDeleteL(TStreamId anId)
1.129 + {
1.130 + if (iCoord==NULL)
1.131 + __LEAVE(KErrNotFound);
1.132 +//
1.133 + CoordL().DeleteL(anId);
1.134 + }
1.135 +
1.136 +EXPORT_C void CPermanentFileStore::DoCommitL()
1.137 +//
1.138 +// Establish a new commit point, committing changes made since the last one.
1.139 +//
1.140 + {
1.141 + if (iCoord!=NULL&&TrimL().CommitL(iRoot))
1.142 + {
1.143 + return;
1.144 + }
1.145 +//
1.146 + SynchL();
1.147 + }
1.148 +
1.149 +EXPORT_C void CPermanentFileStore::DoRevertL()
1.150 +//
1.151 +// Roll back to the state at the last commit point.
1.152 +//
1.153 + {
1.154 + CPermanentStoreCoord* coord=iCoord;
1.155 + if (coord!=NULL&&coord->RevertL(iRoot))
1.156 + return;
1.157 +//
1.158 + SynchL();
1.159 + }
1.160 +
1.161 +EXPORT_C MIncrementalCollector* CPermanentFileStore::DoReclaimL()
1.162 + {
1.163 + return CPermanentStoreCollector::ReclaimerL(CoordL());
1.164 + }
1.165 +
1.166 +EXPORT_C MIncrementalCollector* CPermanentFileStore::DoCompactL()
1.167 + {
1.168 + return CPermanentStoreCollector::CompactorL(TrimL());
1.169 + }
1.170 +
1.171 +CPermanentStoreCoord& CPermanentFileStore::CoordL() const
1.172 + {
1.173 + CPermanentStoreCoord* coord=iCoord;
1.174 + if (coord==NULL)
1.175 + {
1.176 + coord=new(ELeave) CPermanentStoreCoord(KBase,Host());
1.177 + MUTABLE_CAST(CPermanentStoreCoord*&,iCoord)=coord;
1.178 + }
1.179 + else if (!Host().IsActive())
1.180 + CONST_CAST(CPermanentFileStore*,this)->RefreshL();
1.181 + return *coord;
1.182 + }
1.183 +
1.184 +CPermanentStoreCoord& CPermanentFileStore::TrimL()
1.185 + {
1.186 + CPermanentStoreCoord& coord=CoordL();
1.187 + if (!coord.IsTrim())
1.188 + {
1.189 + TInt lim=coord.LimitL().Offset(); // it can be slightly smaller than this
1.190 + TInt size=Host().HostL()->SizeL();
1.191 + if (size>lim)
1.192 + SetSizeL(lim);
1.193 + coord.Clipped();
1.194 + }
1.195 + return coord;
1.196 + }
1.197 +
1.198 +EXPORT_C CFileStore* CPermanentFileStore::DoNewL(RFile& aFile)
1.199 +//
1.200 +// Factory function creating a new file.
1.201 +//
1.202 + {
1.203 + return new(ELeave) CPermanentFileStore(aFile);
1.204 + }
1.205 +