// EIKBMSTR.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#include <eikbmstr.h>
#include <s32stor.h>

EXPORT_C CBeamingStore* CBeamingStore::NewForSendingL()
	{
	CBeamingStore* self=new(ELeave) CBeamingStore;
	CleanupStack::PushL(self);
	self->ConstructForSendingL();
	CleanupStack::Pop();
	return self;
	}

void CBeamingStore::ConstructForSendingL()
	{
	iBuf=CBufSeg::NewL(256);
	iStreamBuf.Set(*iBuf, 0, TBufBuf::EWrite);
	RWriteStream stream(&iStreamBuf);
	iStore=CEmbeddedStore::NewL(stream);
	iStrmDict=CStreamDictionary::NewL();
	}

EXPORT_C CBeamingStore* CBeamingStore::NewForReceivingL()
	{
	CBeamingStore* self=new(ELeave) CBeamingStore;
	CleanupStack::PushL(self);
	self->ConstructForReceivingL();
	CleanupStack::Pop();
	return self;
	}

void CBeamingStore::ConstructForReceivingL()
	{
	iBuf=CBufFlat::NewL(256);
	iStrmDict=CStreamDictionary::NewL();
	}

EXPORT_C void CBeamingStore::ReadyToSendL()
	{
	RStoreWriteStream root;
	TStreamId rootId=root.CreateLC(*iStore);
	root << (*iStrmDict);
	root.CommitL();
	CleanupStack::PopAndDestroy(); // root
	iStore->SetRootL(rootId);
	iStore->CommitL();
	}

EXPORT_C void CBeamingStore::ReceiveCompleteL()
	{
	iStreamBuf.Set(*iBuf, 0, TBufBuf::ERead);
	RReadStream stream(&iStreamBuf);
	iStore=CEmbeddedStore::FromL(stream);
	TStreamId rootId=iStore->Root();
	RStoreReadStream root;
	root.OpenLC(*iStore, rootId);
	root >> (*iStrmDict);
	CleanupStack::PopAndDestroy();	// root
	}

EXPORT_C CBeamingStore::~CBeamingStore()	
	{
	delete iBuf;
	delete iStore;
	delete iStrmDict;
	}
