os/persistentdata/persistentstorage/store/USTOR/UT_EMBED.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/store/USTOR/UT_EMBED.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,165 @@
     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 "UT_STD.H"
    1.20 +
    1.21 +EXPORT_C CEmbeddedStore* CEmbeddedStore::FromL(RReadStream& aHost)
    1.22 +/** Opens the store hosted by the specified stream.
    1.23 +
    1.24 +Note that ownership of the stream passes to the store; the referenced RReadStream 
    1.25 +is cleared.
    1.26 +
    1.27 +@param aHost A reference to the stream hosting the embedded store.
    1.28 +@return A pointer to the embedded store object. */
    1.29 +	{
    1.30 +	CEmbeddedStore* store=FromLC(aHost);
    1.31 +	CleanupStack::Pop();
    1.32 +	return store;
    1.33 +	}
    1.34 +
    1.35 +EXPORT_C CEmbeddedStore* CEmbeddedStore::FromLC(RReadStream& aHost)
    1.36 +/** Open the store hosted by the specified stream, putting a pointer to the store 
    1.37 +onto the cleanup stack.
    1.38 +
    1.39 +Putting a pointer to the embedded store object onto the cleanup stack allows 
    1.40 +the object and allocated resources to be cleaned up if a subsequent leave 
    1.41 +occurs.
    1.42 +
    1.43 +Note that ownership of the stream passes to the store and the referenced RReadStream 
    1.44 +is cleared.
    1.45 +
    1.46 +@param aHost A reference to the stream hosting the embedded store.
    1.47 +@return A pointer to the embedded store object. */
    1.48 +	{
    1.49 +	CEmbeddedStore* store=CEmbeddedStore::DoNewLC(aHost.Source());
    1.50 +	store->MarshalL(aHost);
    1.51 +	return store;
    1.52 +	}
    1.53 +
    1.54 +EXPORT_C CEmbeddedStore* CEmbeddedStore::NewL(RWriteStream& aHost)
    1.55 +/** Creates an embedded store within the specified host stream.
    1.56 +
    1.57 +Note that ownership of the stream passes to the store and the referenced RWriteStream 
    1.58 +is cleared.
    1.59 +
    1.60 +@param aHost A reference to the stream which is to host the embedded store.
    1.61 +@return A pointer to the embedded store object. */
    1.62 +	{
    1.63 +	CEmbeddedStore* store=NewLC(aHost);
    1.64 +	CleanupStack::Pop();
    1.65 +	return store;
    1.66 +	}
    1.67 +
    1.68 +EXPORT_C CEmbeddedStore* CEmbeddedStore::NewLC(RWriteStream& aHost)
    1.69 +/** Creates an embedded store within the specified host stream, putting a pointer 
    1.70 +to the store onto the cleanup stack.
    1.71 +
    1.72 +Putting a pointer to the embedded store object onto the cleanup stack allows 
    1.73 +the object and allocated resources to be cleaned up if a subsequent leave 
    1.74 +occurs.
    1.75 +
    1.76 +Note that ownership of the stream passes to the store and the referenced RWriteStream 
    1.77 +is cleared.
    1.78 +
    1.79 +@param aHost A reference to the stream which is to host the embedded store.
    1.80 +@return A pointer to the embedded store object. */
    1.81 +	{
    1.82 +	CEmbeddedStore* store=CEmbeddedStore::DoNewLC(aHost.Sink());
    1.83 +	store->ConstructL(aHost);
    1.84 +	return store;
    1.85 +	}
    1.86 +
    1.87 +EXPORT_C void CEmbeddedStore::Detach()
    1.88 +/** Gives up ownership of the host stream buffer. The caller takes on the responsibility 
    1.89 +for discarding the buffer. */
    1.90 +	{
    1.91 +	iHost.Host();
    1.92 +	iHost.Release();
    1.93 +	}
    1.94 +
    1.95 +EXPORT_C CEmbeddedStore::CEmbeddedStore(MStreamBuf* aHost)
    1.96 +	: iHost(aHost)
    1.97 +	{
    1.98 +	__ASSERT_DEBUG(aHost!=NULL,Panic(EStoreNotOpen));
    1.99 +	}
   1.100 +
   1.101 +EXPORT_C void CEmbeddedStore::MarshalL(RReadStream& aStream)
   1.102 +//
   1.103 +// Second-phase construction for opening existing stores.
   1.104 +//
   1.105 +	{
   1.106 +	MStreamBuf* src=aStream.Source();
   1.107 +	aStream=RReadStream();
   1.108 +	__ASSERT_DEBUG(src!=NULL&&src==iHost.Host(),User::Invariant());
   1.109 +	iStart=src->TellL(MStreamBuf::ERead);
   1.110 +	RReadStream stream(src);
   1.111 +	stream>>iRoot;
   1.112 +	}
   1.113 +
   1.114 +EXPORT_C void CEmbeddedStore::ConstructL(RWriteStream& aStream)
   1.115 +//
   1.116 +// Second-phase construction for creating new stores.
   1.117 +//
   1.118 +	{
   1.119 +	MStreamBuf* snk=aStream.Sink();
   1.120 +	aStream=RWriteStream();
   1.121 +	__ASSERT_DEBUG(snk!=NULL&&snk==iHost.Host(),User::Invariant());
   1.122 +	iStart=snk->TellL(MStreamBuf::EWrite);
   1.123 +	RWriteStream stream(snk);
   1.124 +	stream<<iRoot;
   1.125 +	}
   1.126 +
   1.127 +EXPORT_C CEmbeddedStore::~CEmbeddedStore()
   1.128 +/** Frees resources owned by the object, prior to its destruction. In particular, 
   1.129 +the destructor closes the associated file. */
   1.130 +	{
   1.131 +	MStreamBuf* buf=iHost.Host();
   1.132 +	if (buf!=NULL)
   1.133 +		buf->Release();
   1.134 +	}
   1.135 +
   1.136 +EXPORT_C MStreamBuf* CEmbeddedStore::DoReadL(TStreamId anId) const
   1.137 +	{
   1.138 +	return HDirectStoreBuf::OpenL(MUTABLE_CAST(TStreamExchange&,iHost),anId,HDirectStoreBuf::ERead);
   1.139 +	}
   1.140 +
   1.141 +EXPORT_C MStreamBuf* CEmbeddedStore::DoCreateL(TStreamId& anId)
   1.142 +	{
   1.143 +	return HDirectStoreBuf::CreateL(iHost,anId,HDirectStoreBuf::ERead|HDirectStoreBuf::EWrite);
   1.144 +	}
   1.145 +
   1.146 +EXPORT_C void CEmbeddedStore::DoSetRootL(TStreamId anId)
   1.147 +	{
   1.148 +	RShareWriteStream stream(iHost,iStart);
   1.149 +	stream.PushL();
   1.150 +	stream<<anId;
   1.151 +	CleanupStack::PopAndDestroy();
   1.152 +	iRoot=anId;
   1.153 +	}
   1.154 +	
   1.155 +EXPORT_C void CEmbeddedStore::DoCommitL()
   1.156 +	{
   1.157 +	iHost.HostL()->SynchL();
   1.158 +	}
   1.159 +	
   1.160 +CEmbeddedStore* CEmbeddedStore::DoNewLC(MStreamBuf* aHost)
   1.161 +	{
   1.162 +	aHost->PushL();
   1.163 +	CEmbeddedStore* store=new(ELeave) CEmbeddedStore(aHost);
   1.164 +	CleanupStack::Pop();
   1.165 +	CleanupStack::PushL(store);
   1.166 +	return store;
   1.167 +	}
   1.168 +