00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _threadsafestream_h
00018 #define _threadsafestream_h
00019
00020 #include <stdio.h>
00021
00022 #include <spl/types.h>
00023 #include <spl/Debug.h>
00024 #include <spl/threading/Event.h>
00025 #include <spl/threading/Mutex.h>
00026 #include <spl/io/IStream.h>
00027 #include <spl/Memory.h>
00028 #include <spl/RefCountPtrCast.h>
00029 #include <spl/io/Stream.h>
00030 #include <spl/String.h>
00031 #include <spl/collection/Vector.h>
00032
00044 class ThreadSafeStream;
00045 typedef RefCountPtrCast<ThreadSafeStream, spl::IStream, spl::IStreamPtr> ThreadSafeStreamPtr;
00046 typedef WeakReference<ThreadSafeStream, spl::IStreamPtr> ThreadSafeStreamRef;
00047
00048 REGISTER_TYPEOF(148, ThreadSafeStreamPtr);
00049 REGISTER_TYPEOF( 470, ThreadSafeStreamRef );
00050
00052 class ThreadSafeStream : public spl::IStream
00053 {
00054 protected:
00055 spl::IStreamPtr m_strm;
00056 Mutex m_lock;
00057
00058 public:
00059 ThreadSafeStream( spl::IStreamPtr strm );
00060 virtual ~ThreadSafeStream();
00061
00062 inline void Lock() { m_lock.Lock(); }
00063 inline void Unlock() { m_lock.Unlock(); }
00064
00065 virtual void Close();
00066 virtual void Flush();
00067 virtual int Read(Array<byte>& buffer, const int offset, int count);
00068 virtual int ReadByte();
00069 virtual long Seek(const long offset, const SeekOrigin origin);
00070 virtual void Write(const Array<byte>& buffer, const int offset, const int count);
00071 virtual void WriteByte(byte value);
00072
00073 virtual bool CanRead() const;
00074 virtual bool CanSeek() const;
00075 virtual bool CanWrite() const;
00076
00077 virtual long Length() const;
00078 virtual long Position() const;
00079
00080 #ifdef DEBUG
00081 virtual void ValidateMem() const;
00082 virtual void CheckMem() const;
00083 #endif
00084 };
00085
00086 REGISTER_TYPEOF(150, ThreadSafeStream);
00087
00091 #endif