os/persistentdata/persistentstorage/store/pcstore/src/filestreambuf.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#if !defined(__FILESTREAMBUF_H__)
sl@0
    17
#define __FILESTREAMBUF_H__
sl@0
    18
sl@0
    19
#include <stdio.h>
sl@0
    20
#include <pcstore/streamid.h>
sl@0
    21
sl@0
    22
namespace PCStore
sl@0
    23
{
sl@0
    24
class CDirectFileStore;
sl@0
    25
sl@0
    26
/**
sl@0
    27
@internalComponent
sl@0
    28
 
sl@0
    29
A file stream buffer that provides I/O interfaces for streamed data.
sl@0
    30
sl@0
    31
This file stream buffer: 
sl@0
    32
. is unbuffered: all data passed to it will immediately be written to the corresponding file
sl@0
    33
  or returned to its caller.
sl@0
    34
sl@0
    35
. provides read or write capability: it opens the file in read or write mode. After it is 
sl@0
    36
  instantiated, only read or write function can be called, depending on the file open mode. 
sl@0
    37
  Exception will be thrown upon an unmatching call.
sl@0
    38
sl@0
    39
. is unseekable. It only moves the file pointer to the position represented by the stream id, 
sl@0
    40
  which is passed to its constructor. In the subsequent read or write operations, the pointer 
sl@0
    41
  always goes forward.
sl@0
    42
sl@0
    43
For each file store, one object of this class is created in the constructor of CDirectFileStore. 
sl@0
    44
CDirectFileStore will pass the reference of this object to the stream it creates. In order to 
sl@0
    45
ensure there is only one stream opened in any moment, streams will call the StreamOpen and 
sl@0
    46
StreamClose methods respectively in their constructor and destructor to signal their open 
sl@0
    47
and close.
sl@0
    48
sl@0
    49
@see CDirectFileStore 
sl@0
    50
@see CStoreWriteStream
sl@0
    51
@see CStoreReadStream
sl@0
    52
*/
sl@0
    53
class CFileStreamBuf
sl@0
    54
	{
sl@0
    55
public:
sl@0
    56
	//Enumerations for the file open mode
sl@0
    57
	enum TFileMode 
sl@0
    58
	{
sl@0
    59
	EReadFile=0,
sl@0
    60
	EWriteFile=1
sl@0
    61
	};
sl@0
    62
sl@0
    63
public:
sl@0
    64
	CFileStreamBuf(const char* aFileName, TFileMode aMode);
sl@0
    65
	~CFileStreamBuf();
sl@0
    66
	void StreamOpen(TStreamId aStreamId);
sl@0
    67
	void StreamClose();
sl@0
    68
	TStreamId GetNewStreamId();
sl@0
    69
	void Read(const TUint8* aPtr, TInt32 aLength);
sl@0
    70
	void Write(const TUint8* aPtr, TInt32 aLength);
sl@0
    71
sl@0
    72
private:
sl@0
    73
	CFileStreamBuf(const CFileStreamBuf& aBuf); 
sl@0
    74
	CFileStreamBuf& operator=(const CFileStreamBuf& aBuf); 
sl@0
    75
sl@0
    76
private:
sl@0
    77
	FILE* iFile;
sl@0
    78
	TBool iStreamOpened;
sl@0
    79
	};
sl@0
    80
}
sl@0
    81
#endif // !defined(__FILESTREAMBUF_H__)