TransportReassembly.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_TRANSPORTREASSEMBLY
00009 #define OPENDDS_DCPS_TRANSPORTREASSEMBLY
00010 
00011 #include "dds/DCPS/dcps_export.h"
00012 #include "dds/DCPS/Definitions.h"
00013 #include "ReceivedDataSample.h"
00014 #include "dds/DCPS/PoolAllocator.h"
00015 
00016 namespace OpenDDS {
00017 namespace DCPS {
00018 
00019 class OpenDDS_Dcps_Export TransportReassembly {
00020 public:
00021 
00022   /// Called by TransportReceiveStrategy if the fragmentation header flag
00023   /// is set.  Returns true/false to indicate if data should be delivered to
00024   /// the datalink.  The 'data' argument may be modified by this method.
00025   bool reassemble(const SequenceNumber& transportSeq, bool firstFrag,
00026                   ReceivedDataSample& data);
00027 
00028   bool reassemble(const SequenceRange& seqRange, ReceivedDataSample& data);
00029 
00030   /// Called by TransportReceiveStrategy to indicate that we can
00031   /// stop tracking partially-reassembled messages when we know the
00032   /// remaining fragments are not expected to arrive.
00033   void data_unavailable(const SequenceRange& transportSeqDropped);
00034 
00035   void data_unavailable(const SequenceNumber& dataSampleSeq,
00036                         const RepoId& pub_id);
00037 
00038   /// Returns true if this object is storing fragments for the given
00039   /// DataSampleHeader sequence number from the given publication.
00040   bool has_frags(const SequenceNumber& seq, const RepoId& pub_id) const;
00041 
00042   /// Populates bitmap for missing fragment sequence numbers and set numBits
00043   /// for the given message sequence and publisher ID.
00044   /// @returns the base fragment sequence number for bit zero in the bitmap
00045   CORBA::ULong get_gaps(const SequenceNumber& msg_seq, const RepoId& pub_id,
00046                         CORBA::Long bitmap[], CORBA::ULong length,
00047                         CORBA::ULong& numBits) const;
00048 
00049 private:
00050 
00051   bool reassemble_i(const SequenceRange& seqRange, bool firstFrag,
00052                     ReceivedDataSample& data);
00053 
00054   // A FragKey represents the identifier for an original (pre-fragmentation)
00055   // message.  Since DataSampleHeader sequence numbers are distinct for each
00056   // "publication" (DataWriter), the partially-received messages need to be
00057   // stored in a structure that's keyed off of both the PublicationId and the
00058   // SequenceNumber.
00059   struct FragKey {
00060     FragKey(const PublicationId& pubId, const SequenceNumber& dataSampleSeq);
00061 
00062     bool operator<(const FragKey& rhs) const
00063     {
00064       if (compare_(this->publication_, rhs.publication_)) return true;
00065       if (compare_(rhs.publication_, this->publication_)) return false;
00066       return this->data_sample_seq_ < rhs.data_sample_seq_;
00067     }
00068 
00069     static GUID_tKeyLessThan compare_;
00070     PublicationId publication_;
00071     SequenceNumber data_sample_seq_;
00072   };
00073 
00074   // A FragRange represents a chunk of a partially-reassembled message.
00075   // The transport_seq_ range is the range of transport sequence numbers
00076   // that were used to send the given chunk of data.
00077   struct FragRange {
00078     FragRange(const SequenceRange& seqRange,
00079               const ReceivedDataSample& data);
00080 
00081     SequenceRange transport_seq_;
00082     ReceivedDataSample rec_ds_;
00083   };
00084 
00085   // Each element of the FragMap "fragments_" represents one sent message
00086   // (one DataSampleHeader before fragmentation).  The list must have at
00087   // least one value in it.  If a FragRange in the list has a sample_ with
00088   // a null ACE_Message_Block*, it's one that was data_unavailable().
00089   typedef OPENDDS_MAP(FragKey, OPENDDS_LIST(FragRange) ) FragMap;
00090   FragMap fragments_;
00091 
00092   OPENDDS_SET(FragKey) have_first_;
00093 
00094   static bool insert(OPENDDS_LIST(FragRange)& flist,
00095                      const SequenceRange& seqRange,
00096                      ReceivedDataSample& data);
00097 };
00098 
00099 }
00100 }
00101 
00102 #endif

Generated on Fri Feb 12 20:05:28 2016 for OpenDDS by  doxygen 1.4.7