Line data Source code
1 : /* 2 : * Distributed under the OpenDDS License. 3 : * See: http://www.opendds.org/license.html 4 : */ 5 : 6 : #include "MetaSubmessage.h" 7 : 8 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 9 : 10 : namespace OpenDDS { 11 : namespace DCPS { 12 : 13 : namespace { 14 : struct SortPredicate { 15 80 : bool operator()(const MetaSubmessage& x, const MetaSubmessage& y) const 16 : { 17 80 : if (x.src_guid_ != y.src_guid_) { 18 39 : return x.src_guid_ < y.src_guid_; 19 : } 20 : 21 41 : if (x.dst_guid_ != y.dst_guid_) { 22 17 : return x.dst_guid_ < y.dst_guid_; 23 : } 24 : 25 24 : if (x.sm_._d() != y.sm_._d()) { 26 10 : return x.sm_._d() < y.sm_._d(); 27 : } 28 : 29 : // Order heartbeats and acknacks by count, descending. 30 14 : switch (x.sm_._d()) { 31 9 : case RTPS::HEARTBEAT: 32 9 : return x.sm_.heartbeat_sm().count.value > y.sm_.heartbeat_sm().count.value; 33 5 : case RTPS::ACKNACK: 34 5 : return x.sm_.acknack_sm().count.value > y.sm_.acknack_sm().count.value; 35 0 : default: 36 0 : return false; 37 : } 38 : } 39 : }; 40 : 41 : struct EqualPredicate { 42 14 : bool operator()(const MetaSubmessage& x, const MetaSubmessage& y) const 43 : { 44 14 : return x.src_guid_ == y.src_guid_ && 45 27 : x.dst_guid_ == y.dst_guid_ && 46 27 : x.sm_._d() == y.sm_._d(); 47 : } 48 : }; 49 : } 50 : 51 2 : size_t dedup(MetaSubmessageVec& vec) 52 : { 53 2 : size_t count = 0; 54 : 55 2 : if (vec.empty()) { 56 1 : return count; 57 : } 58 : 59 1 : std::sort(vec.begin(), vec.end(), SortPredicate()); 60 1 : MetaSubmessageVec::iterator pos = vec.begin(); 61 1 : MetaSubmessageVec::iterator next = pos; 62 1 : std::advance(next, 1); 63 1 : const MetaSubmessageVec::iterator limit = vec.end(); 64 : EqualPredicate eq; 65 18 : for (; next != limit; ++pos, ++next) { 66 17 : if ((pos->sm_._d() == RTPS::HEARTBEAT || pos->sm_._d() == RTPS::ACKNACK) && eq(*pos, *next)) { 67 10 : next->ignore_ = true; 68 10 : ++count; 69 : } 70 : } 71 : 72 1 : return count; 73 : } 74 : 75 : } // namespace DCPS 76 : } // namespace OpenDDS 77 : 78 : OPENDDS_END_VERSIONED_NAMESPACE_DECL