TransportHeader.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_TRANSPORTHEADER_H
00009 #define OPENDDS_DCPS_TRANSPORTHEADER_H
00010 
00011 #include "ace/Basic_Types.h"
00012 #include "ace/CDR_Base.h"
00013 
00014 #include "dds/DCPS/Definitions.h"
00015 
00016 namespace OpenDDS {
00017 namespace DCPS {
00018 
00019 // If TransportHeader changes size, must recalculate
00020 // serialized size and update static variable here
00021 static const ACE_UINT32 TRANSPORT_HDR_SERIALIZED_SZ(28);
00022 
00023 /**
00024  * @struct TransportHeader
00025  *
00026  * @brief Defines class that represents a transport packet header.
00027  *
00028  * The TransportHeader is the transport packet header.  Each packet
00029  * sent by the transport will always start with a transport packet
00030  * header, followed by one or more data samples (all belonging to the
00031  * same transport packet).
00032  */
00033 struct OpenDDS_Dcps_Export TransportHeader {
00034   static const ACE_CDR::Octet DCPS_PROTOCOL[6];
00035 
00036   /// Default constructor.
00037   TransportHeader();
00038 
00039   /// Construct with values extracted from a buffer.
00040   explicit TransportHeader(ACE_Message_Block& buffer);
00041 
00042   /// Assignment from an ACE_Message_Block.
00043   TransportHeader& operator=(ACE_Message_Block& buffer);
00044 
00045   void incomplete(ACE_Message_Block&) {}
00046 
00047   /// Determine if the serializer should swap bytes.
00048   bool swap_bytes() const;
00049 
00050   /// Determine if this is a valid packet header.
00051   bool valid() const;
00052 
00053   /// The protocol of the packet being transmitted.
00054   ACE_CDR::Octet protocol_[6];
00055 
00056   /// Flags: marshaled as a single byte (ACE_CDR::Octet)
00057   bool byte_order_;
00058   bool first_fragment_;
00059   bool last_fragment_;
00060 
00061   /// Constants for bit masking the marshaled flags byte.
00062   /// This needs to match the 'Flags' above.
00063   enum { BYTE_ORDER_FLAG, FIRST_FRAGMENT_FLAG, LAST_FRAGMENT_FLAG };
00064 
00065   /// Reserved for future use (provides padding for preamble).
00066   ACE_CDR::Octet reserved_;
00067 
00068   /// The size of the message following this header, not including the
00069   /// bytes used by this TransportHeader.
00070   ACE_UINT32 length_;
00071 
00072   /// The sequence number of the packet identified by this header; this
00073   /// value is guaranteed to be a monotonically increasing number per
00074   /// transport instance.
00075   SequenceNumber sequence_;
00076 
00077   /// A transport-specific identification number which uniquely
00078   /// identifies the source of the packet.
00079   ACE_INT64 source_;
00080 
00081   /// Similar to IDL compiler generated methods.
00082   static size_t max_marshaled_size();
00083 
00084   /// Demarshal transport packet from ACE_Message_Block.
00085   void init(ACE_Message_Block* buffer);
00086 
00087   bool first_fragment() { return this->first_fragment_; }
00088   bool last_fragment()  { return this->last_fragment_; }
00089   void last_fragment(bool frag) { this->last_fragment_ = frag; }
00090   const SequenceNumber& sequence() { return this->sequence_; }
00091 
00092   static ACE_UINT32 get_length(const char* marshaled_transport_header);
00093 
00094 private:
00095   struct no_init_t {};
00096   static const no_init_t no_init;
00097   explicit TransportHeader(const no_init_t&);
00098 };
00099 
00100 OpenDDS_Dcps_Export
00101 bool operator<<(ACE_Message_Block&, const TransportHeader& value);
00102 
00103 } // namespace DCPS
00104 } // namespace OpenDDS
00105 
00106 
00107 #if defined(__ACE_INLINE__)
00108 #include "TransportHeader.inl"
00109 #endif /* __ACE_INLINE__ */
00110 
00111 #endif  /* OPENDDS_DCPS_TRANSPORTHEADER_H */

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