Line data Source code
1 : /* 2 : * 3 : * 4 : * Distributed under the OpenDDS License. 5 : * See: http://www.opendds.org/license.html 6 : */ 7 : 8 : #ifndef OPENDDS_DCPS_TRANSPORT_FRAMEWORK_RECEIVEDDATASAMPLE_H 9 : #define OPENDDS_DCPS_TRANSPORT_FRAMEWORK_RECEIVEDDATASAMPLE_H 10 : 11 : #include <dds/DCPS/DataSampleHeader.h> 12 : #include <dds/DCPS/PoolAllocator.h> 13 : 14 : #include <dds/DCPS/MessageBlock.h> 15 : 16 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 17 : 18 : namespace OpenDDS { 19 : namespace DCPS { 20 : 21 : /** 22 : * @class ReceivedDataSample 23 : * 24 : * @brief Holds a data sample received by the transport. 25 : * 26 : * This is the type of object that is delivered to the 27 : * TransportReceiveListener objects by the transport. 28 : * Note that the data sample header has already been 29 : * demarshalled by the transport, and the ACE_Message_Block (chain) 30 : * represents the "data" portion of the sample. 31 : * 32 : * Internally, ReceivedDataSample uses an alternate representation 33 : * of the ACE_Message_Block with contiguous storage (vector) 34 : * instead of a linked list to implement the continuation chain. 35 : */ 36 : class OpenDDS_Dcps_Export ReceivedDataSample { 37 : public: 38 : ReceivedDataSample(); 39 : 40 : explicit ReceivedDataSample(const ACE_Message_Block& payload); 41 : 42 : /// The demarshalled sample header. 43 : DataSampleHeader header_; 44 : 45 : /// Fragment size used by this sample 46 : ACE_UINT32 fragment_size_; 47 : 48 : /// true if at least one Data Block is stored (even if it has 0 useable bytes) 49 1515 : bool has_data() const { return !blocks_.empty(); } 50 : 51 : /// total length of usable bytes (between rd_ptr and wr_ptr) of all Data Blocks 52 : size_t data_length() const; 53 : 54 1160 : void clear() { blocks_.clear(); } 55 : 56 : ACE_Message_Block* data(ACE_Allocator* mb_alloc = 0) const; 57 : 58 : /// write the data payload to the Serializer 59 : bool write_data(Serializer& ser) const; 60 : 61 : /// copy the data payload into an OctetSeq 62 : DDS::OctetSeq copy_data() const; 63 : 64 : /// @brief Retreive one byte of data from the payload 65 : /// @param offset must be in the range [0, data_length()) 66 : unsigned char peek(size_t offset) const; 67 : 68 : /// @brief Update this ReceivedDataSample's data payload to include 69 : /// the prefix's data payload before any existing bytes. 70 : /// Headers are not modified. 71 : /// @param prefix the source ReceivedDataSample, its data will be removed and 72 : /// taken over by this ReceivedDataSample 73 : void prepend(ReceivedDataSample& prefix); 74 : 75 : /// @brief Update this ReceivedDataSample's data payload to include 76 : /// the suffix's data payload after any existing bytes. 77 : /// Headers are not modified. 78 : /// @param suffix the source ReceivedDataSample, its data will be removed and 79 : /// taken over by this ReceivedDataSample 80 : void append(ReceivedDataSample& suffix); 81 : 82 : /// @brief Add passed-in data to payload bytes 83 : /// @param data start of bytes to add to the payload (makes a copy) 84 : /// @param size number of bytes to add to the payload 85 : void append(const char* data, size_t size); 86 : 87 : /// @brief Replace all payload bytes with passed-in data 88 : /// Based on the ACE_Message_Block(const char*, size_t) constructor, doesn't copy data 89 : /// @param data start of bytes to use as the payload 90 : /// @param size number of bytes to use as the payload 91 : void replace(const char* data, size_t size); 92 : 93 : ReceivedDataSample get_fragment_range(FragmentNumber start_frag, FragmentNumber end_frag = INVALID_FRAGMENT); 94 : 95 : private: 96 : 97 : OPENDDS_VECTOR(MessageBlock) blocks_; 98 : }; 99 : 100 : } // namespace DCPS 101 : } // namespace OpenDDS 102 : 103 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 104 : 105 : #endif /* OPENDDS_DCPS_RECEIVEDDATASAMPLE_H */