Removed recursive mutexes. Simplified stream filters as a side

effect.  Removed -D_BSD_SOURCE and -D_XOPEN_SOURCE=500 from
compile since they're not longer necessary.
This commit is contained in:
crs
2004-09-29 21:59:26 +00:00
parent 376bba970b
commit 07e2a3e511
18 changed files with 148 additions and 302 deletions

View File

@@ -13,6 +13,8 @@
*/
#include "CStreamFilter.h"
#include "IEventQueue.h"
#include "TMethodEventJob.h"
//
// CStreamFilter
@@ -22,11 +24,16 @@ CStreamFilter::CStreamFilter(IStream* stream, bool adoptStream) :
m_stream(stream),
m_adopted(adoptStream)
{
// do nothing
// replace handlers for m_stream
EVENTQUEUE->removeHandlers(m_stream->getEventTarget());
EVENTQUEUE->adoptHandler(CEvent::kUnknown, m_stream->getEventTarget(),
new TMethodEventJob<CStreamFilter>(this,
&CStreamFilter::handleUpstreamEvent));
}
CStreamFilter::~CStreamFilter()
{
EVENTQUEUE->removeHandler(CEvent::kUnknown, m_stream->getEventTarget());
if (m_adopted) {
delete m_stream;
}
@@ -68,16 +75,10 @@ CStreamFilter::shutdownOutput()
getStream()->shutdownOutput();
}
void
CStreamFilter::setEventFilter(IEventJob* filter)
{
getStream()->setEventFilter(filter);
}
void*
CStreamFilter::getEventTarget() const
{
return getStream()->getEventTarget();
return const_cast<void*>(reinterpret_cast<const void*>(this));
}
bool
@@ -92,14 +93,21 @@ CStreamFilter::getSize() const
return getStream()->getSize();
}
IEventJob*
CStreamFilter::getEventFilter() const
{
return getStream()->getEventFilter();
}
IStream*
CStreamFilter::getStream() const
{
return m_stream;
}
void
CStreamFilter::filterEvent(const CEvent& event)
{
EVENTQUEUE->dispatchEvent(CEvent(event.getType(),
getEventTarget(), event.getData()));
}
void
CStreamFilter::handleUpstreamEvent(const CEvent& event, void*)
{
filterEvent(event);
}

View File

@@ -33,19 +33,17 @@ public:
~CStreamFilter();
// IStream overrides
// These all just forward to the underlying stream. Override as
// necessary.
// These all just forward to the underlying stream except getEventTarget.
// Override as necessary. getEventTarget returns a pointer to this.
virtual void close();
virtual UInt32 read(void* buffer, UInt32 n);
virtual void write(const void* buffer, UInt32 n);
virtual void flush();
virtual void shutdownInput();
virtual void shutdownOutput();
virtual void setEventFilter(IEventJob* filter);
virtual void* getEventTarget() const;
virtual bool isReady() const;
virtual UInt32 getSize() const;
virtual IEventJob* getEventFilter() const;
protected:
//! Get the stream
@@ -54,6 +52,16 @@ protected:
*/
IStream* getStream() const;
//! Handle events from source stream
/*!
Does the event filtering. The default simply dispatches an event
identical except using this object as the event target.
*/
virtual void filterEvent(const CEvent&);
private:
void handleUpstreamEvent(const CEvent&, void*);
private:
IStream* m_stream;
bool m_adopted;

View File

@@ -18,8 +18,6 @@
#include "IInterface.h"
#include "CEvent.h"
class IEventJob;
//! Bidirectional stream interface
/*!
Defines the interface for all streams.
@@ -77,22 +75,14 @@ public:
*/
virtual void shutdownOutput() = 0;
//! Set the event filter
/*!
If not NULL, the \p filter is passed any event that would've been
added to the queue. The filter can discard the event, modify it
and add it to the queue, and add other events. The default filter
is NULL. The caller retains ownership of the filter.
*/
virtual void setEventFilter(IEventJob* filter) = 0;
//@}
//! @name accessors
//@{
//! Get event target
/*!
Returns the event target for events generated by this stream.
Returns the event target for events generated by this stream. It
should be the source stream in a chain of stream filters.
*/
virtual void* getEventTarget() const = 0;
@@ -113,12 +103,6 @@ public:
*/
virtual UInt32 getSize() const = 0;
//! Get the event filter
/*!
Returns the current event filter.
*/
virtual IEventJob* getEventFilter() const = 0;
//! Get input ready event type
/*!
Returns the input ready event type. A stream sends this event