• Main Page
  • Classes
  • Files
  • File List

CStreamFilter.cpp

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

Generated on Sat May 25 2013 00:00:04 for Synergy by  doxygen 1.7.1