Line data Source code
1 : /* 2 : * 3 : * 4 : * Distributed under the OpenDDS License. 5 : * See: http://www.opendds.org/license.html 6 : */ 7 : 8 : #ifndef OPENDDS_DCPS_SENDSTATEDATASAMPLELIST_H 9 : #define OPENDDS_DCPS_SENDSTATEDATASAMPLELIST_H 10 : 11 : #include "PoolAllocator.h" 12 : #include "Definitions.h" 13 : #include "Dynamic_Cached_Allocator_With_Overflow_T.h" 14 : 15 : #include "transport/framework/TransportDefs.h" 16 : #include "dds/DdsDcpsInfoUtilsC.h" 17 : 18 : #include <ace/config-lite.h> 19 : 20 : #include <iterator> 21 : 22 : class DDS_TEST; 23 : 24 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 25 : 26 : namespace OpenDDS { 27 : namespace DCPS { 28 : 29 : class DataSampleElement; 30 : 31 : const int MAX_READERS_TO_RESEND = 5; 32 : 33 : /** 34 : * @struct SendStateDataSampleListIterator 35 : * 36 : * @brief @c SendStateDataSampleList STL-style iterator implementation. 37 : * 38 : * This class implements a STL-style iterator for the OpenDDS 39 : * @c SendStateDataSampleList class. The resulting iterator may be used 40 : * @c with the STL generic algorithms. It is meant for iteration 41 : * @c over the "send samples" in a @c SendStateDataSampleList. 42 : */ 43 : class OpenDDS_Dcps_Export SendStateDataSampleListIterator { 44 : public: 45 : typedef std::bidirectional_iterator_tag iterator_category; 46 : typedef DataSampleElement value_type; 47 : typedef std::ptrdiff_t difference_type; 48 : typedef value_type* pointer; 49 : typedef value_type& reference; 50 : 51 : /// Default constructor required by ForwardIterator concept 52 : SendStateDataSampleListIterator() {} 53 : 54 : /** 55 : * This constructor is used when constructing an "end" iterator. 56 : */ 57 : SendStateDataSampleListIterator(DataSampleElement* head, 58 : DataSampleElement* tail, 59 : DataSampleElement* current); 60 : 61 : SendStateDataSampleListIterator& operator++(); 62 : SendStateDataSampleListIterator operator++(int); 63 : SendStateDataSampleListIterator& operator--(); 64 : SendStateDataSampleListIterator operator--(int); 65 : 66 : reference operator*(); 67 : pointer operator->(); 68 : 69 : bool 70 0 : operator==(const SendStateDataSampleListIterator& rhs) const { 71 0 : return this->head_ == rhs.head_ 72 0 : && this->tail_ == rhs.tail_ 73 0 : && this->current_ == rhs.current_; 74 : } 75 : 76 : bool 77 0 : operator!=(const SendStateDataSampleListIterator& rhs) const { 78 0 : return !(*this == rhs); 79 : } 80 : 81 : private: 82 : DataSampleElement* head_; 83 : DataSampleElement* tail_; 84 : DataSampleElement* current_; 85 : 86 : friend class SendStateDataSampleListConstIterator; 87 : }; 88 : 89 : /** 90 : * @struct SendStateDataSampleListConstIterator 91 : * 92 : * @brief @c SendStateDataSampleList STL-style const iterator implementation. 93 : * 94 : * This class implements a STL-style const iterator for the OpenDDS 95 : * @c SendStateDataSampleList class. The resulting iterator may be used 96 : * @c with the STL generic algorithms. It is meant for iteration 97 : * @c over the "send samples" in a @c SendStateDataSampleList. 98 : */ 99 : class OpenDDS_Dcps_Export SendStateDataSampleListConstIterator { 100 : public: 101 : typedef std::bidirectional_iterator_tag iterator_category; 102 : typedef const DataSampleElement value_type; 103 : typedef std::ptrdiff_t difference_type; 104 : typedef const DataSampleElement* pointer; 105 : typedef const DataSampleElement& reference; 106 : 107 : /// Default constructor required by ForwardIterator concept 108 : SendStateDataSampleListConstIterator() {} 109 : 110 : SendStateDataSampleListConstIterator(const DataSampleElement* head, 111 : const DataSampleElement* tail, 112 : const DataSampleElement* current); 113 : 114 : SendStateDataSampleListConstIterator(const SendStateDataSampleListIterator& iterator); 115 : 116 : SendStateDataSampleListConstIterator& operator++(); 117 : SendStateDataSampleListConstIterator operator++(int); 118 : SendStateDataSampleListConstIterator& operator--(); 119 : SendStateDataSampleListConstIterator operator--(int); 120 : reference operator*() const; 121 : pointer operator->() const; 122 : 123 : bool 124 0 : operator==(const SendStateDataSampleListConstIterator& rhs) const { 125 0 : return this->head_ == rhs.head_ 126 0 : && this->tail_ == rhs.tail_ 127 0 : && this->current_ == rhs.current_; 128 : } 129 : 130 : bool 131 : operator!=(const SendStateDataSampleListConstIterator& rhs) const { 132 : return !(*this == rhs); 133 : } 134 : 135 : private: 136 : const DataSampleElement* head_; 137 : const DataSampleElement* tail_; 138 : const DataSampleElement* current_; 139 : 140 : }; 141 : 142 : /** 143 : * A list of DataSampleElement pointers to be queued by the order the 144 : * samples are to be transmitted over the transport layer. 145 : * Cache the number of elements in the list so that list traversal is 146 : * not required to find this information. 147 : * The Publisher may use this to maintain a list of samples to 148 : * be sent with PRESENTATION.access_scope==GROUP by obtaining 149 : * data from each DataWriter as it becomes available and 150 : * concatenating the data in the order in which it was written. 151 : * Manages DataSampleElement's previous_send_sample/next_send_sample pointers 152 : */ 153 : class OpenDDS_Dcps_Export SendStateDataSampleList { 154 : 155 : friend class ::DDS_TEST; 156 : 157 : static const SendStateDataSampleList* 158 : send_list_containing_element(const DataSampleElement* element, 159 : SendStateDataSampleList** begin, 160 : SendStateDataSampleList** end); 161 : 162 : public: 163 : 164 : /// STL-style bidirectional iterator and const-iterator types. 165 : typedef SendStateDataSampleListIterator iterator; 166 : typedef SendStateDataSampleListConstIterator const_iterator; 167 : 168 : typedef std::reverse_iterator<iterator> reverse_iterator; 169 : typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 170 : 171 : /// Default constructor clears the list. 172 : SendStateDataSampleList(); 173 0 : ~SendStateDataSampleList() {} 174 : 175 : /// Returns a pointer to the SendStateDataSampleList containing a 176 : /// given DataSampleElement for use in the typical situation where 177 : /// the send state of a DataSampleElement is tracked by shifting 178 : /// it between distinct SendStateDataSampleLists, one for each state 179 : template <size_t N> 180 : static const SendStateDataSampleList* 181 0 : send_list_containing_element(const DataSampleElement* element, 182 : SendStateDataSampleList* (&send_lists)[N]) 183 : { 184 0 : return send_list_containing_element(element, 185 0 : &send_lists[0], &send_lists[N]); 186 : } 187 : 188 : /// Reset to initial state. 189 : void reset(); 190 : 191 : ssize_t size() const; 192 : DataSampleElement* head() const; 193 : DataSampleElement* tail() const; 194 : 195 : void enqueue_head(const DataSampleElement* element); 196 : 197 : void enqueue_tail(const DataSampleElement* element); 198 : void enqueue_tail(SendStateDataSampleList list); 199 : 200 : bool dequeue_head(DataSampleElement*& stale); 201 : 202 : bool dequeue(const DataSampleElement* stale); 203 : 204 : /// Remove from whichever list "stale" belongs to, without needing 205 : /// a reference to the SendStateDataSampleList object itself. 206 : /// That SendStateDataSampleList is no longer accurate and can't be used. 207 : static void remove(DataSampleElement* stale); 208 : 209 : /// Return iterator to beginning of list. 210 : iterator begin(); 211 : const_iterator begin() const; 212 : 213 : /// Return iterator to end of list. 214 : iterator end(); 215 : const_iterator end() const; 216 : 217 : reverse_iterator rbegin(); 218 : const_reverse_iterator rbegin() const; 219 : reverse_iterator rend(); 220 : const_reverse_iterator rend() const; 221 : 222 : protected: 223 : 224 : /// The first element of the list. 225 : DataSampleElement* head_; 226 : 227 : /// The last element of the list. 228 : DataSampleElement* tail_; 229 : 230 : /// Number of elements in the list. 231 : ssize_t size_; 232 : //TBD size is never negative so should be size_t but this ripples through 233 : // the transport code so leave it for now. SHH 234 : 235 : }; 236 : 237 : } // namespace DCPS 238 : } // namespace OpenDDS 239 : 240 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 241 : 242 : #if defined(__ACE_INLINE__) 243 : #include "SendStateDataSampleList.inl" 244 : #endif /* __ACE_INLINE__ */ 245 : 246 : #endif /* OPENDDS_DCPS_SENDSTATEDATASAMPLELIST_H */