CStreamFilter.cpp

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2004 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "CStreamFilter.h"
00016 #include "IEventQueue.h"
00017 #include "TMethodEventJob.h"
00018 
00019 //
00020 // CStreamFilter
00021 //
00022 
00023 CStreamFilter::CStreamFilter(IStream* stream, bool adoptStream) :
00024     m_stream(stream),
00025     m_adopted(adoptStream)
00026 {
00027     // replace handlers for m_stream
00028     EVENTQUEUE->removeHandlers(m_stream->getEventTarget());
00029     EVENTQUEUE->adoptHandler(CEvent::kUnknown, m_stream->getEventTarget(),
00030                             new TMethodEventJob<CStreamFilter>(this,
00031                                 &CStreamFilter::handleUpstreamEvent));
00032 }
00033 
00034 CStreamFilter::~CStreamFilter()
00035 {
00036     EVENTQUEUE->removeHandler(CEvent::kUnknown, m_stream->getEventTarget());
00037     if (m_adopted) {
00038         delete m_stream;
00039     }
00040 }
00041 
00042 void
00043 CStreamFilter::close()
00044 {
00045     getStream()->close();
00046 }
00047 
00048 UInt32
00049 CStreamFilter::read(void* buffer, UInt32 n)
00050 {
00051     return getStream()->read(buffer, n);
00052 }
00053 
00054 void
00055 CStreamFilter::write(const void* buffer, UInt32 n)
00056 {
00057     getStream()->write(buffer, n);
00058 }
00059 
00060 void
00061 CStreamFilter::flush()
00062 {
00063     getStream()->flush();
00064 }
00065 
00066 void
00067 CStreamFilter::shutdownInput()
00068 {
00069     getStream()->shutdownInput();
00070 }
00071 
00072 void
00073 CStreamFilter::shutdownOutput()
00074 {
00075     getStream()->shutdownOutput();
00076 }
00077 
00078 void*
00079 CStreamFilter::getEventTarget() const
00080 {
00081     return const_cast<void*>(reinterpret_cast<const void*>(this));
00082 }
00083 
00084 bool
00085 CStreamFilter::isReady() const
00086 {
00087     return getStream()->isReady();
00088 }
00089 
00090 UInt32
00091 CStreamFilter::getSize() const
00092 {
00093     return getStream()->getSize();
00094 }
00095 
00096 IStream*
00097 CStreamFilter::getStream() const
00098 {
00099     return m_stream;
00100 }
00101 
00102 void
00103 CStreamFilter::filterEvent(const CEvent& event)
00104 {
00105     EVENTQUEUE->dispatchEvent(CEvent(event.getType(),
00106                         getEventTarget(), event.getData()));
00107 }
00108 
00109 void
00110 CStreamFilter::handleUpstreamEvent(const CEvent& event, void*)
00111 {
00112     filterEvent(event);
00113 }

Generated on Fri Nov 6 00:18:45 2009 for synergy-plus by  doxygen 1.4.7