SendStateDataSampleList.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #ifndef OPENDDS_DCPS_SENDSTATEDATASAMPLELIST_H
00009 #define OPENDDS_DCPS_SENDSTATEDATASAMPLELIST_H
00010 
00011 #include "dds/DdsDcpsInfoUtilsC.h"
00012 #include "PoolAllocator.h"
00013 #include "Definitions.h"
00014 #include "transport/framework/TransportDefs.h"
00015 #include "Dynamic_Cached_Allocator_With_Overflow_T.h"
00016 #include "ace/config-lite.h"
00017 
00018 #include <iterator>
00019 
00020 class DDS_TEST;
00021 
00022 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 namespace OpenDDS {
00025 namespace DCPS {
00026 
00027 class DataSampleElement;
00028 
00029 const int MAX_READERS_TO_RESEND = 5;
00030 
00031 /**
00032  * @struct SendStateDataSampleListIterator
00033  *
00034  * @brief @c SendStateDataSampleList STL-style iterator implementation.
00035  *
00036  * This class implements a STL-style iterator for the OpenDDS
00037  * @c SendStateDataSampleList class.  The resulting iterator may be used
00038  * @c with the STL generic algorithms.  It is meant for iteration
00039  * @c over the "send samples" in a @c SendStateDataSampleList.
00040  */
00041 class OpenDDS_Dcps_Export SendStateDataSampleListIterator
00042   : public std::iterator<std::bidirectional_iterator_tag, DataSampleElement>
00043 {
00044 public:
00045 
00046   /// Default constructor required by ForwardIterator concept
00047   SendStateDataSampleListIterator(){}
00048 
00049   /**
00050    * This constructor is used when constructing an "end" iterator.
00051    */
00052   SendStateDataSampleListIterator(DataSampleElement* head,
00053                          DataSampleElement* tail,
00054                          DataSampleElement* current);
00055 
00056   SendStateDataSampleListIterator& operator++();
00057   SendStateDataSampleListIterator  operator++(int);
00058   SendStateDataSampleListIterator& operator--();
00059   SendStateDataSampleListIterator  operator--(int);
00060 
00061   reference operator*();
00062   pointer operator->();
00063 
00064   bool
00065   operator==(const SendStateDataSampleListIterator& rhs) const {
00066     return this->head_ == rhs.head_
00067            && this->tail_ == rhs.tail_
00068            && this->current_ == rhs.current_;
00069   }
00070 
00071   bool
00072   operator!=(const SendStateDataSampleListIterator& rhs) const {
00073     return !(*this == rhs);
00074   }
00075 
00076 private:
00077   DataSampleElement* head_;
00078   DataSampleElement* tail_;
00079   DataSampleElement* current_;
00080 
00081   friend class SendStateDataSampleListConstIterator;
00082 };
00083 
00084 /**
00085  * @struct SendStateDataSampleListConstIterator
00086  *
00087  * @brief @c SendStateDataSampleList STL-style const iterator implementation.
00088  *
00089  * This class implements a STL-style const iterator for the OpenDDS
00090  * @c SendStateDataSampleList class.  The resulting iterator may be used
00091  * @c with the STL generic algorithms.  It is meant for iteration
00092  * @c over the "send samples" in a @c SendStateDataSampleList.
00093  */
00094 class OpenDDS_Dcps_Export SendStateDataSampleListConstIterator
00095   : public std::iterator<std::bidirectional_iterator_tag, DataSampleElement>
00096 {
00097 public:
00098   typedef const DataSampleElement* pointer;
00099   typedef const DataSampleElement& reference;
00100 
00101   /// Default constructor required by ForwardIterator concept
00102   SendStateDataSampleListConstIterator(){}
00103 
00104   SendStateDataSampleListConstIterator(const DataSampleElement* head,
00105                                   const DataSampleElement* tail,
00106                                   const DataSampleElement* current);
00107 
00108   SendStateDataSampleListConstIterator(const SendStateDataSampleListIterator& iterator);
00109 
00110   SendStateDataSampleListConstIterator& operator++();
00111   SendStateDataSampleListConstIterator  operator++(int);
00112   SendStateDataSampleListConstIterator& operator--();
00113   SendStateDataSampleListConstIterator  operator--(int);
00114   reference operator*() const;
00115   pointer operator->() const;
00116 
00117   bool
00118   operator==(const SendStateDataSampleListConstIterator& rhs) const {
00119     return this->head_ == rhs.head_
00120            && this->tail_ == rhs.tail_
00121            && this->current_ == rhs.current_;
00122   }
00123 
00124   bool
00125   operator!=(const SendStateDataSampleListConstIterator& rhs) const {
00126     return !(*this == rhs);
00127   }
00128 
00129 private:
00130   const DataSampleElement* head_;
00131   const DataSampleElement* tail_;
00132   const DataSampleElement* current_;
00133 
00134 };
00135 
00136 /**
00137 * A list of DataSampleElement pointers to be queued by the order the
00138 * samples are to be transmitted over the transport layer.
00139 * Cache the number of elements in the list so that list traversal is
00140 * not required to find this information.
00141 * The Publisher may use this to maintain a list of samples to
00142 * be sent with PRESENTATION.access_scope==GROUP by obtaining
00143 * data from each DataWriter as it becomes available and
00144 * concatenating the data in the order in which it was written.
00145 * Manages DataSampleElement's previous_send_sample/next_send_sample pointers
00146 */
00147 class OpenDDS_Dcps_Export SendStateDataSampleList {
00148 
00149   friend class ::DDS_TEST;
00150 
00151   static const SendStateDataSampleList*
00152     send_list_containing_element(const DataSampleElement* element,
00153                                  SendStateDataSampleList** begin,
00154                                  SendStateDataSampleList** end);
00155 
00156  public:
00157 
00158   /// STL-style bidirectional iterator and const-iterator types.
00159   typedef SendStateDataSampleListIterator iterator;
00160   typedef SendStateDataSampleListConstIterator const_iterator;
00161 
00162 #if defined __SUNPRO_CC && __SUNPRO_CC <= 0x5130 \
00163    && defined _RWSTD_NO_CLASS_PARTIAL_SPEC
00164   typedef std::reverse_iterator<iterator, std::bidirectional_iterator_tag,
00165                                 DataSampleElement, DataSampleElement&,
00166                                 DataSampleElement*, std::ptrdiff_t>
00167     reverse_iterator;
00168   typedef std::reverse_iterator<const_iterator, std::bidirectional_iterator_tag,
00169                                 const DataSampleElement,
00170                                 const DataSampleElement&,
00171                                 const DataSampleElement*, std::ptrdiff_t>
00172     const_reverse_iterator;
00173 #else
00174   typedef std::reverse_iterator<iterator> reverse_iterator;
00175   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00176 #endif
00177 
00178   /// Default constructor clears the list.
00179   SendStateDataSampleList();
00180   ~SendStateDataSampleList(){}
00181 
00182   /// Returns a pointer to the SendStateDataSampleList containing a
00183   /// given DataSampleElement for use in the typical situation where
00184   /// the send state of a DataSampleElement is tracked by shifting
00185   /// it between distinct SendStateDataSampleLists, one for each state
00186   template <size_t N>
00187   static const SendStateDataSampleList*
00188     send_list_containing_element(const DataSampleElement* element,
00189                                  SendStateDataSampleList* (&send_lists)[N])
00190   {
00191     return send_list_containing_element(element,
00192                                         &send_lists[0], &send_lists[N]);
00193   }
00194 
00195   /// Reset to initial state.
00196   void reset();
00197 
00198   ssize_t size() const;
00199   DataSampleElement* head() const;
00200   DataSampleElement* tail() const;
00201 
00202   void enqueue_head(const DataSampleElement* element);
00203 
00204   void enqueue_tail(const DataSampleElement* element);
00205   void enqueue_tail(SendStateDataSampleList list);
00206 
00207   bool dequeue_head(DataSampleElement*& stale);
00208 
00209   bool dequeue(const DataSampleElement* stale);
00210 
00211   /// Remove from whichever list "stale" belongs to, without needing
00212   /// a reference to the SendStateDataSampleList object itself.
00213   /// That SendStateDataSampleList is no longer accurate and can't be used.
00214   static void remove(DataSampleElement* stale);
00215 
00216   /// Return iterator to beginning of list.
00217   iterator begin();
00218   const_iterator begin() const;
00219 
00220   /// Return iterator to end of list.
00221   iterator end();
00222   const_iterator end() const;
00223 
00224   reverse_iterator rbegin();
00225   const_reverse_iterator rbegin() const;
00226   reverse_iterator rend();
00227   const_reverse_iterator rend() const;
00228 
00229  protected:
00230 
00231   /// The first element of the list.
00232   DataSampleElement* head_;
00233 
00234   /// The last element of the list.
00235   DataSampleElement* tail_;
00236 
00237   /// Number of elements in the list.
00238   ssize_t                size_;
00239   //TBD size is never negative so should be size_t but this ripples through
00240   // the transport code so leave it for now. SHH
00241 
00242 };
00243 
00244 } // namespace DCPS
00245 } // namespace OpenDDS
00246 
00247 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00248 
00249 #if defined(__ACE_INLINE__)
00250 #include "SendStateDataSampleList.inl"
00251 #endif /* __ACE_INLINE__ */
00252 
00253 #endif  /* OPENDDS_DCPS_SENDSTATEDATASAMPLELIST_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1