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

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1