00001 /* Copyright (C) 2002 Carsten Griwodz 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, this code may be used in unmodified form 00006 * provided that this copyright notice and this permission notice appear 00007 * in supporting documentation. 00008 * 00009 * The code may be made subject to the terms of the GNU General Public 00010 * License, Version 2, and re-distributed under the terms of this license. 00011 * 00012 * Commercial use other than under the terms of the GNU General Public 00013 * License is allowed only after negotiation of conditions with the authors. 00014 */ 00015 #ifndef DUMMY_LIST_H 00016 #define DUMMY_LIST_H 00017 00018 #include <sys/types.h> 00019 00020 #include "MNList.h" 00021 #include "MNTimeval.h" 00022 #include "SHData.h" 00023 00024 namespace SH 00025 { 00026 00027 class DummyLayerSourceSH; 00028 00033 class DummyListBase 00034 { 00035 public: 00036 struct entry 00037 { 00038 u_int32_t sequence_number; 00039 u_int32_t priority; 00040 u_int32_t length; 00041 }; 00042 00043 DummyListBase( ) { } 00044 virtual ~DummyListBase( ) { } 00045 00046 virtual void init( u_int32_t initial_fill, 00047 u_int32_t blocksize, 00048 u_int32_t bandwidth ) = 0; 00049 virtual u_int32_t runtimeSec( ) = 0; 00050 virtual void setSeqno( u_int32_t ) = 0; 00051 virtual void setMaxSeqno( u_int32_t ) = 0; 00052 virtual void compress_queue( u_int32_t q_len ) = 0; 00053 00054 virtual void fill( ) = 0; 00055 00056 virtual u_int32_t get( DataPtr& item ) = 0; 00057 virtual void put( DataPtr item ) = 0; 00058 00059 virtual u_int32_t size() const = 0; 00060 00061 virtual bool eof() const = 0; 00062 00063 private: 00064 DummyListBase( const DummyListBase& ); 00065 DummyListBase& operator=( const DummyListBase& ); 00066 }; 00067 00068 class DummyList : public DummyListBase 00069 { 00070 struct EntryList 00071 { 00072 MNList<entry> _list; 00073 u_int32_t _bytelen; 00074 00075 inline void* first() { 00076 return _list.first(); 00077 } 00078 inline void* succ(void* p) { 00079 return _list.succ(p); 00080 } 00081 inline bool empty() const { 00082 return _list.empty(); 00083 } 00084 inline void push_back( entry& e ) { 00085 push_back(e); 00086 _bytelen += e.length; 00087 } 00088 inline entry inf(void* p) { 00089 return _list.inf(p); 00090 } 00091 inline const entry& inf(void* p) const { 00092 return _list.inf(p); 00093 } 00094 inline entry pop( ) { 00095 _bytelen -= _list.peek_front().length; 00096 return _list.pop(); 00097 } 00098 inline void del_item(void* p) { 00099 _bytelen -= _list.inf(p).length; 00100 _list.del_item(p); 00101 } 00102 inline u_int32_t bytelength() const { 00103 return _bytelen; 00104 } 00105 inline u_int32_t length() const { 00106 return _list.length(); 00107 } 00108 }; 00109 00110 EntryList l; 00111 bool _autofill; 00112 Timeval _start_time; 00113 Timeval _run_time; 00114 u_int32_t _seq_no; 00115 u_int32_t _max_seq_no; 00116 u_int32_t _pri_idx; 00117 u_int32_t _pri_len; 00118 uchar_t* _pri; 00119 u_int32_t _blocksize; 00120 u_int32_t _initial_fill; 00121 u_int32_t _q_len; 00122 u_int32_t _packets_pulled; 00123 u_int32_t _bandwidth; 00124 public: 00125 DummyList( bool autofill ); 00126 ~DummyList( ); 00127 00128 void init( u_int32_t initial_fill, 00129 u_int32_t blocksize, 00130 u_int32_t bandwidth ); 00131 u_int32_t runtimeSec( ); 00132 void setPri( const char* pri ); 00133 void setSeqno( u_int32_t ); 00134 void setMaxSeqno( u_int32_t ); 00135 void compress_queue( u_int32_t q_len ); 00136 00137 void fill( ); 00138 00139 u_int32_t get( DataPtr& item ); 00140 void put( DataPtr item ); 00141 00142 inline u_int32_t getBlocksize() const { 00143 return _blocksize; 00144 } 00145 00146 inline u_int32_t size() const { 00147 return l.length(); 00148 } 00149 00150 inline bool eof() const { 00151 return ( _seq_no >= _max_seq_no ); 00152 } 00153 private: 00157 bool remove_one_from_queue( u_int32_t pri ); 00158 00159 u_int32_t pull_dummy( u_int32_t& seqno, u_int32_t& pri ); 00160 00161 private: 00162 DummyList( ); 00163 DummyList( const DummyList& ); 00164 DummyList& operator=( const DummyList& ); 00165 }; 00166 00168 00169 }; // namespace SH 00170 00171 #endif /* DUMMY_LIST_H */ 00172