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

AxPipe::CSink Class Reference

The base class of all CSink and CPipe derived pipe sections. More...

#include <AxPipe.h>

Inheritance diagram for AxPipe::CSink:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual void OutPump (CSeg *pSeg)
 Hand off a segment to Work().

 CSink ()
 Initialize member variables.

virtual ~CSink ()
 Plug the pipe, destroy the sink and release remaining m_pSeg if any.

virtual void AppendSink (CSink *pSink, bool fAutoDelete)
 Error catcher.

virtual void DestructSink ()
 Destruct code place holder for derived classes.

virtual void Sync ()
 Ensure that all threads downstream are idle.


Protected Member Functions

void Work ()
 Process one CSeg.

CSegGetSeg (size_t cb)
 Allocate a new segment, possibly from the next section of the pipe.

virtual void Signal (void *vId, void *p)
 Out of band signalling down stream place holder.

longlong SizeMax ()
 Estimate the final sinks size, if limited.

virtual longlong OutSizeMax ()
 Overrideable, Calculate the maximum size of the CSink.

virtual CSegOutGetSeg (size_t cb)
 Overrideable, Allocate a CSeg for this sink.

virtual bool OutSignal (void *vId, void *p)
 Overrideable, Receive an out of band signal from upstream.

virtual bool OutOpen ()
 Overrideable, Open the data stream for processing.

virtual bool OutFlush ()
 Overrideable, Handle request for flush of buffered data.

virtual bool OutClose ()
 Overrideable, Output any final data, close and prepare for new Open().

virtual void OutPlug ()
 Plug this section.

virtual void OutSpecial (CSeg *pSeg)
 Overrideable, Consume a special segment.

virtual void Out (CSeg *pSeg)=0
 Overrideable, Consume a segment and Pump() the processed result downstream.


Protected Attributes

bool m_fIsOpen
 Keep track if this part is open.

CSegm_pSeg
 Next/Current segment to work on.


Private Member Functions

bool DoSegWork (CSeg *pSeg)
 Send a CSeg onwards for processing, handling special types.


Friends

class CPipe
 CPipe needs private access.


Detailed Description

The base class of all CSink and CPipe derived pipe sections.

A CSink should be at the terminating end of all pipe lines, if you really don't need one, attach a /dev/null equivalent sink, CSinkNull. (The framework will work anyway, but it's good practice.)

Convention dictates that all CSink derived classes are named with CSink as a prefix.

CPipe is a derivation of CSink too, basically with the added logic to send data onwards.

See also:
CSource

CPipe

CFilter

Definition at line 213 of file AxPipe.h.


Member Function Documentation

void AxPipe::CSink::AppendSink CSink pSink,
bool  fAutoDelete
[virtual]
 

Error catcher.

You can't append a CSink to a CSink, so this implements code to catch that error.

Reimplemented in AxPipe::CPipe, and AxPipe::CSplit.

Definition at line 260 of file CSink.cpp.

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

Referenced by AxPipe::CPipe::AppendSink().

void AxPipe::CSink::DestructSink  )  [virtual]
 

Destruct code place holder for derived classes.

Called by the virtual destructor, the default implementation for CSink does nothing. The purpose of DestructSink() is to ensure that the whole chain gets destructed, also depending on if they should be auto deleted. It should be called by the destructor before it does the remaining destructing.

Reimplemented in AxPipe::CPipe, and AxPipe::CSplit.

Definition at line 278 of file CSink.cpp.

References _T.

Referenced by AxPipe::CPipe::DestructSink().

bool AxPipe::CSink::DoSegWork CSeg pSeg  )  [private]
 

Send a CSeg onwards for processing, handling special types.

Helper function that is also called by derived classes that want slightly different Work() logic, but can leverage this common base. Checks for special AxPipe::eSegType types, and calls the appropriate OutOpen(), OutClose(), OutFlush() and Out() functions depending on the case. Only in the case of Out() does the actual data segment get passed on. Any custom AxPipe::eSegType segment types gets passed as normal segments to Out(). Ensures that the pipe is Open() at this stage before sending data etc.

Returns:
true if the caller should propagate the segment. Otherwise pSeg may be CSeg::Release()'d.

Definition at line 45 of file CSink.cpp.

References AxPipe::ERROR_CODE_NOTOPEN, AxPipe::eSegTypeClose, AxPipe::eSegTypeFlush, AxPipe::eSegTypeOpen, AxPipe::eSegTypePlug, AxPipe::CSeg::Len(), m_fIsOpen, Out(), OutClose(), OutFlush(), OutOpen(), OutPlug(), OutSpecial(), AxPipe::CSeg::Release(), AxPipe::CError::SetError(), and AxPipe::CSeg::Type().

Referenced by Work(), and AxPipe::CPipe::Work().

CSeg * AxPipe::CSink::GetSeg size_t  cb  )  [protected]
 

Allocate a new segment, possibly from the next section of the pipe.

Allocate a new segment, possibly from the next section of the pipe.

Callable from user code in derived classes.

Call this to get a segment if you suspect the next in line is a sink that might provide an efficient segment, such as for a memory mapped file.

Returns:
A writeable CSeg of the requested size, or NULL on error.

Reimplemented in AxPipe::CPipe.

Definition at line 134 of file CSink.cpp.

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

Overrideable, Consume a segment and Pump() the processed result downstream.

The provided segment is guaranteed to be non-NULL and non-zero-length A special CSeg with a non-zero AxPipe::eSegType value will be sent to OutSpecial(). This is must be implemented in derived classes, there is no default. For CSink directly derived class the actual method of consuming it is up to the CSink, for CPipe derived classes, CPipe::Pump() is the normal method for sending processed data.

Parameters:
pSeg A memory segment to process or consume.
See also:
CPipe::Out()

CPipe::Pump()

AxPipe::eSegType

Implemented in AxPipe::CPipe, AxPipe::CSinkNull, AxPipe::CSplit, AxPipe::CSource, AxPipe::CFilter, AxPipe::CJoin::CTSinkJoin, AxPipe::CSinkMemFile, AxPipe::Stock::CPipeFindSync, AxPipe::Stock::CPipeHMAC_SHA1< iBits >, AxPipe::Stock::CPipeInflate, and AxPipe::Stock::CPipeSHA1.

Referenced by DoSegWork().

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

Overrideable, Output any final data, close and prepare for new Open().

The code should handle multiple (extra) calls to an already closed stream with no ill effects, i.e. silently ignore them. This default implementation returns false to stop propagation, since it's a CSink.

Returns:
true if the framework should propagate the Close() request downstream.

Reimplemented in AxPipe::CPipe, AxPipe::CSplit, AxPipe::CFilter, AxPipe::CJoin::CTSinkJoin, AxPipe::CSourceMemFile, AxPipe::CSinkMemFile, AxPipe::Stock::CPipeHMAC_SHA1< iBits >, AxPipe::Stock::CPipeInflate, and AxPipe::Stock::CPipeSHA1.

Definition at line 226 of file CSink.cpp.

Referenced by DoSegWork().

bool AxPipe::CSink::OutFlush  )  [protected, virtual]
 

Overrideable, Handle request for flush of buffered data.

You are not required to honor the request.

Returns:
true if the framework should propagate the Flush() request downstream.

Reimplemented in AxPipe::CSplit, AxPipe::CFilter, and AxPipe::CJoin::CTSinkJoin.

Definition at line 217 of file CSink.cpp.

Referenced by DoSegWork().

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

Overrideable, Allocate a CSeg for this sink.

Override in user derived classes to provide an efficient memory segment output from a CSink, especially for memory mapped files.

See also:
GetSeg() The User callable function.
Returns:
A writeable segment.

Reimplemented in AxPipe::CPipe, and AxPipe::CSinkMemFile.

Definition at line 183 of file CSink.cpp.

Referenced by AxPipe::CPipe::GetSeg().

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

Overrideable, Open the data stream for processing.

Override in user derived classes. Called by the framework as a result of an Open() call here or upstream. Prepare for processing of a new stream, it must support being called again after a Close() call. No data may be processed by the stream without an Open() call.

The default implementation for a CSink returns false, as it does not make sense to propagate downstream from a CSink()

Returns:
true if the framework should propagate the Open() request downstream.

Reimplemented in AxPipe::CPipe, AxPipe::CSplit, AxPipe::CFilter, AxPipe::CSourceMemFile, AxPipe::CSinkMemFile, AxPipe::Stock::CPipeHMAC_SHA1< iBits >, AxPipe::Stock::CPipeInflate, and AxPipe::Stock::CPipeSHA1.

Definition at line 210 of file CSink.cpp.

Referenced by DoSegWork().

void AxPipe::CSink::OutPlug  )  [protected, virtual]
 

Plug this section.

Unless we're already exited, end processing and wait for it to reach idle state. Should not be called from Work() or Out(). Finally, we wait for the worker thread, if any, to actually exit, thus assuring that when Plug() returns, it is safe to call the destructor. The purpose of Plug is to finalize all processing and to ensure that any errors are found and reported. Final error checking for processing should thus not be done before Plug() is called. After Plug() is called, the only thing that should be done with the object and the pipe line is to destruct it.

Reimplemented in AxPipe::CJoin.

Definition at line 122 of file CSink.cpp.

References _T.

Referenced by DoSegWork().

void AxPipe::CSink::OutPump CSeg pSeg  )  [virtual]
 

Hand off a segment to Work().

Do not call from user code, only from derived framework classes. The normal usage is to have the previous section up the line call this via it's CPipe::m_pSink pointer, the roundabout way is to enable seamless threading. Is frequently called from other library-internal classes, therefore public

Parameters:
pSeg The segment to send off to Work(). Don't use it afterwards unless you've CSeg::AddRef()'d it.

Reimplemented in AxPipe::CPipeBlock.

Definition at line 162 of file CSink.cpp.

References m_pSeg, AxPipe::CNoThread::WorkSignal(), and AxPipe::CNoThread::WorkStart().

Referenced by AxPipe::CSource::Close(), AxPipe::CPipe::Close(), AxPipe::CPipe::Flush(), AxPipe::CSource::Open(), AxPipe::CPipe::Open(), AxPipe::CSource::Out(), AxPipe::CSource::Plug(), AxPipe::CPipe::Pump(), AxPipe::CSplit::PumpSplit(), and AxPipe::CPipe::Work().

bool AxPipe::CSink::OutSignal void *  vId,
void *  p
[protected, virtual]
 

Overrideable, Receive an out of band signal from upstream.

Override in user derived classes to receive a signal sent from upstream. This will be called synchronized with the data stream, so previously sent data will have reached this section, unless some intermediate section buffers. No automatic Flush() request is sent though. This CSink default implementation does nothing and returns false to stop propagation, since it's CSink.

Returns:
false to stop the signal-propagation, true to continue it.
Parameters:
vId A unique value identifying the signal, suggested is ClassId().
p An opaque pointer value, interpretable by the receiver.
See also:
CPipe::OutSignal()

Reimplemented in AxPipe::CPipe.

Definition at line 197 of file CSink.cpp.

Referenced by AxPipe::CPipe::Signal().

longlong AxPipe::CSink::OutSizeMax  )  [protected, virtual]
 

Overrideable, Calculate the maximum size of the CSink.

Override this in user derived classes to return the maximum size of the sink, or -1 for expandable. The default CSink implementation always returns -1.

Returns:
The maximum output size in bytes. -1 if unknown or unlimited.
See also:
SizeMax()

Reimplemented in AxPipe::CPipe.

Definition at line 174 of file CSink.cpp.

References AxPipe::longlong.

Referenced by AxPipe::CPipe::OutSizeMax(), and SizeMax().

void AxPipe::CSink::OutSpecial CSeg pSeg  )  [protected, virtual]
 

Overrideable, Consume a special segment.

Segments may be marked as special with a non-zero value based on AxPipe::eSegType types. These are filtered out of the stream by the framework and presented here instead of to Out(). Use this in derived classes to provide in band signalling and for other custom needs. Start numbering from AxPipe::eSegTypeDerived.

The default implementation here just calls CSeg::Release() on the provided CSeg .

These segements may be zero-length.

See also:
AxPipe::eSegType

Reimplemented in AxPipe::CPipe, and AxPipe::CSplit.

Definition at line 239 of file CSink.cpp.

References AxPipe::CSeg::Release().

Referenced by DoSegWork().

void AxPipe::CSink::Signal void *  vId,
void *  p
[protected, virtual]
 

Out of band signalling down stream place holder.

Callable from user code in derived classes.

Does nothing, this is a CSink.

See also:
CPipe::Signal()

Reimplemented in AxPipe::CPipe.

Definition at line 143 of file CSink.cpp.

Referenced by AxPipe::CPipe::Signal().

longlong AxPipe::CSink::SizeMax  )  [protected]
 

Estimate the final sinks size, if limited.

Callable from user code in derived classes.

Returns:
The maximum output size in bytes. -1 if unknown or unlimited.
See also:
OutSizeMax() The corresponding overrideable

Definition at line 151 of file CSink.cpp.

References AxPipe::longlong, and OutSizeMax().

void AxPipe::CSink::Sync  )  [virtual]
 

Ensure that all threads downstream are idle.

Synchronize all work downstream, ensuring that there is no work in progress.

Reimplemented in AxPipe::CPipe, and AxPipe::CSplit.

Definition at line 267 of file CSink.cpp.

References AxPipe::CNoThread::WaitForIdle().

Referenced by AxPipe::CPipe::Sync().

void AxPipe::CSink::Work  )  [protected, virtual]
 

Process one CSeg.

Called with CSink::m_pSeg set to whatever needs to be processed. Work guarantees to never call Out() with anything but a valid, non-zero-length data segment. Other cases are handled by OutOpen(), OutClose() and OutFlush(). A Plug() request causes nothing to be sent to Out().

Implements AxPipe::CNoThread.

Reimplemented in AxPipe::CPipe, and AxPipe::CFilter.

Definition at line 105 of file CSink.cpp.

References DoSegWork(), and m_pSeg.


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