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 #ifndef _streamdelegatedispatch_h 00018 #define _streamdelegatedispatch_h 00019 00020 #include <spl/types.h> 00021 #include <spl/Debug.h> 00022 00023 #include <spl/DelegateDispatch.h> 00024 #include <spl/io/IStream.h> 00025 #include <spl/Memory.h> 00026 #include <spl/RefCountPtr.h> 00027 #include <spl/RefCountPtrCast.h> 00028 #include <spl/String.h> 00029 00039 class StreamDelegateDispatch : public IMemoryValidate 00040 { 00041 private: 00042 DelegateDispatch m_onClose; 00043 DelegateDispatchOneParameter<const String&> m_onError; 00044 DelegateDispatchTwoParameter<const Array<byte>&, int> m_onRead; 00045 00046 public: 00047 inline StreamDelegateDispatch() 00048 : m_onClose(), m_onError(), m_onRead() 00049 { 00050 } 00051 00052 virtual ~StreamDelegateDispatch(); 00053 00054 inline DelegateDispatch& OnClose() { return m_onClose; } 00055 inline DelegateDispatchOneParameter<const String&>& OnError() { return m_onError; } 00056 inline DelegateDispatchTwoParameter<const Array<byte>&, int>& OnRead() { return m_onRead; } 00057 00058 inline void DispatchOnClose() { m_onClose.Call(); } 00059 inline void DispatchOnError(const String& msg) { m_onError.Call(msg); } 00060 inline void DispatchOnRead(const Array<byte>&a, int len) { m_onRead.Call(a, len); } 00061 00063 void Add(IStreamReadListener* l); 00064 00065 #ifdef DEBUG 00066 virtual void ValidateMem() const; 00067 virtual void CheckMem() const; 00068 #endif 00069 }; 00070 00071 REGISTER_TYPEOF(130, StreamDelegateDispatch); 00072 00075 #endif