OpenDDS  Snapshot(2023/04/28-20:55)
NetworkConfigMonitor.cpp
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
9 
10 #include "NetworkConfigMonitor.h"
11 
12 #include "Qos_Helper.h"
13 #include "Service_Participant.h"
14 
16 
17 namespace OpenDDS {
18 namespace DCPS {
19 
20 bool NetworkInterfaceAddress::exclude_from_multicast(const char* configured_interface) const
21 {
22  if (!can_multicast) {
23  return true;
24  }
25 
26  if (configured_interface && *configured_interface && name != configured_interface) {
27  OPENDDS_STRING ci_semi(configured_interface);
28  if (ci_semi.find_first_of(':') == OPENDDS_STRING::npos) {
29  ci_semi += ':';
30  }
31  NetworkAddress as_addr(ci_semi.c_str());
32  if (as_addr == NetworkAddress() || address != as_addr) {
33  return true;
34  }
35  }
36 
37  const NetworkAddress sp_default = TheServiceParticipant->default_address();
38  return sp_default != NetworkAddress() && address != sp_default;
39 }
40 
42  : writer_(make_rch<InternalDataWriter<NetworkInterfaceAddress> >(DataWriterQosBuilder().durability_transient_local()))
43 {}
44 
46 {}
47 
49 {
50  topic->connect(writer_);
51 }
52 
54 {
55  topic->disconnect(writer_);
56 }
57 
58 void NetworkConfigMonitor::set(const List& list)
59 {
61 
62  for (List::const_iterator pos = list.begin(), limit = list.end(); pos != limit; ++pos) {
63  List::const_iterator iter = std::find_if(list_.begin(), list_.end(), NetworkInterfaceAddressKeyEqual(*pos));
64  if (iter != list_.end()) {
65  if (*iter != *pos) {
66  // Change.
67  writer_->write(*pos);
68  }
69  } else {
70  // New.
71  writer_->write(*pos);
72  }
73  }
74 
75  for (List::const_iterator pos = list_.begin(), limit = list_.end(); pos != limit; ++pos) {
76  List::const_iterator iter = std::find_if(list.begin(), list.end(), NetworkInterfaceAddressKeyEqual(*pos));
77  if (iter == list.end()) {
78  // Deleted.
79  writer_->unregister_instance(*pos);
80  }
81  }
82 
83  list_ = list;
84 }
85 
87 {
89 
90  for (List::const_iterator pos = list_.begin(), limit = list_.end(); pos != limit; ++pos) {
91  writer_->unregister_instance(*pos);
92  }
93 
94  list_.clear();
95 }
96 
98 {
100 
101  List::iterator pos = std::find_if(list_.begin(), list_.end(), NetworkInterfaceAddressKeyEqual(nia));
102  if (pos != list_.end()) {
103  if (*pos != nia) {
104  writer_->write(nia);
105  *pos = nia;
106  }
107  } else {
108  writer_->write(nia);
109  list_.push_back(nia);
110  }
111 }
112 
114 {
116 
117  for (List::iterator pos = list_.begin(), limit = list_.end(); pos != limit;) {
118  if (pos->name == name) {
119  writer_->unregister_instance(*pos);
120  list_.erase(pos++);
121  } else {
122  ++pos;
123  }
124  }
125 }
126 
128 {
130 
131  for (List::iterator pos = list_.begin(), limit = list_.end(); pos != limit;) {
132  if (pos->name == name && pos->address == address) {
133  writer_->unregister_instance(*pos);
134  list_.erase(pos++);
135  } else {
136  ++pos;
137  }
138  }
139 }
140 
141 } // DCPS
142 } // OpenDDS
143 
bool exclude_from_multicast(const char *configured_interface) const
#define ACE_GUARD(MUTEX, OBJ, LOCK)
RcHandle< T > make_rch()
Definition: RcHandle_T.h:256
void connect(RcHandle< InternalTopic< NetworkInterfaceAddress > > topic)
#define OPENDDS_STRING
void remove_interface(const OPENDDS_STRING &name)
void disconnect(RcHandle< InternalTopic< NetworkInterfaceAddress > > topic)
const char *const name
Definition: debug.cpp:60
RcHandle< InternalDataWriter< NetworkInterfaceAddress > > writer_
void remove_address(const OPENDDS_STRING &name, const NetworkAddress &address)
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
#define TheServiceParticipant
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28