Line data Source code
1 : /* 2 : * 3 : * 4 : * Distributed under the OpenDDS License. 5 : * See: http://www.opendds.org/license.html 6 : */ 7 : 8 : #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/ 9 : #include "SendStateDataSampleList.h" 10 : #include "DataSampleElement.h" 11 : #include "Definitions.h" 12 : #include "PublicationInstance.h" 13 : 14 : #include "transport/framework/TransportSendListener.h" 15 : 16 : #if !defined (__ACE_INLINE__) 17 : #include "SendStateDataSampleList.inl" 18 : #endif /* __ACE_INLINE__ */ 19 : 20 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 21 : 22 : namespace OpenDDS { 23 : namespace DCPS { 24 : 25 : 26 : const SendStateDataSampleList* 27 0 : SendStateDataSampleList::send_list_containing_element(const DataSampleElement* element, 28 : SendStateDataSampleList** begin, 29 : SendStateDataSampleList** end) 30 : { 31 0 : const DataSampleElement* head = element; 32 : 33 0 : while (head->previous_send_sample_ != 0) { 34 0 : head = head->previous_send_sample_; 35 : } 36 : 37 0 : for (SendStateDataSampleList** it = begin; it != end; ++it) { 38 0 : if ((*it)->head_ == head) { 39 0 : return *it; 40 : } 41 : } 42 0 : return 0; 43 : } 44 : 45 : 46 : bool 47 0 : SendStateDataSampleList::dequeue(const DataSampleElement* stale) 48 : { 49 0 : if (head_ == 0) { 50 0 : return false; 51 : } 52 : 53 : // Same as dequeue from head. 54 0 : if (stale == head_) { 55 0 : DataSampleElement* tmp = head_; 56 0 : return dequeue_head(tmp); 57 : } 58 : 59 : // Search from head_->next_send_sample_. 60 0 : DataSampleElement* toRemove = 0; 61 0 : for (DataSampleElement* item = head_->next_send_sample_; 62 0 : item != 0 && toRemove == 0; 63 0 : item = item->next_send_sample_) { 64 0 : if (item == stale) { 65 0 : toRemove = item; 66 : } 67 : } 68 : 69 0 : if (toRemove) { 70 0 : --size_; 71 : // Remove from the previous element. 72 0 : toRemove->previous_send_sample_->next_send_sample_ = toRemove->next_send_sample_; 73 : 74 : // Remove from the next element. 75 0 : if (toRemove->next_send_sample_ != 0) { 76 : // Remove from the inside of the list. 77 0 : toRemove->next_send_sample_->previous_send_sample_ = toRemove->previous_send_sample_; 78 : 79 : } else { 80 : // Remove from the tail of the list. 81 0 : tail_ = toRemove->previous_send_sample_; 82 : } 83 : 84 0 : toRemove->next_send_sample_ = 0; 85 0 : toRemove->previous_send_sample_ = 0; 86 : } 87 : 88 0 : return toRemove != 0; 89 : } 90 : 91 : void 92 0 : SendStateDataSampleList::enqueue_tail(SendStateDataSampleList list) 93 : { 94 0 : if (head_ == 0) { 95 0 : head_ = list.head_; 96 0 : tail_ = list.tail_; 97 0 : size_ = list.size_; 98 : 99 : } else { 100 0 : tail_->next_send_sample_ = list.head_; 101 0 : list.head_->previous_send_sample_ = tail_; 102 0 : tail_ = list.tail_; 103 0 : size_ = size_ + list.size_; 104 : } 105 0 : } 106 : 107 : // ----------------------------------------------- 108 : 109 0 : SendStateDataSampleListIterator::SendStateDataSampleListIterator( 110 : DataSampleElement* head, 111 : DataSampleElement* tail, 112 0 : DataSampleElement* current) 113 0 : : head_(head) 114 0 : , tail_(tail) 115 0 : , current_(current) 116 : { 117 0 : } 118 : 119 : SendStateDataSampleListIterator& 120 0 : SendStateDataSampleListIterator::operator++() 121 : { 122 0 : if (this->current_) { 123 0 : this->current_ = this->current_->next_send_sample_; 124 : } 125 : 126 0 : return *this; 127 : } 128 : 129 : SendStateDataSampleListIterator 130 0 : SendStateDataSampleListIterator::operator++(int) 131 : { 132 0 : SendStateDataSampleListIterator tmp(*this); 133 0 : ++(*this); 134 0 : return tmp; 135 : } 136 : 137 : SendStateDataSampleListIterator& 138 0 : SendStateDataSampleListIterator::operator--() 139 : { 140 0 : if (this->current_) { 141 0 : this->current_ = this->current_->previous_send_sample_; 142 : } else { 143 0 : this->current_ = this->tail_; 144 : } 145 : 146 0 : return *this; 147 : } 148 : 149 : SendStateDataSampleListIterator 150 0 : SendStateDataSampleListIterator::operator--(int) 151 : { 152 0 : SendStateDataSampleListIterator tmp(*this); 153 0 : --(*this); 154 0 : return tmp; 155 : } 156 : 157 : SendStateDataSampleListIterator::reference 158 0 : SendStateDataSampleListIterator::operator*() 159 : { 160 : // Hopefully folks will be smart enough to not dereference a 161 : // null iterator. Such a case should only exist for an "end" 162 : // iterator. Otherwise we may want to throw an exception here. 163 : // assert (this->current_ != 0); 164 : 165 0 : return *(this->current_); 166 : } 167 : 168 : SendStateDataSampleListIterator::pointer 169 0 : SendStateDataSampleListIterator::operator->() 170 : { 171 0 : return this->current_; 172 : } 173 : 174 0 : SendStateDataSampleListConstIterator::SendStateDataSampleListConstIterator( 175 : const DataSampleElement* head, 176 : const DataSampleElement* tail, 177 0 : const DataSampleElement* current) 178 0 : : head_(head) 179 0 : , tail_(tail) 180 0 : , current_(current) 181 : { 182 0 : } 183 : 184 0 : SendStateDataSampleListConstIterator::SendStateDataSampleListConstIterator( 185 0 : const SendStateDataSampleListIterator& iterator) 186 0 : : head_(iterator.head_) 187 0 : , tail_(iterator.tail_) 188 0 : , current_(iterator.current_) 189 : { 190 0 : } 191 : 192 : SendStateDataSampleListConstIterator& 193 0 : SendStateDataSampleListConstIterator::operator++() 194 : { 195 0 : if (this->current_) { 196 0 : this->current_ = this->current_->next_send_sample_; 197 : } 198 : 199 0 : return *this; 200 : } 201 : 202 : SendStateDataSampleListConstIterator 203 0 : SendStateDataSampleListConstIterator::operator++(int) 204 : { 205 0 : SendStateDataSampleListConstIterator tmp(*this); 206 0 : ++(*this); 207 0 : return tmp; 208 : } 209 : 210 : SendStateDataSampleListConstIterator& 211 0 : SendStateDataSampleListConstIterator::operator--() 212 : { 213 0 : if (this->current_) { 214 0 : this->current_ = this->current_->previous_send_sample_; 215 : } else { 216 0 : this->current_ = this->tail_; 217 : } 218 : 219 0 : return *this; 220 : } 221 : 222 : SendStateDataSampleListConstIterator 223 0 : SendStateDataSampleListConstIterator::operator--(int) 224 : { 225 0 : SendStateDataSampleListConstIterator tmp(*this); 226 0 : --(*this); 227 0 : return tmp; 228 : } 229 : 230 : SendStateDataSampleListConstIterator::reference 231 0 : SendStateDataSampleListConstIterator::operator*() const 232 : { 233 : // Hopefully folks will be smart enough to not dereference a 234 : // null iterator. Such a case should only exist for an "end" 235 : // iterator. Otherwise we may want to throw an exception here. 236 : // assert (this->current_ != 0); 237 : 238 0 : return *(this->current_); 239 : } 240 : 241 : SendStateDataSampleListConstIterator::pointer 242 0 : SendStateDataSampleListConstIterator::operator->() const 243 : { 244 0 : return this->current_; 245 : } 246 : 247 : } // namespace DCPS 248 : } // namespace OpenDDS 249 : 250 : OPENDDS_END_VERSIONED_NAMESPACE_DECL