Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

AxPipe::CSinkMemFile Class Reference

A CSink implemented with a memory mapped file as the destination. More...

#include <CFileMap.h>

Inheritance diagram for AxPipe::CSinkMemFile:

Inheritance graph
[legend]
Collaboration diagram for AxPipe::CSinkMemFile:

Collaboration graph
[legend]
List of all members.

Public Member Functions

CSinkMemFileInit (const TCHAR *szFileName, size_t cbChunk=64 *1024)
 Set file and chunk size.

 CSinkMemFile ()
 Initialize member variables etc.

virtual ~CSinkMemFile ()
 Additional destruction necessary...


Protected Member Functions

HANDLE GetHandle ()
 Get the handle to the opened file.

bool OutClose ()
 Close the file, as well as all mappings, set end of file etc.

CSegOutGetSeg (size_t cb)
 Get a writeable segment, mapped to the output file if possible.

void Out (CSeg *pSeg)
 Write a segment to the file, optimizing the case where it already is a mapping.

bool OutOpen ()
 Open the file named in Init() for output.


Private Attributes

HANDLE m_hFile
 The opened file.

HANDLE m_hMapping
 The mapping of the file.

size_t m_cbChunk
 The chunk size we send down stream.

longlong m_cbFileSize
 The length of the file in bytes.

longlong m_cbStreamPos
 The next file position to read a chunk from.

_TCHAR * m_szFileName
 The provided file name, new[]'d and delete[]'d here.

longlong m_cbInPos
 The file pointer position to get the next segment to write to.

longlong m_cbOutPos
 The file pointer position to write the next output to.

longlong m_cbMappingSize
 The size of the current mapping - changed dynamically.

CRITICAL_SECTION m_CritSect
 Threading protection for certain code sections.


Detailed Description

A CSink implemented with a memory mapped file as the destination.

Definition at line 102 of file CFileMap.h.


Member Function Documentation

HANDLE AxPipe::CSinkMemFile::GetHandle  )  [protected]
 

Get the handle to the opened file.

Returns:
An operating system handle to the open file.

Definition at line 232 of file CFileMap.cpp.

References m_hFile.

CSinkMemFile * AxPipe::CSinkMemFile::Init const TCHAR *  szFileName,
size_t  cbChunk = 64*1024
 

Set file and chunk size.

Parameters:
szFileName The name of the file, it is copied and saved here.
cbChunk The size of the chunks we provide upon request via OutGetSeg() upstream.
Returns:
A pointer to 'this' CSourceMemFile

Definition at line 241 of file CFileMap.cpp.

References _TCHAR, m_cbChunk, and m_szFileName.

void AxPipe::CSinkMemFile::Out CSeg pSeg  )  [protected, virtual]
 

Write a segment to the file, optimizing the case where it already is a mapping.

Write a segment to the file by copying into a memory mapped segment, unless we're already such a segment, in which case we actually need do nothing except keep track of the length of valid data 'written'.

Parameters:
pSeg The segment, possibly actually a CSegMap, determined by run time type info.

Implements AxPipe::CSink.

Definition at line 346 of file CFileMap.cpp.

References _T, AxPipe::ERROR_CODE_GENERIC, AxPipe::CSegMap::GetPos(), AxPipe::CSeg::Len(), m_cbOutPos, m_CritSect, m_hMapping, AxPipe::MapUserView(), OutGetSeg(), AxPipe::CSeg::PtrRd(), AxPipe::CSeg::PtrWr(), AxPipe::CSeg::Release(), AxPipe::CSeg::RTClassId(), and AxPipe::CError::SetError().

bool AxPipe::CSinkMemFile::OutClose void   )  [protected, virtual]
 

Close the file, as well as all mappings, set end of file etc.

Check for errors with GetErrorCode()

Returns:
true to propagate the close.

Reimplemented from AxPipe::CSink.

Definition at line 253 of file CFileMap.cpp.

References _T, AxPipe::ERROR_CODE_GENERIC, m_cbOutPos, m_hFile, m_hMapping, and AxPipe::CError::SetError().

CSeg * AxPipe::CSinkMemFile::OutGetSeg size_t  cb  )  [protected, virtual]
 

Get a writeable segment, mapped to the output file if possible.

Map a request for an output segment directly to the output file. If necessary, re-create a mapping to a possibly extended file.

For this to be useful, the upstream caller must get segments in the same sequence that they are output, and also keep them the same size, i.e. not get a segment and then change the CSeg::Len() or CSeg::Drop() bytes off it. In fact using CSeg::Drop() will cause undefined effects. Shortening is possible, but strongly recommended against, as it will make the code quite inefficient.

Parameters:
cb The size in bytes of the segment to get.
Returns:
A (possibly memory mapped) pointer to a CSeg of the requested size.

Reimplemented from AxPipe::CSink.

Definition at line 300 of file CFileMap.cpp.

References _T, AxPipe::ERROR_CODE_GENERIC, AxPipe::longlong, m_cbInPos, m_cbMappingSize, m_cbOutPos, m_CritSect, m_hFile, m_hMapping, AxPipe::MapUserView(), and AxPipe::CError::SetError().

Referenced by Out().

bool AxPipe::CSinkMemFile::OutOpen  )  [protected, virtual]
 

Open the file named in Init() for output.

Check for errors with GetErrorCode().

Returns:
true to propagate the open, which we do if no error. false is not an error condition.

Reimplemented from AxPipe::CSink.

Definition at line 399 of file CFileMap.cpp.

References _T, AxPipe::ERROR_CODE_GENERIC, m_cbInPos, m_cbMappingSize, m_cbOutPos, m_hFile, m_szFileName, and AxPipe::CError::SetError().


The documentation for this class was generated from the following files:
Generated on Mon Feb 2 13:19:28 2004 for AxPipe by doxygen 1.3.5