• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/io/StreamReadPump.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL 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  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #include <spl/io/Stream.h>
00018 
00019 #ifdef _stream2_h
00020 /* _stream2_h is in Stream.h, only compile this file if using the new Stream.h header */
00021 
00022 #ifndef _streamreadpump_h
00023 #define _streamreadpump_h
00024 
00025 #include <spl/collection/Array.h>
00026 #include <spl/DelegateDispatch.h>
00027 #include <spl/io/StreamDelegateDispatch.h>
00028 #include <spl/threading/Thread.h>
00029 
00040 class StreamReadPump : public Thread
00041 {
00042 private:
00043         // forbid copy constructor
00044         inline StreamReadPump(const StreamReadPump& pmp) {}
00045         inline void operator =(const StreamReadPump& pmp) {}
00046 
00047 protected:
00048         spl::IStreamPtr m_strm;
00049         volatile bool m_running;
00050         Array<byte> m_buf;
00051         int m_bufsize;
00052 
00053         StreamDelegateDispatch m_eventDispatch;
00054 
00055 public:
00056         StreamReadPump(spl::IStreamPtr strm, int bufsize = 512);
00057         ~StreamReadPump();
00058 
00059         inline spl::IStreamPtr GetStream() { return m_strm; }
00060 
00061         void Run();
00062         void Stop();
00063 
00064         inline StreamDelegateDispatch& Delegates() { return m_eventDispatch; }
00065 
00066 #ifdef DEBUG
00067         virtual void ValidateMem() const;
00068         virtual void CheckMem() const;
00069 #endif
00070 };
00071 
00072 REGISTER_TYPEOF(132, StreamReadPump);
00073 
00076 #endif
00077 #endif