00001 /*MT* 00002 00003 MediaTomb - http://www.mediatomb.cc/ 00004 00005 io_handler_buffer_helper.h - this file is part of MediaTomb. 00006 00007 Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>, 00008 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc> 00009 00010 Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>, 00011 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>, 00012 Leonhard Wimmer <leo@mediatomb.cc> 00013 00014 MediaTomb is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU General Public License version 2 00016 as published by the Free Software Foundation. 00017 00018 MediaTomb is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 version 2 along with MediaTomb; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00026 00027 $Id: io_handler_buffer_helper.h 2081 2010-03-23 20:18:00Z lww $ 00028 */ 00029 00031 00032 #ifndef __IO_HANDLER_BUFFER_HELPER_H__ 00033 #define __IO_HANDLER_BUFFER_HELPER_H__ 00034 00035 #include <pthread.h> 00036 00037 #include "common.h" 00038 #include "upnp.h" 00039 #include "io_handler.h" 00040 #include "sync.h" 00041 00045 class IOHandlerBufferHelper : public IOHandler 00046 { 00047 public: 00048 00055 IOHandlerBufferHelper(size_t bufSize, size_t initialFillSize); 00056 virtual ~IOHandlerBufferHelper(); 00057 00058 // inherited from IOHandler 00059 virtual void open(enum UpnpOpenFileMode mode); 00060 virtual int read(char *buf, size_t length); 00061 virtual void seek(off_t offset, int whence); 00062 virtual void close(); 00063 00064 protected: 00065 size_t bufSize; 00066 size_t initialFillSize; 00067 char* buffer; 00068 bool isOpen; 00069 bool eof; 00070 bool readError; 00071 bool waitForInitialFillSize; 00072 bool signalAfterEveryRead; 00073 bool checkSocket; 00074 00075 // buffer stuff.. 00076 bool empty; 00077 size_t a; 00078 size_t b; 00079 off_t posRead; 00080 00081 // seek stuff... 00082 bool seekEnabled; 00083 bool doSeek; 00084 off_t seekOffset; 00085 int seekWhence; 00086 00087 // thread stuff.. 00088 void startBufferThread(); 00089 void stopBufferThread(); 00090 static void *staticThreadProc(void *arg); 00091 virtual void threadProc() = 0; 00092 00093 pthread_t bufferThread; 00094 bool threadShutdown; 00095 zmm::Ref<Cond> cond; 00096 zmm::Ref<Mutex> mutex; 00097 }; 00098 00099 #endif // __IO_HANDLER_BUFFER_HELPER_H__
1.6.1