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