sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "UT_STD.H" sl@0: sl@0: EXPORT_C CEmbeddedStore* CEmbeddedStore::FromL(RReadStream& aHost) sl@0: /** Opens the store hosted by the specified stream. sl@0: sl@0: Note that ownership of the stream passes to the store; the referenced RReadStream sl@0: is cleared. sl@0: sl@0: @param aHost A reference to the stream hosting the embedded store. sl@0: @return A pointer to the embedded store object. */ sl@0: { sl@0: CEmbeddedStore* store=FromLC(aHost); sl@0: CleanupStack::Pop(); sl@0: return store; sl@0: } sl@0: sl@0: EXPORT_C CEmbeddedStore* CEmbeddedStore::FromLC(RReadStream& aHost) sl@0: /** Open the store hosted by the specified stream, putting a pointer to the store sl@0: onto the cleanup stack. sl@0: sl@0: Putting a pointer to the embedded store object onto the cleanup stack allows sl@0: the object and allocated resources to be cleaned up if a subsequent leave sl@0: occurs. sl@0: sl@0: Note that ownership of the stream passes to the store and the referenced RReadStream sl@0: is cleared. sl@0: sl@0: @param aHost A reference to the stream hosting the embedded store. sl@0: @return A pointer to the embedded store object. */ sl@0: { sl@0: CEmbeddedStore* store=CEmbeddedStore::DoNewLC(aHost.Source()); sl@0: store->MarshalL(aHost); sl@0: return store; sl@0: } sl@0: sl@0: EXPORT_C CEmbeddedStore* CEmbeddedStore::NewL(RWriteStream& aHost) sl@0: /** Creates an embedded store within the specified host stream. sl@0: sl@0: Note that ownership of the stream passes to the store and the referenced RWriteStream sl@0: is cleared. sl@0: sl@0: @param aHost A reference to the stream which is to host the embedded store. sl@0: @return A pointer to the embedded store object. */ sl@0: { sl@0: CEmbeddedStore* store=NewLC(aHost); sl@0: CleanupStack::Pop(); sl@0: return store; sl@0: } sl@0: sl@0: EXPORT_C CEmbeddedStore* CEmbeddedStore::NewLC(RWriteStream& aHost) sl@0: /** Creates an embedded store within the specified host stream, putting a pointer sl@0: to the store onto the cleanup stack. sl@0: sl@0: Putting a pointer to the embedded store object onto the cleanup stack allows sl@0: the object and allocated resources to be cleaned up if a subsequent leave sl@0: occurs. sl@0: sl@0: Note that ownership of the stream passes to the store and the referenced RWriteStream sl@0: is cleared. sl@0: sl@0: @param aHost A reference to the stream which is to host the embedded store. sl@0: @return A pointer to the embedded store object. */ sl@0: { sl@0: CEmbeddedStore* store=CEmbeddedStore::DoNewLC(aHost.Sink()); sl@0: store->ConstructL(aHost); sl@0: return store; sl@0: } sl@0: sl@0: EXPORT_C void CEmbeddedStore::Detach() sl@0: /** Gives up ownership of the host stream buffer. The caller takes on the responsibility sl@0: for discarding the buffer. */ sl@0: { sl@0: iHost.Host(); sl@0: iHost.Release(); sl@0: } sl@0: sl@0: EXPORT_C CEmbeddedStore::CEmbeddedStore(MStreamBuf* aHost) sl@0: : iHost(aHost) sl@0: { sl@0: __ASSERT_DEBUG(aHost!=NULL,Panic(EStoreNotOpen)); sl@0: } sl@0: sl@0: EXPORT_C void CEmbeddedStore::MarshalL(RReadStream& aStream) sl@0: // sl@0: // Second-phase construction for opening existing stores. sl@0: // sl@0: { sl@0: MStreamBuf* src=aStream.Source(); sl@0: aStream=RReadStream(); sl@0: __ASSERT_DEBUG(src!=NULL&&src==iHost.Host(),User::Invariant()); sl@0: iStart=src->TellL(MStreamBuf::ERead); sl@0: RReadStream stream(src); sl@0: stream>>iRoot; sl@0: } sl@0: sl@0: EXPORT_C void CEmbeddedStore::ConstructL(RWriteStream& aStream) sl@0: // sl@0: // Second-phase construction for creating new stores. sl@0: // sl@0: { sl@0: MStreamBuf* snk=aStream.Sink(); sl@0: aStream=RWriteStream(); sl@0: __ASSERT_DEBUG(snk!=NULL&&snk==iHost.Host(),User::Invariant()); sl@0: iStart=snk->TellL(MStreamBuf::EWrite); sl@0: RWriteStream stream(snk); sl@0: stream<Release(); sl@0: } sl@0: sl@0: EXPORT_C MStreamBuf* CEmbeddedStore::DoReadL(TStreamId anId) const sl@0: { sl@0: return HDirectStoreBuf::OpenL(MUTABLE_CAST(TStreamExchange&,iHost),anId,HDirectStoreBuf::ERead); sl@0: } sl@0: sl@0: EXPORT_C MStreamBuf* CEmbeddedStore::DoCreateL(TStreamId& anId) sl@0: { sl@0: return HDirectStoreBuf::CreateL(iHost,anId,HDirectStoreBuf::ERead|HDirectStoreBuf::EWrite); sl@0: } sl@0: sl@0: EXPORT_C void CEmbeddedStore::DoSetRootL(TStreamId anId) sl@0: { sl@0: RShareWriteStream stream(iHost,iStart); sl@0: stream.PushL(); sl@0: stream<SynchL(); sl@0: } sl@0: sl@0: CEmbeddedStore* CEmbeddedStore::DoNewLC(MStreamBuf* aHost) sl@0: { sl@0: aHost->PushL(); sl@0: CEmbeddedStore* store=new(ELeave) CEmbeddedStore(aHost); sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PushL(store); sl@0: return store; sl@0: } sl@0: