Public Member Functions | Protected Member Functions

CStreamFilter Class Reference

A stream filter. More...

#include <CStreamFilter.h>

Inherits synergy::IStream.

Inherited by CCryptoStream, and CPacketStreamFilter.

List of all members.

Public Member Functions

 CStreamFilter (IEventQueue *eventQueue, synergy::IStream *stream, bool adoptStream=true)
virtual void close ()
 Close the stream.
virtual UInt32 read (void *buffer, UInt32 n)
 Read from stream.
virtual void write (const void *buffer, UInt32 n)
 Write to stream.
virtual void flush ()
 Flush the stream.
virtual void shutdownInput ()
 Shutdown input.
virtual void shutdownOutput ()
 Shutdown output.
virtual void * getEventTarget () const
 Get event target.
virtual bool isReady () const
 Test if read() will succeed.
virtual UInt32 getSize () const
 Get bytes available to read.

Protected Member Functions

synergy::IStreamgetStream () const
 Get the stream.
virtual void filterEvent (const CEvent &)
 Handle events from source stream.

Detailed Description

A stream filter.

This class wraps a stream. Subclasses provide indirect access to the wrapped stream, typically performing some filtering.

Definition at line 30 of file CStreamFilter.h.


Constructor & Destructor Documentation

CStreamFilter::CStreamFilter ( IEventQueue eventQueue,
synergy::IStream stream,
bool  adoptStream = true 
)

Create a wrapper around stream. Iff adoptStream is true then this object takes ownership of the stream and will delete it in the d'tor.

Definition at line 27 of file CStreamFilter.cpp.

References IEventQueue::adoptHandler(), synergy::IStream::getEventQueue(), synergy::IStream::getEventTarget(), CEvent::kUnknown, and IEventQueue::removeHandlers().


Member Function Documentation

void CStreamFilter::close (  )  [virtual]

Close the stream.

Closes the stream. Pending input data and buffered output data are discarded. Use flush() before close() to send buffered output data. Attempts to read() after a close return 0, attempts to write() generate output error events, and attempts to flush() return immediately.

Implements synergy::IStream.

Reimplemented in CPacketStreamFilter.

Definition at line 48 of file CStreamFilter.cpp.

References synergy::IStream::close(), and getStream().

void CStreamFilter::filterEvent ( const CEvent event  )  [protected, virtual]

Handle events from source stream.

Does the event filtering. The default simply dispatches an event identical except using this object as the event target.

Reimplemented in CPacketStreamFilter.

Definition at line 108 of file CStreamFilter.cpp.

References IEventQueue::dispatchEvent(), synergy::IStream::getEventQueue(), getEventTarget(), and CEvent::getType().

void CStreamFilter::flush (  )  [virtual]

Flush the stream.

Waits until all buffered data has been written to the stream.

Implements synergy::IStream.

Definition at line 66 of file CStreamFilter.cpp.

References synergy::IStream::flush(), and getStream().

void * CStreamFilter::getEventTarget (  )  const [virtual]

Get event target.

Returns the event target for events generated by this stream. It should be the source stream in a chain of stream filters.

Implements synergy::IStream.

Definition at line 84 of file CStreamFilter.cpp.

Referenced by filterEvent(), and CPacketStreamFilter::read().

UInt32 CStreamFilter::getSize (  )  const [virtual]

Get bytes available to read.

Returns a conservative estimate of the available bytes to read (i.e. a number not greater than the actual number of bytes). Some streams may not be able to determine this and will always return zero.

Implements synergy::IStream.

Reimplemented in CPacketStreamFilter.

Definition at line 96 of file CStreamFilter.cpp.

References synergy::IStream::getSize(), and getStream().

synergy::IStream * CStreamFilter::getStream (  )  const [protected]

Get the stream.

Returns the stream passed to the c'tor.

Definition at line 102 of file CStreamFilter.cpp.

Referenced by close(), flush(), getSize(), isReady(), read(), CCryptoStream::read(), shutdownInput(), shutdownOutput(), write(), CPacketStreamFilter::write(), and CCryptoStream::write().

bool CStreamFilter::isReady (  )  const [virtual]

Test if read() will succeed.

Returns true iff an immediate read() will return data. This may or may not be the same as getSize() > 0, depending on the stream type.

Implements synergy::IStream.

Reimplemented in CPacketStreamFilter.

Definition at line 90 of file CStreamFilter.cpp.

References getStream(), and synergy::IStream::isReady().

UInt32 CStreamFilter::read ( void *  buffer,
UInt32  n 
) [virtual]

Read from stream.

Read up to n bytes into buffer, returning the number read (zero if no data is available or input is shutdown). buffer may be NULL in which case the data is discarded.

Implements synergy::IStream.

Reimplemented in CCryptoStream, and CPacketStreamFilter.

Definition at line 54 of file CStreamFilter.cpp.

References getStream(), and synergy::IStream::read().

void CStreamFilter::shutdownInput (  )  [virtual]

Shutdown input.

Shutdown the input side of the stream. Any pending input data is discarded and further reads immediately return 0.

Implements synergy::IStream.

Reimplemented in CPacketStreamFilter.

Definition at line 72 of file CStreamFilter.cpp.

References getStream(), and synergy::IStream::shutdownInput().

void CStreamFilter::shutdownOutput (  )  [virtual]

Shutdown output.

Shutdown the output side of the stream. Any buffered output data is discarded and further writes generate output error events. Use flush() before shutdownOutput() to send buffered output data.

Implements synergy::IStream.

Definition at line 78 of file CStreamFilter.cpp.

References getStream(), and synergy::IStream::shutdownOutput().

void CStreamFilter::write ( const void *  buffer,
UInt32  n 
) [virtual]

Write to stream.

Write n bytes from buffer to the stream. If this can't complete immediately it will block. Data may be buffered in order to return more quickly. A output error event is generated when writing fails.

Implements synergy::IStream.

Reimplemented in CCryptoStream, and CPacketStreamFilter.

Definition at line 60 of file CStreamFilter.cpp.

References getStream(), and synergy::IStream::write().


The documentation for this class was generated from the following files: